aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2023-10-12 10:44:27 +0000
committerGitHub <[email protected]>2023-10-12 10:44:27 +0000
commit01eb1a73396002bf0a335f51d31328d21b32bb02 (patch)
tree910a705a484f59bd385fc58ecd1038889b8131eb
parenteb368f77a46682f76dcc4d75f9ba4ce80dfb4193 (diff)
parentf0d6ee69bcac6a22213c06f303176daf9f5445ff (diff)
Merge pull request #2033 from andresovela/stm32-add-timeout-to-i2c
stm32: add timeout to I2C driver
-rwxr-xr-xci.sh106
-rwxr-xr-xci_stable.sh61
-rw-r--r--embassy-stm32/src/i2c/mod.rs5
-rw-r--r--embassy-stm32/src/i2c/timeout.rs209
-rw-r--r--embassy-stm32/src/i2c/v2.rs203
-rw-r--r--examples/stm32f4/src/bin/i2c.rs9
-rw-r--r--examples/stm32h5/src/bin/i2c.rs9
-rw-r--r--examples/stm32h7/src/bin/i2c.rs9
8 files changed, 259 insertions, 352 deletions
diff --git a/ci.sh b/ci.sh
index 332222982..c246e6a98 100755
--- a/ci.sh
+++ b/ci.sh
@@ -69,62 +69,68 @@ cargo batch \
69 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly \ 69 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly \
70 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly,intrinsics \ 70 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly,intrinsics \
71 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly,qspi-as-gpio \ 71 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly,qspi-as-gpio \
72 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time-driver-any,unstable-traits \ 72 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time-driver-any,unstable-traits,time \
73 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time-driver-any \ 73 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time-driver-any,time \
74 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,time-driver-any \ 74 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,time-driver-any,time \
75 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,time-driver-any,unstable-traits \ 75 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,time-driver-any,unstable-traits,time \
76 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti \ 76 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,time \
77 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,unstable-traits \ 77 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti,unstable-traits,time \
78 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt \ 78 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,time \
79 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,exti,time-driver-any,unstable-traits \ 79 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,exti,time-driver-any,unstable-traits,time \
80 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,exti,time-driver-any \ 80 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,exti,time-driver-any,time \
81 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,time-driver-any \ 81 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,time-driver-any,time \
82 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,time-driver-any,unstable-traits \ 82 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,time-driver-any,unstable-traits,time \
83 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,exti,time \
84 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,exti,unstable-traits,time \
85 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,time \
83 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,exti \ 86 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,exti \
84 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,exti,unstable-traits \ 87 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt,exti,unstable-traits \
85 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt \ 88 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,nightly,defmt \
86 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f401ve,defmt,exti,time-driver-any,unstable-traits \ 89 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f401ve,defmt,exti,time-driver-any,unstable-traits \
87 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f405zg,defmt,exti,time-driver-any,unstable-traits \ 90 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f405zg,defmt,exti,time-driver-any,unstable-traits \
88 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f407zg,defmt,exti,time-driver-any,unstable-traits \ 91 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f407zg,defmt,exti,time-driver-any,unstable-traits \
89 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f410tb,defmt,exti,time-driver-any,unstable-traits \ 92 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f401ve,defmt,exti,time-driver-any,unstable-traits,time \
90 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f411ce,defmt,exti,time-driver-any,unstable-traits \ 93 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f405zg,defmt,exti,time-driver-any,unstable-traits,time \
91 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f412zg,defmt,exti,time-driver-any,unstable-traits \ 94 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f407zg,defmt,exti,time-driver-any,unstable-traits,time \
92 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f413vh,defmt,exti,time-driver-any,unstable-traits \ 95 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f410tb,defmt,exti,time-driver-any,unstable-traits,time \
93 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f415zg,defmt,exti,time-driver-any,unstable-traits \ 96 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f411ce,defmt,exti,time-driver-any,unstable-traits,time \
94 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f417zg,defmt,exti,time-driver-any,unstable-traits \ 97 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f412zg,defmt,exti,time-driver-any,unstable-traits,time \
95 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f423zh,defmt,exti,time-driver-any,unstable-traits \ 98 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f413vh,defmt,exti,time-driver-any,unstable-traits,time \
96 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f427zi,defmt,exti,time-driver-any,unstable-traits \ 99 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f415zg,defmt,exti,time-driver-any,unstable-traits,time \
97 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f429zi,log,exti,time-driver-any,unstable-traits,embedded-sdmmc \ 100 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f417zg,defmt,exti,time-driver-any,unstable-traits,time \
98 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f437zi,log,exti,time-driver-any,unstable-traits \ 101 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f423zh,defmt,exti,time-driver-any,unstable-traits,time \
99 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f439zi,defmt,exti,time-driver-any,unstable-traits \ 102 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f427zi,defmt,exti,time-driver-any,unstable-traits,time \
100 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f446ze,defmt,exti,time-driver-any,unstable-traits \ 103 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f429zi,log,exti,time-driver-any,unstable-traits,embedded-sdmmc,time \
101 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f469zi,defmt,exti,time-driver-any,unstable-traits \ 104 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f437zi,log,exti,time-driver-any,unstable-traits,time \
102 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f479zi,defmt,exti,time-driver-any,unstable-traits,embedded-sdmmc \ 105 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f439zi,defmt,exti,time-driver-any,unstable-traits,time \
103 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f730i8,defmt,exti,time-driver-any,unstable-traits \ 106 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f446ze,defmt,exti,time-driver-any,unstable-traits,time \
104 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h753zi,defmt,exti,time-driver-any,unstable-traits \ 107 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f469zi,defmt,exti,time-driver-any,unstable-traits,time \
105 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h735zg,defmt,exti,time-driver-any,unstable-traits \ 108 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f479zi,defmt,exti,time-driver-any,unstable-traits,embedded-sdmmc,time \
106 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h755zi-cm7,defmt,exti,time-driver-any,unstable-traits \ 109 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f730i8,defmt,exti,time-driver-any,unstable-traits,time \
107 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h7b3ai,defmt,exti,time-driver-any,unstable-traits \ 110 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h753zi,defmt,exti,time-driver-any,unstable-traits,time \
108 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32l476vg,defmt,exti,time-driver-any,unstable-traits \ 111 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h735zg,defmt,exti,time-driver-any,unstable-traits,time \
109 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32l422cb,defmt,exti,time-driver-any,unstable-traits \ 112 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h755zi-cm7,defmt,exti,time-driver-any,unstable-traits,time \
110 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wb15cc,defmt,exti,time-driver-any,unstable-traits \ 113 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h7b3ai,defmt,exti,time-driver-any,unstable-traits,time \
111 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l072cz,defmt,exti,time-driver-any,unstable-traits \ 114 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32l476vg,defmt,exti,time-driver-any,unstable-traits,time \
112 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l041f6,defmt,exti,time-driver-any,unstable-traits \ 115 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32l422cb,defmt,exti,time-driver-any,unstable-traits,time \
113 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l073cz,defmt,exti,time-driver-any,unstable-traits,low-power \ 116 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wb15cc,defmt,exti,time-driver-any,unstable-traits,time \
114 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32l151cb-a,defmt,exti,time-driver-any,unstable-traits \ 117 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l072cz,defmt,exti,time-driver-any,unstable-traits,time \
115 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f398ve,defmt,exti,time-driver-any,unstable-traits \ 118 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l041f6,defmt,exti,time-driver-any,unstable-traits,time \
116 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f378cc,defmt,exti,time-driver-any,unstable-traits \ 119 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32l073cz,defmt,exti,time-driver-any,unstable-traits,low-power,time \
117 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32g0c1ve,defmt,exti,time-driver-any,unstable-traits \ 120 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32l151cb-a,defmt,exti,time-driver-any,unstable-traits,time \
118 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f217zg,defmt,exti,time-driver-any,unstable-traits \ 121 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f398ve,defmt,exti,time-driver-any,unstable-traits,time \
119 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features nightly,stm32l552ze,defmt,exti,time-driver-any,unstable-traits \ 122 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f378cc,defmt,exti,time-driver-any,unstable-traits,time \
120 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32wl54jc-cm0p,defmt,exti,time-driver-any,unstable-traits \ 123 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32g0c1ve,defmt,exti,time-driver-any,unstable-traits,time \
121 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wle5jb,defmt,exti,time-driver-any,unstable-traits \ 124 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f217zg,defmt,exti,time-driver-any,unstable-traits,time \
122 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32g474pe,defmt,exti,time-driver-any,unstable-traits \ 125 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features nightly,stm32l552ze,defmt,exti,time-driver-any,unstable-traits,time \
123 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f107vc,defmt,exti,time-driver-any,unstable-traits \ 126 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features nightly,stm32wl54jc-cm0p,defmt,exti,time-driver-any,unstable-traits,time \
124 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f103re,defmt,exti,time-driver-any,unstable-traits \ 127 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32wle5jb,defmt,exti,time-driver-any,unstable-traits,time \
125 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f100c4,defmt,exti,time-driver-any,unstable-traits \ 128 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32g474pe,defmt,exti,time-driver-any,unstable-traits,time \
126 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32h503rb,defmt,exti,time-driver-any,unstable-traits \ 129 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f107vc,defmt,exti,time-driver-any,unstable-traits,time \
127 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32h562ag,defmt,exti,time-driver-any,unstable-traits \ 130 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f103re,defmt,exti,time-driver-any,unstable-traits,time \
131 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32f100c4,defmt,exti,time-driver-any,unstable-traits,time \
132 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32h503rb,defmt,exti,time-driver-any,unstable-traits,time \
133 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features nightly,stm32h562ag,defmt,exti,time-driver-any,unstable-traits,time \
128 --- build --release --manifest-path cyw43/Cargo.toml --target thumbv6m-none-eabi --features ''\ 134 --- build --release --manifest-path cyw43/Cargo.toml --target thumbv6m-none-eabi --features ''\
129 --- build --release --manifest-path cyw43/Cargo.toml --target thumbv6m-none-eabi --features 'log' \ 135 --- build --release --manifest-path cyw43/Cargo.toml --target thumbv6m-none-eabi --features 'log' \
130 --- build --release --manifest-path cyw43/Cargo.toml --target thumbv6m-none-eabi --features 'defmt' \ 136 --- build --release --manifest-path cyw43/Cargo.toml --target thumbv6m-none-eabi --features 'defmt' \
diff --git a/ci_stable.sh b/ci_stable.sh
index 4ee5f4106..1fe4e3a1e 100755
--- a/ci_stable.sh
+++ b/ci_stable.sh
@@ -40,33 +40,38 @@ cargo batch \
40 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32u585zi,defmt,exti,time-driver-any,unstable-traits \ 40 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32u585zi,defmt,exti,time-driver-any,unstable-traits \
41 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wb55vy,defmt,exti,time-driver-any,unstable-traits \ 41 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wb55vy,defmt,exti,time-driver-any,unstable-traits \
42 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wl55cc-cm4,defmt,exti,time-driver-any,unstable-traits \ 42 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wl55cc-cm4,defmt,exti,time-driver-any,unstable-traits \
43 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l4r9zi,defmt,exti,time-driver-any,unstable-traits \ 43 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g473cc,defmt,exti,time-driver-any,unstable-traits,time \
44 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f303vc,defmt,exti,time-driver-any,unstable-traits \ 44 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32g491re,defmt,exti,time-driver-any,unstable-traits,time \
45 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any \ 45 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32u585zi,defmt,exti,time-driver-any,unstable-traits,time \
46 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any,unstable-traits \ 46 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wb55vy,defmt,exti,time-driver-any,unstable-traits,time \
47 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any \ 47 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32wl55cc-cm4,defmt,exti,time-driver-any,unstable-traits,time \
48 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any,unstable-traits \ 48 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l4r9zi,defmt,exti,time-driver-any,unstable-traits,time \
49 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any \ 49 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f303vc,defmt,exti,time-driver-any,unstable-traits,time \
50 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any,unstable-traits \ 50 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any,time \
51 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any \ 51 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f411ce,defmt,time-driver-any,unstable-traits,time \
52 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any,unstable-traits \ 52 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any,time \
53 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any \ 53 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,time-driver-any,unstable-traits,time \
54 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any,unstable-traits \ 54 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any,time \
55 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any \ 55 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,time-driver-any,unstable-traits,time \
56 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any,unstable-traits \ 56 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any,time \
57 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any \ 57 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,time-driver-any,unstable-traits,time \
58 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any,unstable-traits \ 58 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any,time \
59 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any \ 59 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,time-driver-any,unstable-traits,time \
60 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,unstable-traits \ 60 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any,time \
61 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any \ 61 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,time-driver-any,unstable-traits,time \
62 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any,unstable-traits \ 62 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any,time \
63 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any \ 63 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f410tb,defmt,exti,time-driver-any,unstable-traits,time \
64 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any,unstable-traits \ 64 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,time \
65 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any \ 65 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi,log,exti,time-driver-any,unstable-traits,time \
66 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any,unstable-traits \ 66 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any,time \
67 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any \ 67 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32h755zi-cm7,defmt,exti,time-driver-any,unstable-traits,time \
68 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,unstable-traits \ 68 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any,time \
69 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any \ 69 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32l476vg,defmt,exti,time-driver-any,unstable-traits,time \
70 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,unstable-traits \ 70 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any,time \
71 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv6m-none-eabi --features stm32l072cz,defmt,exti,time-driver-any,unstable-traits,time \
72 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,time \
73 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32l151cb-a,defmt,exti,time-driver-any,unstable-traits,time \
74 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,time \
75 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f217zg,defmt,exti,time-driver-any,unstable-traits,time \
71 --- build --release --manifest-path examples/nrf52840/Cargo.toml --target thumbv7em-none-eabi --no-default-features --out-dir out/examples/nrf52840 --bin raw_spawn \ 76 --- build --release --manifest-path examples/nrf52840/Cargo.toml --target thumbv7em-none-eabi --no-default-features --out-dir out/examples/nrf52840 --bin raw_spawn \
72 --- build --release --manifest-path examples/stm32l0/Cargo.toml --target thumbv6m-none-eabi --no-default-features --out-dir out/examples/stm32l0 --bin raw_spawn \ 77 --- build --release --manifest-path examples/stm32l0/Cargo.toml --target thumbv6m-none-eabi --no-default-features --out-dir out/examples/stm32l0 --bin raw_spawn \
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs
index 62d13e909..dde1a5040 100644
--- a/embassy-stm32/src/i2c/mod.rs
+++ b/embassy-stm32/src/i2c/mod.rs
@@ -7,11 +7,6 @@ use crate::interrupt;
7mod _version; 7mod _version;
8pub use _version::*; 8pub use _version::*;
9 9
10#[cfg(feature = "time")]
11mod timeout;
12#[cfg(feature = "time")]
13pub use timeout::*;
14
15use crate::peripherals; 10use crate::peripherals;
16 11
17#[derive(Debug, PartialEq, Eq)] 12#[derive(Debug, PartialEq, Eq)]
diff --git a/embassy-stm32/src/i2c/timeout.rs b/embassy-stm32/src/i2c/timeout.rs
deleted file mode 100644
index 103017cd1..000000000
--- a/embassy-stm32/src/i2c/timeout.rs
+++ /dev/null
@@ -1,209 +0,0 @@
1use embassy_time::{Duration, Instant};
2
3use super::{Error, I2c, Instance};
4
5/// An I2C wrapper, which provides `embassy-time` based timeouts for all `embedded-hal` trait methods.
6///
7/// This is useful for recovering from a shorted bus or a device stuck in a clock stretching state.
8/// A regular [I2c] would freeze until condition is removed.
9pub struct TimeoutI2c<'a, 'd: 'a, T: Instance, TXDMA, RXDMA> {
10 i2c: &'a mut I2c<'d, T, TXDMA, RXDMA>,
11 timeout: Duration,
12}
13
14fn timeout_fn(timeout: Duration) -> impl Fn() -> Result<(), Error> {
15 let deadline = Instant::now() + timeout;
16 move || {
17 if Instant::now() > deadline {
18 Err(Error::Timeout)
19 } else {
20 Ok(())
21 }
22 }
23}
24
25impl<'a, 'd: 'a, T: Instance, TXDMA, RXDMA> TimeoutI2c<'a, 'd, T, TXDMA, RXDMA> {
26 pub fn new(i2c: &'a mut I2c<'d, T, TXDMA, RXDMA>, timeout: Duration) -> Self {
27 Self { i2c, timeout }
28 }
29
30 // =========================
31 // Async public API
32
33 #[cfg(i2c_v2)]
34 pub async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Error>
35 where
36 TXDMA: crate::i2c::TxDma<T>,
37 {
38 self.write_timeout(address, write, self.timeout).await
39 }
40
41 #[cfg(i2c_v2)]
42 pub async fn write_timeout(&mut self, address: u8, write: &[u8], timeout: Duration) -> Result<(), Error>
43 where
44 TXDMA: crate::i2c::TxDma<T>,
45 {
46 self.i2c.write_timeout(address, write, timeout_fn(timeout)).await
47 }
48
49 #[cfg(i2c_v2)]
50 pub async fn write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error>
51 where
52 TXDMA: crate::i2c::TxDma<T>,
53 {
54 self.write_vectored_timeout(address, write, self.timeout).await
55 }
56
57 #[cfg(i2c_v2)]
58 pub async fn write_vectored_timeout(&mut self, address: u8, write: &[&[u8]], timeout: Duration) -> Result<(), Error>
59 where
60 TXDMA: crate::i2c::TxDma<T>,
61 {
62 self.i2c
63 .write_vectored_timeout(address, write, timeout_fn(timeout))
64 .await
65 }
66
67 #[cfg(i2c_v2)]
68 pub async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error>
69 where
70 RXDMA: crate::i2c::RxDma<T>,
71 {
72 self.read_timeout(address, buffer, self.timeout).await
73 }
74
75 #[cfg(i2c_v2)]
76 pub async fn read_timeout(&mut self, address: u8, buffer: &mut [u8], timeout: Duration) -> Result<(), Error>
77 where
78 RXDMA: crate::i2c::RxDma<T>,
79 {
80 self.i2c.read_timeout(address, buffer, timeout_fn(timeout)).await
81 }
82
83 #[cfg(i2c_v2)]
84 pub async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error>
85 where
86 TXDMA: super::TxDma<T>,
87 RXDMA: super::RxDma<T>,
88 {
89 self.write_read_timeout(address, write, read, self.timeout).await
90 }
91
92 #[cfg(i2c_v2)]
93 pub async fn write_read_timeout(
94 &mut self,
95 address: u8,
96 write: &[u8],
97 read: &mut [u8],
98 timeout: Duration,
99 ) -> Result<(), Error>
100 where
101 TXDMA: super::TxDma<T>,
102 RXDMA: super::RxDma<T>,
103 {
104 self.i2c
105 .write_read_timeout(address, write, read, timeout_fn(timeout))
106 .await
107 }
108
109 // =========================
110 // Blocking public API
111
112 /// Blocking read with a custom timeout
113 pub fn blocking_read_timeout(&mut self, addr: u8, read: &mut [u8], timeout: Duration) -> Result<(), Error> {
114 self.i2c.blocking_read_timeout(addr, read, timeout_fn(timeout))
115 }
116
117 /// Blocking read with default timeout, provided in [`TimeoutI2c::new()`]
118 pub fn blocking_read(&mut self, addr: u8, read: &mut [u8]) -> Result<(), Error> {
119 self.blocking_read_timeout(addr, read, self.timeout)
120 }
121
122 /// Blocking write with a custom timeout
123 pub fn blocking_write_timeout(&mut self, addr: u8, write: &[u8], timeout: Duration) -> Result<(), Error> {
124 self.i2c.blocking_write_timeout(addr, write, timeout_fn(timeout))
125 }
126
127 /// Blocking write with default timeout, provided in [`TimeoutI2c::new()`]
128 pub fn blocking_write(&mut self, addr: u8, write: &[u8]) -> Result<(), Error> {
129 self.blocking_write_timeout(addr, write, self.timeout)
130 }
131
132 /// Blocking write-read with a custom timeout
133 pub fn blocking_write_read_timeout(
134 &mut self,
135 addr: u8,
136 write: &[u8],
137 read: &mut [u8],
138 timeout: Duration,
139 ) -> Result<(), Error> {
140 self.i2c
141 .blocking_write_read_timeout(addr, write, read, timeout_fn(timeout))
142 }
143
144 /// Blocking write-read with default timeout, provided in [`TimeoutI2c::new()`]
145 pub fn blocking_write_read(&mut self, addr: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> {
146 self.blocking_write_read_timeout(addr, write, read, self.timeout)
147 }
148}
149
150impl<'a, 'd: 'a, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::Read
151 for TimeoutI2c<'a, 'd, T, TXDMA, RXDMA>
152{
153 type Error = Error;
154
155 fn read(&mut self, addr: u8, read: &mut [u8]) -> Result<(), Self::Error> {
156 self.blocking_read(addr, read)
157 }
158}
159
160impl<'a, 'd: 'a, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::Write
161 for TimeoutI2c<'a, 'd, T, TXDMA, RXDMA>
162{
163 type Error = Error;
164
165 fn write(&mut self, addr: u8, write: &[u8]) -> Result<(), Self::Error> {
166 self.blocking_write(addr, write)
167 }
168}
169
170impl<'a, 'd: 'a, T: Instance, TXDMA, RXDMA> embedded_hal_02::blocking::i2c::WriteRead
171 for TimeoutI2c<'a, 'd, T, TXDMA, RXDMA>
172{
173 type Error = Error;
174
175 fn write_read(&mut self, addr: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> {
176 self.blocking_write_read(addr, write, read)
177 }
178}
179
180#[cfg(feature = "unstable-traits")]
181mod eh1 {
182 use super::*;
183
184 impl<'a, 'd: 'a, T: Instance, TXDMA, RXDMA> embedded_hal_1::i2c::ErrorType for TimeoutI2c<'a, 'd, T, TXDMA, RXDMA> {
185 type Error = Error;
186 }
187
188 impl<'a, 'd: 'a, T: Instance, TXDMA, RXDMA> embedded_hal_1::i2c::I2c for TimeoutI2c<'a, 'd, T, TXDMA, RXDMA> {
189 fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> {
190 self.blocking_read(address, read)
191 }
192
193 fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> {
194 self.blocking_write(address, write)
195 }
196
197 fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> {
198 self.blocking_write_read(address, write, read)
199 }
200
201 fn transaction(
202 &mut self,
203 _address: u8,
204 _operations: &mut [embedded_hal_1::i2c::Operation<'_>],
205 ) -> Result<(), Self::Error> {
206 todo!();
207 }
208 }
209}
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs
index 543d8f1b4..41aa0b6d0 100644
--- a/embassy-stm32/src/i2c/v2.rs
+++ b/embassy-stm32/src/i2c/v2.rs
@@ -1,14 +1,21 @@
1use core::cmp; 1use core::cmp;
2#[cfg(feature = "time")]
2use core::future::poll_fn; 3use core::future::poll_fn;
3use core::marker::PhantomData; 4use core::marker::PhantomData;
5#[cfg(feature = "time")]
4use core::task::Poll; 6use core::task::Poll;
5 7
6use embassy_embedded_hal::SetConfig; 8use embassy_embedded_hal::SetConfig;
9#[cfg(feature = "time")]
7use embassy_hal_internal::drop::OnDrop; 10use embassy_hal_internal::drop::OnDrop;
8use embassy_hal_internal::{into_ref, PeripheralRef}; 11use embassy_hal_internal::{into_ref, PeripheralRef};
9use embassy_sync::waitqueue::AtomicWaker; 12use embassy_sync::waitqueue::AtomicWaker;
13#[cfg(feature = "time")]
14use embassy_time::{Duration, Instant};
10 15
11use crate::dma::{NoDma, Transfer}; 16use crate::dma::NoDma;
17#[cfg(feature = "time")]
18use crate::dma::Transfer;
12use crate::gpio::sealed::AFType; 19use crate::gpio::sealed::AFType;
13use crate::gpio::Pull; 20use crate::gpio::Pull;
14use crate::i2c::{Error, Instance, SclPin, SdaPin}; 21use crate::i2c::{Error, Instance, SclPin, SdaPin};
@@ -43,6 +50,8 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl
43pub struct Config { 50pub struct Config {
44 pub sda_pullup: bool, 51 pub sda_pullup: bool,
45 pub scl_pullup: bool, 52 pub scl_pullup: bool,
53 #[cfg(feature = "time")]
54 pub transaction_timeout: Duration,
46} 55}
47 56
48impl Default for Config { 57impl Default for Config {
@@ -50,6 +59,8 @@ impl Default for Config {
50 Self { 59 Self {
51 sda_pullup: false, 60 sda_pullup: false,
52 scl_pullup: false, 61 scl_pullup: false,
62 #[cfg(feature = "time")]
63 transaction_timeout: Duration::from_millis(100),
53 } 64 }
54 } 65 }
55} 66}
@@ -68,9 +79,12 @@ impl State {
68 79
69pub struct I2c<'d, T: Instance, TXDMA = NoDma, RXDMA = NoDma> { 80pub struct I2c<'d, T: Instance, TXDMA = NoDma, RXDMA = NoDma> {
70 _peri: PeripheralRef<'d, T>, 81 _peri: PeripheralRef<'d, T>,
82 #[allow(dead_code)]
71 tx_dma: PeripheralRef<'d, TXDMA>, 83 tx_dma: PeripheralRef<'d, TXDMA>,
72 #[allow(dead_code)] 84 #[allow(dead_code)]
73 rx_dma: PeripheralRef<'d, RXDMA>, 85 rx_dma: PeripheralRef<'d, RXDMA>,
86 #[cfg(feature = "time")]
87 timeout: Duration,
74} 88}
75 89
76impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { 90impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
@@ -132,6 +146,8 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
132 _peri: peri, 146 _peri: peri,
133 tx_dma, 147 tx_dma,
134 rx_dma, 148 rx_dma,
149 #[cfg(feature = "time")]
150 timeout: config.transaction_timeout,
135 } 151 }
136 } 152 }
137 153
@@ -422,6 +438,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
422 result 438 result
423 } 439 }
424 440
441 #[cfg(feature = "time")]
425 async fn write_dma_internal( 442 async fn write_dma_internal(
426 &mut self, 443 &mut self,
427 address: u8, 444 address: u8,
@@ -512,6 +529,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
512 Ok(()) 529 Ok(())
513 } 530 }
514 531
532 #[cfg(feature = "time")]
515 async fn read_dma_internal( 533 async fn read_dma_internal(
516 &mut self, 534 &mut self,
517 address: u8, 535 address: u8,
@@ -594,42 +612,41 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
594 // ========================= 612 // =========================
595 // Async public API 613 // Async public API
596 614
615 #[cfg(feature = "time")]
597 pub async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> 616 pub async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Error>
598 where 617 where
599 TXDMA: crate::i2c::TxDma<T>, 618 TXDMA: crate::i2c::TxDma<T>,
600 { 619 {
601 self.write_timeout(address, write, || Ok(())).await 620 self.write_timeout(address, write, self.timeout).await
602 } 621 }
603 622
604 pub async fn write_timeout( 623 #[cfg(feature = "time")]
605 &mut self, 624 pub async fn write_timeout(&mut self, address: u8, write: &[u8], timeout: Duration) -> Result<(), Error>
606 address: u8,
607 write: &[u8],
608 check_timeout: impl Fn() -> Result<(), Error>,
609 ) -> Result<(), Error>
610 where 625 where
611 TXDMA: crate::i2c::TxDma<T>, 626 TXDMA: crate::i2c::TxDma<T>,
612 { 627 {
613 if write.is_empty() { 628 if write.is_empty() {
614 self.write_internal(address, write, true, check_timeout) 629 self.write_internal(address, write, true, timeout_fn(timeout))
615 } else { 630 } else {
616 self.write_dma_internal(address, write, true, true, check_timeout).await 631 embassy_time::with_timeout(
632 timeout,
633 self.write_dma_internal(address, write, true, true, timeout_fn(timeout)),
634 )
635 .await
636 .unwrap_or(Err(Error::Timeout))
617 } 637 }
618 } 638 }
619 639
640 #[cfg(feature = "time")]
620 pub async fn write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> 641 pub async fn write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error>
621 where 642 where
622 TXDMA: crate::i2c::TxDma<T>, 643 TXDMA: crate::i2c::TxDma<T>,
623 { 644 {
624 self.write_vectored_timeout(address, write, || Ok(())).await 645 self.write_vectored_timeout(address, write, self.timeout).await
625 } 646 }
626 647
627 pub async fn write_vectored_timeout( 648 #[cfg(feature = "time")]
628 &mut self, 649 pub async fn write_vectored_timeout(&mut self, address: u8, write: &[&[u8]], timeout: Duration) -> Result<(), Error>
629 address: u8,
630 write: &[&[u8]],
631 check_timeout: impl Fn() -> Result<(), Error>,
632 ) -> Result<(), Error>
633 where 650 where
634 TXDMA: crate::i2c::TxDma<T>, 651 TXDMA: crate::i2c::TxDma<T>,
635 { 652 {
@@ -644,67 +661,88 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
644 let next = iter.next(); 661 let next = iter.next();
645 let is_last = next.is_none(); 662 let is_last = next.is_none();
646 663
647 self.write_dma_internal(address, c, first, is_last, || check_timeout()) 664 embassy_time::with_timeout(
648 .await?; 665 timeout,
666 self.write_dma_internal(address, c, first, is_last, timeout_fn(timeout)),
667 )
668 .await
669 .unwrap_or(Err(Error::Timeout))?;
649 first = false; 670 first = false;
650 current = next; 671 current = next;
651 } 672 }
652 Ok(()) 673 Ok(())
653 } 674 }
654 675
676 #[cfg(feature = "time")]
655 pub async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> 677 pub async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error>
656 where 678 where
657 RXDMA: crate::i2c::RxDma<T>, 679 RXDMA: crate::i2c::RxDma<T>,
658 { 680 {
659 self.read_timeout(address, buffer, || Ok(())).await 681 self.read_timeout(address, buffer, self.timeout).await
660 } 682 }
661 683
662 pub async fn read_timeout( 684 #[cfg(feature = "time")]
663 &mut self, 685 pub async fn read_timeout(&mut self, address: u8, buffer: &mut [u8], timeout: Duration) -> Result<(), Error>
664 address: u8,
665 buffer: &mut [u8],
666 check_timeout: impl Fn() -> Result<(), Error>,
667 ) -> Result<(), Error>
668 where 686 where
669 RXDMA: crate::i2c::RxDma<T>, 687 RXDMA: crate::i2c::RxDma<T>,
670 { 688 {
671 if buffer.is_empty() { 689 if buffer.is_empty() {
672 self.read_internal(address, buffer, false, check_timeout) 690 self.read_internal(address, buffer, false, timeout_fn(timeout))
673 } else { 691 } else {
674 self.read_dma_internal(address, buffer, false, check_timeout).await 692 embassy_time::with_timeout(
693 timeout,
694 self.read_dma_internal(address, buffer, false, timeout_fn(timeout)),
695 )
696 .await
697 .unwrap_or(Err(Error::Timeout))
675 } 698 }
676 } 699 }
677 700
701 #[cfg(feature = "time")]
678 pub async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> 702 pub async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error>
679 where 703 where
680 TXDMA: super::TxDma<T>, 704 TXDMA: super::TxDma<T>,
681 RXDMA: super::RxDma<T>, 705 RXDMA: super::RxDma<T>,
682 { 706 {
683 self.write_read_timeout(address, write, read, || Ok(())).await 707 self.write_read_timeout(address, write, read, self.timeout).await
684 } 708 }
685 709
710 #[cfg(feature = "time")]
686 pub async fn write_read_timeout( 711 pub async fn write_read_timeout(
687 &mut self, 712 &mut self,
688 address: u8, 713 address: u8,
689 write: &[u8], 714 write: &[u8],
690 read: &mut [u8], 715 read: &mut [u8],
691 check_timeout: impl Fn() -> Result<(), Error>, 716 timeout: Duration,
692 ) -> Result<(), Error> 717 ) -> Result<(), Error>
693 where 718 where
694 TXDMA: super::TxDma<T>, 719 TXDMA: super::TxDma<T>,
695 RXDMA: super::RxDma<T>, 720 RXDMA: super::RxDma<T>,
696 { 721 {
722 let start_instant = Instant::now();
723 let check_timeout = timeout_fn(timeout);
697 if write.is_empty() { 724 if write.is_empty() {
698 self.write_internal(address, write, false, || check_timeout())?; 725 self.write_internal(address, write, false, &check_timeout)?;
699 } else { 726 } else {
700 self.write_dma_internal(address, write, true, true, || check_timeout()) 727 embassy_time::with_timeout(
701 .await?; 728 timeout,
729 self.write_dma_internal(address, write, true, true, &check_timeout),
730 )
731 .await
732 .unwrap_or(Err(Error::Timeout))?;
702 } 733 }
703 734
735 let time_left_until_timeout = timeout - Instant::now().duration_since(start_instant);
736
704 if read.is_empty() { 737 if read.is_empty() {
705 self.read_internal(address, read, true, check_timeout)?; 738 self.read_internal(address, read, true, &check_timeout)?;
706 } else { 739 } else {
707 self.read_dma_internal(address, read, true, check_timeout).await?; 740 embassy_time::with_timeout(
741 time_left_until_timeout,
742 self.read_dma_internal(address, read, true, &check_timeout),
743 )
744 .await
745 .unwrap_or(Err(Error::Timeout))?;
708 } 746 }
709 747
710 Ok(()) 748 Ok(())
@@ -713,33 +751,73 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
713 // ========================= 751 // =========================
714 // Blocking public API 752 // Blocking public API
715 753
754 #[cfg(feature = "time")]
755 pub fn blocking_read_timeout(&mut self, address: u8, read: &mut [u8], timeout: Duration) -> Result<(), Error> {
756 self.read_internal(address, read, false, timeout_fn(timeout))
757 // Automatic Stop
758 }
759
760 #[cfg(not(feature = "time"))]
716 pub fn blocking_read_timeout( 761 pub fn blocking_read_timeout(
717 &mut self, 762 &mut self,
718 address: u8, 763 address: u8,
719 read: &mut [u8], 764 read: &mut [u8],
720 check_timeout: impl Fn() -> Result<(), Error>, 765 check_timeout: impl Fn() -> Result<(), Error>,
721 ) -> Result<(), Error> { 766 ) -> Result<(), Error> {
722 self.read_internal(address, read, false, &check_timeout) 767 self.read_internal(address, read, false, check_timeout)
723 // Automatic Stop 768 // Automatic Stop
724 } 769 }
725 770
771 #[cfg(feature = "time")]
772 pub fn blocking_read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Error> {
773 self.blocking_read_timeout(address, read, self.timeout)
774 }
775
776 #[cfg(not(feature = "time"))]
726 pub fn blocking_read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Error> { 777 pub fn blocking_read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Error> {
727 self.blocking_read_timeout(address, read, || Ok(())) 778 self.blocking_read_timeout(address, read, || Ok(()))
728 } 779 }
729 780
781 #[cfg(feature = "time")]
782 pub fn blocking_write_timeout(&mut self, address: u8, write: &[u8], timeout: Duration) -> Result<(), Error> {
783 self.write_internal(address, write, true, timeout_fn(timeout))
784 }
785
786 #[cfg(not(feature = "time"))]
730 pub fn blocking_write_timeout( 787 pub fn blocking_write_timeout(
731 &mut self, 788 &mut self,
732 address: u8, 789 address: u8,
733 write: &[u8], 790 write: &[u8],
734 check_timeout: impl Fn() -> Result<(), Error>, 791 check_timeout: impl Fn() -> Result<(), Error>,
735 ) -> Result<(), Error> { 792 ) -> Result<(), Error> {
736 self.write_internal(address, write, true, &check_timeout) 793 self.write_internal(address, write, true, check_timeout)
737 } 794 }
738 795
796 #[cfg(feature = "time")]
797 pub fn blocking_write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> {
798 self.blocking_write_timeout(address, write, self.timeout)
799 }
800
801 #[cfg(not(feature = "time"))]
739 pub fn blocking_write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> { 802 pub fn blocking_write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> {
740 self.blocking_write_timeout(address, write, || Ok(())) 803 self.blocking_write_timeout(address, write, || Ok(()))
741 } 804 }
742 805
806 #[cfg(feature = "time")]
807 pub fn blocking_write_read_timeout(
808 &mut self,
809 address: u8,
810 write: &[u8],
811 read: &mut [u8],
812 timeout: Duration,
813 ) -> Result<(), Error> {
814 let check_timeout = timeout_fn(timeout);
815 self.write_internal(address, write, false, &check_timeout)?;
816 self.read_internal(address, read, true, &check_timeout)
817 // Automatic Stop
818 }
819
820 #[cfg(not(feature = "time"))]
743 pub fn blocking_write_read_timeout( 821 pub fn blocking_write_read_timeout(
744 &mut self, 822 &mut self,
745 address: u8, 823 address: u8,
@@ -752,11 +830,17 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
752 // Automatic Stop 830 // Automatic Stop
753 } 831 }
754 832
833 #[cfg(feature = "time")]
834 pub fn blocking_write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> {
835 self.blocking_write_read_timeout(address, write, read, self.timeout)
836 }
837
838 #[cfg(not(feature = "time"))]
755 pub fn blocking_write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { 839 pub fn blocking_write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> {
756 self.blocking_write_read_timeout(address, write, read, || Ok(())) 840 self.blocking_write_read_timeout(address, write, read, || Ok(()))
757 } 841 }
758 842
759 pub fn blocking_write_vectored_timeout( 843 fn blocking_write_vectored_with_timeout(
760 &mut self, 844 &mut self,
761 address: u8, 845 address: u8,
762 write: &[&[u8]], 846 write: &[&[u8]],
@@ -765,6 +849,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
765 if write.is_empty() { 849 if write.is_empty() {
766 return Err(Error::ZeroLengthTransfer); 850 return Err(Error::ZeroLengthTransfer);
767 } 851 }
852
768 let first_length = write[0].len(); 853 let first_length = write[0].len();
769 let last_slice_index = write.len() - 1; 854 let last_slice_index = write.len() - 1;
770 855
@@ -833,6 +918,33 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
833 result 918 result
834 } 919 }
835 920
921 #[cfg(feature = "time")]
922 pub fn blocking_write_vectored_timeout(
923 &mut self,
924 address: u8,
925 write: &[&[u8]],
926 timeout: Duration,
927 ) -> Result<(), Error> {
928 let check_timeout = timeout_fn(timeout);
929 self.blocking_write_vectored_with_timeout(address, write, check_timeout)
930 }
931
932 #[cfg(not(feature = "time"))]
933 pub fn blocking_write_vectored_timeout(
934 &mut self,
935 address: u8,
936 write: &[&[u8]],
937 check_timeout: impl Fn() -> Result<(), Error>,
938 ) -> Result<(), Error> {
939 self.blocking_write_vectored_with_timeout(address, write, check_timeout)
940 }
941
942 #[cfg(feature = "time")]
943 pub fn blocking_write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> {
944 self.blocking_write_vectored_timeout(address, write, self.timeout)
945 }
946
947 #[cfg(not(feature = "time"))]
836 pub fn blocking_write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> { 948 pub fn blocking_write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> {
837 self.blocking_write_vectored_timeout(address, write, || Ok(())) 949 self.blocking_write_vectored_timeout(address, write, || Ok(()))
838 } 950 }
@@ -844,6 +956,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> Drop for I2c<'d, T, TXDMA, RXDMA> {
844 } 956 }
845} 957}
846 958
959#[cfg(feature = "time")]
847mod eh02 { 960mod eh02 {
848 use super::*; 961 use super::*;
849 962
@@ -1043,7 +1156,7 @@ mod eh1 {
1043 } 1156 }
1044} 1157}
1045 1158
1046#[cfg(all(feature = "unstable-traits", feature = "nightly"))] 1159#[cfg(all(feature = "unstable-traits", feature = "nightly", feature = "time"))]
1047mod eha { 1160mod eha {
1048 use super::super::{RxDma, TxDma}; 1161 use super::super::{RxDma, TxDma};
1049 use super::*; 1162 use super::*;
@@ -1089,3 +1202,15 @@ impl<'d, T: Instance> SetConfig for I2c<'d, T> {
1089 Ok(()) 1202 Ok(())
1090 } 1203 }
1091} 1204}
1205
1206#[cfg(feature = "time")]
1207fn timeout_fn(timeout: Duration) -> impl Fn() -> Result<(), Error> {
1208 let deadline = Instant::now() + timeout;
1209 move || {
1210 if Instant::now() > deadline {
1211 Err(Error::Timeout)
1212 } else {
1213 Ok(())
1214 }
1215 }
1216}
diff --git a/examples/stm32f4/src/bin/i2c.rs b/examples/stm32f4/src/bin/i2c.rs
index a92957325..032bd97ee 100644
--- a/examples/stm32f4/src/bin/i2c.rs
+++ b/examples/stm32f4/src/bin/i2c.rs
@@ -5,10 +5,9 @@
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::dma::NoDma; 7use embassy_stm32::dma::NoDma;
8use embassy_stm32::i2c::{Error, I2c, TimeoutI2c}; 8use embassy_stm32::i2c::{Error, I2c};
9use embassy_stm32::time::Hertz; 9use embassy_stm32::time::Hertz;
10use embassy_stm32::{bind_interrupts, i2c, peripherals}; 10use embassy_stm32::{bind_interrupts, i2c, peripherals};
11use embassy_time::Duration;
12use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
13 12
14const ADDRESS: u8 = 0x5F; 13const ADDRESS: u8 = 0x5F;
@@ -34,13 +33,9 @@ async fn main(_spawner: Spawner) {
34 Default::default(), 33 Default::default(),
35 ); 34 );
36 35
37 // I2C bus can freeze if SCL line is shorted or due to a broken device that clock stretches for too long.
38 // TimeoutI2c allows recovering from such errors by throwing `Error::Timeout` after a given delay.
39 let mut timeout_i2c = TimeoutI2c::new(&mut i2c, Duration::from_millis(1000));
40
41 let mut data = [0u8; 1]; 36 let mut data = [0u8; 1];
42 37
43 match timeout_i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data) { 38 match i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data) {
44 Ok(()) => info!("Whoami: {}", data[0]), 39 Ok(()) => info!("Whoami: {}", data[0]),
45 Err(Error::Timeout) => error!("Operation timed out"), 40 Err(Error::Timeout) => error!("Operation timed out"),
46 Err(e) => error!("I2c Error: {:?}", e), 41 Err(e) => error!("I2c Error: {:?}", e),
diff --git a/examples/stm32h5/src/bin/i2c.rs b/examples/stm32h5/src/bin/i2c.rs
index 8b6fe71ae..8b1662f39 100644
--- a/examples/stm32h5/src/bin/i2c.rs
+++ b/examples/stm32h5/src/bin/i2c.rs
@@ -4,10 +4,9 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::i2c::{Error, I2c, TimeoutI2c}; 7use embassy_stm32::i2c::{Error, I2c};
8use embassy_stm32::time::Hertz; 8use embassy_stm32::time::Hertz;
9use embassy_stm32::{bind_interrupts, i2c, peripherals}; 9use embassy_stm32::{bind_interrupts, i2c, peripherals};
10use embassy_time::Duration;
11use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
12 11
13const ADDRESS: u8 = 0x5F; 12const ADDRESS: u8 = 0x5F;
@@ -33,13 +32,9 @@ async fn main(_spawner: Spawner) {
33 Default::default(), 32 Default::default(),
34 ); 33 );
35 34
36 // I2C bus can freeze if SCL line is shorted or due to a broken device that clock stretches for too long.
37 // TimeoutI2c allows recovering from such errors by throwing `Error::Timeout` after a given delay.
38 let mut timeout_i2c = TimeoutI2c::new(&mut i2c, Duration::from_millis(1000));
39
40 let mut data = [0u8; 1]; 35 let mut data = [0u8; 1];
41 36
42 match timeout_i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data) { 37 match i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data) {
43 Ok(()) => info!("Whoami: {}", data[0]), 38 Ok(()) => info!("Whoami: {}", data[0]),
44 Err(Error::Timeout) => error!("Operation timed out"), 39 Err(Error::Timeout) => error!("Operation timed out"),
45 Err(e) => error!("I2c Error: {:?}", e), 40 Err(e) => error!("I2c Error: {:?}", e),
diff --git a/examples/stm32h7/src/bin/i2c.rs b/examples/stm32h7/src/bin/i2c.rs
index c2979c59b..9aa0ca08b 100644
--- a/examples/stm32h7/src/bin/i2c.rs
+++ b/examples/stm32h7/src/bin/i2c.rs
@@ -4,10 +4,9 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::i2c::{Error, I2c, TimeoutI2c}; 7use embassy_stm32::i2c::{Error, I2c};
8use embassy_stm32::time::Hertz; 8use embassy_stm32::time::Hertz;
9use embassy_stm32::{bind_interrupts, i2c, peripherals}; 9use embassy_stm32::{bind_interrupts, i2c, peripherals};
10use embassy_time::Duration;
11use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
12 11
13const ADDRESS: u8 = 0x5F; 12const ADDRESS: u8 = 0x5F;
@@ -33,13 +32,9 @@ async fn main(_spawner: Spawner) {
33 Default::default(), 32 Default::default(),
34 ); 33 );
35 34
36 // I2C bus can freeze if SCL line is shorted or due to a broken device that clock stretches for too long.
37 // TimeoutI2c allows recovering from such errors by throwing `Error::Timeout` after a given delay.
38 let mut timeout_i2c = TimeoutI2c::new(&mut i2c, Duration::from_millis(1000));
39
40 let mut data = [0u8; 1]; 35 let mut data = [0u8; 1];
41 36
42 match timeout_i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data) { 37 match i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data) {
43 Ok(()) => info!("Whoami: {}", data[0]), 38 Ok(()) => info!("Whoami: {}", data[0]),
44 Err(Error::Timeout) => error!("Operation timed out"), 39 Err(Error::Timeout) => error!("Operation timed out"),
45 Err(e) => error!("I2c Error: {:?}", e), 40 Err(e) => error!("I2c Error: {:?}", e),