Skip to content

Commit

Permalink
Atmega4809 board definitions, closes #657
Browse files Browse the repository at this point in the history
  • Loading branch information
ArminJo committed Jul 4, 2020
1 parent 8abc69d commit ffd08fb
Showing 1 changed file with 50 additions and 15 deletions.
65 changes: 50 additions & 15 deletions src/private/IRremoteBoardDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@
#define BLINKLED_ON() (PORTD |= B00000001)
#define BLINKLED_OFF() (PORTD &= B11111110)

// Nano Every, Uno WiFi Rev2
#elif defined(__AVR_ATmega4809__)
#define BLINKLED LED_BUILTIN
#define BLINKLED_ON() (digitalWrite(BLINKLED, HIGH))
#define BLINKLED_OFF() (digitalWrite(BLINKLED, LOW))

#elif defined(ARDUINO_ARCH_SAMD)
#define BLINKLED LED_BUILTIN
#define BLINKLED_ON() (digitalWrite(LED_BUILTIN, HIGH))
Expand Down Expand Up @@ -195,6 +201,11 @@
//#define IR_USE_TIMER4 // tx = pin 6
//#define IR_USE_TIMER5 // tx = pin 46

// Nano Every, Uno WiFi Rev2
#elif defined(__AVR_ATmega4809__)
#define IR_USE_TIMER_4809_1 // tx = pin 24
//#define IR_USE_TIMER_4809_2 // TODO tx = pin 21

// Teensy 1.0
#elif defined(__AVR_AT90USB162__)
#define IR_USE_TIMER1 // tx = pin 17
Expand Down Expand Up @@ -338,11 +349,11 @@
#define TIMER_INTR_NAME TIMER2_COMPA_vect

#define TIMER_CONFIG_KHZ(val) ({ \
const uint8_t pwmval = SYSCLOCK / 2000 / (val); \
const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
TCCR2A = _BV(WGM20); \
TCCR2B = _BV(WGM22) | _BV(CS20); \
OCR2A = pwmval; \
OCR2B = pwmval / (100/DUTY_CYCLE); \
OCR2B = pwmval * DUTY_CYCLE / 100; \
})

#define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000)
Expand Down Expand Up @@ -406,11 +417,11 @@ TCNT2 = 0; \
#define TIMER_INTR_NAME TIMER1_COMPA_vect

#define TIMER_CONFIG_KHZ(val) ({ \
const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
const uint32_t pwmval = SYSCLOCK / 2000 / (val); \
TCCR1A = _BV(WGM11); \
TCCR1B = _BV(WGM13) | _BV(CS10); \
ICR1 = pwmval; \
OCR1A = pwmval / (100/DUTY_CYCLE); \
OCR1A = pwmval * DUTY_CYCLE / 100; \
})

#define TIMER_CONFIG_NORMAL() ({ \
Expand Down Expand Up @@ -456,11 +467,11 @@ TCNT1 = 0; \
#define TIMER_INTR_NAME TIMER3_COMPA_vect

#define TIMER_CONFIG_KHZ(val) ({ \
const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
const uint32_t pwmval = SYSCLOCK / 2000 / (val); \
TCCR3A = _BV(WGM31); \
TCCR3B = _BV(WGM33) | _BV(CS30); \
ICR3 = pwmval; \
OCR3A = pwmval / (100/DUTY_CYCLE); \
OCR3A = pwmval * DUTY_CYCLE / 100; \
})

#define TIMER_CONFIG_NORMAL() ({ \
Expand Down Expand Up @@ -504,16 +515,16 @@ TCNT1 = 0; \
#define TIMER_INTR_NAME TIMER4_OVF_vect

#define TIMER_CONFIG_KHZ(val) ({ \
const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
const uint32_t pwmval = SYSCLOCK / 2000 / (val); \
TCCR4A = (1<<PWM4A); \
TCCR4B = _BV(CS40); \
TCCR4C = 0; \
TCCR4D = (1<<WGM40); \
TCCR4E = 0; \
TC4H = pwmval >> 8; \
OCR4C = pwmval; \
TC4H = (pwmval / (100/DUTY_CYCLE)) >> 8; \
OCR4A = (pwmval / (100/DUTY_CYCLE)) & 255; \
TC4H = (pwmval * DUTY_CYCLE / 100) >> 8; \
OCR4A = (pwmval * DUTY_CYCLE / 100) & 255; \
})

#define TIMER_CONFIG_NORMAL() ({ \
Expand Down Expand Up @@ -552,11 +563,11 @@ TCNT4 = 0; \
#define TIMER_INTR_NAME TIMER4_COMPA_vect

#define TIMER_CONFIG_KHZ(val) ({ \
const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
const uint32_t pwmval = SYSCLOCK / 2000 / (val); \
TCCR4A = _BV(WGM41); \
TCCR4B = _BV(WGM43) | _BV(CS40); \
ICR4 = pwmval; \
OCR4A = pwmval / (100/DUTY_CYCLE); \
OCR4A = pwmval * DUTY_CYCLE / 100; \
})

#define TIMER_CONFIG_NORMAL() ({ \
Expand Down Expand Up @@ -588,11 +599,11 @@ TCNT4 = 0; \
#define TIMER_INTR_NAME TIMER5_COMPA_vect

#define TIMER_CONFIG_KHZ(val) ({ \
const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
const uint32_t pwmval = SYSCLOCK / 2000 / (val); \
TCCR5A = _BV(WGM51); \
TCCR5B = _BV(WGM53) | _BV(CS50); \
ICR5 = pwmval; \
OCR5A = pwmval / (100/DUTY_CYCLE); \
OCR5A = pwmval * DUTY_CYCLE / 100; \
})

#define TIMER_CONFIG_NORMAL() ({ \
Expand Down Expand Up @@ -714,11 +725,11 @@ FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_PS(0) | FTM_SC_TOF | FTM_SC_TOIE; \
#define TIMER_DISABLE_INTR (TIMSK &= ~(_BV(OCIE0A)))
#define TIMER_INTR_NAME TIMER0_COMPA_vect
#define TIMER_CONFIG_KHZ(val) ({ \
const uint8_t pwmval = SYSCLOCK / 2000 / (val); \
const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
TCCR0A = _BV(WGM00); \
TCCR0B = _BV(WGM02) | _BV(CS00); \
OCR0A = pwmval; \
OCR0B = pwmval / (100/DUTY_CYCLE); \
OCR0B = pwmval * DUTY_CYCLE / 100; \
})
#define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000)
#if (TIMER_COUNT_TOP < 256)
Expand All @@ -739,6 +750,30 @@ FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_PS(0) | FTM_SC_TOF | FTM_SC_TOIE; \

#define IR_SEND_PIN 1 /* ATtiny85 */

#elif defined(IR_USE_TIMER_4809_1)
// ATmega4809 TCB0
#define TIMER_RESET TCB0.INTFLAGS = TCB_CAPT_bm
#define TIMER_ENABLE_PWM (TCB0.CTRLB = TCB_CNTMODE_PWM8_gc)
#define TIMER_DISABLE_PWM (TCB0.CTRLB &= ~(TCB_CNTMODE_PWM8_gc))
#define TIMER_ENABLE_INTR (TCB0.INTCTRL = TCB_CAPT_bm)
#define TIMER_DISABLE_INTR (TCB0.INTCTRL &= ~(TCB_CAPT_bm))
#define TIMER_INTR_NAME TCB0_INT_vect
#define TIMER_CONFIG_KHZ(val) ({ \
const uint32_t pwmval = SYSCLOCK / 2000 / (val); \
TCB0.CTRLB = TCB_CNTMODE_PWM8_gc; \
TCB0.CCMPL = pwmval; \
TCB0.CCMPH = pwmval * DUTY_CYCLE / 100; \
TCB0.CTRLA = (TCB_CLKSEL_CLKDIV1_gc) | (TCB_ENABLE_bm); \
})
#define TIMER_COUNT_TOP ((SYSCLOCK * USECPERTICK / 1000000))
#define TIMER_CONFIG_NORMAL() ({ \
TCB0.CTRLB = (TCB_CNTMODE_INT_gc); \
TCB0.CCMP = TIMER_COUNT_TOP; \
TCB0.INTCTRL = TCB_CAPT_bm; \
TCB0.CTRLA = (TCB_CLKSEL_CLKDIV1_gc) | (TCB_ENABLE_bm); \
})

#define TIMER_PWM_PIN 6 /* Nano Every, Uno WiFi Rev2 */
//---------------------------------------------------------
// ESP32 (ESP8266 should likely be added here too)
//
Expand Down

0 comments on commit ffd08fb

Please sign in to comment.