Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for the Rust Embedded embedded-hal #540

Merged
merged 1 commit into from
May 28, 2024

Conversation

alistair23
Copy link
Collaborator

This is very initial support for the embedded_hal [1]. This allows general embedded Rust crates to be built on top of libtock-rs with minimal porting effort.

This currently just stubs out the support and implements the digital::OutputPin trait for GPIO pins.

1: https://docs.rs/embedded-hal/1.0.0/embedded_hal/index.html

jrvanwhy
jrvanwhy previously approved these changes May 2, 2024
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
This is very initial support for the embedded_hal [1]. This allows
general embedded Rust crates to be built on top of libtock-rs with
minimal porting effort.

This currently just stubs out the support and implements the
`digital::OutputPin` trait for GPIO pins.

1: https://docs.rs/embedded-hal/1.0.0/embedded_hal/index.html

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
README.md Show resolved Hide resolved
Copy link
Member

@lschuermann lschuermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding support for the embedded HAL is a great addition. I met with some of the Embedded WG folks a couple days ago, and based on some informal conversations this seems like something that's in scope for the HAL too.

I'm not sure whether it would perhaps not be better to ship this as a separate crate. We can't extend libtock-rs' types in other crates, but we can introduce wrapper types that then implement the embedded HAL. I'm slightly skeptical of sprinkling these #[cfg( attributes throughout the codebase, as it can become quite hard to reason about the various interactions and interface compositions across permutations of features.

This seems like a good first step though.

@alistair23
Copy link
Collaborator Author

I'm not sure whether it would perhaps not be better to ship this as a separate crate. We can't extend libtock-rs' types in other crates, but we can introduce wrapper types that then implement the embedded HAL. I'm slightly skeptical of sprinkling these #[cfg( attributes throughout the conference, as it can become quite hard to reason about the various interactions and interface compositions across permutations of features.

A separate crate is probably the way to go. One of the issues we have is that libtock-rs uses types, which don't work very well.

For examples, for the SPI work I have this

#[cfg(feature = "rust_embedded")]
impl<S: Syscalls, C: Config> embedded_hal::spi::SpiDevice for SpiController<S, C> {
    fn transaction(
        &mut self,
        operations: &mut [embedded_hal::spi::Operation<'_, u8>],
    ) -> Result<(), Self::Error> {
...

Then following the standard libtock-rs style we have

pub mod spi_controller {
    use libtock_spi_controller as spi_controller;
    pub type SpiController = spi_controller::SpiController<super::runtime::TockSyscalls>;
}

But that results in errors like this when trying to actually use the type

93 |     let di = SPIInterface::new(SpiController, dc);
   |                                ^^^^^^^^^^^^^
   |
   = note: can't use a type alias as a constructor

Wrapper structs in a crate should help with that. I think this PR is still ok as a first step. Any thoughts on the way to setup the crate are appreciated

@alistair23
Copy link
Collaborator Author

Is this ready to merge now?

@jrvanwhy jrvanwhy added this pull request to the merge queue May 28, 2024
Merged via the queue into tock:master with commit 97a8bea May 28, 2024
3 checks passed
@alistair23 alistair23 deleted the alistair/rust_embedded branch May 28, 2024 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants