diff options
Diffstat (limited to 'firmware/drivers/i2c.c')
-rw-r--r-- | firmware/drivers/i2c.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/firmware/drivers/i2c.c b/firmware/drivers/i2c.c index 6530227ad7..24ad77495d 100644 --- a/firmware/drivers/i2c.c +++ b/firmware/drivers/i2c.c | |||
@@ -23,22 +23,23 @@ | |||
23 | #include "debug.h" | 23 | #include "debug.h" |
24 | #include "system.h" | 24 | #include "system.h" |
25 | 25 | ||
26 | #define PB13 0x2000 | 26 | /* |
27 | #define PB7 0x0080 | 27 | ** SDA is PB7 |
28 | #define PB5 0x0020 | 28 | ** SCL is PB13 |
29 | 29 | */ | |
30 | |||
30 | /* cute little functions, atomic read-modify-write */ | 31 | /* cute little functions, atomic read-modify-write */ |
31 | #define SDA_LO __clear_bit_constant(7, &PBDRL) | 32 | #define SDA_LO and_b(~0x80, &PBDRL) |
32 | #define SDA_HI __set_bit_constant(7, &PBDRL) | 33 | #define SDA_HI or_b(0x80, &PBDRL) |
33 | #define SDA_INPUT __clear_bit_constant(7, &PBIORL) | 34 | #define SDA_INPUT and_b(~0x80, &PBIORL) |
34 | #define SDA_OUTPUT __set_bit_constant(7, &PBIORL) | 35 | #define SDA_OUTPUT or_b(0x80, &PBIORL) |
35 | #define SDA (PBDR & PB7) | 36 | #define SDA (PBDR & 0x80) |
36 | 37 | ||
37 | #define SCL_INPUT __clear_bit_constant(13-8, &PBIORH) | 38 | #define SCL_INPUT and_b(~0x20, &PBIORH) |
38 | #define SCL_OUTPUT __set_bit_constant(13-8, &PBIORH) | 39 | #define SCL_OUTPUT or_b(0x20, &PBIORH) |
39 | #define SCL_LO __clear_bit_constant(13-8, &PBDRH) | 40 | #define SCL_LO and_b(~0x20, &PBDRH) |
40 | #define SCL_HI __set_bit_constant(13-8, &PBDRH) | 41 | #define SCL_HI or_b(0x20, &PBDRH) |
41 | #define SCL (PBDR & PB13) | 42 | #define SCL (PBDR & 0x2000) |
42 | 43 | ||
43 | /* arbitrary delay loop */ | 44 | /* arbitrary delay loop */ |
44 | #define DELAY do { int _x; for(_x=0;_x<20;_x++);} while (0) | 45 | #define DELAY do { int _x; for(_x=0;_x<20;_x++);} while (0) |
@@ -82,11 +83,11 @@ void i2c_init(void) | |||
82 | PBCR2 &= ~0xcc00; /* PB5 abd PB7 */ | 83 | PBCR2 &= ~0xcc00; /* PB5 abd PB7 */ |
83 | 84 | ||
84 | /* PB5 is "MAS enable". make it output and high */ | 85 | /* PB5 is "MAS enable". make it output and high */ |
85 | __set_bit_constant(5, &PBIORL); | 86 | or_b(0x20, &PBIORL); |
86 | __set_bit_constant(5, &PBDRL); | 87 | or_b(0x20, &PBDRL); |
87 | 88 | ||
88 | /* Set the clock line PB13 to an output */ | 89 | /* Set the clock line PB13 to an output */ |
89 | __set_bit_constant(13-8, &PBIORH); | 90 | or_b(0x20, &PBIORH); |
90 | 91 | ||
91 | SDA_OUTPUT; | 92 | SDA_OUTPUT; |
92 | SDA_HI; | 93 | SDA_HI; |