![](/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
- Committer:
- Matt Briggs
- Date:
- 2017-01-26
- Revision:
- 40:2ec4be320961
- Child:
- 44:ece6330e9b57
File content as of revision 40:2ec4be320961:
/* * baseboardIO.h * * Created on: Jan 25, 2017 * Author: mbriggs */ #include "DS2408.h" #ifndef BASEBOARDIO_H_ #define BASEBOARDIO_H_ /** * @class BaseboardIO * @brief This class abstracts utilizing the IO mostly found on the baseboard * this includes IO which is implemented via portExpanders. This API currently * does not implement interfaces for communications like UART or for memory like * flash devices. */ class BaseboardIO { public: /** * @brief BaseboardIO constructor * * @details Just initialized internal variables does not configure devices. * Should call init before other functions are called. * * On Entry: * * On Exit: * Internal variables are set to a known state but futher initialziation is required * * @return */ BaseboardIO(); /** * @brief Initialize IO to current values * * @details Initialize IO to current state and ensure that class variables * are updated to latest values. The following are initialized. * 1. PortExpanders are setup are read * 2. Relay is forced to known state * 3. Interrupts are setup * * On Entry: * * On Exit: * Either IO is configured or an error is returned * * @return CmdResult */ CmdResult init(); //////////////////////////////// // Registering for interrupts // //////////////////////////////// /** * @brief Register for contact closure interrupt * * @details Pass function pointer which will be called when interrupt occurs. * * On Entry: * * On Exit: * Callback registered * * @return */ void regCCInInt(void (*callback) (void)); /** * @brief Register for tamper interrupt * * @details Pass function pointer which will be called when interrupt occurs. * * On Entry: * * On Exit: * Callback registered * * @return */ void regTamperInt(void (*callback) (void)); /** * @brief Register for pair button interrupt * * @details Pass function pointer which will be called when interrupt occurs. Note * there is a hardware switch which can prevent the tamper sensor from pulling the line * down. If this switch deasserted there is no way in software to reconfigure this. * * On Entry: * * On Exit: * Callback registered * * @return */ void regPairBtnInt(void (*callback) (void)); /////////// // Input // /////////// /** * @brief samples current IO including port expanders * * @details Samples values and stores them so that IO accessors can execute quicker. * * Future: * Add some detail about how robust the values displayed here are. * It might be a good idea to add a timestamp for this IO * * On Entry: * * On Exit: * Internal class variables are updated or error is returned. * * @return CmdResult */ CmdResult sampleUserSwitches(); /** * @brief Returns the current state of the pair button * * @details This just simply uses the last sample of the IO to return a bool. * If the button is depressed than true is returned other wise false * * On Entry: * IO should be sampled recently * * On Exit: * * @return bool */ bool isPairBtn(); /** * @brief Returns the current state of the NO/NC switch * * @details This just simply uses the last sample of the IO to return a bool. * If the switch is in asserted position that the devices is normally closed (NC) * therefore false is returned. Otherwise device is normally open (NO) and therefore * returns true. * * On Entry: * IO should be sampled recently * * On Exit: * * @return bool */ bool isCCOutNO(); /** * @brief Returns the current state of the NO/NC switch * * @details This just simply uses the last sample of the IO to return a bool. * If the switch is in asserted position that the devices is normally closed (NC) * therefore true is returned. Otherwise device is normally open (NO) and therefore * returns false. * * On Entry: * IO should be sampled recently * * On Exit: * * @return bool */ bool isCCOutNC() {return isCCOutNO();} /** * @brief Returns the current state of the Rx/Tx switch * * @details This just simply uses the last sample of the IO to return a bool. * If the switch is in asserted position that the devices is transmitter (Tx) * therefore false is returned. Otherwise device is a receiver(Rx) and therefore * returns true. * * On Entry: * IO should be sampled recently * * On Exit: * * @return bool */ bool isRx(); /** * @brief Returns the current state of the Rx/Tx switch * * @details This just simply uses the last sample of the IO to return a bool. * If the switch is in asserted position that the devices is transmitter (Tx) * therefore true is returned. Otherwise device is a receiver(Rx) and therefore * returns false. * * On Entry: * IO should be sampled recently * * On Exit: * * @return bool */ bool isTx() {return !isRx();} /** * @brief Returns the current state of the LoRaWAN switch * * @details This just simply uses the last sample of the IO to return a bool. * If the switch is in asserted position that the device is will report via LoRaWAN * otherwise the device will use peer-to-peer mode. * * On Entry: * IO should be sampled recently * * On Exit: * * @return bool */ bool isLoRaWANMode(); /** * @brief Returns value of a rotary switch (TODO give board location) * * On Entry: * IO should be sampled recently * * On Exit: * * @return uint8_t */ uint8_t rotarySwitch1(); /** * @brief Returns value of a rotary switch (TODO give board location) * * On Entry: * IO should be sampled recently * * On Exit: * * @return uint8_t */ uint8_t rotarySwitch2(); //////////// // Output // //////////// /** * @brief Turns LED on * * @return CmdResult */ CmdResult ledOn(); /** * @brief Turns LED off * * @return CmdResult */ CmdResult ledOff(); /** * @brief Changes state of relay to alert * * @details If the configured as normally open then the relay closes and * vice versa for normally closed. * * @return CmdResult */ CmdResult relayAlert(); /** * @brief Changes state of relay to normal * * @details If the configured as normally open then the relay opens and * vice versa for normally closed. * * @return CmdResult */ CmdResult relayNormal(); /** * @brief Enables/disables serial chip * * @details This controls IO to ON/~OFF pin of RS232 chip. If transmitting * ensure serialTx is called as well. * * @return CmdResult */ CmdResult serialRx(bool enable); /** * @brief Controls serial chip transmission * * @details This controls IO to Tx_DIS pin of RS232 chip. Note calling this function will * also enable serialRx. * * @return CmdResult */ CmdResult serialTx(bool enable); private: void (*mCCInIntCallback) (void); void (*mTamperIntCallback) (void); void (*mPairBtnIntCallback) (void); uint8_t portExpanderROM0[8]; uint8_t portExpanderVal0; uint8_t portExpanderROM1[8]; uint8_t portExpanderVal1; /** * @brief Reads baseboard information from non-volatile memory (NVM) * * @details This data is read from the xDot's internal EEPROM. This * method is called from init(). The following * is stored: * 1. Storage code word * 2. 8-bit Baseboard configuration data * 3. 8-bit Baseboard revision data * 4. 16-bit Baseboard serial number * 5. 2 x 64-bit OneWire ROM port expander addresses * * TODO add memory map information * * @return CmdResult */ CmdResult readInfoFromNVM(); /** * @brief Stores baseboard information to non-volatile memory (NVM) * * @details This method is called during special configuration events like first time boot or factory reset. * * TODO add memory map information * * @return CmdResult */ CmdResult writeInfoToNVM(); /** * @brief Scans OneWire bus for port expanders and attempts to identify each. * * @details For this method to succeed switches must be in factory reset positions. * * @return CmdResult */ CmdResult identifyPortExpanders(); }; #endif /* BASEBOARDIO_BASEBOARDIO_H_ */