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