diff options
author | Bertrik Sikken <bertrik@sikken.nl> | 2008-12-08 19:01:00 +0000 |
---|---|---|
committer | Bertrik Sikken <bertrik@sikken.nl> | 2008-12-08 19:01:00 +0000 |
commit | bbb1f8904359e3e399bb2fd99c3ffc9e42c78216 (patch) | |
tree | 3a3baec2b75cb0f656d4045396174c943b4beadf /firmware/drivers | |
parent | 9856a37de3ab581b894ee4e663d3f91475008968 (diff) |
* combine i2c_ack and i2c_outb
* do not switch sda back and forth between input and output when reading a byte
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19365 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
-rw-r--r-- | firmware/drivers/generic_i2c.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/firmware/drivers/generic_i2c.c b/firmware/drivers/generic_i2c.c index 0dcc957260..dcbe46f654 100644 --- a/firmware/drivers/generic_i2c.c +++ b/firmware/drivers/generic_i2c.c @@ -27,8 +27,8 @@ #define MAX_I2C_INTERFACES 5 -int i2c_num_ifs = 0; -struct i2c_interface *i2c_if[MAX_I2C_INTERFACES]; +static int i2c_num_ifs = 0; +static struct i2c_interface *i2c_if[MAX_I2C_INTERFACES]; static void i2c_start(struct i2c_interface *iface) { @@ -94,14 +94,12 @@ static unsigned char i2c_inb(struct i2c_interface *iface, bool ack) /* clock in each bit, MSB first */ for ( i=0x80; i; i>>=1 ) { - iface->sda_input(); iface->scl_hi(); iface->delay_thigh(); if (iface->sda()) byte |= i; iface->scl_lo(); iface->delay_hd_dat(); - iface->sda_output(); } i2c_ack(iface, ack); @@ -109,7 +107,7 @@ static unsigned char i2c_inb(struct i2c_interface *iface, bool ack) return byte; } -static void i2c_outb(struct i2c_interface *iface, unsigned char byte) +static int i2c_outb(struct i2c_interface *iface, unsigned char byte) { int i; @@ -129,6 +127,8 @@ static void i2c_outb(struct i2c_interface *iface, unsigned char byte) } iface->sda_hi(); + + return i2c_getack(iface); } static struct i2c_interface *find_if(int address) @@ -152,8 +152,7 @@ int i2c_write_data(int bus_address, int address, return -1; i2c_start(iface); - i2c_outb(iface, iface->address & 0xfe); - if (!i2c_getack(iface)) + if (!i2c_outb(iface, iface->address & 0xfe)) { ret = -2; goto end; @@ -161,8 +160,7 @@ int i2c_write_data(int bus_address, int address, if (address != -1) { - i2c_outb(iface, address); - if (!i2c_getack(iface)) + if (!i2c_outb(iface, address)) { ret = -3; goto end; @@ -171,8 +169,7 @@ int i2c_write_data(int bus_address, int address, for(i = 0;i < count;i++) { - i2c_outb(iface, buf[i]); - if (!i2c_getack(iface)) + if (!i2c_outb(iface, buf[i])) { ret = -4; break; @@ -196,14 +193,12 @@ int i2c_read_data(int bus_address, int address, if (address != -1) { i2c_start(iface); - i2c_outb(iface, iface->address & 0xfe); - if (!i2c_getack(iface)) + if (!i2c_outb(iface, iface->address & 0xfe)) { ret = -2; goto end; } - i2c_outb(iface, address); - if (!i2c_getack(iface)) + if (!i2c_outb(iface, address)) { ret = -3; goto end; @@ -211,8 +206,7 @@ int i2c_read_data(int bus_address, int address, } i2c_start(iface); - i2c_outb(iface, iface->address | 1); - if (!i2c_getack(iface)) + if (!i2c_outb(iface, iface->address | 1)) { ret = -4; goto end; |