mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 13:03:39 +00:00
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:
committed by
GitHub
parent
c83f712c17
commit
a7b205c26c
+20
-4
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user