Skip to content

libraries: Wire: define WIRE_HOWMANY - #706

Open
KurtE wants to merge 1 commit into
arduino:mainfrom
KurtE:main
Open

KurtE wants to merge 1 commit into
arduino:mainfrom
KurtE:main

Conversation

@KurtE

@KurtE KurtE commented Oct 20, 2026

Copy link
Copy Markdown

There are times when a sketch wants to know how many Wire objects there are. Example wire scanner app.

In the MBED wire library this was defined as WIRE_HOWMANY

So simply defined it from DT_NODE_HAS_PROP(DT_PATH(zephyr_user), i2cs)

Here is an example sketch, that can make use of it. Note: I put more or less the same zephyr stuff in it, such
that it does it on it's own.
zephyr_wire_scanner-261020a.zip

@github-actions

Copy link
Copy Markdown

Built 1.0.1-0.pr.706.261020t1528z+ga894004c

CI run PASSED 🟢

ArtifactBoardCoreTestsRAMSketchesWarningsErrors
✅ zephyr_contrib ek_ra8d1 2 🏷️ ✅

12.0%

2--
frdm_mcxn947 7 🏷️ ✅

53.4%

2--
frdm_rw612 3 🏷️ ✅

74.6%

2--
✅* zephyr_main giga 10 🏷️ ✅*

45.9%

862-
nano33ble 5 🏷️ ✅

79.2%

44--
nano_connect 6 🏷️ ✅*

69.5%

388-
nano_matter 3 🏷️ ✅

⚠️ 86.5%

22--
nicla_sense 3 🏷️ ✅

⚠️ 89.0%

18--
nicla_vision 11 🏷️ ✅

40.4%

68--
opta 11 🏷️ ✅

42.3%

76--
portentac33 6 🏷️ ✅

⚠️ 100.0%

72--
portentah7 10 🏷️ ✅*

51.2%

1022-
✅ zephyr_unoq unoq 2 🏷️ ✅

43.5%

56--
ventunoq 5 🏷️ ✅

23.7%

48--
Legend

BoardTestStatus description
🔥 🔥 Test run failed to complete.
❌ 🔴 Test completed with unexpected errors.
⁉️ ⁉️ Test was expected to fail but passed; exception entry is outdated.
✔️* 🚫 Test completed with errors, but all are known/expected.
✅* 🟡 Test completed with some warnings; no errors detected.
✅ 🟢 Test passed successfully, with no warnings or errors.
🌑 🌑 Test was skipped.

@pennam pennam left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @KurtE, thanks for the contribution!

In addition to your changes, could we also remove the WIRE_HOWMANY definition in the nano_connect variant and add a fallback to arduino_i2c? This would keep it consistent with the approach used in Wire.cpp

diff --git a/libraries/Wire/Wire.h b/libraries/Wire/Wire.h
index 49ca362..ac8c331 100644
--- a/libraries/Wire/Wire.h
+++ b/libraries/Wire/Wire.h
@@ -93,4 +93,13 @@ DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), i2cs, DECLARE_EXTERN_WIRE_N)
 extern arduino::ZephyrI2C Wire;
 #endif
 
+/* Number of Wire instances, matching the instantiation logic in Wire.cpp */
+#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), i2cs)
+#define WIRE_HOWMANY DT_PROP_LEN(DT_PATH(zephyr_user), i2cs)
+#elif DT_NODE_EXISTS(DT_NODELABEL(arduino_i2c))
+#define WIRE_HOWMANY 1
+#else
+#define WIRE_HOWMANY 0
+#endif
+
 typedef arduino::ZephyrI2C TwoWire;
diff --git a/variants/arduino_nano_connect_rp2040/variant.h b/variants/arduino_nano_connect_rp2040/variant.h
index 66281ed..fd1614e 100644
--- a/variants/arduino_nano_connect_rp2040/variant.h
+++ b/variants/arduino_nano_connect_rp2040/variant.h
@@ -97,8 +97,6 @@ static const uint8_t SCK  = PIN_SPI_SCK;
 
 // Wire (I2C)
 // ----------
-#define WIRE_HOWMANY        (1)
-
 #define PIN_WIRE_SDA        (18u)
 #define PIN_WIRE_SCL        (19u)

There are times when a sketch wants to know how many Wire objects there are.  Example wire scanner app.

In the MBED wire library this was defined as WIRE_HOWMANY

So simply defined it from DT_NODE_HAS_PROP(DT_PATH(zephyr_user), i2cs)
@KurtE

KurtE commented Oct 21, 2026

Copy link
Copy Markdown
Author

Pushed up the changes...
I don't have the connect to test it, but compiled

@github-actions

Copy link
Copy Markdown

Built 1.1.0-rc1.pr.706.261021t1448z+g89548ac0

CI run FAILED: 🔥 giga, 🔥 nano_matter, 🔥 nicla_vision, 🔥 unoq, 🔥 ventunoq, 🔥 ek_ra8d1

ArtifactBoardCoreTestsRAMSketchesWarningsErrors
🔥 zephyr_contrib ek_ra8d1 🔥Core build failed!
frdm_mcxn947 7 🏷️ ✅

53.4%

2--
frdm_rw612 8 🏷️ ✅

73.4%

2--
🔥 zephyr_main giga 🔥Core build failed!
nano33ble 5 🏷️ ✅

79.2%

44--
nano_connect 6 🏷️ ✅

69.5%

38--
nano_matter 🔥Core build failed!
nicla_sense 3 🏷️ ✅

⚠️ 89.0%

18--
nicla_vision 🔥Core build failed!
opta 11 🏷️ ✅

42.3%

76--
portentac33 6 🏷️ ✅

⚠️ 100.0%

72--
portentah7 10 🏷️ ✅*

51.2%

1002-
🔥 zephyr_unoq unoq 🔥Core build failed!
ventunoq 🔥Core build failed!
Legend

BoardTestStatus description
🔥 🔥 Test run failed to complete.
❌ 🔴 Test completed with unexpected errors.
⁉️ ⁉️ Test was expected to fail but passed; exception entry is outdated.
✔️* 🚫 Test completed with errors, but all are known/expected.
✅* 🟡 Test completed with some warnings; no errors detected.
✅ 🟢 Test passed successfully, with no warnings or errors.
🌑 🌑 Test was skipped.

Caution

zephyr_contrib is blocked due to failures on ek_ra8d1!

Caution

zephyr_main is blocked due to failures on giga, nano_matter, nicla_vision!

Caution

zephyr_unoq is blocked due to failures on unoq, ventunoq!

@KurtE
KurtE requested a review from pennam October 21, 2026 15:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants