From 81e85f4e8b082dcc776c7290282dcf22b0bf9ffd Mon Sep 17 00:00:00 2001 From: asterix Date: Thu, 5 Aug 2010 08:34:20 +0000 Subject: [PATCH] Add adc support for atmega1280. Signed-off by Fabio Bizzi. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4144 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/avr/drv/adc_avr.c | 13 ++++++++++++- bertos/cpu/avr/drv/adc_avr.h | 8 +++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/bertos/cpu/avr/drv/adc_avr.c b/bertos/cpu/avr/drv/adc_avr.c index 3eb08b79..c42f8e3b 100644 --- a/bertos/cpu/avr/drv/adc_avr.c +++ b/bertos/cpu/avr/drv/adc_avr.c @@ -104,12 +104,23 @@ void adc_hw_select_ch(uint8_t ch) #elif CPU_AVR_ATMEGA32 || CPU_AVR_ATMEGA64 || CPU_AVR_ATMEGA128 || CPU_AVR_ATMEGA1281 \ || CPU_AVR_ATMEGA1280 ADMUX &= ~(BV(MUX4) | BV(MUX3) | BV(MUX2) | BV(MUX1) | BV(MUX0)); + #if CPU_AVR_ATMEGA1280 + ADCSRB &= ~(BV(MUX5)); + #endif #else #error Unknown CPU #endif - /* Select channel, only first 8 channel modes are supported for now */ + /* Select channel, only first 8 channel modes are supported */ ADMUX |= (ch & 0x07); + + #if CPU_AVR_ATMEGA1280 + /* Select channel, all 16 channels are supported */ + if (ch > 0x07) + ADCSRB |= BV(MUX5); + + #endif + } diff --git a/bertos/cpu/avr/drv/adc_avr.h b/bertos/cpu/avr/drv/adc_avr.h index 417e4536..c42cf324 100644 --- a/bertos/cpu/avr/drv/adc_avr.h +++ b/bertos/cpu/avr/drv/adc_avr.h @@ -39,7 +39,13 @@ #include -#define ADC_MUX_MAXCH 7 +#if CPU_AVR_ATMEGA1280 + /* 16 channels aivailable */ + #define ADC_MUX_MAXCH 15 +#else + /* only 8 channels aivailable */ + #define ADC_MUX_MAXCH 7 +#endif #define ADC_BITS 10 void adc_hw_select_ch(uint8_t ch); -- 2.25.1