Analog-to-digital converter (ADC) driver. More...
Modules | |
Driver for ADC peripheral (nRF51) configuration | |
Data Structures | |
struct | nrf_drv_adc_done_evt_t |
Analog-to-digital converter driver DONE event. More... | |
struct | nrf_drv_adc_sample_evt_t |
Analog-to-digital converter driver SAMPLE event. More... | |
struct | nrf_drv_adc_evt_t |
Analog-to-digital converter driver event. More... | |
struct | nrf_drv_adc_channel_config_t |
ADC channel configuration. More... | |
struct | nrf_drv_adc_channel_s |
ADC channel. More... | |
struct | nrf_drv_adc_config_t |
ADC configuration. More... | |
Macros | |
#define | NRF_DRV_ADC_DEFAULT_CHANNEL(analog_input) |
Macro for initializing the ADC channel with the default configuration. More... | |
#define | NRF_DRV_ADC_DEFAULT_CONFIG |
ADC default configuration. More... | |
Typedefs | |
typedef int16_t | nrf_adc_value_t |
typedef struct nrf_drv_adc_channel_s | nrf_drv_adc_channel_t |
typedef void(* | nrf_drv_adc_event_handler_t )(nrf_drv_adc_evt_t const *p_event) |
User event handler prototype. More... | |
Enumerations | |
enum | nrf_drv_adc_evt_type_t { NRF_DRV_ADC_EVT_DONE, NRF_DRV_ADC_EVT_SAMPLE } |
Driver event types. More... | |
Functions | |
ret_code_t | nrf_drv_adc_init (nrf_drv_adc_config_t const *p_config, nrf_drv_adc_event_handler_t event_handler) |
Function for initializing the ADC. More... | |
void | nrf_drv_adc_uninit (void) |
Function for uninitializing the ADC. More... | |
void | nrf_drv_adc_channel_enable (nrf_drv_adc_channel_t *const p_channel) |
Function for enabling an ADC channel. More... | |
void | nrf_drv_adc_channel_disable (nrf_drv_adc_channel_t *const p_channel) |
Function for disabling an ADC channel. | |
void | nrf_drv_adc_sample (void) |
Function for starting ADC sampling. More... | |
ret_code_t | nrf_drv_adc_sample_convert (nrf_drv_adc_channel_t const *const p_channel, nrf_adc_value_t *p_value) |
Function for executing a single ADC conversion. More... | |
ret_code_t | nrf_drv_adc_buffer_convert (nrf_adc_value_t *buffer, uint16_t size) |
Function for converting data to the buffer. More... | |
bool | nrf_drv_adc_is_busy (void) |
Function for retrieving the ADC state. More... | |
__STATIC_INLINE uint32_t | nrf_drv_adc_start_task_get (void) |
Function for getting the address of the ADC START task. More... | |
Analog-to-digital converter (ADC) driver.
#define NRF_DRV_ADC_DEFAULT_CHANNEL | ( | analog_input | ) |
Macro for initializing the ADC channel with the default configuration.
#define NRF_DRV_ADC_DEFAULT_CONFIG |
ADC default configuration.
typedef void(* nrf_drv_adc_event_handler_t)(nrf_drv_adc_evt_t const *p_event) |
User event handler prototype.
This function is called when the requested number of samples has been processed.
p_event | Event. |
ret_code_t nrf_drv_adc_buffer_convert | ( | nrf_adc_value_t * | buffer, |
uint16_t | size | ||
) |
Function for converting data to the buffer.
If the driver is initialized in non-blocking mode, this function returns when the first conversion is set up. When the buffer is filled, the application is notified by the event handler. If the driver is initialized in blocking mode, the function returns when the buffer is filled.
Conversion is done on all enabled channels, but it is not triggered by this function. This function will prepare the ADC for sampling and then wait for the SAMPLE task. Sampling can be triggered manually by the nrf_drv_adc_sample function or by PPI using the NRF_ADC_TASK_START task.
[in] | buffer | Result buffer. |
[in] | size | Buffer size in samples. |
NRF_SUCCESS | If conversion was successful. |
NRF_ERROR_BUSY | If the driver is busy. |
void nrf_drv_adc_channel_enable | ( | nrf_drv_adc_channel_t *const | p_channel | ) |
Function for enabling an ADC channel.
This function configures and enables the channel. When nrf_drv_adc_buffer_convert is called, all channels that have been enabled with this function are sampled.
p_channel
is used by the driver as an item in a list. Therefore, it cannot be an automatic variable, and an assertion fails if it is an automatic variable (if asserts are enabled). ret_code_t nrf_drv_adc_init | ( | nrf_drv_adc_config_t const * | p_config, |
nrf_drv_adc_event_handler_t | event_handler | ||
) |
Function for initializing the ADC.
If a valid event handler is provided, the driver is initialized in non-blocking mode. If event_handler is NULL, the driver works in blocking mode.
[in] | p_config | Driver configuration. |
[in] | event_handler | Event handler provided by the user. |
NRF_SUCCESS | If initialization was successful. |
NRF_ERROR_INVALID_STATE | If the driver is already initialized. |
bool nrf_drv_adc_is_busy | ( | void | ) |
Function for retrieving the ADC state.
true | If the ADC is busy. |
false | If the ADC is ready. |
void nrf_drv_adc_sample | ( | void | ) |
Function for starting ADC sampling.
This function triggers single ADC sampling. If more than one channel is enabled, the driver emulates scanning and all channels are sampled in the order they were enabled.
ret_code_t nrf_drv_adc_sample_convert | ( | nrf_drv_adc_channel_t const *const | p_channel, |
nrf_adc_value_t * | p_value | ||
) |
Function for executing a single ADC conversion.
This function selects the desired input and starts a single conversion. If a valid pointer is provided for the result, the function blocks until the conversion is completed. Otherwise, the function returns when the conversion is started, and the result is provided in an event (driver must be initialized in non-blocking mode otherwise an assertion will fail). The function will fail if ADC is busy. The channel does not need to be enabled to perform a single conversion.
[in] | p_channel | Channel. |
[out] | p_value | Pointer to the location where the result should be placed. Unless NULL is provided, the function is blocking. |
NRF_SUCCESS | If conversion was successful. |
NRF_ERROR_BUSY | If the ADC driver is busy. |
__STATIC_INLINE uint32_t nrf_drv_adc_start_task_get | ( | void | ) |
Function for getting the address of the ADC START task.
This function is used to get the address of the START task, which can be used to trigger ADC conversion.
void nrf_drv_adc_uninit | ( | void | ) |
Function for uninitializing the ADC.
This function stops all ongoing conversions and disables all channels.