aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/machine/uart.go
diff options
context:
space:
mode:
authorPatricio Whittingslow <[email protected]>2023-07-15 11:24:53 -0300
committerGitHub <[email protected]>2023-07-15 11:24:53 -0300
commita7b205c26cab4f87d9b2e5e845482cd206ba1daf (patch)
tree5b47320a07339d7da8e7cd7dfae72224f9f3f48c /src/machine/uart.go
parentc83f712c17b6024d2cc3130db1d7bb0899e7b419 (diff)
downloadtinygo-a7b205c26cab4f87d9b2e5e845482cd206ba1daf.tar.gz
tinygo-a7b205c26cab4f87d9b2e5e845482cd206ba1daf.zip
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
Diffstat (limited to 'src/machine/uart.go')
-rw-r--r--src/machine/uart.go22
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
}