From 277b3f71e3d5912c430be16332e0a9470dbcb6ad Mon Sep 17 00:00:00 2001 From: BCG Date: Sat, 29 Jan 2022 10:39:17 -0500 Subject: [PATCH] Added no-op io.Reader implementation to machine.NullSerial --- src/machine/machine_rp2040_gpio.go | 4 ++-- src/machine/serial.go | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/machine/machine_rp2040_gpio.go b/src/machine/machine_rp2040_gpio.go index e20a84c691..642de6bc7d 100644 --- a/src/machine/machine_rp2040_gpio.go +++ b/src/machine/machine_rp2040_gpio.go @@ -10,7 +10,7 @@ import ( "unsafe" ) -type io struct { +type rpio struct { status volatile.Register32 ctrl volatile.Register32 } @@ -22,7 +22,7 @@ type irqCtrl struct { } type ioBank0Type struct { - io [30]io + io [30]rpio intR [4]volatile.Register32 proc0IRQctrl irqCtrl proc1IRQctrl irqCtrl diff --git a/src/machine/serial.go b/src/machine/serial.go index fd02d6ca00..a2449d60fc 100644 --- a/src/machine/serial.go +++ b/src/machine/serial.go @@ -1,6 +1,9 @@ package machine -import "errors" +import ( + "errors" + "io" +) var errNoByte = errors.New("machine: no byte read") @@ -44,3 +47,14 @@ func (ns NullSerial) Buffered() int { func (ns NullSerial) Write(p []byte) (n int, err error) { return len(p), nil } + +// Read is a no-op; always returns that zero bytes were read with no error +func (ns NullSerial) Read(p []byte) (n int, err error) { + return 0, nil +} + +// type check to ensure NullSerial implements interfaces for drivers.UART +var ( + _ io.Reader = NullSerial{} + _ io.Writer = NullSerial{} +)