Skip to content

Commit 83c6c0a

Browse files
committed
libraries: Wire: Instantiate Wire following dts configuration
Instaintiate Wire with i2c device that defined in 'i2cs' array under zephyr,user node. If 'i2cs' array is not defined, tries to instantiate with i2c device that labeled as 'arduino_i2c'. As a result of apply new rule, the i2c_dev that declared in pinmap.h is no more used, remove it. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
1 parent d455500 commit 83c6c0a

File tree

11 files changed

+14
-12
lines changed

11 files changed

+14
-12
lines changed

libraries/Wire/Wire.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,9 @@ void arduino::ZephyrI2C::flush() {}
104104
void arduino::ZephyrI2C::onReceive(voidFuncPtrParamInt cb) {}
105105
void arduino::ZephyrI2C::onRequest(voidFuncPtr cb) {}
106106

107-
arduino::ZephyrI2C Wire(i2c_dev);
107+
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), i2cs) && (DT_PROP_LEN(DT_PATH(zephyr_user), i2cs) > 0)
108+
arduino::ZephyrI2C Wire(DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), i2cs, 0)));
109+
/* If i2cs node is not defined, tries to use arduino_i2c */
110+
#elif DT_NODE_EXISTS(DT_NODELABEL(arduino_i2c))
111+
arduino::ZephyrI2C Wire(DEVICE_DT_GET(DT_NODELABEL(arduino_i2c)));
112+
#endif

libraries/Wire/Wire.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class ZephyrI2C : public HardwareI2C {
5757

5858
} // namespace arduino
5959

60+
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), i2cs) && \
61+
(DT_PROP_LEN(DT_PATH(zephyr_user), i2cs) > 0) || \
62+
DT_NODE_EXISTS(DT_NODELABEL(arduino_i2c))
6063
extern arduino::ZephyrI2C Wire;
64+
#endif
6165

6266
typedef arduino::ZephyrI2C TwoWire;

variants/arduino_mkrzero/arduino_mkrzero.overlay

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
io-channel-pins = <15 16 17 18 19 20 21>;
4646

4747
serials = <&sercom5>;
48+
i2cs = <&sercom0>;
4849
};
4950
};
5051

variants/arduino_mkrzero/arduino_mkrzero_pinmap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@
1010
#include <zephyr/drivers/i2c.h>
1111

1212
#define LED_BUILTIN 22
13-
14-
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(sercom0));

variants/arduino_nano_33_ble/arduino_nano_33_ble.overlay

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

4545
serials = <&uart0>;
46+
i2cs = <&arduino_nano_i2c>;
4647
};
4748
};
4849

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
@@ -12,5 +12,3 @@
1212
#include <zephyr/device.h>
1313

1414
#define LED_BUILTIN 13
15-
16-
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
io-channel-pins = <14 15 16 17 18 19 20 21>;
4444

4545
serials = <&uart0>;
46+
i2cs = <&arduino_nano_i2c>;
4647
};
4748
};
4849

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
@@ -12,5 +12,3 @@
1212
#include <zephyr/device.h>
1313

1414
#define LED_BUILTIN 13
15-
16-
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));

variants/arduino_nano_33_iot/arduino_nano_33_iot.overlay

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
io-channel-pins = <14 15 16 17 18 19 20 21>;
4646

4747
serials = <&sercom5>;
48+
i2cs = <&arduino_nano_i2c>;
4849
};
4950
};
5051

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
@@ -12,6 +12,3 @@
1212
#include <zephyr/device.h>
1313

1414
#define LED_BUILTIN 13
15-
16-
const static struct device *i2c_dev =
17-
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
@@ -13,6 +13,4 @@
1313

1414
#define LED_BUILTIN 22
1515

16-
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(arduino_i2c));
17-
1816
#endif

0 commit comments

Comments
 (0)