Home | History | Annotate | Download | only in arduino
      1 /*
      2   pins_arduino.h - Pin definition functions for Arduino
      3   Part of Arduino - http://www.arduino.cc/
      4 
      5   Copyright (c) 2007 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: wiring.h 249 2007-02-03 16:52:51Z mellis $
     23 */
     24 
     25 #ifndef Pins_Arduino_h
     26 #define Pins_Arduino_h
     27 
     28 #include <avr/pgmspace.h>
     29 
     30 #define NOT_A_PIN 0
     31 #define NOT_A_PORT 0
     32 
     33 #define NOT_ON_TIMER 0
     34 #define TIMER0A 1
     35 #define TIMER0B 2
     36 #define TIMER1A 3
     37 #define TIMER1B 4
     38 #define TIMER2  5
     39 #define TIMER2A 6
     40 #define TIMER2B 7
     41 
     42 #define TIMER3A 8
     43 #define TIMER3B 9
     44 #define TIMER3C 10
     45 #define TIMER4A 11
     46 #define TIMER4B 12
     47 #define TIMER4C 13
     48 #define TIMER5A 14
     49 #define TIMER5B 15
     50 #define TIMER5C 16
     51 
     52 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
     53 const static uint8_t SS   = 53;
     54 const static uint8_t MOSI = 51;
     55 const static uint8_t MISO = 50;
     56 const static uint8_t SCK  = 52;
     57 #else
     58 const static uint8_t SS   = 10;
     59 const static uint8_t MOSI = 11;
     60 const static uint8_t MISO = 12;
     61 const static uint8_t SCK  = 13;
     62 #endif
     63 
     64 // On the ATmega1280, the addresses of some of the port registers are
     65 // greater than 255, so we can't store them in uint8_t's.
     66 extern const uint16_t PROGMEM port_to_mode_PGM[];
     67 extern const uint16_t PROGMEM port_to_input_PGM[];
     68 extern const uint16_t PROGMEM port_to_output_PGM[];
     69 
     70 extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
     71 // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
     72 extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
     73 extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
     74 
     75 // Get the bit location within the hardware port of the given virtual pin.
     76 // This comes from the pins_*.c file for the active board configuration.
     77 //
     78 // These perform slightly better as macros compared to inline functions
     79 //
     80 #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
     81 #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
     82 #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
     83 #define analogInPinToBit(P) (P)
     84 #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
     85 #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
     86 #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
     87 
     88 #endif
     89