# 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,               /* Aliased to NORTH_RX_PIN */
    00061   ARDUINO_TX = 1,               /* Aliased to NORTH_TX_PIN */
    00062   ARDUINO_DIGITAL_PIN2 = 2,     /* Aliased to NORTH_D0_PIN */
    00063   ARDUINO_DIGITAL_PIN3 = 3,     /* Aliased to NORTH_D1_PIN */
    00064   ARDUINO_DIGITAL_PIN4 = 4,     /* Aliased to NORTH_D2_PIN */
    00065   ARDUINO_DIGITAL_PIN5 = 5,     /* Aliased to NORTH_D3_PIN */
    00066   ARDUINO_DIGITAL_PIN6 = 6,     /* Aliased to SOUTH_D0_PIN */
    00067   ARDUINO_DIGITAL_PIN7 = 7,     /* Aliased to SOUTH_D1_PIN */
    00068   ARDUINO_DIGITAL_PIN8 = 8,     /* Aliased to SOUTH_D2_PIN */
    00069   ARDUINO_DIGITAL_PIN9 = 9,     /* Aliased to SOUTH_D3_PIN */
    00070   ARDUINO_DIGITAL_PIN10 = 10,   /* Aliased to EAST_D0_PIN */
    00071   ARDUINO_DIGITAL_PIN11 = 11,   /* Aliased to EAST_D1_PIN */
    00072   ARDUINO_DIGITAL_PIN12 = 12,   /* Aliased to EAST_D2_PIN */
    00073   ARDUINO_DIGITAL_PIN13 = 13,   /* Aliased to BODY_RGB_RED_PIN */
    00074
    00075   ARDUINO_ANALOG_PIN1 = 14,     /* Aliased to NORTH_ISENSE_PIN */
    00076   ARDUINO_ANALOG_PIN2 = 15,     /* Aliased to SOUTH_ISENSE_PIN */
    00077   ARDUINO_ANALOG_PIN3 = 16,     /* Aliased to EAST_ISENSE_PIN */
    00078   ARDUINO_ANALOG_PIN4 = 17,     /* Aliased to WEST_ISENSE_PIN */
    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, /* 20 */
    00084   NORTH_D1_PIN = NORTH_BASE_PIN+FACE_D1_PIN, /* 21 */
    00085   NORTH_D2_PIN = NORTH_BASE_PIN+FACE_D2_PIN, /* 22 */
    00086   NORTH_D3_PIN = NORTH_BASE_PIN+FACE_D3_PIN, /* 23 */
    00087   NORTH_RX_PIN = NORTH_BASE_PIN+FACE_RX_PIN, /* 24 */
    00088   NORTH_TX_PIN = NORTH_BASE_PIN+FACE_TX_PIN, /* 25 */
    00089   NORTH_VIN_ENABLE_PIN = NORTH_BASE_PIN+FACE_VIN_ENABLE_PIN, /* 26 */
    00090   NORTH_VOUT_ENABLE_PIN = NORTH_BASE_PIN+FACE_VOUT_ENABLE_PIN, /* 27 */
    00091   NORTH_ISENSE_PIN = NORTH_BASE_PIN+FACE_ISENSE_PIN, /* 28 */
    00092   NORTH_LED_PIN = NORTH_BASE_PIN+FACE_LED_PIN, /* 29 */
    00093   NORTH_SIDE_LED_PIN = NORTH_BASE_PIN+FACE_SIDE_LED_PIN, /* 30 */
    00094
    00095   SOUTH_BASE_PIN = 31,
    00096   SOUTH_D0_PIN = SOUTH_BASE_PIN+FACE_D0_PIN, /* 31 */
    00097   SOUTH_D1_PIN = SOUTH_BASE_PIN+FACE_D1_PIN, /* 32 */
    00098   SOUTH_D2_PIN = SOUTH_BASE_PIN+FACE_D2_PIN, /* 33 */
    00099   SOUTH_D3_PIN = SOUTH_BASE_PIN+FACE_D3_PIN, /* 34 */
    00100   SOUTH_RX_PIN = SOUTH_BASE_PIN+FACE_RX_PIN, /* 35 */
    00101   SOUTH_TX_PIN = SOUTH_BASE_PIN+FACE_TX_PIN, /* 36 */
    00102   SOUTH_VIN_ENABLE_PIN = SOUTH_BASE_PIN+FACE_VIN_ENABLE_PIN, /* 37 */
    00103   SOUTH_VOUT_ENABLE_PIN = SOUTH_BASE_PIN+FACE_VOUT_ENABLE_PIN, /* 38 */
    00104   SOUTH_ISENSE_PIN = SOUTH_BASE_PIN+FACE_ISENSE_PIN, /* 39 */
    00105   SOUTH_LED_PIN = SOUTH_BASE_PIN+FACE_LED_PIN, /* 40 */
    00106   SOUTH_SIDE_LED_PIN = SOUTH_BASE_PIN+FACE_SIDE_LED_PIN, /* 41 */
    00107
    00108   EAST_BASE_PIN = 42,
    00109   EAST_D0_PIN = EAST_BASE_PIN+FACE_D0_PIN, /* 42 */
    00110   EAST_D1_PIN = EAST_BASE_PIN+FACE_D1_PIN, /* 43 */
    00111   EAST_D2_PIN = EAST_BASE_PIN+FACE_D2_PIN, /* 44 */
    00112   EAST_D3_PIN = EAST_BASE_PIN+FACE_D3_PIN, /* 45 */
    00113   EAST_RX_PIN = EAST_BASE_PIN+FACE_RX_PIN, /* 46 */
    00114   EAST_TX_PIN = EAST_BASE_PIN+FACE_TX_PIN, /* 47 */
    00115   EAST_VIN_ENABLE_PIN = EAST_BASE_PIN+FACE_VIN_ENABLE_PIN, /* 48 */
    00116   EAST_VOUT_ENABLE_PIN = EAST_BASE_PIN+FACE_VOUT_ENABLE_PIN, /* 49 */
    00117   EAST_ISENSE_PIN = EAST_BASE_PIN+FACE_ISENSE_PIN, /* 50 */
    00118   EAST_LED_PIN = EAST_BASE_PIN+FACE_LED_PIN, /* 51 */
    00119   EAST_SIDE_LED_PIN = EAST_BASE_PIN+FACE_SIDE_LED_PIN, /* 52 */
    00120
    00121   WEST_BASE_PIN = 53,
    00122   WEST_D0_PIN = WEST_BASE_PIN+FACE_D0_PIN, /* 53 */
    00123   WEST_D1_PIN = WEST_BASE_PIN+FACE_D1_PIN, /* 54 */
    00124   WEST_D2_PIN = WEST_BASE_PIN+FACE_D2_PIN, /* 55 */
    00125   WEST_D3_PIN = WEST_BASE_PIN+FACE_D3_PIN, /* 56 */
    00126   WEST_RX_PIN = WEST_BASE_PIN+FACE_RX_PIN, /* 57 */
    00127   WEST_TX_PIN = WEST_BASE_PIN+FACE_TX_PIN, /* 58 */
    00128   WEST_VIN_ENABLE_PIN = WEST_BASE_PIN+FACE_VIN_ENABLE_PIN, /* 59 */
    00129   WEST_VOUT_ENABLE_PIN = WEST_BASE_PIN+FACE_VOUT_ENABLE_PIN, /* 60 */
    00130   WEST_ISENSE_PIN = WEST_BASE_PIN+FACE_ISENSE_PIN, /* 61 */
    00131   WEST_LED_PIN = WEST_BASE_PIN+FACE_LED_PIN, /* 62 */
    00132   WEST_SIDE_LED_PIN = WEST_BASE_PIN+FACE_SIDE_LED_PIN, /* 63 */
    00133
    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,
    00139
    00140   BODY_EEPROM_SSEL1_PIN = 68,
    00141   BODY_EEPROM_SCK1_PIN = 69,
    00142   BODY_EEPROM_MISO1_PIN = 70,
    00143   BODY_EEPROM_MOSI1_PIN = 71,
    00144
    00145   VIRTUAL_PIN_COUNT = 72,
    00146
    00147   /* Alternate names and structures on the pin numbers */
    00148   ALIAS_COUNT=20,
    00149   FIRST_SFB_PIN=20
    00150 };
    00151
    00157 struct PinInfo_s  {
    00158   u8 portNumber;
    00159   u8 bitNumber;
    00160   u8 aliasMode;
    00161   u8 flags;
    00162 } __attribute__ ((aligned (4)));
    00163
    00170 #define SFB_GET_PIN_PORT_AND_MASK(sfbPin,infoVar,portVar,maskVar) \
    00171  do {                                                           \
    00172    (infoVar) = pinInfoMap[sfbPin];                              \
    00173    if ((infoVar).aliasMode >= ALIAS_COUNT) {                    \
    00174      (sfbPin) = (infoVar).aliasMode;                            \
    00175      (infoVar) = pinInfoMap[sfbPin];                            \
    00176    }                                                            \
    00177    (portVar) = (infoVar).portNumber;                            \
    00178    (maskVar) = 1UL<<(infoVar).bitNumber;                        \
    00179  } while (0)
    00180
    00181 typedef const struct PinInfo_s PinInfo_t;  /* We're putting the pin info into flash, so, const.. */
    00182
    00183 extern PinInfo_t pinInfoMap[VIRTUAL_PIN_COUNT];  /* Read-only */
    00184
    00185 enum { PIN_SKETCH_MAP_WORDS = (VIRTUAL_PIN_COUNT+31)/32 };
    00186
    00187 #define GET_SKETCH_FLAG(sfbPin) \
    00188   ((pinSketchMap[(sfbPin)>>5]>>((sfbPin)&31))&1)
    00189 #define SET_SKETCH_FLAG(sfbPin) \
    00190   (pinSketchMap[(sfbPin)>>5] |= 1<<((sfbPin)&31))
    00191 #define CLR_SKETCH_FLAG(sfbPin) \
    00192   (pinSketchMap[(sfbPin)>>5] &= ~(1<<((sfbPin)&31)))
    00193
    00194 extern u32 pinSketchMap[PIN_SKETCH_MAP_WORDS];   /* Bit mask of which pins the sketch is controlling */
    00195
    00196 extern int pinInFace(int facePin, int face);
    00197
    00198 extern void reflexDigitalWrite(int sfbPin, int value);
    00199 extern void implDigitalWrite(int sfbPin, int value);
    00200
    00201 static inline void reflexLedOn(int sfbPin) { reflexDigitalWrite(sfbPin,LOW); }
    00202 static inline void reflexLedOff(int sfbPin) { reflexDigitalWrite(sfbPin,HIGH); }
    00203 static inline void reflexLedSet(int sfbPin,int on) { reflexDigitalWrite(sfbPin,on?LOW:HIGH); }
    00204
    00205 extern int reflexDigitalRead(int sfbPin);
    00206 extern int implDigitalRead(int sfbPin);
    00207
    00208 extern void reflexPinMode(int sfbPin, int mode);
    00209 extern void implPinMode(int sfbPin, int mode);
    00210
    00211 extern void pins_startup_initialization();
    00212
    00222 #define PULLUP_ONLY 0
    00223 #define NEITHER_PULLUP_NOR_PULLDOWN 2
    00224 #define PULLDOWN_ONLY 3
    00225
    00226 extern void reflexSetPinResistor(int sfbPin, int pullupDownCode);
    00227 extern void implSetPinResistor(int sfbPin, int pullupDownCode);
    00228
    00229 #include "SFBHWPins.h"
    00230
    00231 #endif  /* SFBPINS_H */