Support for ATmega169P

Squash and rebase of https://github.com/arduino/Arduino/pull/1989
This commit is contained in:
Frank Oltmanns 2017-11-13 15:19:49 +01:00 committed by Martino Facchin
parent 6c861d8c70
commit 3c18bf7281
4 changed files with 28 additions and 1 deletions

View File

@ -51,6 +51,10 @@ Version Modified By Date Comments
#define TIMSK1 TIMSK
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
// timerx_toggle_count:
// > 0 - duration specified
// = 0 - stopped
@ -189,6 +193,17 @@ static int8_t toneBegin(uint8_t _pin)
break;
#endif
#if defined(TCCR2A) && !defined(TCCR2B)
case 2:
// 8 bit timer
TCCR2A = 0;
bitWrite(TCCR2A, WGM21, 1);
bitWrite(TCCR2A, CS20, 1);
timer2_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer2_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
#if defined(TCCR3A) && defined(TCCR3B) && defined(TIMSK3)
case 3:
// 16 bit timer
@ -306,6 +321,10 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
{
TCCR2B = (TCCR2B & 0b11111000) | prescalarbits;
}
#elif defined(TCCR2A)
{
TCCR2A = (TCCR2A & 0b11111000) | prescalarbits;
}
#else
{
// dummy place holder to make the above ifdefs work
@ -450,6 +469,8 @@ void disableTimer(uint8_t _timer)
#endif
#if defined(TCCR2B) && defined(CS22)
TCCR2B = (TCCR2B & 0b11111000) | (1 << CS22);
#elif defined(TCCR2A) && defined(CS22)
sbi(TCCR2A, CS22); //e.g. ATmega169P
#endif
#if defined(OCR2A)
OCR2A = 0;

View File

@ -309,7 +309,9 @@ void init()
#if defined(TCCR2) && defined(CS22)
sbi(TCCR2, CS22);
#elif defined(TCCR2B) && defined(CS22)
sbi(TCCR2B, CS22);
sbi(TCCR2B, CS22); //e.g. ATmega48PA/88PA/168PA/328P
#elif defined(TCCR2A) && defined(CS22)
sbi(TCCR2A, CS22); //e.g. ATmega169P
//#else
// Timer 2 not finished (may not be present on this CPU)
#endif

View File

@ -50,6 +50,8 @@ int analogRead(uint8_t pin)
if (pin >= 18) pin -= 18; // allow for channel or pin numbers
#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
if (pin >= 24) pin -= 24; // allow for channel or pin numbers
#elif defined(__AVR_ATmega169P__)
if (pin >= 45) pin -= 45; // allow for channel or pin numbers
#else
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
#endif

View File

@ -59,6 +59,8 @@ uint32_t countPulseASM(volatile uint8_t *port, uint8_t bit, uint8_t stateMask, u
#define EXTERNAL_NUM_INTERRUPTS 3
#elif defined(__AVR_ATmega32U4__)
#define EXTERNAL_NUM_INTERRUPTS 5
#elif defined(__AVR_ATmega169P__)
#define EXTERNAL_NUM_INTERRUPTS 1
#else
#define EXTERNAL_NUM_INTERRUPTS 2
#endif