# SFBPins.h

Go to the documentation of this file.

    00001 /*                                       -*- mode:C++; fill-column: 100 -*-
    00002   SFBPins.h Definitions of the programmer visible 'pins' in SFB
    00003   Copyright (C) 2008 The Regents of the University of New Mexico.  All rights reserved.
    00004
    00005   This library is free software; you can redistribute it and/or
    00006   modify it under the terms of the GNU Lesser General Public
    00007   License as published by the Free Software Foundation; either
    00008   version 2.1 of the License, or (at your option) any later version.
    00009
    00010   This library is distributed in the hope that it will be useful,
    00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013   Lesser General Public License for more details.
    00014
    00015   You should have received a copy of the GNU General Public License
    00016   along with this library; if not, write to the Free Software
    00017   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00018   USA
    00019
    00020   $Id$
    00021 */
    00029 #ifndef SFBPINS_H
    00030 #define SFBPINS_H
    00031
    00032 #include "SFBTypes.h"  /* for u8, etc */
    00033 #include "SFBConstants.h"  /* for HIGH, LOW, etc */
    00034
    00035 #define NOT_A_PIN 99
    00036 #define NOT_A_PORT 99
    00037
    00038 /* Face pin offsets */
    00039 enum {
    00040   FACE_D0_PIN = 0,
    00041   FACE_D1_PIN = 1,
    00042   FACE_D2_PIN = 2,
    00043   FACE_D3_PIN = 3,
    00044   FACE_RX_PIN = 4,
    00045   FACE_TX_PIN = 5,
    00046   FACE_VIN_ENABLE_PIN = 6,
    00047   FACE_VOUT_ENABLE_PIN = 7,
    00048   FACE_ISENSE_PIN = 8,
    00049   FACE_LED_PIN = 9,
    00050   FACE_SIDE_LED_PIN = 10,
    00051   FACE_PIN_COUNT = 11
    00052 };
    00053
    00054 /* Virtual pin definitions.  Indices into the tables below.  First set
    00055  * of values are aliases, forming a kind Arduino compatibility layer.
    00056  * In SFBPins.c they are aliased to the 'real' SFB pins appearing later
    00057  * in the table.
    00058  */
    00059 enum {
    00060   ARDUINO_RX = 0,
    00061   ARDUINO_TX = 1,
    00062   ARDUINO_DIGITAL_PIN2 = 2,
    00063   ARDUINO_DIGITAL_PIN3 = 3,
    00064   ARDUINO_DIGITAL_PIN4 = 4,
    00065   ARDUINO_DIGITAL_PIN5 = 5,
    00066   ARDUINO_DIGITAL_PIN6 = 6,
    00067   ARDUINO_DIGITAL_PIN7 = 7,
    00068   ARDUINO_DIGITAL_PIN8 = 8,
    00069   ARDUINO_DIGITAL_PIN9 = 9,
    00070   ARDUINO_DIGITAL_PIN10 = 10,
    00071   ARDUINO_DIGITAL_PIN11 = 11,
    00072   ARDUINO_DIGITAL_PIN12 = 12,
    00073   ARDUINO_DIGITAL_PIN13 = 13,
    00075   ARDUINO_ANALOG_PIN1 = 14,
    00076   ARDUINO_ANALOG_PIN2 = 15,
    00077   ARDUINO_ANALOG_PIN3 = 16,
    00078   ARDUINO_ANALOG_PIN4 = 17,
    00079   ARDUINO_ANALOG_PIN5 = 18,
    00080   ARDUINO_ANALOG_PIN6 = 19,
    00081
    00082   NORTH_BASE_PIN = 20,
    00083   NORTH_D0_PIN = NORTH_BASE_PIN+FACE_D0_PIN,
    00084   NORTH_D1_PIN = NORTH_BASE_PIN+FACE_D1_PIN,
    00085   NORTH_D2_PIN = NORTH_BASE_PIN+FACE_D2_PIN,
    00086   NORTH_D3_PIN = NORTH_BASE_PIN+FACE_D3_PIN,
    00087   NORTH_RX_PIN = NORTH_BASE_PIN+FACE_RX_PIN,
    00088   NORTH_TX_PIN = NORTH_BASE_PIN+FACE_TX_PIN,
    00089   NORTH_VIN_ENABLE_PIN = NORTH_BASE_PIN+FACE_VIN_ENABLE_PIN,
    00090   NORTH_VOUT_ENABLE_PIN = NORTH_BASE_PIN+FACE_VOUT_ENABLE_PIN,
    00091   NORTH_ISENSE_PIN = NORTH_BASE_PIN+FACE_ISENSE_PIN,
    00092   NORTH_LED_PIN = NORTH_BASE_PIN+FACE_LED_PIN,
    00093   NORTH_SIDE_LED_PIN = NORTH_BASE_PIN+FACE_SIDE_LED_PIN,
    00095   SOUTH_BASE_PIN = 31,
    00096   SOUTH_D0_PIN = SOUTH_BASE_PIN+FACE_D0_PIN,
    00097   SOUTH_D1_PIN = SOUTH_BASE_PIN+FACE_D1_PIN,
    00098   SOUTH_D2_PIN = SOUTH_BASE_PIN+FACE_D2_PIN,
    00099   SOUTH_D3_PIN = SOUTH_BASE_PIN+FACE_D3_PIN,
    00100   SOUTH_RX_PIN = SOUTH_BASE_PIN+FACE_RX_PIN,
    00101   SOUTH_TX_PIN = SOUTH_BASE_PIN+FACE_TX_PIN,
    00102   SOUTH_VIN_ENABLE_PIN = SOUTH_BASE_PIN+FACE_VIN_ENABLE_PIN,
    00103   SOUTH_VOUT_ENABLE_PIN = SOUTH_BASE_PIN+FACE_VOUT_ENABLE_PIN,
    00104   SOUTH_ISENSE_PIN = SOUTH_BASE_PIN+FACE_ISENSE_PIN,
    00105   SOUTH_LED_PIN = SOUTH_BASE_PIN+FACE_LED_PIN,
    00106   SOUTH_SIDE_LED_PIN = SOUTH_BASE_PIN+FACE_SIDE_LED_PIN,
    00108   EAST_BASE_PIN = 42,
    00109   EAST_D0_PIN = EAST_BASE_PIN+FACE_D0_PIN,
    00110   EAST_D1_PIN = EAST_BASE_PIN+FACE_D1_PIN,
    00111   EAST_D2_PIN = EAST_BASE_PIN+FACE_D2_PIN,
    00112   EAST_D3_PIN = EAST_BASE_PIN+FACE_D3_PIN,
    00113   EAST_RX_PIN = EAST_BASE_PIN+FACE_RX_PIN,
    00114   EAST_TX_PIN = EAST_BASE_PIN+FACE_TX_PIN,
    00115   EAST_VIN_ENABLE_PIN = EAST_BASE_PIN+FACE_VIN_ENABLE_PIN,
    00116   EAST_VOUT_ENABLE_PIN = EAST_BASE_PIN+FACE_VOUT_ENABLE_PIN,
    00117   EAST_ISENSE_PIN = EAST_BASE_PIN+FACE_ISENSE_PIN,
    00118   EAST_LED_PIN = EAST_BASE_PIN+FACE_LED_PIN,
    00119   EAST_SIDE_LED_PIN = EAST_BASE_PIN+FACE_SIDE_LED_PIN,
    00121   WEST_BASE_PIN = 53,
    00122   WEST_D0_PIN = WEST_BASE_PIN+FACE_D0_PIN,
    00123   WEST_D1_PIN = WEST_BASE_PIN+FACE_D1_PIN,
    00124   WEST_D2_PIN = WEST_BASE_PIN+FACE_D2_PIN,
    00125   WEST_D3_PIN = WEST_BASE_PIN+FACE_D3_PIN,
    00126   WEST_RX_PIN = WEST_BASE_PIN+FACE_RX_PIN,
    00127   WEST_TX_PIN = WEST_BASE_PIN+FACE_TX_PIN,
    00128   WEST_VIN_ENABLE_PIN = WEST_BASE_PIN+FACE_VIN_ENABLE_PIN,
    00129   WEST_VOUT_ENABLE_PIN = WEST_BASE_PIN+FACE_VOUT_ENABLE_PIN,
    00130   WEST_ISENSE_PIN = WEST_BASE_PIN+FACE_ISENSE_PIN,
    00131   WEST_LED_PIN = WEST_BASE_PIN+FACE_LED_PIN,
    00132   WEST_SIDE_LED_PIN = WEST_BASE_PIN+FACE_SIDE_LED_PIN,
    00134   /* Non-face-specific pins */
    00135   BODY_SWITCH0_PIN = 64,
    00136   BODY_RGB_RED_PIN = 65,
    00137   BODY_RGB_GREEN_PIN = 66,
    00138   BODY_RGB_BLUE_PIN = 67,
    00140   BODY_EEPROM_SSEL1_PIN = 68,
    00141   BODY_EEPROM_SCK1_PIN = 69,
    00142   BODY_EEPROM_MISO1_PIN = 70,
    00143   BODY_EEPROM_MOSI1_PIN = 71,
    00145   BODY_AMUX_READ_PIN = 72,
    00146   BODY_AMUX_SELA_PIN = 73,
    00147   BODY_AMUX_SELB_PIN = 74,
    00148   BODY_AMUX_SELC_PIN = 75,
    00150   VIRTUAL_PIN_COUNT = 76,
    00151
    00152   /* Alternate names and structures on the pin numbers */
    00153   ALIAS_COUNT=20,
    00154   FIRST_SFB_PIN=20
    00155 };
    00156
    00162 struct PinInfo_s  {
    00163   u8 portNumber;
    00164   u8 bitNumber;
    00165   u8 aliasMode;
    00166   u8 flags;
    00167 } __attribute__ ((aligned (4)));
    00168
    00175 #define SFB_GET_PIN_PORT_AND_MASK(sfbPin,infoVar,portVar,maskVar) \
    00176  do {                                                           \
    00177    (infoVar) = pinInfoMap[sfbPin];                              \
    00178    if ((infoVar).aliasMode >= ALIAS_COUNT) {                    \
    00179      (sfbPin) = (infoVar).aliasMode;                            \
    00180      (infoVar) = pinInfoMap[sfbPin];                            \
    00181    }                                                            \
    00182    (portVar) = (infoVar).portNumber;                            \
    00183    (maskVar) = 1UL<<(infoVar).bitNumber;                        \
    00184  } while (0)
    00185
    00186 typedef const struct PinInfo_s PinInfo_t;  /* We're putting the pin info into flash, so, const.. */
    00187
    00188 extern PinInfo_t pinInfoMap[VIRTUAL_PIN_COUNT];  /* Read-only */
    00189
    00190 enum { PIN_SKETCH_MAP_WORDS = (VIRTUAL_PIN_COUNT+31)/32 };
    00191
    00192 #define GET_SKETCH_FLAG(sfbPin) \
    00193   ((pinSketchMap[(sfbPin)>>5]>>((sfbPin)&31))&1)
    00194 #define SET_SKETCH_FLAG(sfbPin) \
    00195   (pinSketchMap[(sfbPin)>>5] |= 1<<((sfbPin)&31))
    00196 #define CLR_SKETCH_FLAG(sfbPin) \
    00197   (pinSketchMap[(sfbPin)>>5] &= ~(1<<((sfbPin)&31)))
    00198
    00199 extern u32 pinSketchMap[PIN_SKETCH_MAP_WORDS];   /* Bit mask of which pins the sketch is controlling */
    00200
    00201 extern int pinInFace(int facePin, int face);
    00202
    00203 extern void reflexDigitalWrite(int sfbPin, int value);
    00204 extern void implDigitalWrite(int sfbPin, int value);
    00205
    00206 static inline void reflexLedOn(int sfbPin) { reflexDigitalWrite(sfbPin,LOW); }
    00207 static inline void reflexLedOff(int sfbPin) { reflexDigitalWrite(sfbPin,HIGH); }
    00208 static inline void reflexLedSet(int sfbPin,int on) { reflexDigitalWrite(sfbPin,on?LOW:HIGH); }
    00209
    00210 extern int reflexDigitalRead(int sfbPin);
    00211 extern int implDigitalRead(int sfbPin);
    00212
    00213 extern void reflexPinMode(int sfbPin, int mode);
    00214 extern void implPinMode(int sfbPin, int mode);
    00215
    00216 extern void pins_startup_initialization();
    00217
    00227 #define PULLUP_ONLY 0
    00228 #define NEITHER_PULLUP_NOR_PULLDOWN 2
    00229 #define PULLDOWN_ONLY 3
    00230
    00231 extern void reflexSetPinResistor(int sfbPin, int pullupDownCode);
    00232 extern void implSetPinResistor(int sfbPin, int pullupDownCode);
    00233
    00234 #include "SFBHWPins.h"
    00235
    00236 #endif  /* SFBPINS_H */