Class for representing and controlling entire I2C transactions (the master side). This class allows one to separate in code the configuration of I2C transactions from their use. This property simplifies the process of executing transactions in, for example, the body of a real-time control loop.
I2CTransaction.h@5:ad382f9f43ca, 2014-05-26 (annotated)
- Committer:
- symbiotic
- Date:
- Mon May 26 20:06:44 2014 +0000
- Revision:
- 5:ad382f9f43ca
- Parent:
- 3:a9d61e73fe97
- Child:
- 6:4775131da69b
Added support for resetting transactions that are in an error state (not clear that this is a good idea with theMODI2C library)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
symbiotic | 0:96a7926b9d64 | 1 | #ifndef I2CTRANSACTION_H |
symbiotic | 0:96a7926b9d64 | 2 | #define I2CTRANSACTION_H |
symbiotic | 0:96a7926b9d64 | 3 | #include "MODI2C.h" |
symbiotic | 0:96a7926b9d64 | 4 | |
symbiotic | 0:96a7926b9d64 | 5 | class I2CTransaction |
symbiotic | 0:96a7926b9d64 | 6 | { |
symbiotic | 0:96a7926b9d64 | 7 | public: |
symbiotic | 0:96a7926b9d64 | 8 | I2CTransaction(int address, char* writePacket, int writePacketLength, char* readPacket = NULL, int readPacketLength = 0); |
symbiotic | 0:96a7926b9d64 | 9 | static void setFrequency(int frequency); |
symbiotic | 5:ad382f9f43ca | 10 | static void setMaxRetry(int maxRetry); |
symbiotic | 0:96a7926b9d64 | 11 | bool completed(); |
symbiotic | 0:96a7926b9d64 | 12 | int getStatus(int i); |
symbiotic | 0:96a7926b9d64 | 13 | bool initiateTransaction(); |
symbiotic | 0:96a7926b9d64 | 14 | bool waitForCompletion(int timeout = 1000); |
symbiotic | 0:96a7926b9d64 | 15 | void displayStatus(Serial *pc, char * strg); |
symbiotic | 0:96a7926b9d64 | 16 | bool success(); |
symbiotic | 3:a9d61e73fe97 | 17 | bool transmissionError(); |
symbiotic | 5:ad382f9f43ca | 18 | bool checkTransaction(); |
symbiotic | 5:ad382f9f43ca | 19 | static int getI2CQueueLength(); |
symbiotic | 0:96a7926b9d64 | 20 | |
symbiotic | 0:96a7926b9d64 | 21 | private: |
symbiotic | 0:96a7926b9d64 | 22 | static MODI2C *i2c; |
symbiotic | 0:96a7926b9d64 | 23 | |
symbiotic | 0:96a7926b9d64 | 24 | int status[2]; // Status words for both the write and read halves of the transaction |
symbiotic | 0:96a7926b9d64 | 25 | int address; |
symbiotic | 0:96a7926b9d64 | 26 | char* writePacket; |
symbiotic | 0:96a7926b9d64 | 27 | int writePacketLength; |
symbiotic | 0:96a7926b9d64 | 28 | char* readPacket; |
symbiotic | 0:96a7926b9d64 | 29 | int readPacketLength; |
symbiotic | 5:ad382f9f43ca | 30 | int retryCount; |
symbiotic | 5:ad382f9f43ca | 31 | static int maxRetryCount; |
symbiotic | 0:96a7926b9d64 | 32 | }; |
symbiotic | 0:96a7926b9d64 | 33 | |
symbiotic | 0:96a7926b9d64 | 34 | |
symbiotic | 0:96a7926b9d64 | 35 | #endif |
symbiotic | 0:96a7926b9d64 | 36 |