mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-21 18:57:16 +08:00
feat[ADC]: 新增 ADC V2 驱动支持 (#11440)
* feat[ADC V2]: add ADC V2 driver support add ADC V2 core APIs, session state management, and sequence read support add STM32 ADC V2 HAL backend with internal-channel and VREF handling add per-series STM32 ADC V2 default configuration headers wire ADC V2 Kconfig and SConscript integration for components and STM32 BSP drivers keep ADC V2 mutually exclusive with the legacy ADC driver path * feat[ADC V2]: add ADC V2 MSH special channel read support add generic ADC V2 MSH commands for probing, configuring, raw reads, voltage reads, and sequence reads add STM32 ADC V2 backend special commands for VREFINT, temperature sensor, and VBAT reads add STM32 helper APIs for special logical channels, sampling time, resolution, and temperature calculation wire ADC V2 MSH sources through Kconfig and SConscript * feat[ADC V2]: add ADC V2 stream DMA support add ADC V2 stream APIs with latest-frame and FIFO buffering policies wire STM32 ADC V2 to circular DMA stream mode with per-instance Kconfig options extend STM32 ADC config headers and DMA helpers for stream DMA configuration add FinSH stream commands for start, read, cancel, and stop operations handle Cortex-M7 cache-safe DMA buffers for STM32 stream sampling * feat[ADC V2]: add timer trigger support for ADC V2 streams add ADC V2 trigger configuration, validation, and lifecycle coordination add timer update trigger support through clock timer TRGO controls map STM32 ADC V2 timer update triggers to HAL external trigger selector fields add Kconfig, SConscript, and MSH entries for ADC trigger setup and inspection * feat[ADCV2]: add timer and comparator trigger selectors add ADC V2 timer compare and analog comparator trigger configuration support extend clock timer trigger config with compare event and channel fields wire STM32 ADC external trigger selector mappings for TIM update, TIM compare, and COMP output add FinSH trigger_set commands and Kconfig switches for timer and comparator trigger backends * fix[ADC V2]: resolve ADC V1 compatibility Kconfig loop * ci[ADC V2][stm32]: add ADC v2 peripheral config for stm32f407-rt-spark BSP
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2026, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2026-05-20 wdfk-prog add ADC V2 trigger declarations
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file adc_v2_trigger.h
|
||||
* @brief ADC V2 trigger framework declarations.
|
||||
*/
|
||||
|
||||
#ifndef __ADC_V2_TRIGGER_H__
|
||||
#define __ADC_V2_TRIGGER_H__
|
||||
|
||||
#include <rtconfig.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if defined(RT_ADC_USING_TRIGGER)
|
||||
struct rt_adc_device;
|
||||
struct rt_device;
|
||||
|
||||
/**
|
||||
* @brief ADC hardware trigger event type.
|
||||
*
|
||||
* @note A platform backend may support only part of these trigger types.
|
||||
* Unsupported trigger types shall be rejected by the framework or backend
|
||||
* with an error such as -RT_ENOSYS.
|
||||
*/
|
||||
enum rt_adc_trigger_type
|
||||
{
|
||||
RT_ADC_TRIGGER_TIMER_UPDATE = 0, /**< Use a timer update/TRGO event. */
|
||||
RT_ADC_TRIGGER_TIMER_COMPARE, /**< Use a timer compare event. */
|
||||
RT_ADC_TRIGGER_PWM_EDGE, /**< Use a PWM edge event. */
|
||||
RT_ADC_TRIGGER_EXTI_EDGE, /**< Use an external interrupt edge event. */
|
||||
RT_ADC_TRIGGER_ANALOG_COMPARE, /**< Use an analog comparator event. */
|
||||
RT_ADC_TRIGGER_BACKEND, /**< Use a backend-specific trigger event. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief ADC trigger edge selector.
|
||||
*/
|
||||
enum rt_adc_trigger_edge
|
||||
{
|
||||
RT_ADC_TRIGGER_EDGE_NONE = 0, /**< No edge selection is required. */
|
||||
RT_ADC_TRIGGER_EDGE_RISING, /**< Use the rising edge. */
|
||||
RT_ADC_TRIGGER_EDGE_FALLING, /**< Use the falling edge. */
|
||||
RT_ADC_TRIGGER_EDGE_BOTH, /**< Use both rising and falling edges. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Timer-based ADC trigger event.
|
||||
*/
|
||||
struct rt_adc_trigger_timer_event
|
||||
{
|
||||
struct rt_device *timer; /**< Timer device used as trigger source. */
|
||||
rt_uint32_t freq_hz; /**< Timer trigger output frequency in hertz. */
|
||||
rt_uint16_t channel; /**< Timer channel, or 0 for update/TRGO event. */
|
||||
rt_uint16_t reserved; /**< Reserved for future extension. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief PWM-based ADC trigger event.
|
||||
*/
|
||||
struct rt_adc_trigger_pwm_event
|
||||
{
|
||||
struct rt_device *pwm; /**< PWM device used as trigger source. */
|
||||
rt_uint16_t channel; /**< PWM channel. */
|
||||
enum rt_adc_trigger_edge edge; /**< PWM edge used as trigger event. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief External interrupt ADC trigger event.
|
||||
*/
|
||||
struct rt_adc_trigger_exti_event
|
||||
{
|
||||
struct rt_device *pin; /**< Pin or GPIO controller device. */
|
||||
rt_uint16_t line; /**< External interrupt line or pin number. */
|
||||
enum rt_adc_trigger_edge edge; /**< Interrupt edge used as trigger event. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Analog comparator ADC trigger event.
|
||||
*/
|
||||
struct rt_adc_trigger_compare_event
|
||||
{
|
||||
struct rt_device *comparator; /**< Optional comparator device used as trigger source. */
|
||||
rt_uint16_t channel; /**< Comparator channel or instance index. */
|
||||
enum rt_adc_trigger_edge edge; /**< Comparator output edge used as trigger event. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Backend-specific ADC trigger event.
|
||||
*/
|
||||
struct rt_adc_trigger_backend_event
|
||||
{
|
||||
rt_uint32_t selector; /**< Backend-specific trigger selector. */
|
||||
rt_uint32_t edge; /**< Backend-specific edge selector. */
|
||||
const void *data; /**< Optional backend-specific configuration. */
|
||||
rt_size_t data_size; /**< Size of backend-specific configuration. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief ADC trigger configuration.
|
||||
*/
|
||||
struct rt_adc_trigger_cfg
|
||||
{
|
||||
enum rt_adc_trigger_type type; /**< Trigger event type. */
|
||||
rt_uint32_t flags; /**< Common trigger flags, reserved for future extension. */
|
||||
|
||||
union
|
||||
{
|
||||
struct rt_adc_trigger_timer_event timer; /**< Timer trigger event. */
|
||||
struct rt_adc_trigger_pwm_event pwm; /**< PWM trigger event. */
|
||||
struct rt_adc_trigger_exti_event exti; /**< External interrupt trigger event. */
|
||||
struct rt_adc_trigger_compare_event compare; /**< Comparator trigger event. */
|
||||
struct rt_adc_trigger_backend_event backend; /**< Backend-specific trigger event. */
|
||||
} event; /**< Trigger event payload. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief ADC trigger runtime control block.
|
||||
*/
|
||||
struct rt_adc_trigger_ctrl
|
||||
{
|
||||
struct rt_adc_trigger_cfg cfg; /**< Cached device-level hardware trigger configuration. */
|
||||
rt_bool_t configured; /**< Whether cfg contains a cached hardware trigger request. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Set one device-level ADC hardware trigger request.
|
||||
* @param device Pointer to the ADC device object.
|
||||
* @param cfg Pointer to the ADC trigger configuration object.
|
||||
* @return Operation status.
|
||||
* @note This function only checks the framework-level trigger structure and
|
||||
* caches the request. It does not write ADC trigger registers immediately.
|
||||
* Backend compatibility is reported when the cached trigger is
|
||||
* preconfigured before a conversion hardware configuration.
|
||||
*/
|
||||
rt_err_t rt_adc_trigger_set(struct rt_adc_device *device, const struct rt_adc_trigger_cfg *cfg);
|
||||
|
||||
/**
|
||||
* @brief Clear the cached device-level ADC hardware trigger request.
|
||||
* @param device Pointer to the ADC device object.
|
||||
* @return Operation status.
|
||||
* @note This function does not write ADC trigger registers immediately. The
|
||||
* next conversion hardware configuration preconfigures the backend
|
||||
* software/default trigger state.
|
||||
*/
|
||||
rt_err_t rt_adc_trigger_clear(struct rt_adc_device *device);
|
||||
|
||||
/**
|
||||
* @brief Check whether one ADC device has a cached hardware trigger request.
|
||||
* @param device Pointer to the ADC device object.
|
||||
* @return RT_TRUE if a hardware trigger request is set, otherwise RT_FALSE.
|
||||
*/
|
||||
rt_bool_t rt_adc_trigger_is_set(struct rt_adc_device *device);
|
||||
#endif /* defined(RT_ADC_USING_TRIGGER) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ADC_V2_TRIGGER_H__ */
|
||||
@@ -47,9 +47,41 @@ typedef enum
|
||||
CLOCK_TIMER_CTRL_FREQ_SET = RT_DEVICE_CTRL_BASE(Timer) + 0x01,
|
||||
CLOCK_TIMER_CTRL_STOP = RT_DEVICE_CTRL_BASE(Timer) + 0x02,
|
||||
CLOCK_TIMER_CTRL_INFO_GET = RT_DEVICE_CTRL_BASE(Timer) + 0x03,
|
||||
CLOCK_TIMER_CTRL_MODE_SET = RT_DEVICE_CTRL_BASE(Timer) + 0x04
|
||||
CLOCK_TIMER_CTRL_MODE_SET = RT_DEVICE_CTRL_BASE(Timer) + 0x04,
|
||||
#if defined(RT_USING_CLOCK_TIMER_TRIGGER)
|
||||
CLOCK_TIMER_CTRL_TRIGGER_CONFIG = RT_DEVICE_CTRL_BASE(Timer) + 0x05,
|
||||
CLOCK_TIMER_CTRL_TRIGGER_START = RT_DEVICE_CTRL_BASE(Timer) + 0x06,
|
||||
CLOCK_TIMER_CTRL_TRIGGER_STOP = RT_DEVICE_CTRL_BASE(Timer) + 0x07,
|
||||
CLOCK_TIMER_CTRL_TRIGGER_RELEASE = RT_DEVICE_CTRL_BASE(Timer) + 0x08
|
||||
#endif /* defined(RT_USING_CLOCK_TIMER_TRIGGER) */
|
||||
} rt_clock_timer_ctrl_t;
|
||||
|
||||
#if defined(RT_USING_CLOCK_TIMER_TRIGGER)
|
||||
/**
|
||||
* @brief Hardware timer trigger output event type.
|
||||
*/
|
||||
enum rt_clock_timer_trigger_event
|
||||
{
|
||||
CLOCK_TIMER_TRIGGER_EVENT_UPDATE = 0, /**< Generate trigger on timer update/overflow event. */
|
||||
CLOCK_TIMER_TRIGGER_EVENT_COMPARE, /**< Generate trigger on timer compare match event. */
|
||||
CLOCK_TIMER_TRIGGER_EVENT_PWM_EDGE, /**< Generate trigger on timer PWM output reference edge. */
|
||||
CLOCK_TIMER_TRIGGER_EVENT_BACKEND /**< Generate trigger from a backend-specific timer event. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Hardware trigger output configuration.
|
||||
* @note This interface does not arbitrate timer ownership. Callers must
|
||||
* provide a timer dedicated to hardware trigger output.
|
||||
*/
|
||||
struct rt_clock_timer_trigger_cfg
|
||||
{
|
||||
rt_uint32_t freq_hz; /**< Trigger output frequency in hertz. */
|
||||
enum rt_clock_timer_trigger_event event; /**< Timer event used as trigger output. */
|
||||
rt_uint16_t channel; /**< Timer compare channel, or 0 for update event. */
|
||||
rt_uint16_t reserved; /**< Reserved for future extension. */
|
||||
};
|
||||
#endif /* defined(RT_USING_CLOCK_TIMER_TRIGGER) */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CLOCK_TIMER_MODE_ONESHOT = 0x01,
|
||||
|
||||
@@ -272,9 +272,11 @@ extern "C" {
|
||||
#include "drivers/dev_audio.h"
|
||||
#endif /* RT_USING_AUDIO */
|
||||
|
||||
#ifdef RT_USING_ADC
|
||||
#ifdef RT_USING_ADC_V2
|
||||
#include "drivers/adc_v2.h"
|
||||
#elif defined(RT_USING_ADC)
|
||||
#include "drivers/adc.h"
|
||||
#endif /* RT_USING_ADC */
|
||||
#endif /* RT_USING_ADC_V2 */
|
||||
|
||||
#ifdef RT_USING_DAC
|
||||
#include "drivers/dac.h"
|
||||
|
||||
Reference in New Issue
Block a user