all: use interfaces for UART objects

This makes it possible to replace UART objects with dummy
implementations, for example. Or allows changing the `machine.UART` type
to `*machine.UART` without breaking compatibility.
This commit is contained in:
Ayke van Laethem
2021-03-06 00:27:42 +01:00
committed by Ron Evans
parent 1345bc2161
commit e77e9249cd
3 changed files with 17 additions and 6 deletions
+2 -3
View File
@@ -4,7 +4,6 @@ package gps // import "tinygo.org/x/drivers/gps"
import (
"encoding/hex"
"errors"
"machine"
"strings"
"time"
@@ -21,13 +20,13 @@ type Device struct {
buffer []byte
bufIdx int
sentence strings.Builder
uart *machine.UART
uart drivers.UART
bus drivers.I2C
address uint16
}
// NewUART creates a new UART GPS connection. The UART must already be configured.
func NewUART(uart *machine.UART) Device {
func NewUART(uart drivers.UART) Device {
return Device{
uart: uart,
buffer: make([]byte, bufferSize),