Skip to content

Commit 42088f9

Browse files
aykevldeadprogram
authored andcommitted
attiny: remove dummy UART
I think it's better not to provide a UART0 global at all than one that does nothing.
1 parent c60c36f commit 42088f9

File tree

7 files changed

+23
-33
lines changed

7 files changed

+23
-33
lines changed

src/machine/machine_atmega.go

+6
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ func (i2c I2C) readByte() byte {
114114
return byte(avr.TWDR.Get())
115115
}
116116

117+
// UART
118+
var (
119+
// UART0 is the hardware serial port on the AVR.
120+
UART0 = UART{Buffer: NewRingBuffer()}
121+
)
122+
117123
// UART on the AVR.
118124
type UART struct {
119125
Buffer *RingBuffer

src/machine/machine_attiny.go

-17
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,6 @@
22

33
package machine
44

5-
// UART on the AVR is a dummy implementation. UART has not been implemented for ATtiny
6-
// devices.
7-
type UART struct {
8-
Buffer *RingBuffer
9-
}
10-
11-
// Configure is a dummy implementation. UART has not been implemented for ATtiny
12-
// devices.
13-
func (uart UART) Configure(config UARTConfig) {
14-
}
15-
16-
// WriteByte is a dummy implementation. UART has not been implemented for ATtiny
17-
// devices.
18-
func (uart UART) WriteByte(c byte) error {
19-
return nil
20-
}
21-
225
// Tx is a dummy implementation. I2C has not been implemented for ATtiny
236
// devices.
247
func (i2c I2C) Tx(addr uint16, w, r []byte) error {

src/machine/machine_avr.go

-6
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,3 @@ type I2C struct {
148148

149149
// I2C0 is the only I2C interface on most AVRs.
150150
var I2C0 = I2C{}
151-
152-
// UART
153-
var (
154-
// UART0 is the hardware serial port on the AVR.
155-
UART0 = UART{Buffer: NewRingBuffer()}
156-
)

src/machine/uart.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build avr esp nrf sam sifive stm32 k210 nxp
1+
// +build atmega esp nrf sam sifive stm32 k210 nxp
22

33
package machine
44

src/runtime/runtime_atmega.go

+9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ package runtime
44

55
import (
66
"device/avr"
7+
"machine"
78
)
89

10+
func initUART() {
11+
machine.UART0.Configure(machine.UARTConfig{})
12+
}
13+
14+
func putchar(c byte) {
15+
machine.UART0.WriteByte(c)
16+
}
17+
918
// Sleep for a given period. The period is defined by the WDT peripheral, and is
1019
// on most chips (at least) 3 bits wide, in powers of two from 16ms to 2s
1120
// (0=16ms, 1=32ms, 2=64ms...). Note that the WDT is not very accurate: it can

src/runtime/runtime_attiny.go

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import (
66
"device/avr"
77
)
88

9+
func initUART() {
10+
}
11+
12+
func putchar(c byte) {
13+
// UART is not supported.
14+
}
15+
916
func sleepWDT(period uint8) {
1017
// TODO: use the watchdog timer instead of a busy loop.
1118
for i := 0x45; i != 0; i-- {

src/runtime/runtime_avr.go

-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package runtime
44

55
import (
66
"device/avr"
7-
"machine"
87
"unsafe"
98
)
109

@@ -59,14 +58,6 @@ func init() {
5958
initUART()
6059
}
6160

62-
func initUART() {
63-
machine.UART0.Configure(machine.UARTConfig{})
64-
}
65-
66-
func putchar(c byte) {
67-
machine.UART0.WriteByte(c)
68-
}
69-
7061
const asyncScheduler = false
7162

7263
const tickNanos = 1024 * 16384 // roughly 16ms in nanoseconds

0 commit comments

Comments
 (0)