File tree 6 files changed +56
-0
lines changed
6 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,13 @@ version = "0.1.0"
15
15
# more information.
16
16
rust-version = " 1.74"
17
17
18
+ [features ]
19
+ rust_embedded = [
20
+ " embedded-hal" ,
21
+ " libtock_platform/rust_embedded" ,
22
+ " libtock_gpio/rust_embedded"
23
+ ]
24
+
18
25
[dependencies ]
19
26
libtock_adc = { path = " apis/adc" }
20
27
libtock_air_quality = { path = " apis/air_quality" }
@@ -38,6 +45,8 @@ libtock_runtime = { path = "runtime" }
38
45
libtock_sound_pressure = { path = " apis/sound_pressure" }
39
46
libtock_temperature = { path = " apis/temperature" }
40
47
48
+ embedded-hal = { version = " 1.0" , optional = true }
49
+
41
50
[build-dependencies ]
42
51
libtock_build_scripts = { path = " build_scripts" }
43
52
Original file line number Diff line number Diff line change @@ -63,6 +63,19 @@ This script does the following steps for you:
63
63
- create a TAB (tock application bundle)
64
64
- if you have a J-Link compatible board connected: flash this TAB to your board (using tockloader)
65
65
66
+ # ## Enabling rust-embedded support
67
+
68
+ libtock-rs can be built to be compatible with the rust-embedded
69
+ [embedded_hal](https://docs.rs/embedded-hal/1.0.0/embedded_hal/index.html) by
70
+ including the following when running ` make`
71
+
72
+ ` ` ` shell
73
+ FEATURES=rust_embedded
74
+ ` ` `
75
+
76
+ If using libtock-rs or a sub-crate as a cargo dependency the ` rust_embedded`
77
+ can also be enabled via Cargo.
78
+
66
79
# ## Building a generic TAB (Tock Application Bundle) file
67
80
68
81
To build your example for a variety of boards you can use
Original file line number Diff line number Diff line change @@ -8,8 +8,12 @@ repository = "https://www.github.com/tock/libtock-rs"
8
8
rust-version.workspace = true
9
9
description = " libtock gpio driver"
10
10
11
+ [features ]
12
+ rust_embedded = [" embedded-hal" ]
13
+
11
14
[dependencies ]
12
15
libtock_platform = { path = " ../../platform" }
16
+ embedded-hal = { version = " 1.0" , optional = true }
13
17
14
18
[dev-dependencies ]
15
19
libtock_unittest = { path = " ../../unittest" }
Original file line number Diff line number Diff line change @@ -231,6 +231,22 @@ impl<S: Syscalls> Gpio<S> {
231
231
}
232
232
}
233
233
234
+ #[ cfg( feature = "rust_embedded" ) ]
235
+ impl < ' a , S : Syscalls > embedded_hal:: digital:: ErrorType for OutputPin < ' a , S > {
236
+ type Error = ErrorCode ;
237
+ }
238
+
239
+ #[ cfg( feature = "rust_embedded" ) ]
240
+ impl < ' a , S : Syscalls > embedded_hal:: digital:: OutputPin for OutputPin < ' a , S > {
241
+ fn set_low ( & mut self ) -> Result < ( ) , Self :: Error > {
242
+ self . clear ( )
243
+ }
244
+
245
+ fn set_high ( & mut self ) -> Result < ( ) , Self :: Error > {
246
+ self . set ( )
247
+ }
248
+ }
249
+
234
250
#[ cfg( test) ]
235
251
mod tests;
236
252
Original file line number Diff line number Diff line change @@ -12,3 +12,9 @@ name = "libtock_platform"
12
12
repository = " https://www.github.com/tock/libtock/rs"
13
13
rust-version.workspace = true
14
14
version = " 0.1.0"
15
+
16
+ [features ]
17
+ rust_embedded = [" embedded-hal" ]
18
+
19
+ [dependencies ]
20
+ embedded-hal = { version = " 1.0" , optional = true }
Original file line number Diff line number Diff line change @@ -283,3 +283,11 @@ impl TryFrom<u32> for ErrorCode {
283
283
}
284
284
}
285
285
}
286
+
287
+ #[ cfg( feature = "rust_embedded" ) ]
288
+ impl embedded_hal:: digital:: Error for ErrorCode {
289
+ fn kind ( & self ) -> embedded_hal:: digital:: ErrorKind {
290
+ use embedded_hal:: digital:: ErrorKind ;
291
+ ErrorKind :: Other
292
+ }
293
+ }
You can’t perform that action at this time.
0 commit comments