From 42088f938ed3fa4fb485aed9ee587fb18b86e992 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 5 Mar 2021 19:04:42 +0100 Subject: [PATCH] attiny: remove dummy UART I think it's better not to provide a UART0 global at all than one that does nothing. --- src/machine/machine_atmega.go | 6 ++++++ src/machine/machine_attiny.go | 17 ----------------- src/machine/machine_avr.go | 6 ------ src/machine/uart.go | 2 +- src/runtime/runtime_atmega.go | 9 +++++++++ src/runtime/runtime_attiny.go | 7 +++++++ src/runtime/runtime_avr.go | 9 --------- 7 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/machine/machine_atmega.go b/src/machine/machine_atmega.go index feba3b76..7bfdb9ca 100644 --- a/src/machine/machine_atmega.go +++ b/src/machine/machine_atmega.go @@ -114,6 +114,12 @@ func (i2c I2C) readByte() byte { return byte(avr.TWDR.Get()) } +// UART +var ( + // UART0 is the hardware serial port on the AVR. + UART0 = UART{Buffer: NewRingBuffer()} +) + // UART on the AVR. type UART struct { Buffer *RingBuffer diff --git a/src/machine/machine_attiny.go b/src/machine/machine_attiny.go index ecafae87..402b4e31 100644 --- a/src/machine/machine_attiny.go +++ b/src/machine/machine_attiny.go @@ -2,23 +2,6 @@ package machine -// UART on the AVR is a dummy implementation. UART has not been implemented for ATtiny -// devices. -type UART struct { - Buffer *RingBuffer -} - -// Configure is a dummy implementation. UART has not been implemented for ATtiny -// devices. -func (uart UART) Configure(config UARTConfig) { -} - -// WriteByte is a dummy implementation. UART has not been implemented for ATtiny -// devices. -func (uart UART) WriteByte(c byte) error { - return nil -} - // Tx is a dummy implementation. I2C has not been implemented for ATtiny // devices. func (i2c I2C) Tx(addr uint16, w, r []byte) error { diff --git a/src/machine/machine_avr.go b/src/machine/machine_avr.go index d7db15ae..68626bd1 100644 --- a/src/machine/machine_avr.go +++ b/src/machine/machine_avr.go @@ -148,9 +148,3 @@ type I2C struct { // I2C0 is the only I2C interface on most AVRs. var I2C0 = I2C{} - -// UART -var ( - // UART0 is the hardware serial port on the AVR. - UART0 = UART{Buffer: NewRingBuffer()} -) diff --git a/src/machine/uart.go b/src/machine/uart.go index 40d2d99c..971ff23e 100644 --- a/src/machine/uart.go +++ b/src/machine/uart.go @@ -1,4 +1,4 @@ -// +build avr esp nrf sam sifive stm32 k210 nxp +// +build atmega esp nrf sam sifive stm32 k210 nxp package machine diff --git a/src/runtime/runtime_atmega.go b/src/runtime/runtime_atmega.go index 9e1e6cbf..6d02e071 100644 --- a/src/runtime/runtime_atmega.go +++ b/src/runtime/runtime_atmega.go @@ -4,8 +4,17 @@ package runtime import ( "device/avr" + "machine" ) +func initUART() { + machine.UART0.Configure(machine.UARTConfig{}) +} + +func putchar(c byte) { + machine.UART0.WriteByte(c) +} + // Sleep for a given period. The period is defined by the WDT peripheral, and is // on most chips (at least) 3 bits wide, in powers of two from 16ms to 2s // (0=16ms, 1=32ms, 2=64ms...). Note that the WDT is not very accurate: it can diff --git a/src/runtime/runtime_attiny.go b/src/runtime/runtime_attiny.go index e0f6cc2e..9f783937 100644 --- a/src/runtime/runtime_attiny.go +++ b/src/runtime/runtime_attiny.go @@ -6,6 +6,13 @@ import ( "device/avr" ) +func initUART() { +} + +func putchar(c byte) { + // UART is not supported. +} + func sleepWDT(period uint8) { // TODO: use the watchdog timer instead of a busy loop. for i := 0x45; i != 0; i-- { diff --git a/src/runtime/runtime_avr.go b/src/runtime/runtime_avr.go index ae8a4d41..8365b7f8 100644 --- a/src/runtime/runtime_avr.go +++ b/src/runtime/runtime_avr.go @@ -4,7 +4,6 @@ package runtime import ( "device/avr" - "machine" "unsafe" ) @@ -59,14 +58,6 @@ func init() { initUART() } -func initUART() { - machine.UART0.Configure(machine.UARTConfig{}) -} - -func putchar(c byte) { - machine.UART0.WriteByte(c) -} - const asyncScheduler = false const tickNanos = 1024 * 16384 // roughly 16ms in nanoseconds