madmachineio / SwiftIO

A Swift framework for microcontrollers abstraction layer.
https://madmachineio.github.io/SwiftIO/documentation/swiftio
MIT License
179 stars 14 forks source link

API refinements #33

Open lhoward opened 9 months ago

lhoward commented 9 months ago

Just using this as a catch-all, can split out into separate issues later

lhoward commented 9 months ago

Here's my current approach for async, which at least has the advantage that it's quite minimally intrusive to the HAL.

There's a simple function to get the underlying FD, e.g.:

int swifthal_spi_get_fd(void * _Nonnull spi);

and then there is (e.g.) an AsyncSPI actor which wraps SPI to do its initialisation but does all the underlying I/O using IORingSwift. So the async wrappers are really extremely straightforward. Once I have them working in my application, I will have some feedback about the suitability of the APIs, etc, and then perhaps down the track we can look at adapting IORingSwift to also support RTIO.

Same for UART, I2C, etc.

lhoward commented 9 months ago

Pleased to report I have async SPI working with a RPi4 controller, proprietary peripheral.

Was quite an effort, particularly because Linux's user-space SPI API is blocking (hence IORingSwift, which took a while to iron out all race conditions).

The code uses SwiftIO for initialisation and hands over to AsyncSPI (of course, eventually it would be great to have this integrated into SwiftIO itself).

lhoward commented 2 months ago

Another request would be to use Errno from SwiftSystem. Currently I'm converting between the two, obviously it's trivial and doesn't really matter but it would be nice to standardise. Of course, getting SwiftSystem to run on Zephyr might take a little work.