SFBHWI2C.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef SFBHWI2C_H
00024 #define SFBHWI2C_H
00025
00035 #include "SFBTypes.h"
00036
00038 enum I2CStatusCodes {
00039 I2C_MODE_UNINITIALIZED = -4,
00040 I2C_MODE_ARBITRATION_ERROR = -3,
00041 I2C_MODE_NO_ACK = -2,
00042 I2C_MODE_ERROR = -1,
00043 I2C_MODE_DONE = 0,
00044 I2C_MODE_RECEIVE = 1,
00045 I2C_MODE_TRANSMIT = 2,
00046 I2C_MODE_TRANSCEIVE = 3
00047 };
00048
00050 enum I2CInterfaceCodes {
00051 I2C_1 = 1,
00052 I2C_2 = 2
00053 };
00054
00059 enum I2CPinSelectCode {
00060 I2C1_PINS_WEST_TX_RX = 0,
00061 I2C1_PINS_SOUTH_D3_D2 = 1,
00062 I2C2_PINS_EAST_TX_RX = 0
00063 };
00064
00072 typedef u32 (*I2CByteSource)(int offset);
00073
00080 typedef bool (*I2CByteSink)(u8 byte);
00081
00087 class SFBHWI2C {
00088
00089 public:
00090
00097 SFBHWI2C(u32 interface ) ;
00098
00110 void setByteSource(I2CByteSource function) {
00111 if (!function && byteSource) msgLen = 0;
00112 byteSource = function;
00113 }
00114
00127 void setByteSink(I2CByteSink function) {
00128 if (!function && byteSink) msgLen = 0;
00129 byteSink = function;
00130 }
00131
00141 void transmit(u8 address, u32 length, u8 *message);
00142
00152 void receive(u8 address, u32 length, u8 *message);
00153
00175 void transceive(u8 address, u32 xmtLength, u8 *xmtData, u32 rcvLength, u8 *rcvData);
00176
00186 void init(u32 pins, u32 bitRate);
00187
00196 s8 status();
00197
00207 void setBitRate(u32 bitRate);
00208
00213 u32 count();
00214
00215 private:
00216 void i2cInterrupt() ;
00217 friend void I2C1Handler();
00218 friend void I2C2Handler();
00219 void masterReceive();
00220 void masterTransmit();
00221
00222 I2CByteSource byteSource;
00223
00224 I2CByteSink byteSink;
00225
00226 u32 dataCount;
00227
00228 u32 msgLen;
00229
00230 u8* msg;
00231
00232 u32 xcvLen;
00233
00234 u8* xcvMsg;
00235
00236 const u8 i2c;
00237
00238 s8 mode;
00239
00240 u8 addr;
00241
00242 };
00243
00244 #endif
00245