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
00001 #ifndef I2CTRANSACTION_H 00002 #define I2CTRANSACTION_H 00003 #include "MODI2C.h" 00004 00005 class I2CTransaction 00006 { 00007 public: 00008 I2CTransaction(int address, char* writePacket, int writePacketLength, char* readPacket = NULL, int readPacketLength = 0); 00009 static void setFrequency(int frequency); 00010 static void setMaxRetry(int maxRetry); 00011 bool completed(); 00012 int getStatus(int i); 00013 bool initiateTransaction(); 00014 bool waitForCompletion(int timeout = 1000); 00015 void displayStatus(Serial *pc, char * strg); 00016 bool success(); 00017 bool transmissionError(); 00018 bool checkTransaction(); 00019 void clearStatus(); 00020 static int getI2CQueueLength(); 00021 static void reset(); 00022 static void resetBus(); 00023 static void cycleBus(); 00024 static void initI2C(PinName sda, PinName scl); 00025 00026 private: 00027 static MODI2C *i2c; 00028 00029 int status[2]; // Status words for both the write and read halves of the transaction 00030 int address; 00031 char* writePacket; 00032 int writePacketLength; 00033 char* readPacket; 00034 int readPacketLength; 00035 int retryCount; 00036 static int maxRetryCount; 00037 }; 00038 00039 00040 #endif 00041
Generated on Tue Jul 12 2022 23:09:24 by
1.7.2