summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorBertrik Sikken <bertrik@sikken.nl>2008-12-08 19:01:00 +0000
committerBertrik Sikken <bertrik@sikken.nl>2008-12-08 19:01:00 +0000
commitbbb1f8904359e3e399bb2fd99c3ffc9e42c78216 (patch)
tree3a3baec2b75cb0f656d4045396174c943b4beadf /firmware
parent9856a37de3ab581b894ee4e663d3f91475008968 (diff)
downloadrockbox-bbb1f8904359e3e399bb2fd99c3ffc9e42c78216.tar.gz
rockbox-bbb1f8904359e3e399bb2fd99c3ffc9e42c78216.zip
* 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')
-rw-r--r--firmware/drivers/generic_i2c.c28
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 @@
27 27
28#define MAX_I2C_INTERFACES 5 28#define MAX_I2C_INTERFACES 5
29 29
30int i2c_num_ifs = 0; 30static int i2c_num_ifs = 0;
31struct i2c_interface *i2c_if[MAX_I2C_INTERFACES]; 31static struct i2c_interface *i2c_if[MAX_I2C_INTERFACES];
32 32
33static void i2c_start(struct i2c_interface *iface) 33static void i2c_start(struct i2c_interface *iface)
34{ 34{
@@ -94,14 +94,12 @@ static unsigned char i2c_inb(struct i2c_interface *iface, bool ack)
94 94
95 /* clock in each bit, MSB first */ 95 /* clock in each bit, MSB first */
96 for ( i=0x80; i; i>>=1 ) { 96 for ( i=0x80; i; i>>=1 ) {
97 iface->sda_input();
98 iface->scl_hi(); 97 iface->scl_hi();
99 iface->delay_thigh(); 98 iface->delay_thigh();
100 if (iface->sda()) 99 if (iface->sda())
101 byte |= i; 100 byte |= i;
102 iface->scl_lo(); 101 iface->scl_lo();
103 iface->delay_hd_dat(); 102 iface->delay_hd_dat();
104 iface->sda_output();
105 } 103 }
106 104
107 i2c_ack(iface, ack); 105 i2c_ack(iface, ack);
@@ -109,7 +107,7 @@ static unsigned char i2c_inb(struct i2c_interface *iface, bool ack)
109 return byte; 107 return byte;
110} 108}
111 109
112static void i2c_outb(struct i2c_interface *iface, unsigned char byte) 110static int i2c_outb(struct i2c_interface *iface, unsigned char byte)
113{ 111{
114 int i; 112 int i;
115 113
@@ -129,6 +127,8 @@ static void i2c_outb(struct i2c_interface *iface, unsigned char byte)
129 } 127 }
130 128
131 iface->sda_hi(); 129 iface->sda_hi();
130
131 return i2c_getack(iface);
132} 132}
133 133
134static struct i2c_interface *find_if(int address) 134static struct i2c_interface *find_if(int address)
@@ -152,8 +152,7 @@ int i2c_write_data(int bus_address, int address,
152 return -1; 152 return -1;
153 153
154 i2c_start(iface); 154 i2c_start(iface);
155 i2c_outb(iface, iface->address & 0xfe); 155 if (!i2c_outb(iface, iface->address & 0xfe))
156 if (!i2c_getack(iface))
157 { 156 {
158 ret = -2; 157 ret = -2;
159 goto end; 158 goto end;
@@ -161,8 +160,7 @@ int i2c_write_data(int bus_address, int address,
161 160
162 if (address != -1) 161 if (address != -1)
163 { 162 {
164 i2c_outb(iface, address); 163 if (!i2c_outb(iface, address))
165 if (!i2c_getack(iface))
166 { 164 {
167 ret = -3; 165 ret = -3;
168 goto end; 166 goto end;
@@ -171,8 +169,7 @@ int i2c_write_data(int bus_address, int address,
171 169
172 for(i = 0;i < count;i++) 170 for(i = 0;i < count;i++)
173 { 171 {
174 i2c_outb(iface, buf[i]); 172 if (!i2c_outb(iface, buf[i]))
175 if (!i2c_getack(iface))
176 { 173 {
177 ret = -4; 174 ret = -4;
178 break; 175 break;
@@ -196,14 +193,12 @@ int i2c_read_data(int bus_address, int address,
196 if (address != -1) 193 if (address != -1)
197 { 194 {
198 i2c_start(iface); 195 i2c_start(iface);
199 i2c_outb(iface, iface->address & 0xfe); 196 if (!i2c_outb(iface, iface->address & 0xfe))
200 if (!i2c_getack(iface))
201 { 197 {
202 ret = -2; 198 ret = -2;
203 goto end; 199 goto end;
204 } 200 }
205 i2c_outb(iface, address); 201 if (!i2c_outb(iface, address))
206 if (!i2c_getack(iface))
207 { 202 {
208 ret = -3; 203 ret = -3;
209 goto end; 204 goto end;
@@ -211,8 +206,7 @@ int i2c_read_data(int bus_address, int address,
211 } 206 }
212 207
213 i2c_start(iface); 208 i2c_start(iface);
214 i2c_outb(iface, iface->address | 1); 209 if (!i2c_outb(iface, iface->address | 1))
215 if (!i2c_getack(iface))
216 { 210 {
217 ret = -4; 211 ret = -4;
218 goto end; 212 goto end;