![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Fork to see if I can get working
Dependencies: BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated
Fork of xDotBridge_update_test20180823 by
xDotBridge/inc/BaseboardIO.h@62:9751a8504c82, 2017-03-14 (annotated)
- Committer:
- Matt Briggs
- Date:
- Tue Mar 14 08:32:55 2017 -0600
- Revision:
- 62:9751a8504c82
- Parent:
- 59:485545afc4dc
- Child:
- 98:3609f600c2f5
First cut at pair code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Matt Briggs | 40:2ec4be320961 | 1 | /* |
Matt Briggs | 40:2ec4be320961 | 2 | * baseboardIO.h |
Matt Briggs | 40:2ec4be320961 | 3 | * |
Matt Briggs | 40:2ec4be320961 | 4 | * Created on: Jan 25, 2017 |
Matt Briggs | 40:2ec4be320961 | 5 | * Author: mbriggs |
Matt Briggs | 40:2ec4be320961 | 6 | */ |
Matt Briggs | 40:2ec4be320961 | 7 | #include "DS2408.h" |
Matt Briggs | 40:2ec4be320961 | 8 | |
Matt Briggs | 40:2ec4be320961 | 9 | #ifndef BASEBOARDIO_H_ |
Matt Briggs | 40:2ec4be320961 | 10 | #define BASEBOARDIO_H_ |
Matt Briggs | 40:2ec4be320961 | 11 | |
Matt Briggs | 62:9751a8504c82 | 12 | const uint16_t BASEBOARDIO_NVM_START_ADDR = 0x1100; |
Matt Briggs | 55:79ab0bbc5008 | 13 | const uint16_t BASEBOARDIO_NVM_SIZE = 32; // Bytes |
Matt Briggs | 55:79ab0bbc5008 | 14 | const uint16_t BASEBOARDIO_FLAG = 0x5A00; |
Matt Briggs | 55:79ab0bbc5008 | 15 | const uint16_t BASEBOARDIO_REV = 0x0000; |
Matt Briggs | 59:485545afc4dc | 16 | #define ALSO_USE_LRR_LED 1 // Only set to 1 for debug otherwise it is a waste of power |
Matt Briggs | 55:79ab0bbc5008 | 17 | |
Matt Briggs | 55:79ab0bbc5008 | 18 | class NvmBBIOObj { |
Matt Briggs | 55:79ab0bbc5008 | 19 | public: |
Matt Briggs | 55:79ab0bbc5008 | 20 | NvmBBIOObj(); |
Matt Briggs | 55:79ab0bbc5008 | 21 | void setDefaults(); |
Matt Briggs | 55:79ab0bbc5008 | 22 | CmdResult fromBytes(uint8_t *data, uint8_t size); |
Matt Briggs | 55:79ab0bbc5008 | 23 | CmdResult toBytes(uint8_t *data, uint8_t &size); |
Matt Briggs | 55:79ab0bbc5008 | 24 | |
Matt Briggs | 55:79ab0bbc5008 | 25 | uint16_t getBaseboardIOFlag(); |
Matt Briggs | 55:79ab0bbc5008 | 26 | bool validBaseboardIOFlag(); |
Matt Briggs | 55:79ab0bbc5008 | 27 | uint16_t getBaseboardIORev(); |
Matt Briggs | 55:79ab0bbc5008 | 28 | bool validBaseboardIORev(); |
Matt Briggs | 55:79ab0bbc5008 | 29 | |
Matt Briggs | 55:79ab0bbc5008 | 30 | uint16_t getSerialNum(); |
Matt Briggs | 55:79ab0bbc5008 | 31 | void setSerialNum(uint16_t in); |
Matt Briggs | 55:79ab0bbc5008 | 32 | uint32_t getBaseboardIOConfig(); |
Matt Briggs | 55:79ab0bbc5008 | 33 | void setBaseboardIOConfig(uint32_t in); |
Matt Briggs | 55:79ab0bbc5008 | 34 | void getPortExpanderROM0(uint8_t *addr); |
Matt Briggs | 55:79ab0bbc5008 | 35 | void setPortExpanderROM0(const uint8_t *addr); |
Matt Briggs | 55:79ab0bbc5008 | 36 | void getPortExpanderROM1(uint8_t *addr); |
Matt Briggs | 55:79ab0bbc5008 | 37 | void setPortExpanderROM1(const uint8_t *addr); |
Matt Briggs | 55:79ab0bbc5008 | 38 | // Make public to save memory |
Matt Briggs | 55:79ab0bbc5008 | 39 | uint8_t mPortExpanderROM0[8]; |
Matt Briggs | 55:79ab0bbc5008 | 40 | uint8_t mPortExpanderROM1[8]; |
Matt Briggs | 55:79ab0bbc5008 | 41 | |
Matt Briggs | 55:79ab0bbc5008 | 42 | private: |
Matt Briggs | 55:79ab0bbc5008 | 43 | uint16_t mBaseboardIOFlag; |
Matt Briggs | 55:79ab0bbc5008 | 44 | uint16_t mBaseboardIORev; |
Matt Briggs | 55:79ab0bbc5008 | 45 | uint16_t mSerialNum; |
Matt Briggs | 55:79ab0bbc5008 | 46 | uint16_t mBaseboardIOConfig; |
Matt Briggs | 55:79ab0bbc5008 | 47 | }; |
Matt Briggs | 55:79ab0bbc5008 | 48 | |
Matt Briggs | 40:2ec4be320961 | 49 | /** |
Matt Briggs | 40:2ec4be320961 | 50 | * @class BaseboardIO |
Matt Briggs | 40:2ec4be320961 | 51 | * @brief This class abstracts utilizing the IO mostly found on the baseboard |
Matt Briggs | 40:2ec4be320961 | 52 | * this includes IO which is implemented via portExpanders. This API currently |
Matt Briggs | 40:2ec4be320961 | 53 | * does not implement interfaces for communications like UART or for memory like |
Matt Briggs | 40:2ec4be320961 | 54 | * flash devices. |
Matt Briggs | 40:2ec4be320961 | 55 | */ |
Matt Briggs | 40:2ec4be320961 | 56 | class BaseboardIO |
Matt Briggs | 40:2ec4be320961 | 57 | { |
Matt Briggs | 40:2ec4be320961 | 58 | public: |
Matt Briggs | 58:15aa7a785b9f | 59 | static const PinName OneWireMasterPinName = I2C_SDA; |
Matt Briggs | 58:15aa7a785b9f | 60 | static const PinName CCInPinName = WAKE; // Interrupt pin PA_0 |
Matt Briggs | 58:15aa7a785b9f | 61 | static const PinName TamperPinName = GPIO1; // Interrupt pin PA_5 |
Matt Briggs | 58:15aa7a785b9f | 62 | static const PinName PairBtnPinName = UART_CTS; // Interrupt pin PA_11 |
Matt Briggs | 59:485545afc4dc | 63 | static const PinName LedPinName = GPIO3; |
Matt Briggs | 59:485545afc4dc | 64 | static const PinName LrrLedPinName = GPIO0; |
Matt Briggs | 58:15aa7a785b9f | 65 | static const PinName SwitchedIOCtrlPinName = I2C_SCL; |
Matt Briggs | 58:15aa7a785b9f | 66 | |
Matt Briggs | 40:2ec4be320961 | 67 | /** |
Matt Briggs | 40:2ec4be320961 | 68 | * @brief BaseboardIO constructor |
Matt Briggs | 40:2ec4be320961 | 69 | * |
Matt Briggs | 40:2ec4be320961 | 70 | * @details Just initialized internal variables does not configure devices. |
Matt Briggs | 40:2ec4be320961 | 71 | * Should call init before other functions are called. |
Matt Briggs | 40:2ec4be320961 | 72 | * |
Matt Briggs | 40:2ec4be320961 | 73 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 74 | * |
Matt Briggs | 40:2ec4be320961 | 75 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 76 | * Internal variables are set to a known state but futher initialziation is required |
Matt Briggs | 40:2ec4be320961 | 77 | * |
Matt Briggs | 40:2ec4be320961 | 78 | * @return |
Matt Briggs | 40:2ec4be320961 | 79 | */ |
Matt Briggs | 40:2ec4be320961 | 80 | BaseboardIO(); |
Matt Briggs | 40:2ec4be320961 | 81 | |
Matt Briggs | 40:2ec4be320961 | 82 | /** |
Matt Briggs | 40:2ec4be320961 | 83 | * @brief Initialize IO to current values |
Matt Briggs | 40:2ec4be320961 | 84 | * |
Matt Briggs | 40:2ec4be320961 | 85 | * @details Initialize IO to current state and ensure that class variables |
Matt Briggs | 40:2ec4be320961 | 86 | * are updated to latest values. The following are initialized. |
Matt Briggs | 40:2ec4be320961 | 87 | * 1. PortExpanders are setup are read |
Matt Briggs | 40:2ec4be320961 | 88 | * 2. Relay is forced to known state |
Matt Briggs | 40:2ec4be320961 | 89 | * 3. Interrupts are setup |
Matt Briggs | 40:2ec4be320961 | 90 | * |
Matt Briggs | 40:2ec4be320961 | 91 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 92 | * |
Matt Briggs | 40:2ec4be320961 | 93 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 94 | * Either IO is configured or an error is returned |
Matt Briggs | 40:2ec4be320961 | 95 | * |
Matt Briggs | 40:2ec4be320961 | 96 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 97 | */ |
Matt Briggs | 56:40b454c952cc | 98 | CmdResult init() |
Matt Briggs | 56:40b454c952cc | 99 | { |
Matt Briggs | 56:40b454c952cc | 100 | return init(false); // By default do not overwrite NVM |
Matt Briggs | 56:40b454c952cc | 101 | } |
Matt Briggs | 56:40b454c952cc | 102 | CmdResult init(bool overwriteNvm); |
Matt Briggs | 40:2ec4be320961 | 103 | |
Matt Briggs | 40:2ec4be320961 | 104 | //////////////////////////////// |
Matt Briggs | 40:2ec4be320961 | 105 | // Registering for interrupts // |
Matt Briggs | 40:2ec4be320961 | 106 | //////////////////////////////// |
Matt Briggs | 40:2ec4be320961 | 107 | /** |
Matt Briggs | 40:2ec4be320961 | 108 | * @brief Register for contact closure interrupt |
Matt Briggs | 40:2ec4be320961 | 109 | * |
Matt Briggs | 40:2ec4be320961 | 110 | * @details Pass function pointer which will be called when interrupt occurs. |
Matt Briggs | 40:2ec4be320961 | 111 | * |
Matt Briggs | 40:2ec4be320961 | 112 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 113 | * |
Matt Briggs | 40:2ec4be320961 | 114 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 115 | * Callback registered |
Matt Briggs | 40:2ec4be320961 | 116 | * |
Matt Briggs | 40:2ec4be320961 | 117 | * @return |
Matt Briggs | 40:2ec4be320961 | 118 | */ |
Matt Briggs | 44:ece6330e9b57 | 119 | void regCCInInt(Callback<void()> func); |
Matt Briggs | 40:2ec4be320961 | 120 | |
Matt Briggs | 40:2ec4be320961 | 121 | /** |
Matt Briggs | 40:2ec4be320961 | 122 | * @brief Register for tamper interrupt |
Matt Briggs | 40:2ec4be320961 | 123 | * |
Matt Briggs | 40:2ec4be320961 | 124 | * @details Pass function pointer which will be called when interrupt occurs. |
Matt Briggs | 40:2ec4be320961 | 125 | * |
Matt Briggs | 40:2ec4be320961 | 126 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 127 | * |
Matt Briggs | 40:2ec4be320961 | 128 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 129 | * Callback registered |
Matt Briggs | 40:2ec4be320961 | 130 | * |
Matt Briggs | 40:2ec4be320961 | 131 | * @return |
Matt Briggs | 40:2ec4be320961 | 132 | */ |
Matt Briggs | 44:ece6330e9b57 | 133 | void regTamperInt(Callback<void()> func); |
Matt Briggs | 40:2ec4be320961 | 134 | |
Matt Briggs | 40:2ec4be320961 | 135 | /** |
Matt Briggs | 40:2ec4be320961 | 136 | * @brief Register for pair button interrupt |
Matt Briggs | 40:2ec4be320961 | 137 | * |
Matt Briggs | 40:2ec4be320961 | 138 | * @details Pass function pointer which will be called when interrupt occurs. Note |
Matt Briggs | 40:2ec4be320961 | 139 | * there is a hardware switch which can prevent the tamper sensor from pulling the line |
Matt Briggs | 40:2ec4be320961 | 140 | * down. If this switch deasserted there is no way in software to reconfigure this. |
Matt Briggs | 40:2ec4be320961 | 141 | * |
Matt Briggs | 40:2ec4be320961 | 142 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 143 | * |
Matt Briggs | 40:2ec4be320961 | 144 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 145 | * Callback registered |
Matt Briggs | 40:2ec4be320961 | 146 | * |
Matt Briggs | 40:2ec4be320961 | 147 | * @return |
Matt Briggs | 40:2ec4be320961 | 148 | */ |
Matt Briggs | 44:ece6330e9b57 | 149 | void regPairBtnInt(Callback<void()> func); |
Matt Briggs | 40:2ec4be320961 | 150 | |
Matt Briggs | 40:2ec4be320961 | 151 | /////////// |
Matt Briggs | 40:2ec4be320961 | 152 | // Input // |
Matt Briggs | 40:2ec4be320961 | 153 | /////////// |
Matt Briggs | 40:2ec4be320961 | 154 | /** |
Matt Briggs | 40:2ec4be320961 | 155 | * @brief samples current IO including port expanders |
Matt Briggs | 40:2ec4be320961 | 156 | * |
Matt Briggs | 40:2ec4be320961 | 157 | * @details Samples values and stores them so that IO accessors can execute quicker. |
Matt Briggs | 40:2ec4be320961 | 158 | * |
Matt Briggs | 40:2ec4be320961 | 159 | * Future: |
Matt Briggs | 40:2ec4be320961 | 160 | * Add some detail about how robust the values displayed here are. |
Matt Briggs | 40:2ec4be320961 | 161 | * It might be a good idea to add a timestamp for this IO |
Matt Briggs | 40:2ec4be320961 | 162 | * |
Matt Briggs | 40:2ec4be320961 | 163 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 164 | * |
Matt Briggs | 40:2ec4be320961 | 165 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 166 | * Internal class variables are updated or error is returned. |
Matt Briggs | 40:2ec4be320961 | 167 | * |
Matt Briggs | 40:2ec4be320961 | 168 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 169 | */ |
Matt Briggs | 40:2ec4be320961 | 170 | CmdResult sampleUserSwitches(); |
Matt Briggs | 40:2ec4be320961 | 171 | |
Matt Briggs | 40:2ec4be320961 | 172 | /** |
Matt Briggs | 40:2ec4be320961 | 173 | * @brief Returns the current state of the pair button |
Matt Briggs | 40:2ec4be320961 | 174 | * |
Matt Briggs | 40:2ec4be320961 | 175 | * @details This just simply uses the last sample of the IO to return a bool. |
Matt Briggs | 40:2ec4be320961 | 176 | * If the button is depressed than true is returned other wise false |
Matt Briggs | 40:2ec4be320961 | 177 | * |
Matt Briggs | 40:2ec4be320961 | 178 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 179 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 180 | * |
Matt Briggs | 40:2ec4be320961 | 181 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 182 | * |
Matt Briggs | 40:2ec4be320961 | 183 | * @return bool |
Matt Briggs | 40:2ec4be320961 | 184 | */ |
Matt Briggs | 40:2ec4be320961 | 185 | bool isPairBtn(); |
Matt Briggs | 57:bdac7dd17af2 | 186 | bool isCCInAlert(); |
Matt Briggs | 40:2ec4be320961 | 187 | |
Matt Briggs | 40:2ec4be320961 | 188 | /** |
Matt Briggs | 40:2ec4be320961 | 189 | * @brief Returns the current state of the NO/NC switch |
Matt Briggs | 40:2ec4be320961 | 190 | * |
Matt Briggs | 40:2ec4be320961 | 191 | * @details This just simply uses the last sample of the IO to return a bool. |
Matt Briggs | 40:2ec4be320961 | 192 | * If the switch is in asserted position that the devices is normally closed (NC) |
Matt Briggs | 40:2ec4be320961 | 193 | * therefore false is returned. Otherwise device is normally open (NO) and therefore |
Matt Briggs | 40:2ec4be320961 | 194 | * returns true. |
Matt Briggs | 40:2ec4be320961 | 195 | * |
Matt Briggs | 40:2ec4be320961 | 196 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 197 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 198 | * |
Matt Briggs | 40:2ec4be320961 | 199 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 200 | * |
Matt Briggs | 40:2ec4be320961 | 201 | * @return bool |
Matt Briggs | 40:2ec4be320961 | 202 | */ |
Matt Briggs | 48:bab9f747d9ed | 203 | bool isCCNO(); |
Matt Briggs | 40:2ec4be320961 | 204 | |
Matt Briggs | 40:2ec4be320961 | 205 | /** |
Matt Briggs | 40:2ec4be320961 | 206 | * @brief Returns the current state of the NO/NC switch |
Matt Briggs | 40:2ec4be320961 | 207 | * |
Matt Briggs | 40:2ec4be320961 | 208 | * @details This just simply uses the last sample of the IO to return a bool. |
Matt Briggs | 40:2ec4be320961 | 209 | * If the switch is in asserted position that the devices is normally closed (NC) |
Matt Briggs | 40:2ec4be320961 | 210 | * therefore true is returned. Otherwise device is normally open (NO) and therefore |
Matt Briggs | 40:2ec4be320961 | 211 | * returns false. |
Matt Briggs | 40:2ec4be320961 | 212 | * |
Matt Briggs | 40:2ec4be320961 | 213 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 214 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 215 | * |
Matt Briggs | 40:2ec4be320961 | 216 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 217 | * |
Matt Briggs | 40:2ec4be320961 | 218 | * @return bool |
Matt Briggs | 40:2ec4be320961 | 219 | */ |
Matt Briggs | 49:18f1354f9e51 | 220 | bool isCCNC() {return !isCCNO();} |
Matt Briggs | 40:2ec4be320961 | 221 | |
Matt Briggs | 40:2ec4be320961 | 222 | /** |
Matt Briggs | 40:2ec4be320961 | 223 | * @brief Returns the current state of the Rx/Tx switch |
Matt Briggs | 40:2ec4be320961 | 224 | * |
Matt Briggs | 40:2ec4be320961 | 225 | * @details This just simply uses the last sample of the IO to return a bool. |
Matt Briggs | 40:2ec4be320961 | 226 | * If the switch is in asserted position that the devices is transmitter (Tx) |
Matt Briggs | 40:2ec4be320961 | 227 | * therefore false is returned. Otherwise device is a receiver(Rx) and therefore |
Matt Briggs | 40:2ec4be320961 | 228 | * returns true. |
Matt Briggs | 40:2ec4be320961 | 229 | * |
Matt Briggs | 40:2ec4be320961 | 230 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 231 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 232 | * |
Matt Briggs | 40:2ec4be320961 | 233 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 234 | * |
Matt Briggs | 40:2ec4be320961 | 235 | * @return bool |
Matt Briggs | 40:2ec4be320961 | 236 | */ |
Matt Briggs | 40:2ec4be320961 | 237 | bool isRx(); |
Matt Briggs | 40:2ec4be320961 | 238 | |
Matt Briggs | 40:2ec4be320961 | 239 | /** |
Matt Briggs | 40:2ec4be320961 | 240 | * @brief Returns the current state of the Rx/Tx switch |
Matt Briggs | 40:2ec4be320961 | 241 | * |
Matt Briggs | 40:2ec4be320961 | 242 | * @details This just simply uses the last sample of the IO to return a bool. |
Matt Briggs | 40:2ec4be320961 | 243 | * If the switch is in asserted position that the devices is transmitter (Tx) |
Matt Briggs | 40:2ec4be320961 | 244 | * therefore true is returned. Otherwise device is a receiver(Rx) and therefore |
Matt Briggs | 40:2ec4be320961 | 245 | * returns false. |
Matt Briggs | 40:2ec4be320961 | 246 | * |
Matt Briggs | 40:2ec4be320961 | 247 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 248 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 249 | * |
Matt Briggs | 40:2ec4be320961 | 250 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 251 | * |
Matt Briggs | 40:2ec4be320961 | 252 | * @return bool |
Matt Briggs | 40:2ec4be320961 | 253 | */ |
Matt Briggs | 40:2ec4be320961 | 254 | bool isTx() {return !isRx();} |
Matt Briggs | 40:2ec4be320961 | 255 | |
Matt Briggs | 40:2ec4be320961 | 256 | /** |
Matt Briggs | 40:2ec4be320961 | 257 | * @brief Returns the current state of the LoRaWAN switch |
Matt Briggs | 40:2ec4be320961 | 258 | * |
Matt Briggs | 40:2ec4be320961 | 259 | * @details This just simply uses the last sample of the IO to return a bool. |
Matt Briggs | 40:2ec4be320961 | 260 | * If the switch is in asserted position that the device is will report via LoRaWAN |
Matt Briggs | 40:2ec4be320961 | 261 | * otherwise the device will use peer-to-peer mode. |
Matt Briggs | 40:2ec4be320961 | 262 | * |
Matt Briggs | 40:2ec4be320961 | 263 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 264 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 265 | * |
Matt Briggs | 40:2ec4be320961 | 266 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 267 | * |
Matt Briggs | 40:2ec4be320961 | 268 | * @return bool |
Matt Briggs | 40:2ec4be320961 | 269 | */ |
Matt Briggs | 40:2ec4be320961 | 270 | bool isLoRaWANMode(); |
Matt Briggs | 40:2ec4be320961 | 271 | |
Matt Briggs | 40:2ec4be320961 | 272 | /** |
Matt Briggs | 50:e89647e77fd5 | 273 | * @brief Returns the current state of the serial switch |
Matt Briggs | 50:e89647e77fd5 | 274 | * |
Matt Briggs | 50:e89647e77fd5 | 275 | * @details This just simply uses the last sample of the IO to return a bool. |
Matt Briggs | 50:e89647e77fd5 | 276 | * If enabled then the serial chip will be listening for traffic at least in |
Matt Briggs | 50:e89647e77fd5 | 277 | * the case of a TX. |
Matt Briggs | 50:e89647e77fd5 | 278 | * |
Matt Briggs | 50:e89647e77fd5 | 279 | * On Entry: |
Matt Briggs | 50:e89647e77fd5 | 280 | * IO should be sampled recently |
Matt Briggs | 50:e89647e77fd5 | 281 | * |
Matt Briggs | 50:e89647e77fd5 | 282 | * On Exit: |
Matt Briggs | 50:e89647e77fd5 | 283 | * |
Matt Briggs | 50:e89647e77fd5 | 284 | * @return bool |
Matt Briggs | 50:e89647e77fd5 | 285 | */ |
Matt Briggs | 50:e89647e77fd5 | 286 | bool isSerialEnabled(); |
Matt Briggs | 50:e89647e77fd5 | 287 | |
Matt Briggs | 50:e89647e77fd5 | 288 | /** |
Matt Briggs | 40:2ec4be320961 | 289 | * @brief Returns value of a rotary switch (TODO give board location) |
Matt Briggs | 40:2ec4be320961 | 290 | * |
Matt Briggs | 40:2ec4be320961 | 291 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 292 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 293 | * |
Matt Briggs | 40:2ec4be320961 | 294 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 295 | * |
Matt Briggs | 40:2ec4be320961 | 296 | * @return uint8_t |
Matt Briggs | 40:2ec4be320961 | 297 | */ |
Matt Briggs | 40:2ec4be320961 | 298 | uint8_t rotarySwitch1(); |
Matt Briggs | 40:2ec4be320961 | 299 | |
Matt Briggs | 40:2ec4be320961 | 300 | /** |
Matt Briggs | 40:2ec4be320961 | 301 | * @brief Returns value of a rotary switch (TODO give board location) |
Matt Briggs | 40:2ec4be320961 | 302 | * |
Matt Briggs | 40:2ec4be320961 | 303 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 304 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 305 | * |
Matt Briggs | 40:2ec4be320961 | 306 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 307 | * |
Matt Briggs | 40:2ec4be320961 | 308 | * @return uint8_t |
Matt Briggs | 40:2ec4be320961 | 309 | */ |
Matt Briggs | 40:2ec4be320961 | 310 | uint8_t rotarySwitch2(); |
Matt Briggs | 40:2ec4be320961 | 311 | |
Matt Briggs | 40:2ec4be320961 | 312 | //////////// |
Matt Briggs | 40:2ec4be320961 | 313 | // Output // |
Matt Briggs | 40:2ec4be320961 | 314 | //////////// |
Matt Briggs | 40:2ec4be320961 | 315 | /** |
Matt Briggs | 40:2ec4be320961 | 316 | * @brief Turns LED on |
Matt Briggs | 40:2ec4be320961 | 317 | * |
Matt Briggs | 40:2ec4be320961 | 318 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 319 | */ |
Matt Briggs | 40:2ec4be320961 | 320 | CmdResult ledOn(); |
Matt Briggs | 40:2ec4be320961 | 321 | |
Matt Briggs | 40:2ec4be320961 | 322 | /** |
Matt Briggs | 40:2ec4be320961 | 323 | * @brief Turns LED off |
Matt Briggs | 40:2ec4be320961 | 324 | * |
Matt Briggs | 40:2ec4be320961 | 325 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 326 | */ |
Matt Briggs | 40:2ec4be320961 | 327 | CmdResult ledOff(); |
Matt Briggs | 40:2ec4be320961 | 328 | |
Matt Briggs | 40:2ec4be320961 | 329 | /** |
Matt Briggs | 40:2ec4be320961 | 330 | * @brief Changes state of relay to alert |
Matt Briggs | 40:2ec4be320961 | 331 | * |
Matt Briggs | 40:2ec4be320961 | 332 | * @details If the configured as normally open then the relay closes and |
Matt Briggs | 40:2ec4be320961 | 333 | * vice versa for normally closed. |
Matt Briggs | 40:2ec4be320961 | 334 | * |
Matt Briggs | 40:2ec4be320961 | 335 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 336 | */ |
Matt Briggs | 40:2ec4be320961 | 337 | CmdResult relayAlert(); |
Matt Briggs | 40:2ec4be320961 | 338 | |
Matt Briggs | 40:2ec4be320961 | 339 | /** |
Matt Briggs | 40:2ec4be320961 | 340 | * @brief Changes state of relay to normal |
Matt Briggs | 40:2ec4be320961 | 341 | * |
Matt Briggs | 40:2ec4be320961 | 342 | * @details If the configured as normally open then the relay opens and |
Matt Briggs | 40:2ec4be320961 | 343 | * vice versa for normally closed. |
Matt Briggs | 40:2ec4be320961 | 344 | * |
Matt Briggs | 40:2ec4be320961 | 345 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 346 | */ |
Matt Briggs | 40:2ec4be320961 | 347 | CmdResult relayNormal(); |
Matt Briggs | 40:2ec4be320961 | 348 | |
Matt Briggs | 40:2ec4be320961 | 349 | /** |
Matt Briggs | 40:2ec4be320961 | 350 | * @brief Enables/disables serial chip |
Matt Briggs | 40:2ec4be320961 | 351 | * |
Matt Briggs | 40:2ec4be320961 | 352 | * @details This controls IO to ON/~OFF pin of RS232 chip. If transmitting |
Matt Briggs | 40:2ec4be320961 | 353 | * ensure serialTx is called as well. |
Matt Briggs | 40:2ec4be320961 | 354 | * |
Matt Briggs | 40:2ec4be320961 | 355 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 356 | */ |
Matt Briggs | 40:2ec4be320961 | 357 | CmdResult serialRx(bool enable); |
Matt Briggs | 40:2ec4be320961 | 358 | |
Matt Briggs | 40:2ec4be320961 | 359 | /** |
Matt Briggs | 40:2ec4be320961 | 360 | * @brief Controls serial chip transmission |
Matt Briggs | 40:2ec4be320961 | 361 | * |
Matt Briggs | 40:2ec4be320961 | 362 | * @details This controls IO to Tx_DIS pin of RS232 chip. Note calling this function will |
Matt Briggs | 40:2ec4be320961 | 363 | * also enable serialRx. |
Matt Briggs | 40:2ec4be320961 | 364 | * |
Matt Briggs | 40:2ec4be320961 | 365 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 366 | */ |
Matt Briggs | 40:2ec4be320961 | 367 | CmdResult serialTx(bool enable); |
Matt Briggs | 40:2ec4be320961 | 368 | |
Matt Briggs | 58:15aa7a785b9f | 369 | CmdResult prepareSleep(); |
Matt Briggs | 58:15aa7a785b9f | 370 | CmdResult exitSleep(); |
Matt Briggs | 58:15aa7a785b9f | 371 | |
Matt Briggs | 40:2ec4be320961 | 372 | private: |
Matt Briggs | 44:ece6330e9b57 | 373 | // Initialized during constructor |
Matt Briggs | 55:79ab0bbc5008 | 374 | NvmBBIOObj mNvmObj; |
Matt Briggs | 44:ece6330e9b57 | 375 | OneWire mOWMaster; |
Matt Briggs | 44:ece6330e9b57 | 376 | InterruptIn mCCIn; |
Matt Briggs | 44:ece6330e9b57 | 377 | InterruptIn mTamper; |
Matt Briggs | 44:ece6330e9b57 | 378 | InterruptIn mPairBtn; |
Matt Briggs | 44:ece6330e9b57 | 379 | DigitalOut mLed; |
Matt Briggs | 59:485545afc4dc | 380 | DigitalOut mLrrLed; |
Matt Briggs | 44:ece6330e9b57 | 381 | DigitalOut mSwitchedIOCtrl; |
Matt Briggs | 40:2ec4be320961 | 382 | |
Matt Briggs | 55:79ab0bbc5008 | 383 | // uint8_t mPortExpanderROM0[8]; // FIXME could probably get rid of |
Matt Briggs | 44:ece6330e9b57 | 384 | uint8_t mPortExpanderVal0; |
Matt Briggs | 55:79ab0bbc5008 | 385 | // uint8_t mPortExpanderROM1[8]; |
Matt Briggs | 44:ece6330e9b57 | 386 | uint8_t mPortExpanderVal1; |
Matt Briggs | 44:ece6330e9b57 | 387 | |
Matt Briggs | 44:ece6330e9b57 | 388 | DS2408 *mPortEx0; |
Matt Briggs | 44:ece6330e9b57 | 389 | DS2408 *mPortEx1; |
Matt Briggs | 40:2ec4be320961 | 390 | |
Matt Briggs | 49:18f1354f9e51 | 391 | void enableSwitchedIO () { |
Matt Briggs | 49:18f1354f9e51 | 392 | mSwitchedIOCtrl = 0; // assert since PMOS |
Matt Briggs | 49:18f1354f9e51 | 393 | } |
Matt Briggs | 49:18f1354f9e51 | 394 | void disableSwitchedIO () { |
Matt Briggs | 49:18f1354f9e51 | 395 | mSwitchedIOCtrl = 1; // deassertted since PMOS |
Matt Briggs | 49:18f1354f9e51 | 396 | } |
Matt Briggs | 49:18f1354f9e51 | 397 | |
Matt Briggs | 40:2ec4be320961 | 398 | /** |
Matt Briggs | 40:2ec4be320961 | 399 | * @brief Reads baseboard information from non-volatile memory (NVM) |
Matt Briggs | 40:2ec4be320961 | 400 | * |
Matt Briggs | 40:2ec4be320961 | 401 | * @details This data is read from the xDot's internal EEPROM. This |
Matt Briggs | 40:2ec4be320961 | 402 | * method is called from init(). The following |
Matt Briggs | 40:2ec4be320961 | 403 | * is stored: |
Matt Briggs | 40:2ec4be320961 | 404 | * 1. Storage code word |
Matt Briggs | 40:2ec4be320961 | 405 | * 2. 8-bit Baseboard configuration data |
Matt Briggs | 40:2ec4be320961 | 406 | * 3. 8-bit Baseboard revision data |
Matt Briggs | 40:2ec4be320961 | 407 | * 4. 16-bit Baseboard serial number |
Matt Briggs | 40:2ec4be320961 | 408 | * 5. 2 x 64-bit OneWire ROM port expander addresses |
Matt Briggs | 40:2ec4be320961 | 409 | * |
Matt Briggs | 40:2ec4be320961 | 410 | * TODO add memory map information |
Matt Briggs | 40:2ec4be320961 | 411 | * |
Matt Briggs | 40:2ec4be320961 | 412 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 413 | */ |
Matt Briggs | 40:2ec4be320961 | 414 | CmdResult readInfoFromNVM(); |
Matt Briggs | 40:2ec4be320961 | 415 | |
Matt Briggs | 40:2ec4be320961 | 416 | /** |
Matt Briggs | 40:2ec4be320961 | 417 | * @brief Stores baseboard information to non-volatile memory (NVM) |
Matt Briggs | 40:2ec4be320961 | 418 | * |
Matt Briggs | 40:2ec4be320961 | 419 | * @details This method is called during special configuration events like first time boot or factory reset. |
Matt Briggs | 40:2ec4be320961 | 420 | * |
Matt Briggs | 40:2ec4be320961 | 421 | * TODO add memory map information |
Matt Briggs | 40:2ec4be320961 | 422 | * |
Matt Briggs | 40:2ec4be320961 | 423 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 424 | */ |
Matt Briggs | 40:2ec4be320961 | 425 | CmdResult writeInfoToNVM(); |
Matt Briggs | 40:2ec4be320961 | 426 | |
Matt Briggs | 40:2ec4be320961 | 427 | /** |
Matt Briggs | 40:2ec4be320961 | 428 | * @brief Scans OneWire bus for port expanders and attempts to identify each. |
Matt Briggs | 40:2ec4be320961 | 429 | * |
Matt Briggs | 40:2ec4be320961 | 430 | * @details For this method to succeed switches must be in factory reset positions. |
Matt Briggs | 44:ece6330e9b57 | 431 | * Rotary 1 and 2 should be at 0 |
Matt Briggs | 44:ece6330e9b57 | 432 | * DIP Switches should be fully closed |
Matt Briggs | 40:2ec4be320961 | 433 | * |
Matt Briggs | 40:2ec4be320961 | 434 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 435 | */ |
Matt Briggs | 40:2ec4be320961 | 436 | CmdResult identifyPortExpanders(); |
Matt Briggs | 44:ece6330e9b57 | 437 | |
Matt Briggs | 44:ece6330e9b57 | 438 | /** |
Matt Briggs | 44:ece6330e9b57 | 439 | * @brief Forces relay to closed state |
Matt Briggs | 44:ece6330e9b57 | 440 | * |
Matt Briggs | 44:ece6330e9b57 | 441 | * @details Note coil assertion timing is done here |
Matt Briggs | 44:ece6330e9b57 | 442 | * |
Matt Briggs | 44:ece6330e9b57 | 443 | * @return CmdResult |
Matt Briggs | 44:ece6330e9b57 | 444 | */ |
Matt Briggs | 44:ece6330e9b57 | 445 | CmdResult closeRelay(); |
Matt Briggs | 44:ece6330e9b57 | 446 | |
Matt Briggs | 44:ece6330e9b57 | 447 | /** |
Matt Briggs | 44:ece6330e9b57 | 448 | * @brief Forces relay to open state |
Matt Briggs | 44:ece6330e9b57 | 449 | * |
Matt Briggs | 44:ece6330e9b57 | 450 | * @details Note coil assertion timing is done here |
Matt Briggs | 44:ece6330e9b57 | 451 | * |
Matt Briggs | 44:ece6330e9b57 | 452 | * @return CmdResult |
Matt Briggs | 44:ece6330e9b57 | 453 | */ |
Matt Briggs | 44:ece6330e9b57 | 454 | CmdResult openRelay(); |
Matt Briggs | 40:2ec4be320961 | 455 | }; |
Matt Briggs | 40:2ec4be320961 | 456 | |
Matt Briggs | 55:79ab0bbc5008 | 457 | |
Matt Briggs | 40:2ec4be320961 | 458 | #endif /* BASEBOARDIO_BASEBOARDIO_H_ */ |