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.

Committer:
symbiotic
Date:
Sat Dec 20 15:41:21 2014 +0000
Revision:
8:63e07ac95a2c
Parent:
7:61e9a1da1f20
Added Transaction reset support

Who changed what in which revision?

UserRevisionLine numberNew 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 7:61e9a1da1f20 19 void clearStatus();
symbiotic 5:ad382f9f43ca 20 static int getI2CQueueLength();
symbiotic 6:4775131da69b 21 static void reset();
symbiotic 6:4775131da69b 22 static void resetBus();
symbiotic 6:4775131da69b 23 static void cycleBus();
symbiotic 7:61e9a1da1f20 24 static void initI2C(PinName sda, PinName scl);
symbiotic 0:96a7926b9d64 25
symbiotic 0:96a7926b9d64 26 private:
symbiotic 0:96a7926b9d64 27 static MODI2C *i2c;
symbiotic 0:96a7926b9d64 28
symbiotic 0:96a7926b9d64 29 int status[2]; // Status words for both the write and read halves of the transaction
symbiotic 0:96a7926b9d64 30 int address;
symbiotic 0:96a7926b9d64 31 char* writePacket;
symbiotic 0:96a7926b9d64 32 int writePacketLength;
symbiotic 0:96a7926b9d64 33 char* readPacket;
symbiotic 0:96a7926b9d64 34 int readPacketLength;
symbiotic 5:ad382f9f43ca 35 int retryCount;
symbiotic 5:ad382f9f43ca 36 static int maxRetryCount;
symbiotic 0:96a7926b9d64 37 };
symbiotic 0:96a7926b9d64 38
symbiotic 0:96a7926b9d64 39
symbiotic 0:96a7926b9d64 40 #endif
symbiotic 0:96a7926b9d64 41