I2C changes for the K64F

Fixed also here single byte read (probably)
pull/288/head
Sissors 2014-04-30 14:50:02 +02:00
parent 2ec18a06d8
commit 127eba40bd
1 changed files with 4 additions and 20 deletions

View File

@ -44,8 +44,6 @@ static const PinMap PinMap_I2C_SCL[] = {
{NC , NC , 0}
};
static uint8_t first_read;
void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
uint32_t i2c_sda = pinmap_peripheral(sda, PinMap_I2C_SDA);
uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL);
@ -60,12 +58,10 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
pinmap_pinout(sda, PinMap_I2C_SDA);
pinmap_pinout(scl, PinMap_I2C_SCL);
first_read = 1;
}
int i2c_start(i2c_t *obj) {
i2c_hal_send_start(obj->instance);
first_read = 1;
return 0;
}
@ -78,7 +74,6 @@ int i2c_stop(i2c_t *obj) {
// This wait is also included on the samples
// code provided with the freedom board
for (n = 0; n < 100; n++) __NOP();
first_read = 1;
return 0;
}
@ -229,26 +224,15 @@ int i2c_byte_read(i2c_t *obj, int last) {
// set rx mode
i2c_hal_set_direction(obj->instance, kI2CReceive);
if(first_read) {
// first dummy read
i2c_do_read(obj, &data, 0);
first_read = 0;
}
if (last) {
// set tx mode
i2c_hal_set_direction(obj->instance, kI2CTransmit);
return i2c_hal_read(obj->instance);
}
// Setup read
i2c_do_read(obj, &data, last);
return data;
// set tx mode
i2c_hal_set_direction(obj->instance, kI2CTransmit);
return i2c_hal_read(obj->instance);
}
int i2c_byte_write(i2c_t *obj, int data) {
first_read = 1;
// set tx mode
i2c_hal_set_direction(obj->instance, kI2CTransmit);