SmartSnippets DA1459x SDK
Functions

Initialization, configuration, measurement and voltage conversion functions. More...

Functions

void hw_gpadc_init (const hw_gpadc_config_t *cfg, bool enable)
 Initialize ADC. More...
 
void hw_gpadc_configure (const hw_gpadc_config_t *cfg)
 Configure ADC. More...
 
void hw_gpadc_register_interrupt (hw_gpadc_interrupt_cb cb)
 Register interrupt handler. More...
 
void hw_gpadc_unregister_interrupt (void)
 Unregister interrupt handler. More...
 
void hw_gpadc_unregister_interrupt_no_clear (void)
 Unregister interrupt handler without clearing the ADC engine interrupt. Only the NVIC interrupt is disabled and cleared. More...
 
__STATIC_INLINE void hw_gpadc_clear_interrupt (void)
 Clear interrupt. More...
 
__STATIC_INLINE void hw_gpadc_enable (void)
 Enable ADC. More...
 
__STATIC_INLINE void hw_gpadc_disable (void)
 Disable ADC. More...
 
__STATIC_INLINE bool hw_gpadc_is_enabled (void)
 ADC enabled state. More...
 
__STATIC_INLINE void hw_gpadc_start (void)
 Start conversion. More...
 
__STATIC_INLINE bool hw_gpadc_in_progress (void)
 Check if conversion is in progress. More...
 
__STATIC_INLINE uint16_t hw_gpadc_get_raw_value (void)
 Get raw ADC value. More...
 
uint16_t hw_gpadc_get_value (void)
 Get conversion result value with gain compensation and over sampling. More...
 
__STATIC_INLINE void hw_gpadc_adc_measure (void)
 Start the ADC conversion engine, providing a measurement. More...
 
bool hw_gpadc_read (uint32_t nof_conv, uint16_t *out_buf, hw_gpadc_read_cb cb, void *user_data)
 Generic read function Follows. More...
 
void hw_gpadc_abort_read (void)
 Stop conversions. More...
 
uint16_t hw_gpadc_apply_correction (const hw_gpadc_config_t *cfg, uint16_t raw)
 Apply a fine trimming algorithm to the conversion result. More...
 
int16_t hw_gpadc_convert_to_millivolt (const hw_gpadc_config_t *cfg, uint16_t raw)
 Convert a GPADC raw measurement to voltage in mVolt. If no configuration is given, the current state of the GPADC control registers is used for the conversion parameters. More...
 
int16_t hw_gpadc_get_voltage (void)
 Get the measured voltage in mVolt. More...
 

Detailed Description

Initialization, configuration, measurement and voltage conversion functions.

Function Documentation

◆ hw_gpadc_abort_read()

void hw_gpadc_abort_read ( void  )

Stop conversions.

Application can call this function to abort an ongoing read operation. It is applicable only in when the ADC operates either in interrupt or DMA mode.

See also
hw_gpadc_read

◆ hw_gpadc_adc_measure()

__STATIC_INLINE void hw_gpadc_adc_measure ( void  )

Start the ADC conversion engine, providing a measurement.

See also
hw_gpadc_start
hw_gpadc_in_progress
Note
The function polls the ADC engine waiting for the measurement to be ready.

◆ hw_gpadc_apply_correction()

uint16_t hw_gpadc_apply_correction ( const hw_gpadc_config_t cfg,
uint16_t  raw 
)

Apply a fine trimming algorithm to the conversion result.

Parameters
[in]cfgconfiguration parameters for the conversion, NULL to use the current ADC settings
[in]rawthe raw result of the ADC conversion
Returns
16-bit left-aligned corrected value

◆ hw_gpadc_clear_interrupt()

__STATIC_INLINE void hw_gpadc_clear_interrupt ( void  )

Clear interrupt.

In case an interrupt handler has been registered, the application does not have to call this function in the interrupt handler to clear the interrupt. This is handled by the GPADC driver module.

See also
hw_gpadc_register_interrupt

◆ hw_gpadc_configure()

void hw_gpadc_configure ( const hw_gpadc_config_t cfg)

Configure ADC.

Shortcut to call appropriate configuration function. cfg must be valid.

Parameters
[in]cfgconfiguration

◆ hw_gpadc_convert_to_millivolt()

int16_t hw_gpadc_convert_to_millivolt ( const hw_gpadc_config_t cfg,
uint16_t  raw 
)

Convert a GPADC raw measurement to voltage in mVolt. If no configuration is given, the current state of the GPADC control registers is used for the conversion parameters.

Parameters
[in]cfgconfiguration parameters for the conversion, NULL to use the current ADC settings
[in]rawthe raw result of the ADC conversion
Returns
voltage (mVolt)
See also
hw_gpadc_apply_correction

◆ hw_gpadc_disable()

__STATIC_INLINE void hw_gpadc_disable ( void  )

Disable ADC.

Application should wait for conversion to be completed before disabling ADC. In case of continuous mode, application should disable continuous mode and then wait for conversion to be completed in order to have ADC in defined state.

See also
hw_gpadc_in_progress
hw_gpadc_set_continuous

◆ hw_gpadc_enable()

__STATIC_INLINE void hw_gpadc_enable ( void  )

Enable ADC.

Sampling is started after calling this function, to start conversion application should call hw_gpadc_start().

See also
hw_gpadc_start

◆ hw_gpadc_get_raw_value()

__STATIC_INLINE uint16_t hw_gpadc_get_raw_value ( void  )

Get raw ADC value.

See also
HW_GPADC_RESULT_MODE
Returns
raw ADC value.
Note
Neither correction nor conversion takes place.

◆ hw_gpadc_get_value()

uint16_t hw_gpadc_get_value ( void  )

Get conversion result value with gain compensation and over sampling.

Invalid bits are discarded from result, i.e. oversampling is taken into account when calculating value.

Returns
conversion result value
See also
hw_gpadc_get_raw_value
hw_gpadc_set_oversampling
hw_gpadc_apply_correction

◆ hw_gpadc_get_voltage()

int16_t hw_gpadc_get_voltage ( void  )

Get the measured voltage in mVolt.

Returns
voltage (mVolt)
See also
hw_gpadc_get_value

◆ hw_gpadc_in_progress()

__STATIC_INLINE bool hw_gpadc_in_progress ( void  )

Check if conversion is in progress.

Returns
conversion state

◆ hw_gpadc_init()

void hw_gpadc_init ( const hw_gpadc_config_t cfg,
bool  enable 
)

Initialize ADC.

cfg can be NULL - no configuration is performed in such case.

Parameters
[in]cfgconfiguration
[in]enableenable the ADC LDO after the configuration is applied

◆ hw_gpadc_is_enabled()

__STATIC_INLINE bool hw_gpadc_is_enabled ( void  )

ADC enabled state.

Returns
true if ADC is enabled, false if disabled

◆ hw_gpadc_read()

bool hw_gpadc_read ( uint32_t  nof_conv,
uint16_t *  out_buf,
hw_gpadc_read_cb  cb,
void *  user_data 
)

Generic read function Follows.

See also
hw_gpadc_init() or
hw_gpadc_configure(). According to the
hw_gpadc_config_t passed in the above mentioned functions, the generic read function starts the ADC engine, delivers the requested conversions and stops the ADC engine when finished. If a callback is set by the user, the function operates in interrupt mode, otherwise in blocking mode. The results are always in raw format, which means they need post-processing to be converted to something valuable. To ensure all conversions are in place, the caller may poll for the falling of the GP_ADC_START bit via
hw_gpadc_in_progress.
hw_gpadc_get_value
hw_gpadc_convert_to_millivolt
hw_gpadc_apply_correction
Parameters
[in]nof_convnumber of conversions to be delivered. Must be non-zero
[out]out_bufbuffer to place the conversion results, NULL is allowed making the user responsible for fetching the converted results from the GP_ADC_RESULT_REG
[in]cbuser callback to execute when conversions are over, NULL for polling mode which blocks until conversions are over
[in]user_dataparameter for callback
Returns
true if conversions have started, false otherwise
Note
Interrupt mode can operate without an output buffer but never without a user callback.
DMA mode can operate without a callback but never without an output buffer.
If in
See also
hw_gpadc_config_t the
dma_setup section is valid, the converted results are transfered through DMA to the requested buffer. In this case the ADC interrupt in M33 is bypassed, unless there is deliberate extra handling by the user outside this function. At any given point, calling
hw_gpadc_abort_read will abandon the converting process, executing the user callback passed as argument.

◆ hw_gpadc_register_interrupt()

void hw_gpadc_register_interrupt ( hw_gpadc_interrupt_cb  cb)

Register interrupt handler.

Additionally, interrupt is enabled after calling this function. Any pending interrupt is cleared before callback registration.

Parameters
[in]cbcallback to be fired on interrupt
See also
hw_gpadc_clear_interrupt

◆ hw_gpadc_start()

__STATIC_INLINE void hw_gpadc_start ( void  )

Start conversion.

Application should not call this function while conversion is still in progress.

See also
hw_gpadc_in_progress

◆ hw_gpadc_unregister_interrupt()

void hw_gpadc_unregister_interrupt ( void  )

Unregister interrupt handler.

Additionally, interrupt is disabled after calling this function. Any pending interrupt is cleared.

See also
hw_gpadc_clear_interrupt

◆ hw_gpadc_unregister_interrupt_no_clear()

void hw_gpadc_unregister_interrupt_no_clear ( void  )

Unregister interrupt handler without clearing the ADC engine interrupt. Only the NVIC interrupt is disabled and cleared.

See also
hw_gpadc_unregister_interrupt
hw_gpadc_clear_interrupt