Skip to content

Commit b4bf6ff

Browse files
committed
chore(examples): switch examples to generic auto-resolved I3C bus
Signed-off-by: Aymane Bahssain <aymane.bahssain@st.com>
1 parent b8b8426 commit b4bf6ff

9 files changed

Lines changed: 35 additions & 51 deletions

File tree

libraries/I3C/examples/BasicBegin/BasicBegin.ino

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
#include <I3C.h>
22

3-
// Choose the bus instance available on your board.
4-
5-
#define I3C_BUS I3C1Bus
6-
73
void setup() {
84
Serial.begin(115200);
95
while (!Serial) {}
106

117
Serial.println("I3C Basic Begin");
128

13-
// Option 1: use default board I3C pins
14-
if (!I3C_BUS.begin(1000000)) {
9+
if (!I3C.begin(1000000)) {
1510
Serial.println("Failed to initialize I3C bus");
1611
while (1) {}
1712
}

libraries/I3C/examples/Controller_Target/ControllerWrite/ControllerWrite.ino

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "I3C.h"
22

3-
#define I3C_BUS I3C1Bus
43
static I3CDiscoveredDevice devices[8];
54

65
void printHex2(uint8_t v) {
@@ -15,13 +14,13 @@ void setup() {
1514

1615
Serial.println("=== Controller Write / Target Receive ===");
1716

18-
if (!I3C_BUS.begin(I3C_SDA, I3C_SCL, 1000000U)) {
17+
if (!I3C.begin(I3C_SDA, I3C_SCL, 1000000U)) {
1918
Serial.println("begin() failed");
2019
while (1) {}
2120
}
2221

2322
size_t found = 0;
24-
int rc = I3C_BUS.discover(devices, 8, &found);
23+
int rc = I3C.discover(devices, 8, &found);
2524

2625
if (rc != 0 || found == 0) {
2726
Serial.println("No target found");
@@ -43,7 +42,7 @@ void setup() {
4342
0x0D, 0x0E, 0x0F, 0x10
4443
};
4544

46-
int wr = I3C_BUS.write(da, tx, sizeof(tx), 1000);
45+
int wr = I3C.write(da, tx, sizeof(tx), 1000);
4746
Serial.print("write rc = ");
4847
Serial.println(wr);
4948
}

libraries/I3C/examples/Controller_Target/TargetReceive/TargetReceive.ino

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "I3C.h"
22

3-
#define I3C_BUS I3C1Bus
43
static uint8_t rxBuf[16];
54

65
void printHex2(uint8_t v) {
@@ -19,21 +18,21 @@ void setup() {
1918
cfg.identifier = 0x62;
2019
cfg.mipiIdentifier = 0x1;
2120

22-
if (!I3C_BUS.beginTarget(I3C_SDA, I3C_SCL, cfg)) {
21+
if (!I3C.beginTarget(I3C_SDA, I3C_SCL, cfg)) {
2322
Serial.println("beginTarget failed");
2423
while (1) {}
2524
}
2625

27-
while (!I3C_BUS.hasAddress()) {
26+
while (!I3C.hasAddress()) {
2827
delay(10);
2928
}
3029

3130
Serial.print("DA = 0x");
32-
Serial.println(I3C_BUS.address(), HEX);
31+
Serial.println(I3C.address(), HEX);
3332

34-
HAL_I3C_FlushAllFifo(I3C_BUS.halHandle());
33+
HAL_I3C_FlushAllFifo(I3C.halHandle());
3534

36-
int rc = I3C_BUS.receive(rxBuf, sizeof(rxBuf), 10000);
35+
int rc = I3C.receive(rxBuf, sizeof(rxBuf), 10000);
3736
Serial.print("receive rc = ");
3837
Serial.println(rc);
3938

libraries/I3C/examples/DeviceReady/DeviceReady.ino

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
#include <I3C.h>
22

3-
#define I3C_BUS I3C1Bus
4-
5-
63
void setup() {
74
Serial.begin(115200);
85
while (!Serial) {}
96

107
Serial.println("I3C Device Ready Example");
118

12-
if (!I3C_BUS.begin(1000000)) {
9+
if (!I3C.begin(1000000)) {
1310
Serial.println("Failed to initialize I3C bus");
1411
while (1) {}
1512
}
1613

1714
for (uint8_t addr = 1; addr < 0x7F; ++addr) {
1815

19-
bool i3cReady = I3C_BUS.isI3CDeviceReady(addr);
16+
bool i3cReady = I3C.isI3CDeviceReady(addr);
2017
if (i3cReady) {
2118
Serial.print("I3C device at DA 0x");
2219
Serial.print(addr, HEX);

libraries/I3C/examples/ScanBus/ScanBus.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ void setup() {
2121

2222
Serial.println("=== I3C ScanBus ===");
2323

24-
if (!I3C1Bus.begin(I3C_SDA, I3C_SCL, 1000000U)) {
24+
if (!I3C.begin(I3C_SDA, I3C_SCL, 1000000U)) {
2525
Serial.println("begin() failed");
2626
while (1) {}
2727
}
2828

2929
size_t found = 0;
3030

31-
int rc = I3C1Bus.discover(devices, 8, &found);
31+
int rc = I3C.discover(devices, 8, &found);
3232

3333
Serial.print("discover rc = ");
3434
Serial.println(rc);

libraries/I3C/examples/TargetIBI/Controller/Controller.ino

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "I3C.h"
22

3-
#define I3C_BUS I3C1Bus
43
static I3CDiscoveredDevice devices[8];
54
static volatile bool callbackSeen = false;
65

@@ -24,13 +23,13 @@ void setup() {
2423

2524
Serial.println("=== Controller IBI Example ===");
2625

27-
if (!I3C_BUS.begin(I3C_SDA, I3C_SCL, 1000000U)) {
26+
if (!I3C.begin(I3C_SDA, I3C_SCL, 1000000U)) {
2827
Serial.println("begin() failed");
2928
while (1) {}
3029
}
3130

3231
size_t found = 0;
33-
int rc = I3C_BUS.discover(devices, 8, &found);
32+
int rc = I3C.discover(devices, 8, &found);
3433

3534
if (rc != 0 || found == 0) {
3635
Serial.println("No target found");
@@ -39,29 +38,29 @@ void setup() {
3938

4039
uint8_t da = devices[0].dynAddr;
4140

42-
I3C_BUS.onIbi(myIbiCallback, (void *)&callbackSeen);
41+
I3C.onIbi(myIbiCallback, (void *)&callbackSeen);
4342

44-
rc = I3C_BUS.enableIbi(1, da, false, false, 1000);
43+
rc = I3C.enableIbi(1, da, false, false, 1000);
4544
Serial.print("enableIbi rc = ");
4645
Serial.println(rc);
4746

48-
rc = I3C_BUS.enableControllerEvents();
47+
rc = I3C.enableControllerEvents();
4948
Serial.print("enableControllerEvents rc = ");
5049
Serial.println(rc);
5150

5251
Serial.println("Waiting for IBI...");
5352
}
5453

5554
void loop() {
56-
if (I3C_BUS.hasIbi()) {
55+
if (I3C.hasIbi()) {
5756
I3CControllerIbiInfo ibi{};
58-
if (I3C_BUS.peekIbi(ibi)) {
57+
if (I3C.peekIbi(ibi)) {
5958
Serial.print("peekIbi source DA = 0x");
6059
printHex2(ibi.sourceDa);
6160
Serial.println();
6261
}
6362

64-
if (I3C_BUS.readIbi(ibi)) {
63+
if (I3C.readIbi(ibi)) {
6564
Serial.print("readIbi source DA = 0x");
6665
printHex2(ibi.sourceDa);
6766
Serial.println();

libraries/I3C/examples/TargetIBI/Target/Target.ino

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include "I3C.h"
22

3-
#define I3C_BUS I3C1Bus
4-
53
void setup() {
64
Serial.begin(115200);
75
while (!Serial) {}
@@ -15,21 +13,21 @@ void setup() {
1513
cfg.ibiRequest = true;
1614
cfg.ibiPayload = false;
1715

18-
if (!I3C_BUS.beginTarget(I3C_SDA, I3C_SCL, cfg)) {
16+
if (!I3C.beginTarget(I3C_SDA, I3C_SCL, cfg)) {
1917
Serial.println("beginTarget failed");
2018
while (1) {}
2119
}
2220

23-
while (!I3C_BUS.hasAddress()) {
21+
while (!I3C.hasAddress()) {
2422
delay(10);
2523
}
2624

2725
Serial.print("DA = 0x");
28-
Serial.println(I3C_BUS.address(), HEX);
26+
Serial.println(I3C.address(), HEX);
2927

3028
delay(2000);
3129

32-
int rc = I3C_BUS.sendIbi(nullptr, 0, 1000);
30+
int rc = I3C.sendIbi(nullptr, 0, 1000);
3331
Serial.print("sendIbi rc = ");
3432
Serial.println(rc);
3533
}

libraries/I3C/examples/TargetNotifications/Controller/Controller.ino

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "I3C.h"
22

3-
#define I3C_BUS I3C1Bus
43
static I3CDiscoveredDevice devices[8];
54

65
void printHex2(uint8_t v) {
@@ -15,13 +14,13 @@ void setup() {
1514

1615
Serial.println("=== Controller Trigger Target Events ===");
1716

18-
if (!I3C_BUS.begin(I3C_SDA, I3C_SCL, 1000000U)) {
17+
if (!I3C.begin(I3C_SDA, I3C_SCL, 1000000U)) {
1918
Serial.println("begin() failed");
2019
while (1) {}
2120
}
2221

2322
size_t found = 0;
24-
int rc = I3C_BUS.discover(devices, 8, &found);
23+
int rc = I3C.discover(devices, 8, &found);
2524

2625
if (rc != 0 || found == 0) {
2726
Serial.println("No target found");
@@ -36,13 +35,13 @@ void setup() {
3635

3736
delay(2000);
3837

39-
rc = I3C_BUS.setEvents(da, false, 0x01, 1000); // DISEC INTR
38+
rc = I3C.setEvents(da, false, 0x01, 1000); // DISEC INTR
4039
Serial.print("DISEC(INTR) rc = ");
4140
Serial.println(rc);
4241

4342
delay(5000);
4443

45-
rc = I3C_BUS.setEvents(da, true, 0x01, 1000); // ENEC INTR
44+
rc = I3C.setEvents(da, true, 0x01, 1000); // ENEC INTR
4645
Serial.print("ENEC(INTR) rc = ");
4746
Serial.println(rc);
4847
}

libraries/I3C/examples/TargetNotifications/Target/Target.ino

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include "I3C.h"
22

3-
#define I3C_BUS I3C1Bus
4-
53
void setup() {
64
Serial.begin(115200);
75
while (!Serial) {}
@@ -13,32 +11,32 @@ void setup() {
1311
cfg.identifier = 0x62;
1412
cfg.mipiIdentifier = 0x1;
1513

16-
if (!I3C_BUS.beginTarget(I3C_SDA, I3C_SCL, cfg)) {
14+
if (!I3C.beginTarget(I3C_SDA, I3C_SCL, cfg)) {
1715
Serial.println("beginTarget failed");
1816
while (1) {}
1917
}
2018

21-
while (!I3C_BUS.hasAddress()) {
19+
while (!I3C.hasAddress()) {
2220
delay(10);
2321
}
2422

2523
Serial.print("DA = 0x");
26-
Serial.println(I3C_BUS.address(), HEX);
24+
Serial.println(I3C.address(), HEX);
2725

28-
int rc = I3C_BUS.enableTargetEvents(nullptr, HAL_I3C_IT_INTUPDIE);
26+
int rc = I3C.enableTargetEvents(nullptr, HAL_I3C_IT_INTUPDIE);
2927
Serial.print("enableTargetEvents rc = ");
3028
Serial.println(rc);
3129
}
3230

3331
void loop() {
3432
uint32_t eventId = 0;
35-
if (I3C_BUS.readTargetEvent(eventId)) {
33+
if (I3C.readTargetEvent(eventId)) {
3634
Serial.print("Target event = 0x");
3735
Serial.println(eventId, HEX);
3836

3937
if ((eventId & EVENT_ID_ENEC_DISEC) != 0U) {
4038
I3C_CCCInfoTypeDef info{};
41-
if (HAL_I3C_GetCCCInfo(I3C_BUS.halHandle(), EVENT_ID_ENEC_DISEC, &info) == HAL_OK) {
39+
if (HAL_I3C_GetCCCInfo(I3C.halHandle(), EVENT_ID_ENEC_DISEC, &info) == HAL_OK) {
4240
Serial.print(" HotJoinAllowed = ");
4341
Serial.println(info.HotJoinAllowed ? "YES" : "NO");
4442

0 commit comments

Comments
 (0)