diff options
author | Bertrik Sikken <bertrik@sikken.nl> | 2008-12-08 19:32:05 +0000 |
---|---|---|
committer | Bertrik Sikken <bertrik@sikken.nl> | 2008-12-08 19:32:05 +0000 |
commit | ed96b2a4ddf39b91621e125a95380d3a23a1cc73 (patch) | |
tree | 7d657aa129f826e05c3f51a4b21eac119fb2094f | |
parent | bbb1f8904359e3e399bb2fd99c3ffc9e42c78216 (diff) | |
download | rockbox-ed96b2a4ddf39b91621e125a95380d3a23a1cc73.tar.gz rockbox-ed96b2a4ddf39b91621e125a95380d3a23a1cc73.zip |
Sansa Clip: implement the fmradio_i2c interface using generic_i2c
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19366 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/export/fmradio_i2c.h | 1 | ||||
-rw-r--r-- | firmware/target/arm/as3525/sansa-clip/fmradio-i2c-clip.c | 137 |
2 files changed, 138 insertions, 0 deletions
diff --git a/firmware/export/fmradio_i2c.h b/firmware/export/fmradio_i2c.h index e97ad0d2e1..5d1252768c 100644 --- a/firmware/export/fmradio_i2c.h +++ b/firmware/export/fmradio_i2c.h | |||
@@ -22,6 +22,7 @@ | |||
22 | #ifndef FMRADIO_I2C_H | 22 | #ifndef FMRADIO_I2C_H |
23 | #define FMRADIO_I2C_H | 23 | #define FMRADIO_I2C_H |
24 | 24 | ||
25 | void fmradio_i2c_init(void); | ||
25 | int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count); | 26 | int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count); |
26 | int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count); | 27 | int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count); |
27 | 28 | ||
diff --git a/firmware/target/arm/as3525/sansa-clip/fmradio-i2c-clip.c b/firmware/target/arm/as3525/sansa-clip/fmradio-i2c-clip.c new file mode 100644 index 0000000000..e3444b8acf --- /dev/null +++ b/firmware/target/arm/as3525/sansa-clip/fmradio-i2c-clip.c | |||
@@ -0,0 +1,137 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Bertrik Sikken | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | /* | ||
23 | This is the fmradio_i2c interface, used by the radio driver | ||
24 | to communicate with the radio tuner chip. | ||
25 | |||
26 | It is implemented using the generic i2c driver, which does "bit-banged" | ||
27 | I2C with a couple of GPIO pins. | ||
28 | */ | ||
29 | |||
30 | #include "as3525.h" | ||
31 | #include "generic_i2c.h" | ||
32 | #include "fmradio_i2c.h" | ||
33 | |||
34 | #define I2C_SCL_PIN 4 | ||
35 | #define I2C_SDA_PIN 5 | ||
36 | |||
37 | static void fm_scl_hi(void) | ||
38 | { | ||
39 | GPIOB_PIN(I2C_SCL_PIN) = 1 << I2C_SCL_PIN; | ||
40 | } | ||
41 | |||
42 | static void fm_scl_lo(void) | ||
43 | { | ||
44 | GPIOB_PIN(I2C_SCL_PIN) = 0; | ||
45 | } | ||
46 | |||
47 | static void fm_sda_hi(void) | ||
48 | { | ||
49 | GPIOB_PIN(I2C_SDA_PIN) = 1 << I2C_SDA_PIN; | ||
50 | } | ||
51 | |||
52 | static void fm_sda_lo(void) | ||
53 | { | ||
54 | GPIOB_PIN(I2C_SDA_PIN) = 0; | ||
55 | } | ||
56 | |||
57 | static void fm_sda_input(void) | ||
58 | { | ||
59 | GPIOB_DIR &= ~(1 << I2C_SDA_PIN); | ||
60 | } | ||
61 | |||
62 | static void fm_sda_output(void) | ||
63 | { | ||
64 | GPIOB_DIR |= 1 << I2C_SDA_PIN; | ||
65 | } | ||
66 | |||
67 | static void fm_scl_input(void) | ||
68 | { | ||
69 | GPIOB_DIR &= ~(1 << I2C_SCL_PIN); | ||
70 | } | ||
71 | |||
72 | static void fm_scl_output(void) | ||
73 | { | ||
74 | GPIOB_DIR |= 1 << I2C_SCL_PIN; | ||
75 | } | ||
76 | |||
77 | static int fm_sda(void) | ||
78 | { | ||
79 | return GPIOB_PIN(I2C_SDA_PIN); | ||
80 | } | ||
81 | |||
82 | static int fm_scl(void) | ||
83 | { | ||
84 | return GPIOB_PIN(I2C_SCL_PIN); | ||
85 | } | ||
86 | |||
87 | /* simple and crude delay, used for all delays in the generic i2c driver */ | ||
88 | static void fm_delay(void) | ||
89 | { | ||
90 | volatile int i; | ||
91 | |||
92 | /* this loop is uncalibrated and could use more sophistication */ | ||
93 | for (i = 0; i < 100; i++) { | ||
94 | } | ||
95 | } | ||
96 | |||
97 | /* interface towards the generic i2c driver */ | ||
98 | static struct i2c_interface fm_i2c_interface = { | ||
99 | .address = 0x10 << 1, | ||
100 | |||
101 | .scl_hi = fm_scl_hi, | ||
102 | .scl_lo = fm_scl_lo, | ||
103 | .sda_hi = fm_sda_hi, | ||
104 | .sda_lo = fm_sda_lo, | ||
105 | .sda_input = fm_sda_input, | ||
106 | .sda_output = fm_sda_output, | ||
107 | .scl_input = fm_scl_input, | ||
108 | .scl_output = fm_scl_output, | ||
109 | .scl = fm_scl, | ||
110 | .sda = fm_sda, | ||
111 | |||
112 | .delay_hd_sta = fm_delay, | ||
113 | .delay_hd_dat = fm_delay, | ||
114 | .delay_su_dat = fm_delay, | ||
115 | .delay_su_sto = fm_delay, | ||
116 | .delay_su_sta = fm_delay, | ||
117 | .delay_thigh = fm_delay | ||
118 | }; | ||
119 | |||
120 | /* initialise i2c for fmradio */ | ||
121 | void fmradio_i2c_init(void) | ||
122 | { | ||
123 | i2c_add_node(&fm_i2c_interface); | ||
124 | } | ||
125 | |||
126 | int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) | ||
127 | { | ||
128 | return i2c_write_data(address, -1, buf, count); | ||
129 | } | ||
130 | |||
131 | int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) | ||
132 | { | ||
133 | return i2c_read_data(address, -1, buf, count); | ||
134 | } | ||
135 | |||
136 | |||
137 | |||