rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] rust: LED abstractions
@ 2024-10-09 10:57 Fiona Behrens
  2024-10-09 10:57 ` [RFC PATCH 1/2] rust: LED abstraction Fiona Behrens
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Fiona Behrens @ 2024-10-09 10:57 UTC (permalink / raw)
  To: Pavel Machek, Lee Jones, linux-leds
  Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, FUJITA Tomonori, linux-kernel, rust-for-linux,
	Fiona Behrens

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/20241005122531.20298-3-fujita.tomonori@gmail.com/
[2]: https://lore.kernel.org/rust-for-linux/20240926-b4-miscdevice-v1-1-7349c2b2837a@google.com/

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

-- 
2.46.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-11-27 11:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-09 10:57 [RFC PATCH 0/2] rust: LED abstractions Fiona Behrens
2024-10-09 10:57 ` [RFC PATCH 1/2] rust: LED abstraction Fiona Behrens
2024-11-16 15:47   ` Marek Behún
2024-11-18 10:19     ` Alice Ryhl
2024-11-18 16:39       ` Miguel Ojeda
2024-11-18 10:22   ` Alice Ryhl
2024-11-21  9:47     ` Fiona Behrens
2024-11-27 11:39       ` Alice Ryhl
2024-10-09 10:57 ` [RFC PATCH 2/2] samples: rust: led sample Fiona Behrens
2024-11-11  9:41 ` [RFC PATCH 0/2] rust: LED abstractions Lee Jones
2024-11-11 10:21   ` Fiona Behrens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).