From 67330bb22c04bfd75067d2e395857c2eff2e514b Mon Sep 17 00:00:00 2001 From: Rafi Khan Date: Thu, 23 Jul 2015 19:12:23 -0600 Subject: [PATCH] Add support for ATtiny85 --- IRremoteInt.h | 36 ++++++++++++++++++++++++++++++ examples/IRsendDemo/IRsendDemo.ino | 3 --- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/IRremoteInt.h b/IRremoteInt.h index 60f744a..47c6123 100644 --- a/IRremoteInt.h +++ b/IRremoteInt.h @@ -195,6 +195,10 @@ EXTERN volatile irparams_t irparams; #elif defined(__AVR_ATtiny84__) #define IR_USE_TIMER1 +//ATtiny85 +#elif defined(__AVR_ATtiny85__) + #define IR_USE_TIMER_TINY0 // tx = pin 1 + // Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc #else //#define IR_USE_TIMER1 // tx = pin 9 @@ -551,7 +555,39 @@ EXTERN volatile irparams_t irparams; }) #define TIMER_PWM_PIN 16 +// defines for timer_tiny0 (8 bits) +#elif defined(IR_USE_TIMER_TINY0) +#define TIMER_RESET +#define TIMER_ENABLE_PWM (TCCR0A |= _BV(COM0B1)) +#define TIMER_DISABLE_PWM (TCCR0A &= ~(_BV(COM0B1))) +#define TIMER_ENABLE_INTR (TIMSK |= _BV(OCIE0A)) +#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); \ + TCCR0A = _BV(WGM00); \ + TCCR0B = _BV(WGM02) | _BV(CS00); \ + OCR0A = pwmval; \ + OCR0B = pwmval / 3; \ +}) +#define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000) +#if (TIMER_COUNT_TOP < 256) +#define TIMER_CONFIG_NORMAL() ({ \ + TCCR0A = _BV(WGM01); \ + TCCR0B = _BV(CS00); \ + OCR0A = TIMER_COUNT_TOP; \ + TCNT0 = 0; \ +}) +#else +#define TIMER_CONFIG_NORMAL() ({ \ + TCCR0A = _BV(WGM01); \ + TCCR0B = _BV(CS01); \ + OCR0A = TIMER_COUNT_TOP / 8; \ + TCNT0 = 0; \ +}) +#endif +#define TIMER_PWM_PIN 1 /* ATtiny85 */ //--------------------------------------------------------- // Unknown Timer diff --git a/examples/IRsendDemo/IRsendDemo.ino b/examples/IRsendDemo/IRsendDemo.ino index a21af31..e3772ed 100644 --- a/examples/IRsendDemo/IRsendDemo.ino +++ b/examples/IRsendDemo/IRsendDemo.ino @@ -12,14 +12,11 @@ IRsend irsend; void setup() { - Serial.begin(9600); } void loop() { - if (Serial.read() != -1) { for (int i = 0; i < 3; i++) { irsend.sendSony(0xa90, 12); // Sony TV power code delay(40); } - } }