SmartSnippets DA1459x SDK
Functions

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

Functions

void hw_sdadc_init (const hw_sdadc_config_t *cfg)
 Initialize SDADC. More...
 
void hw_sdadc_audio_init (hw_sdadc_interrupt_cb cb, const hw_sdadc_pga_config_t *cfg)
 Initialize the SDADC to configure the audio path. More...
 
void hw_sdadc_configure (const hw_sdadc_config_t *cfg)
 Configure SDADC. More...
 
void hw_sdadc_register_interrupt (hw_sdadc_interrupt_cb cb)
 Register interrupt handler. More...
 
void hw_sdadc_unregister_interrupt (void)
 Unregister interrupt handler. More...
 
__STATIC_INLINE void hw_sdadc_clear_interrupt (void)
 Clear interrupt. More...
 
void hw_sdadc_stop_and_wait (void)
 Stop and Wait. More...
 
__STATIC_INLINE void hw_sdadc_enable (void)
 Enable SDADC. More...
 
__STATIC_INLINE void hw_sdadc_disable (void)
 Disable SDADC. More...
 
__STATIC_INLINE bool hw_sdadc_is_enabled (void)
 Get the enable status of the SDADC. More...
 
void hw_sdadc_start (void)
 Start conversion. More...
 
__STATIC_INLINE void hw_sdadc_adc_measure (void)
 Start the ADC conversion engine, providing one measurement. More...
 
int32_t hw_sdadc_get_voltage (const hw_sdadc_config_t *cfg)
 Perform an ADC measurement and return the ADC value converted to mV. More...
 
int32_t hw_sdadc_convert_to_millivolt (const hw_sdadc_config_t *cfg, uint16_t raw)
 Convert the ADC value to mV. More...
 
bool hw_sdadc_read (uint32_t nof_conv, uint16_t *out_buf, hw_sdadc_read_cb cb, void *user_data)
 Generic read function Follows. More...
 
void hw_sdadc_abort_read (void)
 Stop conversions. More...
 
void hw_sdadc_store_ext_ref_calibration_values (int16_t gain, int16_t offset)
 Store external reference voltage calibration values. More...
 
__STATIC_INLINE bool hw_sdadc_in_progress (void)
 Check if conversion is in progress. More...
 

Detailed Description

Initialization, configuration, measurement and voltage conversion functions.

Function Documentation

◆ hw_sdadc_abort_read()

void hw_sdadc_abort_read ( void  )

Stop conversions.

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

See also
hw_sdadc_read

◆ hw_sdadc_adc_measure()

__STATIC_INLINE void hw_sdadc_adc_measure ( void  )

Start the ADC conversion engine, providing one measurement.

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

◆ hw_sdadc_audio_init()

void hw_sdadc_audio_init ( hw_sdadc_interrupt_cb  cb,
const hw_sdadc_pga_config_t *  cfg 
)

Initialize the SDADC to configure the audio path.

Sets the SDADC control register to support the audio path and registers the function to be called upon SDADC_IRQn interrupt firing. Still, hw_sdadc_start() must be called by the application to start conversion.

Parameters
[in]cbinterrupt callback function
[in]cfgpga configuration
Note
If cfg is NULL, this function does not configure the PGA
See also
hw_sdadc_register_interrupt

◆ hw_sdadc_clear_interrupt()

__STATIC_INLINE void hw_sdadc_clear_interrupt ( void  )

Clear interrupt.

Application should call this in interrupt handler to clear interrupt.

See also
hw_sdadc_register_interrupt

◆ hw_sdadc_configure()

void hw_sdadc_configure ( const hw_sdadc_config_t cfg)

Configure SDADC.

Shortcut to call appropriate configuration function. If cfg is NULL, this function does nothing.

Parameters
[in]cfgconfiguration

◆ hw_sdadc_convert_to_millivolt()

int32_t hw_sdadc_convert_to_millivolt ( const hw_sdadc_config_t cfg,
uint16_t  raw 
)

Convert the ADC value to mV.

Parameters
[in]cfgsdadc configuration
[in]rawadc raw value
Returns
The ADC raw value converted to mV

◆ hw_sdadc_disable()

__STATIC_INLINE void hw_sdadc_disable ( void  )

Disable SDADC.

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

See also
hw_sdadc_stop_and_wait

◆ hw_sdadc_enable()

__STATIC_INLINE void hw_sdadc_enable ( void  )

Enable SDADC.

This function enables the SDADC. LDO, bias currents and modulator are enabled. To start a conversion, the application should call hw_sdadc_start().

See also
hw_sdadc_start

◆ hw_sdadc_get_voltage()

int32_t hw_sdadc_get_voltage ( const hw_sdadc_config_t cfg)

Perform an ADC measurement and return the ADC value converted to mV.

Parameters
[in]cfgsdadc configuration
Returns
The ADC value converted to mV
See also
hw_sdadc_start
hw_sdadc_get_raw_value

◆ hw_sdadc_in_progress()

__STATIC_INLINE bool hw_sdadc_in_progress ( void  )

Check if conversion is in progress.

Returns
conversion state

◆ hw_sdadc_init()

void hw_sdadc_init ( const hw_sdadc_config_t cfg)

Initialize SDADC.

Stops ongoing sdadc operation, if any, sets the SDADC control register to default values, then enables the SDADC and calls the configuration function. It also disables and clears pending SDADC interrupts.

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

Parameters
[in]cfgconfiguration
See also
hw_sdadc_configure

◆ hw_sdadc_is_enabled()

__STATIC_INLINE bool hw_sdadc_is_enabled ( void  )

Get the enable status of the SDADC.

Returns
SDADC enable status

◆ hw_sdadc_read()

bool hw_sdadc_read ( uint32_t  nof_conv,
uint16_t *  out_buf,
hw_sdadc_read_cb  cb,
void *  user_data 
)

Generic read function Follows.

See also
hw_sdadc_init() or
hw_sdadc_configure(). According to the
hw_sdadc_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 start bit via
hw_sdadc_in_progress.
hw_sdadc_get_value
hw_sdadc_convert_to_millivolt
hw_sdadc_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 but user has to set a user callback in order to be able to fetch the converted results from the SD_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_sdadc_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_sdadc_abort_read will abandon the converting process, executing the user callback passed as argument.

◆ hw_sdadc_register_interrupt()

void hw_sdadc_register_interrupt ( hw_sdadc_interrupt_cb  cb)

Register interrupt handler.

Interrupt is enabled after calling this function. Application is responsible for clearing interrupt using hw_sdadc_clear_interrupt(). If no callback is specified interrupt is cleared by driver.

Parameters
[in]cbcallback fired on interrupt
See also
hw_sdadc_clear_interrupt

◆ hw_sdadc_start()

void hw_sdadc_start ( void  )

Start conversion.

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

See also
hw_sdadc_in_progress

◆ hw_sdadc_stop_and_wait()

void hw_sdadc_stop_and_wait ( void  )

Stop and Wait.

Disable the continuous mode, and wait for the ADC engine to finish

Note
When DMA is in use, calling this function also disables the respective DMA channel and unregisters its callback.

◆ hw_sdadc_store_ext_ref_calibration_values()

void hw_sdadc_store_ext_ref_calibration_values ( int16_t  gain,
int16_t  offset 
)

Store external reference voltage calibration values.

Parameters
[in]gaingain correction value
[in]offsetoffset correction value
Note
In case of external VREF, this function must be called before hw_sdadc_configure().

◆ hw_sdadc_unregister_interrupt()

void hw_sdadc_unregister_interrupt ( void  )

Unregister interrupt handler.

Interrupt is disabled after calling this function.