-
Notifications
You must be signed in to change notification settings - Fork 109
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
Conversation
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>
f92ed8b
to
dcf5d94
Compare
There was a problem hiding this 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.
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
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 |
Is this ready to merge now? |
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