Skip to content

Commit 127eba4

Browse files
committed
I2C changes for the K64F
Fixed also here single byte read (probably)
1 parent 2ec18a0 commit 127eba4

File tree

1 file changed

+4
-20
lines changed
  • libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KSDK_MCUS/TARGET_K64F

1 file changed

+4
-20
lines changed

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KSDK_MCUS/TARGET_K64F/i2c_api.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ static const PinMap PinMap_I2C_SCL[] = {
4444
{NC , NC , 0}
4545
};
4646

47-
static uint8_t first_read;
48-
4947
void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
5048
uint32_t i2c_sda = pinmap_peripheral(sda, PinMap_I2C_SDA);
5149
uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL);
@@ -60,12 +58,10 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
6058

6159
pinmap_pinout(sda, PinMap_I2C_SDA);
6260
pinmap_pinout(scl, PinMap_I2C_SCL);
63-
first_read = 1;
6461
}
6562

6663
int i2c_start(i2c_t *obj) {
6764
i2c_hal_send_start(obj->instance);
68-
first_read = 1;
6965
return 0;
7066
}
7167

@@ -78,7 +74,6 @@ int i2c_stop(i2c_t *obj) {
7874
// This wait is also included on the samples
7975
// code provided with the freedom board
8076
for (n = 0; n < 100; n++) __NOP();
81-
first_read = 1;
8277
return 0;
8378
}
8479

@@ -229,26 +224,15 @@ int i2c_byte_read(i2c_t *obj, int last) {
229224
// set rx mode
230225
i2c_hal_set_direction(obj->instance, kI2CReceive);
231226

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
244228
i2c_do_read(obj, &data, last);
245229

246-
return data;
230+
// set tx mode
231+
i2c_hal_set_direction(obj->instance, kI2CTransmit);
232+
return i2c_hal_read(obj->instance);
247233
}
248234

249235
int i2c_byte_write(i2c_t *obj, int data) {
250-
first_read = 1;
251-
252236
// set tx mode
253237
i2c_hal_set_direction(obj->instance, kI2CTransmit);
254238

0 commit comments

Comments
 (0)