From 26ed8c9062f0a549507938ec525460f8c10b8acc Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio <gdisirio@gmail.com> Date: Sun, 9 Dec 2018 13:03:19 +0000 Subject: ADC reworked. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12467 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- os/hal/include/hal_adc.h | 121 +++++++++++ os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.h | 190 +++++------------ os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h | 219 +++++--------------- os/hal/ports/STM32/LLD/ADCv3/hal_adc_lld.h | 266 +++++++++--------------- os/hal/ports/STM32/STM32F1xx/hal_adc_lld.h | 191 ++++------------- os/hal/ports/STM32/STM32F37x/hal_adc_lld.h | 319 ++++++++++++----------------- os/hal/ports/STM32/STM32L1xx/hal_adc_lld.h | 217 +++++--------------- os/hal/templates/hal_adc_lld.h | 107 +--------- 8 files changed, 555 insertions(+), 1075 deletions(-) (limited to 'os') diff --git a/os/hal/include/hal_adc.h b/os/hal/include/hal_adc.h index c08c77f5a..8ccc8241e 100644 --- a/os/hal/include/hal_adc.h +++ b/os/hal/include/hal_adc.h @@ -76,8 +76,129 @@ typedef enum { ADC_ERROR = 5 /**< Conversion error. */ } adcstate_t; +/** + * @brief Type of a structure representing an ADC driver. + */ +typedef struct hal_adc_driver ADCDriver; + +/** + * @brief Type of a structure representing an ADC driver configuration. + */ +typedef struct hal_adc_config ADCConfig; + +/** + * @brief Conversion group configuration structure. + * @details This implementation-dependent structure describes a conversion + * operation. + * @note The use of this configuration structure requires knowledge of + * STM32 ADC cell registers interface, please refer to the STM32 + * reference manual for details. + */ +typedef struct hal_adc_configuration_group ADCConversionGroup; + +/* Including the low level driver header, it exports information required + for completing types.*/ #include "hal_adc_lld.h" +/** + * @brief Type of an ADC notification callback. + * + * @param[in] adcp pointer to the @p ADCDriver object triggering the + * callback + * @param[in] buffer pointer to the most recent samples data + * @param[in] n number of buffer rows available starting from @p buffer + */ +typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n); + +/** + * @brief Type of an ADC error callback. + * + * @param[in] adcp pointer to the @p ADCDriver object triggering the + * callback + * @param[in] err ADC error code + */ +typedef void (*adcerrorcallback_t)(ADCDriver *adcp, adcerror_t err); + +/** + * @brief Conversion group configuration structure. + * @details This implementation-dependent structure describes a conversion + * operation. + * @note The use of this configuration structure requires knowledge of + * STM32 ADC cell registers interface, please refer to the STM32 + * reference manual for details. + */ +struct hal_adc_configuration_group { + /** + * @brief Enables the circular buffer mode for the group. + */ + bool circular; + /** + * @brief Number of the analog channels belonging to the conversion group. + */ + adc_channels_num_t num_channels; + /** + * @brief Callback function associated to the group or @p NULL. + */ + adccallback_t end_cb; + /** + * @brief Error callback or @p NULL. + */ + adcerrorcallback_t error_cb; + /* End of the mandatory fields.*/ + adc_lld_configuration_group_fields; +}; + +/** + * @brief Driver configuration structure. + */ +struct hal_adc_config { + /* End of the mandatory fields.*/ + adc_lld_config_fields; +}; + +/** + * @brief Structure representing an ADC driver. + */ +struct hal_adc_driver { + /** + * @brief Driver state. + */ + adcstate_t state; + /** + * @brief Current configuration data. + */ + const ADCConfig *config; + /** + * @brief Current samples buffer pointer or @p NULL. + */ + adcsample_t *samples; + /** + * @brief Current samples buffer depth or @p 0. + */ + size_t depth; + /** + * @brief Current conversion group pointer or @p NULL. + */ + const ADCConversionGroup *grpp; +#if ADC_USE_WAIT || defined(__DOXYGEN__) + /** + * @brief Waiting thread. + */ + thread_reference_t thread; +#endif +#if ADC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) + /** + * @brief Mutex protecting the peripheral. + */ + mutex_t mutex; +#endif /* ADC_USE_MUTUAL_EXCLUSION */ +#if defined(ADC_DRIVER_EXT_FIELDS) + ADC_DRIVER_EXT_FIELDS +#endif + /* End of the mandatory fields.*/ + adc_lld_driver_fields; +}; + /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ diff --git a/os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.h b/os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.h index 2da8b80d8..ec33dd626 100644 --- a/os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.h +++ b/os/hal/ports/STM32/LLD/ADCv1/hal_adc_lld.h @@ -255,154 +255,70 @@ typedef enum { ADC_ERR_AWD = 2 /**< Analog watchdog triggered. */ } adcerror_t; -/** - * @brief Type of a structure representing an ADC driver. - */ -typedef struct ADCDriver ADCDriver; +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ /** - * @brief ADC notification callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] buffer pointer to the most recent samples data - * @param[in] n number of buffer rows available starting from @p buffer + * @brief Low level fields of the ADC driver structure. */ -typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n); +#define adc_lld_driver_fields \ + /* Pointer to the ADCx registers block.*/ \ + ADC_TypeDef *adc; \ + /* Pointer to associated DMA channel.*/ \ + const stm32_dma_stream_t *dmastp; \ + /* DMA mode bit mask.*/ \ + uint32_t dmamode /** - * @brief ADC error callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] err ADC error code + * @brief Low level fields of the ADC configuration structure. */ -typedef void (*adcerrorcallback_t)(ADCDriver *adcp, adcerror_t err); +#define adc_lld_config_fields \ + /* Dummy configuration, it is not needed.*/ \ + uint32_t dummy /** - * @brief Conversion group configuration structure. - * @details This implementation-dependent structure describes a conversion - * operation. - * @note The use of this configuration structure requires knowledge of - * STM32 ADC cell registers interface, please refer to the STM32 - * reference manual for details. + * @brief Low level fields of the ADC configuration structure. */ -typedef struct { - /** - * @brief Enables the circular buffer mode for the group. - */ - bool circular; - /** - * @brief Number of the analog channels belonging to the conversion group. - */ - adc_channels_num_t num_channels; - /** - * @brief Callback function associated to the group or @p NULL. - */ - adccallback_t end_cb; - /** - * @brief Error callback or @p NULL. - */ - adcerrorcallback_t error_cb; - /* End of the mandatory fields.*/ - /** - * @brief ADC CFGR1 register initialization data. - * @note The bits DMAEN and DMACFG are enforced internally - * to the driver, keep them to zero. - * @note The bits @p ADC_CFGR1_CONT or @p ADC_CFGR1_DISCEN must be - * specified in continuous more or if the buffer depth is - * greater than one. - */ - uint32_t cfgr1; #if (STM32_ADC_SUPPORTS_OVERSAMPLING == TRUE) || defined(__DOXYGEN__) - /** - * @brief ADC CFGR2 register initialization data. - * @note CKMODE bits must not be specified in this field and left to - * zero. - */ - uint32_t cfgr2; -#endif - /** - * @brief ADC TR register initialization data. - */ - uint32_t tr; - /** - * @brief ADC SMPR register initialization data. - */ - uint32_t smpr; - /** - * @brief ADC CHSELR register initialization data. - * @details The number of bits at logic level one in this register must - * be equal to the number in the @p num_channels field. - */ - uint32_t chselr; -} ADCConversionGroup; - -/** - * @brief Driver configuration structure. - * @note It could be empty on some architectures. - */ -typedef struct { - uint32_t dummy; -} ADCConfig; - -/** - * @brief Structure representing an ADC driver. - */ -struct ADCDriver { - /** - * @brief Driver state. - */ - adcstate_t state; - /** - * @brief Current configuration data. - */ - const ADCConfig *config; - /** - * @brief Current samples buffer pointer or @p NULL. - */ - adcsample_t *samples; - /** - * @brief Current samples buffer depth or @p 0. - */ - size_t depth; - /** - * @brief Current conversion group pointer or @p NULL. - */ - const ADCConversionGroup *grpp; -#if ADC_USE_WAIT || defined(__DOXYGEN__) - /** - * @brief Waiting thread. - */ - thread_reference_t thread; -#endif -#if ADC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) - /** - * @brief Mutex protecting the peripheral. - */ - mutex_t mutex; -#endif /* ADC_USE_MUTUAL_EXCLUSION */ -#if defined(ADC_DRIVER_EXT_FIELDS) - ADC_DRIVER_EXT_FIELDS +#define adc_lld_configuration_group_fields \ + /* ADC CFGR1 register initialization data. \ + NOTE: The bits DMAEN and DMACFG are enforced internally \ + to the driver, keep them to zero. \ + NOTE: The bits @p ADC_CFGR1_CONT or @p ADC_CFGR1_DISCEN must be \ + specified in continuous more or if the buffer depth is \ + greater than one.*/ \ + uint32_t cfgr1; \ + /* ADC CFGR2 register initialization data. \ + NOTE: CKMODE bits must not be specified in this field and left to \ + zero.*/ \ + uint32_t cfgr2; \ + /* ADC TR register initialization data.*/ \ + uint32_t tr; \ + /* ADC SMPR register initialization data.*/ \ + uint32_t smpr; \ + /* ADC CHSELR register initialization data. \ + NOTE: The number of bits at logic level one in this register must \ + be equal to the number in the @p num_channels field.*/ \ + uint32_t chselr +#else +#define adc_lld_configuration_group_fields \ + /* ADC CFGR1 register initialization data. \ + NOTE: The bits DMAEN and DMACFG are enforced internally \ + to the driver, keep them to zero. \ + NOTE: The bits @p ADC_CFGR1_CONT or @p ADC_CFGR1_DISCEN must be \ + specified in continuous more or if the buffer depth is \ + greater than one.*/ \ + uint32_t cfgr1; \ + /* ADC TR register initialization data.*/ \ + uint32_t tr; \ + /* ADC SMPR register initialization data.*/ \ + uint32_t smpr; \ + /* ADC CHSELR register initialization data. \ + NOTE: The number of bits at logic level one in this register must \ + be equal to the number in the @p num_channels field.*/ \ + uint32_t chselr #endif - /* End of the mandatory fields.*/ - /** - * @brief Pointer to the ADCx registers block. - */ - ADC_TypeDef *adc; - /** - * @brief Pointer to associated DMA channel. - */ - const stm32_dma_stream_t *dmastp; - /** - * @brief DMA mode bit mask. - */ - uint32_t dmamode; -}; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ /** * @brief Changes the value of the ADC CCR register. diff --git a/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h b/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h index 3fe808a8e..5202f946b 100644 --- a/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h +++ b/os/hal/ports/STM32/LLD/ADCv2/hal_adc_lld.h @@ -317,174 +317,65 @@ typedef enum { ADC_ERR_WATCHDOG = 2 /**< ADC watchdog condition. */ } adcerror_t; -/** - * @brief Type of a structure representing an ADC driver. - */ -typedef struct ADCDriver ADCDriver; - -/** - * @brief ADC notification callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] buffer pointer to the most recent samples data - * @param[in] n number of buffer rows available starting from @p buffer - */ -typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n); - -/** - * @brief ADC error callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] err ADC error code - */ -typedef void (*adcerrorcallback_t)(ADCDriver *adcp, adcerror_t err); - -/** - * @brief Conversion group configuration structure. - * @details This implementation-dependent structure describes a conversion - * operation. - * @note The use of this configuration structure requires knowledge of - * STM32 ADC cell registers interface, please refer to the STM32 - * reference manual for details. - */ -typedef struct { - /** - * @brief Enables the circular buffer mode for the group. - */ - bool circular; - /** - * @brief Number of the analog channels belonging to the conversion group. - */ - adc_channels_num_t num_channels; - /** - * @brief Callback function associated to the group or @p NULL. - */ - adccallback_t end_cb; - /** - * @brief Error callback or @p NULL. - */ - adcerrorcallback_t error_cb; - /* End of the mandatory fields.*/ - /** - * @brief ADC CR1 register initialization data. - * @note All the required bits must be defined into this field except - * @p ADC_CR1_SCAN that is enforced inside the driver. - */ - uint32_t cr1; - /** - * @brief ADC CR2 register initialization data. - * @note All the required bits must be defined into this field except - * @p ADC_CR2_DMA, @p ADC_CR2_CONT and @p ADC_CR2_ADON that are - * enforced inside the driver. - */ - uint32_t cr2; - /** - * @brief ADC SMPR1 register initialization data. - * @details In this field must be specified the sample times for channels - * 10...18. - */ - uint32_t smpr1; - /** - * @brief ADC SMPR2 register initialization data. - * @details In this field must be specified the sample times for channels - * 0...9. - */ - uint32_t smpr2; - /** - * @brief ADC watchdog high threshold register. - * @details This field defines the high threshold of the analog watchdog. - */ - uint16_t htr; - /** - * @brief ADC watchdog low threshold register. - * @details This field defines the low threshold of the analog watchdog. - */ - uint16_t ltr; - /** - * @brief ADC SQR1 register initialization data. - * @details Conversion group sequence 13...16 + sequence length. - */ - uint32_t sqr1; - /** - * @brief ADC SQR2 register initialization data. - * @details Conversion group sequence 7...12. - */ - uint32_t sqr2; - /** - * @brief ADC SQR3 register initialization data. - * @details Conversion group sequence 1...6. - */ - uint32_t sqr3; -} ADCConversionGroup; - -/** - * @brief Driver configuration structure. - * @note It could be empty on some architectures. - */ -typedef struct { - uint32_t dummy; -} ADCConfig; - -/** - * @brief Structure representing an ADC driver. - */ -struct ADCDriver { - /** - * @brief Driver state. - */ - adcstate_t state; - /** - * @brief Current configuration data. - */ - const ADCConfig *config; - /** - * @brief Current samples buffer pointer or @p NULL. - */ - adcsample_t *samples; - /** - * @brief Current samples buffer depth or @p 0. - */ - size_t depth; - /** - * @brief Current conversion group pointer or @p NULL. - */ - const ADCConversionGroup *grpp; -#if ADC_USE_WAIT || defined(__DOXYGEN__) - /** - * @brief Waiting thread. - */ - thread_reference_t thread; -#endif -#if ADC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) - /** - * @brief Mutex protecting the peripheral. - */ - mutex_t mutex; -#endif /* ADC_USE_MUTUAL_EXCLUSION */ -#if defined(ADC_DRIVER_EXT_FIELDS) - ADC_DRIVER_EXT_FIELDS -#endif - /* End of the mandatory fields.*/ - /** - * @brief Pointer to the ADCx registers block. - */ - ADC_TypeDef *adc; - /** - * @brief Pointer to associated DMA channel. - */ - const stm32_dma_stream_t *dmastp; - /** - * @brief DMA mode bit mask. - */ - uint32_t dmamode; -}; - /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ +/** + * @brief Low level fields of the ADC driver structure. + */ +#define adc_lld_driver_fields \ + /* Pointer to the ADCx registers block.*/ \ + ADC_TypeDef *adc; \ + /* Pointer to associated DMA channel.*/ \ + const stm32_dma_stream_t *dmastp; \ + /* DMA mode bit mask.*/ \ + uint32_t dmamode + +/** + * @brief Low level fields of the ADC configuration structure. + */ +#define adc_lld_config_fields \ + /* Dummy configuration, it is not needed.*/ \ + uint32_t dummy + +/** + * @brief Low level fields of the ADC configuration structure. + */ +#define adc_lld_configuration_group_fields \ + /* ADC CR1 register initialization data. \ + NOTE: All the required bits must be defined into this field except \ + @p ADC_CR1_SCAN that is enforced inside the driver.*/ \ + uint32_t cr1; \ + /* ADC CR2 register initialization data. \ + NOTE: All the required bits must be defined into this field except \ + @p ADC_CR2_DMA, @p ADC_CR2_CONT and @p ADC_CR2_ADON that are \ + enforced inside the driver.*/ \ + uint32_t cr2; \ + /* ADC SMPR1 register initialization data. \ + NOTE: In this field must be specified the sample times for channels \ + 10...18.*/ \ + uint32_t smpr1; \ + /* ADC SMPR2 register initialization data. \ + NOTE: In this field must be specified the sample times for channels \ + 0...9.*/ \ + uint32_t smpr2; \ + /* ADC watchdog high threshold register. \ + NOTE: This field defines the high threshold of the analog watchdog.*/ \ + uint16_t htr; \ + /* ADC watchdog low threshold register. \ + NOTE: This field defines the low threshold of the analog watchdog.*/ \ + uint16_t ltr; \ + /* ADC SQR1 register initialization data. \ + NOTE: Conversion group sequence 13...16 + sequence length.*/ \ + uint32_t sqr1; \ + /* ADC SQR2 register initialization data. \ + NOTE: Conversion group sequence 7...12.*/ \ + uint32_t sqr2; \ + /* ADC SQR3 register initialization data. \ + NOTE: Conversion group sequence 1...6.*/ \ + uint32_t sqr3 + /** * @name Sequences building helper macros * @{ diff --git a/os/hal/ports/STM32/LLD/ADCv3/hal_adc_lld.h b/os/hal/ports/STM32/LLD/ADCv3/hal_adc_lld.h index 149ef22cf..341fb7687 100644 --- a/os/hal/ports/STM32/LLD/ADCv3/hal_adc_lld.h +++ b/os/hal/ports/STM32/LLD/ADCv3/hal_adc_lld.h @@ -659,186 +659,106 @@ typedef enum { ADC_ERR_AWD3 = 4 /**< Watchdog 3 triggered. */ } adcerror_t; +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + /** - * @brief Type of a structure representing an ADC driver. - */ -typedef struct ADCDriver ADCDriver; + * @brief Low level fields of the ADC driver structure. + */ +#if (STM32_ADC_DUAL_MODE == TRUE) || defined(__DOXYGEN__) +#define adc_lld_driver_fields \ + /* Pointer to the master ADCx registers block.*/ \ + ADC_TypeDef *adcm; \ + /* Pointer to the slave ADCx registers block.*/ \ + ADC_TypeDef *adcs; \ + /* Pointer to the common ADCx_y registers block.*/ \ + ADC_Common_TypeDef *adcc; \ + /* Pointer to associated DMA channel.*/ \ + const stm32_dma_stream_t *dmastp; \ + /* DMA mode bit mask.*/ \ + uint32_t dmamode +#else +#define adc_lld_driver_fields \ + /* Pointer to the master ADCx registers block.*/ \ + ADC_TypeDef *adcm; \ + /* Pointer to the slave ADCx registers block.*/ \ + ADC_Common_TypeDef *adcc; \ + /* Pointer to associated DMA channel.*/ \ + const stm32_dma_stream_t *dmastp; \ + /* DMA mode bit mask.*/ \ + uint32_t dmamode +#endif /** - * @brief ADC notification callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] buffer pointer to the most recent samples data - * @param[in] n number of buffer rows available starting from @p buffer + * @brief Low level fields of the ADC configuration structure. */ -typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n); +#define adc_lld_config_fields \ + /* ADC DIFSEL register initialization data.*/ \ + uint32_t difsel /** - * @brief ADC error callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] err ADC error code - */ -typedef void (*adcerrorcallback_t)(ADCDriver *adcp, adcerror_t err); - -/** - * @brief Conversion group configuration structure. - * @details This implementation-dependent structure describes a conversion - * operation. - * @note The use of this configuration structure requires knowledge of - * STM32 ADC cell registers interface, please refer to the STM32 - * reference manual for details. - */ -typedef struct { - /** - * @brief Enables the circular buffer mode for the group. - */ - bool circular; - /** - * @brief Number of the analog channels belonging to the conversion group. - */ - adc_channels_num_t num_channels; - /** - * @brief Callback function associated to the group or @p NULL. - */ - adccallback_t end_cb; - /** - * @brief Error callback or @p NULL. - */ - adcerrorcallback_t error_cb; - /* End of the mandatory fields.*/ - /** - * @brief ADC CFGR register initialization data. - * @note The bits DMAEN and DMACFG are enforced internally - * to the driver, keep them to zero. - * @note The bits @p ADC_CFGR_CONT or @p ADC_CFGR_DISCEN must be - * specified in continuous mode or if the buffer depth is - * greater than one. - */ - uint32_t cfgr; + * @brief Low level fields of the ADC group configuration structure. + */ #if (STM32_ADCV3_OVERSAMPLING == TRUE) || defined(__DOXYGEN__) - /** - * @brief ADC CFGR2 register initialization data. - * @note The bits DMAEN and DMACFG are enforced internally - * to the driver, keep them to zero. - * @note The bits @p ADC_CFGR_CONT or @p ADC_CFGR_DISCEN must be - * specified in continuous mode or if the buffer depth is - * greater than one. - */ - uint32_t cfgr2; -#endif - /** - * @brief ADC TR1 register initialization data. - */ - uint32_t tr1; -#if STM32_ADC_DUAL_MODE || defined(__DOXYGEN__) - /** - * @brief ADC CCR register initialization data. - * @note Put this field to zero if not using oversampling. - */ - uint32_t ccr; -#endif - /** - * @brief ADC SMPRx registers initialization data. - */ - uint32_t smpr[2]; - /** - * @brief ADC SQRx register initialization data. - */ - uint32_t sqr[4]; -#if STM32_ADC_DUAL_MODE || defined(__DOXYGEN__) - /** - * @brief Slave ADC SMPRx registers initialization data. - * @note This field is only present in dual mode. - */ - uint32_t ssmpr[2]; - /** - * @brief Slave ADC SQRx register initialization data. - * @note This field is only present in dual mode. - */ - uint32_t ssqr[4]; -#endif /* STM32_ADC_DUAL_MODE */ -} ADCConversionGroup; - -/** - * @brief Driver configuration structure. - */ -typedef struct { - /** - * @brief ADC DIFSEL register initialization data. - */ - uint32_t difsel; -} ADCConfig; - -/** - * @brief Structure representing an ADC driver. - */ -struct ADCDriver { - /** - * @brief Driver state. - */ - adcstate_t state; - /** - * @brief Current configuration data. - */ - const ADCConfig *config; - /** - * @brief Current samples buffer pointer or @p NULL. - */ - adcsample_t *samples; - /** - * @brief Current samples buffer depth or @p 0. - */ - size_t depth; - /** - * @brief Current conversion group pointer or @p NULL. - */ - const ADCConversionGroup *grpp; -#if ADC_USE_WAIT || defined(__DOXYGEN__) - /** - * @brief Waiting thread. - */ - thread_reference_t thread; -#endif -#if ADC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) - /** - * @brief Mutex protecting the peripheral. - */ - mutex_t mutex; -#endif /* ADC_USE_MUTUAL_EXCLUSION */ -#if defined(ADC_DRIVER_EXT_FIELDS) - ADC_DRIVER_EXT_FIELDS -#endif - /* End of the mandatory fields.*/ - /** - * @brief Pointer to the master ADCx registers block. - */ - ADC_TypeDef *adcm; -#if STM32_ADC_DUAL_MODE || defined(__DOXYGEN__) - /** - * @brief Pointer to the slave ADCx registers block. - */ - ADC_TypeDef *adcs; -#endif /* STM32_ADC_DUAL_MODE */ - /** - * @brief Pointer to the common ADCx_y registers block. - */ - ADC_Common_TypeDef *adcc; - /** - * @brief Pointer to associated DMA channel. - */ - const stm32_dma_stream_t *dmastp; - /** - * @brief DMA mode bit mask. - */ - uint32_t dmamode; -}; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ +#if (STM32_ADC_DUAL_MODE == TRUE) || defined(__DOXYGEN__) +#define adc_lld_configuration_group_fields \ + /* ADC CFGR register initialization data. \ + NOTE: The bits DMAEN and DMACFG are enforced internally \ + to the driver, keep them to zero. \ + NOTE: The bits @p ADC_CFGR_CONT or @p ADC_CFGR_DISCEN must be \ + specified in continuous mode or if the buffer depth is \ + greater than one.*/ \ + uint32_t cfgr; \ + /* ADC CFGR2 register initialization data. \ + NOTE: The bits DMAEN and DMACFG are enforced internally \ + to the driver, keep them to zero. \ + NOTE: The bits @p ADC_CFGR_CONT or @p ADC_CFGR_DISCEN must be \ + specified in continuous mode or if the buffer depth is \ + greater than one.*/ \ + uint32_t cfgr2; \ + /* ADC TR1 register initialization data.*/ \ + uint32_t tr1; \ + /* ADC CCR register initialization data. \ + NOTE: Put this field to zero if not using oversampling.*/ \ + uint32_t ccr; \ + /* ADC SMPRx registers initialization data.*/ \ + uint32_t smpr[2]; \ + /* ADC SQRx register initialization data.*/ \ + uint32_t sqr[4]; \ + /* Slave ADC SMPRx registers initialization data. \ + NOTE: This field is only present in dual mode.*/ \ + uint32_t ssmpr[2]; \ + /* Slave ADC SQRx register initialization data. \ + NOTE: This field is only present in dual mode.*/ \ + uint32_t ssqr[4] +#else /* STM32_ADC_DUAL_MODE == FALSE */ +#define adc_lld_configuration_group_fields \ + uint32_t cfgr; \ + uint32_t cfgr2; \ + uint32_t tr1; \ + uint32_t smpr[2]; \ + uint32_t sqr[4] +#endif /* STM32_ADC_DUAL_MODE == FALSE */ + +#else /* STM32_ADCV3_OVERSAMPLING == FALSE */ +#if (STM32_ADC_DUAL_MODE == TRUE) || defined(__DOXYGEN__) +#define adc_lld_configuration_group_fields \ + uint32_t cfgr; \ + uint32_t tr1; \ + uint32_t ccr; \ + uint32_t smpr[2]; \ + uint32_t sqr[4]; \ + uint32_t ssmpr[2]; \ + uint32_t ssqr[4] +#else /* STM32_ADC_DUAL_MODE == FALSE */ +#define adc_lld_configuration_group_fields \ + uint32_t cfgr; \ + uint32_t tr1; \ + uint32_t smpr[2]; \ + uint32_t sqr[4] +#endif /* STM32_ADC_DUAL_MODE == FALSE */ +#endif /* STM32_ADCV3_OVERSAMPLING == FALSE */ /** * @name Threashold register initializer diff --git a/os/hal/ports/STM32/STM32F1xx/hal_adc_lld.h b/os/hal/ports/STM32/STM32F1xx/hal_adc_lld.h index 0449ca01b..38772cab9 100644 --- a/os/hal/ports/STM32/STM32F1xx/hal_adc_lld.h +++ b/os/hal/ports/STM32/STM32F1xx/hal_adc_lld.h @@ -148,163 +148,58 @@ typedef enum { ADC_ERR_DMAFAILURE = 0 /**< DMA operations failure. */ } adcerror_t; -/** - * @brief Type of a structure representing an ADC driver. - */ -typedef struct ADCDriver ADCDriver; - -/** - * @brief ADC notification callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] buffer pointer to the most recent samples data - * @param[in] n number of buffer rows available starting from @p buffer - */ -typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n); - -/** - * @brief ADC error callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] err ADC error code - */ -typedef void (*adcerrorcallback_t)(ADCDriver *adcp, adcerror_t err); +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ /** - * @brief Conversion group configuration structure. - * @details This implementation-dependent structure describes a conversion - * operation. - * @note The use of this configuration structure requires knowledge of - * STM32 ADC cell registers interface, please refer to the STM32 - * reference manual for details. + * @brief Low level fields of the ADC driver structure. */ -typedef struct { - /** - * @brief Enables the circular buffer mode for the group. - */ - bool circular; - /** - * @brief Number of the analog channels belonging to the conversion group. - */ - adc_channels_num_t num_channels; - /** - * @brief Callback function associated to the group or @p NULL. - */ - adccallback_t end_cb; - /** - * @brief Error callback or @p NULL. - */ - adcerrorcallback_t error_cb; - /* End of the mandatory fields.*/ - /** - * @brief ADC CR1 register initialization data. - * @note All the required bits must be defined into this field except - * @p ADC_CR1_SCAN that is enforced inside the driver. - */ - uint32_t cr1; - /** - * @brief ADC CR2 register initialization data. - * @note All the required bits must be defined into this field except - * @p ADC_CR2_DMA, @p ADC_CR2_CONT and @p ADC_CR2_ADON that are - * enforced inside the driver. - */ - uint32_t cr2; - /** - * @brief ADC SMPR1 register initialization data. - * @details In this field must be specified the sample times for channels - * 10...17. - */ - uint32_t smpr1; - /** - * @brief ADC SMPR2 register initialization data. - * @details In this field must be specified the sample times for channels - * 0...9. - */ - uint32_t smpr2; - /** - * @brief ADC SQR1 register initialization data. - * @details Conversion group sequence 13...16 + sequence length. - */ - uint32_t sqr1; - /** - * @brief ADC SQR2 register initialization data. - * @details Conversion group sequence 7...12. - */ - uint32_t sqr2; - /** - * @brief ADC SQR3 register initialization data. - * @details Conversion group sequence 1...6. - */ - uint32_t sqr3; -} ADCConversionGroup; +#define adc_lld_driver_fields \ + /* Pointer to the ADCx registers block.*/ \ + ADC_TypeDef *adc; \ + /* Pointer to associated DMA channel.*/ \ + const stm32_dma_stream_t *dmastp; \ + /* DMA mode bit mask.*/ \ + uint32_t dmamode /** - * @brief Driver configuration structure. - * @note It could be empty on some architectures. + * @brief Low level fields of the ADC configuration structure. */ -typedef struct { - uint32_t dummy; -} ADCConfig; +#define adc_lld_config_fields \ + /* Dummy configuration, it is not needed.*/ \ + uint32_t dummy /** - * @brief Structure representing an ADC driver. + * @brief Low level fields of the ADC configuration structure. */ -struct ADCDriver { - /** - * @brief Driver state. - */ - adcstate_t state; - /** - * @brief Current configuration data. - */ - const ADCConfig *config; - /** - * @brief Current samples buffer pointer or @p NULL. - */ - adcsample_t *samples; - /** - * @brief Current samples buffer depth or @p 0. - */ - size_t depth; - /** - * @brief Current conversion group pointer or @p NULL. - */ - const ADCConversionGroup *grpp; -#if ADC_USE_WAIT || defined(__DOXYGEN__) - /** - * @brief Waiting thread. - */ - thread_reference_t thread; -#endif -#if ADC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) - /** - * @brief Mutex protecting the peripheral. - */ - mutex_t mutex; -#endif /* ADC_USE_MUTUAL_EXCLUSION */ -#if defined(ADC_DRIVER_EXT_FIELDS) - ADC_DRIVER_EXT_FIELDS -#endif - /* End of the mandatory fields.*/ - /** - * @brief Pointer to the ADCx registers block. - */ - ADC_TypeDef *adc; - /** - * @brief Pointer to associated DMA channel. - */ - const stm32_dma_stream_t *dmastp; - /** - * @brief DMA mode bit mask. - */ - uint32_t dmamode; -}; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ +#define adc_lld_configuration_group_fields \ + /* ADC CR1 register initialization data. \ + NOTE: All the required bits must be defined into this field except \ + @p ADC_CR1_SCAN that is enforced inside the driver.*/ \ + uint32_t cr1; \ + /* ADC CR2 register initialization data. \ + NOTE: All the required bits must be defined into this field except \ + @p ADC_CR2_DMA, @p ADC_CR2_CONT and @p ADC_CR2_ADON that are \ + enforced inside the driver.*/ \ + uint32_t cr2; \ + /* ADC SMPR1 register initialization data. \ + NOTE: In this field must be specified the sample times for channels \ + 10...17.*/ \ + uint32_t smpr1; \ + /* ADC SMPR2 register initialization data. \ + NOTE: In this field must be specified the sample times for channels \ + 0...9.*/ \ + uint32_t smpr2; \ + /* ADC SQR1 register initialization data. \ + NOTE: Conversion group sequence 13...16 + sequence length.*/ \ + uint32_t sqr1; \ + /* ADC SQR2 register initialization data. \ + NOTE: Conversion group sequence 7...12.*/ \ + uint32_t sqr2; \ + /* ADC SQR3 register initialization data. \ + NOTE: Conversion group sequence 1...6.*/ \ + uint32_t sqr3 /** * @name Sequences building helper macros diff --git a/os/hal/ports/STM32/STM32F37x/hal_adc_lld.h b/os/hal/ports/STM32/STM32F37x/hal_adc_lld.h index 05c122c69..055883a03 100644 --- a/os/hal/ports/STM32/STM32F37x/hal_adc_lld.h +++ b/os/hal/ports/STM32/STM32F37x/hal_adc_lld.h @@ -361,203 +361,136 @@ typedef enum { ADC_ERR_AWD1 = 2 /**< Watchdog 1 triggered. */ } adcerror_t; -/** - * @brief Type of a structure representing an ADC driver. - */ -typedef struct ADCDriver ADCDriver; - -/** - * @brief ADC notification callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] buffer pointer to the most recent samples data - * @param[in] n number of buffer rows available starting from @p buffer - */ -typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n); - -/** - * @brief ADC error callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] err ADC error code - */ -typedef void (*adcerrorcallback_t)(ADCDriver *adcp, adcerror_t err); - -/** - * @brief Conversion group configuration structure. - * @details This implementation-dependent structure describes a conversion - * operation. - * @note The use of this configuration structure requires knowledge of - * STM32 ADC cell registers interface, please refer to the STM32 - * reference manual for details. - */ -typedef struct { - /** - * @brief Enables the circular buffer mode for the group. - */ - bool circular; - /** - * @brief Number of the analog channels belonging to the conversion group. - */ - adc_channels_num_t num_channels; - /** - * @brief Callback function associated to the group or @p NULL. - */ - adccallback_t end_cb; - /** - * @brief Error callback or @p NULL. - */ - adcerrorcallback_t error_cb; - /* End of the mandatory fields.*/ - - /** - * @brief Union of ADC and SDADC config parms. The decision of which struct - * union to use is determined by the ADCDriver. If the ADCDriver adc parm - * is not NULL, then use the adc struct, otherwise if the ADCDriver sdadc parm - * is not NULL, then use the sdadc struct. - */ - union { -#if STM32_ADC_USE_ADC || defined(__DOXYGEN__) - struct { - /** - * @brief ADC CR1 register initialization data. - * @note All the required bits must be defined into this field except - * @p ADC_CR1_SCAN that is enforced inside the driver. - */ - uint32_t cr1; - /** - * @brief ADC CR2 register initialization data. - * @note All the required bits must be defined into this field except - * @p ADC_CR2_DMA, @p ADC_CR2_CONT and @p ADC_CR2_ADON that are - * enforced inside the driver. - */ - uint32_t cr2; - /** - * @brief ADC LTR register initialization data. - */ - uint32_t ltr; - /** - * @brief ADC HTR register initialization data. - */ - uint32_t htr; - /** - * @brief ADC SMPRx registers initialization data. - */ - uint32_t smpr[2]; - /** - * @brief ADC SQRx register initialization data. - */ - uint32_t sqr[3]; - } adc; -#endif /* STM32_ADC_USE_ADC */ -#if STM32_ADC_USE_SDADC || defined(__DOXYGEN__) - struct { - /** - * @brief SDADC CR2 register initialization data. - * @note Only the @p SDADC_CR2_JSWSTART, @p SDADC_CR2_JEXTSEL - * and @p SDADC_CR2_JEXTEN can be specified in this field. - */ - uint32_t cr2; - /** - * @brief SDADC JCHGR register initialization data. - */ - uint32_t jchgr; - /** - * @brief SDADC CONFCHxR registers initialization data. - */ - uint32_t confchr[2]; - } sdadc; -#endif /* STM32_ADC_USE_SDADC */ - } u; -} ADCConversionGroup; - -/** - * @brief Driver configuration structure. - * @note It could be empty on some architectures. - */ -typedef struct { -#if STM32_ADC_USE_SDADC - /** - * @brief SDADC CR1 register initialization data. - */ - uint32_t cr1; - /** - * @brief SDADC CONFxR registers initialization data. - */ - uint32_t confxr[3]; -#else /* !STM32_ADC_USE_SDADC */ - uint32_t dummy; -#endif /* !STM32_ADC_USE_SDADC */ -} ADCConfig; - -/** - * @brief Structure representing an ADC driver. - */ -struct ADCDriver { - /** - * @brief Driver state. - */ - adcstate_t state; - /** - * @brief Current configuration data. - */ - const ADCConfig *config; - /** - * @brief Current samples buffer pointer or @p NULL. - */ - adcsample_t *samples; - /** - * @brief Current samples buffer depth or @p 0. - */ - size_t depth; - /** - * @brief Current conversion group pointer or @p NULL. - */ - const ADCConversionGroup *grpp; -#if ADC_USE_WAIT || defined(__DOXYGEN__) - /** - * @brief Waiting thread. - */ - thread_reference_t thread; -#endif -#if ADC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) - /** - * @brief Mutex protecting the peripheral. - */ - mutex_t mutex; -#endif /* ADC_USE_MUTUAL_EXCLUSION */ -#if defined(ADC_DRIVER_EXT_FIELDS) - ADC_DRIVER_EXT_FIELDS -#endif - /* End of the mandatory fields.*/ -#if STM32_ADC_USE_ADC || defined(__DOXYGEN__) - /** - * @brief Pointer to the ADCx registers block. - */ - ADC_TypeDef *adc; -#endif -#if STM32_ADC_USE_SDADC || defined(__DOXYGEN__) - /** - * @brief Pointer to the SDADCx registers block. - */ - SDADC_TypeDef *sdadc; -#endif - /** - * @brief Pointer to associated DMA channel. - */ - const stm32_dma_stream_t *dmastp; - /** - * @brief DMA mode bit mask. - */ - uint32_t dmamode; -}; - /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ +#if (STM32_ADC_USE_ADC && STM32_ADC_USE_SDADC) || defined(__DOXYGEN__) +/** + * @brief Low level fields of the ADC driver structure. + */ +#define adc_lld_driver_fields \ + /* Pointer to the ADCx registers block.*/ \ + ADC_TypeDef *adc; \ + /* Pointer to the SDADCx registers block.*/ \ + SDADC_TypeDef *sdadc; \ + /* Pointer to associated DMA channel.*/ \ + const stm32_dma_stream_t *dmastp; \ + /* DMA mode bit mask.*/ \ + uint32_t dmamode + +/** + * @brief Low level fields of the ADC configuration structure. + */ +#define adc_lld_config_fields \ + /* SDADC CR1 register initialization data.*/ \ + uint32_t cr1; \ + /* SDADC CONFxR registers initialization data.*/ \ + uint32_t confxr[3] + +/** + * @brief Low level fields of the ADC configuration structure. + */ +#define adc_lld_configuration_group_fields \ + union { \ + struct { \ + /* ADC CR1 register initialization data. \ + NOTE: All the required bits must be defined into this field except \ + @p ADC_CR1_SCAN that is enforced inside the driver.*/ \ + uint32_t cr1; \ + /* ADC CR2 register initialization data. \ + NOTE: All the required bits must be defined into this field except \ + @p ADC_CR2_DMA, @p ADC_CR2_CONT and @p ADC_CR2_ADON that are \ + enforced inside the driver.*/ \ + uint32_t cr2; \ + /* ADC LTR register initialization data.*/ \ + uint32_t ltr; \ + /* ADC HTR register initialization data.*/ \ + uint32_t htr; \ + /* ADC SMPRx registers initialization data.*/ \ + uint32_t smpr[2]; \ + /* ADC SQRx register initialization data.*/ \ + uint32_t sqr[3]; \ + } adc; \ + struct { \ + /* SDADC CR2 register initialization data. \ + NOTE: Only the @p SDADC_CR2_JSWSTART, @p SDADC_CR2_JEXTSEL \ + and @p SDADC_CR2_JEXTEN can be specified in this field.*/ \ + uint32_t cr2; \ + /* SDADC JCHGR register initialization data.*/ \ + uint32_t jchgr; \ + /* SDADC CONFCHxR registers initialization data.*/ \ + uint32_t confchr[2]; \ + } sdadc; \ + } u + +#elif STM32_ADC_USE_ADC +#define adc_lld_driver_fields \ + /* Pointer to the ADCx registers block.*/ \ + ADC_TypeDef *adc; \ + /* Pointer to associated DMA channel.*/ \ + const stm32_dma_stream_t *dmastp; \ + /* DMA mode bit mask.*/ \ + uint32_t dmamode + +#define adc_lld_config_fields \ + /* Dummy configuration, it is not needed.*/ \ + uint32_t dummy + +#define adc_lld_configuration_group_fields \ + union { \ + struct { \ + /* ADC CR1 register initialization data. \ + NOTE: All the required bits must be defined into this field except \ + @p ADC_CR1_SCAN that is enforced inside the driver.*/ \ + uint32_t cr1; \ + /* ADC CR2 register initialization data. \ + NOTE: All the required bits must be defined into this field except \ + @p ADC_CR2_DMA, @p ADC_CR2_CONT and @p ADC_CR2_ADON that are \ + enforced inside the driver.*/ \ + uint32_t cr2; \ + /* ADC LTR register initialization data.*/ \ + uint32_t ltr; \ + /* ADC HTR register initialization data.*/ \ + uint32_t htr; \ + /* ADC SMPRx registers initialization data.*/ \ + uint32_t smpr[2]; \ + /* ADC SQRx register initialization data.*/ \ + uint32_t sqr[3]; \ + } adc; \ + } u + +#elif STM32_ADC_USE_SDADC +#define adc_lld_driver_fields \ + /* Pointer to the SDADCx registers block.*/ \ + SDADC_TypeDef *sdadc; \ + /* Pointer to associated DMA channel.*/ \ + const stm32_dma_stream_t *dmastp; \ + /* DMA mode bit mask.*/ \ + uint32_t dmamode + +#define adc_lld_config_fields \ + /* SDADC CR1 register initialization data.*/ \ + uint32_t cr1; \ + /* SDADC CONFxR registers initialization data.*/ \ + uint32_t confxr[3] + +#define adc_lld_configuration_group_fields \ + union { \ + struct { \ + /* SDADC CR2 register initialization data. \ + NOTE: Only the @p SDADC_CR2_JSWSTART, @p SDADC_CR2_JEXTSEL \ + and @p SDADC_CR2_JEXTEN can be specified in this field.*/ \ + uint32_t cr2; \ + /* SDADC JCHGR register initialization data.*/ \ + uint32_t jchgr; \ + /* SDADC CONFCHxR registers initialization data.*/ \ + uint32_t confchr[2]; \ + } sdadc; \ + } u + +#endif + /** * @name Sequences building helper macros for ADC * @{ diff --git a/os/hal/ports/STM32/STM32L1xx/hal_adc_lld.h b/os/hal/ports/STM32/STM32L1xx/hal_adc_lld.h index 2ff2ec864..31f8679ba 100644 --- a/os/hal/ports/STM32/STM32L1xx/hal_adc_lld.h +++ b/os/hal/ports/STM32/STM32L1xx/hal_adc_lld.h @@ -213,179 +213,68 @@ typedef enum { ADC_ERR_OVERFLOW = 1 /**< ADC overflow condition. */ } adcerror_t; -/** - * @brief Type of a structure representing an ADC driver. - */ -typedef struct ADCDriver ADCDriver; - -/** - * @brief ADC notification callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] buffer pointer to the most recent samples data - * @param[in] n number of buffer rows available starting from @p buffer - */ -typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n); - -/** - * @brief ADC error callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] err ADC error code - */ -typedef void (*adcerrorcallback_t)(ADCDriver *adcp, adcerror_t err); +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ /** - * @brief Conversion group configuration structure. - * @details This implementation-dependent structure describes a conversion - * operation. - * @note The use of this configuration structure requires knowledge of - * STM32 ADC cell registers interface, please refer to the STM32 - * reference manual for details. + * @brief Low level fields of the ADC driver structure. */ -typedef struct { - /** - * @brief Enables the circular buffer mode for the group. - */ - bool circular; - /** - * @brief Number of the analog channels belonging to the conversion group. - */ - adc_channels_num_t num_channels; - /** - * @brief Callback function associated to the group or @p NULL. - */ - adccallback_t end_cb; - /** - * @brief Error callback or @p NULL. - */ - adcerrorcallback_t error_cb; - /* End of the mandatory fields.*/ - /** - * @brief ADC CR1 register initialization data. - * @note All the required bits must be defined into this field except - * @p ADC_CR1_SCAN that is enforced inside the driver. - */ - uint32_t cr1; - /** - * @brief ADC CR2 register initialization data. - * @note All the required bits must be defined into this field except - * @p ADC_CR2_DMA, @p ADC_CR2_CONT and @p ADC_CR2_ADON that are - * enforced inside the driver. - */ - uint32_t cr2; - /** - * @brief ADC SMPR1 register initialization data. - * @details In this field must be specified the sample times for channels - * 20...25. - */ - uint32_t smpr1; - /** - * @brief ADC SMPR2 register initialization data. - * @details In this field must be specified the sample times for channels - * 10...19. - */ - uint32_t smpr2; - /** - * @brief ADC SMPR3 register initialization data. - * @details In this field must be specified the sample times for channels - * 0...9. - */ - uint32_t smpr3; - /** - * @brief ADC SQR1 register initialization data. - * @details Conversion group sequence 25...27 + sequence length. - */ - uint32_t sqr1; - /** - * @brief ADC SQR2 register initialization data. - * @details Conversion group sequence 19...24. - */ - uint32_t sqr2; - /** - * @brief ADC SQR3 register initialization data. - * @details Conversion group sequence 13...18. - */ - uint32_t sqr3; - /** - * @brief ADC SQR3 register initialization data. - * @details Conversion group sequence 7...12. - */ - uint32_t sqr4; - /** - * @brief ADC SQR3 register initialization data. - * @details Conversion group sequence 1...6. - */ - uint32_t sqr5; -} ADCConversionGroup; +#define adc_lld_driver_fields \ + /* Pointer to the ADCx registers block.*/ \ + ADC_TypeDef *adc; \ + /* Pointer to associated DMA channel.*/ \ + const stm32_dma_stream_t *dmastp; \ + /* DMA mode bit mask.*/ \ + uint32_t dmamode /** - * @brief Driver configuration structure. - * @note It could be empty on some architectures. + * @brief Low level fields of the ADC configuration structure. */ -typedef struct { - uint32_t dummy; -} ADCConfig; +#define adc_lld_config_fields \ + /* Dummy configuration, it is not needed.*/ \ + uint32_t dummy /** - * @brief Structure representing an ADC driver. + * @brief Low level fields of the ADC configuration structure. */ -struct ADCDriver { - /** - * @brief Driver state. - */ - adcstate_t state; - /** - * @brief Current configuration data. - */ - const ADCConfig *config; - /** - * @brief Current samples buffer pointer or @p NULL. - */ - adcsample_t *samples; - /** - * @brief Current samples buffer depth or @p 0. - */ - size_t depth; - /** - * @brief Current conversion group pointer or @p NULL. - */ - const ADCConversionGroup *grpp; -#if ADC_USE_WAIT || defined(__DOXYGEN__) - /** - * @brief Waiting thread. - */ - thread_reference_t thread; -#endif -#if ADC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) - /** - * @brief Mutex protecting the peripheral. - */ - mutex_t mutex; -#endif /* ADC_USE_MUTUAL_EXCLUSION */ -#if defined(ADC_DRIVER_EXT_FIELDS) - ADC_DRIVER_EXT_FIELDS -#endif - /* End of the mandatory fields.*/ - /** - * @brief Pointer to the ADCx registers block. - */ - ADC_TypeDef *adc; - /** - * @brief Pointer to associated DMA channel. - */ - const stm32_dma_stream_t *dmastp; - /** - * @brief DMA mode bit mask. - */ - uint32_t dmamode; -}; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ +#define adc_lld_configuration_group_fields \ + /* ADC CR1 register initialization data. \ + NOTE: All the required bits must be defined into this field except \ + @p ADC_CR1_SCAN that is enforced inside the driver.*/ \ + uint32_t cr1; \ + /* ADC CR2 register initialization data. \ + NOTE: All the required bits must be defined into this field except \ + @p ADC_CR2_DMA, @p ADC_CR2_CONT and @p ADC_CR2_ADON that are \ + enforced inside the driver.*/ \ + uint32_t cr2; \ + /* ADC SMPR1 register initialization data. \ + NOTE: In this field must be specified the sample times for channels \ + 20...25.*/ \ + uint32_t smpr1; \ + /* ADC SMPR2 register initialization data. \ + NOTE: In this field must be specified the sample times for channels \ + 10...19.*/ \ + uint32_t smpr2; \ + /* ADC SMPR3 register initialization data. \ + NOTE: In this field must be specified the sample times for channels \ + 0...9.*/ \ + uint32_t smpr3; \ + /* ADC SQR1 register initialization data. \ + NOTE: Conversion group sequence 25...27 + sequence length.*/ \ + uint32_t sqr1; \ + /* ADC SQR2 register initialization data. \ + NOTE: Conversion group sequence 19...24.*/ \ + uint32_t sqr2; \ + /* ADC SQR3 register initialization data. \ + NOTE: Conversion group sequence 13...18.*/ \ + uint32_t sqr3; \ + /* ADC SQR3 register initialization data. \ + NOTE: Conversion group sequence 7...12.*/ \ + uint32_t sqr4; \ + /* ADC SQR3 register initialization data. \ + NOTE: Conversion group sequence 1...6.*/ \ + uint32_t sqr5 /** * @name Sequences building helper macros diff --git a/os/hal/templates/hal_adc_lld.h b/os/hal/templates/hal_adc_lld.h index cd2920c4c..d337dd2aa 100644 --- a/os/hal/templates/hal_adc_lld.h +++ b/os/hal/templates/hal_adc_lld.h @@ -78,111 +78,26 @@ typedef enum { ADC_ERR_AWD = 2 /**< Analog watchdog triggered. */ } adcerror_t; -/** - * @brief Type of a structure representing an ADC driver. - */ -typedef struct ADCDriver ADCDriver; - -/** - * @brief ADC notification callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] buffer pointer to the most recent samples data - * @param[in] n number of buffer rows available starting from @p buffer - */ -typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n); - -/** - * @brief ADC error callback type. - * - * @param[in] adcp pointer to the @p ADCDriver object triggering the - * callback - * @param[in] err ADC error code - */ -typedef void (*adcerrorcallback_t)(ADCDriver *adcp, adcerror_t err); +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ /** - * @brief Conversion group configuration structure. - * @details This implementation-dependent structure describes a conversion - * operation. - * @note The use of this configuration structure requires knowledge of - * PLATFORM ADC cell registers interface, please refer to the PLATFORM - * reference manual for details. + * @brief Low level fields of the ADC driver structure. */ -typedef struct { - /** - * @brief Enables the circular buffer mode for the group. - */ - bool circular; - /** - * @brief Number of the analog channels belonging to the conversion group. - */ - adc_channels_num_t num_channels; - /** - * @brief Callback function associated to the group or @p NULL. - */ - adccallback_t end_cb; - /** - * @brief Error callback or @p NULL. - */ - adcerrorcallback_t error_cb; - /* End of the mandatory fields.*/ -} ADCConversionGroup; +#define adc_lld_driver_fields /** - * @brief Driver configuration structure. - * @note It could be empty on some architectures. + * @brief Low level fields of the ADC configuration structure. */ -typedef struct { - uint32_t dummy; -} ADCConfig; +#define adc_lld_config_fields \ + /* Dummy configuration, it is not needed.*/ \ + uint32_t dummy /** - * @brief Structure representing an ADC driver. + * @brief Low level fields of the ADC configuration structure. */ -struct ADCDriver { - /** - * @brief Driver state. - */ - adcstate_t state; - /** - * @brief Current configuration data. - */ - const ADCConfig *config; - /** - * @brief Current samples buffer pointer or @p NULL. - */ - adcsample_t *samples; - /** - * @brief Current samples buffer depth or @p 0. - */ - size_t depth; - /** - * @brief Current conversion group pointer or @p NULL. - */ - const ADCConversionGroup *grpp; -#if (ADC_USE_WAIT == TRUE) || defined(__DOXYGEN__) - /** - * @brief Waiting thread. - */ - thread_reference_t thread; -#endif -#if (ADC_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__) - /** - * @brief Mutex protecting the peripheral. - */ - mutex_t mutex; -#endif -#if defined(ADC_DRIVER_EXT_FIELDS) - ADC_DRIVER_EXT_FIELDS -#endif - /* End of the mandatory fields.*/ -}; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ +#define adc_lld_configuration_group_fields /*===========================================================================*/ /* External declarations. */ -- cgit v1.2.3