Skip to content

Conversation

@t-wallet
Copy link
Contributor

@t-wallet t-wallet commented Dec 2, 2025

I'm currently writing a SPI device driver which can use any struct that implements embedded_hal::spi::SpiDevice internally, such as a embedded_hal_bus::spi::ExclusiveDevice. I would like to provide an infallible API for platforms which have infallible SPI transactions, such as the RP2350. A SPI transaction on these platforms returns Result<(), DeviceError<Infallible, Infallible>> if we use an ExclusiveDevice, which can obviously be safely unwrapped.

To write this API I create a simple wrapper struct around the original fallible API. I tried to constrain the error type by Into<Infallible> such that any error type that is convertible to Infallible can be used. However, DeviceError<Infallible, Infallible> does not implement this trait yet. So I implemented it in this PR.

Happy to hear opinions and possible alternatives, this was the first solution I saw.

This improves integration with infallible SPI device driver APIs that constrain the SPI device error type
to Into<Infallible>, allowing types such as DeviceError<Infallible, Infallible> to be used.
@t-wallet t-wallet requested a review from a team as a code owner December 2, 2025 14:50
@MabezDev MabezDev added this pull request to the merge queue Dec 4, 2025
Merged via the queue into rust-embedded:master with commit cb1f73e Dec 4, 2025
7 checks passed
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.

3 participants