Skip to content

Commit

Permalink
Squashed 'avr/cores/MCUdude_corefiles/' changes from b1703a37..21b32d15
Browse files Browse the repository at this point in the history
21b32d15 Add support for AVR 5 and 9 series
88a427b0 Add support for AVR 5 and 9 series
54808586 Reorder macro checking To prevent GCC poison error on when compiling for ATmega165

git-subtree-dir: avr/cores/MCUdude_corefiles
git-subtree-split: 21b32d156a382b9945e7c7066c3c32dd62832fd5
  • Loading branch information
MCUdude committed Apr 22, 2022
1 parent 4fb8562 commit 110008d
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 79 deletions.
6 changes: 3 additions & 3 deletions HardwareSerial0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@

#if defined(HAVE_HWSERIAL0)

#if defined(USART_RX_vect)
ISR(USART_RX_vect)
#elif defined(USART0_RX_vect)
#if defined(USART0_RX_vect)
ISR(USART0_RX_vect)
#elif defined(USART0_RXC_vect)
ISR(USART0_RXC_vect)
#elif defined(USART_RXC_vect)
ISR(USART_RXC_vect)
#elif defined(USART_RX_vect)
ISR(USART_RX_vect)
#else
#error "Don't know what the Data Received vector is called for Serial"
#endif
Expand Down
39 changes: 28 additions & 11 deletions Tone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,24 @@ volatile uint8_t timer2_pin_mask;
#define USE_TIMER3
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 3 /*, 1 */ };
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255 */ };


#elif defined(__AVR_ATmega165__) || defined(__AVR_ATmega165A__) || defined(__AVR_ATmega165P__) \
|| defined(__AVR_ATmega165PA__) || defined(__AVR_ATmega325__) || defined(__AVR_ATmega325A__) \
|| defined(__AVR_ATmega325P__) || defined(__AVR_ATmega325PA__) || defined(__AVR_ATmega3250__) \
|| defined(__AVR_ATmega3250A__) || defined(__AVR_ATmega3250P__) || defined(__AVR_ATmega3250PA__) \
|| defined(__AVR_ATmega645__) || defined(__AVR_ATmega645A__) || defined(__AVR_ATmega645P__) \
|| defined(__AVR_ATmega6450__) || defined(__AVR_ATmega6450A__) || defined(__AVR_ATmega6450P__) \
|| defined(__AVR_ATmega169__) || defined(__AVR_ATmega169A__) || defined(__AVR_ATmega169P__) \
|| defined(__AVR_ATmega169PA__) || defined(__AVR_ATmega329__) || defined(__AVR_ATmega329A__) \
|| defined(__AVR_ATmega329P__) || defined(__AVR_ATmega329PA__) || defined(__AVR_ATmega3290__) \
|| defined(__AVR_ATmega3290A__) || defined(__AVR_ATmega3290P__) || defined(__AVR_ATmega3290PA__) \
|| defined(__AVR_ATmega649__) || defined(__AVR_ATmega649A__) || defined(__AVR_ATmega649P__) \
|| defined(__AVR_ATmega6490__) || defined(__AVR_ATmega6490A__) || defined(__AVR_ATmega6490P__)
#define AVAILABLE_TONE_PINS 1
#define USE_TIMER1
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 1 };
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 };

#else // Generic
#define AVAILABLE_TONE_PINS 1
#define USE_TIMER2
Expand All @@ -136,26 +153,26 @@ volatile uint8_t timer2_pin_mask;
#endif

// Identifies the timer which has prescaler values 1/8/32/64/128/256/1024
// Other timers are lacking 32 and 128 because clock select bits are used
// Other timers are lacking 32 and 128 because clock select bits are used
// for external clock input
#if defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
#define TIMER_WITH_FULL_PRESCALER 0
#define TIMER_WITH_FULL_PRESCALER 0
#else
#define TIMER_WITH_FULL_PRESCALER 2
#define TIMER_WITH_FULL_PRESCALER 2
#endif


static int8_t toneBegin(uint8_t _pin)
{
int8_t _timer = -1;

// if we're already using the pin, the timer should be configured.
// if we're already using the pin, the timer should be configured.
for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
if (tone_pins[i] == _pin) {
return pgm_read_byte(tone_pin_to_timer_PGM + i);
}
}

// search for an unused timer.
for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
if (tone_pins[i] == 255) {
Expand All @@ -164,7 +181,7 @@ static int8_t toneBegin(uint8_t _pin)
break;
}
}

if (_timer != -1)
{
// Set timer specific stuff
Expand Down Expand Up @@ -273,7 +290,7 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
{
// Set the pinMode as OUTPUT
pinMode(_pin, OUTPUT);

// if we are using an 8 bit timer, scan through prescalars to find the best fit
if (_timer == 0 || _timer == 2)
{
Expand Down Expand Up @@ -364,7 +381,7 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
#endif

}


// Calculate the toggle count
if (duration > 0)
Expand Down Expand Up @@ -500,15 +517,15 @@ void disableTimer(uint8_t _timer)
void noTone(uint8_t _pin)
{
int8_t _timer = -1;

for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
if (tone_pins[i] == _pin) {
_timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
tone_pins[i] = 255;
break;
}
}

disableTimer(_timer);

digitalWrite(_pin, 0);
Expand Down
Loading

0 comments on commit 110008d

Please sign in to comment.