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.
This commit is contained in:
Ayke van Laethem
2021-05-13 12:32:12 +02:00
committed by Ron Evans
parent 7c949ad386
commit aa5b8d0df7
46 changed files with 246 additions and 179 deletions
+4 -3
View File
@@ -124,7 +124,8 @@ func (i2c *I2C) readByte() byte {
// UART
var (
// UART0 is the hardware serial port on the AVR.
UART0 = UART{Buffer: NewRingBuffer()}
UART0 = &_UART0
_UART0 = UART{Buffer: NewRingBuffer()}
)
// UART on the AVR.
@@ -133,7 +134,7 @@ type UART struct {
}
// Configure the UART on the AVR. Defaults to 9600 baud on Arduino.
func (uart UART) Configure(config UARTConfig) {
func (uart *UART) Configure(config UARTConfig) {
if config.BaudRate == 0 {
config.BaudRate = 9600
}
@@ -165,7 +166,7 @@ func (uart UART) Configure(config UARTConfig) {
}
// WriteByte writes a byte of data to the UART.
func (uart UART) WriteByte(c byte) error {
func (uart *UART) WriteByte(c byte) error {
// Wait until UART buffer is not busy.
for !avr.UCSR0A.HasBits(avr.UCSR0A_UDRE0) {
}