aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/include
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-12-09 13:03:19 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-12-09 13:03:19 +0000
commit26ed8c9062f0a549507938ec525460f8c10b8acc (patch)
tree52b888ed7166bcefa4549714178f85b40a4903e4 /os/hal/include
parent964ca6029035706e5ba5be7a8304eba67920386d (diff)
downloadChibiOS-26ed8c9062f0a549507938ec525460f8c10b8acc.tar.gz
ChibiOS-26ed8c9062f0a549507938ec525460f8c10b8acc.tar.bz2
ChibiOS-26ed8c9062f0a549507938ec525460f8c10b8acc.zip
ADC reworked.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12467 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'os/hal/include')
-rw-r--r--os/hal/include/hal_adc.h121
1 files changed, 121 insertions, 0 deletions
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. */
/*===========================================================================*/