sipeed / bl602-hal

Hardware Abstract Layer for BL602 RISC-V WiFi + BLE SoC in embedded Rust
Other
74 stars 14 forks source link

Improve behaviour of uart::try_write and uart::try_flush #16

Closed 9names closed 3 years ago

9names commented 3 years ago

try_write is supposed to return nb::Error::WouldBlock if it's not possible to write, but it was ignoring errors. This PR changes it to return nb::Error::WouldBlock when the FIFO is full.

try_flush isn't very documented, but my intuition is that it's supposed to return nb::Error::WouldBlock until everything that was previously written has been fully transmitted (so you can safely turn off the UART peripheral, reset the device, etc) My first attempt just checked if the FIFO had any data in it, but this would return Ok() when the last byte was still being transmitted. The current solution is to return nb::Error::WouldBlock if the FIFO has bytes in it or the TX BUSY bit is set