mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-19 14:14:00 +00:00
all: refactor all current drivers to use new machine.Pin interface
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
@@ -8,24 +8,20 @@ import (
|
|||||||
|
|
||||||
// Device holds the pins and the delay between steps
|
// Device holds the pins and the delay between steps
|
||||||
type Device struct {
|
type Device struct {
|
||||||
pins [4]machine.GPIO
|
pins [4]machine.Pin
|
||||||
stepDelay int32
|
stepDelay int32
|
||||||
stepNumber int32
|
stepNumber int32
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new easystepper driver given 4 pins numbers (not pin object),
|
// New returns a new easystepper driver given 4 pins numbers (not pin object),
|
||||||
// number of steps and rpm
|
// number of steps and rpm
|
||||||
func New(pin1 uint8, pin2 uint8, pin3 uint8, pin4 uint8, steps int32, rpm int32) Device {
|
func New(pin1, pin2, pin3, pin4 machine.Pin, steps int32, rpm int32) Device {
|
||||||
m1 := machine.GPIO{pin1}
|
pin1.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
m1.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
pin2.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
m2 := machine.GPIO{pin2}
|
pin3.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
m2.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
pin4.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
m3 := machine.GPIO{pin3}
|
|
||||||
m3.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
|
||||||
m4 := machine.GPIO{pin4}
|
|
||||||
m4.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
|
||||||
return Device{
|
return Device{
|
||||||
pins: [4]machine.GPIO{m1, m2, m3, m4},
|
pins: [4]machine.Pin{pin1, pin2, pin3, pin4},
|
||||||
stepDelay: 60000000 / (steps * rpm),
|
stepDelay: 60000000 / (steps * rpm),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ const pass = "YOURPASS"
|
|||||||
|
|
||||||
// change these to connect to a different UART or pins for the ESP8266/ESP32
|
// change these to connect to a different UART or pins for the ESP8266/ESP32
|
||||||
var (
|
var (
|
||||||
uart = machine.UART1
|
uart = machine.UART1
|
||||||
tx uint8 = machine.D10
|
tx = machine.D10
|
||||||
rx uint8 = machine.D11
|
rx = machine.D11
|
||||||
|
|
||||||
console = machine.UART0
|
console = machine.UART0
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ const pass = "YOURPASS"
|
|||||||
|
|
||||||
// change these to connect to a different UART or pins for the ESP8266/ESP32
|
// change these to connect to a different UART or pins for the ESP8266/ESP32
|
||||||
var (
|
var (
|
||||||
uart = machine.UART1
|
uart = machine.UART1
|
||||||
tx uint8 = machine.D10
|
tx = machine.D10
|
||||||
rx uint8 = machine.D11
|
rx = machine.D11
|
||||||
|
|
||||||
console = machine.UART0
|
console = machine.UART0
|
||||||
|
|
||||||
@@ -38,8 +38,8 @@ func main() {
|
|||||||
adaptor = espat.New(uart)
|
adaptor = espat.New(uart)
|
||||||
adaptor.Configure()
|
adaptor.Configure()
|
||||||
|
|
||||||
readyled := machine.GPIO{machine.LED}
|
readyled := machine.LED
|
||||||
readyled.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
readyled.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
readyled.High()
|
readyled.High()
|
||||||
|
|
||||||
// first check if connected
|
// first check if connected
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ const hubIP = "0.0.0.0"
|
|||||||
|
|
||||||
// change these to connect to a different UART or pins for the ESP8266/ESP32
|
// change these to connect to a different UART or pins for the ESP8266/ESP32
|
||||||
var (
|
var (
|
||||||
uart = machine.UART1
|
uart = machine.UART1
|
||||||
tx uint8 = machine.D10
|
tx = machine.D10
|
||||||
rx uint8 = machine.D11
|
rx = machine.D11
|
||||||
|
|
||||||
console = machine.UART0
|
console = machine.UART0
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
lcd, _ := hd44780.NewGPIO4Bit(
|
lcd, _ := hd44780.NewGPIO4Bit(
|
||||||
[]uint8{machine.P0, machine.P1, machine.P2, machine.P3},
|
[]machine.Pin{machine.P0, machine.P1, machine.P2, machine.P3},
|
||||||
machine.P4,
|
machine.P4,
|
||||||
machine.P5,
|
machine.P5,
|
||||||
machine.P6,
|
machine.P6,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
lcd, _ := hd44780.NewGPIO4Bit(
|
lcd, _ := hd44780.NewGPIO4Bit(
|
||||||
[]uint8{machine.P0, machine.P1, machine.P2, machine.P3},
|
[]machine.Pin{machine.P0, machine.P1, machine.P2, machine.P3},
|
||||||
machine.P4,
|
machine.P4,
|
||||||
machine.P5,
|
machine.P5,
|
||||||
machine.P6,
|
machine.P6,
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
dcPin := machine.GPIO{machine.P3}
|
dcPin := machine.P3
|
||||||
dcPin.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
rstPin := machine.GPIO{machine.P4}
|
rstPin := machine.P4
|
||||||
rstPin.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
scePin := machine.GPIO{machine.P5}
|
scePin := machine.P5
|
||||||
scePin.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
scePin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
|
||||||
machine.SPI0.Configure(machine.SPIConfig{})
|
machine.SPI0.Configure(machine.SPIConfig{})
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
dcPin := machine.GPIO{machine.P3}
|
dcPin := machine.P3
|
||||||
dcPin.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
rstPin := machine.GPIO{machine.P4}
|
rstPin := machine.P4
|
||||||
rstPin.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
scePin := machine.GPIO{machine.P5}
|
scePin := machine.P5
|
||||||
scePin.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
scePin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
|
||||||
machine.SPI0.Configure(machine.SPIConfig{})
|
machine.SPI0.Configure(machine.SPIConfig{})
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
neo := machine.GPIO{machine.NEOPIXELS}
|
neo := machine.NEOPIXELS
|
||||||
neo.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
neo.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
|
||||||
ws := ws2812.New(neo)
|
ws := ws2812.New(neo)
|
||||||
leds := make([]color.RGBA, 10)
|
leds := make([]color.RGBA, 10)
|
||||||
|
|||||||
+31
-36
@@ -7,36 +7,31 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type GPIO struct {
|
type GPIO struct {
|
||||||
dataPins []machine.GPIO
|
dataPins []machine.Pin
|
||||||
e machine.GPIO
|
en machine.Pin
|
||||||
rw machine.GPIO
|
rw machine.Pin
|
||||||
rs machine.GPIO
|
rs machine.Pin
|
||||||
|
|
||||||
write func(data byte)
|
write func(data byte)
|
||||||
read func() byte
|
read func() byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGPIO(dataPins []uint8, e, rs, rw uint8, mode byte) Device {
|
func newGPIO(dataPins []machine.Pin, en, rs, rw machine.Pin, mode byte) Device {
|
||||||
|
pins := make([]machine.Pin, len(dataPins))
|
||||||
pins := make([]machine.GPIO, len(dataPins))
|
|
||||||
for i := 0; i < len(dataPins); i++ {
|
for i := 0; i < len(dataPins); i++ {
|
||||||
m := machine.GPIO{Pin: dataPins[i]}
|
dataPins[i].Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
m.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
pins[i] = dataPins[i]
|
||||||
pins[i] = m
|
|
||||||
}
|
}
|
||||||
enable := machine.GPIO{e}
|
en.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
enable.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
rs.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
registerSelect := machine.GPIO{rs}
|
rw.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
registerSelect.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
rw.Low()
|
||||||
readWrite := machine.GPIO{rw}
|
|
||||||
readWrite.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
|
||||||
readWrite.Low()
|
|
||||||
|
|
||||||
gpio := GPIO{
|
gpio := GPIO{
|
||||||
dataPins: pins,
|
dataPins: pins,
|
||||||
e: enable,
|
en: en,
|
||||||
rs: registerSelect,
|
rs: rs,
|
||||||
rw: readWrite,
|
rw: rw,
|
||||||
}
|
}
|
||||||
|
|
||||||
if mode == DATA_LENGTH_4BIT {
|
if mode == DATA_LENGTH_4BIT {
|
||||||
@@ -73,19 +68,19 @@ func (g *GPIO) Write(data []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GPIO) write8BitMode(data byte) {
|
func (g *GPIO) write8BitMode(data byte) {
|
||||||
g.e.High()
|
g.en.High()
|
||||||
g.setPins(data)
|
g.setPins(data)
|
||||||
g.e.Low()
|
g.en.Low()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GPIO) write4BitMode(data byte) {
|
func (g *GPIO) write4BitMode(data byte) {
|
||||||
g.e.High()
|
g.en.High()
|
||||||
g.setPins(data >> 4)
|
g.setPins(data >> 4)
|
||||||
g.e.Low()
|
g.en.Low()
|
||||||
|
|
||||||
g.e.High()
|
g.en.High()
|
||||||
g.setPins(data)
|
g.setPins(data)
|
||||||
g.e.Low()
|
g.en.Low()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read reads len(data) bytes from display RAM to data starting from RAM address counter position
|
// Read reads len(data) bytes from display RAM to data starting from RAM address counter position
|
||||||
@@ -95,35 +90,35 @@ func (g *GPIO) Read(data []byte) (n int, err error) {
|
|||||||
return 0, errors.New("Length greater than 0 is required")
|
return 0, errors.New("Length greater than 0 is required")
|
||||||
}
|
}
|
||||||
g.rw.High()
|
g.rw.High()
|
||||||
g.reconfigureGPIOMode(machine.GPIO_INPUT)
|
g.reconfigureGPIOMode(machine.PinInput)
|
||||||
for i := 0; i < len(data); i++ {
|
for i := 0; i < len(data); i++ {
|
||||||
data[i] = g.read()
|
data[i] = g.read()
|
||||||
n++
|
n++
|
||||||
}
|
}
|
||||||
g.reconfigureGPIOMode(machine.GPIO_OUTPUT)
|
g.reconfigureGPIOMode(machine.PinInput)
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GPIO) read4BitMode() byte {
|
func (g *GPIO) read4BitMode() byte {
|
||||||
g.e.High()
|
g.en.High()
|
||||||
data := (g.pins() << 4 & 0xF0)
|
data := (g.pins() << 4 & 0xF0)
|
||||||
g.e.Low()
|
g.en.Low()
|
||||||
g.e.High()
|
g.en.High()
|
||||||
data |= (g.pins() & 0x0F)
|
data |= (g.pins() & 0x0F)
|
||||||
g.e.Low()
|
g.en.Low()
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GPIO) read8BitMode() byte {
|
func (g *GPIO) read8BitMode() byte {
|
||||||
g.e.High()
|
g.en.High()
|
||||||
data := g.pins()
|
data := g.pins()
|
||||||
g.e.Low()
|
g.en.Low()
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GPIO) reconfigureGPIOMode(mode machine.GPIOMode) {
|
func (g *GPIO) reconfigureGPIOMode(mode machine.PinMode) {
|
||||||
for i := 0; i < len(g.dataPins); i++ {
|
for i := 0; i < len(g.dataPins); i++ {
|
||||||
g.dataPins[i].Configure(machine.GPIOConfig{Mode: mode})
|
g.dataPins[i].Configure(machine.PinConfig{Mode: mode})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -3,6 +3,7 @@ package hd44780
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewGPIO4Bit returns 4bit data length HD44780 driver. Datapins are LCD DB pins starting from DB4 to DB7
|
// NewGPIO4Bit returns 4bit data length HD44780 driver. Datapins are LCD DB pins starting from DB4 to DB7
|
||||||
func NewGPIO4Bit(dataPins []uint8, e, rs, rw uint8) (Device, error) {
|
func NewGPIO4Bit(dataPins []machine.Pin, e, rs, rw machine.Pin) (Device, error) {
|
||||||
const fourBitMode = 4
|
const fourBitMode = 4
|
||||||
if len(dataPins) != fourBitMode {
|
if len(dataPins) != fourBitMode {
|
||||||
return Device{}, errors.New("4 pins are required in data slice (D4-D7) when HD44780 is used in 4 bit mode")
|
return Device{}, errors.New("4 pins are required in data slice (D4-D7) when HD44780 is used in 4 bit mode")
|
||||||
@@ -47,7 +48,7 @@ func NewGPIO4Bit(dataPins []uint8, e, rs, rw uint8) (Device, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewGPIO8Bit returns 8bit data length HD44780 driver. Datapins are LCD DB pins starting from DB0 to DB7
|
// NewGPIO8Bit returns 8bit data length HD44780 driver. Datapins are LCD DB pins starting from DB0 to DB7
|
||||||
func NewGPIO8Bit(dataPins []uint8, e, rs, rw uint8) (Device, error) {
|
func NewGPIO8Bit(dataPins []machine.Pin, e, rs, rw machine.Pin) (Device, error) {
|
||||||
const eightBitMode = 8
|
const eightBitMode = 8
|
||||||
if len(dataPins) != eightBitMode {
|
if len(dataPins) != eightBitMode {
|
||||||
return Device{}, errors.New("8 pins are required in data slice (D0-D7) when HD44780 is used in 8 bit mode")
|
return Device{}, errors.New("8 pins are required in data slice (D0-D7) when HD44780 is used in 8 bit mode")
|
||||||
|
|||||||
+19
-25
@@ -21,12 +21,12 @@ type Config struct {
|
|||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus machine.SPI
|
bus machine.SPI
|
||||||
a machine.GPIO
|
a machine.Pin
|
||||||
b machine.GPIO
|
b machine.Pin
|
||||||
c machine.GPIO
|
c machine.Pin
|
||||||
d machine.GPIO
|
d machine.Pin
|
||||||
oe machine.GPIO
|
oe machine.Pin
|
||||||
lat machine.GPIO
|
lat machine.Pin
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
brightness uint8
|
brightness uint8
|
||||||
@@ -51,28 +51,22 @@ type Device struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new HUB75 driver. Pass in a fully configured SPI bus.
|
// New returns a new HUB75 driver. Pass in a fully configured SPI bus.
|
||||||
func New(b machine.SPI, latPin uint8, oePin uint8, aPin uint8, bPin uint8, cPin uint8, dPin uint8) Device {
|
func New(b machine.SPI, latPin, oePin, aPin, bPin, cPin, dPin machine.Pin) Device {
|
||||||
pinA := machine.GPIO{aPin}
|
aPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinA.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
bPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinB := machine.GPIO{bPin}
|
cPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinB.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
dPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinC := machine.GPIO{cPin}
|
oePin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinC.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
latPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinD := machine.GPIO{dPin}
|
|
||||||
pinD.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
|
||||||
pinOE := machine.GPIO{oePin}
|
|
||||||
pinOE.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
|
||||||
pinLAT := machine.GPIO{latPin}
|
|
||||||
pinLAT.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
|
||||||
|
|
||||||
return Device{
|
return Device{
|
||||||
bus: b,
|
bus: b,
|
||||||
a: pinA,
|
a: aPin,
|
||||||
b: pinB,
|
b: bPin,
|
||||||
c: pinC,
|
c: cPin,
|
||||||
d: pinD,
|
d: dPin,
|
||||||
oe: pinOE,
|
oe: oePin,
|
||||||
lat: pinLAT,
|
lat: latPin,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
pin [12]*machine.GPIO
|
pin [12]machine.Pin
|
||||||
buffer [3][9]bool
|
buffer [3][9]bool
|
||||||
rotation uint8
|
rotation uint8
|
||||||
}
|
}
|
||||||
@@ -59,9 +59,9 @@ func New() Device {
|
|||||||
func (d *Device) Configure(cfg Config) {
|
func (d *Device) Configure(cfg Config) {
|
||||||
d.SetRotation(cfg.Rotation)
|
d.SetRotation(cfg.Rotation)
|
||||||
|
|
||||||
for i := uint8(machine.LED_COL_1); i <= machine.LED_ROW_3; i++ {
|
for i := machine.LED_COL_1; i <= machine.LED_ROW_3; i++ {
|
||||||
d.pin[i-machine.LED_COL_1] = &machine.GPIO{i}
|
d.pin[i-machine.LED_COL_1] = i
|
||||||
d.pin[i-machine.LED_COL_1].Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
d.pin[i-machine.LED_COL_1].Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
}
|
}
|
||||||
d.ClearDisplay()
|
d.ClearDisplay()
|
||||||
d.DisableAll()
|
d.DisableAll()
|
||||||
|
|||||||
+4
-4
@@ -13,9 +13,9 @@ import (
|
|||||||
// Device wraps an SPI connection.
|
// Device wraps an SPI connection.
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus machine.SPI
|
bus machine.SPI
|
||||||
dcPin machine.GPIO
|
dcPin machine.Pin
|
||||||
rstPin machine.GPIO
|
rstPin machine.Pin
|
||||||
scePin machine.GPIO
|
scePin machine.Pin
|
||||||
buffer []byte
|
buffer []byte
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
@@ -28,7 +28,7 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new PCD8544 connection. The SPI bus must already be configured.
|
// New creates a new PCD8544 connection. The SPI bus must already be configured.
|
||||||
func New(bus machine.SPI, dcPin machine.GPIO, rstPin machine.GPIO, scePin machine.GPIO) *Device {
|
func New(bus machine.SPI, dcPin, rstPin, scePin machine.Pin) *Device {
|
||||||
return &Device{
|
return &Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
dcPin: dcPin,
|
dcPin: dcPin,
|
||||||
|
|||||||
+10
-13
@@ -35,9 +35,9 @@ type I2CBus struct {
|
|||||||
|
|
||||||
type SPIBus struct {
|
type SPIBus struct {
|
||||||
wire machine.SPI
|
wire machine.SPI
|
||||||
dcPin machine.GPIO
|
dcPin machine.Pin
|
||||||
resetPin machine.GPIO
|
resetPin machine.Pin
|
||||||
csPin machine.GPIO
|
csPin machine.Pin
|
||||||
}
|
}
|
||||||
|
|
||||||
type Buser interface {
|
type Buser interface {
|
||||||
@@ -59,19 +59,16 @@ func NewI2C(bus machine.I2C) Device {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewSPI creates a new SSD1306 connection. The SPI wire must already be configured.
|
// NewSPI creates a new SSD1306 connection. The SPI wire must already be configured.
|
||||||
func NewSPI(bus machine.SPI, dcPin uint8, resetPin uint8, csPin uint8) Device {
|
func NewSPI(bus machine.SPI, dcPin, resetPin, csPin machine.Pin) Device {
|
||||||
pinDc := machine.GPIO{dcPin}
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinDc.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinReset := machine.GPIO{resetPin}
|
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinReset.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
|
||||||
pinCs := machine.GPIO{csPin}
|
|
||||||
pinCs.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
|
||||||
return Device{
|
return Device{
|
||||||
bus: &SPIBus{
|
bus: &SPIBus{
|
||||||
wire: bus,
|
wire: bus,
|
||||||
dcPin: pinDc,
|
dcPin: dcPin,
|
||||||
resetPin: pinReset,
|
resetPin: resetPin,
|
||||||
csPin: pinCs,
|
csPin: csPin,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ type Device struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new thermistor driver given an ADC pin.
|
// New returns a new thermistor driver given an ADC pin.
|
||||||
func New(pin uint8) Device {
|
func New(pin machine.Pin) Device {
|
||||||
adc := machine.ADC{pin}
|
adc := machine.ADC{pin}
|
||||||
return Device{
|
return Device{
|
||||||
adc: &adc,
|
adc: &adc,
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ type Config struct {
|
|||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus machine.SPI
|
bus machine.SPI
|
||||||
cs machine.GPIO
|
cs machine.Pin
|
||||||
dc machine.GPIO
|
dc machine.Pin
|
||||||
rst machine.GPIO
|
rst machine.Pin
|
||||||
busy machine.GPIO
|
busy machine.Pin
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
buffer []uint8
|
buffer []uint8
|
||||||
@@ -44,21 +44,17 @@ var lutPartialUpdate = [30]uint8{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus.
|
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus.
|
||||||
func New(bus machine.SPI, csPin uint8, dcPin uint8, rstPin uint8, busyPin uint8) Device {
|
func New(bus machine.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
|
||||||
pinCs := machine.GPIO{csPin}
|
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinCs.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinDc := machine.GPIO{dcPin}
|
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinDc.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||||
pinRst := machine.GPIO{rstPin}
|
|
||||||
pinRst.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
|
||||||
pinBusy := machine.GPIO{busyPin}
|
|
||||||
pinBusy.Configure(machine.GPIOConfig{Mode: machine.GPIO_INPUT})
|
|
||||||
return Device{
|
return Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
cs: pinCs,
|
cs: csPin,
|
||||||
dc: pinDc,
|
dc: dcPin,
|
||||||
rst: pinRst,
|
rst: rstPin,
|
||||||
busy: pinBusy,
|
busy: busyPin,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ type Config struct {
|
|||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus machine.SPI
|
bus machine.SPI
|
||||||
cs machine.GPIO
|
cs machine.Pin
|
||||||
dc machine.GPIO
|
dc machine.Pin
|
||||||
rst machine.GPIO
|
rst machine.Pin
|
||||||
busy machine.GPIO
|
busy machine.Pin
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
buffer [][]uint8
|
buffer [][]uint8
|
||||||
@@ -31,21 +31,17 @@ type Device struct {
|
|||||||
type Color uint8
|
type Color uint8
|
||||||
|
|
||||||
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus.
|
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus.
|
||||||
func New(bus machine.SPI, csPin uint8, dcPin uint8, rstPin uint8, busyPin uint8) Device {
|
func New(bus machine.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
|
||||||
pinCs := machine.GPIO{csPin}
|
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinCs.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinDc := machine.GPIO{dcPin}
|
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
pinDc.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||||
pinRst := machine.GPIO{rstPin}
|
|
||||||
pinRst.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
|
||||||
pinBusy := machine.GPIO{busyPin}
|
|
||||||
pinBusy.Configure(machine.GPIOConfig{Mode: machine.GPIO_INPUT})
|
|
||||||
return Device{
|
return Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
cs: pinCs,
|
cs: csPin,
|
||||||
dc: pinDc,
|
dc: dcPin,
|
||||||
rst: pinRst,
|
rst: rstPin,
|
||||||
busy: pinBusy,
|
busy: busyPin,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -8,12 +8,12 @@ import (
|
|||||||
|
|
||||||
// Device wraps a pin object for an easy driver interface.
|
// Device wraps a pin object for an easy driver interface.
|
||||||
type Device struct {
|
type Device struct {
|
||||||
Pin machine.GPIO
|
Pin machine.Pin
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new WS2812 driver. It does not touch the pin object: you have
|
// New returns a new WS2812 driver. It does not touch the pin object: you have
|
||||||
// to configure it as an output pin before calling New.
|
// to configure it as an output pin before calling New.
|
||||||
func New(pin machine.GPIO) Device {
|
func New(pin machine.Pin) Device {
|
||||||
return Device{pin}
|
return Device{pin}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user