Hello,
I am back with my pins_arduino.h for the ATmega2561. If you care to take a look at it, maybe you can find any errors. I don't know if I correctly modified the second set of definitions where I have maked them old/new. I am not sure how to write these definitions.
I arranged the pins in an order that reflects the pin order of the chip pins.
What do you think? Oh, I left off the last table because the file was to big
Stank
$Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
#define NUM_DIGITAL_PINS 54
#define NUM_ANALOG_INPUTS 8
#define analogInputToDigitalPin(p) ((p < 8) ? (p) + 46 : -1)
//old#define analogInputToDigitalPin(p) ((p < 16) ? (p) + 54 : -1)
#define digitalPinHasPWM(p) (((p) >= 3 && (p) <= 5) || ((p) >= 12 && (p)<= 15))
//old#define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p)<= 46))
static const uint8_t SS = 8;
static const uint8_t SCK = 9;
static const uint8_t MOSI = 10;
static const uint8_t MISO = 11;
static const uint8_t SCL = 16;
static const uint8_t SDA = 17;
static const uint8_t LED_BUILTIN = 13;
static const uint8_t A0 = 53;
static const uint8_t A1 = 52;
static const uint8_t A2 = 51;
static const uint8_t A3 = 50;
static const uint8_t A4 = 49;
static const uint8_t A5 = 48;
static const uint8_t A6 = 47;
static const uint8_t A7 = 46;
// 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
//old#define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 13)) || \
//old (((p) >= 50) && ((p) <= 53)) || \
//old (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
#define digitalPinToPCICR(p) ( (((p) >= 12) && ((p) <= 15)) || \
(((p) >= 8) && ((p) <= 11)) || \
(((p) >= 54) && ((p) <= 53)) ? (&PCICR) : ((uint8_t *)0) )
//old#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
//old ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
//old 0 ) )
#define digitalPinToPCICRbit(p) ( (((p) >= 12) && ((p) <= 15)) || (((p) >= 8) && ((p) <= 11)) ? 0 : \
( (((p) >= 54) && ((p) <= 53)) ? 2 : \
0 ) )
//old#define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
//old ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
//old ((uint8_t *)0) ) )
#define digitalPinToPCMSK(p) ( (((p) >= 12) && ((p) <= 15)) || (((p) >= 8) && ((p) <= 11)) ? (&PCMSK0) : \
( (((p) >= 54) && ((p) <= 53)) ? (&PCMSK2) : \
((uint8_t *)0) ) )
//old#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 ) ) ) ) ) )
#define digitalPinToPCMSKbit(p) ( (((p) >= 12) && ((p) <= 15)) ? ((p) - 6) : \
( ((p) == 11) ? 3 : \
( ((p) == 10) ? 2 : \
( ((p) == 9) ? 1 : \
( ((p) == 8) ? 0 : \
( (((p) >= 54) && ((p) <= 53)) ? ((p) - 54) : \
0 ) ) ) ) ) )
#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,
};
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,
};
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,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
// PORTLIST
// -------------------------------------------
PE , // PE 0 ** 0 ** USART0_RX
PE , // PE 1 ** 1 ** USART0_TX
PE , // PE 2 ** 2 ** D2
PE , // PE 3 ** 3 ** PWM1
PE , // PE 4 ** 4 ** PWM2
PE , // PE 5 ** 5 ** PWM3
PE , // PE 6 ** 6 ** D6
PE , // PE 7 ** 7 ** D7
PB , // PB 0 ** 8 ** SPI_SS
PB , // PB 1 ** 9 ** SPI_SCK
PB , // PB 2 ** 10 ** SPI_MOSI
PB , // PB 3 ** 11 ** SPI_MISO
PB , // PB 4 ** 12 ** PWM4
PB , // PB 5 ** 13 ** PWM5
PB , // PB 6 ** 14 ** PWM6
PB , // PB 7 ** 15 ** PWM7
PD , // PD 0 ** 16 ** I2C_SCL
PD , // PD 1 ** 17 ** I2C_SDA
PD , // PD 2 ** 18 ** USART1_RX
PD , // PD 3 ** 19 ** USART1_TX
PD , // PD 4 ** 20 ** D20
PD , // PD 5 ** 21 ** D21
PD , // PD 6 ** 22 ** D22
PD , // PD 7 ** 23 ** D23
PC , // PC 0 ** 24 ** D24
PC , // PC 1 ** 25 ** D25
PC , // PC 2 ** 26 ** D26
PC , // PC 3 ** 27 ** D27
PC , // PC 4 ** 28 ** D28
PC , // PC 5 ** 29 ** D29
PC , // PC 6 ** 30 ** D30
PC , // PC 7 ** 31 ** D31
PA , // PA 7 ** 32 ** D32
PA , // PA 6 ** 33 ** D33
PA , // PA 5 ** 34 ** D34
PA , // PA 4 ** 35 ** D35
PA , // PA 3 ** 36 ** D36
PA , // PA 2 ** 37 ** D37
PA , // PA 1 ** 38 ** D38
PA , // PA 0 ** 39 ** D39
PG , // PG 0 ** 40 ** D40
PG , // PG 1 ** 41 ** D41
PG , // PG 2 ** 42 ** D42
PG , // PG 3 ** 43 ** D43
PG , // PG 4 ** 44 ** D44
PG , // PG 5 ** 45 ** PWM8
PF , // PF 7 ** 46 ** A7
PF , // PF 6 ** 47 ** A6
PF , // PF 5 ** 48 ** A5
PF , // PF 4 ** 49 ** A4
PF , // PF 3 ** 50 ** A3
PF , // PF 2 ** 51 ** A2
PF , // PF 1 ** 52 ** A1
PF , // PF 0 ** 53 ** A0
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
// PIN IN PORT
// -------------------------------------------
_BV( 0 ) , // PE 0 ** 0 ** USART0_RX
_BV( 1 ) , // PE 1 ** 1 ** USART0_TX
_BV( 2 ) , // PE 2 ** 2 ** D2
_BV( 3 ) , // PE 3 ** 3 ** PWM1
_BV( 4 ) , // PE 4 ** 4 ** PWM2
_BV( 5 ) , // PE 5 ** 5 ** PWM3
_BV( 6 ) , // PE 6 ** 6 ** D6
_BV( 7 ) , // PE 7 ** 7 ** D7
_BV( 0 ) , // PB 0 ** 8 ** SPI_SS
_BV( 1 ) , // PB 1 ** 9 ** SPI_SCK
_BV( 2 ) , // PB 2 ** 10 ** SPI_MOSI
_BV( 3 ) , // PB 3 ** 11 ** SPI_MISO
_BV( 4 ) , // PB 4 ** 12 ** PWM4
_BV( 5 ) , // PB 5 ** 13 ** PWM5
_BV( 6 ) , // PB 6 ** 14 ** PWM6
_BV( 7 ) , // PB 7 ** 15 ** PWM7
_BV( 0 ) , // PD 0 ** 16 ** I2C_SCL
_BV( 1 ) , // PD 1 ** 17 ** I2C_SDA
_BV( 2 ) , // PD 2 ** 18 ** USART1_RX
_BV( 3 ) , // PD 3 ** 19 ** USART1_TX
_BV( 4 ) , // PD 4 ** 20 ** D20
_BV( 5 ) , // PD 5 ** 21 ** D21
_BV( 6 ) , // PD 6 ** 22 ** D22
_BV( 7 ) , // PD 7 ** 23 ** D23
_BV( 0 ) , // PC 0 ** 24 ** D24
_BV( 1 ) , // PC 1 ** 25 ** D25
_BV( 2 ) , // PC 2 ** 26 ** D26
_BV( 3 ) , // PC 3 ** 27 ** D27
_BV( 4 ) , // PC 4 ** 28 ** D28
_BV( 5 ) , // PC 5 ** 29 ** D29
_BV( 6 ) , // PC 6 ** 30 ** D30
_BV( 7 ) , // PC 7 ** 31 ** D31
_BV( 7 ) , // PA 7 ** 32 ** D32
_BV( 6 ) , // PA 6 ** 33 ** D33
_BV( 5 ) , // PA 5 ** 34 ** D34
_BV( 4 ) , // PA 4 ** 35 ** D35
_BV( 3 ) , // PA 3 ** 36 ** D36
_BV( 2 ) , // PA 2 ** 37 ** D37
_BV( 1 ) , // PA 1 ** 38 ** D38
_BV( 0 ) , // PA 0 ** 39 ** D39
_BV( 0 ) , // PG 0 ** 40 ** D40
_BV( 1 ) , // PG 1 ** 41 ** D41
_BV( 2 ) , // PG 2 ** 42 ** D42
_BV( 3 ) , // PG 3 ** 43 ** D43
_BV( 4 ) , // PG 4 ** 44 ** D44
_BV( 5 ) , // PG 5 ** 45 ** PWM8
_BV( 7 ) , // PF 7 ** 46 ** A7
_BV( 6 ) , // PF 6 ** 47 ** A6
_BV( 5 ) , // PF 5 ** 48 ** A5
_BV( 4 ) , // PF 4 ** 49 ** A4
_BV( 3 ) , // PF 3 ** 50 ** A3
_BV( 2 ) , // PF 2 ** 51 ** A2
_BV( 1 ) , // PF 1 ** 52 ** A1
_BV( 0 ) , // PF 0 ** 53 ** A0
};