From 3696fa044687542ee6b4a9bc488348e184ee3ae2 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 11 Feb 2011 17:53:24 -0500 Subject: Optimized digitalWrite(), etc. from Alvaro Lopez. --- cores/arduino/pins_arduino.h | 452 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 443 insertions(+), 9 deletions(-) (limited to 'cores/arduino/pins_arduino.h') diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index bc931c5..63f4257 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -49,6 +49,10 @@ #define TIMER5B 15 #define TIMER5C 16 +#ifndef INLINED +#define INLINED static __attribute__((always_inline)) inline +#endif + #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) const static uint8_t SS = 53; const static uint8_t MOSI = 51; @@ -72,17 +76,447 @@ extern const uint8_t PROGMEM digital_pin_to_port_PGM[]; extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]; extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; +// inlined versions of lookup-table-based pin mappings. Don't use directly. + +// Don't use PA, so on, might clash with sketch + +#define PORT_INDEX_PA 1 +#define PORT_INDEX_PB 2 +#define PORT_INDEX_PC 3 +#define PORT_INDEX_PD 4 +#define PORT_INDEX_PE 5 +#define PORT_INDEX_PF 6 +#define PORT_INDEX_PG 7 +#define PORT_INDEX_PH 8 +#define PORT_INDEX_PJ 10 +#define PORT_INDEX_PK 11 +#define PORT_INDEX_PL 12 + +__attribute__((error("Invalid pin specified. This pin does not map to any I/O port"))) static void invalidPinSpecified(void); + + +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) + +INLINED volatile uint8_t *inlined_portModeRegister(uint8_t port_index) +{ + switch (port_index) { + case 1: return &DDRA; + case 2: return &DDRB; + case 3: return &DDRC; + case 4: return &DDRD; + case 5: return &DDRE; + case 6: return &DDRF; + case 7: return &DDRG; + case 8: return &DDRH; + case 10: return &DDRJ; + case 11: return &DDRK; + case 12: return &DDRL; + default: return NOT_A_PORT; + } +} + +INLINED volatile uint8_t *inlined_portOutputRegister(uint8_t port_index) +{ + switch (port_index) { + case 1: return &PORTA; + case 2: return &PORTB; + case 3: return &PORTC; + case 4: return &PORTD; + case 5: return &PORTE; + case 6: return &PORTF; + case 7: return &PORTG; + case 8: return &PORTH; + case 10: return &PORTJ; + case 11: return &PORTK; + case 12: return &PORTL; + default: return NOT_A_PORT; + } +} + +INLINED volatile uint8_t *inlined_portInputRegister(uint8_t port_index) +{ + switch (port_index) { + case 1: return &PINA; + case 2: return &PINB; + case 3: return &PINC; + case 4: return &PIND; + case 5: return &PINE; + case 6: return &PINF; + case 7: return &PING; + case 8: return &PINH; + case 10: return &PINJ; + case 11: return &PINK; + case 12: return &PINL; + default: return NOT_A_PIN; + } +}; + +INLINED uint8_t inlined_digitalPinToPort(uint8_t pin) +{ + switch (pin) { + case 0: // PE 0 ** 0 ** USART0_RX + case 1: // PE 1 ** 1 ** USART0_TX + case 2: // PE 4 ** 2 ** PWM2 + case 3: // PE 5 ** 3 ** PWM3 + return PORT_INDEX_PE; + + case 4: // PG 5 ** 4 ** PWM4 + return PORT_INDEX_PG; + + case 5: // PE 3 ** 5 ** PWM5 + return PORT_INDEX_PE; + + case 6: // PH 3 ** 6 ** PWM6 + case 7: // PH 4 ** 7 ** PWM7 + case 8: // PH 5 ** 8 ** PWM8 + case 9: // PH 6 ** 9 ** PWM9 + return PORT_INDEX_PH; + + case 10: // PB 4 ** 10 ** PWM10 + case 11: // PB 5 ** 11 ** PWM11 + case 12: // PB 6 ** 12 ** PWM12 + case 13: // PB 7 ** 13 ** PWM13 + return PORT_INDEX_PB; + + case 14: // PJ 1 ** 14 ** USART3_TX + case 15: // PJ 0 ** 15 ** USART3_RX + return PORT_INDEX_PJ; + + case 16: // PH 1 ** 16 ** USART2_TX + case 17: // PH 0 ** 17 ** USART2_RX + return PORT_INDEX_PH; + + case 18: // PD 3 ** 18 ** USART1_TX + case 19: // PD 2 ** 19 ** USART1_RX + case 20: // PD 1 ** 20 ** I2C_SDA + case 21: // PD 0 ** 21 ** I2C_SCL + return PORT_INDEX_PD; + + case 22: // PA 0 ** 22 ** D22 + case 23: // PA 1 ** 23 ** D23 + case 24: // PA 2 ** 24 ** D24 + case 25: // PA 3 ** 25 ** D25 + case 26: // PA 4 ** 26 ** D26 + case 27: // PA 5 ** 27 ** D27 + case 28: // PA 6 ** 28 ** D28 + case 29: // PA 7 ** 29 ** D29 + return PORT_INDEX_PA; + + case 30: // PC 7 ** 30 ** D30 + case 31: // PC 6 ** 31 ** D31 + case 32: // PC 5 ** 32 ** D32 + case 33: // PC 4 ** 33 ** D33 + case 34: // PC 3 ** 34 ** D34 + case 35: // PC 2 ** 35 ** D35 + case 36: // PC 1 ** 36 ** D36 + case 37: // PC 0 ** 37 ** D37 + return PORT_INDEX_PC; + + case 38: // PD 7 ** 38 ** D38 + return PORT_INDEX_PD; + + case 39: // PG 2 ** 39 ** D39 + case 40: // PG 1 ** 40 ** D40 + case 41: // PG 0 ** 41 ** D41 + return PORT_INDEX_PG; + + case 42: // PL 7 ** 42 ** D42 + case 43: // PL 6 ** 43 ** D43 + case 44: // PL 5 ** 44 ** D44 + case 45: // PL 4 ** 45 ** D45 + case 46: // PL 3 ** 46 ** D46 + case 47: // PL 2 ** 47 ** D47 + case 48: // PL 1 ** 48 ** D48 + case 49: // PL 0 ** 49 ** D49 + return PORT_INDEX_PL; + + case 50: // PB 3 ** 50 ** SPI_MISO + case 51: // PB 2 ** 51 ** SPI_MOSI + case 52: // PB 1 ** 52 ** SPI_SCK + case 53: // PB 0 ** 53 ** SPI_SS + return PORT_INDEX_PB; + + case 54: // PF 0 ** 54 ** A0 + case 55: // PF 1 ** 55 ** A1 + case 56: // PF 2 ** 56 ** A2 + case 57: // PF 3 ** 57 ** A3 + case 58: // PF 4 ** 58 ** A4 + case 59: // PF 5 ** 59 ** A5 + case 60: // PF 6 ** 60 ** A6 + case 61: // PF 7 ** 61 ** A7 + return PORT_INDEX_PF; + + case 62: // PK 0 ** 62 ** A8 + case 63: // PK 1 ** 63 ** A9 + case 64: // PK 2 ** 64 ** A10 + case 65: // PK 3 ** 65 ** A11 + case 66: // PK 4 ** 66 ** A12 + case 67: // PK 5 ** 67 ** A13 + case 68: // PK 6 ** 68 ** A14 + case 69: // PK 7 ** 69 ** A15 + return PORT_INDEX_PK; + default: + invalidPinSpecified(); + } +} + +INLINED uint8_t inlined_digitalPinToBitMask(uint8_t pin) +{ + switch(pin) { + case 0: return _BV( 0 ); // PE 0 ** 0 ** USART0_RX + case 1: return _BV( 1 ); // PE 1 ** 1 ** USART0_TX + case 2: return _BV( 4 ); // PE 4 ** 2 ** PWM2 + case 3: return _BV( 5 ); // PE 5 ** 3 ** PWM3 + case 4: return _BV( 5 ); // PG 5 ** 4 ** PWM4 + case 5: return _BV( 3 ); // PE 3 ** 5 ** PWM5 + case 6: return _BV( 3 ); // PH 3 ** 6 ** PWM6 + case 7: return _BV( 4 ); // PH 4 ** 7 ** PWM7 + case 8: return _BV( 5 ); // PH 5 ** 8 ** PWM8 + case 9: return _BV( 6 ); // PH 6 ** 9 ** PWM9 + case 10: return _BV( 4 ); // PB 4 ** 10 ** PWM10 + case 11: return _BV( 5 ); // PB 5 ** 11 ** PWM11 + case 12: return _BV( 6 ); // PB 6 ** 12 ** PWM12 + case 13: return _BV( 7 ); // PB 7 ** 13 ** PWM13 + case 14: return _BV( 1 ); // PJ 1 ** 14 ** USART3_TX + case 15: return _BV( 0 ); // PJ 0 ** 15 ** USART3_RX + case 16: return _BV( 1 ); // PH 1 ** 16 ** USART2_TX + case 17: return _BV( 0 ); // PH 0 ** 17 ** USART2_RX + case 18: return _BV( 3 ); // PD 3 ** 18 ** USART1_TX + case 19: return _BV( 2 ); // PD 2 ** 19 ** USART1_RX + case 20: return _BV( 1 ); // PD 1 ** 20 ** I2C_SDA + case 21: return _BV( 0 ); // PD 0 ** 21 ** I2C_SCL + case 22: return _BV( 0 ); // PA 0 ** 22 ** D22 + case 23: return _BV( 1 ); // PA 1 ** 23 ** D23 + case 24: return _BV( 2 ); // PA 2 ** 24 ** D24 + case 25: return _BV( 3 ); // PA 3 ** 25 ** D25 + case 26: return _BV( 4 ); // PA 4 ** 26 ** D26 + case 27: return _BV( 5 ); // PA 5 ** 27 ** D27 + case 28: return _BV( 6 ); // PA 6 ** 28 ** D28 + case 29: return _BV( 7 ); // PA 7 ** 29 ** D29 + case 30: return _BV( 7 ); // PC 7 ** 30 ** D30 + case 31: return _BV( 6 ); // PC 6 ** 31 ** D31 + case 32: return _BV( 5 ); // PC 5 ** 32 ** D32 + case 33: return _BV( 4 ); // PC 4 ** 33 ** D33 + case 34: return _BV( 3 ); // PC 3 ** 34 ** D34 + case 35: return _BV( 2 ); // PC 2 ** 35 ** D35 + case 36: return _BV( 1 ); // PC 1 ** 36 ** D36 + case 37: return _BV( 0 ); // PC 0 ** 37 ** D37 + case 38: return _BV( 7 ); // PD 7 ** 38 ** D38 + case 39: return _BV( 2 ); // PG 2 ** 39 ** D39 + case 40: return _BV( 1 ); // PG 1 ** 40 ** D40 + case 41: return _BV( 0 ); // PG 0 ** 41 ** D41 + case 42: return _BV( 7 ); // PL 7 ** 42 ** D42 + case 43: return _BV( 6 ); // PL 6 ** 43 ** D43 + case 44: return _BV( 5 ); // PL 5 ** 44 ** D44 + case 45: return _BV( 4 ); // PL 4 ** 45 ** D45 + case 46: return _BV( 3 ); // PL 3 ** 46 ** D46 + case 47: return _BV( 2 ); // PL 2 ** 47 ** D47 + case 48: return _BV( 1 ); // PL 1 ** 48 ** D48 + case 49: return _BV( 0 ); // PL 0 ** 49 ** D49 + case 50: return _BV( 3 ); // PB 3 ** 50 ** SPI_MISO + case 51: return _BV( 2 ); // PB 2 ** 51 ** SPI_MOSI + case 52: return _BV( 1 ); // PB 1 ** 52 ** SPI_SCK + case 53: return _BV( 0 ); // PB 0 ** 53 ** SPI_SS + case 54: return _BV( 0 ); // PF 0 ** 54 ** A0 + case 55: return _BV( 1 ); // PF 1 ** 55 ** A1 + case 56: return _BV( 2 ); // PF 2 ** 56 ** A2 + case 57: return _BV( 3 ); // PF 3 ** 57 ** A3 + case 58: return _BV( 4 ); // PF 4 ** 58 ** A4 + case 59: return _BV( 5 ); // PF 5 ** 59 ** A5 + case 60: return _BV( 6 ); // PF 6 ** 60 ** A6 + case 61: return _BV( 7 ); // PF 7 ** 61 ** A7 + case 62: return _BV( 0 ); // PK 0 ** 62 ** A8 + case 63: return _BV( 1 ); // PK 1 ** 63 ** A9 + case 64: return _BV( 2 ); // PK 2 ** 64 ** A10 + case 65: return _BV( 3 ); // PK 3 ** 65 ** A11 + case 66: return _BV( 4 ); // PK 4 ** 66 ** A12 + case 67: return _BV( 5 ); // PK 5 ** 67 ** A13 + case 68: return _BV( 6 ); // PK 6 ** 68 ** A14 + case 69: return _BV( 7 ); // PK 7 ** 69 ** A15 + default: + // TODO: add error here + invalidPinSpecified(); + } +} + +INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) +{ + switch(pin) { + case 2: return TIMER3B; // PE 4 ** 2 ** PWM2 + case 3: return TIMER3C; // PE 5 ** 3 ** PWM3 + case 4: return TIMER0B; // PG 5 ** 4 ** PWM4 + case 5: return TIMER3A; // PE 3 ** 5 ** PWM5 + case 6: return TIMER4A; // PH 3 ** 6 ** PWM6 + case 7: return TIMER4B; // PH 4 ** 7 ** PWM7 + case 8: return TIMER4C; // PH 5 ** 8 ** PWM8 + case 9: return TIMER2B; // PH 6 ** 9 ** PWM9 + case 10: return TIMER2A; // PB 4 ** 10 ** PWM10 + case 11: return TIMER1A; // PB 5 ** 11 ** PWM11 + case 12: return TIMER1B; // PB 6 ** 12 ** PWM12 + case 13: return TIMER0A; // PB 7 ** 13 ** PWM13 + case 44: return TIMER5C; // PL 5 ** 44 ** D44 + case 45: return TIMER5B; // PL 4 ** 45 ** D45 + case 46: return TIMER5A; // PL 3 ** 46 ** D46 + default: invalidPinSpecified(); + } +} + +#else // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) + +INLINED volatile uint8_t *inlined_portModeRegister(uint8_t port_index) +{ + switch (port_index) { + case 2: return &DDRB; + case 3: return &DDRC; + case 4: return &DDRD; + default: invalidPinSpecified(); + } +} + +INLINED volatile uint8_t *inlined_portOutputRegister(uint8_t port_index) +{ + switch (port_index) { + case 2: return &PORTB; + case 3: return &PORTC; + case 4: return &PORTD; + default: invalidPinSpecified(); + } +} + +INLINED volatile uint8_t *inlined_portInputRegister(uint8_t port_index) +{ + switch (port_index) { + case 2: return &PINB; + case 3: return &PINC; + case 4: return &PIND; + default: invalidPinSpecified(); + } +} + +INLINED uint8_t inlined_digitalPinToPort(uint8_t pin) +{ + switch(pin) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + return PORT_INDEX_PD; + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + return PORT_INDEX_PB; + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + return PORT_INDEX_PC; + default: + invalidPinSpecified(); + } +} + +INLINED uint8_t inlined_digitalPinToBitMask(uint8_t pin) +{ + switch(pin) { + case 0: return _BV(0); /* 0, port D */ + case 1: return _BV(1); + case 2: return _BV(2); + case 3: return _BV(3); + case 4: return _BV(4); + case 5: return _BV(5); + case 6: return _BV(6); + case 7: return _BV(7); + case 8: return _BV(0); /* 8, port B */ + case 9: return _BV(1); + case 10: return _BV(2); + case 11: return _BV(3); + case 12: return _BV(4); + case 13: return _BV(5); + case 14: return _BV(0); /* 14, port C */ + case 15: return _BV(1); + case 16: return _BV(2); + case 17: return _BV(3); + case 18: return _BV(4); + case 19: return _BV(5); + default: + // TODO: throw error here + invalidPinSpecified(); + } +} + +INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) +{ + switch(pin) { +#if defined(__AVR_ATmega8__) + case 11: return TIMER2; +#else + case 3: return TIMER2B; + case 5: return TIMER0B; + case 6: return TIMER0A; + case 11: return TIMER2A; +#endif + case 9: return TIMER1A; + case 10: return TIMER1B; + default: invalidPinSpecified(); + } +} + +#endif // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) + // Get the bit location within the hardware port of the given virtual pin. // This comes from the pins_*.c file for the active board configuration. -// -// These perform slightly better as macros compared to inline functions -// -#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) ) -#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) ) -#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) ) + #define analogInPinToBit(P) (P) -#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) ) -#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) ) -#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) ) + +INLINED uint8_t digitalPinToPort(uint8_t pin) { + if (__builtin_constant_p(pin)) + return inlined_digitalPinToPort(pin); + else + return pgm_read_byte( digital_pin_to_port_PGM + pin ); +} + +INLINED uint8_t digitalPinToBitMask(uint8_t pin) { + if (__builtin_constant_p(pin)) + return inlined_digitalPinToBitMask(pin); + else + return pgm_read_byte( digital_pin_to_bit_mask_PGM + pin ); +} + +INLINED uint8_t digitalPinToTimer(uint8_t pin) { + if (__builtin_constant_p(pin)) + return inlined_digitalPinToTimer(pin); + else + return pgm_read_byte( digital_pin_to_timer_PGM + pin ); +} + +INLINED volatile uint8_t *portOutputRegister(uint8_t index) { + if (__builtin_constant_p(index)) + return inlined_portOutputRegister(index); + else + return (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + index ) ); +} + +INLINED volatile uint8_t* portInputRegister(uint8_t index) { + if (__builtin_constant_p(index)) + return inlined_portInputRegister(index); + else + return (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + index) ); +} + +INLINED volatile uint8_t* portModeRegister(uint8_t index) { + if (__builtin_constant_p(index)) + return inlined_portModeRegister(index); + else + return (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + index) ); +} #endif -- cgit v1.2.3-18-g5258 From eed15e48d68d10426e015515ec4143849739f2de Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 11 Feb 2011 19:29:46 -0500 Subject: Changes to optimized digitalWrte(), etc. Factoring out the implementation of digitalWrite(), digitalRead(), and pinMode() into macros that can either be inlined (for constant pin numbers) or executed within a function (non-constant pins). Removing testing for timers on pins in digitalWrite(), digitalRead(), and pinMode(). Moving pin to port macros from pins_arduino.h to wiring.h. --- cores/arduino/pins_arduino.h | 46 ++++---------------------------------------- 1 file changed, 4 insertions(+), 42 deletions(-) (limited to 'cores/arduino/pins_arduino.h') diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index 63f4257..4bf6470 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -339,6 +339,8 @@ INLINED uint8_t inlined_digitalPinToBitMask(uint8_t pin) } } +// XXX: this needs to return false (or -1) if the pin doesn't have a timer, +// rather than throwing a compilation error. INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) { switch(pin) { @@ -453,6 +455,8 @@ INLINED uint8_t inlined_digitalPinToBitMask(uint8_t pin) } } +// XXX: this needs to return false (or -1) if the pin doesn't have a timer, +// rather than throwing a compilation error. INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) { switch(pin) { @@ -477,46 +481,4 @@ INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) #define analogInPinToBit(P) (P) -INLINED uint8_t digitalPinToPort(uint8_t pin) { - if (__builtin_constant_p(pin)) - return inlined_digitalPinToPort(pin); - else - return pgm_read_byte( digital_pin_to_port_PGM + pin ); -} - -INLINED uint8_t digitalPinToBitMask(uint8_t pin) { - if (__builtin_constant_p(pin)) - return inlined_digitalPinToBitMask(pin); - else - return pgm_read_byte( digital_pin_to_bit_mask_PGM + pin ); -} - -INLINED uint8_t digitalPinToTimer(uint8_t pin) { - if (__builtin_constant_p(pin)) - return inlined_digitalPinToTimer(pin); - else - return pgm_read_byte( digital_pin_to_timer_PGM + pin ); -} - -INLINED volatile uint8_t *portOutputRegister(uint8_t index) { - if (__builtin_constant_p(index)) - return inlined_portOutputRegister(index); - else - return (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + index ) ); -} - -INLINED volatile uint8_t* portInputRegister(uint8_t index) { - if (__builtin_constant_p(index)) - return inlined_portInputRegister(index); - else - return (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + index) ); -} - -INLINED volatile uint8_t* portModeRegister(uint8_t index) { - if (__builtin_constant_p(index)) - return inlined_portModeRegister(index); - else - return (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + index) ); -} - #endif -- cgit v1.2.3-18-g5258 From cd050d05d1fa7ae87da68574a9e50edf6ac1ed8f Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 12 Feb 2011 14:47:08 -0500 Subject: Adding noAnalogWrite() function to disable PWM. Also, removing the inline version of digitalPinToTimer() (since we're not optimizing the functions that use it anyway). The noAnalogWrite() function is in wiring_analog.c, deriving from the previous turnOffPWM() which has moved from wiring_digital.c. http://code.google.com/p/arduino/issues/detail?id=476 --- cores/arduino/pins_arduino.h | 43 ------------------------------------------- 1 file changed, 43 deletions(-) (limited to 'cores/arduino/pins_arduino.h') diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index 4bf6470..ca6a821 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -339,30 +339,6 @@ INLINED uint8_t inlined_digitalPinToBitMask(uint8_t pin) } } -// XXX: this needs to return false (or -1) if the pin doesn't have a timer, -// rather than throwing a compilation error. -INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) -{ - switch(pin) { - case 2: return TIMER3B; // PE 4 ** 2 ** PWM2 - case 3: return TIMER3C; // PE 5 ** 3 ** PWM3 - case 4: return TIMER0B; // PG 5 ** 4 ** PWM4 - case 5: return TIMER3A; // PE 3 ** 5 ** PWM5 - case 6: return TIMER4A; // PH 3 ** 6 ** PWM6 - case 7: return TIMER4B; // PH 4 ** 7 ** PWM7 - case 8: return TIMER4C; // PH 5 ** 8 ** PWM8 - case 9: return TIMER2B; // PH 6 ** 9 ** PWM9 - case 10: return TIMER2A; // PB 4 ** 10 ** PWM10 - case 11: return TIMER1A; // PB 5 ** 11 ** PWM11 - case 12: return TIMER1B; // PB 6 ** 12 ** PWM12 - case 13: return TIMER0A; // PB 7 ** 13 ** PWM13 - case 44: return TIMER5C; // PL 5 ** 44 ** D44 - case 45: return TIMER5B; // PL 4 ** 45 ** D45 - case 46: return TIMER5A; // PL 3 ** 46 ** D46 - default: invalidPinSpecified(); - } -} - #else // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) INLINED volatile uint8_t *inlined_portModeRegister(uint8_t port_index) @@ -455,25 +431,6 @@ INLINED uint8_t inlined_digitalPinToBitMask(uint8_t pin) } } -// XXX: this needs to return false (or -1) if the pin doesn't have a timer, -// rather than throwing a compilation error. -INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) -{ - switch(pin) { -#if defined(__AVR_ATmega8__) - case 11: return TIMER2; -#else - case 3: return TIMER2B; - case 5: return TIMER0B; - case 6: return TIMER0A; - case 11: return TIMER2A; -#endif - case 9: return TIMER1A; - case 10: return TIMER1B; - default: invalidPinSpecified(); - } -} - #endif // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) // Get the bit location within the hardware port of the given virtual pin. -- cgit v1.2.3-18-g5258 From 63515122ca28d9a60e6aba2948fb01765ca1138e Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 18 Feb 2011 10:40:56 -0500 Subject: Revert "Adding noAnalogWrite() function to disable PWM." This reverts commit 38d4a34fec6925b29a732d13e200f54ee4b42025. --- cores/arduino/pins_arduino.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'cores/arduino/pins_arduino.h') diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index ca6a821..4bf6470 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -339,6 +339,30 @@ INLINED uint8_t inlined_digitalPinToBitMask(uint8_t pin) } } +// XXX: this needs to return false (or -1) if the pin doesn't have a timer, +// rather than throwing a compilation error. +INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) +{ + switch(pin) { + case 2: return TIMER3B; // PE 4 ** 2 ** PWM2 + case 3: return TIMER3C; // PE 5 ** 3 ** PWM3 + case 4: return TIMER0B; // PG 5 ** 4 ** PWM4 + case 5: return TIMER3A; // PE 3 ** 5 ** PWM5 + case 6: return TIMER4A; // PH 3 ** 6 ** PWM6 + case 7: return TIMER4B; // PH 4 ** 7 ** PWM7 + case 8: return TIMER4C; // PH 5 ** 8 ** PWM8 + case 9: return TIMER2B; // PH 6 ** 9 ** PWM9 + case 10: return TIMER2A; // PB 4 ** 10 ** PWM10 + case 11: return TIMER1A; // PB 5 ** 11 ** PWM11 + case 12: return TIMER1B; // PB 6 ** 12 ** PWM12 + case 13: return TIMER0A; // PB 7 ** 13 ** PWM13 + case 44: return TIMER5C; // PL 5 ** 44 ** D44 + case 45: return TIMER5B; // PL 4 ** 45 ** D45 + case 46: return TIMER5A; // PL 3 ** 46 ** D46 + default: invalidPinSpecified(); + } +} + #else // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) INLINED volatile uint8_t *inlined_portModeRegister(uint8_t port_index) @@ -431,6 +455,25 @@ INLINED uint8_t inlined_digitalPinToBitMask(uint8_t pin) } } +// XXX: this needs to return false (or -1) if the pin doesn't have a timer, +// rather than throwing a compilation error. +INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) +{ + switch(pin) { +#if defined(__AVR_ATmega8__) + case 11: return TIMER2; +#else + case 3: return TIMER2B; + case 5: return TIMER0B; + case 6: return TIMER0A; + case 11: return TIMER2A; +#endif + case 9: return TIMER1A; + case 10: return TIMER1B; + default: invalidPinSpecified(); + } +} + #endif // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) // Get the bit location within the hardware port of the given virtual pin. -- cgit v1.2.3-18-g5258 From 860c6f203103f329d192547c4f62ff2471f99b43 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 18 Feb 2011 10:41:29 -0500 Subject: Revert "Changes to optimized digitalWrte(), etc." This reverts commit aa1f1cbda9d6bb52785f98b40746920853d6579b. --- cores/arduino/pins_arduino.h | 46 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'cores/arduino/pins_arduino.h') diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index 4bf6470..63f4257 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -339,8 +339,6 @@ INLINED uint8_t inlined_digitalPinToBitMask(uint8_t pin) } } -// XXX: this needs to return false (or -1) if the pin doesn't have a timer, -// rather than throwing a compilation error. INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) { switch(pin) { @@ -455,8 +453,6 @@ INLINED uint8_t inlined_digitalPinToBitMask(uint8_t pin) } } -// XXX: this needs to return false (or -1) if the pin doesn't have a timer, -// rather than throwing a compilation error. INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) { switch(pin) { @@ -481,4 +477,46 @@ INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) #define analogInPinToBit(P) (P) +INLINED uint8_t digitalPinToPort(uint8_t pin) { + if (__builtin_constant_p(pin)) + return inlined_digitalPinToPort(pin); + else + return pgm_read_byte( digital_pin_to_port_PGM + pin ); +} + +INLINED uint8_t digitalPinToBitMask(uint8_t pin) { + if (__builtin_constant_p(pin)) + return inlined_digitalPinToBitMask(pin); + else + return pgm_read_byte( digital_pin_to_bit_mask_PGM + pin ); +} + +INLINED uint8_t digitalPinToTimer(uint8_t pin) { + if (__builtin_constant_p(pin)) + return inlined_digitalPinToTimer(pin); + else + return pgm_read_byte( digital_pin_to_timer_PGM + pin ); +} + +INLINED volatile uint8_t *portOutputRegister(uint8_t index) { + if (__builtin_constant_p(index)) + return inlined_portOutputRegister(index); + else + return (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + index ) ); +} + +INLINED volatile uint8_t* portInputRegister(uint8_t index) { + if (__builtin_constant_p(index)) + return inlined_portInputRegister(index); + else + return (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + index) ); +} + +INLINED volatile uint8_t* portModeRegister(uint8_t index) { + if (__builtin_constant_p(index)) + return inlined_portModeRegister(index); + else + return (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + index) ); +} + #endif -- cgit v1.2.3-18-g5258 From 218eb5e80706b53c691da133461830c895e0c8ff Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Tue, 1 Mar 2011 20:00:16 -0500 Subject: Moving wiring.h contents into Arduino.h. --- cores/arduino/pins_arduino.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'cores/arduino/pins_arduino.h') diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index 63f4257..f48d5bc 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -65,6 +65,34 @@ const static uint8_t MISO = 12; const static uint8_t SCK = 13; #endif +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +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; +#else +const static uint8_t A0 = 14; +const static uint8_t A1 = 15; +const static uint8_t A2 = 16; +const static uint8_t A3 = 17; +const static uint8_t A4 = 18; +const static uint8_t A5 = 19; +const static uint8_t A6 = 20; +const static uint8_t A7 = 21; +#endif + // On the ATmega1280, the addresses of some of the port registers are // greater than 255, so we can't store them in uint8_t's. extern const uint16_t PROGMEM port_to_mode_PGM[]; -- cgit v1.2.3-18-g5258 From d7a87f18f06481f2ca3c342dfdd1268d934ecedb Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Wed, 2 Mar 2011 23:05:25 -0500 Subject: Re-arranging header files and small fixes to optimized core functions. --- cores/arduino/pins_arduino.h | 51 ++------------------------------------------ 1 file changed, 2 insertions(+), 49 deletions(-) (limited to 'cores/arduino/pins_arduino.h') diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index f48d5bc..e9d3fc7 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -385,7 +385,7 @@ INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) case 44: return TIMER5C; // PL 5 ** 44 ** D44 case 45: return TIMER5B; // PL 4 ** 45 ** D45 case 46: return TIMER5A; // PL 3 ** 46 ** D46 - default: invalidPinSpecified(); + default: return NOT_ON_TIMER; } } @@ -494,57 +494,10 @@ INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) #endif case 9: return TIMER1A; case 10: return TIMER1B; - default: invalidPinSpecified(); + default: return NOT_ON_TIMER; } } #endif // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) -// Get the bit location within the hardware port of the given virtual pin. -// This comes from the pins_*.c file for the active board configuration. - -#define analogInPinToBit(P) (P) - -INLINED uint8_t digitalPinToPort(uint8_t pin) { - if (__builtin_constant_p(pin)) - return inlined_digitalPinToPort(pin); - else - return pgm_read_byte( digital_pin_to_port_PGM + pin ); -} - -INLINED uint8_t digitalPinToBitMask(uint8_t pin) { - if (__builtin_constant_p(pin)) - return inlined_digitalPinToBitMask(pin); - else - return pgm_read_byte( digital_pin_to_bit_mask_PGM + pin ); -} - -INLINED uint8_t digitalPinToTimer(uint8_t pin) { - if (__builtin_constant_p(pin)) - return inlined_digitalPinToTimer(pin); - else - return pgm_read_byte( digital_pin_to_timer_PGM + pin ); -} - -INLINED volatile uint8_t *portOutputRegister(uint8_t index) { - if (__builtin_constant_p(index)) - return inlined_portOutputRegister(index); - else - return (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + index ) ); -} - -INLINED volatile uint8_t* portInputRegister(uint8_t index) { - if (__builtin_constant_p(index)) - return inlined_portInputRegister(index); - else - return (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + index) ); -} - -INLINED volatile uint8_t* portModeRegister(uint8_t index) { - if (__builtin_constant_p(index)) - return inlined_portModeRegister(index); - else - return (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + index) ); -} - #endif -- cgit v1.2.3-18-g5258 From 58d683239d80d4620a3ab35c4eac53bbe2c35d50 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Thu, 3 Mar 2011 18:46:45 -0500 Subject: Removing optimized digitalWrite(), digitalRead(), pinMode(). --- cores/arduino/pins_arduino.h | 407 ------------------------------------------- 1 file changed, 407 deletions(-) (limited to 'cores/arduino/pins_arduino.h') diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index e9d3fc7..98af18e 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -93,411 +93,4 @@ const static uint8_t A6 = 20; const static uint8_t A7 = 21; #endif -// On the ATmega1280, the addresses of some of the port registers are -// greater than 255, so we can't store them in uint8_t's. -extern const uint16_t PROGMEM port_to_mode_PGM[]; -extern const uint16_t PROGMEM port_to_input_PGM[]; -extern const uint16_t PROGMEM port_to_output_PGM[]; - -extern const uint8_t PROGMEM digital_pin_to_port_PGM[]; -// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[]; -extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]; -extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; - -// inlined versions of lookup-table-based pin mappings. Don't use directly. - -// Don't use PA, so on, might clash with sketch - -#define PORT_INDEX_PA 1 -#define PORT_INDEX_PB 2 -#define PORT_INDEX_PC 3 -#define PORT_INDEX_PD 4 -#define PORT_INDEX_PE 5 -#define PORT_INDEX_PF 6 -#define PORT_INDEX_PG 7 -#define PORT_INDEX_PH 8 -#define PORT_INDEX_PJ 10 -#define PORT_INDEX_PK 11 -#define PORT_INDEX_PL 12 - -__attribute__((error("Invalid pin specified. This pin does not map to any I/O port"))) static void invalidPinSpecified(void); - - -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) - -INLINED volatile uint8_t *inlined_portModeRegister(uint8_t port_index) -{ - switch (port_index) { - case 1: return &DDRA; - case 2: return &DDRB; - case 3: return &DDRC; - case 4: return &DDRD; - case 5: return &DDRE; - case 6: return &DDRF; - case 7: return &DDRG; - case 8: return &DDRH; - case 10: return &DDRJ; - case 11: return &DDRK; - case 12: return &DDRL; - default: return NOT_A_PORT; - } -} - -INLINED volatile uint8_t *inlined_portOutputRegister(uint8_t port_index) -{ - switch (port_index) { - case 1: return &PORTA; - case 2: return &PORTB; - case 3: return &PORTC; - case 4: return &PORTD; - case 5: return &PORTE; - case 6: return &PORTF; - case 7: return &PORTG; - case 8: return &PORTH; - case 10: return &PORTJ; - case 11: return &PORTK; - case 12: return &PORTL; - default: return NOT_A_PORT; - } -} - -INLINED volatile uint8_t *inlined_portInputRegister(uint8_t port_index) -{ - switch (port_index) { - case 1: return &PINA; - case 2: return &PINB; - case 3: return &PINC; - case 4: return &PIND; - case 5: return &PINE; - case 6: return &PINF; - case 7: return &PING; - case 8: return &PINH; - case 10: return &PINJ; - case 11: return &PINK; - case 12: return &PINL; - default: return NOT_A_PIN; - } -}; - -INLINED uint8_t inlined_digitalPinToPort(uint8_t pin) -{ - switch (pin) { - case 0: // PE 0 ** 0 ** USART0_RX - case 1: // PE 1 ** 1 ** USART0_TX - case 2: // PE 4 ** 2 ** PWM2 - case 3: // PE 5 ** 3 ** PWM3 - return PORT_INDEX_PE; - - case 4: // PG 5 ** 4 ** PWM4 - return PORT_INDEX_PG; - - case 5: // PE 3 ** 5 ** PWM5 - return PORT_INDEX_PE; - - case 6: // PH 3 ** 6 ** PWM6 - case 7: // PH 4 ** 7 ** PWM7 - case 8: // PH 5 ** 8 ** PWM8 - case 9: // PH 6 ** 9 ** PWM9 - return PORT_INDEX_PH; - - case 10: // PB 4 ** 10 ** PWM10 - case 11: // PB 5 ** 11 ** PWM11 - case 12: // PB 6 ** 12 ** PWM12 - case 13: // PB 7 ** 13 ** PWM13 - return PORT_INDEX_PB; - - case 14: // PJ 1 ** 14 ** USART3_TX - case 15: // PJ 0 ** 15 ** USART3_RX - return PORT_INDEX_PJ; - - case 16: // PH 1 ** 16 ** USART2_TX - case 17: // PH 0 ** 17 ** USART2_RX - return PORT_INDEX_PH; - - case 18: // PD 3 ** 18 ** USART1_TX - case 19: // PD 2 ** 19 ** USART1_RX - case 20: // PD 1 ** 20 ** I2C_SDA - case 21: // PD 0 ** 21 ** I2C_SCL - return PORT_INDEX_PD; - - case 22: // PA 0 ** 22 ** D22 - case 23: // PA 1 ** 23 ** D23 - case 24: // PA 2 ** 24 ** D24 - case 25: // PA 3 ** 25 ** D25 - case 26: // PA 4 ** 26 ** D26 - case 27: // PA 5 ** 27 ** D27 - case 28: // PA 6 ** 28 ** D28 - case 29: // PA 7 ** 29 ** D29 - return PORT_INDEX_PA; - - case 30: // PC 7 ** 30 ** D30 - case 31: // PC 6 ** 31 ** D31 - case 32: // PC 5 ** 32 ** D32 - case 33: // PC 4 ** 33 ** D33 - case 34: // PC 3 ** 34 ** D34 - case 35: // PC 2 ** 35 ** D35 - case 36: // PC 1 ** 36 ** D36 - case 37: // PC 0 ** 37 ** D37 - return PORT_INDEX_PC; - - case 38: // PD 7 ** 38 ** D38 - return PORT_INDEX_PD; - - case 39: // PG 2 ** 39 ** D39 - case 40: // PG 1 ** 40 ** D40 - case 41: // PG 0 ** 41 ** D41 - return PORT_INDEX_PG; - - case 42: // PL 7 ** 42 ** D42 - case 43: // PL 6 ** 43 ** D43 - case 44: // PL 5 ** 44 ** D44 - case 45: // PL 4 ** 45 ** D45 - case 46: // PL 3 ** 46 ** D46 - case 47: // PL 2 ** 47 ** D47 - case 48: // PL 1 ** 48 ** D48 - case 49: // PL 0 ** 49 ** D49 - return PORT_INDEX_PL; - - case 50: // PB 3 ** 50 ** SPI_MISO - case 51: // PB 2 ** 51 ** SPI_MOSI - case 52: // PB 1 ** 52 ** SPI_SCK - case 53: // PB 0 ** 53 ** SPI_SS - return PORT_INDEX_PB; - - case 54: // PF 0 ** 54 ** A0 - case 55: // PF 1 ** 55 ** A1 - case 56: // PF 2 ** 56 ** A2 - case 57: // PF 3 ** 57 ** A3 - case 58: // PF 4 ** 58 ** A4 - case 59: // PF 5 ** 59 ** A5 - case 60: // PF 6 ** 60 ** A6 - case 61: // PF 7 ** 61 ** A7 - return PORT_INDEX_PF; - - case 62: // PK 0 ** 62 ** A8 - case 63: // PK 1 ** 63 ** A9 - case 64: // PK 2 ** 64 ** A10 - case 65: // PK 3 ** 65 ** A11 - case 66: // PK 4 ** 66 ** A12 - case 67: // PK 5 ** 67 ** A13 - case 68: // PK 6 ** 68 ** A14 - case 69: // PK 7 ** 69 ** A15 - return PORT_INDEX_PK; - default: - invalidPinSpecified(); - } -} - -INLINED uint8_t inlined_digitalPinToBitMask(uint8_t pin) -{ - switch(pin) { - case 0: return _BV( 0 ); // PE 0 ** 0 ** USART0_RX - case 1: return _BV( 1 ); // PE 1 ** 1 ** USART0_TX - case 2: return _BV( 4 ); // PE 4 ** 2 ** PWM2 - case 3: return _BV( 5 ); // PE 5 ** 3 ** PWM3 - case 4: return _BV( 5 ); // PG 5 ** 4 ** PWM4 - case 5: return _BV( 3 ); // PE 3 ** 5 ** PWM5 - case 6: return _BV( 3 ); // PH 3 ** 6 ** PWM6 - case 7: return _BV( 4 ); // PH 4 ** 7 ** PWM7 - case 8: return _BV( 5 ); // PH 5 ** 8 ** PWM8 - case 9: return _BV( 6 ); // PH 6 ** 9 ** PWM9 - case 10: return _BV( 4 ); // PB 4 ** 10 ** PWM10 - case 11: return _BV( 5 ); // PB 5 ** 11 ** PWM11 - case 12: return _BV( 6 ); // PB 6 ** 12 ** PWM12 - case 13: return _BV( 7 ); // PB 7 ** 13 ** PWM13 - case 14: return _BV( 1 ); // PJ 1 ** 14 ** USART3_TX - case 15: return _BV( 0 ); // PJ 0 ** 15 ** USART3_RX - case 16: return _BV( 1 ); // PH 1 ** 16 ** USART2_TX - case 17: return _BV( 0 ); // PH 0 ** 17 ** USART2_RX - case 18: return _BV( 3 ); // PD 3 ** 18 ** USART1_TX - case 19: return _BV( 2 ); // PD 2 ** 19 ** USART1_RX - case 20: return _BV( 1 ); // PD 1 ** 20 ** I2C_SDA - case 21: return _BV( 0 ); // PD 0 ** 21 ** I2C_SCL - case 22: return _BV( 0 ); // PA 0 ** 22 ** D22 - case 23: return _BV( 1 ); // PA 1 ** 23 ** D23 - case 24: return _BV( 2 ); // PA 2 ** 24 ** D24 - case 25: return _BV( 3 ); // PA 3 ** 25 ** D25 - case 26: return _BV( 4 ); // PA 4 ** 26 ** D26 - case 27: return _BV( 5 ); // PA 5 ** 27 ** D27 - case 28: return _BV( 6 ); // PA 6 ** 28 ** D28 - case 29: return _BV( 7 ); // PA 7 ** 29 ** D29 - case 30: return _BV( 7 ); // PC 7 ** 30 ** D30 - case 31: return _BV( 6 ); // PC 6 ** 31 ** D31 - case 32: return _BV( 5 ); // PC 5 ** 32 ** D32 - case 33: return _BV( 4 ); // PC 4 ** 33 ** D33 - case 34: return _BV( 3 ); // PC 3 ** 34 ** D34 - case 35: return _BV( 2 ); // PC 2 ** 35 ** D35 - case 36: return _BV( 1 ); // PC 1 ** 36 ** D36 - case 37: return _BV( 0 ); // PC 0 ** 37 ** D37 - case 38: return _BV( 7 ); // PD 7 ** 38 ** D38 - case 39: return _BV( 2 ); // PG 2 ** 39 ** D39 - case 40: return _BV( 1 ); // PG 1 ** 40 ** D40 - case 41: return _BV( 0 ); // PG 0 ** 41 ** D41 - case 42: return _BV( 7 ); // PL 7 ** 42 ** D42 - case 43: return _BV( 6 ); // PL 6 ** 43 ** D43 - case 44: return _BV( 5 ); // PL 5 ** 44 ** D44 - case 45: return _BV( 4 ); // PL 4 ** 45 ** D45 - case 46: return _BV( 3 ); // PL 3 ** 46 ** D46 - case 47: return _BV( 2 ); // PL 2 ** 47 ** D47 - case 48: return _BV( 1 ); // PL 1 ** 48 ** D48 - case 49: return _BV( 0 ); // PL 0 ** 49 ** D49 - case 50: return _BV( 3 ); // PB 3 ** 50 ** SPI_MISO - case 51: return _BV( 2 ); // PB 2 ** 51 ** SPI_MOSI - case 52: return _BV( 1 ); // PB 1 ** 52 ** SPI_SCK - case 53: return _BV( 0 ); // PB 0 ** 53 ** SPI_SS - case 54: return _BV( 0 ); // PF 0 ** 54 ** A0 - case 55: return _BV( 1 ); // PF 1 ** 55 ** A1 - case 56: return _BV( 2 ); // PF 2 ** 56 ** A2 - case 57: return _BV( 3 ); // PF 3 ** 57 ** A3 - case 58: return _BV( 4 ); // PF 4 ** 58 ** A4 - case 59: return _BV( 5 ); // PF 5 ** 59 ** A5 - case 60: return _BV( 6 ); // PF 6 ** 60 ** A6 - case 61: return _BV( 7 ); // PF 7 ** 61 ** A7 - case 62: return _BV( 0 ); // PK 0 ** 62 ** A8 - case 63: return _BV( 1 ); // PK 1 ** 63 ** A9 - case 64: return _BV( 2 ); // PK 2 ** 64 ** A10 - case 65: return _BV( 3 ); // PK 3 ** 65 ** A11 - case 66: return _BV( 4 ); // PK 4 ** 66 ** A12 - case 67: return _BV( 5 ); // PK 5 ** 67 ** A13 - case 68: return _BV( 6 ); // PK 6 ** 68 ** A14 - case 69: return _BV( 7 ); // PK 7 ** 69 ** A15 - default: - // TODO: add error here - invalidPinSpecified(); - } -} - -INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) -{ - switch(pin) { - case 2: return TIMER3B; // PE 4 ** 2 ** PWM2 - case 3: return TIMER3C; // PE 5 ** 3 ** PWM3 - case 4: return TIMER0B; // PG 5 ** 4 ** PWM4 - case 5: return TIMER3A; // PE 3 ** 5 ** PWM5 - case 6: return TIMER4A; // PH 3 ** 6 ** PWM6 - case 7: return TIMER4B; // PH 4 ** 7 ** PWM7 - case 8: return TIMER4C; // PH 5 ** 8 ** PWM8 - case 9: return TIMER2B; // PH 6 ** 9 ** PWM9 - case 10: return TIMER2A; // PB 4 ** 10 ** PWM10 - case 11: return TIMER1A; // PB 5 ** 11 ** PWM11 - case 12: return TIMER1B; // PB 6 ** 12 ** PWM12 - case 13: return TIMER0A; // PB 7 ** 13 ** PWM13 - case 44: return TIMER5C; // PL 5 ** 44 ** D44 - case 45: return TIMER5B; // PL 4 ** 45 ** D45 - case 46: return TIMER5A; // PL 3 ** 46 ** D46 - default: return NOT_ON_TIMER; - } -} - -#else // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) - -INLINED volatile uint8_t *inlined_portModeRegister(uint8_t port_index) -{ - switch (port_index) { - case 2: return &DDRB; - case 3: return &DDRC; - case 4: return &DDRD; - default: invalidPinSpecified(); - } -} - -INLINED volatile uint8_t *inlined_portOutputRegister(uint8_t port_index) -{ - switch (port_index) { - case 2: return &PORTB; - case 3: return &PORTC; - case 4: return &PORTD; - default: invalidPinSpecified(); - } -} - -INLINED volatile uint8_t *inlined_portInputRegister(uint8_t port_index) -{ - switch (port_index) { - case 2: return &PINB; - case 3: return &PINC; - case 4: return &PIND; - default: invalidPinSpecified(); - } -} - -INLINED uint8_t inlined_digitalPinToPort(uint8_t pin) -{ - switch(pin) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - return PORT_INDEX_PD; - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - return PORT_INDEX_PB; - case 14: - case 15: - case 16: - case 17: - case 18: - case 19: - return PORT_INDEX_PC; - default: - invalidPinSpecified(); - } -} - -INLINED uint8_t inlined_digitalPinToBitMask(uint8_t pin) -{ - switch(pin) { - case 0: return _BV(0); /* 0, port D */ - case 1: return _BV(1); - case 2: return _BV(2); - case 3: return _BV(3); - case 4: return _BV(4); - case 5: return _BV(5); - case 6: return _BV(6); - case 7: return _BV(7); - case 8: return _BV(0); /* 8, port B */ - case 9: return _BV(1); - case 10: return _BV(2); - case 11: return _BV(3); - case 12: return _BV(4); - case 13: return _BV(5); - case 14: return _BV(0); /* 14, port C */ - case 15: return _BV(1); - case 16: return _BV(2); - case 17: return _BV(3); - case 18: return _BV(4); - case 19: return _BV(5); - default: - // TODO: throw error here - invalidPinSpecified(); - } -} - -INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin) -{ - switch(pin) { -#if defined(__AVR_ATmega8__) - case 11: return TIMER2; -#else - case 3: return TIMER2B; - case 5: return TIMER0B; - case 6: return TIMER0A; - case 11: return TIMER2A; -#endif - case 9: return TIMER1A; - case 10: return TIMER1B; - default: return NOT_ON_TIMER; - } -} - -#endif // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) - #endif -- cgit v1.2.3-18-g5258 From b0ab2bc48bd3edd3b42d3a52f0995f220f77f814 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Thu, 3 Mar 2011 18:57:05 -0500 Subject: Rearranging internal #defines in headers. --- cores/arduino/pins_arduino.h | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'cores/arduino/pins_arduino.h') diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index 98af18e..4f0c1c3 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -27,32 +27,6 @@ #include -#define NOT_A_PIN 0 -#define NOT_A_PORT 0 - -#define NOT_ON_TIMER 0 -#define TIMER0A 1 -#define TIMER0B 2 -#define TIMER1A 3 -#define TIMER1B 4 -#define TIMER2 5 -#define TIMER2A 6 -#define TIMER2B 7 - -#define TIMER3A 8 -#define TIMER3B 9 -#define TIMER3C 10 -#define TIMER4A 11 -#define TIMER4B 12 -#define TIMER4C 13 -#define TIMER5A 14 -#define TIMER5B 15 -#define TIMER5C 16 - -#ifndef INLINED -#define INLINED static __attribute__((always_inline)) inline -#endif - #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) const static uint8_t SS = 53; const static uint8_t MOSI = 51; -- cgit v1.2.3-18-g5258 From 6cd58c57dbf8b52d94b4fda3cb565856530b377d Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Thu, 3 Mar 2011 23:54:33 -0500 Subject: Moving all pin definitions into pins_arduino.h. This is a step towards providing portability across AVR's by simply including an appropriate header file. --- cores/arduino/pins_arduino.h | 442 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 442 insertions(+) (limited to 'cores/arduino/pins_arduino.h') diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index 4f0c1c3..169e734 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -67,4 +67,446 @@ const static uint8_t A6 = 20; const static uint8_t A7 = 21; #endif +#ifdef ARDUINO_MAIN + +// On the Arduino board, digital pins are also used +// for the analog output (software PWM). Analog input +// pins are a separate set. + +// 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.) + +// 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 + +#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 + + +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +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[] = { + // PORTLIST + // ------------------------------------------- + PE , // PE 0 ** 0 ** USART0_RX + PE , // PE 1 ** 1 ** USART0_TX + PE , // PE 4 ** 2 ** PWM2 + PE , // PE 5 ** 3 ** PWM3 + PG , // PG 5 ** 4 ** PWM4 + PE , // PE 3 ** 5 ** PWM5 + PH , // PH 3 ** 6 ** PWM6 + PH , // PH 4 ** 7 ** PWM7 + PH , // PH 5 ** 8 ** PWM8 + PH , // PH 6 ** 9 ** PWM9 + PB , // PB 4 ** 10 ** PWM10 + PB , // PB 5 ** 11 ** PWM11 + PB , // PB 6 ** 12 ** PWM12 + PB , // PB 7 ** 13 ** PWM13 + PJ , // PJ 1 ** 14 ** USART3_TX + PJ , // PJ 0 ** 15 ** USART3_RX + PH , // PH 1 ** 16 ** USART2_TX + PH , // PH 0 ** 17 ** USART2_RX + PD , // PD 3 ** 18 ** USART1_TX + PD , // PD 2 ** 19 ** USART1_RX + PD , // PD 1 ** 20 ** I2C_SDA + PD , // PD 0 ** 21 ** I2C_SCL + PA , // PA 0 ** 22 ** D22 + PA , // PA 1 ** 23 ** D23 + PA , // PA 2 ** 24 ** D24 + PA , // PA 3 ** 25 ** D25 + PA , // PA 4 ** 26 ** D26 + PA , // PA 5 ** 27 ** D27 + PA , // PA 6 ** 28 ** D28 + PA , // PA 7 ** 29 ** D29 + PC , // PC 7 ** 30 ** D30 + PC , // PC 6 ** 31 ** D31 + PC , // PC 5 ** 32 ** D32 + PC , // PC 4 ** 33 ** D33 + PC , // PC 3 ** 34 ** D34 + PC , // PC 2 ** 35 ** D35 + PC , // PC 1 ** 36 ** D36 + PC , // PC 0 ** 37 ** D37 + PD , // PD 7 ** 38 ** D38 + PG , // PG 2 ** 39 ** D39 + PG , // PG 1 ** 40 ** D40 + PG , // PG 0 ** 41 ** D41 + PL , // PL 7 ** 42 ** D42 + PL , // PL 6 ** 43 ** D43 + PL , // PL 5 ** 44 ** D44 + PL , // PL 4 ** 45 ** D45 + PL , // PL 3 ** 46 ** D46 + PL , // PL 2 ** 47 ** D47 + PL , // PL 1 ** 48 ** D48 + PL , // PL 0 ** 49 ** D49 + PB , // PB 3 ** 50 ** SPI_MISO + PB , // PB 2 ** 51 ** SPI_MOSI + PB , // PB 1 ** 52 ** SPI_SCK + PB , // PB 0 ** 53 ** SPI_SS + PF , // PF 0 ** 54 ** A0 + PF , // PF 1 ** 55 ** A1 + PF , // PF 2 ** 56 ** A2 + PF , // PF 3 ** 57 ** A3 + PF , // PF 4 ** 58 ** A4 + PF , // PF 5 ** 59 ** A5 + PF , // PF 6 ** 60 ** A6 + PF , // PF 7 ** 61 ** A7 + PK , // PK 0 ** 62 ** A8 + PK , // PK 1 ** 63 ** A9 + PK , // PK 2 ** 64 ** A10 + PK , // PK 3 ** 65 ** A11 + PK , // PK 4 ** 66 ** A12 + PK , // PK 5 ** 67 ** A13 + PK , // PK 6 ** 68 ** A14 + PK , // PK 7 ** 69 ** A15 +}; + +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( 4 ) , // PE 4 ** 2 ** PWM2 + _BV( 5 ) , // PE 5 ** 3 ** PWM3 + _BV( 5 ) , // PG 5 ** 4 ** PWM4 + _BV( 3 ) , // PE 3 ** 5 ** PWM5 + _BV( 3 ) , // PH 3 ** 6 ** PWM6 + _BV( 4 ) , // PH 4 ** 7 ** PWM7 + _BV( 5 ) , // PH 5 ** 8 ** PWM8 + _BV( 6 ) , // PH 6 ** 9 ** PWM9 + _BV( 4 ) , // PB 4 ** 10 ** PWM10 + _BV( 5 ) , // PB 5 ** 11 ** PWM11 + _BV( 6 ) , // PB 6 ** 12 ** PWM12 + _BV( 7 ) , // PB 7 ** 13 ** PWM13 + _BV( 1 ) , // PJ 1 ** 14 ** USART3_TX + _BV( 0 ) , // PJ 0 ** 15 ** USART3_RX + _BV( 1 ) , // PH 1 ** 16 ** USART2_TX + _BV( 0 ) , // PH 0 ** 17 ** USART2_RX + _BV( 3 ) , // PD 3 ** 18 ** USART1_TX + _BV( 2 ) , // PD 2 ** 19 ** USART1_RX + _BV( 1 ) , // PD 1 ** 20 ** I2C_SDA + _BV( 0 ) , // PD 0 ** 21 ** I2C_SCL + _BV( 0 ) , // PA 0 ** 22 ** D22 + _BV( 1 ) , // PA 1 ** 23 ** D23 + _BV( 2 ) , // PA 2 ** 24 ** D24 + _BV( 3 ) , // PA 3 ** 25 ** D25 + _BV( 4 ) , // PA 4 ** 26 ** D26 + _BV( 5 ) , // PA 5 ** 27 ** D27 + _BV( 6 ) , // PA 6 ** 28 ** D28 + _BV( 7 ) , // PA 7 ** 29 ** D29 + _BV( 7 ) , // PC 7 ** 30 ** D30 + _BV( 6 ) , // PC 6 ** 31 ** D31 + _BV( 5 ) , // PC 5 ** 32 ** D32 + _BV( 4 ) , // PC 4 ** 33 ** D33 + _BV( 3 ) , // PC 3 ** 34 ** D34 + _BV( 2 ) , // PC 2 ** 35 ** D35 + _BV( 1 ) , // PC 1 ** 36 ** D36 + _BV( 0 ) , // PC 0 ** 37 ** D37 + _BV( 7 ) , // PD 7 ** 38 ** D38 + _BV( 2 ) , // PG 2 ** 39 ** D39 + _BV( 1 ) , // PG 1 ** 40 ** D40 + _BV( 0 ) , // PG 0 ** 41 ** D41 + _BV( 7 ) , // PL 7 ** 42 ** D42 + _BV( 6 ) , // PL 6 ** 43 ** D43 + _BV( 5 ) , // PL 5 ** 44 ** D44 + _BV( 4 ) , // PL 4 ** 45 ** D45 + _BV( 3 ) , // PL 3 ** 46 ** D46 + _BV( 2 ) , // PL 2 ** 47 ** D47 + _BV( 1 ) , // PL 1 ** 48 ** D48 + _BV( 0 ) , // PL 0 ** 49 ** D49 + _BV( 3 ) , // PB 3 ** 50 ** SPI_MISO + _BV( 2 ) , // PB 2 ** 51 ** SPI_MOSI + _BV( 1 ) , // PB 1 ** 52 ** SPI_SCK + _BV( 0 ) , // PB 0 ** 53 ** SPI_SS + _BV( 0 ) , // PF 0 ** 54 ** A0 + _BV( 1 ) , // PF 1 ** 55 ** A1 + _BV( 2 ) , // PF 2 ** 56 ** A2 + _BV( 3 ) , // PF 3 ** 57 ** A3 + _BV( 4 ) , // PF 4 ** 58 ** A4 + _BV( 5 ) , // PF 5 ** 59 ** A5 + _BV( 6 ) , // PF 6 ** 60 ** A6 + _BV( 7 ) , // PF 7 ** 61 ** A7 + _BV( 0 ) , // PK 0 ** 62 ** A8 + _BV( 1 ) , // PK 1 ** 63 ** A9 + _BV( 2 ) , // PK 2 ** 64 ** A10 + _BV( 3 ) , // PK 3 ** 65 ** A11 + _BV( 4 ) , // PK 4 ** 66 ** A12 + _BV( 5 ) , // PK 5 ** 67 ** A13 + _BV( 6 ) , // PK 6 ** 68 ** A14 + _BV( 7 ) , // PK 7 ** 69 ** A15 +}; + +const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { + // TIMERS + // ------------------------------------------- + NOT_ON_TIMER , // PE 0 ** 0 ** USART0_RX + NOT_ON_TIMER , // PE 1 ** 1 ** USART0_TX + TIMER3B , // PE 4 ** 2 ** PWM2 + TIMER3C , // PE 5 ** 3 ** PWM3 + TIMER0B , // PG 5 ** 4 ** PWM4 + TIMER3A , // PE 3 ** 5 ** PWM5 + TIMER4A , // PH 3 ** 6 ** PWM6 + TIMER4B , // PH 4 ** 7 ** PWM7 + TIMER4C , // PH 5 ** 8 ** PWM8 + TIMER2B , // PH 6 ** 9 ** PWM9 + TIMER2A , // PB 4 ** 10 ** PWM10 + TIMER1A , // PB 5 ** 11 ** PWM11 + TIMER1B , // PB 6 ** 12 ** PWM12 + TIMER0A , // PB 7 ** 13 ** PWM13 + NOT_ON_TIMER , // PJ 1 ** 14 ** USART3_TX + NOT_ON_TIMER , // PJ 0 ** 15 ** USART3_RX + NOT_ON_TIMER , // PH 1 ** 16 ** USART2_TX + NOT_ON_TIMER , // PH 0 ** 17 ** USART2_RX + NOT_ON_TIMER , // PD 3 ** 18 ** USART1_TX + NOT_ON_TIMER , // PD 2 ** 19 ** USART1_RX + NOT_ON_TIMER , // PD 1 ** 20 ** I2C_SDA + NOT_ON_TIMER , // PD 0 ** 21 ** I2C_SCL + NOT_ON_TIMER , // PA 0 ** 22 ** D22 + NOT_ON_TIMER , // PA 1 ** 23 ** D23 + NOT_ON_TIMER , // PA 2 ** 24 ** D24 + NOT_ON_TIMER , // PA 3 ** 25 ** D25 + NOT_ON_TIMER , // PA 4 ** 26 ** D26 + NOT_ON_TIMER , // PA 5 ** 27 ** D27 + NOT_ON_TIMER , // PA 6 ** 28 ** D28 + NOT_ON_TIMER , // PA 7 ** 29 ** D29 + NOT_ON_TIMER , // PC 7 ** 30 ** D30 + NOT_ON_TIMER , // PC 6 ** 31 ** D31 + NOT_ON_TIMER , // PC 5 ** 32 ** D32 + NOT_ON_TIMER , // PC 4 ** 33 ** D33 + NOT_ON_TIMER , // PC 3 ** 34 ** D34 + NOT_ON_TIMER , // PC 2 ** 35 ** D35 + NOT_ON_TIMER , // PC 1 ** 36 ** D36 + NOT_ON_TIMER , // PC 0 ** 37 ** D37 + NOT_ON_TIMER , // PD 7 ** 38 ** D38 + NOT_ON_TIMER , // PG 2 ** 39 ** D39 + NOT_ON_TIMER , // PG 1 ** 40 ** D40 + NOT_ON_TIMER , // PG 0 ** 41 ** D41 + NOT_ON_TIMER , // PL 7 ** 42 ** D42 + NOT_ON_TIMER , // PL 6 ** 43 ** D43 + TIMER5C , // PL 5 ** 44 ** D44 + TIMER5B , // PL 4 ** 45 ** D45 + TIMER5A , // PL 3 ** 46 ** D46 + NOT_ON_TIMER , // PL 2 ** 47 ** D47 + NOT_ON_TIMER , // PL 1 ** 48 ** D48 + NOT_ON_TIMER , // PL 0 ** 49 ** D49 + NOT_ON_TIMER , // PB 3 ** 50 ** SPI_MISO + NOT_ON_TIMER , // PB 2 ** 51 ** SPI_MOSI + NOT_ON_TIMER , // PB 1 ** 52 ** SPI_SCK + NOT_ON_TIMER , // PB 0 ** 53 ** SPI_SS + NOT_ON_TIMER , // PF 0 ** 54 ** A0 + NOT_ON_TIMER , // PF 1 ** 55 ** A1 + NOT_ON_TIMER , // PF 2 ** 56 ** A2 + NOT_ON_TIMER , // PF 3 ** 57 ** A3 + NOT_ON_TIMER , // PF 4 ** 58 ** A4 + NOT_ON_TIMER , // PF 5 ** 59 ** A5 + NOT_ON_TIMER , // PF 6 ** 60 ** A6 + NOT_ON_TIMER , // PF 7 ** 61 ** A7 + NOT_ON_TIMER , // PK 0 ** 62 ** A8 + NOT_ON_TIMER , // PK 1 ** 63 ** A9 + NOT_ON_TIMER , // PK 2 ** 64 ** A10 + NOT_ON_TIMER , // PK 3 ** 65 ** A11 + NOT_ON_TIMER , // PK 4 ** 66 ** A12 + NOT_ON_TIMER , // PK 5 ** 67 ** A13 + 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 + +#endif \ No newline at end of file -- cgit v1.2.3-18-g5258 From a19a23ff92bffd2d32fa2c2c84026bdfd711c6ac Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Fri, 4 Mar 2011 21:05:05 -0500 Subject: Factoring pin definitions out of the core. That is, there's now a pins/ directory in a platform, which includes multiple directories, each of which has its own pins_arduino.h. The boards.txt gets a new preferences, .build.pins, whose values is a sub-directory of the pins/ directory (possibly with a "platform:" prefix). That sub-directory is then placed in the include path during compilation. --- cores/arduino/pins_arduino.h | 512 ------------------------------------------- 1 file changed, 512 deletions(-) delete mode 100644 cores/arduino/pins_arduino.h (limited to 'cores/arduino/pins_arduino.h') diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h deleted file mode 100644 index 169e734..0000000 --- a/cores/arduino/pins_arduino.h +++ /dev/null @@ -1,512 +0,0 @@ -/* - 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 - - $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ -*/ - -#ifndef Pins_Arduino_h -#define Pins_Arduino_h - -#include - -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) -const static uint8_t SS = 53; -const static uint8_t MOSI = 51; -const static uint8_t MISO = 50; -const static uint8_t SCK = 52; -#else -const static uint8_t SS = 10; -const static uint8_t MOSI = 11; -const static uint8_t MISO = 12; -const static uint8_t SCK = 13; -#endif - -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) -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; -#else -const static uint8_t A0 = 14; -const static uint8_t A1 = 15; -const static uint8_t A2 = 16; -const static uint8_t A3 = 17; -const static uint8_t A4 = 18; -const static uint8_t A5 = 19; -const static uint8_t A6 = 20; -const static uint8_t A7 = 21; -#endif - -#ifdef ARDUINO_MAIN - -// On the Arduino board, digital pins are also used -// for the analog output (software PWM). Analog input -// pins are a separate set. - -// 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.) - -// 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 - -#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 - - -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) -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[] = { - // PORTLIST - // ------------------------------------------- - PE , // PE 0 ** 0 ** USART0_RX - PE , // PE 1 ** 1 ** USART0_TX - PE , // PE 4 ** 2 ** PWM2 - PE , // PE 5 ** 3 ** PWM3 - PG , // PG 5 ** 4 ** PWM4 - PE , // PE 3 ** 5 ** PWM5 - PH , // PH 3 ** 6 ** PWM6 - PH , // PH 4 ** 7 ** PWM7 - PH , // PH 5 ** 8 ** PWM8 - PH , // PH 6 ** 9 ** PWM9 - PB , // PB 4 ** 10 ** PWM10 - PB , // PB 5 ** 11 ** PWM11 - PB , // PB 6 ** 12 ** PWM12 - PB , // PB 7 ** 13 ** PWM13 - PJ , // PJ 1 ** 14 ** USART3_TX - PJ , // PJ 0 ** 15 ** USART3_RX - PH , // PH 1 ** 16 ** USART2_TX - PH , // PH 0 ** 17 ** USART2_RX - PD , // PD 3 ** 18 ** USART1_TX - PD , // PD 2 ** 19 ** USART1_RX - PD , // PD 1 ** 20 ** I2C_SDA - PD , // PD 0 ** 21 ** I2C_SCL - PA , // PA 0 ** 22 ** D22 - PA , // PA 1 ** 23 ** D23 - PA , // PA 2 ** 24 ** D24 - PA , // PA 3 ** 25 ** D25 - PA , // PA 4 ** 26 ** D26 - PA , // PA 5 ** 27 ** D27 - PA , // PA 6 ** 28 ** D28 - PA , // PA 7 ** 29 ** D29 - PC , // PC 7 ** 30 ** D30 - PC , // PC 6 ** 31 ** D31 - PC , // PC 5 ** 32 ** D32 - PC , // PC 4 ** 33 ** D33 - PC , // PC 3 ** 34 ** D34 - PC , // PC 2 ** 35 ** D35 - PC , // PC 1 ** 36 ** D36 - PC , // PC 0 ** 37 ** D37 - PD , // PD 7 ** 38 ** D38 - PG , // PG 2 ** 39 ** D39 - PG , // PG 1 ** 40 ** D40 - PG , // PG 0 ** 41 ** D41 - PL , // PL 7 ** 42 ** D42 - PL , // PL 6 ** 43 ** D43 - PL , // PL 5 ** 44 ** D44 - PL , // PL 4 ** 45 ** D45 - PL , // PL 3 ** 46 ** D46 - PL , // PL 2 ** 47 ** D47 - PL , // PL 1 ** 48 ** D48 - PL , // PL 0 ** 49 ** D49 - PB , // PB 3 ** 50 ** SPI_MISO - PB , // PB 2 ** 51 ** SPI_MOSI - PB , // PB 1 ** 52 ** SPI_SCK - PB , // PB 0 ** 53 ** SPI_SS - PF , // PF 0 ** 54 ** A0 - PF , // PF 1 ** 55 ** A1 - PF , // PF 2 ** 56 ** A2 - PF , // PF 3 ** 57 ** A3 - PF , // PF 4 ** 58 ** A4 - PF , // PF 5 ** 59 ** A5 - PF , // PF 6 ** 60 ** A6 - PF , // PF 7 ** 61 ** A7 - PK , // PK 0 ** 62 ** A8 - PK , // PK 1 ** 63 ** A9 - PK , // PK 2 ** 64 ** A10 - PK , // PK 3 ** 65 ** A11 - PK , // PK 4 ** 66 ** A12 - PK , // PK 5 ** 67 ** A13 - PK , // PK 6 ** 68 ** A14 - PK , // PK 7 ** 69 ** A15 -}; - -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( 4 ) , // PE 4 ** 2 ** PWM2 - _BV( 5 ) , // PE 5 ** 3 ** PWM3 - _BV( 5 ) , // PG 5 ** 4 ** PWM4 - _BV( 3 ) , // PE 3 ** 5 ** PWM5 - _BV( 3 ) , // PH 3 ** 6 ** PWM6 - _BV( 4 ) , // PH 4 ** 7 ** PWM7 - _BV( 5 ) , // PH 5 ** 8 ** PWM8 - _BV( 6 ) , // PH 6 ** 9 ** PWM9 - _BV( 4 ) , // PB 4 ** 10 ** PWM10 - _BV( 5 ) , // PB 5 ** 11 ** PWM11 - _BV( 6 ) , // PB 6 ** 12 ** PWM12 - _BV( 7 ) , // PB 7 ** 13 ** PWM13 - _BV( 1 ) , // PJ 1 ** 14 ** USART3_TX - _BV( 0 ) , // PJ 0 ** 15 ** USART3_RX - _BV( 1 ) , // PH 1 ** 16 ** USART2_TX - _BV( 0 ) , // PH 0 ** 17 ** USART2_RX - _BV( 3 ) , // PD 3 ** 18 ** USART1_TX - _BV( 2 ) , // PD 2 ** 19 ** USART1_RX - _BV( 1 ) , // PD 1 ** 20 ** I2C_SDA - _BV( 0 ) , // PD 0 ** 21 ** I2C_SCL - _BV( 0 ) , // PA 0 ** 22 ** D22 - _BV( 1 ) , // PA 1 ** 23 ** D23 - _BV( 2 ) , // PA 2 ** 24 ** D24 - _BV( 3 ) , // PA 3 ** 25 ** D25 - _BV( 4 ) , // PA 4 ** 26 ** D26 - _BV( 5 ) , // PA 5 ** 27 ** D27 - _BV( 6 ) , // PA 6 ** 28 ** D28 - _BV( 7 ) , // PA 7 ** 29 ** D29 - _BV( 7 ) , // PC 7 ** 30 ** D30 - _BV( 6 ) , // PC 6 ** 31 ** D31 - _BV( 5 ) , // PC 5 ** 32 ** D32 - _BV( 4 ) , // PC 4 ** 33 ** D33 - _BV( 3 ) , // PC 3 ** 34 ** D34 - _BV( 2 ) , // PC 2 ** 35 ** D35 - _BV( 1 ) , // PC 1 ** 36 ** D36 - _BV( 0 ) , // PC 0 ** 37 ** D37 - _BV( 7 ) , // PD 7 ** 38 ** D38 - _BV( 2 ) , // PG 2 ** 39 ** D39 - _BV( 1 ) , // PG 1 ** 40 ** D40 - _BV( 0 ) , // PG 0 ** 41 ** D41 - _BV( 7 ) , // PL 7 ** 42 ** D42 - _BV( 6 ) , // PL 6 ** 43 ** D43 - _BV( 5 ) , // PL 5 ** 44 ** D44 - _BV( 4 ) , // PL 4 ** 45 ** D45 - _BV( 3 ) , // PL 3 ** 46 ** D46 - _BV( 2 ) , // PL 2 ** 47 ** D47 - _BV( 1 ) , // PL 1 ** 48 ** D48 - _BV( 0 ) , // PL 0 ** 49 ** D49 - _BV( 3 ) , // PB 3 ** 50 ** SPI_MISO - _BV( 2 ) , // PB 2 ** 51 ** SPI_MOSI - _BV( 1 ) , // PB 1 ** 52 ** SPI_SCK - _BV( 0 ) , // PB 0 ** 53 ** SPI_SS - _BV( 0 ) , // PF 0 ** 54 ** A0 - _BV( 1 ) , // PF 1 ** 55 ** A1 - _BV( 2 ) , // PF 2 ** 56 ** A2 - _BV( 3 ) , // PF 3 ** 57 ** A3 - _BV( 4 ) , // PF 4 ** 58 ** A4 - _BV( 5 ) , // PF 5 ** 59 ** A5 - _BV( 6 ) , // PF 6 ** 60 ** A6 - _BV( 7 ) , // PF 7 ** 61 ** A7 - _BV( 0 ) , // PK 0 ** 62 ** A8 - _BV( 1 ) , // PK 1 ** 63 ** A9 - _BV( 2 ) , // PK 2 ** 64 ** A10 - _BV( 3 ) , // PK 3 ** 65 ** A11 - _BV( 4 ) , // PK 4 ** 66 ** A12 - _BV( 5 ) , // PK 5 ** 67 ** A13 - _BV( 6 ) , // PK 6 ** 68 ** A14 - _BV( 7 ) , // PK 7 ** 69 ** A15 -}; - -const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { - // TIMERS - // ------------------------------------------- - NOT_ON_TIMER , // PE 0 ** 0 ** USART0_RX - NOT_ON_TIMER , // PE 1 ** 1 ** USART0_TX - TIMER3B , // PE 4 ** 2 ** PWM2 - TIMER3C , // PE 5 ** 3 ** PWM3 - TIMER0B , // PG 5 ** 4 ** PWM4 - TIMER3A , // PE 3 ** 5 ** PWM5 - TIMER4A , // PH 3 ** 6 ** PWM6 - TIMER4B , // PH 4 ** 7 ** PWM7 - TIMER4C , // PH 5 ** 8 ** PWM8 - TIMER2B , // PH 6 ** 9 ** PWM9 - TIMER2A , // PB 4 ** 10 ** PWM10 - TIMER1A , // PB 5 ** 11 ** PWM11 - TIMER1B , // PB 6 ** 12 ** PWM12 - TIMER0A , // PB 7 ** 13 ** PWM13 - NOT_ON_TIMER , // PJ 1 ** 14 ** USART3_TX - NOT_ON_TIMER , // PJ 0 ** 15 ** USART3_RX - NOT_ON_TIMER , // PH 1 ** 16 ** USART2_TX - NOT_ON_TIMER , // PH 0 ** 17 ** USART2_RX - NOT_ON_TIMER , // PD 3 ** 18 ** USART1_TX - NOT_ON_TIMER , // PD 2 ** 19 ** USART1_RX - NOT_ON_TIMER , // PD 1 ** 20 ** I2C_SDA - NOT_ON_TIMER , // PD 0 ** 21 ** I2C_SCL - NOT_ON_TIMER , // PA 0 ** 22 ** D22 - NOT_ON_TIMER , // PA 1 ** 23 ** D23 - NOT_ON_TIMER , // PA 2 ** 24 ** D24 - NOT_ON_TIMER , // PA 3 ** 25 ** D25 - NOT_ON_TIMER , // PA 4 ** 26 ** D26 - NOT_ON_TIMER , // PA 5 ** 27 ** D27 - NOT_ON_TIMER , // PA 6 ** 28 ** D28 - NOT_ON_TIMER , // PA 7 ** 29 ** D29 - NOT_ON_TIMER , // PC 7 ** 30 ** D30 - NOT_ON_TIMER , // PC 6 ** 31 ** D31 - NOT_ON_TIMER , // PC 5 ** 32 ** D32 - NOT_ON_TIMER , // PC 4 ** 33 ** D33 - NOT_ON_TIMER , // PC 3 ** 34 ** D34 - NOT_ON_TIMER , // PC 2 ** 35 ** D35 - NOT_ON_TIMER , // PC 1 ** 36 ** D36 - NOT_ON_TIMER , // PC 0 ** 37 ** D37 - NOT_ON_TIMER , // PD 7 ** 38 ** D38 - NOT_ON_TIMER , // PG 2 ** 39 ** D39 - NOT_ON_TIMER , // PG 1 ** 40 ** D40 - NOT_ON_TIMER , // PG 0 ** 41 ** D41 - NOT_ON_TIMER , // PL 7 ** 42 ** D42 - NOT_ON_TIMER , // PL 6 ** 43 ** D43 - TIMER5C , // PL 5 ** 44 ** D44 - TIMER5B , // PL 4 ** 45 ** D45 - TIMER5A , // PL 3 ** 46 ** D46 - NOT_ON_TIMER , // PL 2 ** 47 ** D47 - NOT_ON_TIMER , // PL 1 ** 48 ** D48 - NOT_ON_TIMER , // PL 0 ** 49 ** D49 - NOT_ON_TIMER , // PB 3 ** 50 ** SPI_MISO - NOT_ON_TIMER , // PB 2 ** 51 ** SPI_MOSI - NOT_ON_TIMER , // PB 1 ** 52 ** SPI_SCK - NOT_ON_TIMER , // PB 0 ** 53 ** SPI_SS - NOT_ON_TIMER , // PF 0 ** 54 ** A0 - NOT_ON_TIMER , // PF 1 ** 55 ** A1 - NOT_ON_TIMER , // PF 2 ** 56 ** A2 - NOT_ON_TIMER , // PF 3 ** 57 ** A3 - NOT_ON_TIMER , // PF 4 ** 58 ** A4 - NOT_ON_TIMER , // PF 5 ** 59 ** A5 - NOT_ON_TIMER , // PF 6 ** 60 ** A6 - NOT_ON_TIMER , // PF 7 ** 61 ** A7 - NOT_ON_TIMER , // PK 0 ** 62 ** A8 - NOT_ON_TIMER , // PK 1 ** 63 ** A9 - NOT_ON_TIMER , // PK 2 ** 64 ** A10 - NOT_ON_TIMER , // PK 3 ** 65 ** A11 - NOT_ON_TIMER , // PK 4 ** 66 ** A12 - NOT_ON_TIMER , // PK 5 ** 67 ** A13 - 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 - -#endif \ No newline at end of file -- cgit v1.2.3-18-g5258