Skip to content

RFC rust: LED abstractions

Fiona Behrens linux-leds lkml rust-for-linux 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest2 patches 8 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2rust: LED abstractionrust/kernel/leds.rs rust/kernel/lib.rs+401 -06 replies
2/2samples: rust: led samplesamples/rust/Kconfig samples/rust/Makefile samples/rust/rust_led.rs+114 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/2] rust: LED abstractions

This RFC implements a basic LED abstraction to show how this would work with rust.

Currently this just implements a sample driver, to show how to use the abstraction, which just prints the requested state, supporting a on/off LED and an led with brightness level up to 255 and hardware blinking. I intend to write a hardware specific driver for submitting.

The abstractions is a generic struct that holds a generic driver data on which the vtable is implemented. Because this struct also holds the c led_classdev (include/linux/leds.h) struct this struct is pinned and is using pin_init to create and directly register the LED. Dropping the struct unregisteres the LED. I plan to also add devm functions later, but as device abstractions in rust are not yet that far I opted agains that for the first iteration of the LED abstractions.

This is currently using core::time::Duration for the blinking interval, but will likely change that to use the Delta time type from FUJITA Tomonori [1].

This is requiring the Opaque::try_ffi_init patch by Alice Ryhl[2] which just got merged into char-misc-testing.

[1]: https://lore.kernel.org/rust-for-linux/[email protected]/
[2]: https://lore.kernel.org/rust-for-linux/[email protected]/

Fiona Behrens (2):
rust: LED abstraction
samples: rust: led sample

 rust/kernel/leds.rs      | 399 +++++++++++++++++++++++++++++++++++++++
 rust/kernel/lib.rs       |   2 +
 samples/rust/Kconfig     |  10 +
 samples/rust/Makefile    |   1 +
 samples/rust/rust_led.rs | 103 ++++++++++
 5 files changed, 515 insertions(+)
 create mode 100644 rust/kernel/leds.rs
 create mode 100644 samples/rust/rust_led.rs
Signature · 1 line
2.46.0