diff options
author | Marcoen Hirschberg <marcoen@gmail.com> | 2006-09-29 10:54:01 +0000 |
---|---|---|
committer | Marcoen Hirschberg <marcoen@gmail.com> | 2006-09-29 10:54:01 +0000 |
commit | 8e1e6f9b2939abd617b84c515a1018701a2cf082 (patch) | |
tree | 77ad5bf57a5a14c378869992b0bd3aa2f2e8ab3f | |
parent | 3496689c8e1ff48453cb9f46f67b7e36ab9955fd (diff) | |
download | rockbox-8e1e6f9b2939abd617b84c515a1018701a2cf082.tar.gz rockbox-8e1e6f9b2939abd617b84c515a1018701a2cf082.zip |
add the I2C driver for the Gigabeat
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11090 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/SOURCES | 1 | ||||
-rw-r--r-- | firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c | 121 |
2 files changed, 122 insertions, 0 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index 423fe0ee38..ffc2387e66 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -302,6 +302,7 @@ target/arm/gigabeat/meg-fx/usb-meg-fx.c | |||
302 | target/arm/gigabeat/meg-fx/lcd-meg-fx.c | 302 | target/arm/gigabeat/meg-fx/lcd-meg-fx.c |
303 | target/arm/gigabeat/meg-fx/sc606-meg-fx.c | 303 | target/arm/gigabeat/meg-fx/sc606-meg-fx.c |
304 | target/arm/gigabeat/meg-fx/adc-meg-fx.c | 304 | target/arm/gigabeat/meg-fx/adc-meg-fx.c |
305 | target/arm/gigabeat/meg-fx/i2c-meg-fx.c | ||
305 | #endif | 306 | #endif |
306 | #endif | 307 | #endif |
307 | 308 | ||
diff --git a/firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c b/firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c new file mode 100644 index 0000000000..c0e9fb4fc3 --- /dev/null +++ b/firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c | |||
@@ -0,0 +1,121 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include "cpu.h" | ||
21 | #include <stdbool.h> | ||
22 | #include "kernel.h" | ||
23 | #include "system.h" | ||
24 | #include "hwcompat.h" | ||
25 | #include "logf.h" | ||
26 | #include "debug.h" | ||
27 | #include "string.h" | ||
28 | #include "generic_i2c.h" | ||
29 | |||
30 | void i2c_sda_output(void) | ||
31 | { | ||
32 | GPECON |= (1 << 30); | ||
33 | } | ||
34 | |||
35 | void i2c_sda_input(void) | ||
36 | { | ||
37 | GPECON &= ~(3 << 30); | ||
38 | } | ||
39 | |||
40 | void i2c_sda_lo(void) | ||
41 | { | ||
42 | GPEDAT &= ~(1 << 15); | ||
43 | } | ||
44 | |||
45 | void i2c_sda_hi(void) | ||
46 | { | ||
47 | GPEDAT |= (1 << 15); | ||
48 | } | ||
49 | |||
50 | int i2c_sda(void) | ||
51 | { | ||
52 | return GPEDAT & (1 << 15); | ||
53 | } | ||
54 | |||
55 | void i2c_scl_output(void) | ||
56 | { | ||
57 | GPECON |= (1 << 28); | ||
58 | } | ||
59 | |||
60 | void i2c_scl_input(void) | ||
61 | { | ||
62 | GPECON &= ~(3 << 28); | ||
63 | } | ||
64 | |||
65 | void i2c_scl_lo(void) | ||
66 | { | ||
67 | GPEDAT &= ~(1 << 14); | ||
68 | } | ||
69 | |||
70 | int i2c_scl(void) | ||
71 | { | ||
72 | return GPEDAT & (1 << 14); | ||
73 | } | ||
74 | |||
75 | void i2c_scl_hi(void) | ||
76 | { | ||
77 | i2c_scl_input(); | ||
78 | while(!i2c_scl()); | ||
79 | GPEDAT |= (1 << 14); | ||
80 | i2c_scl_output(); | ||
81 | } | ||
82 | |||
83 | void i2c_delay(void) | ||
84 | { | ||
85 | do { int _x; for(_x=0;_x<2000;_x++);} while (0); | ||
86 | } | ||
87 | |||
88 | struct i2c_interface s3c2440_i2c = { | ||
89 | 0x34, /* Address */ | ||
90 | |||
91 | /* Bit-banged interface definitions */ | ||
92 | i2c_scl_hi, /* Drive SCL high, might sleep on clk stretch */ | ||
93 | i2c_scl_lo, /* Drive SCL low */ | ||
94 | i2c_sda_hi, /* Drive SDA high */ | ||
95 | i2c_sda_lo, /* Drive SDA low */ | ||
96 | i2c_sda_input, /* Set SDA as input */ | ||
97 | i2c_sda_output, /* Set SDA as output */ | ||
98 | i2c_scl_input, /* Set SCL as input */ | ||
99 | i2c_scl_output, /* Set SCL as output */ | ||
100 | i2c_scl, /* Read SCL, returns 0 or nonzero */ | ||
101 | i2c_sda, /* Read SDA, returns 0 or nonzero */ | ||
102 | |||
103 | i2c_delay, /* START SDA hold time (tHD:SDA) */ | ||
104 | i2c_delay, /* SDA hold time (tHD:DAT) */ | ||
105 | i2c_delay, /* SDA setup time (tSU:DAT) */ | ||
106 | i2c_delay, /* STOP setup time (tSU:STO) */ | ||
107 | i2c_delay, /* Rep. START setup time (tSU:STA) */ | ||
108 | i2c_delay, /* SCL high period (tHIGH) */ | ||
109 | }; | ||
110 | |||
111 | void i2c_init(void) | ||
112 | { | ||
113 | /* Set GPE15 (SDA) and GPE14 (SCL) to 1 */ | ||
114 | GPECON = (GPECON & ~(0xF<<28)) | 5<<28; | ||
115 | i2c_add_node(&s3c2440_i2c); | ||
116 | } | ||
117 | |||
118 | void i2c_send(int bus_address, int reg_address, const unsigned char buf) | ||
119 | { | ||
120 | i2c_write_data(bus_address, reg_address, &buf, 1); | ||
121 | } | ||