From 421bffc34071f04d5b92e83cd9f02a5ecb3a3e70 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Sat, 4 Jan 2014 12:05:17 +0100 Subject: [PATCH] Change and use defines for ADC channels selection --- drivers/adc.c | 6 +++--- include/core/lpc_regs_12xx.h | 11 +++-------- include/drivers/adc.h | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/adc.c b/drivers/adc.c index e230fe3..d40ea21 100644 --- a/drivers/adc.c +++ b/drivers/adc.c @@ -55,10 +55,10 @@ void adc_start_convertion_once(unsigned int channel, int use_int) return; /* Set conversion channel bit */ - adc->ctrl = ((adc->ctrl & ~LPC_ADC_CHANNEL_MASK) | (0x01 << channel)); + adc->ctrl = ((adc->ctrl & ~LPC_ADC_CHANNEL_MASK) | LPC_ADC_CHANNEL(channel)); if (use_int) { /* Set interrupt Bit */ - adc->int_en = (0x01 << channel); + adc->int_en = LPC_ADC_CHANNEL(channel); } else { adc->int_en = 0; } @@ -95,7 +95,7 @@ int adc_get_value(uint16_t * val, int channel) /* Start burst conversions. * channels is a bit mask of requested channels. - * Use LPC_ADC_CHANNEL_0 .. 7 + * Use LPC_ADC_CHANNEL(x) (x = 0 .. 7) for channels selection. */ void adc_start_burst_conversion(uint8_t channels) { diff --git a/include/core/lpc_regs_12xx.h b/include/core/lpc_regs_12xx.h index 186e176..ff362d3 100644 --- a/include/core/lpc_regs_12xx.h +++ b/include/core/lpc_regs_12xx.h @@ -721,15 +721,10 @@ struct lpc_adc /* ADC Control register bits */ /* LPC_ADC_CHANNEL_* are also used for interrupt register */ #define LPC_ADC_CHANNEL_MASK (0xFF << 0) -#define LPC_ADC_CHANNEL_0 (0x01 << 0) -#define LPC_ADC_CHANNEL_1 (0x01 << 1) -#define LPC_ADC_CHANNEL_2 (0x01 << 2) -#define LPC_ADC_CHANNEL_3 (0x01 << 3) -#define LPC_ADC_CHANNEL_4 (0x01 << 4) -#define LPC_ADC_CHANNEL_5 (0x01 << 5) -#define LPC_ADC_CHANNEL_6 (0x01 << 6) -#define LPC_ADC_CHANNEL_7 (0x01 << 7) +#define LPC_ADC_CHANNEL(x) (0x01 << ((x) & 0x07)) #define LPC_ADC_BURST (0x01 << 16) +/* For more readability when selecting a channel number */ +#define LPC_ADC_NUM(x) (x) /* These are unused for LPC1224 */ #define LPC_ADC_10BITS (0x00 << 17) #define LPC_ADC_9BITS (0x01 << 17) diff --git a/include/drivers/adc.h b/include/drivers/adc.h index 896432c..46f03dc 100644 --- a/include/drivers/adc.h +++ b/include/drivers/adc.h @@ -44,7 +44,7 @@ int adc_get_value(uint16_t * val, int channel); /* Start burst conversions. * channels is a bit mask of requested channels. - * Use LPC_ADC_CHANNEL_0 .. 7 + * Use LPC_ADC_CHANNEL(x) (x = 0 .. 7) for channels selection. */ void adc_start_burst_conversion(uint8_t channels); -- 2.43.0