Andy Lustig
/
Nucleo_statescript
stateScript for Nucleo-F401RE board
hardwareInterface.h@0:ecf80f0172d0, 2016-02-08 (annotated)
- Committer:
- alustig3
- Date:
- Mon Feb 08 18:56:09 2016 +0000
- Revision:
- 0:ecf80f0172d0
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alustig3 | 0:ecf80f0172d0 | 1 | #ifndef HARDWARWEINTERFACE_H |
alustig3 | 0:ecf80f0172d0 | 2 | #define HARDWARWEINTERFACE_H |
alustig3 | 0:ecf80f0172d0 | 3 | |
alustig3 | 0:ecf80f0172d0 | 4 | #include <stdint.h> |
alustig3 | 0:ecf80f0172d0 | 5 | #include <string> |
alustig3 | 0:ecf80f0172d0 | 6 | #include <cstdlib> |
alustig3 | 0:ecf80f0172d0 | 7 | #include <string.h> |
alustig3 | 0:ecf80f0172d0 | 8 | |
alustig3 | 0:ecf80f0172d0 | 9 | #define PENDINGTRIGGERBUFFERSIZE 10 |
alustig3 | 0:ecf80f0172d0 | 10 | |
alustig3 | 0:ecf80f0172d0 | 11 | //#define NUMPORTS 8 //the number of ports available on the hardware |
alustig3 | 0:ecf80f0172d0 | 12 | |
alustig3 | 0:ecf80f0172d0 | 13 | using namespace std; |
alustig3 | 0:ecf80f0172d0 | 14 | |
alustig3 | 0:ecf80f0172d0 | 15 | //for debugging output |
alustig3 | 0:ecf80f0172d0 | 16 | //#define DEBUGOUTPUT |
alustig3 | 0:ecf80f0172d0 | 17 | |
alustig3 | 0:ecf80f0172d0 | 18 | //used to organize digital change events |
alustig3 | 0:ecf80f0172d0 | 19 | struct changeEvent { |
alustig3 | 0:ecf80f0172d0 | 20 | uint32_t timeStamp; |
alustig3 | 0:ecf80f0172d0 | 21 | bool triggered; |
alustig3 | 0:ecf80f0172d0 | 22 | }; |
alustig3 | 0:ecf80f0172d0 | 23 | |
alustig3 | 0:ecf80f0172d0 | 24 | class sDigitalOut |
alustig3 | 0:ecf80f0172d0 | 25 | { |
alustig3 | 0:ecf80f0172d0 | 26 | public: |
alustig3 | 0:ecf80f0172d0 | 27 | sDigitalOut(); |
alustig3 | 0:ecf80f0172d0 | 28 | |
alustig3 | 0:ecf80f0172d0 | 29 | virtual void init(int pin) = 0; |
alustig3 | 0:ecf80f0172d0 | 30 | virtual void write(int value) = 0; |
alustig3 | 0:ecf80f0172d0 | 31 | virtual int read() = 0; |
alustig3 | 0:ecf80f0172d0 | 32 | protected: |
alustig3 | 0:ecf80f0172d0 | 33 | |
alustig3 | 0:ecf80f0172d0 | 34 | }; |
alustig3 | 0:ecf80f0172d0 | 35 | |
alustig3 | 0:ecf80f0172d0 | 36 | class sDigitalIn |
alustig3 | 0:ecf80f0172d0 | 37 | { |
alustig3 | 0:ecf80f0172d0 | 38 | public: |
alustig3 | 0:ecf80f0172d0 | 39 | sDigitalIn(); |
alustig3 | 0:ecf80f0172d0 | 40 | |
alustig3 | 0:ecf80f0172d0 | 41 | virtual void init(int pin) = 0; |
alustig3 | 0:ecf80f0172d0 | 42 | virtual int read() = 0; |
alustig3 | 0:ecf80f0172d0 | 43 | virtual void interrupt_up_callback() = 0; |
alustig3 | 0:ecf80f0172d0 | 44 | virtual void interrupt_down_callback() = 0; |
alustig3 | 0:ecf80f0172d0 | 45 | void setUpdate(bool); |
alustig3 | 0:ecf80f0172d0 | 46 | |
alustig3 | 0:ecf80f0172d0 | 47 | changeEvent lastUpEvent; |
alustig3 | 0:ecf80f0172d0 | 48 | changeEvent lastDownEvent; |
alustig3 | 0:ecf80f0172d0 | 49 | |
alustig3 | 0:ecf80f0172d0 | 50 | protected: |
alustig3 | 0:ecf80f0172d0 | 51 | |
alustig3 | 0:ecf80f0172d0 | 52 | bool updating; |
alustig3 | 0:ecf80f0172d0 | 53 | changeEvent bufferedUpEvent; |
alustig3 | 0:ecf80f0172d0 | 54 | changeEvent bufferedDownEvent; |
alustig3 | 0:ecf80f0172d0 | 55 | void addStateChange(int newState, uint32_t timeStamp); |
alustig3 | 0:ecf80f0172d0 | 56 | |
alustig3 | 0:ecf80f0172d0 | 57 | }; |
alustig3 | 0:ecf80f0172d0 | 58 | |
alustig3 | 0:ecf80f0172d0 | 59 | class sSerialPort |
alustig3 | 0:ecf80f0172d0 | 60 | { |
alustig3 | 0:ecf80f0172d0 | 61 | public: |
alustig3 | 0:ecf80f0172d0 | 62 | sSerialPort(); |
alustig3 | 0:ecf80f0172d0 | 63 | |
alustig3 | 0:ecf80f0172d0 | 64 | virtual void init() = 0; |
alustig3 | 0:ecf80f0172d0 | 65 | virtual bool readable() = 0; |
alustig3 | 0:ecf80f0172d0 | 66 | virtual char readChar() = 0; |
alustig3 | 0:ecf80f0172d0 | 67 | virtual void writeChar(char s)= 0; |
alustig3 | 0:ecf80f0172d0 | 68 | virtual int requestToWriteString(char *s, int numBytes) = 0; |
alustig3 | 0:ecf80f0172d0 | 69 | |
alustig3 | 0:ecf80f0172d0 | 70 | protected: |
alustig3 | 0:ecf80f0172d0 | 71 | |
alustig3 | 0:ecf80f0172d0 | 72 | |
alustig3 | 0:ecf80f0172d0 | 73 | }; |
alustig3 | 0:ecf80f0172d0 | 74 | |
alustig3 | 0:ecf80f0172d0 | 75 | class sSound |
alustig3 | 0:ecf80f0172d0 | 76 | { |
alustig3 | 0:ecf80f0172d0 | 77 | public: |
alustig3 | 0:ecf80f0172d0 | 78 | sSound(); |
alustig3 | 0:ecf80f0172d0 | 79 | void setFile(string fileNameIn); |
alustig3 | 0:ecf80f0172d0 | 80 | void setFile(unsigned char fileNumIn); |
alustig3 | 0:ecf80f0172d0 | 81 | void setVolume(int* volumeIn); |
alustig3 | 0:ecf80f0172d0 | 82 | void setVolume(int volumeIn); |
alustig3 | 0:ecf80f0172d0 | 83 | void setPlayback(bool playIn); |
alustig3 | 0:ecf80f0172d0 | 84 | void setReset(); |
alustig3 | 0:ecf80f0172d0 | 85 | virtual void execute() = 0; |
alustig3 | 0:ecf80f0172d0 | 86 | |
alustig3 | 0:ecf80f0172d0 | 87 | protected: |
alustig3 | 0:ecf80f0172d0 | 88 | char fileName[21]; |
alustig3 | 0:ecf80f0172d0 | 89 | bool fileNameExists; |
alustig3 | 0:ecf80f0172d0 | 90 | unsigned char fileNum; |
alustig3 | 0:ecf80f0172d0 | 91 | bool givenTrackNum; |
alustig3 | 0:ecf80f0172d0 | 92 | int* volumePtr; |
alustig3 | 0:ecf80f0172d0 | 93 | int volume; |
alustig3 | 0:ecf80f0172d0 | 94 | bool play; |
alustig3 | 0:ecf80f0172d0 | 95 | bool reset; |
alustig3 | 0:ecf80f0172d0 | 96 | }; |
alustig3 | 0:ecf80f0172d0 | 97 | |
alustig3 | 0:ecf80f0172d0 | 98 | class sSystem |
alustig3 | 0:ecf80f0172d0 | 99 | { |
alustig3 | 0:ecf80f0172d0 | 100 | public: |
alustig3 | 0:ecf80f0172d0 | 101 | sSystem(); |
alustig3 | 0:ecf80f0172d0 | 102 | virtual void timerinit() = 0; |
alustig3 | 0:ecf80f0172d0 | 103 | virtual void setStandAloneClock() = 0; |
alustig3 | 0:ecf80f0172d0 | 104 | virtual void setSlaveClock() = 0; |
alustig3 | 0:ecf80f0172d0 | 105 | virtual sDigitalOut* getDigitalOutPtr(int portNum) = 0; |
alustig3 | 0:ecf80f0172d0 | 106 | virtual sDigitalIn* getDigitalInPtr(int portNum) = 0; |
alustig3 | 0:ecf80f0172d0 | 107 | virtual sSound* createNewSoundAction() = 0; |
alustig3 | 0:ecf80f0172d0 | 108 | virtual void externalClockReset() = 0; //needs to reset harware timer before calling immediateClockReset(); |
alustig3 | 0:ecf80f0172d0 | 109 | virtual void incrementClock() = 0; |
alustig3 | 0:ecf80f0172d0 | 110 | virtual void mainLoopToDo(); |
alustig3 | 0:ecf80f0172d0 | 111 | virtual void pauseInterrupts(); |
alustig3 | 0:ecf80f0172d0 | 112 | virtual void resumeInterrupts(); |
alustig3 | 0:ecf80f0172d0 | 113 | virtual int getPendingFunctionTriggers(uint16_t *bufferPtr); //Returns the number of pending shortcut triggers |
alustig3 | 0:ecf80f0172d0 | 114 | virtual uint32_t getDigitalOutputChangeFlags(); |
alustig3 | 0:ecf80f0172d0 | 115 | virtual uint32_t getDigitalInputChangeFlags(); |
alustig3 | 0:ecf80f0172d0 | 116 | void setPortUpdatesOn(int portNum); |
alustig3 | 0:ecf80f0172d0 | 117 | void setPortUpdatesOff(int portNum); |
alustig3 | 0:ecf80f0172d0 | 118 | bool* getIgnoreUpdates(); |
alustig3 | 0:ecf80f0172d0 | 119 | |
alustig3 | 0:ecf80f0172d0 | 120 | |
alustig3 | 0:ecf80f0172d0 | 121 | |
alustig3 | 0:ecf80f0172d0 | 122 | protected: |
alustig3 | 0:ecf80f0172d0 | 123 | |
alustig3 | 0:ecf80f0172d0 | 124 | //virtual void timerInterrupt() = 0; |
alustig3 | 0:ecf80f0172d0 | 125 | |
alustig3 | 0:ecf80f0172d0 | 126 | void immediateClockReset(); |
alustig3 | 0:ecf80f0172d0 | 127 | int currentDINPin; |
alustig3 | 0:ecf80f0172d0 | 128 | int currentDOUTPin; |
alustig3 | 0:ecf80f0172d0 | 129 | uint32_t currentDigitalOuputStates; |
alustig3 | 0:ecf80f0172d0 | 130 | uint32_t currentDigitalInputStates; |
alustig3 | 0:ecf80f0172d0 | 131 | bool ignorePortUpdates[32]; |
alustig3 | 0:ecf80f0172d0 | 132 | |
alustig3 | 0:ecf80f0172d0 | 133 | |
alustig3 | 0:ecf80f0172d0 | 134 | |
alustig3 | 0:ecf80f0172d0 | 135 | |
alustig3 | 0:ecf80f0172d0 | 136 | }; |
alustig3 | 0:ecf80f0172d0 | 137 | |
alustig3 | 0:ecf80f0172d0 | 138 | |
alustig3 | 0:ecf80f0172d0 | 139 | //Used to buffer output text. Used mainly for 'display' commands within the script, |
alustig3 | 0:ecf80f0172d0 | 140 | //and alloed the reset of the block to execute quickly instead. The text is then streamed out |
alustig3 | 0:ecf80f0172d0 | 141 | //slowly via serial (one character per main loop execution). outputStream is a simple circular |
alustig3 | 0:ecf80f0172d0 | 142 | //buffer that cannot be resized after initiation. |
alustig3 | 0:ecf80f0172d0 | 143 | class outputStream { |
alustig3 | 0:ecf80f0172d0 | 144 | |
alustig3 | 0:ecf80f0172d0 | 145 | public: |
alustig3 | 0:ecf80f0172d0 | 146 | outputStream(int bufferSizeIn); |
alustig3 | 0:ecf80f0172d0 | 147 | ~outputStream(); |
alustig3 | 0:ecf80f0172d0 | 148 | void setSerial(sSerialPort *s); |
alustig3 | 0:ecf80f0172d0 | 149 | void send(const string &outputString); |
alustig3 | 0:ecf80f0172d0 | 150 | void send(const char* s); |
alustig3 | 0:ecf80f0172d0 | 151 | void debug(const char* s); |
alustig3 | 0:ecf80f0172d0 | 152 | outputStream &operator<<(const string &outputString); |
alustig3 | 0:ecf80f0172d0 | 153 | outputStream &operator<<(int outputNum); |
alustig3 | 0:ecf80f0172d0 | 154 | outputStream &operator<<(uint32_t outputNum); |
alustig3 | 0:ecf80f0172d0 | 155 | outputStream &operator<<(const char* s); |
alustig3 | 0:ecf80f0172d0 | 156 | char getNextChar(); |
alustig3 | 0:ecf80f0172d0 | 157 | bool unsentData; |
alustig3 | 0:ecf80f0172d0 | 158 | void flush(); |
alustig3 | 0:ecf80f0172d0 | 159 | |
alustig3 | 0:ecf80f0172d0 | 160 | private: |
alustig3 | 0:ecf80f0172d0 | 161 | int readHead; |
alustig3 | 0:ecf80f0172d0 | 162 | int writeHead; |
alustig3 | 0:ecf80f0172d0 | 163 | int totalWriteHead; |
alustig3 | 0:ecf80f0172d0 | 164 | int totalReadHead; |
alustig3 | 0:ecf80f0172d0 | 165 | int bufferSize; |
alustig3 | 0:ecf80f0172d0 | 166 | char tmpOut; |
alustig3 | 0:ecf80f0172d0 | 167 | char* outputBuffer; |
alustig3 | 0:ecf80f0172d0 | 168 | sSerialPort* serialPtr; |
alustig3 | 0:ecf80f0172d0 | 169 | }; |
alustig3 | 0:ecf80f0172d0 | 170 | |
alustig3 | 0:ecf80f0172d0 | 171 | |
alustig3 | 0:ecf80f0172d0 | 172 | |
alustig3 | 0:ecf80f0172d0 | 173 | #endif // HARDWARWEINTERFACE_H |