aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/machine/machine_esp8266.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-05-13 12:32:12 +0200
committerRon Evans <[email protected]>2021-05-13 16:43:37 +0200
commitaa5b8d0df733330147fb7cc2912a9c4fb44a8b47 (patch)
tree8455be579dde2e4398cb6bd4494d0267d1860f8e /src/machine/machine_esp8266.go
parent7c949ad386ef36eb0be100eb54a4190740f6f24d (diff)
downloadtinygo-aa5b8d0df733330147fb7cc2912a9c4fb44a8b47.tar.gz
tinygo-aa5b8d0df733330147fb7cc2912a9c4fb44a8b47.zip
machine: make UART objects pointer receivers
This means that machine.UART0, machine.UART1, etc are of type *machine.UART, not machine.UART. This makes them easier to pass around and avoids surprises when they are passed around by value while they should be passed around by reference. There is a small code size impact in some cases, but it is relatively minor.
Diffstat (limited to 'src/machine/machine_esp8266.go')
-rw-r--r--src/machine/machine_esp8266.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/machine/machine_esp8266.go b/src/machine/machine_esp8266.go
index 19c5dd0af..e8a9ecf64 100644
--- a/src/machine/machine_esp8266.go
+++ b/src/machine/machine_esp8266.go
@@ -140,7 +140,8 @@ func (p Pin) PortMaskClear() (*uint32, uint32) {
}
// UART0 is a hardware UART that supports both TX and RX.
-var UART0 = UART{Buffer: NewRingBuffer()}
+var UART0 = &_UART0
+var _UART0 = UART{Buffer: NewRingBuffer()}
type UART struct {
Buffer *RingBuffer
@@ -148,7 +149,7 @@ type UART struct {
// Configure the UART baud rate. TX and RX pins are fixed by the hardware so
// cannot be modified and will be ignored.
-func (uart UART) Configure(config UARTConfig) {
+func (uart *UART) Configure(config UARTConfig) {
if config.BaudRate == 0 {
config.BaudRate = 115200
}
@@ -157,7 +158,7 @@ func (uart UART) Configure(config UARTConfig) {
// WriteByte writes a single byte to the output buffer. Note that the hardware
// includes a buffer of 128 bytes which will be used first.
-func (uart UART) WriteByte(c byte) error {
+func (uart *UART) WriteByte(c byte) error {
for (esp.UART0.UART_STATUS.Get()>>16)&0xff >= 128 {
// Wait until the TX buffer has room.
}