diff options
-rwxr-xr-x | cores/arduino/Arduino.h | 8 | ||||
-rw-r--r-- | cores/arduino/WString.cpp | 2 | ||||
-rwxr-xr-x | cores/arduino/main.cpp | 1 | ||||
-rwxr-xr-x | cores/arduino/wiring.c | 4 | ||||
-rwxr-xr-x | cores/arduino/wiring_digital.c | 1 | ||||
-rw-r--r--[-rwxr-xr-x] | variants/mega/pins_arduino.h | 228 | ||||
-rw-r--r-- | variants/standard/pins_arduino.h | 2 |
7 files changed, 78 insertions, 168 deletions
diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 7f2fc05..ebd374a 100755 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -40,6 +40,11 @@ extern "C"{ #define FALLING 2 #define RISING 3 +#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) +#define DEFAULT 0 +#define EXTERNAL 1 +#define INTERNAL 2 +#else #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #define INTERNAL1V1 2 #define INTERNAL2V56 3 @@ -48,6 +53,7 @@ extern "C"{ #endif #define DEFAULT 1 #define EXTERNAL 0 +#endif // undefine stdlib's abs if encountered #ifdef abs @@ -142,6 +148,7 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; #define NOT_A_PIN 0 #define NOT_A_PORT 0 +#ifdef ARDUINO_MAIN #define PA 1 #define PB 2 #define PC 3 @@ -153,6 +160,7 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; #define PJ 10 #define PK 11 #define PL 12 +#endif #define NOT_ON_TIMER 0 #define TIMER0A 1 diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index ad8d828..3e81331 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -593,7 +593,7 @@ void String::replace(const String& find, const String& replace) if (size == len) return; if (size > capacity && !changeBuffer(size)) return; // XXX: tell user! int index = len - 1; - while ((index = lastIndexOf(find, index)) >= 0) { + while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) { readFrom = buffer + index + find.len; memmove(readFrom + diff, readFrom, len - (readFrom - buffer)); len += diff; diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index 0ef5256..34450f4 100755 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -1,4 +1,3 @@ -#define ARDUINO_MAIN #include <Arduino.h> int main(void) diff --git a/cores/arduino/wiring.c b/cores/arduino/wiring.c index 1b3fd44..bc01949 100755 --- a/cores/arduino/wiring.c +++ b/cores/arduino/wiring.c @@ -221,11 +221,15 @@ void init() // set timer 1 prescale factor to 64 sbi(TCCR1B, CS11); +#if F_CPU >= 8000000L sbi(TCCR1B, CS10); +#endif #elif defined(TCCR1) && defined(CS11) && defined(CS10) sbi(TCCR1, CS11); +#if F_CPU >= 8000000L sbi(TCCR1, CS10); #endif +#endif // put timer 1 in 8-bit phase correct pwm mode #if defined(TCCR1A) && defined(WGM10) sbi(TCCR1A, WGM10); diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index dd1b949..97ef134 100755 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -24,6 +24,7 @@ $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ */ +#define ARDUINO_MAIN #include "wiring_private.h" #include "pins_arduino.h" diff --git a/variants/mega/pins_arduino.h b/variants/mega/pins_arduino.h index 62e10ad..57ec97f 100755..100644 --- a/variants/mega/pins_arduino.h +++ b/variants/mega/pins_arduino.h @@ -1,8 +1,8 @@ /* - pins_arduino.c - pin definitions for the Arduino board - Part of Arduino / Wiring Lite + pins_arduino.h - Pin definition functions for Arduino + Part of Arduino - http://www.arduino.cc/ - Copyright (c) 2005 David A. Mellis + Copyright (c) 2007 David A. Mellis This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -19,66 +19,72 @@ Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - $Id$ + $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ */ -#include <avr/io.h> -#include "wiring_private.h" -#include "pins_arduino.h" +#ifndef Pins_Arduino_h +#define Pins_Arduino_h -// On the Arduino board, digital pins are also used -// for the analog output (software PWM). Analog input -// pins are a separate set. +#include <avr/pgmspace.h> -// ATMEL ATMEGA8 & 168 / ARDUINO -// -// +-\/-+ -// PC6 1| |28 PC5 (AI 5) -// (D 0) PD0 2| |27 PC4 (AI 4) -// (D 1) PD1 3| |26 PC3 (AI 3) -// (D 2) PD2 4| |25 PC2 (AI 2) -// PWM+ (D 3) PD3 5| |24 PC1 (AI 1) -// (D 4) PD4 6| |23 PC0 (AI 0) -// VCC 7| |22 GND -// GND 8| |21 AREF -// PB6 9| |20 AVCC -// PB7 10| |19 PB5 (D 13) -// PWM+ (D 5) PD5 11| |18 PB4 (D 12) -// PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM -// (D 7) PD7 13| |16 PB2 (D 10) PWM -// (D 8) PB0 14| |15 PB1 (D 9) PWM -// +----+ -// -// (PWM+ indicates the additional PWM pins on the ATmega168.) +#define NUM_DIGITAL_PINS 70 +#define NUM_ANALOG_INPUTS 16 +#define analogInputToDigitalPin(p) ((p < 16) ? (p) + 54 : -1) +#define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p)<= 46)) -// ATMEL ATMEGA1280 / ARDUINO -// -// 0-7 PE0-PE7 works -// 8-13 PB0-PB5 works -// 14-21 PA0-PA7 works -// 22-29 PH0-PH7 works -// 30-35 PG5-PG0 works -// 36-43 PC7-PC0 works -// 44-51 PJ7-PJ0 works -// 52-59 PL7-PL0 works -// 60-67 PD7-PD0 works -// A0-A7 PF0-PF7 -// A8-A15 PK0-PK7 +const static uint8_t SS = 53; +const static uint8_t MOSI = 51; +const static uint8_t MISO = 50; +const static uint8_t SCK = 52; -#define PA 1 -#define PB 2 -#define PC 3 -#define PD 4 -#define PE 5 -#define PF 6 -#define PG 7 -#define PH 8 -#define PJ 10 -#define PK 11 -#define PL 12 +const static uint8_t SDA = 20; +const static uint8_t SCL = 21; +const static uint8_t LED_BUILTIN = 13; +const static uint8_t A0 = 54; +const static uint8_t A1 = 55; +const static uint8_t A2 = 56; +const static uint8_t A3 = 57; +const static uint8_t A4 = 58; +const static uint8_t A5 = 59; +const static uint8_t A6 = 60; +const static uint8_t A7 = 61; +const static uint8_t A8 = 62; +const static uint8_t A9 = 63; +const static uint8_t A10 = 64; +const static uint8_t A11 = 65; +const static uint8_t A12 = 66; +const static uint8_t A13 = 67; +const static uint8_t A14 = 68; +const static uint8_t A15 = 69; + +// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins) +// Only pins available for RECEIVE (TRANSMIT can be on any pin): +// (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me) +// Pins: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 + +#define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 13)) || \ + (((p) >= 50) && ((p) <= 53)) || \ + (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) ) + +#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \ + ( (((p) >= 62) && ((p) <= 69)) ? 2 : \ + 0 ) ) + +#define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \ + ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \ + ((uint8_t *)0) ) ) + +#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \ + ( ((p) == 50) ? 3 : \ + ( ((p) == 51) ? 2 : \ + ( ((p) == 52) ? 1 : \ + ( ((p) == 53) ? 0 : \ + ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \ + 0 ) ) ) ) ) ) + +#ifdef ARDUINO_MAIN -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) const uint16_t PROGMEM port_to_mode_PGM[] = { NOT_A_PORT, (uint16_t) &DDRA, @@ -351,115 +357,7 @@ const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { NOT_ON_TIMER , // PK 6 ** 68 ** A14 NOT_ON_TIMER , // PK 7 ** 69 ** A15 }; -#else -// these arrays map port names (e.g. port B) to the -// appropriate addresses for various functions (e.g. reading -// and writing) -const uint16_t PROGMEM port_to_mode_PGM[] = { - NOT_A_PORT, - NOT_A_PORT, - (uint16_t) &DDRB, - (uint16_t) &DDRC, - (uint16_t) &DDRD, -}; - -const uint16_t PROGMEM port_to_output_PGM[] = { - NOT_A_PORT, - NOT_A_PORT, - (uint16_t) &PORTB, - (uint16_t) &PORTC, - (uint16_t) &PORTD, -}; -const uint16_t PROGMEM port_to_input_PGM[] = { - NOT_A_PORT, - NOT_A_PORT, - (uint16_t) &PINB, - (uint16_t) &PINC, - (uint16_t) &PIND, -}; - -const uint8_t PROGMEM digital_pin_to_port_PGM[] = { - PD, /* 0 */ - PD, - PD, - PD, - PD, - PD, - PD, - PD, - PB, /* 8 */ - PB, - PB, - PB, - PB, - PB, - PC, /* 14 */ - PC, - PC, - PC, - PC, - PC, -}; - -const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { - _BV(0), /* 0, port D */ - _BV(1), - _BV(2), - _BV(3), - _BV(4), - _BV(5), - _BV(6), - _BV(7), - _BV(0), /* 8, port B */ - _BV(1), - _BV(2), - _BV(3), - _BV(4), - _BV(5), - _BV(0), /* 14, port C */ - _BV(1), - _BV(2), - _BV(3), - _BV(4), - _BV(5), -}; - -const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { - NOT_ON_TIMER, /* 0 - port D */ - NOT_ON_TIMER, - NOT_ON_TIMER, - // on the ATmega168, digital pin 3 has hardware pwm -#if defined(__AVR_ATmega8__) - NOT_ON_TIMER, -#else - TIMER2B, -#endif - NOT_ON_TIMER, - // on the ATmega168, digital pins 5 and 6 have hardware pwm -#if defined(__AVR_ATmega8__) - NOT_ON_TIMER, - NOT_ON_TIMER, -#else - TIMER0B, - TIMER0A, -#endif - NOT_ON_TIMER, - NOT_ON_TIMER, /* 8 - port B */ - TIMER1A, - TIMER1B, -#if defined(__AVR_ATmega8__) - TIMER2, -#else - TIMER2A, -#endif - NOT_ON_TIMER, - NOT_ON_TIMER, - NOT_ON_TIMER, - NOT_ON_TIMER, /* 14 - port C */ - NOT_ON_TIMER, - NOT_ON_TIMER, - NOT_ON_TIMER, - NOT_ON_TIMER, -}; #endif + +#endif
\ No newline at end of file diff --git a/variants/standard/pins_arduino.h b/variants/standard/pins_arduino.h index 3999d1f..6e774d4 100644 --- a/variants/standard/pins_arduino.h +++ b/variants/standard/pins_arduino.h @@ -44,7 +44,7 @@ const static uint8_t SCK = 13; const static uint8_t SDA = 18; const static uint8_t SCL = 19; -const static uint8_t LED = 13; +const static uint8_t LED_BUILTIN = 13; const static uint8_t A0 = 14; const static uint8_t A1 = 15; |