summaryrefslogtreecommitdiff
path: root/firmware/drivers/fmradio_i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/fmradio_i2c.c')
-rw-r--r--firmware/drivers/fmradio_i2c.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/firmware/drivers/fmradio_i2c.c b/firmware/drivers/fmradio_i2c.c
index 4e491093f0..2475084696 100644
--- a/firmware/drivers/fmradio_i2c.c
+++ b/firmware/drivers/fmradio_i2c.c
@@ -30,18 +30,38 @@
30/* cute little functions, atomic read-modify-write */ 30/* cute little functions, atomic read-modify-write */
31/* SDA is GPIO1,23 */ 31/* SDA is GPIO1,23 */
32 32
33#define SDA_LO and_l(~0x00800000, &GPIO1_OUT) // and_b(~0x10, &PBDRL) 33#ifdef IRIVER_H300_SERIES
34#define SDA_HI or_l( 0x00800000, &GPIO1_OUT) // or_b( 0x10, &PBDRL) 34
35#define SDA_INPUT and_l(~0x00800000, &GPIO1_ENABLE) // and_b(~0x10, &PBIORL) 35/* SDA is GPIO57 */
36#define SDA_OUTPUT or_l( 0x00800000, &GPIO1_ENABLE) // or_b( 0x10, &PBIORL) 36#define SDA_LO and_l(~0x02000000, &GPIO1_OUT)
37#define SDA ( 0x00800000 & GPIO1_READ) // (PBDR & 0x0010) 37#define SDA_HI or_l( 0x02000000, &GPIO1_OUT)
38 38#define SDA_INPUT and_l(~0x02000000, &GPIO1_ENABLE)
39/* SCL is GPIO, 3 */ 39#define SDA_OUTPUT or_l( 0x02000000, &GPIO1_ENABLE)
40#define SCL_INPUT and_l(~0x00000008, &GPIO_ENABLE) // and_b(~0x02, &PBIORL) 40#define SDA ( 0x02000000 & GPIO1_READ)
41#define SCL_OUTPUT or_l( 0x00000008, &GPIO_ENABLE) // or_b( 0x02, &PBIORL) 41
42#define SCL_LO and_l(~0x00000008, &GPIO_OUT) // and_b(~0x02, &PBDRL) 42/* SCL is GPIO56 */
43#define SCL_HI or_l( 0x00000008, &GPIO_OUT) // or_b( 0x02, &PBDRL) 43#define SCL_INPUT and_l(~0x01000000, &GPIO1_ENABLE)
44#define SCL ( 0x00000008 & GPIO_READ) // (PBDR & 0x0002) 44#define SCL_OUTPUT or_l( 0x01000000, &GPIO1_ENABLE)
45#define SCL_LO and_l(~0x01000000, &GPIO1_OUT)
46#define SCL_HI or_l( 0x01000000, &GPIO1_OUT)
47#define SCL ( 0x01000000 & GPIO1_READ)
48
49#else
50
51/* SDA is GPIO55 */
52#define SDA_LO and_l(~0x00800000, &GPIO1_OUT)
53#define SDA_HI or_l( 0x00800000, &GPIO1_OUT)
54#define SDA_INPUT and_l(~0x00800000, &GPIO1_ENABLE)
55#define SDA_OUTPUT or_l( 0x00800000, &GPIO1_ENABLE)
56#define SDA ( 0x00800000 & GPIO1_READ)
57
58/* SCL is GPIO3 */
59#define SCL_INPUT and_l(~0x00000008, &GPIO_ENABLE)
60#define SCL_OUTPUT or_l( 0x00000008, &GPIO_ENABLE)
61#define SCL_LO and_l(~0x00000008, &GPIO_OUT)
62#define SCL_HI or_l( 0x00000008, &GPIO_OUT)
63#define SCL ( 0x00000008 & GPIO_READ)
64#endif
45 65
46/* delay loop to achieve 400kHz at 120MHz CPU frequency */ 66/* delay loop to achieve 400kHz at 120MHz CPU frequency */
47#define DELAY do { int _x; for(_x=0;_x<22;_x++);} while(0) 67#define DELAY do { int _x; for(_x=0;_x<22;_x++);} while(0)
@@ -84,8 +104,8 @@ static void fmradio_i2c_ack(void)
84 SCL_INPUT; /* Set the clock to input */ 104 SCL_INPUT; /* Set the clock to input */
85 while(!SCL) /* and wait for the slave to release it */ 105 while(!SCL) /* and wait for the slave to release it */
86 { 106 {
87 SCL_OUTPUT; /* Set the clock to output */
88 SCL_HI; 107 SCL_HI;
108 SCL_OUTPUT; /* Set the clock to output */
89 SCL_INPUT; /* Set the clock to input */ 109 SCL_INPUT; /* Set the clock to input */
90 DELAY; 110 DELAY;
91 } 111 }
@@ -111,8 +131,8 @@ static int fmradio_i2c_getack(void)
111 SCL_INPUT; /* Set the clock to input */ 131 SCL_INPUT; /* Set the clock to input */
112 while(!SCL) /* and wait for the slave to release it */ 132 while(!SCL) /* and wait for the slave to release it */
113 { 133 {
114 SCL_OUTPUT; /* Set the clock to output */
115 SCL_HI; 134 SCL_HI;
135 SCL_OUTPUT; /* Set the clock to output */
116 SCL_INPUT; /* Set the clock to input */ 136 SCL_INPUT; /* Set the clock to input */
117 DELAY; 137 DELAY;
118 } 138 }
@@ -160,10 +180,12 @@ static unsigned char fmradio_i2c_inb(void)
160 /* clock in each bit, MSB first */ 180 /* clock in each bit, MSB first */
161 for ( i=0x80; i; i>>=1 ) { 181 for ( i=0x80; i; i>>=1 ) {
162 SDA_INPUT; /* And set to input */ 182 SDA_INPUT; /* And set to input */
163 SCL_HI; 183 DELAY;
164 DELAY; 184 DELAY;
165 if ( SDA ) 185 if ( SDA )
166 byte |= i; 186 byte |= i;
187 SCL_HI;
188 DELAY;
167 SCL_LO; 189 SCL_LO;
168 DELAY; 190 DELAY;
169 SDA_OUTPUT; 191 SDA_OUTPUT;