pins_arduino.h
1 /* 2 pins_arduino.c - pin definitions for the Arduino board 3 Part of Arduino / Wiring Lite 4 5 Copyright (c) 2005 David A. Mellis 6 7 This library is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or (at your option) any later version. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General 18 Public License along with this library; if not, write to the 19 Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 Boston, MA 02111-1307 USA 21 22 $Id: pins_arduino.c 565 2009-03-25 10:50:00Z dmellis $ 23 24 Modified 28-08-2009 for attiny84 R.Wiersma 25 Modified 09-10-2009 for attiny45 A.Saporetti 26 */ 27 28 #ifndef Pins_Arduino_h 29 #define Pins_Arduino_h 30 31 #include <avr/pgmspace.h> 32 33 // Defines to make D4 support PWM 34 // See for more info: http://forums.adafruit.com/viewtopic.php?f=52&t=43951 35 #define TCCR1A GTCCR 36 #define WGM10 PWM1B 37 38 // ATMEL ATTINY45 / ARDUINO 39 // 40 // +-\/-+ 41 // Ain0 (D 5) PB5 1| |8 Vcc 42 // Ain3 (D 3) PB3 2| |7 PB2 (D 2) Ain1 43 // Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1 44 // GND 4| |5 PB0 (D 0) pwm0 45 // +----+ 46 47 #define NUM_DIGITAL_PINS 3 48 #define NUM_ANALOG_INPUTS 1 49 #define LED_BUILTIN 1 50 #define SPI_INTERFACES_COUNT 0 51 52 #define PIN_A0 (6) 53 #define PIN_A1 (7) 54 #define PIN_A2 (8) 55 #define PIN_A3 (9) 56 57 static const uint8_t A0 = PIN_A0; 58 static const uint8_t A1 = PIN_A1; 59 static const uint8_t A2 = PIN_A2; 60 static const uint8_t A3 = PIN_A3; 61 62 #define digitalPinToPCICR(p) ( ((p) >= 0 && (p) <= 4) ? (&GIMSK) : ((uint8_t *)0) ) 63 #define digitalPinToPCICRbit(p) ( PCIE ) 64 #define digitalPinToPCMSK(p) ( ((p) <= 4) ? (&PCMSK) : ((uint8_t *)0) ) 65 #define digitalPinToPCMSKbit(p) ( (p) ) 66 67 #define digitalPinToInterrupt(p) ((p) == 2 ? 0 : NOT_AN_INTERRUPT) 68 69 #define analogPinToChannel(p) ( (p) < 6 ? (p) : (p) - 6 ) 70 71 #define TCCR1A GTCCR 72 73 #ifdef ARDUINO_MAIN 74 75 void initVariant() 76 { 77 GTCCR |= (1 << PWM1B); 78 } 79 80 // these arrays map port names (e.g. port B) to the 81 // appropriate addresses for various functions (e.g. reading 82 // and writing) tiny45 only port B 83 const uint16_t PROGMEM port_to_mode_PGM[] = { 84 NOT_A_PORT, 85 NOT_A_PORT, 86 (uint16_t) &DDRB, 87 }; 88 89 const uint16_t PROGMEM port_to_output_PGM[] = { 90 NOT_A_PORT, 91 NOT_A_PORT, 92 (uint16_t) &PORTB, 93 }; 94 95 const uint16_t PROGMEM port_to_input_PGM[] = { 96 NOT_A_PIN, 97 NOT_A_PIN, 98 (uint16_t) &PINB, 99 }; 100 101 const uint8_t PROGMEM digital_pin_to_port_PGM[] = { 102 PB, /* 0 */ 103 PB, 104 PB, 105 PB, 106 PB, 107 PB, // 5 108 PB, // A0 109 PB, 110 PB, 111 PB, // A4 112 }; 113 114 const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { 115 _BV(0), /* 0, port B */ 116 _BV(1), 117 _BV(2), 118 _BV(3), /* 3 port B */ 119 _BV(4), 120 _BV(5), 121 _BV(5), 122 _BV(2), 123 _BV(4), 124 _BV(3), 125 }; 126 127 const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { 128 TIMER0A, /* OC0A */ 129 TIMER0B, 130 NOT_ON_TIMER, 131 NOT_ON_TIMER, 132 TIMER1B, 133 NOT_ON_TIMER, 134 NOT_ON_TIMER, 135 NOT_ON_TIMER, 136 NOT_ON_TIMER, 137 NOT_ON_TIMER, 138 }; 139 140 #endif 141 142 #endif