aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/wiring_analog.c
diff options
context:
space:
mode:
Diffstat (limited to 'cores/arduino/wiring_analog.c')
-rw-r--r--cores/arduino/wiring_analog.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c
index d248f4c..2b1f3a0 100644
--- a/cores/arduino/wiring_analog.c
+++ b/cores/arduino/wiring_analog.c
@@ -46,8 +46,11 @@ int analogRead(uint8_t pin)
#else
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
#endif
-
-#if defined(ADCSRB) && defined(MUX5)
+
+#if defined(__AVR_ATmega32U4__)
+ pin = analogPinToChannel(pin);
+ ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);
+#elif defined(ADCSRB) && defined(MUX5)
// the MUX5 bit of ADCSRB selects whether we're reading from channels
// 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high).
ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);
@@ -222,6 +225,14 @@ void analogWrite(uint8_t pin, int val)
OCR4C = val; // set pwm duty
break;
#endif
+
+ #if defined(TCCR4A) && defined(COM4D1)
+ case TIMER4D:
+ // connect pwm to pin on timer 4, channel D
+ sbi(TCCR4A, COM4D1);
+ OCR4D = val; // set pwm duty
+ break;
+ #endif
#if defined(TCCR5A) && defined(COM5A1)
case TIMER5A: