Skip to content

Commit 62d1863

Browse files
committed
x
1 parent e4be5a6 commit 62d1863

File tree

11 files changed

+34
-13
lines changed

11 files changed

+34
-13
lines changed

libraries/Wire/Wire.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,15 @@ void arduino::ZephyrI2C::flush() {}
101101
void arduino::ZephyrI2C::onReceive(voidFuncPtrParamInt cb) {}
102102
void arduino::ZephyrI2C::onRequest(voidFuncPtr cb) {}
103103

104-
arduino::ZephyrI2C Wire;
104+
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), i2cs) && (DT_PROP_LEN(DT_PATH(zephyr_user), i2cs) > 0)
105+
arduino::ZephyrI2C Wire(DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), i2cs, 0)));
106+
#elif DT_NODE_EXISTS(DT_NODELABEL(arduino_i2c))
107+
arduino::ZephyrI2C Wire(DEVICE_DT_GET(DT_NODELABEL(arduino_i2c)));
108+
#endif
109+
110+
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), i2cs) && (DT_PROP_LEN(DT_PATH(zephyr_user), i2cs) > 1)
111+
#define HOGE(n, p, i) \
112+
const struct device* i2c_dev ## i = DEVICE_DT_GET(DT_PHANDLE_BY_IDX(n, p, i)); \
113+
arduino::ZephyrI2C Wire ## i(i2c_dev ## i);
114+
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), i2cs, HOGE)
115+
#endif

libraries/Wire/Wire.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class ZephyrI2C : public HardwareI2C {
4141
virtual void flush();
4242
virtual int available();
4343

44+
ZephyrI2C(const struct device* i2c) : i2c_dev(i2c) { }
45+
4446
private:
4547
int _address;
4648
uint8_t txBuffer[256];
@@ -50,10 +52,21 @@ class ZephyrI2C : public HardwareI2C {
5052
uint8_t buffer[256];
5153
};
5254
struct rx_ring_buf rxRingBuffer;
55+
const struct device* i2c_dev;
5356
};
5457

5558
} // namespace arduino
5659

60+
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), i2cs) && (DT_PROP_LEN(DT_PATH(zephyr_user), i2cs) > 0) \
61+
|| DT_NODE_EXISTS(DT_NODELABEL(arduino_i2c))
5762
extern arduino::ZephyrI2C Wire;
63+
#endif
64+
65+
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), i2cs) && (DT_PROP_LEN(DT_PATH(zephyr_user), i2cs) > 1)
66+
#define FUGA(n, p, i) \
67+
extern const struct device* i2c_dev ## i; extern arduino::ZephyrI2C Wire ## i;
68+
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), i2cs, FUGA)
69+
#endif
70+
5871

59-
typedef arduino::ZephyrI2C TwoWire;
72+
typedef arduino::ZephyrI2C TwoWire;

variants/arduino_mkrzero/arduino_mkrzero.overlay

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
<&adc 6>,
4545
<&adc 7>;
4646
io-channel-pins = <15 16 17 18 19 20 21>;
47+
48+
i2cs = <&sercom0>;
4749
};
4850
};
4951

variants/arduino_mkrzero/arduino_mkrzero_pinmap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,3 @@
88
#include <zephyr/drivers/gpio.h>
99
#include <zephyr/kernel.h>
1010
#include <zephyr/drivers/i2c.h>
11-
12-
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(sercom0));

variants/arduino_nano_33_ble/arduino_nano_33_ble.overlay

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
io-channel-pins = <14 15 16 17 18 19 20 21>;
4444

4545
builtin-led-gpios = <&arduino_nano_header 13 0>;
46+
47+
i2cs = <&arduino_nano_i2c>, <&i2c1>;
4648
};
4749
};
4850

variants/arduino_nano_33_ble/arduino_nano_33_ble_pinmap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@
1010
#include <zephyr/kernel.h>
1111
#include <zephyr/drivers/i2c.h>
1212
#include <zephyr/device.h>
13-
14-
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));

variants/arduino_nano_33_ble_sense/arduino_nano_33_ble_sense.overlay

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
io-channel-pins = <14 15 16 17 18 19 20 21>;
4444

4545
builtin-led-gpios = <&arduino_nano_header 13 0>;
46+
47+
i2cs = <&arduino_nano_i2c>;
4648
};
4749
};
4850

variants/arduino_nano_33_ble_sense/arduino_nano_33_ble_sense_pinmap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@
1010
#include <zephyr/kernel.h>
1111
#include <zephyr/drivers/i2c.h>
1212
#include <zephyr/device.h>
13-
14-
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));

variants/arduino_nano_33_iot/arduino_nano_33_iot.overlay

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
<&adc 6>,
4444
<&adc 7>;
4545
io-channel-pins = <14 15 16 17 18 19 20 21>;
46+
47+
i2cs = <&arduino_nano_i2c>;
4648
};
4749
};
4850

variants/arduino_nano_33_iot/arduino_nano_33_iot_pinmap.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,3 @@
1010
#include <zephyr/kernel.h>
1111
#include <zephyr/drivers/i2c.h>
1212
#include <zephyr/device.h>
13-
14-
const static struct device *i2c_dev =
15-
DEVICE_DT_GET(DT_NODELABEL(arduino_nano_i2c));

variants/nrf52840dk_nrf52840/nrf52840dk_nrf52840_pinmap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@
1111
#include <zephyr/drivers/i2c.h>
1212
#include <zephyr/kernel.h>
1313

14-
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(arduino_i2c));
15-
1614
#endif

0 commit comments

Comments
 (0)