aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/AVR/MEGA/LLD/ADCv1
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/ports/AVR/MEGA/LLD/ADCv1')
-rw-r--r--os/hal/ports/AVR/MEGA/LLD/ADCv1/hal_adc_lld.c61
-rw-r--r--os/hal/ports/AVR/MEGA/LLD/ADCv1/hal_adc_lld.h36
2 files changed, 56 insertions, 41 deletions
diff --git a/os/hal/ports/AVR/MEGA/LLD/ADCv1/hal_adc_lld.c b/os/hal/ports/AVR/MEGA/LLD/ADCv1/hal_adc_lld.c
index f742cf580..79f71def1 100644
--- a/os/hal/ports/AVR/MEGA/LLD/ADCv1/hal_adc_lld.c
+++ b/os/hal/ports/AVR/MEGA/LLD/ADCv1/hal_adc_lld.c
@@ -26,26 +26,36 @@
#if HAL_USE_ADC || defined(__DOXYGEN__)
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local definitions. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver exported variables. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver exported variables. */
+/*==========================================================================*/
/** @brief ADC1 driver identifier.*/
#if AVR_ADC_USE_ADC1 || defined(__DOXYGEN__)
ADCDriver ADCD1;
#endif
-/*===========================================================================*/
-/* Driver local variables. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local variables. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local functions. */
+/*==========================================================================*/
+/**
+ * @brief Get the ADC channel.
+ *
+ * @param[in] mask the mask containing the channel number
+ * @param[in] currentChannel the current channel.
+ *
+ * @return the channel number.
+ * @retval ADC channel number
+ * @retval -1 in case of error.
+ */
static size_t getAdcChannelNumberFromMask(uint8_t mask,
uint8_t currentChannel) {
@@ -59,17 +69,22 @@ static size_t getAdcChannelNumberFromMask(uint8_t mask,
}
/* error, should never reach this line */
- return -1; // To check
+ return -1;
}
+/**
+ * @brief Configure the ADC channel.
+ *
+ * @param[in] channelNum the channel number to set.
+ */
static void setAdcChannel(uint8_t channelNum) {
ADMUX = (ADMUX & 0xf8) | (channelNum & 0x07);
}
-/*===========================================================================*/
-/* Driver interrupt handlers. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver interrupt handlers. */
+/*==========================================================================*/
#include <util/delay.h>
@@ -101,9 +116,9 @@ OSAL_IRQ_HANDLER(ADC_vect) {
OSAL_IRQ_EPILOGUE();
}
-/*===========================================================================*/
-/* Driver exported functions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver exported functions. */
+/*==========================================================================*/
/**
* @brief Low level ADC driver initialization.
@@ -114,10 +129,10 @@ void adc_lld_init(void) {
adcObjectInit(&ADCD1);
- //prescaler 128, only value possible at 20Mhz, interrupt
+ /* Prescaler 128, only value possible at 20Mhz, interrupt. */
ADCSRA = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0) | (1 << ADIE);
- //uso aref, only valid for arduino. arduino ha aref collegato
+ /* uso aref, only valid for arduino. arduino ha aref collegato. */
ADMUX = (0 << REFS1) | (0 << REFS0);
}
@@ -131,7 +146,7 @@ void adc_lld_init(void) {
void adc_lld_start(ADCDriver *adcp) {
if (adcp->state == ADC_STOP) {
- /* Clock activation.*/
+ /* Clock activation. */
ADCSRA |= (1 << ADEN);
}
@@ -150,7 +165,7 @@ void adc_lld_start(ADCDriver *adcp) {
void adc_lld_stop(ADCDriver *adcp) {
if (adcp->state == ADC_READY) {
- /* Clock de-activation.*/
+ /* Clock de-activation. */
ADCSRA &= ~(1 << ADEN);
}
}
diff --git a/os/hal/ports/AVR/MEGA/LLD/ADCv1/hal_adc_lld.h b/os/hal/ports/AVR/MEGA/LLD/ADCv1/hal_adc_lld.h
index c0bd82f0c..8183dc819 100644
--- a/os/hal/ports/AVR/MEGA/LLD/ADCv1/hal_adc_lld.h
+++ b/os/hal/ports/AVR/MEGA/LLD/ADCv1/hal_adc_lld.h
@@ -27,30 +27,30 @@
#if HAL_USE_ADC || defined(__DOXYGEN__)
-/*===========================================================================*/
-/* Driver constants. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver constants. */
+/*==========================================================================*/
#define ANALOG_REFERENCE_AREF 0
#define ANALOG_REFERENCE_AVCC 1
#define ANALOG_REFERENCE_1V1 2
#define ANALOG_REFERENCE_2V56 3
-/*===========================================================================*/
-/* Driver pre-compile time settings. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver pre-compile time settings. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Derived constants and error checks. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Derived constants and error checks. */
+/*==========================================================================*/
#if !CH_CFG_USE_SEMAPHORES
#error "the ADC driver requires CH_CFG_USE_SEMAPHORES"
#endif
-/*===========================================================================*/
-/* Driver data structures and types. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver data structures and types. */
+/*==========================================================================*/
/**
* @brief ADC sample data type.
@@ -167,13 +167,13 @@ struct ADCDriver {
size_t currentBufferPosition;
};
-/*===========================================================================*/
-/* Driver macros. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver macros. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* External declarations. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* External declarations. */
+/*==========================================================================*/
#if AVR_ADC_USE_ADC1 && !defined(__DOXYGEN__)
extern ADCDriver ADCD1;