Make UARTs adhere to the std.Io.Reader interface - #1008
Conversation
6446f2d to
e7b3e2e
Compare
| 1 => try w.writeByte(buf[0]), | ||
| else => unreachable, | ||
| else => { | ||
| const b = uart.read_word_blocking(uart_reader.deadline) catch |err| switch (err) { |
There was a problem hiding this comment.
Since we're returning one error regardless, we don't need to capture the error here, you can write instead something like:
const b = uart.read_word_blocking(uart_reader.deadline) catch return error.ReadFailed;
There was a problem hiding this comment.
Thanks a ton for the comment! It should be applied on 78b1d61.
Thanks again!
| @@ -177,6 +177,8 @@ pub const UART = enum(u1) { | |||
| .deadline = deadline, | |||
There was a problem hiding this comment.
Quick question that popped up when using the interfaces. Is this deadline correct? It's initialised when instantiating the Reader struct, but at least for the RP2040 I'm creating these deadlines with time.deadline_in_ms() which simply adds the argument with the current time to define an absolute timestamp when the deadline elapses.
Now, given the deadline's instantiated at the very beginning and never recreated it basically becomes a no-op as it's always elapsed later down the road.
Would it make sense to instead of passing an instantiated mdf.time.Deadline pass an integer (i.e. deadline_ms) to instantiate the deadline whenever we make a call such as a in stream()?
Maybe I'm just using the API wrong...
Should this be an error I'd be more than happy to provide a separate PR handling this as it affects both the Reader and Writer.
Thanks a ton for your time.
When trying to leverage an UART through an
std.Io.Readerinterface I was met with compilation errors such asThis PR adds changes so that the UART's HAL adheres to the
std.Io.Readerinterface whilst also updating thestreamfunction.The reader implementation works on my side when driving the UART for performing Modbus requests.
If there's anything that should be changed don't hesitate to do so: these are my first steps with Zig!
Thanks a ton for your time.