diff options
Diffstat (limited to 'src/machine/uart.go')
-rw-r--r-- | src/machine/uart.go | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/machine/uart.go b/src/machine/uart.go index 37d322332..eeeb7d6a0 100644 --- a/src/machine/uart.go +++ b/src/machine/uart.go @@ -59,11 +59,27 @@ func (uart *UART) Read(data []byte) (n int, err error) { return size, nil } -// Write data to the UART. +// 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 _, v := range data { - uart.WriteByte(v) + 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 } |