machine.UART refactor (#3832)

* add gosched calls to UART

* add UART.flush() stubs for all supported architectures

* add comment un uart.go on flush functionality

* uart.writeByte as base of UART usage

* fix NXP having duplicate WriteByte

* fix writeByte not returning error on some platforms

* add flush method for fe310 device

* check for error in WriteByte call to writeByte
This commit is contained in:
Patricio Whittingslow
2023-07-15 11:24:53 -03:00
committed by GitHub
parent c83f712c17
commit a7b205c26c
14 changed files with 69 additions and 19 deletions
+20 -4
View File
@@ -59,11 +59,27 @@ func (uart *UART) Read(data []byte) (n int, err error) {
return size, nil
}
// Write data to the UART.
func (uart *UART) Write(data []byte) (n int, err error) {
for _, v := range data {
uart.WriteByte(v)
// WriteByte writes a byte of data over the UART's Tx.
// This function blocks until the data is finished being sent.
func (uart *UART) WriteByte(c byte) error {
err := uart.writeByte(c)
if err != nil {
return err
}
uart.flush() // flush() blocks until all data has been transmitted.
return nil
}
// Write data over the UART's Tx.
// This function blocks until the data is finished being sent.
func (uart *UART) Write(data []byte) (n int, err error) {
for i, v := range data {
err = uart.writeByte(v)
if err != nil {
return i, err
}
}
uart.flush() // flush() blocks until all data has been transmitted.
return len(data), nil
}