@@ -44,8 +44,6 @@ static const PinMap PinMap_I2C_SCL[] = {
44
44
{NC , NC , 0 }
45
45
};
46
46
47
- static uint8_t first_read ;
48
-
49
47
void i2c_init (i2c_t * obj , PinName sda , PinName scl ) {
50
48
uint32_t i2c_sda = pinmap_peripheral (sda , PinMap_I2C_SDA );
51
49
uint32_t i2c_scl = pinmap_peripheral (scl , PinMap_I2C_SCL );
@@ -60,12 +58,10 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
60
58
61
59
pinmap_pinout (sda , PinMap_I2C_SDA );
62
60
pinmap_pinout (scl , PinMap_I2C_SCL );
63
- first_read = 1 ;
64
61
}
65
62
66
63
int i2c_start (i2c_t * obj ) {
67
64
i2c_hal_send_start (obj -> instance );
68
- first_read = 1 ;
69
65
return 0 ;
70
66
}
71
67
@@ -78,7 +74,6 @@ int i2c_stop(i2c_t *obj) {
78
74
// This wait is also included on the samples
79
75
// code provided with the freedom board
80
76
for (n = 0 ; n < 100 ; n ++ ) __NOP ();
81
- first_read = 1 ;
82
77
return 0 ;
83
78
}
84
79
@@ -229,26 +224,15 @@ int i2c_byte_read(i2c_t *obj, int last) {
229
224
// set rx mode
230
225
i2c_hal_set_direction (obj -> instance , kI2CReceive );
231
226
232
- if (first_read ) {
233
- // first dummy read
234
- i2c_do_read (obj , & data , 0 );
235
- first_read = 0 ;
236
- }
237
-
238
- if (last ) {
239
- // set tx mode
240
- i2c_hal_set_direction (obj -> instance , kI2CTransmit );
241
- return i2c_hal_read (obj -> instance );
242
- }
243
-
227
+ // Setup read
244
228
i2c_do_read (obj , & data , last );
245
229
246
- return data ;
230
+ // set tx mode
231
+ i2c_hal_set_direction (obj -> instance , kI2CTransmit );
232
+ return i2c_hal_read (obj -> instance );
247
233
}
248
234
249
235
int i2c_byte_write (i2c_t * obj , int data ) {
250
- first_read = 1 ;
251
-
252
236
// set tx mode
253
237
i2c_hal_set_direction (obj -> instance , kI2CTransmit );
254
238
0 commit comments