From: Nathael Pajani Date: Sun, 27 Apr 2014 16:52:14 +0000 (+0200) Subject: Improved ADC support (untested) X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=22d8ff1f5b6778e4d2a9929b751efee3bf5b9eab;p=soft%2Flpc122x%2Fcore Improved ADC support (untested) --- diff --git a/drivers/adc.c b/drivers/adc.c index 7404320..29f8bf0 100644 --- a/drivers/adc.c +++ b/drivers/adc.c @@ -101,12 +101,33 @@ int adc_get_value(uint16_t * val, int channel) void adc_start_burst_conversion(uint8_t channels) { struct lpc_adc* adc = LPC_ADC; + uint32_t reg_val = 0; - /* Set conversion channel bits */ - adc->ctrl = ((adc->ctrl & ~LPC_ADC_CHANNEL_MASK) | channels); - adc->ctrl |= LPC_ADC_BURST; + /* Set conversion channel bits and burst mode */ + reg_val = ((adc->ctrl & ~LPC_ADC_CHANNEL_MASK) | channels | LPC_ADC_BURST); + /* Clear single burst flag */ + reg_val &= ~(LPC_ADC_SINGLE_BURST); + + adc->ctrl = (reg_val & LPC_ADC_CTRL_MASK); +} + +/* Start single burst conversions : triggers a single conversion for each of the + * selected channels. + * channels is a bit mask of requested channels. + * Use LPC_ADC_CHANNEL(x) (x = 0 .. 7) for channels selection. + */ +void adc_start_single_burst_conversion(uint8_t channels) +{ + struct lpc_adc* adc = LPC_ADC; + uint32_t reg_val = 0; + + /* Set conversion channel bits and burst mode */ + reg_val = ((adc->ctrl & ~LPC_ADC_CHANNEL_MASK) | channels); + reg_val |= (LPC_ADC_BURST | LPC_ADC_SINGLE_BURST); + adc->ctrl = (reg_val & LPC_ADC_CTRL_MASK); } + /* Unsupported Yet */ /* This should be used to configure conversion start on falling or rising edges of * some signals, or on timer for burst conversions. diff --git a/include/core/lpc_regs_12xx.h b/include/core/lpc_regs_12xx.h index c476d40..f0dfd0d 100644 --- a/include/core/lpc_regs_12xx.h +++ b/include/core/lpc_regs_12xx.h @@ -736,18 +736,24 @@ struct lpc_adc #define LPC_ADC ((struct lpc_adc *) LPC_ADC_BASE) /* ADC Control register bits */ +#define LPC_ADC_CTRL_MASK 0x0F01FFFF /* LPC_ADC_CHANNEL_* are also used for interrupt register */ #define LPC_ADC_CHANNEL_MASK (0xFF << 0) #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) #define LPC_ADC_8BITS (0x02 << 17) #define LPC_ADC_7BITS (0x03 << 17) #define LPC_ADC_6BITS (0x04 << 17) +#define LPC_ADC_5BITS (0x05 << 17) +#define LPC_ADC_4BITS (0x06 << 17) +#define LPC_ADC_3BITS (0x07 << 17) +#define LPC_ADC_BITS_MASK (0x07 << 17) + +#define LPC_ADC_SINGLE_BURST (0x01 << 20) + #define LPC_ADC_START_CONV_NOW (0x01 << 24) #define LPC_ADC_START_CONV_MASK (0x07 << 24) @@ -757,5 +763,7 @@ struct lpc_adc #define LPC_ADC_OVERRUN (0x01 << 30) #define LPC_ADC_CONV_DONE (0x01 << 31) +/* For more readability when selecting a channel number */ +#define LPC_ADC_NUM(x) (x) #endif /* LPC_REGS_H */ diff --git a/include/drivers/adc.h b/include/drivers/adc.h index 553f4b6..b4f1bba 100644 --- a/include/drivers/adc.h +++ b/include/drivers/adc.h @@ -45,6 +45,13 @@ int adc_get_value(uint16_t * val, int channel); */ void adc_start_burst_conversion(uint8_t channels); +/* Start single burst conversions : triggers a single conversion for each of the + * selected channels. + * channels is a bit mask of requested channels. + * Use LPC_ADC_CHANNEL(x) (x = 0 .. 7) for channels selection. + */ +void adc_start_single_burst_conversion(uint8_t channels); + /* Unsupported Yet */ /* This should be used to configure conversion start on falling or rising edges of * some signals, or on timer for burst conversions.