ADC Hardware Abstraction Layer API Reference.
More...
◆ hal_adc_close()
err_t hal_adc_close |
( |
handle_t * | handle | ) |
|
Closes ADC HAL layer object, clears all buffers used by object and clears config.
- Parameters
-
[in,out] | handle | ADC handle. |
- Returns
- Nothing.
Example
err_t hal_adc_close(handle_t *handle)
Close ADC HAL layer object.
◆ hal_adc_configure_default()
Configures ADC configuration structure to default initialization values. Take into consideration that this is just structure variable initial values setting. Values need to be redefined by user.
- Parameters
-
[in,out] | config | ADC HAL layer configuration settings. See hal_adc_config_t structure definition for detailed explanation. |
Default values:
Function | Default value |
Input pin | HAL_PIN_NC (invalid pin) |
Resolution | 12 bit |
Vref input | External voltage reference source |
Vref value | -1 (invalid reference voltage value) |
- Returns
- Nothing.
Example
void hal_adc_configure_default(hal_adc_config_t *config)
Configure ADC HAL configuration structure..
ADC HAL initialization configuration structure, consisted of the following fields :
Definition hal_adc.h:134
◆ hal_adc_open()
err_t hal_adc_open |
( |
handle_t * | handle, |
|
|
bool | hal_obj_open_state ) |
Function allocates memory needed for ADC HAL and pin for specified object.
- Parameters
-
[in,out] | handle | ADC handle. |
[in] | hal_obj_open_state | ADC state, is it open or not. |
- Returns
- The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
Example
adc_configure_default( &hal_adc_cfg );
hal_adc_cfg.
pin. = MIKROBUS_1_AN;
err_t hal_adc_open(handle_t *handle, bool hal_obj_open_state)
Open the ADC HAL layer object on selected pin.
hal_pin_name_t pin
Definition hal_adc.h:135
ADC HAL context structure, consisted of the following fields :
Definition hal_adc.h:152
handle_t handle
Definition hal_adc.h:153
◆ hal_adc_read()
err_t hal_adc_read |
( |
handle_t * | handle, |
|
|
uint16_t * | readDatabuf ) |
- Parameters
-
[in] | handle | ADC handle. |
[out] | readDatabuf | Data buffer to place read data in. |
- Returns
- The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
- Precondition
- Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.
Example
err_t hal_adc_read(handle_t *handle, uint16_t *readDatabuf)
Read analog value on pin.
◆ hal_adc_read_voltage()
err_t hal_adc_read_voltage |
( |
handle_t * | handle, |
|
|
float * | readDatabuf ) |
- Parameters
-
[in] | handle | ADC handle. |
[out] | readDatabuf | Data buffer to place read data in. |
- Returns
- The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
- Precondition
- Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.
Example
err_t hal_adc_read_voltage(handle_t *handle, float *readDatabuf)
Read analog voltage value on pin.
◆ hal_adc_set_resolution()
Initializes ADC HAL on the hardware level and sets sample resolution to specified config->resolution
value.
- Parameters
-
[in] | handle | ADC handle. |
[in] | config | ADC HAL configuration structure. See hal_adc_config_t structure definition for detailed explanation. |
- Returns
- The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
- Precondition
- Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.
- Warning
- If desired resolution can not be achieved, error will be returned. Make sure to poll the return value in your code.
Example
err_t hal_adc_set_resolution(handle_t *handle, hal_adc_config_t *config)
Set ADC HAL sample resolution.
◆ hal_adc_set_vref_input()
Initializes ADC HAL on the hardware level and sets sample reference voltage source to specified config->vref_input
value.
- Parameters
-
[in] | handle | ADC handle. |
[in] | config | ADC HAL configuration structure. See hal_adc_config_t structure definition for detailed explanation. |
- Returns
- The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
- Precondition
- Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.
- Warning
- If desired reference voltage source can not be achieved, error will be returned. Make sure to poll the return value in your code.
Example
err_t hal_adc_set_vref_input(handle_t *handle, hal_adc_config_t *config)
Set ADC HAL reference voltage source to desired value.
◆ hal_adc_set_vref_value()
Sets sample reference voltage value to specified config->vref_value
value used later for calculating voltage.
- Parameters
-
[in] | handle | ADC handle. |
[in] | config | ADC HAL configuration structure. See hal_adc_config_t structure definition for detailed explanation. |
- Returns
- Nothing.
- Precondition
- Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.
- Warning
- If desired reference voltage value is not set, calculated voltage value on AN pin will be wrong.
Example
void hal_adc_set_vref_value(handle_t *handle, hal_adc_config_t *config)
Set ADC HAL reference voltage value to desired value.