summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-04-10 11:09:57 +0200
committerDaniel Friesel <derf@finalrewind.org>2021-04-10 11:09:57 +0200
commite585d5246b7391d35a5dc4b1ce2f79a310570f5e (patch)
tree198056eb5108053d18606fb3ffe0986d5babaa7c
parentea1f28f59505579d90f0e51b1023c72f6fbb2ed8 (diff)
Allow software and hardware i2c to be used together (e.g. on different pins)
-rw-r--r--Makefile4
-rw-r--r--include/driver/soft_i2c.h2
-rw-r--r--src/app/i2cdetect/main.cc5
-rw-r--r--src/arch/arduino-nano/Kconfig2
-rw-r--r--src/arch/blinkenrocket/Kconfig2
-rw-r--r--src/arch/msp430fr5969lp/Kconfig2
-rw-r--r--src/arch/msp430fr5994lp/Kconfig2
-rw-r--r--src/driver/Kconfig2
-rw-r--r--src/driver/soft_i2c.cc4
9 files changed, 19 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 4f518ae..3a00779 100644
--- a/Makefile
+++ b/Makefile
@@ -273,6 +273,10 @@ ifdef CONFIG_driver_softi2c
COMMON_FLAGS += -DDRIVER_SOFTI2C
endif
+ifdef CONFIG_meta_driver_hardware_i2c
+ COMMON_FLAGS += -DDRIVER_HARDWARE_I2C
+endif
+
ifdef CONFIG_lib_inflate
CXX_TARGETS += src/lib/inflate.cc
endif
diff --git a/include/driver/soft_i2c.h b/include/driver/soft_i2c.h
index 05fbce6..b581a38 100644
--- a/include/driver/soft_i2c.h
+++ b/include/driver/soft_i2c.h
@@ -35,6 +35,8 @@ class SoftI2C {
unsigned char rx_len, unsigned char *rx_buf);
};
+#ifndef DRIVER_HARDWARE_I2C
extern SoftI2C i2c;
+#endif
#endif
diff --git a/src/app/i2cdetect/main.cc b/src/app/i2cdetect/main.cc
index fb6f54c..95a34bb 100644
--- a/src/app/i2cdetect/main.cc
+++ b/src/app/i2cdetect/main.cc
@@ -6,9 +6,10 @@
#include "arch.h"
#include "driver/gpio.h"
#include "driver/stdout.h"
-#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C)
+#ifdef DRIVER_HARDWARE_I2C
#include "driver/i2c.h"
-#else
+#endif
+#ifdef DRIVER_SOFTI2C
#include "driver/soft_i2c.h"
#endif
diff --git a/src/arch/arduino-nano/Kconfig b/src/arch/arduino-nano/Kconfig
index ab25a8f..ce9a987 100644
--- a/src/arch/arduino-nano/Kconfig
+++ b/src/arch/arduino-nano/Kconfig
@@ -16,7 +16,7 @@ select meta_driver_adc
config arch_arduino_nano_driver_i2c
bool "I2C"
-depends on !driver_softi2c
+select meta_driver_hardware_i2c
select meta_driver_i2c
config arch_arduino_nano_driver_neopixel
diff --git a/src/arch/blinkenrocket/Kconfig b/src/arch/blinkenrocket/Kconfig
index ead54f9..c9b04a5 100644
--- a/src/arch/blinkenrocket/Kconfig
+++ b/src/arch/blinkenrocket/Kconfig
@@ -3,7 +3,7 @@
# SPDX-License-Identifier: CC0-1.0
config arch_blinkenrocket_driver_i2c
bool "I2C"
-depends on !driver_softi2c
+select meta_driver_hardware_i2c
select meta_driver_i2c
config arch_blinkenrocket_driver_uptime
diff --git a/src/arch/msp430fr5969lp/Kconfig b/src/arch/msp430fr5969lp/Kconfig
index 70fb3e4..80d74e4 100644
--- a/src/arch/msp430fr5969lp/Kconfig
+++ b/src/arch/msp430fr5969lp/Kconfig
@@ -11,7 +11,7 @@ select meta_driver_counter
config arch_msp430fr5969lp_driver_i2c
bool "I2C on eUSCI_B0"
-depends on !driver_softi2c
+select meta_driver_hardware_i2c
select meta_driver_i2c
## broken
diff --git a/src/arch/msp430fr5994lp/Kconfig b/src/arch/msp430fr5994lp/Kconfig
index abbfcab..0c97499 100644
--- a/src/arch/msp430fr5994lp/Kconfig
+++ b/src/arch/msp430fr5994lp/Kconfig
@@ -11,7 +11,7 @@ select meta_driver_counter
config arch_msp430fr5994lp_driver_i2c
bool "I2C on eUSCI_B1"
-depends on !driver_softi2c
+select meta_driver_hardware_i2c
select meta_driver_i2c
## broken
diff --git a/src/driver/Kconfig b/src/driver/Kconfig
index dbf70e0..0b1b98b 100644
--- a/src/driver/Kconfig
+++ b/src/driver/Kconfig
@@ -6,6 +6,8 @@ config meta_driver_adc
bool
config meta_driver_counter
bool
+config meta_driver_hardware_i2c
+bool
config meta_driver_i2c
bool
config meta_driver_neopixel
diff --git a/src/driver/soft_i2c.cc b/src/driver/soft_i2c.cc
index 975fa2e..8b87e93 100644
--- a/src/driver/soft_i2c.cc
+++ b/src/driver/soft_i2c.cc
@@ -235,6 +235,8 @@ ON_TIMER_INTERRUPT_head
ON_TIMER_INTERRUPT_tail
#endif
+#ifndef DRIVER_HARDWARE_I2C
+
#if SOFTI2C_PULLUP_EXTERNAL
#ifdef MULTIPASS_ARCH_msp430fr5969lp
SoftI2C i2c(GPIO::p1_6, GPIO::p1_7, GPIO::p1_4, GPIO::p1_5);
@@ -258,3 +260,5 @@ SoftI2C i2c(GPIO::p5_0, GPIO::p5_1);
SoftI2C i2c(GPIO::px00, GPIO::px01);
#endif /* MULTIPASS_ARCH_* */
#endif /* !SOFTI2C_PULLUP_EXTERNAL */
+
+#endif /* !DRIVER_HARDWARE_I2C */