Skip to content

Commit

Permalink
Ensure UART implements
Browse files Browse the repository at this point in the history
  • Loading branch information
bgould committed Nov 11, 2023
1 parent 2b21595 commit 5723a0c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/machine/machine_nrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ var (
)

// Configure the UART.
func (uart *UART) Configure(config UARTConfig) {
func (uart *UART) Configure(config UARTConfig) error {
// Default baud rate to 115200.
if config.BaudRate == 0 {
config.BaudRate = 115200
Expand All @@ -196,6 +196,8 @@ func (uart *UART) Configure(config UARTConfig) {
intr := interrupt.New(nrf.IRQ_UART0, _UART0.handleInterrupt)
intr.SetPriority(0xc0) // low priority
intr.Enable()

return nil
}

// SetBaudRate sets the communication speed for the UART.
Expand Down
10 changes: 10 additions & 0 deletions src/machine/serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@ func (ns NullSerial) Buffered() int {
func (ns NullSerial) Write(p []byte) (n int, err error) {
return len(p), nil
}

type Serialer interface {
WriteByte(c byte) error
Write(data []byte) (n int, err error)
Configure(config UARTConfig) error
Buffered() int
ReadByte() (byte, error)
DTR() bool
RTS() bool
}
12 changes: 12 additions & 0 deletions src/machine/uart.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
ParityOdd
)

var _ Serialer = (*UART)(nil)

// To implement the UART interface for a board, you must declare a concrete type as follows:
//
// type UART struct {
Expand Down Expand Up @@ -104,3 +106,13 @@ func (uart *UART) Buffered() int {
func (uart *UART) Receive(data byte) {
uart.Buffer.Put(data)
}

func (uart *UART) DTR() bool {
// Not Implemented ... part of machine.Serialer interface
return false
}

func (uart *UART) RTS() bool {
// Not Implemented ... part of machine.Serialer interface
return false
}
10 changes: 0 additions & 10 deletions src/machine/usb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ var (
USBCDC Serialer
)

type Serialer interface {
WriteByte(c byte) error
Write(data []byte) (n int, err error)
Configure(config UARTConfig) error
Buffered() int
ReadByte() (byte, error)
DTR() bool
RTS() bool
}

var usbDescriptor descriptor.Descriptor

func usbVendorID() uint16 {
Expand Down

0 comments on commit 5723a0c

Please sign in to comment.