Last active
August 15, 2016 01:40
-
-
Save paulo-raca/78f7448f18121b014ccabf6997209e7f to your computer and use it in GitHub Desktop.
Arduino support for ATMEGA2560 -- With ALL ports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
pins_arduino.h - Pin definition functions for Arduino | |
Part of Arduino - http://www.arduino.cc/ | |
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 | |
License as published by the Free Software Foundation; either | |
version 2.1 of the License, or (at your option) any later version. | |
This library is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
Lesser General Public License for more details. | |
You should have received a copy of the GNU Lesser General | |
Public License along with this library; if not, write to the | |
Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
Boston, MA 02111-1307 USA | |
*/ | |
#ifndef Pins_Arduino_h | |
#define Pins_Arduino_h | |
#include <avr/pgmspace.h> | |
#define PIN_PA_BASE 0x00 | |
#define PIN_PA0 (PIN_PA_BASE+0) | |
#define PIN_PA1 (PIN_PA_BASE+1) | |
#define PIN_PA2 (PIN_PA_BASE+2) | |
#define PIN_PA3 (PIN_PA_BASE+3) | |
#define PIN_PA4 (PIN_PA_BASE+4) | |
#define PIN_PA5 (PIN_PA_BASE+5) | |
#define PIN_PA6 (PIN_PA_BASE+6) | |
#define PIN_PA7 (PIN_PA_BASE+7) | |
#define PIN_PB_BASE 0x08 | |
#define PIN_PB0 (PIN_PB_BASE+0) | |
#define PIN_PB1 (PIN_PB_BASE+1) | |
#define PIN_PB2 (PIN_PB_BASE+2) | |
#define PIN_PB3 (PIN_PB_BASE+3) | |
#define PIN_PB4 (PIN_PB_BASE+4) | |
#define PIN_PB5 (PIN_PB_BASE+5) | |
#define PIN_PB6 (PIN_PB_BASE+6) | |
#define PIN_PB7 (PIN_PB_BASE+7) | |
#define PIN_PC_BASE 0x10 | |
#define PIN_PC0 (PIN_PC_BASE+0) | |
#define PIN_PC1 (PIN_PC_BASE+1) | |
#define PIN_PC2 (PIN_PC_BASE+2) | |
#define PIN_PC3 (PIN_PC_BASE+3) | |
#define PIN_PC4 (PIN_PC_BASE+4) | |
#define PIN_PC5 (PIN_PC_BASE+5) | |
#define PIN_PC6 (PIN_PC_BASE+6) | |
#define PIN_PC7 (PIN_PC_BASE+7) | |
#define PIN_PD_BASE 0x18 | |
#define PIN_PD0 (PIN_PD_BASE+0) | |
#define PIN_PD1 (PIN_PD_BASE+1) | |
#define PIN_PD2 (PIN_PD_BASE+2) | |
#define PIN_PD3 (PIN_PD_BASE+3) | |
#define PIN_PD4 (PIN_PD_BASE+4) | |
#define PIN_PD5 (PIN_PD_BASE+5) | |
#define PIN_PD6 (PIN_PD_BASE+6) | |
#define PIN_PD7 (PIN_PD_BASE+7) | |
#define PIN_PE_BASE 0x20 | |
#define PIN_PE0 (PIN_PE_BASE+0) | |
#define PIN_PE1 (PIN_PE_BASE+1) | |
#define PIN_PE2 (PIN_PE_BASE+2) | |
#define PIN_PE3 (PIN_PE_BASE+3) | |
#define PIN_PE4 (PIN_PE_BASE+4) | |
#define PIN_PE5 (PIN_PE_BASE+5) | |
#define PIN_PE6 (PIN_PE_BASE+6) | |
#define PIN_PE7 (PIN_PE_BASE+7) | |
#define PIN_PF_BASE 0x28 | |
#define PIN_PF0 (PIN_PF_BASE+0) | |
#define PIN_PF1 (PIN_PF_BASE+1) | |
#define PIN_PF2 (PIN_PF_BASE+2) | |
#define PIN_PF3 (PIN_PF_BASE+3) | |
#define PIN_PF4 (PIN_PF_BASE+4) | |
#define PIN_PF5 (PIN_PF_BASE+5) | |
#define PIN_PF6 (PIN_PF_BASE+6) | |
#define PIN_PF7 (PIN_PF_BASE+7) | |
#define PIN_PG_BASE 0x30 | |
#define PIN_PG0 (PIN_PG_BASE+0) | |
#define PIN_PG1 (PIN_PG_BASE+1) | |
#define PIN_PG2 (PIN_PG_BASE+2) | |
#define PIN_PG3 (PIN_PG_BASE+3) | |
#define PIN_PG4 (PIN_PG_BASE+4) | |
#define PIN_PG5 (PIN_PG_BASE+5) | |
// #define PIN_PG6 (PIN_PG_BASE+6) | |
// #define PIN_PG7 (PIN_PG_BASE+7) | |
#define PIN_PH_BASE 0x38 | |
#define PIN_PH0 (PIN_PH_BASE+0) | |
#define PIN_PH1 (PIN_PH_BASE+1) | |
#define PIN_PH2 (PIN_PH_BASE+2) | |
#define PIN_PH3 (PIN_PH_BASE+3) | |
#define PIN_PH4 (PIN_PH_BASE+4) | |
#define PIN_PH5 (PIN_PH_BASE+5) | |
#define PIN_PH6 (PIN_PH_BASE+6) | |
#define PIN_PH7 (PIN_PH_BASE+7) | |
// #define PIN_PI_BASE 0x40 | |
// #define PIN_PI0 (PIN_PI_BASE+0) | |
// #define PIN_PI1 (PIN_PI_BASE+1) | |
// #define PIN_PI2 (PIN_PI_BASE+2) | |
// #define PIN_PI3 (PIN_PI_BASE+3) | |
// #define PIN_PI4 (PIN_PI_BASE+4) | |
// #define PIN_PI5 (PIN_PI_BASE+5) | |
// #define PIN_PI6 (PIN_PI_BASE+6) | |
// #define PIN_PI7 (PIN_PI_BASE+7) | |
#define PIN_PJ_BASE 0x48 | |
#define PIN_PJ0 (PIN_PJ_BASE+0) | |
#define PIN_PJ1 (PIN_PJ_BASE+1) | |
#define PIN_PJ2 (PIN_PJ_BASE+2) | |
#define PIN_PJ3 (PIN_PJ_BASE+3) | |
#define PIN_PJ4 (PIN_PJ_BASE+4) | |
#define PIN_PJ5 (PIN_PJ_BASE+5) | |
#define PIN_PJ6 (PIN_PJ_BASE+6) | |
// #define PIN_PJ7 (PIN_PJ_BASE+7) | |
#define PIN_PK_BASE 0x50 | |
#define PIN_PK0 (PIN_PK_BASE+0) | |
#define PIN_PK1 (PIN_PK_BASE+1) | |
#define PIN_PK2 (PIN_PK_BASE+2) | |
#define PIN_PK3 (PIN_PK_BASE+3) | |
#define PIN_PK4 (PIN_PK_BASE+4) | |
#define PIN_PK5 (PIN_PK_BASE+5) | |
#define PIN_PK6 (PIN_PK_BASE+6) | |
#define PIN_PK7 (PIN_PK_BASE+7) | |
#define PIN_PL_BASE 0x58 | |
#define PIN_PL0 (PIN_PL_BASE+0) | |
#define PIN_PL1 (PIN_PL_BASE+1) | |
#define PIN_PL2 (PIN_PL_BASE+2) | |
#define PIN_PL3 (PIN_PL_BASE+3) | |
#define PIN_PL4 (PIN_PL_BASE+4) | |
#define PIN_PL5 (PIN_PL_BASE+5) | |
#define PIN_PL6 (PIN_PL_BASE+6) | |
#define PIN_PL7 (PIN_PL_BASE+7) | |
#define NUM_DIGITAL_PINS PIN_PL7+1 | |
#define NUM_ANALOG_INPUTS 16 | |
#define analogInputToDigitalPin(p) ((((p) >= 0) && ((p) < 8)) ? (PIN_PF0 + (p) - 0 + ) : \ | |
(((p) >= 8) && ((p) < 16)) ? (PIN_PK0 + (p) - 8) : \ | |
(-1)) | |
#define digitalPinHasPWM(p) ( \ | |
((p) >= PIN_PB4 && (p) <= PIN_PB7) || \ | |
((p) >= PIN_PE3 && (p) <= PIN_PE5) || \ | |
((p) == PIN_PG5) || \ | |
((p) >= PIN_PH3 && (p) <= PIN_PH6) || \ | |
((p) >= PIN_PL3 && (p) <= PIN_PL5) \ | |
) | |
#define PIN_SPI_SS PIN_PB0 | |
#define PIN_SPI_SCK PIN_PB1 | |
#define PIN_SPI_MOSI PIN_PB2 | |
#define PIN_SPI_MISO PIN_PB3 | |
static const uint8_t SS = PIN_SPI_SS; | |
static const uint8_t MOSI = PIN_SPI_MOSI; | |
static const uint8_t MISO = PIN_SPI_MISO; | |
static const uint8_t SCK = PIN_SPI_SCK; | |
#define PIN_WIRE_SCL PIN_PD0 | |
#define PIN_WIRE_SDA PIN_PD1 | |
static const uint8_t SDA = PIN_WIRE_SDA; | |
static const uint8_t SCL = PIN_WIRE_SCL; | |
#define LED_BUILTIN PIN_PE3 | |
//FIXME ============ | |
// A majority of the pins are NOT PCINTs, | |
#define digitalPinToPCICR(p) ((((p) >= PIN_PB0) && ((p) <= PIN_PB7)) ? (&PCICR) : \ | |
(((p) >= PIN_PJ0) && ((p) <= PIN_PJ6) || ((p) == PIN_PE0)) ? (&PCICR) : \ | |
(((p) >= PIN_PK0) && ((p) <= PIN_PK7)) ? (&PCICR) : \ | |
((uint8_t *)0)) | |
#define digitalPinToPCICRbit(p) ((((p) >= PIN_PB0) && ((p) <= PIN_PB7)) ? (0) : \ | |
(((p) >= PIN_PJ0) && ((p) <= PIN_PJ6) || ((p) == PIN_PE0)) ? (1) : \ | |
(((p) >= PIN_PK0) && ((p) <= PIN_PK7)) ? (2) : \ | |
(0)) | |
#define digitalPinToPCMSK(p) ((((p) >= PIN_PB0) && ((p) <= PIN_PB7)) ? (&PCMSK0) : \ | |
(((p) >= PIN_PJ0) && ((p) <= PIN_PJ6) || ((p) == PIN_PE0)) ? (&PCMSK1) : \ | |
(((p) >= PIN_PK0) && ((p) <= PIN_PK7)) ? (&PCMSK2) : \ | |
(0)) | |
#define digitalPinToPCMSKbit(p) ((((p) >= PIN_PB0) && ((p) <= PIN_PB7)) ? ((p)-PIN_PB0) : \ | |
(((p) >= PIN_PJ0) && ((p) <= PIN_PJ6)) ? ((p)-PIN_PJ0+1) : \ | |
(((p) == PIN_PE0)) ? (0) : \ | |
(((p) >= PIN_PK0) && ((p) <= PIN_PK7)) ? ((p)-PIN_PK0) : \ | |
(0)) | |
#define digitalPinToInterrupt(p) ((((p) >= PIN_PD0) && ((p) <= PIN_PD3)) ? ((p)-PIN_PD0) : \ | |
(((p) >= PIN_PE4) && ((p) <= PIN_PE7)) ? ((p)-PIN_PE4) : \ | |
(NOT_AN_INTERRUPT)) | |
#ifdef ARDUINO_MAIN | |
const uint16_t PROGMEM port_to_mode_PGM[] = { | |
NOT_A_PORT, | |
(uint16_t) &DDRA, | |
(uint16_t) &DDRB, | |
(uint16_t) &DDRC, | |
(uint16_t) &DDRD, | |
(uint16_t) &DDRE, | |
(uint16_t) &DDRF, | |
(uint16_t) &DDRG, | |
(uint16_t) &DDRH, | |
NOT_A_PORT, | |
(uint16_t) &DDRJ, | |
(uint16_t) &DDRK, | |
(uint16_t) &DDRL, | |
}; | |
const uint16_t PROGMEM port_to_output_PGM[] = { | |
NOT_A_PORT, | |
(uint16_t) &PORTA, | |
(uint16_t) &PORTB, | |
(uint16_t) &PORTC, | |
(uint16_t) &PORTD, | |
(uint16_t) &PORTE, | |
(uint16_t) &PORTF, | |
(uint16_t) &PORTG, | |
(uint16_t) &PORTH, | |
NOT_A_PORT, | |
(uint16_t) &PORTJ, | |
(uint16_t) &PORTK, | |
(uint16_t) &PORTL, | |
}; | |
const uint16_t PROGMEM port_to_input_PGM[] = { | |
NOT_A_PIN, | |
(uint16_t) &PINA, | |
(uint16_t) &PINB, | |
(uint16_t) &PINC, | |
(uint16_t) &PIND, | |
(uint16_t) &PINE, | |
(uint16_t) &PINF, | |
(uint16_t) &PING, | |
(uint16_t) &PINH, | |
NOT_A_PIN, | |
(uint16_t) &PINJ, | |
(uint16_t) &PINK, | |
(uint16_t) &PINL, | |
}; | |
const uint8_t PROGMEM digital_pin_to_port_PGM[] = { | |
PA, PA, PA, PA, PA, PA, PA, PA, | |
PB, PB, PB, PB, PB, PB, PB, PB, | |
PC, PC, PC, PC, PC, PC, PC, PC, | |
PD, PD, PD, PD, PD, PD, PD, PD, | |
PE, PE, PE, PE, PE, PE, PE, PE, | |
PF, PF, PF, PF, PF, PF, PF, PF, | |
PG, PG, PG, PG, PG, PG, PG, PG, | |
PH, PH, PH, PH, PH, PH, PH, PH, | |
PI, PI, PI, PI, PI, PI, PI, PI, | |
PJ, PJ, PJ, PJ, PJ, PJ, PJ, PJ, | |
PK, PK, PK, PK, PK, PK, PK, PK, | |
PL, PL, PL, PL, PL, PL, PL, PL | |
}; | |
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { | |
_BV( 0 ), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7), //PA | |
_BV( 0 ), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7), //PB | |
_BV( 0 ), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7), //PC | |
_BV( 0 ), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7), //PD | |
_BV( 0 ), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7), //PE | |
_BV( 0 ), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7), //PF | |
_BV( 0 ), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7), //PG | |
_BV( 0 ), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7), //PH | |
_BV( 0 ), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7), //PI | |
_BV( 0 ), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7), //PJ | |
_BV( 0 ), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7), //PK | |
_BV( 0 ), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7) //PL | |
}; | |
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { | |
NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, //PA | |
NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, TIMER2A, TIMER1A, TIMER1B, TIMER0A, //PB | |
NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, //PC | |
NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, //PD | |
NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, TIMER3A, TIMER3B, TIMER3C, NOT_ON_TIMER, NOT_ON_TIMER, //PE | |
NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, //PF | |
NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, TIMER0B, NOT_ON_TIMER, NOT_ON_TIMER, //PG | |
NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, //PI | |
NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, TIMER4A, TIMER4B, TIMER4C, TIMER2B, NOT_ON_TIMER, //PH | |
NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, //PJ | |
NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, //PK | |
NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, TIMER5A, TIMER5B, TIMER5C, NOT_ON_TIMER, NOT_ON_TIMER //PL | |
}; | |
#endif | |
// These serial port names are intended to allow libraries and architecture-neutral | |
// sketches to automatically default to the correct port name for a particular type | |
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, | |
// the first hardware serial port whose RX/TX pins are not dedicated to another use. | |
// | |
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor | |
// | |
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial | |
// | |
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library | |
// | |
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. | |
// | |
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX | |
// pins are NOT connected to anything by default. | |
#define SERIAL_PORT_MONITOR Serial | |
#define SERIAL_PORT_HARDWARE Serial | |
#define SERIAL_PORT_HARDWARE1 Serial1 | |
#define SERIAL_PORT_HARDWARE2 Serial2 | |
#define SERIAL_PORT_HARDWARE3 Serial3 | |
#define SERIAL_PORT_HARDWARE_OPEN Serial1 | |
#define SERIAL_PORT_HARDWARE_OPEN1 Serial2 | |
#define SERIAL_PORT_HARDWARE_OPEN2 Serial3 | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment