Skip to content

Commit

Permalink
Added no-op io.Reader implementation to machine.NullSerial
Browse files Browse the repository at this point in the history
  • Loading branch information
bgould committed Jan 29, 2022
1 parent a7a69d3 commit 277b3f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/machine/machine_rp2040_gpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"unsafe"
)

type io struct {
type rpio struct {
status volatile.Register32
ctrl volatile.Register32
}
Expand All @@ -22,7 +22,7 @@ type irqCtrl struct {
}

type ioBank0Type struct {
io [30]io
io [30]rpio
intR [4]volatile.Register32
proc0IRQctrl irqCtrl
proc1IRQctrl irqCtrl
Expand Down
16 changes: 15 additions & 1 deletion src/machine/serial.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package machine

import "errors"
import (
"errors"
"io"
)

var errNoByte = errors.New("machine: no byte read")

Expand Down Expand Up @@ -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{}
)

0 comments on commit 277b3f7

Please sign in to comment.