/*
  pins_wiring.h - Pin definition functions for Wiring
  To use with the OneWire library for Wiring, place this file
  in the utility directory under the OneWire library
  
  Copyright (c) 2008 Alan K. Duncan
  This is based very heavily on pin_arduino.c in the Arduino
  distribution.  It bears the same GNU Lesser General Public License
  as listed below

  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_Wiring_h
#define Pins_Wiring_h

#include <avr/pgmspace.h>

#define NOT_A_PIN       0
#define NOT_A_PORT      0

#define NOT_ON_TIMER    0
#define TIMER0          1
#define TIMER1A         2
#define TIMER1B         3
#define TIMER2          4
#define TIMER3A         5
#define TIMER3B         6
#define TIMER3C         7

extern const uint8_t PROGMEM *port_to_mode_PGM[];
extern const uint8_t PROGMEM *port_to_input_PGM[];
extern const uint8_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[];

// 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_byte( port_to_output_PGM + (P))) )
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_input_PGM + (P))) )
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_mode_PGM + (P))) )

#endif
