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
+5 -4
View File
@@ -338,10 +338,11 @@ type UART struct {
}
var (
UART0 = UART{Bus: kendryte.UARTHS, Buffer: NewRingBuffer()}
UART0 = &_UART0
_UART0 = UART{Bus: kendryte.UARTHS, Buffer: NewRingBuffer()}
)
func (uart UART) Configure(config UARTConfig) {
func (uart *UART) Configure(config UARTConfig) {
// Use default baudrate if not set.
if config.BaudRate == 0 {
@@ -366,7 +367,7 @@ func (uart UART) Configure(config UARTConfig) {
// Enable interrupts on receive.
uart.Bus.IE.Set(kendryte.UARTHS_IE_RXWM)
intr := interrupt.New(kendryte.IRQ_UARTHS, UART0.handleInterrupt)
intr := interrupt.New(kendryte.IRQ_UARTHS, _UART0.handleInterrupt)
intr.SetPriority(5)
intr.Enable()
}
@@ -383,7 +384,7 @@ func (uart *UART) handleInterrupt(interrupt.Interrupt) {
uart.Receive(c)
}
func (uart UART) WriteByte(c byte) {
func (uart *UART) WriteByte(c byte) {
for uart.Bus.TXDATA.Get()&kendryte.UARTHS_TXDATA_FULL != 0 {
}