eBoard ①⑧⑨
Written for SIA 2017/2018
eagle_I2C.h
Go to the documentation of this file.
1 #ifndef EAGLE_EBOARD_HELPLIB_I2C
2  #define EAGLE_EBOARD_HELPLIB_I2C
3 
12 //=====================================================================================================================================================
13 // I²C
14 //=====================================================================================================================================================
15 
16  //-------------------------------------------------------------------------------------------------------------------------------------------------
17  // send1
18  //-------------------------------------------------------------------------------------------------------------------------------------------------
19 
35  optVAL_t sendI2C(optVAL_t deviceID,byte *buf, byte buf_len);
36 
37  //-------------------------------------------------------------------------------------------------------------------------------------------------
38  // send2
39  //-------------------------------------------------------------------------------------------------------------------------------------------------
40 
55  optVAL_t sendI2C(optVAL_t deviceID, byte buf);
56 
57  //-------------------------------------------------------------------------------------------------------------------------------------------------
58  // I²C ping
59  //-------------------------------------------------------------------------------------------------------------------------------------------------
60 
69  void pingI2C(optVAL_t ret[], optVAL_t ret_len);
70 
71  //-------------------------------------------------------------------------------------------------------------------------------------------------
72  // read1
73  //-------------------------------------------------------------------------------------------------------------------------------------------------
74 
85  inline void readI2C(optVAL_t deviceID, optVAL_t ret[], optVAL_t ret_len,bool blocking=true);
86 
87 
89 
90  void pingI2C(optVAL_t ret[], optVAL_t ret_len){
91  optVAL_t count = 0;
92  for (byte i = 1; (i < 255 && !STOP); i++) /*ignore special*/ {
93  if(i==200)continue; //internal
94  Wire.beginTransmission (i);
95  if (Wire.endTransmission () == 0) {
96  if(count < ret_len) ret[count] = i;
97  count++;
98  delay (1);
99  }
100  }
101  }
102 
103  optVAL_t sendI2C(optVAL_t deviceID,byte *buf, byte buf_len) {
104  Wire.beginTransmission(deviceID);
105  Wire.write(buf,buf_len);
106  return Wire.endTransmission();
107  }
108 
109  optVAL_t sendI2C(optVAL_t deviceID, byte buf){
110  Wire.beginTransmission(deviceID);
111  Wire.write(buf);
112  return Wire.endTransmission();
113  }
114 
115  void readI2C(optVAL_t deviceID,optVAL_t ret[] , optVAL_t ret_len,bool blocking) {
116  for(optVAL_t rect = 0x0; (Wire.available() || (((blocking && (rect < ret_len))) && (!STOP))); rect++)
117  ret[rect] = Wire.read();
118  }
120 
121 #endif
const unsigned char * buf[11]
to enable &#39;smooth&#39; access (:
optVAL_t sendI2C(optVAL_t deviceID, byte *buf, byte buf_len)
Sends a buffer of bytes to a certain I²C-Device.
void readI2C(optVAL_t deviceID, optVAL_t ret[], optVAL_t ret_len, bool blocking=true)
Reads a special amount of bits from a certain I²C-Device.
static bool STOP
Definition: eBoard.h:123
TwoWire Wire
this is the well-known Arduino Wire Interface, just a little bit &#39;modified&#39; ;P
int optVAL_t
Definition: eBoard.h:137
void pingI2C(optVAL_t ret[], optVAL_t ret_len)
Sends a byte to a certain I²C-Device.