rust-embedded / linux-embedded-hal

Implementation of the `embedded-hal` traits for Linux devices
Apache License 2.0
232 stars 40 forks source link

impl embedded_hal::digital::Error for linux_embedded_hal::gpio_cdev::Error #112

Open SpieringsAE opened 4 months ago

SpieringsAE commented 4 months ago

I'm trying to write an initialisation function for a driver, but the fact that the pin initialisation functions don't give me an embedded-hal Error trait is being a bit of a pain in the behind for me. I can't properly incorperate the errors that arise when setting up gpios in my drivers error enum.

My situation is an SPI device that has two additional gpios, a reset and an interrupt pin. This is a very hardware specific driver so the pins and spidev are created in the driver::new() function.

The linux_embedded_hal::spi::SPIError does implement embedded_hal::spi::Error so that one is fine I think.

Is this a workable idea?

reitermarkus commented 4 months ago

Would the implementation in https://github.com/rust-embedded/linux-embedded-hal/pull/110 solve your issue as well?

In there, the CdevPin::new method returns a CdevPinError defined in this crate instead of needing to construct the CdevPin from the external type as is currently the case.

SpieringsAE commented 4 months ago

I think yes that could very much do that. I also think my request isn't possible, as the gpio_cdev::Error Is just a re-export so this crate doesn't influence it. So yeah it seems like there needs to be a linux-embedded-hal way to create a pin without having to deal with gpio-cdev errors.