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@100:0882cf295f8e, 2017-11-29 (annotated)
- Committer:
- mbriggs_vortex
- Date:
- Wed Nov 29 13:54:36 2017 -0700
- Revision:
- 100:0882cf295f8e
- Parent:
- 98:3609f600c2f5
Adding relaese bin to repo
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 | |
mbriggs_vortex | 98:3609f600c2f5 | 205 | void setIsCCNO(bool val); |
mbriggs_vortex | 98:3609f600c2f5 | 206 | |
mbriggs_vortex | 98:3609f600c2f5 | 207 | void setIsCCNC(bool val) {setIsCCNO(!val);} |
mbriggs_vortex | 98:3609f600c2f5 | 208 | |
Matt Briggs | 40:2ec4be320961 | 209 | /** |
Matt Briggs | 40:2ec4be320961 | 210 | * @brief Returns the current state of the NO/NC switch |
Matt Briggs | 40:2ec4be320961 | 211 | * |
Matt Briggs | 40:2ec4be320961 | 212 | * @details This just simply uses the last sample of the IO to return a bool. |
Matt Briggs | 40:2ec4be320961 | 213 | * If the switch is in asserted position that the devices is normally closed (NC) |
Matt Briggs | 40:2ec4be320961 | 214 | * therefore true is returned. Otherwise device is normally open (NO) and therefore |
Matt Briggs | 40:2ec4be320961 | 215 | * returns false. |
Matt Briggs | 40:2ec4be320961 | 216 | * |
Matt Briggs | 40:2ec4be320961 | 217 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 218 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 219 | * |
Matt Briggs | 40:2ec4be320961 | 220 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 221 | * |
Matt Briggs | 40:2ec4be320961 | 222 | * @return bool |
Matt Briggs | 40:2ec4be320961 | 223 | */ |
Matt Briggs | 49:18f1354f9e51 | 224 | bool isCCNC() {return !isCCNO();} |
Matt Briggs | 40:2ec4be320961 | 225 | |
Matt Briggs | 40:2ec4be320961 | 226 | /** |
Matt Briggs | 40:2ec4be320961 | 227 | * @brief Returns the current state of the Rx/Tx switch |
Matt Briggs | 40:2ec4be320961 | 228 | * |
Matt Briggs | 40:2ec4be320961 | 229 | * @details This just simply uses the last sample of the IO to return a bool. |
Matt Briggs | 40:2ec4be320961 | 230 | * If the switch is in asserted position that the devices is transmitter (Tx) |
Matt Briggs | 40:2ec4be320961 | 231 | * therefore false is returned. Otherwise device is a receiver(Rx) and therefore |
Matt Briggs | 40:2ec4be320961 | 232 | * returns true. |
Matt Briggs | 40:2ec4be320961 | 233 | * |
Matt Briggs | 40:2ec4be320961 | 234 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 235 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 236 | * |
Matt Briggs | 40:2ec4be320961 | 237 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 238 | * |
Matt Briggs | 40:2ec4be320961 | 239 | * @return bool |
Matt Briggs | 40:2ec4be320961 | 240 | */ |
Matt Briggs | 40:2ec4be320961 | 241 | bool isRx(); |
Matt Briggs | 40:2ec4be320961 | 242 | |
mbriggs_vortex | 98:3609f600c2f5 | 243 | void setIsRx(bool val); |
mbriggs_vortex | 98:3609f600c2f5 | 244 | |
mbriggs_vortex | 98:3609f600c2f5 | 245 | void setIsTx(bool val) {setIsRx(!val);} |
mbriggs_vortex | 98:3609f600c2f5 | 246 | |
Matt Briggs | 40:2ec4be320961 | 247 | /** |
Matt Briggs | 40:2ec4be320961 | 248 | * @brief Returns the current state of the Rx/Tx switch |
Matt Briggs | 40:2ec4be320961 | 249 | * |
Matt Briggs | 40:2ec4be320961 | 250 | * @details This just simply uses the last sample of the IO to return a bool. |
Matt Briggs | 40:2ec4be320961 | 251 | * If the switch is in asserted position that the devices is transmitter (Tx) |
Matt Briggs | 40:2ec4be320961 | 252 | * therefore true is returned. Otherwise device is a receiver(Rx) and therefore |
Matt Briggs | 40:2ec4be320961 | 253 | * returns false. |
Matt Briggs | 40:2ec4be320961 | 254 | * |
Matt Briggs | 40:2ec4be320961 | 255 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 256 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 257 | * |
Matt Briggs | 40:2ec4be320961 | 258 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 259 | * |
Matt Briggs | 40:2ec4be320961 | 260 | * @return bool |
Matt Briggs | 40:2ec4be320961 | 261 | */ |
Matt Briggs | 40:2ec4be320961 | 262 | bool isTx() {return !isRx();} |
Matt Briggs | 40:2ec4be320961 | 263 | |
Matt Briggs | 40:2ec4be320961 | 264 | /** |
Matt Briggs | 40:2ec4be320961 | 265 | * @brief Returns the current state of the LoRaWAN switch |
Matt Briggs | 40:2ec4be320961 | 266 | * |
Matt Briggs | 40:2ec4be320961 | 267 | * @details This just simply uses the last sample of the IO to return a bool. |
Matt Briggs | 40:2ec4be320961 | 268 | * If the switch is in asserted position that the device is will report via LoRaWAN |
Matt Briggs | 40:2ec4be320961 | 269 | * otherwise the device will use peer-to-peer mode. |
Matt Briggs | 40:2ec4be320961 | 270 | * |
Matt Briggs | 40:2ec4be320961 | 271 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 272 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 273 | * |
Matt Briggs | 40:2ec4be320961 | 274 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 275 | * |
Matt Briggs | 40:2ec4be320961 | 276 | * @return bool |
Matt Briggs | 40:2ec4be320961 | 277 | */ |
Matt Briggs | 40:2ec4be320961 | 278 | bool isLoRaWANMode(); |
Matt Briggs | 40:2ec4be320961 | 279 | |
Matt Briggs | 40:2ec4be320961 | 280 | /** |
Matt Briggs | 50:e89647e77fd5 | 281 | * @brief Returns the current state of the serial switch |
Matt Briggs | 50:e89647e77fd5 | 282 | * |
Matt Briggs | 50:e89647e77fd5 | 283 | * @details This just simply uses the last sample of the IO to return a bool. |
Matt Briggs | 50:e89647e77fd5 | 284 | * If enabled then the serial chip will be listening for traffic at least in |
Matt Briggs | 50:e89647e77fd5 | 285 | * the case of a TX. |
Matt Briggs | 50:e89647e77fd5 | 286 | * |
Matt Briggs | 50:e89647e77fd5 | 287 | * On Entry: |
Matt Briggs | 50:e89647e77fd5 | 288 | * IO should be sampled recently |
Matt Briggs | 50:e89647e77fd5 | 289 | * |
Matt Briggs | 50:e89647e77fd5 | 290 | * On Exit: |
Matt Briggs | 50:e89647e77fd5 | 291 | * |
Matt Briggs | 50:e89647e77fd5 | 292 | * @return bool |
Matt Briggs | 50:e89647e77fd5 | 293 | */ |
Matt Briggs | 50:e89647e77fd5 | 294 | bool isSerialEnabled(); |
Matt Briggs | 50:e89647e77fd5 | 295 | |
Matt Briggs | 50:e89647e77fd5 | 296 | /** |
Matt Briggs | 40:2ec4be320961 | 297 | * @brief Returns value of a rotary switch (TODO give board location) |
Matt Briggs | 40:2ec4be320961 | 298 | * |
Matt Briggs | 40:2ec4be320961 | 299 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 300 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 301 | * |
Matt Briggs | 40:2ec4be320961 | 302 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 303 | * |
Matt Briggs | 40:2ec4be320961 | 304 | * @return uint8_t |
Matt Briggs | 40:2ec4be320961 | 305 | */ |
Matt Briggs | 40:2ec4be320961 | 306 | uint8_t rotarySwitch1(); |
Matt Briggs | 40:2ec4be320961 | 307 | |
mbriggs_vortex | 98:3609f600c2f5 | 308 | void setRotarySwitch1(uint8_t val); |
mbriggs_vortex | 98:3609f600c2f5 | 309 | |
Matt Briggs | 40:2ec4be320961 | 310 | /** |
Matt Briggs | 40:2ec4be320961 | 311 | * @brief Returns value of a rotary switch (TODO give board location) |
Matt Briggs | 40:2ec4be320961 | 312 | * |
Matt Briggs | 40:2ec4be320961 | 313 | * On Entry: |
Matt Briggs | 40:2ec4be320961 | 314 | * IO should be sampled recently |
Matt Briggs | 40:2ec4be320961 | 315 | * |
Matt Briggs | 40:2ec4be320961 | 316 | * On Exit: |
Matt Briggs | 40:2ec4be320961 | 317 | * |
Matt Briggs | 40:2ec4be320961 | 318 | * @return uint8_t |
Matt Briggs | 40:2ec4be320961 | 319 | */ |
Matt Briggs | 40:2ec4be320961 | 320 | uint8_t rotarySwitch2(); |
Matt Briggs | 40:2ec4be320961 | 321 | |
mbriggs_vortex | 98:3609f600c2f5 | 322 | // void setRotarySwitch2(uint8_t val); |
mbriggs_vortex | 98:3609f600c2f5 | 323 | |
Matt Briggs | 40:2ec4be320961 | 324 | //////////// |
Matt Briggs | 40:2ec4be320961 | 325 | // Output // |
Matt Briggs | 40:2ec4be320961 | 326 | //////////// |
Matt Briggs | 40:2ec4be320961 | 327 | /** |
Matt Briggs | 40:2ec4be320961 | 328 | * @brief Turns LED on |
Matt Briggs | 40:2ec4be320961 | 329 | * |
Matt Briggs | 40:2ec4be320961 | 330 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 331 | */ |
Matt Briggs | 40:2ec4be320961 | 332 | CmdResult ledOn(); |
Matt Briggs | 40:2ec4be320961 | 333 | |
Matt Briggs | 40:2ec4be320961 | 334 | /** |
Matt Briggs | 40:2ec4be320961 | 335 | * @brief Turns LED off |
Matt Briggs | 40:2ec4be320961 | 336 | * |
Matt Briggs | 40:2ec4be320961 | 337 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 338 | */ |
Matt Briggs | 40:2ec4be320961 | 339 | CmdResult ledOff(); |
Matt Briggs | 40:2ec4be320961 | 340 | |
Matt Briggs | 40:2ec4be320961 | 341 | /** |
Matt Briggs | 40:2ec4be320961 | 342 | * @brief Changes state of relay to alert |
Matt Briggs | 40:2ec4be320961 | 343 | * |
Matt Briggs | 40:2ec4be320961 | 344 | * @details If the configured as normally open then the relay closes and |
Matt Briggs | 40:2ec4be320961 | 345 | * vice versa for normally closed. |
Matt Briggs | 40:2ec4be320961 | 346 | * |
Matt Briggs | 40:2ec4be320961 | 347 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 348 | */ |
Matt Briggs | 40:2ec4be320961 | 349 | CmdResult relayAlert(); |
Matt Briggs | 40:2ec4be320961 | 350 | |
Matt Briggs | 40:2ec4be320961 | 351 | /** |
Matt Briggs | 40:2ec4be320961 | 352 | * @brief Changes state of relay to normal |
Matt Briggs | 40:2ec4be320961 | 353 | * |
Matt Briggs | 40:2ec4be320961 | 354 | * @details If the configured as normally open then the relay opens and |
Matt Briggs | 40:2ec4be320961 | 355 | * vice versa for normally closed. |
Matt Briggs | 40:2ec4be320961 | 356 | * |
Matt Briggs | 40:2ec4be320961 | 357 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 358 | */ |
Matt Briggs | 40:2ec4be320961 | 359 | CmdResult relayNormal(); |
Matt Briggs | 40:2ec4be320961 | 360 | |
Matt Briggs | 40:2ec4be320961 | 361 | /** |
Matt Briggs | 40:2ec4be320961 | 362 | * @brief Enables/disables serial chip |
Matt Briggs | 40:2ec4be320961 | 363 | * |
Matt Briggs | 40:2ec4be320961 | 364 | * @details This controls IO to ON/~OFF pin of RS232 chip. If transmitting |
Matt Briggs | 40:2ec4be320961 | 365 | * ensure serialTx is called as well. |
Matt Briggs | 40:2ec4be320961 | 366 | * |
Matt Briggs | 40:2ec4be320961 | 367 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 368 | */ |
Matt Briggs | 40:2ec4be320961 | 369 | CmdResult serialRx(bool enable); |
Matt Briggs | 40:2ec4be320961 | 370 | |
Matt Briggs | 40:2ec4be320961 | 371 | /** |
Matt Briggs | 40:2ec4be320961 | 372 | * @brief Controls serial chip transmission |
Matt Briggs | 40:2ec4be320961 | 373 | * |
Matt Briggs | 40:2ec4be320961 | 374 | * @details This controls IO to Tx_DIS pin of RS232 chip. Note calling this function will |
Matt Briggs | 40:2ec4be320961 | 375 | * also enable serialRx. |
Matt Briggs | 40:2ec4be320961 | 376 | * |
Matt Briggs | 40:2ec4be320961 | 377 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 378 | */ |
Matt Briggs | 40:2ec4be320961 | 379 | CmdResult serialTx(bool enable); |
Matt Briggs | 40:2ec4be320961 | 380 | |
Matt Briggs | 58:15aa7a785b9f | 381 | CmdResult prepareSleep(); |
Matt Briggs | 58:15aa7a785b9f | 382 | CmdResult exitSleep(); |
Matt Briggs | 58:15aa7a785b9f | 383 | |
Matt Briggs | 40:2ec4be320961 | 384 | private: |
Matt Briggs | 44:ece6330e9b57 | 385 | // Initialized during constructor |
Matt Briggs | 55:79ab0bbc5008 | 386 | NvmBBIOObj mNvmObj; |
Matt Briggs | 44:ece6330e9b57 | 387 | OneWire mOWMaster; |
Matt Briggs | 44:ece6330e9b57 | 388 | InterruptIn mCCIn; |
Matt Briggs | 44:ece6330e9b57 | 389 | InterruptIn mTamper; |
Matt Briggs | 44:ece6330e9b57 | 390 | InterruptIn mPairBtn; |
Matt Briggs | 44:ece6330e9b57 | 391 | DigitalOut mLed; |
Matt Briggs | 59:485545afc4dc | 392 | DigitalOut mLrrLed; |
Matt Briggs | 44:ece6330e9b57 | 393 | DigitalOut mSwitchedIOCtrl; |
Matt Briggs | 40:2ec4be320961 | 394 | |
Matt Briggs | 55:79ab0bbc5008 | 395 | // uint8_t mPortExpanderROM0[8]; // FIXME could probably get rid of |
Matt Briggs | 44:ece6330e9b57 | 396 | uint8_t mPortExpanderVal0; |
Matt Briggs | 55:79ab0bbc5008 | 397 | // uint8_t mPortExpanderROM1[8]; |
Matt Briggs | 44:ece6330e9b57 | 398 | uint8_t mPortExpanderVal1; |
Matt Briggs | 44:ece6330e9b57 | 399 | |
Matt Briggs | 44:ece6330e9b57 | 400 | DS2408 *mPortEx0; |
Matt Briggs | 44:ece6330e9b57 | 401 | DS2408 *mPortEx1; |
Matt Briggs | 40:2ec4be320961 | 402 | |
Matt Briggs | 49:18f1354f9e51 | 403 | void enableSwitchedIO () { |
Matt Briggs | 49:18f1354f9e51 | 404 | mSwitchedIOCtrl = 0; // assert since PMOS |
Matt Briggs | 49:18f1354f9e51 | 405 | } |
Matt Briggs | 49:18f1354f9e51 | 406 | void disableSwitchedIO () { |
Matt Briggs | 49:18f1354f9e51 | 407 | mSwitchedIOCtrl = 1; // deassertted since PMOS |
Matt Briggs | 49:18f1354f9e51 | 408 | } |
Matt Briggs | 49:18f1354f9e51 | 409 | |
Matt Briggs | 40:2ec4be320961 | 410 | /** |
Matt Briggs | 40:2ec4be320961 | 411 | * @brief Reads baseboard information from non-volatile memory (NVM) |
Matt Briggs | 40:2ec4be320961 | 412 | * |
Matt Briggs | 40:2ec4be320961 | 413 | * @details This data is read from the xDot's internal EEPROM. This |
Matt Briggs | 40:2ec4be320961 | 414 | * method is called from init(). The following |
Matt Briggs | 40:2ec4be320961 | 415 | * is stored: |
Matt Briggs | 40:2ec4be320961 | 416 | * 1. Storage code word |
Matt Briggs | 40:2ec4be320961 | 417 | * 2. 8-bit Baseboard configuration data |
Matt Briggs | 40:2ec4be320961 | 418 | * 3. 8-bit Baseboard revision data |
Matt Briggs | 40:2ec4be320961 | 419 | * 4. 16-bit Baseboard serial number |
Matt Briggs | 40:2ec4be320961 | 420 | * 5. 2 x 64-bit OneWire ROM port expander addresses |
Matt Briggs | 40:2ec4be320961 | 421 | * |
Matt Briggs | 40:2ec4be320961 | 422 | * TODO add memory map information |
Matt Briggs | 40:2ec4be320961 | 423 | * |
Matt Briggs | 40:2ec4be320961 | 424 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 425 | */ |
Matt Briggs | 40:2ec4be320961 | 426 | CmdResult readInfoFromNVM(); |
Matt Briggs | 40:2ec4be320961 | 427 | |
Matt Briggs | 40:2ec4be320961 | 428 | /** |
Matt Briggs | 40:2ec4be320961 | 429 | * @brief Stores baseboard information to non-volatile memory (NVM) |
Matt Briggs | 40:2ec4be320961 | 430 | * |
Matt Briggs | 40:2ec4be320961 | 431 | * @details This method is called during special configuration events like first time boot or factory reset. |
Matt Briggs | 40:2ec4be320961 | 432 | * |
Matt Briggs | 40:2ec4be320961 | 433 | * TODO add memory map information |
Matt Briggs | 40:2ec4be320961 | 434 | * |
Matt Briggs | 40:2ec4be320961 | 435 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 436 | */ |
Matt Briggs | 40:2ec4be320961 | 437 | CmdResult writeInfoToNVM(); |
Matt Briggs | 40:2ec4be320961 | 438 | |
Matt Briggs | 40:2ec4be320961 | 439 | /** |
Matt Briggs | 40:2ec4be320961 | 440 | * @brief Scans OneWire bus for port expanders and attempts to identify each. |
Matt Briggs | 40:2ec4be320961 | 441 | * |
Matt Briggs | 40:2ec4be320961 | 442 | * @details For this method to succeed switches must be in factory reset positions. |
Matt Briggs | 44:ece6330e9b57 | 443 | * Rotary 1 and 2 should be at 0 |
Matt Briggs | 44:ece6330e9b57 | 444 | * DIP Switches should be fully closed |
Matt Briggs | 40:2ec4be320961 | 445 | * |
Matt Briggs | 40:2ec4be320961 | 446 | * @return CmdResult |
Matt Briggs | 40:2ec4be320961 | 447 | */ |
Matt Briggs | 40:2ec4be320961 | 448 | CmdResult identifyPortExpanders(); |
Matt Briggs | 44:ece6330e9b57 | 449 | |
Matt Briggs | 44:ece6330e9b57 | 450 | /** |
Matt Briggs | 44:ece6330e9b57 | 451 | * @brief Forces relay to closed state |
Matt Briggs | 44:ece6330e9b57 | 452 | * |
Matt Briggs | 44:ece6330e9b57 | 453 | * @details Note coil assertion timing is done here |
Matt Briggs | 44:ece6330e9b57 | 454 | * |
Matt Briggs | 44:ece6330e9b57 | 455 | * @return CmdResult |
Matt Briggs | 44:ece6330e9b57 | 456 | */ |
Matt Briggs | 44:ece6330e9b57 | 457 | CmdResult closeRelay(); |
Matt Briggs | 44:ece6330e9b57 | 458 | |
Matt Briggs | 44:ece6330e9b57 | 459 | /** |
Matt Briggs | 44:ece6330e9b57 | 460 | * @brief Forces relay to open state |
Matt Briggs | 44:ece6330e9b57 | 461 | * |
Matt Briggs | 44:ece6330e9b57 | 462 | * @details Note coil assertion timing is done here |
Matt Briggs | 44:ece6330e9b57 | 463 | * |
Matt Briggs | 44:ece6330e9b57 | 464 | * @return CmdResult |
Matt Briggs | 44:ece6330e9b57 | 465 | */ |
Matt Briggs | 44:ece6330e9b57 | 466 | CmdResult openRelay(); |
Matt Briggs | 40:2ec4be320961 | 467 | }; |
Matt Briggs | 40:2ec4be320961 | 468 | |
Matt Briggs | 55:79ab0bbc5008 | 469 | |
Matt Briggs | 40:2ec4be320961 | 470 | #endif /* BASEBOARDIO_BASEBOARDIO_H_ */ |