Skip to content

Commit c2fbc64

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 b051e56 commit c2fbc64

File tree

11 files changed

+18
-12
lines changed

11 files changed

+18
-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: 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 = <15 16 17 18 19 20 21>;
46+
47+
i2cs = <&sercom0>;
4648
};
4749
};
4850

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
<&adc 4>,
4242
<&adc 1>;
4343
io-channel-pins = <14 15 16 17 18 19 20 21>;
44+
45+
i2cs = <&arduino_nano_i2c>;
4446
};
4547
};
4648

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
<&adc 4>,
4242
<&adc 1>;
4343
io-channel-pins = <14 15 16 17 18 19 20 21>;
44+
45+
i2cs = <&arduino_nano_i2c>;
4446
};
4547
};
4648

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: 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
@@ -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)