diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/fmradio_i2c.c | 38 | ||||
-rw-r--r-- | firmware/target/coldfire/iriver/h100/adc-h100.c | 12 | ||||
-rw-r--r-- | firmware/target/coldfire/iriver/h100/sw_i2c-h100.c | 12 |
3 files changed, 49 insertions, 13 deletions
diff --git a/firmware/drivers/fmradio_i2c.c b/firmware/drivers/fmradio_i2c.c index 1c9bc300c2..0a1d0c1fd7 100644 --- a/firmware/drivers/fmradio_i2c.c +++ b/firmware/drivers/fmradio_i2c.c | |||
@@ -80,7 +80,17 @@ int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) | |||
80 | #endif | 80 | #endif |
81 | 81 | ||
82 | /* delay loop to achieve 400kHz at 120MHz CPU frequency */ | 82 | /* delay loop to achieve 400kHz at 120MHz CPU frequency */ |
83 | #define DELAY do { volatile int _x; for(_x=0;_x<22;_x++);} while (0) | 83 | #define DELAY \ |
84 | ({ \ | ||
85 | int _x_; \ | ||
86 | asm volatile ( \ | ||
87 | "move.l #21, %[_x_] \r\n" \ | ||
88 | "1: \r\n" \ | ||
89 | "subq.l #1, %[_x_] \r\n" \ | ||
90 | "bhi.b 1b \r\n" \ | ||
91 | : [_x_]"=&d"(_x_) \ | ||
92 | ); \ | ||
93 | }) | ||
84 | 94 | ||
85 | static void fmradio_i2c_start(void) | 95 | static void fmradio_i2c_start(void) |
86 | { | 96 | { |
@@ -102,8 +112,8 @@ static void fmradio_i2c_stop(void) | |||
102 | SDA_HI; | 112 | SDA_HI; |
103 | } | 113 | } |
104 | 114 | ||
105 | 115 | /* Generate ACK or NACK */ | |
106 | static void fmradio_i2c_ack(void) | 116 | static void fmradio_i2c_ack(bool nack) |
107 | { | 117 | { |
108 | /* Here's the deal. The slave is slow, and sometimes needs to wait | 118 | /* Here's the deal. The slave is slow, and sometimes needs to wait |
109 | before it can receive the acknowledge. Therefore it forces the clock | 119 | before it can receive the acknowledge. Therefore it forces the clock |
@@ -114,7 +124,11 @@ static void fmradio_i2c_ack(void) | |||
114 | we have to drive the SCL high repeatedly to simulate a pullup. */ | 124 | we have to drive the SCL high repeatedly to simulate a pullup. */ |
115 | 125 | ||
116 | SCL_LO; /* Set the clock low */ | 126 | SCL_LO; /* Set the clock low */ |
117 | SDA_LO; | 127 | |
128 | if (nack) | ||
129 | SDA_HI; | ||
130 | else | ||
131 | SDA_LO; | ||
118 | 132 | ||
119 | SCL_INPUT; /* Set the clock to input */ | 133 | SCL_INPUT; /* Set the clock to input */ |
120 | while(!SCL) /* and wait for the slave to release it */ | 134 | while(!SCL) /* and wait for the slave to release it */ |
@@ -248,8 +262,7 @@ int fmradio_i2c_read(int address, unsigned char* buf, int count) | |||
248 | for (i=count; i>0; i--) | 262 | for (i=count; i>0; i--) |
249 | { | 263 | { |
250 | *buf++ = fmradio_i2c_inb(); | 264 | *buf++ = fmradio_i2c_inb(); |
251 | if (i != 1) | 265 | fmradio_i2c_ack(i == 1); |
252 | fmradio_i2c_ack(); | ||
253 | } | 266 | } |
254 | } | 267 | } |
255 | else | 268 | else |
@@ -275,7 +288,7 @@ int fmradio_i2c_read(int address, unsigned char* buf, int count) | |||
275 | #define SCL (PBDR & 0x0002) | 288 | #define SCL (PBDR & 0x0002) |
276 | 289 | ||
277 | /* arbitrary delay loop */ | 290 | /* arbitrary delay loop */ |
278 | #define DELAY do { volatile int _x; for(_x=0;_x<20;_x++);} while (0) | 291 | #define DELAY do { int _x; for(_x=0;_x<20;_x++);} while (0) |
279 | 292 | ||
280 | static void fmradio_i2c_start(void) | 293 | static void fmradio_i2c_start(void) |
281 | { | 294 | { |
@@ -296,7 +309,7 @@ static void fmradio_i2c_stop(void) | |||
296 | } | 309 | } |
297 | 310 | ||
298 | 311 | ||
299 | static void fmradio_i2c_ack(void) | 312 | static void fmradio_i2c_ack(bool nack) |
300 | { | 313 | { |
301 | /* Here's the deal. The slave is slow, and sometimes needs to wait | 314 | /* 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 | 315 | before it can receive the acknowledge. Therefore it forces the clock |
@@ -304,7 +317,11 @@ static void fmradio_i2c_ack(void) | |||
304 | high before we release the ack. */ | 317 | high before we release the ack. */ |
305 | 318 | ||
306 | SCL_LO; /* Set the clock low */ | 319 | SCL_LO; /* Set the clock low */ |
307 | SDA_LO; | 320 | |
321 | if (nack) | ||
322 | SDA_HI; | ||
323 | else | ||
324 | SDA_LO; | ||
308 | 325 | ||
309 | SCL_INPUT; /* Set the clock to input */ | 326 | SCL_INPUT; /* Set the clock to input */ |
310 | while(!SCL) /* and wait for the slave to release it */ | 327 | while(!SCL) /* and wait for the slave to release it */ |
@@ -416,8 +433,7 @@ int fmradio_i2c_read(int address, unsigned char* buf, int count) | |||
416 | for (i=count; i>0; i--) | 433 | for (i=count; i>0; i--) |
417 | { | 434 | { |
418 | *buf++ = fmradio_i2c_inb(); | 435 | *buf++ = fmradio_i2c_inb(); |
419 | if (i != 1) | 436 | fmradio_i2c_ack(i == 1); |
420 | fmradio_i2c_ack(); | ||
421 | } | 437 | } |
422 | } | 438 | } |
423 | else | 439 | else |
diff --git a/firmware/target/coldfire/iriver/h100/adc-h100.c b/firmware/target/coldfire/iriver/h100/adc-h100.c index a20b1e8d30..fb5afce9f5 100644 --- a/firmware/target/coldfire/iriver/h100/adc-h100.c +++ b/firmware/target/coldfire/iriver/h100/adc-h100.c | |||
@@ -34,7 +34,17 @@ static unsigned char adcdata[NUM_ADC_CHANNELS]; | |||
34 | #define DI_HI or_l(0x00200000, &GPIO_OUT) | 34 | #define DI_HI or_l(0x00200000, &GPIO_OUT) |
35 | 35 | ||
36 | /* delay loop */ | 36 | /* delay loop */ |
37 | #define DELAY do { int _x; for(_x=0;_x<10;_x++) asm volatile ("");} while (0) | 37 | #define DELAY \ |
38 | ({ \ | ||
39 | int _x_; \ | ||
40 | asm volatile ( \ | ||
41 | "move.l #9, %[_x_] \r\n" \ | ||
42 | "1: \r\n" \ | ||
43 | "subq.l #1, %[_x_] \r\n" \ | ||
44 | "bhi.b 1b \r\n" \ | ||
45 | : [_x_]"=&d"(_x_) \ | ||
46 | ); \ | ||
47 | }) | ||
38 | 48 | ||
39 | unsigned short adc_scan(int channel) | 49 | unsigned short adc_scan(int channel) |
40 | { | 50 | { |
diff --git a/firmware/target/coldfire/iriver/h100/sw_i2c-h100.c b/firmware/target/coldfire/iriver/h100/sw_i2c-h100.c index 49db2b621d..3b2cdc4042 100644 --- a/firmware/target/coldfire/iriver/h100/sw_i2c-h100.c +++ b/firmware/target/coldfire/iriver/h100/sw_i2c-h100.c | |||
@@ -42,7 +42,17 @@ | |||
42 | #define SDA_HI and_l(~0x00002000, &GPIO1_ENABLE) | 42 | #define SDA_HI and_l(~0x00002000, &GPIO1_ENABLE) |
43 | 43 | ||
44 | /* delay loop to achieve 400kHz at 120MHz CPU frequency */ | 44 | /* delay loop to achieve 400kHz at 120MHz CPU frequency */ |
45 | #define DELAY do { volatile int _x; for(_x=0;_x<22;_x++);} while(0) | 45 | #define DELAY \ |
46 | ({ \ | ||
47 | int _x_; \ | ||
48 | asm volatile ( \ | ||
49 | "move.l #21, %[_x_] \r\n" \ | ||
50 | "1: \r\n" \ | ||
51 | "subq.l #1, %[_x_] \r\n" \ | ||
52 | "bhi.b 1b \r\n" \ | ||
53 | : [_x_]"=&d"(_x_) \ | ||
54 | ); \ | ||
55 | }) | ||
46 | 56 | ||
47 | void sw_i2c_init(void) | 57 | void sw_i2c_init(void) |
48 | { | 58 | { |