![]() |
RT-Thread RTOS
An open source embedded real-time operating system
|
#include <rtconfig.h>#include "misc.h"#include <rtatomic.h>#include <rtdevice.h>#include <rtthread.h>
Include dependency graph for adc_v2.h:Data Structures | |
| struct | rt_adc_core_ops |
| struct | rt_adc_sequence_ops |
| struct | rt_adc_ops |
| struct | rt_adc_sequence_cfg |
| struct | rt_adc_session_ctrl |
| struct | rt_adc_device |
Macros | |
| #define | RT_ADC_CHANNEL_MASK(_channel) (1UL << (rt_uint32_t)(_channel)) |
Enumerations | |
| enum | rt_adc_control_cmd { RT_ADC_CMD_GET_RESOLUTION = RT_DEVICE_CTRL_BASE(ADC) + 1 , RT_ADC_CMD_CALIBRATE , RT_ADC_CMD_SET_VREF , RT_ADC_CMD_CALC_VREF , RT_ADC_CMD_GET_VREF_CHANNEL , RT_ADC_CMD_SET_SESSION , RT_ADC_CMD_SET_CONFIG , RT_ADC_CMD_GET_CONFIG , RT_ADC_CMD_CLEAR_CHANNEL_CONFIG } |
| enum | rt_adc_input_mode { RT_ADC_INPUT_MODE_SINGLE_ENDED = 0x01U , RT_ADC_INPUT_MODE_DIFFERENTIAL = 0x02U } |
| enum | rt_adc_state { RT_ADC_STATE_IDLE = 0 , RT_ADC_STATE_LOCKED , RT_ADC_STATE_STREAM } |
Functions | |
| rt_inline rt_size_t | rt_adc_channel_mask_count (rt_uint32_t channels) |
| rt_inline rt_uint8_t | rt_adc_channel_mask_take_lsb (rt_uint32_t *channels) |
| rt_err_t | rt_hw_adc_register (rt_adc_device_t device, const char *name, const struct rt_adc_ops *ops, const void *user_data) |
| rt_err_t | rt_adc_session_channel_index (rt_uint32_t session_channels, rt_uint32_t channel, rt_size_t *index) |
| rt_err_t | rt_adc_read_sequence (rt_adc_device_t device, rt_uint32_t channels, const struct rt_adc_sequence_cfg *cfg, rt_size_t *read_count) |
| rt_err_t | rt_adc_raw_to_voltage_mv (rt_uint32_t raw_value, rt_uint32_t vref_mv, rt_uint8_t resolution_bits, rt_uint32_t *voltage_mv) |
| rt_err_t | rt_adc_raw_to_scaled_voltage_mv (rt_uint32_t raw_value, rt_uint32_t vref_mv, rt_uint8_t resolution_bits, rt_uint32_t scale_num, rt_uint32_t scale_den, rt_uint32_t *voltage_mv) |
| rt_err_t | rt_adc_voltage (rt_adc_device_t device, rt_uint32_t *voltages_mv, rt_size_t size, rt_int32_t timeout_ms) |
Standalone ADC V2 framework declarations.
| #define RT_ADC_CHANNEL_MASK | ( | _channel | ) | (1UL << (rt_uint32_t)(_channel)) |
Build an ADC channel mask from one logical channel index.
| _channel | Logical ADC channel index. |
| enum rt_adc_control_cmd |
ADC control command identifiers.
| enum rt_adc_input_mode |
| enum rt_adc_state |
| rt_inline rt_size_t rt_adc_channel_mask_count | ( | rt_uint32_t | channels | ) |
Count selected ADC channels in one channel mask.
| channels | ADC channel selection mask. |
| rt_inline rt_uint8_t rt_adc_channel_mask_take_lsb | ( | rt_uint32_t * | channels | ) |
Take the lowest selected ADC channel from one channel mask.
| channels | Pointer to the ADC channel selection mask. |
| rt_err_t rt_hw_adc_register | ( | rt_adc_device_t | device, |
| const char * | name, | ||
| const struct rt_adc_ops * | ops, | ||
| const void * | user_data | ||
| ) |
Register an ADC device with the RT-Thread device framework.
| device | Pointer to the ADC device object. |
| name | Pointer to the ADC device name string. |
| ops | Pointer to the ADC driver operation table. |
| user_data | Pointer to driver private data. |
| rt_err_t rt_adc_session_channel_index | ( | rt_uint32_t | session_channels, |
| rt_uint32_t | channel, | ||
| rt_size_t * | index | ||
| ) |
Get the raw sample index of one channel in an ADC session mask.
| session_channels | Configured ADC session channel mask. |
| channel | Single-channel mask to locate. |
| index | Pointer to the output raw sample index. |
| rt_err_t rt_adc_read_sequence | ( | rt_adc_device_t | device, |
| rt_uint32_t | channels, | ||
| const struct rt_adc_sequence_cfg * | cfg, | ||
| rt_size_t * | read_count | ||
| ) |
Read one ADC conversion sequence frame.
| device | Pointer to the ADC device object. |
| channels | ADC channel selection mask. |
| cfg | Pointer to the ADC sequence request object. |
| read_count | Pointer to the stored sample count. |
| rt_err_t rt_adc_raw_to_voltage_mv | ( | rt_uint32_t | raw_value, |
| rt_uint32_t | vref_mv, | ||
| rt_uint8_t | resolution_bits, | ||
| rt_uint32_t * | voltage_mv | ||
| ) |
Convert one raw ADC sample to millivolts.
| raw_value | Raw ADC sample value. |
| vref_mv | ADC reference voltage in millivolts. |
| resolution_bits | ADC resolution in bits. |
| voltage_mv | Pointer to the output voltage in millivolts. |
| rt_err_t rt_adc_raw_to_scaled_voltage_mv | ( | rt_uint32_t | raw_value, |
| rt_uint32_t | vref_mv, | ||
| rt_uint8_t | resolution_bits, | ||
| rt_uint32_t | scale_num, | ||
| rt_uint32_t | scale_den, | ||
| rt_uint32_t * | voltage_mv | ||
| ) |
Convert one ADC raw sample to a scaled voltage in millivolts.
| raw_value | Raw ADC sample code. |
| vref_mv | ADC reference voltage in millivolts. |
| resolution_bits | ADC resolution in bits. |
| scale_num | Voltage scaling numerator. |
| scale_den | Voltage scaling denominator. |
| voltage_mv | Pointer to the output scaled voltage in millivolts. |
The scaled voltage is calculated as:
raw_to_voltage_mv(raw_value) * scale_num / scale_den
scale_num and scale_den may describe any positive rational scaling ratio that does not overflow the internal calculation. The final scaled millivolt value must fit in rt_uint32_t.| RT_EOK | The conversion completed successfully. |
| -RT_EINVAL | A pointer is null, a scale argument is zero, the ADC conversion arguments are invalid, or the scaled result overflows rt_uint32_t. |
| rt_err_t rt_adc_voltage | ( | rt_adc_device_t | device, |
| rt_uint32_t * | voltages_mv, | ||
| rt_size_t | size, | ||
| rt_int32_t | timeout_ms | ||
| ) |
Read ADC samples and convert them to millivolts.
| device | Pointer to the ADC device object. |
| voltages_mv | Pointer to the output voltage buffer in millivolts. |
| size | Output voltage buffer length. |
| timeout_ms | Per-sample timeout in milliseconds; negative means wait forever. |