diff options
author | Barry Wardell <rockbox@barrywardell.net> | 2007-11-10 19:14:01 +0000 |
---|---|---|
committer | Barry Wardell <rockbox@barrywardell.net> | 2007-11-10 19:14:01 +0000 |
commit | 0d8111cb399cf9db7a25d4a5ddc867a22de1a5bc (patch) | |
tree | d0ba66a558f455a7015c65469521b02abc8b2a1a | |
parent | a677678e3196a1981d0ff60cd1f756b985abaaeb (diff) | |
download | rockbox-0d8111cb399cf9db7a25d4a5ddc867a22de1a5bc.tar.gz rockbox-0d8111cb399cf9db7a25d4a5ddc867a22de1a5bc.zip |
Split radio i2c drivers into target tree where they belong. No changes to binaries produced.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15558 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/SOURCES | 7 | ||||
-rw-r--r-- | firmware/target/coldfire/iaudio/x5/fmradio_i2c-x5.c | 37 | ||||
-rw-r--r-- | firmware/target/coldfire/iriver/fmradio_i2c-iriver.c (renamed from firmware/drivers/fmradio_i2c.c) | 195 | ||||
-rw-r--r-- | firmware/target/sh/archos/ondio/fmradio_i2c-ondio.c | 197 |
4 files changed, 242 insertions, 194 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index 94b98979ce..24a6db9fa6 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -163,7 +163,6 @@ drivers/fmradio.c | |||
163 | drivers/tuner/s1a0903x01.c | 163 | drivers/tuner/s1a0903x01.c |
164 | #endif /* (CONFIG_TUNER & S1A0903X01) */ | 164 | #endif /* (CONFIG_TUNER & S1A0903X01) */ |
165 | #if (CONFIG_TUNER & TEA5767) | 165 | #if (CONFIG_TUNER & TEA5767) |
166 | drivers/fmradio_i2c.c | ||
167 | drivers/tuner/tea5767.c | 166 | drivers/tuner/tea5767.c |
168 | #endif /* (CONFIG_TUNER & TEA5767) */ | 167 | #endif /* (CONFIG_TUNER & TEA5767) */ |
169 | #endif /*SIMULATOR */ | 168 | #endif /*SIMULATOR */ |
@@ -406,6 +405,9 @@ target/sh/archos/ondio/button-ondio.c | |||
406 | target/sh/archos/ondio/power-ondio.c | 405 | target/sh/archos/ondio/power-ondio.c |
407 | target/sh/archos/ondio/powermgmt-ondio.c | 406 | target/sh/archos/ondio/powermgmt-ondio.c |
408 | target/sh/archos/ondio/usb-ondio.c | 407 | target/sh/archos/ondio/usb-ondio.c |
408 | #if (CONFIG_TUNER & TEA5767) | ||
409 | target/sh/archos/ondio/fmradio_i2c-ondio.c | ||
410 | #endif | ||
409 | #endif /* SIMULATOR */ | 411 | #endif /* SIMULATOR */ |
410 | #endif /* ARCHOS_ONDIOFM || ARCHOS_ONDIOFM */ | 412 | #endif /* ARCHOS_ONDIOFM || ARCHOS_ONDIOFM */ |
411 | 413 | ||
@@ -459,6 +461,7 @@ target/coldfire/iaudio/usb-iaudio.c | |||
459 | target/coldfire/iaudio/x5/backlight-x5.c | 461 | target/coldfire/iaudio/x5/backlight-x5.c |
460 | target/coldfire/iaudio/x5/button-x5.c | 462 | target/coldfire/iaudio/x5/button-x5.c |
461 | target/coldfire/iaudio/x5/ds2411-x5.c | 463 | target/coldfire/iaudio/x5/ds2411-x5.c |
464 | target/coldfire/iaudio/x5/fmradio_i2c-x5.c | ||
462 | target/coldfire/iaudio/x5/lcd-as-x5.S | 465 | target/coldfire/iaudio/x5/lcd-as-x5.S |
463 | target/coldfire/iaudio/x5/lcd-x5.c | 466 | target/coldfire/iaudio/x5/lcd-x5.c |
464 | target/coldfire/iaudio/x5/m5636-x5.c | 467 | target/coldfire/iaudio/x5/m5636-x5.c |
@@ -505,6 +508,7 @@ target/coldfire/pcf50606-coldfire.c | |||
505 | target/coldfire/iriver/ata-iriver.c | 508 | target/coldfire/iriver/ata-iriver.c |
506 | target/coldfire/iriver/lcd-remote-iriver.c | 509 | target/coldfire/iriver/lcd-remote-iriver.c |
507 | target/coldfire/iriver/system-iriver.c | 510 | target/coldfire/iriver/system-iriver.c |
511 | target/coldfire/iriver/fmradio_i2c-iriver.c | ||
508 | target/coldfire/iriver/h300/sw_i2c-h300.c | 512 | target/coldfire/iriver/h300/sw_i2c-h300.c |
509 | target/coldfire/iriver/h300/adc-h300.c | 513 | target/coldfire/iriver/h300/adc-h300.c |
510 | target/coldfire/iriver/h300/backlight-h300.c | 514 | target/coldfire/iriver/h300/backlight-h300.c |
@@ -527,6 +531,7 @@ target/coldfire/ata-as-coldfire.S | |||
527 | target/coldfire/iriver/ata-iriver.c | 531 | target/coldfire/iriver/ata-iriver.c |
528 | target/coldfire/iriver/lcd-remote-iriver.c | 532 | target/coldfire/iriver/lcd-remote-iriver.c |
529 | target/coldfire/iriver/system-iriver.c | 533 | target/coldfire/iriver/system-iriver.c |
534 | target/coldfire/iriver/fmradio_i2c-iriver.c | ||
530 | target/coldfire/iriver/h100/sw_i2c-h100.c | 535 | target/coldfire/iriver/h100/sw_i2c-h100.c |
531 | target/coldfire/iriver/h100/adc-h100.c | 536 | target/coldfire/iriver/h100/adc-h100.c |
532 | target/coldfire/iriver/h100/backlight-h100.c | 537 | target/coldfire/iriver/h100/backlight-h100.c |
diff --git a/firmware/target/coldfire/iaudio/x5/fmradio_i2c-x5.c b/firmware/target/coldfire/iaudio/x5/fmradio_i2c-x5.c new file mode 100644 index 0000000000..6ee670f9fe --- /dev/null +++ b/firmware/target/coldfire/iaudio/x5/fmradio_i2c-x5.c | |||
@@ -0,0 +1,37 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * Physical interface of the Philips TEA5767 in iAudio x5 | ||
10 | * | ||
11 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
12 | * | ||
13 | * All files in this archive are subject to the GNU General Public License. | ||
14 | * See the file COPYING in the source tree root for full license agreement. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | #include "config.h" | ||
21 | |||
22 | #if (CONFIG_TUNER & TEA5767) | ||
23 | |||
24 | #include "i2c-coldfire.h" | ||
25 | |||
26 | int fmradio_i2c_write(unsigned char address, const unsigned char* buf, | ||
27 | int count) | ||
28 | { | ||
29 | return i2c_write(I2C_IFACE_0, address, buf, count); | ||
30 | } | ||
31 | |||
32 | int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) | ||
33 | { | ||
34 | return i2c_read(I2C_IFACE_0, address, buf, count); | ||
35 | } | ||
36 | |||
37 | #endif | ||
diff --git a/firmware/drivers/fmradio_i2c.c b/firmware/target/coldfire/iriver/fmradio_i2c-iriver.c index 9f890ca34a..7c431dae2b 100644 --- a/firmware/drivers/fmradio_i2c.c +++ b/firmware/target/coldfire/iriver/fmradio_i2c-iriver.c | |||
@@ -5,8 +5,8 @@ | |||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
7 | * \/ \/ \/ \/ \/ | 7 | * \/ \/ \/ \/ \/ |
8 | * $Id$ | 8 | * $Id:$ |
9 | * Physical interface of the Philips TEA5767 in Archos Ondio | 9 | * Physical interface of the Philips TEA5767 in iriver H100/H300 series |
10 | * | 10 | * |
11 | * Copyright (C) 2002 by Linus Nielsen Feltzing | 11 | * Copyright (C) 2002 by Linus Nielsen Feltzing |
12 | * | 12 | * |
@@ -19,29 +19,10 @@ | |||
19 | ****************************************************************************/ | 19 | ****************************************************************************/ |
20 | #include "config.h" | 20 | #include "config.h" |
21 | #include "cpu.h" | 21 | #include "cpu.h" |
22 | #include "kernel.h" | ||
23 | #include "thread.h" | ||
24 | #include "logf.h" | 22 | #include "logf.h" |
25 | #include "system.h" | 23 | #include "system.h" |
26 | #include "string.h" | ||
27 | 24 | ||
28 | #if (CONFIG_TUNER & TEA5767) | 25 | #if (CONFIG_TUNER & TEA5767) |
29 | #if (CONFIG_I2C == I2C_COLDFIRE) | ||
30 | |||
31 | #ifdef IAUDIO_X5 | ||
32 | #include "i2c-coldfire.h" | ||
33 | |||
34 | int fmradio_i2c_write(unsigned char address, const unsigned char* buf, | ||
35 | int count) | ||
36 | { | ||
37 | return i2c_write(I2C_IFACE_0, address, buf, count); | ||
38 | } | ||
39 | |||
40 | int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) | ||
41 | { | ||
42 | return i2c_read(I2C_IFACE_0, address, buf, count); | ||
43 | } | ||
44 | #else | ||
45 | 26 | ||
46 | /* cute little functions, atomic read-modify-write */ | 27 | /* cute little functions, atomic read-modify-write */ |
47 | /* SDA is GPIO1,23 */ | 28 | /* SDA is GPIO1,23 */ |
@@ -257,177 +238,5 @@ int fmradio_i2c_read(int address, unsigned char* buf, int count) | |||
257 | fmradio_i2c_stop(); | 238 | fmradio_i2c_stop(); |
258 | return x; | 239 | return x; |
259 | } | 240 | } |
260 | #endif /* ! IAUDIO_X5 */ | ||
261 | #else | ||
262 | /* cute little functions, atomic read-modify-write */ | ||
263 | /* SDA is PB4 */ | ||
264 | #define SDA_LO and_b(~0x10, &PBDRL) | ||
265 | #define SDA_HI or_b(0x10, &PBDRL) | ||
266 | #define SDA_INPUT and_b(~0x10, &PBIORL) | ||
267 | #define SDA_OUTPUT or_b(0x10, &PBIORL) | ||
268 | #define SDA (PBDR & 0x0010) | ||
269 | |||
270 | /* SCL is PB1 */ | ||
271 | #define SCL_INPUT and_b(~0x02, &PBIORL) | ||
272 | #define SCL_OUTPUT or_b(0x02, &PBIORL) | ||
273 | #define SCL_LO and_b(~0x02, &PBDRL) | ||
274 | #define SCL_HI or_b(0x02, &PBDRL) | ||
275 | #define SCL (PBDR & 0x0002) | ||
276 | |||
277 | /* arbitrary delay loop */ | ||
278 | #define DELAY do { int _x; for(_x=0;_x<20;_x++);} while (0) | ||
279 | |||
280 | static void fmradio_i2c_start(void) | ||
281 | { | ||
282 | SDA_OUTPUT; | ||
283 | SDA_HI; | ||
284 | SCL_HI; | ||
285 | SDA_LO; | ||
286 | DELAY; | ||
287 | SCL_LO; | ||
288 | } | ||
289 | |||
290 | static void fmradio_i2c_stop(void) | ||
291 | { | ||
292 | SDA_LO; | ||
293 | SCL_HI; | ||
294 | DELAY; | ||
295 | SDA_HI; | ||
296 | } | ||
297 | |||
298 | |||
299 | static void fmradio_i2c_ack(bool nack) | ||
300 | { | ||
301 | /* Here's the deal. The slave is slow, and sometimes needs to wait | ||
302 | before it can receive the acknowledge. Therefore it forces the clock | ||
303 | low until it is ready. We need to poll the clock line until it goes | ||
304 | high before we release the ack. */ | ||
305 | |||
306 | SCL_LO; /* Set the clock low */ | ||
307 | |||
308 | if (nack) | ||
309 | SDA_HI; | ||
310 | else | ||
311 | SDA_LO; | ||
312 | |||
313 | SCL_INPUT; /* Set the clock to input */ | ||
314 | while(!SCL) /* and wait for the slave to release it */ | ||
315 | sleep_thread(0); | ||
316 | |||
317 | DELAY; | ||
318 | SCL_OUTPUT; | ||
319 | SCL_LO; | ||
320 | } | ||
321 | 241 | ||
322 | static int fmradio_i2c_getack(void) | ||
323 | { | ||
324 | int ret = 1; | ||
325 | |||
326 | /* Here's the deal. The slave is slow, and sometimes needs to wait | ||
327 | before it can send the acknowledge. Therefore it forces the clock | ||
328 | low until it is ready. We need to poll the clock line until it goes | ||
329 | high before we read the ack. */ | ||
330 | |||
331 | SDA_INPUT; /* And set to input */ | ||
332 | SCL_INPUT; /* Set the clock to input */ | ||
333 | while(!SCL) /* and wait for the slave to release it */ | ||
334 | sleep_thread(0); | ||
335 | |||
336 | if (SDA) | ||
337 | /* ack failed */ | ||
338 | ret = 0; | ||
339 | |||
340 | SCL_OUTPUT; | ||
341 | SCL_LO; | ||
342 | SDA_HI; | ||
343 | SDA_OUTPUT; | ||
344 | return ret; | ||
345 | } | ||
346 | |||
347 | static void fmradio_i2c_outb(unsigned char byte) | ||
348 | { | ||
349 | int i; | ||
350 | |||
351 | /* clock out each bit, MSB first */ | ||
352 | for ( i=0x80; i; i>>=1 ) { | ||
353 | if ( i & byte ) | ||
354 | { | ||
355 | SDA_HI; | ||
356 | } | ||
357 | else | ||
358 | { | ||
359 | SDA_LO; | ||
360 | } | ||
361 | SCL_HI; | ||
362 | SCL_LO; | ||
363 | } | ||
364 | |||
365 | SDA_HI; | ||
366 | } | ||
367 | |||
368 | static unsigned char fmradio_i2c_inb(void) | ||
369 | { | ||
370 | int i; | ||
371 | unsigned char byte = 0; | ||
372 | |||
373 | /* clock in each bit, MSB first */ | ||
374 | for ( i=0x80; i; i>>=1 ) { | ||
375 | SDA_INPUT; /* And set to input */ | ||
376 | SCL_HI; | ||
377 | if ( SDA ) | ||
378 | byte |= i; | ||
379 | SCL_LO; | ||
380 | SDA_OUTPUT; | ||
381 | } | ||
382 | |||
383 | return byte; | ||
384 | } | ||
385 | |||
386 | int fmradio_i2c_write(int address, const unsigned char* buf, int count) | ||
387 | { | ||
388 | int i,x=0; | ||
389 | |||
390 | fmradio_i2c_start(); | ||
391 | fmradio_i2c_outb(address & 0xfe); | ||
392 | if (fmradio_i2c_getack()) | ||
393 | { | ||
394 | for (i=0; i<count; i++) | ||
395 | { | ||
396 | fmradio_i2c_outb(buf[i]); | ||
397 | if (!fmradio_i2c_getack()) | ||
398 | { | ||
399 | x=-2; | ||
400 | break; | ||
401 | } | ||
402 | } | ||
403 | } | ||
404 | else | ||
405 | { | ||
406 | logf("fmradio_i2c_write() - no ack\n"); | ||
407 | x=-1; | ||
408 | } | ||
409 | fmradio_i2c_stop(); | ||
410 | return x; | ||
411 | } | ||
412 | |||
413 | int fmradio_i2c_read(int address, unsigned char* buf, int count) | ||
414 | { | ||
415 | int i,x=0; | ||
416 | |||
417 | fmradio_i2c_start(); | ||
418 | fmradio_i2c_outb(address | 1); | ||
419 | if (fmradio_i2c_getack()) { | ||
420 | for (i=count; i>0; i--) | ||
421 | { | ||
422 | *buf++ = fmradio_i2c_inb(); | ||
423 | fmradio_i2c_ack(i == 1); | ||
424 | } | ||
425 | } | ||
426 | else | ||
427 | x=-1; | ||
428 | fmradio_i2c_stop(); | ||
429 | return x; | ||
430 | } | ||
431 | |||
432 | #endif | ||
433 | #endif | 242 | #endif |
diff --git a/firmware/target/sh/archos/ondio/fmradio_i2c-ondio.c b/firmware/target/sh/archos/ondio/fmradio_i2c-ondio.c new file mode 100644 index 0000000000..f62797480a --- /dev/null +++ b/firmware/target/sh/archos/ondio/fmradio_i2c-ondio.c | |||
@@ -0,0 +1,197 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * Physical interface of the Philips TEA5767 in Archos Ondio | ||
10 | * | ||
11 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
12 | * | ||
13 | * All files in this archive are subject to the GNU General Public License. | ||
14 | * See the file COPYING in the source tree root for full license agreement. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | #include "config.h" | ||
21 | #include "cpu.h" | ||
22 | #include "logf.h" | ||
23 | #include "system.h" | ||
24 | |||
25 | #if (CONFIG_TUNER & TEA5767) | ||
26 | |||
27 | /* cute little functions, atomic read-modify-write */ | ||
28 | /* SDA is PB4 */ | ||
29 | #define SDA_LO and_b(~0x10, &PBDRL) | ||
30 | #define SDA_HI or_b(0x10, &PBDRL) | ||
31 | #define SDA_INPUT and_b(~0x10, &PBIORL) | ||
32 | #define SDA_OUTPUT or_b(0x10, &PBIORL) | ||
33 | #define SDA (PBDR & 0x0010) | ||
34 | |||
35 | /* SCL is PB1 */ | ||
36 | #define SCL_INPUT and_b(~0x02, &PBIORL) | ||
37 | #define SCL_OUTPUT or_b(0x02, &PBIORL) | ||
38 | #define SCL_LO and_b(~0x02, &PBDRL) | ||
39 | #define SCL_HI or_b(0x02, &PBDRL) | ||
40 | #define SCL (PBDR & 0x0002) | ||
41 | |||
42 | /* arbitrary delay loop */ | ||
43 | #define DELAY do { int _x; for(_x=0;_x<20;_x++);} while (0) | ||
44 | |||
45 | static void fmradio_i2c_start(void) | ||
46 | { | ||
47 | SDA_OUTPUT; | ||
48 | SDA_HI; | ||
49 | SCL_HI; | ||
50 | SDA_LO; | ||
51 | DELAY; | ||
52 | SCL_LO; | ||
53 | } | ||
54 | |||
55 | static void fmradio_i2c_stop(void) | ||
56 | { | ||
57 | SDA_LO; | ||
58 | SCL_HI; | ||
59 | DELAY; | ||
60 | SDA_HI; | ||
61 | } | ||
62 | |||
63 | |||
64 | static void fmradio_i2c_ack(bool nack) | ||
65 | { | ||
66 | /* Here's the deal. The slave is slow, and sometimes needs to wait | ||
67 | before it can receive the acknowledge. Therefore it forces the clock | ||
68 | low until it is ready. We need to poll the clock line until it goes | ||
69 | high before we release the ack. */ | ||
70 | |||
71 | SCL_LO; /* Set the clock low */ | ||
72 | |||
73 | if (nack) | ||
74 | SDA_HI; | ||
75 | else | ||
76 | SDA_LO; | ||
77 | |||
78 | SCL_INPUT; /* Set the clock to input */ | ||
79 | while(!SCL) /* and wait for the slave to release it */ | ||
80 | sleep_thread(0); | ||
81 | |||
82 | DELAY; | ||
83 | SCL_OUTPUT; | ||
84 | SCL_LO; | ||
85 | } | ||
86 | |||
87 | static int fmradio_i2c_getack(void) | ||
88 | { | ||
89 | int ret = 1; | ||
90 | |||
91 | /* Here's the deal. The slave is slow, and sometimes needs to wait | ||
92 | before it can send the acknowledge. Therefore it forces the clock | ||
93 | low until it is ready. We need to poll the clock line until it goes | ||
94 | high before we read the ack. */ | ||
95 | |||
96 | SDA_INPUT; /* And set to input */ | ||
97 | SCL_INPUT; /* Set the clock to input */ | ||
98 | while(!SCL) /* and wait for the slave to release it */ | ||
99 | sleep_thread(0); | ||
100 | |||
101 | if (SDA) | ||
102 | /* ack failed */ | ||
103 | ret = 0; | ||
104 | |||
105 | SCL_OUTPUT; | ||
106 | SCL_LO; | ||
107 | SDA_HI; | ||
108 | SDA_OUTPUT; | ||
109 | return ret; | ||
110 | } | ||
111 | |||
112 | static void fmradio_i2c_outb(unsigned char byte) | ||
113 | { | ||
114 | int i; | ||
115 | |||
116 | /* clock out each bit, MSB first */ | ||
117 | for ( i=0x80; i; i>>=1 ) { | ||
118 | if ( i & byte ) | ||
119 | { | ||
120 | SDA_HI; | ||
121 | } | ||
122 | else | ||
123 | { | ||
124 | SDA_LO; | ||
125 | } | ||
126 | SCL_HI; | ||
127 | SCL_LO; | ||
128 | } | ||
129 | |||
130 | SDA_HI; | ||
131 | } | ||
132 | |||
133 | static unsigned char fmradio_i2c_inb(void) | ||
134 | { | ||
135 | int i; | ||
136 | unsigned char byte = 0; | ||
137 | |||
138 | /* clock in each bit, MSB first */ | ||
139 | for ( i=0x80; i; i>>=1 ) { | ||
140 | SDA_INPUT; /* And set to input */ | ||
141 | SCL_HI; | ||
142 | if ( SDA ) | ||
143 | byte |= i; | ||
144 | SCL_LO; | ||
145 | SDA_OUTPUT; | ||
146 | } | ||
147 | |||
148 | return byte; | ||
149 | } | ||
150 | |||
151 | int fmradio_i2c_write(int address, const unsigned char* buf, int count) | ||
152 | { | ||
153 | int i,x=0; | ||
154 | |||
155 | fmradio_i2c_start(); | ||
156 | fmradio_i2c_outb(address & 0xfe); | ||
157 | if (fmradio_i2c_getack()) | ||
158 | { | ||
159 | for (i=0; i<count; i++) | ||
160 | { | ||
161 | fmradio_i2c_outb(buf[i]); | ||
162 | if (!fmradio_i2c_getack()) | ||
163 | { | ||
164 | x=-2; | ||
165 | break; | ||
166 | } | ||
167 | } | ||
168 | } | ||
169 | else | ||
170 | { | ||
171 | logf("fmradio_i2c_write() - no ack\n"); | ||
172 | x=-1; | ||
173 | } | ||
174 | fmradio_i2c_stop(); | ||
175 | return x; | ||
176 | } | ||
177 | |||
178 | int fmradio_i2c_read(int address, unsigned char* buf, int count) | ||
179 | { | ||
180 | int i,x=0; | ||
181 | |||
182 | fmradio_i2c_start(); | ||
183 | fmradio_i2c_outb(address | 1); | ||
184 | if (fmradio_i2c_getack()) { | ||
185 | for (i=count; i>0; i--) | ||
186 | { | ||
187 | *buf++ = fmradio_i2c_inb(); | ||
188 | fmradio_i2c_ack(i == 1); | ||
189 | } | ||
190 | } | ||
191 | else | ||
192 | x=-1; | ||
193 | fmradio_i2c_stop(); | ||
194 | return x; | ||
195 | } | ||
196 | |||
197 | #endif | ||