summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-11-12 10:59:38 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-11-12 10:59:38 +0100
commit96462e6b5be917a5146eaae62234432f1030898f (patch)
treeef95030da8e8768bacc8bf9d42427dfe247b0960
parent8d19dd775c642ebb5662d25f3a27d992ebdeb1ea (diff)
wat
-rw-r--r--src/arch/msp430fr5969lp/driver/i2c.cc13
-rw-r--r--src/driver/soft_i2c.cc8
2 files changed, 15 insertions, 6 deletions
diff --git a/src/arch/msp430fr5969lp/driver/i2c.cc b/src/arch/msp430fr5969lp/driver/i2c.cc
index f807d00..fe5b37b 100644
--- a/src/arch/msp430fr5969lp/driver/i2c.cc
+++ b/src/arch/msp430fr5969lp/driver/i2c.cc
@@ -8,16 +8,25 @@
volatile unsigned short old_ifg = 0;
+#if (F_CPU / F_I2C) < 45
+inline void await_i2c_int(unsigned int ie_flags, unsigned int ifg_flags) {
+ while (!(UCB0IFG & ifg_flags)) ;
+ if (UCB0IFG & (UCNACKIFG | UCCLTOIFG)) {
+ UCB0IFG &= ~(UCNACKIFG | UCCLTOIFG);
+ }
+}
+#else
inline void await_i2c_int(unsigned int ie_flags, unsigned int ifg_flags)
{
UCB0IFG = 0;
old_ifg = 0;
UCB0IE = ie_flags;
- while (!(old_ifg & ifg_flags)) {
+ do {
arch.idle();
- }
+ } while (!(old_ifg & ifg_flags));
UCB0IE = 0;
}
+#endif
signed char I2C::setup()
{
diff --git a/src/driver/soft_i2c.cc b/src/driver/soft_i2c.cc
index 6c36b6f..76042f2 100644
--- a/src/driver/soft_i2c.cc
+++ b/src/driver/soft_i2c.cc
@@ -20,10 +20,10 @@ volatile unsigned char timer_done = 0;
#define SCL_HIGH gpio.input(scl, 1)
#define SCL_LOW gpio.output(scl, 0)
#elif SOFTI2C_PULLUP_EXTERNAL
-#define SDA_HIGH do { gpio.input(sda); gpio.write(sda_pull, 1); } while (0)
-#define SDA_LOW do { gpio.write(sda_pull, 0); gpio.output(sda); } while (0)
-#define SCL_HIGH do { gpio.input(scl); gpio.write(scl_pull, 1); } while (0)
-#define SCL_LOW do { gpio.write(scl_pull, 0); gpio.output(scl); } while (0)
+#define SDA_HIGH { gpio.input(sda); gpio.write(sda_pull, 1); }
+#define SDA_LOW { gpio.write(sda_pull, 0); gpio.output(sda); }
+#define SCL_HIGH { gpio.input(scl); gpio.write(scl_pull, 1); }
+#define SCL_LOW { gpio.write(scl_pull, 0); gpio.output(scl); }
#else /* !SOFTI2C_PULLUP_{INTERNAL,EXTERNAL} */
#define SDA_HIGH gpio.input(sda)
#define SDA_LOW gpio.output(sda)