mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-14 11:53:41 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c305f9b6f | |||
| 1e4110b5a2 | |||
| e286861661 | |||
| 589bf19b01 | |||
| ff4d15cea9 |
+2
-1
@@ -5,6 +5,7 @@ package apa102 // import "tinygo.org/x/drivers/apa102"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
)
|
)
|
||||||
@@ -36,7 +37,7 @@ func New(b drivers.SPI) *Device {
|
|||||||
|
|
||||||
// NewSoftwareSPI returns a new APA102 driver that will use a software based
|
// NewSoftwareSPI returns a new APA102 driver that will use a software based
|
||||||
// implementation of the SPI protocol.
|
// implementation of the SPI protocol.
|
||||||
func NewSoftwareSPI(sckPin, sdoPin drivers.Pin, delay uint32) *Device {
|
func NewSoftwareSPI(sckPin, sdoPin machine.Pin, delay uint32) *Device {
|
||||||
return New(&bbSPI{SCK: sckPin, SDO: sdoPin, Delay: delay})
|
return New(&bbSPI{SCK: sckPin, SDO: sdoPin, Delay: delay})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-7
@@ -1,8 +1,6 @@
|
|||||||
package apa102
|
package apa102
|
||||||
|
|
||||||
import (
|
import "machine"
|
||||||
"tinygo.org/x/drivers"
|
|
||||||
)
|
|
||||||
|
|
||||||
// bbSPI is a dumb bit-bang implementation of SPI protocol that is hardcoded
|
// bbSPI is a dumb bit-bang implementation of SPI protocol that is hardcoded
|
||||||
// to mode 0 and ignores trying to receive data. Just enough for the APA102.
|
// to mode 0 and ignores trying to receive data. Just enough for the APA102.
|
||||||
@@ -10,14 +8,15 @@ import (
|
|||||||
// most purposes other than the APA102 package. It might be desirable to make
|
// most purposes other than the APA102 package. It might be desirable to make
|
||||||
// this more generic and include it in the TinyGo "machine" package instead.
|
// this more generic and include it in the TinyGo "machine" package instead.
|
||||||
type bbSPI struct {
|
type bbSPI struct {
|
||||||
SCK drivers.Pin
|
SCK machine.Pin
|
||||||
SDO drivers.Pin
|
SDO machine.Pin
|
||||||
Delay uint32
|
Delay uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure sets the SCK and SDO pins to low.
|
// Configure sets up the SCK and SDO pins as outputs and sets them low
|
||||||
// Note that the SCK and SDO pins must already be configured as outputs.
|
|
||||||
func (s *bbSPI) Configure() {
|
func (s *bbSPI) Configure() {
|
||||||
|
s.SCK.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
s.SDO.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
s.SCK.Low()
|
s.SCK.Low()
|
||||||
s.SDO.Low()
|
s.SDO.Low()
|
||||||
if s.Delay == 0 {
|
if s.Delay == 0 {
|
||||||
|
|||||||
+7
-4
@@ -1,6 +1,7 @@
|
|||||||
package bmi160
|
package bmi160
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
@@ -10,7 +11,7 @@ import (
|
|||||||
// also an I2C interface, but it is not yet supported.
|
// also an I2C interface, but it is not yet supported.
|
||||||
type DeviceSPI struct {
|
type DeviceSPI struct {
|
||||||
// Chip select pin
|
// Chip select pin
|
||||||
CSB drivers.Pin
|
CSB machine.Pin
|
||||||
|
|
||||||
buf [7]byte
|
buf [7]byte
|
||||||
|
|
||||||
@@ -21,16 +22,18 @@ type DeviceSPI struct {
|
|||||||
// NewSPI returns a new device driver. The pin and SPI interface are not
|
// NewSPI returns a new device driver. The pin and SPI interface are not
|
||||||
// touched, provide a fully configured SPI object and call Configure to start
|
// touched, provide a fully configured SPI object and call Configure to start
|
||||||
// using this device.
|
// using this device.
|
||||||
func NewSPI(csb drivers.Pin, spi drivers.SPI) *DeviceSPI {
|
func NewSPI(csb machine.Pin, spi drivers.SPI) *DeviceSPI {
|
||||||
return &DeviceSPI{
|
return &DeviceSPI{
|
||||||
CSB: csb, // chip select
|
CSB: csb, // chip select
|
||||||
Bus: spi,
|
Bus: spi,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure configures the BMI160 for use. The CSB pin anf the SPI interface
|
// Configure configures the BMI160 for use. It configures the CSB pin and
|
||||||
// should be configured already. This function configures the BMI160 only.
|
// configures the BMI160, but it does not configure the SPI interface (it is
|
||||||
|
// assumed to be up and running).
|
||||||
func (d *DeviceSPI) Configure() error {
|
func (d *DeviceSPI) Configure() error {
|
||||||
|
d.CSB.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
d.CSB.High()
|
d.CSB.High()
|
||||||
|
|
||||||
// The datasheet recommends doing a register read from address 0x7F to get
|
// The datasheet recommends doing a register read from address 0x7F to get
|
||||||
|
|||||||
+4
-4
@@ -2,20 +2,20 @@
|
|||||||
package buzzer // import "tinygo.org/x/drivers/buzzer"
|
package buzzer // import "tinygo.org/x/drivers/buzzer"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"machine"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Device wraps a GPIO connection to a buzzer.
|
// Device wraps a GPIO connection to a buzzer.
|
||||||
type Device struct {
|
type Device struct {
|
||||||
pin drivers.Pin
|
pin machine.Pin
|
||||||
High bool
|
High bool
|
||||||
BPM float64
|
BPM float64
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new buzzer driver given which pin to use
|
// New returns a new buzzer driver given which pin to use
|
||||||
func New(pin drivers.Pin) Device {
|
func New(pin machine.Pin) Device {
|
||||||
return Device{
|
return Device{
|
||||||
pin: pin,
|
pin: pin,
|
||||||
High: false,
|
High: false,
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ package easystepper // import "tinygo.org/x/drivers/easystepper"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// StepMode determines the coil sequence used to perform a single step
|
// StepMode determines the coil sequence used to perform a single step
|
||||||
@@ -34,7 +33,7 @@ func (sm StepMode) stepCount() uint {
|
|||||||
// DeviceConfig contains the configuration data for a single easystepper driver
|
// DeviceConfig contains the configuration data for a single easystepper driver
|
||||||
type DeviceConfig struct {
|
type DeviceConfig struct {
|
||||||
// Pin1 ... Pin4 determines the pins to configure and use for the device
|
// Pin1 ... Pin4 determines the pins to configure and use for the device
|
||||||
Pin1, Pin2, Pin3, Pin4 drivers.Pin
|
Pin1, Pin2, Pin3, Pin4 machine.Pin
|
||||||
// StepCount is the number of steps required to perform a full revolution of the stepper motor
|
// StepCount is the number of steps required to perform a full revolution of the stepper motor
|
||||||
StepCount uint
|
StepCount uint
|
||||||
// RPM determines the speed of the stepper motor in 'Revolutions per Minute'
|
// RPM determines the speed of the stepper motor in 'Revolutions per Minute'
|
||||||
@@ -47,12 +46,12 @@ type DeviceConfig struct {
|
|||||||
type DualDeviceConfig struct {
|
type DualDeviceConfig struct {
|
||||||
DeviceConfig
|
DeviceConfig
|
||||||
// Pin5 ... Pin8 determines the pins to configure and use for the second device
|
// Pin5 ... Pin8 determines the pins to configure and use for the second device
|
||||||
Pin5, Pin6, Pin7, Pin8 drivers.Pin
|
Pin5, Pin6, Pin7, Pin8 machine.Pin
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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]drivers.Pin
|
pins [4]machine.Pin
|
||||||
stepDelay time.Duration
|
stepDelay time.Duration
|
||||||
stepNumber uint8
|
stepNumber uint8
|
||||||
stepMode StepMode
|
stepMode StepMode
|
||||||
@@ -69,15 +68,17 @@ func New(config DeviceConfig) (*Device, error) {
|
|||||||
return nil, errors.New("config.StepCount and config.RPM must be > 0")
|
return nil, errors.New("config.StepCount and config.RPM must be > 0")
|
||||||
}
|
}
|
||||||
return &Device{
|
return &Device{
|
||||||
pins: [4]drivers.Pin{config.Pin1, config.Pin2, config.Pin3, config.Pin4},
|
pins: [4]machine.Pin{config.Pin1, config.Pin2, config.Pin3, config.Pin4},
|
||||||
stepDelay: time.Second * 60 / time.Duration((config.StepCount * config.RPM)),
|
stepDelay: time.Second * 60 / time.Duration((config.StepCount * config.RPM)),
|
||||||
stepMode: config.Mode,
|
stepMode: config.Mode,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure does nothing, as it assumes that the pins of the Device have already
|
// Configure configures the pins of the Device
|
||||||
// been configured by the user as outputs.
|
|
||||||
func (d *Device) Configure() {
|
func (d *Device) Configure() {
|
||||||
|
for _, pin := range d.pins {
|
||||||
|
pin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDual returns a new dual easystepper driver given 8 pins, number of steps and rpm
|
// NewDual returns a new dual easystepper driver given 8 pins, number of steps and rpm
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
// This example shows how to use 128x64 display over I2C
|
|
||||||
// Tested on Seeeduino XIAO Expansion Board https://wiki.seeedstudio.com/Seeeduino-XIAO-Expansion-Board/
|
|
||||||
//
|
|
||||||
// According to manual, I2C address of the display is 0x78, but that's 8-bit address.
|
|
||||||
// TinyGo operates on 7-bit addresses and respective 7-bit address would be 0x3C, which we use below.
|
|
||||||
//
|
|
||||||
// To learn more about different types of I2C addresses, please see following page
|
|
||||||
// https://www.totalphase.com/support/articles/200349176-7-bit-8-bit-and-10-bit-I2C-Slave-Addressing
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
|
|
||||||
"image/color"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ssd1306"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
machine.I2C0.Configure(machine.I2CConfig{
|
|
||||||
Frequency: machine.TWI_FREQ_400KHZ,
|
|
||||||
})
|
|
||||||
|
|
||||||
display := ssd1306.NewI2C(machine.I2C0)
|
|
||||||
display.Configure(ssd1306.Config{
|
|
||||||
Address: 0x3C,
|
|
||||||
Width: 128,
|
|
||||||
Height: 64,
|
|
||||||
})
|
|
||||||
|
|
||||||
display.ClearDisplay()
|
|
||||||
|
|
||||||
x := int16(0)
|
|
||||||
y := int16(0)
|
|
||||||
deltaX := int16(1)
|
|
||||||
deltaY := int16(1)
|
|
||||||
for {
|
|
||||||
pixel := display.GetPixel(x, y)
|
|
||||||
c := color.RGBA{255, 255, 255, 255}
|
|
||||||
if pixel {
|
|
||||||
c = color.RGBA{0, 0, 0, 255}
|
|
||||||
}
|
|
||||||
display.SetPixel(x, y, c)
|
|
||||||
display.Display()
|
|
||||||
|
|
||||||
x += deltaX
|
|
||||||
y += deltaY
|
|
||||||
|
|
||||||
if x == 0 || x == 127 {
|
|
||||||
deltaX = -deltaX
|
|
||||||
}
|
|
||||||
|
|
||||||
if y == 0 || y == 63 {
|
|
||||||
deltaY = -deltaY
|
|
||||||
}
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"machine"
|
|
||||||
|
|
||||||
"image/color"
|
"image/color"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -10,21 +8,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
machine.I2C0.Configure(machine.I2CConfig{
|
// Thumby will have preset size.
|
||||||
Frequency: machine.TWI_FREQ_400KHZ,
|
// If not compiling for thumby the width and height will be whatever we suggest
|
||||||
})
|
const suggestHeight = 32
|
||||||
|
const suggestWidth = 128
|
||||||
display := ssd1306.NewI2C(machine.I2C0)
|
var display *ssd1306.Device
|
||||||
display.Configure(ssd1306.Config{
|
var err error
|
||||||
Address: ssd1306.Address_128_32,
|
display, err = makeSSD1306(suggestWidth, suggestHeight)
|
||||||
Width: 128,
|
if err != nil {
|
||||||
Height: 32,
|
panic(err)
|
||||||
})
|
}
|
||||||
|
|
||||||
display.ClearDisplay()
|
display.ClearDisplay()
|
||||||
|
|
||||||
x := int16(0)
|
width, height := display.Size()
|
||||||
y := int16(0)
|
x := int16(width)
|
||||||
|
y := int16(height)
|
||||||
deltaX := int16(1)
|
deltaX := int16(1)
|
||||||
deltaY := int16(1)
|
deltaY := int16(1)
|
||||||
for {
|
for {
|
||||||
@@ -39,11 +37,11 @@ func main() {
|
|||||||
x += deltaX
|
x += deltaX
|
||||||
y += deltaY
|
y += deltaY
|
||||||
|
|
||||||
if x == 0 || x == 127 {
|
if x == 0 || x == width-1 {
|
||||||
deltaX = -deltaX
|
deltaX = -deltaX
|
||||||
}
|
}
|
||||||
|
|
||||||
if y == 0 || y == 31 {
|
if y == 0 || y == height-1 {
|
||||||
deltaY = -deltaY
|
deltaY = -deltaY
|
||||||
}
|
}
|
||||||
time.Sleep(1 * time.Millisecond)
|
time.Sleep(1 * time.Millisecond)
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
//go:build !thumby
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
|
"tinygo.org/x/drivers/ssd1306"
|
||||||
|
)
|
||||||
|
|
||||||
|
func makeSSD1306(width, height int16) (*ssd1306.Device, error) {
|
||||||
|
err := machine.I2C0.Configure(machine.I2CConfig{
|
||||||
|
Frequency: 400 * machine.KHz,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
address := uint16(ssd1306.Address)
|
||||||
|
if width == 128 && (height == 32 || height == 64) {
|
||||||
|
address = ssd1306.Address_128_32
|
||||||
|
}
|
||||||
|
display := ssd1306.NewI2C(machine.I2C0)
|
||||||
|
display.Configure(ssd1306.Config{
|
||||||
|
Address: address,
|
||||||
|
Width: width,
|
||||||
|
Height: height,
|
||||||
|
})
|
||||||
|
return &display, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
//go:build thumby
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
|
"tinygo.org/x/drivers/ssd1306"
|
||||||
|
)
|
||||||
|
|
||||||
|
func makeSSD1306(_, _ int16) (*ssd1306.Device, error) {
|
||||||
|
// width and height are known for thumby.
|
||||||
|
machine.SPI0.Configure(machine.SPIConfig{})
|
||||||
|
display := ssd1306.NewSPI(machine.SPI0, machine.THUMBY_DC_PIN, machine.THUMBY_RESET_PIN, machine.THUMBY_CS_PIN)
|
||||||
|
display.Configure(ssd1306.Config{
|
||||||
|
Width: 72,
|
||||||
|
Height: 40,
|
||||||
|
ResetCol: ssd1306.ResetValue{28, 99},
|
||||||
|
ResetPage: ssd1306.ResetValue{0, 5},
|
||||||
|
})
|
||||||
|
return &display, nil
|
||||||
|
}
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"image/color"
|
|
||||||
"machine"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ssd1306"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
machine.SPI0.Configure(machine.SPIConfig{
|
|
||||||
Frequency: 8000000,
|
|
||||||
})
|
|
||||||
display := ssd1306.NewSPI(machine.SPI0, machine.P8, machine.P7, machine.P9)
|
|
||||||
display.Configure(ssd1306.Config{
|
|
||||||
Width: 128,
|
|
||||||
Height: 64,
|
|
||||||
})
|
|
||||||
|
|
||||||
display.ClearDisplay()
|
|
||||||
|
|
||||||
x := int16(64)
|
|
||||||
y := int16(32)
|
|
||||||
deltaX := int16(1)
|
|
||||||
deltaY := int16(1)
|
|
||||||
for {
|
|
||||||
pixel := display.GetPixel(x, y)
|
|
||||||
c := color.RGBA{255, 255, 255, 255}
|
|
||||||
if pixel {
|
|
||||||
c = color.RGBA{0, 0, 0, 255}
|
|
||||||
}
|
|
||||||
display.SetPixel(x, y, c)
|
|
||||||
display.Display()
|
|
||||||
|
|
||||||
x += deltaX
|
|
||||||
y += deltaY
|
|
||||||
|
|
||||||
if x == 0 || x == 127 {
|
|
||||||
deltaX = -deltaX
|
|
||||||
}
|
|
||||||
|
|
||||||
if y == 0 || y == 63 {
|
|
||||||
deltaY = -deltaY
|
|
||||||
}
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
// This example using the SSD1306 OLED display over SPI on the Thumby board
|
|
||||||
// A very tiny 72x40 display.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"image/color"
|
|
||||||
"machine"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ssd1306"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
machine.SPI0.Configure(machine.SPIConfig{})
|
|
||||||
display := ssd1306.NewSPI(machine.SPI0, machine.THUMBY_DC_PIN, machine.THUMBY_RESET_PIN, machine.THUMBY_CS_PIN)
|
|
||||||
display.Configure(ssd1306.Config{
|
|
||||||
Width: 72,
|
|
||||||
Height: 40,
|
|
||||||
ResetCol: ssd1306.ResetValue{28, 99},
|
|
||||||
ResetPage: ssd1306.ResetValue{0, 5},
|
|
||||||
})
|
|
||||||
|
|
||||||
display.ClearDisplay()
|
|
||||||
|
|
||||||
x := int16(36)
|
|
||||||
y := int16(20)
|
|
||||||
deltaX := int16(1)
|
|
||||||
deltaY := int16(1)
|
|
||||||
for {
|
|
||||||
pixel := display.GetPixel(x, y)
|
|
||||||
c := color.RGBA{255, 255, 255, 255}
|
|
||||||
if pixel {
|
|
||||||
c = color.RGBA{0, 0, 0, 255}
|
|
||||||
}
|
|
||||||
display.SetPixel(x, y, c)
|
|
||||||
display.Display()
|
|
||||||
|
|
||||||
x += deltaX
|
|
||||||
y += deltaY
|
|
||||||
|
|
||||||
if x == 0 || x == 71 {
|
|
||||||
deltaX = -deltaX
|
|
||||||
}
|
|
||||||
|
|
||||||
if y == 0 || y == 39 {
|
|
||||||
deltaY = -deltaY
|
|
||||||
}
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+6
-4
@@ -5,6 +5,8 @@
|
|||||||
package ft6336
|
package ft6336
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
"tinygo.org/x/drivers/internal/legacy"
|
"tinygo.org/x/drivers/internal/legacy"
|
||||||
"tinygo.org/x/drivers/touch"
|
"tinygo.org/x/drivers/touch"
|
||||||
@@ -15,11 +17,11 @@ type Device struct {
|
|||||||
bus drivers.I2C
|
bus drivers.I2C
|
||||||
buf []byte
|
buf []byte
|
||||||
Address uint8
|
Address uint8
|
||||||
intPin drivers.Pin
|
intPin machine.Pin
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns FT6336 device for the provided I2C bus using default address.
|
// New returns FT6336 device for the provided I2C bus using default address.
|
||||||
func New(i2c drivers.I2C, intPin drivers.Pin) *Device {
|
func New(i2c drivers.I2C, intPin machine.Pin) *Device {
|
||||||
return &Device{
|
return &Device{
|
||||||
bus: i2c,
|
bus: i2c,
|
||||||
buf: make([]byte, 11),
|
buf: make([]byte, 11),
|
||||||
@@ -32,10 +34,10 @@ func New(i2c drivers.I2C, intPin drivers.Pin) *Device {
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the FT6336 device. Note that the interrupt pin must be configured
|
// Configure the FT6336 device.
|
||||||
// separately as an input.
|
|
||||||
func (d *Device) Configure(config Config) error {
|
func (d *Device) Configure(config Config) error {
|
||||||
d.write1Byte(0xA4, 0x00)
|
d.write1Byte(0xA4, 0x00)
|
||||||
|
d.intPin.Configure(machine.PinConfig{Mode: machine.PinInputPulldown})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-7
@@ -5,6 +5,7 @@ package gc9a01 // import "tinygo.org/x/drivers/gc9a01"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"errors"
|
"errors"
|
||||||
@@ -21,10 +22,10 @@ type FrameRate uint8
|
|||||||
// Device wraps an SPI connection.
|
// Device wraps an SPI connection.
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
dcPin drivers.Pin
|
dcPin machine.Pin
|
||||||
resetPin drivers.Pin
|
resetPin machine.Pin
|
||||||
csPin drivers.Pin
|
csPin machine.Pin
|
||||||
blPin drivers.Pin
|
blPin machine.Pin
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
columnOffsetCfg int16
|
columnOffsetCfg int16
|
||||||
@@ -50,9 +51,12 @@ type Config struct {
|
|||||||
Height int16
|
Height int16
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new ST7789 connection. The SPI wire must already be configured, along with the
|
// New creates a new ST7789 connection. The SPI wire must already be configured.
|
||||||
// data/command and reset pins as outputs.
|
func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin machine.Pin) Device {
|
||||||
func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.Pin) Device {
|
resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
blPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
return Device{
|
return Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
resetPin: resetPin,
|
resetPin: resetPin,
|
||||||
|
|||||||
+7
-8
@@ -5,31 +5,30 @@
|
|||||||
package hcsr04
|
package hcsr04
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const TIMEOUT = 23324 // max sensing distance (4m)
|
const TIMEOUT = 23324 // max sensing distance (4m)
|
||||||
|
|
||||||
// Device holds the pins
|
// Device holds the pins
|
||||||
type Device struct {
|
type Device struct {
|
||||||
trigger drivers.Pin
|
trigger machine.Pin
|
||||||
echo drivers.Pin
|
echo machine.Pin
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new ultrasonic driver given 2 pins
|
// New returns a new ultrasonic driver given 2 pins
|
||||||
func New(trigger, echo drivers.Pin) Device {
|
func New(trigger, echo machine.Pin) Device {
|
||||||
return Device{
|
return Device{
|
||||||
trigger: trigger,
|
trigger: trigger,
|
||||||
echo: echo,
|
echo: echo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure expects that the pins of the Device have already
|
// Configure configures the pins of the Device
|
||||||
// been configured by the user. Trigger pin should be an output
|
|
||||||
// and echo pin should be an input.
|
|
||||||
func (d *Device) Configure() {
|
func (d *Device) Configure() {
|
||||||
|
d.trigger.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.echo.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadDistance returns the distance of the object in mm
|
// ReadDistance returns the distance of the object in mm
|
||||||
|
|||||||
+3
-2
@@ -3,6 +3,7 @@ package max6675
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"machine"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
)
|
)
|
||||||
@@ -13,13 +14,13 @@ var ErrThermocoupleOpen = errors.New("thermocouple input open")
|
|||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
cs drivers.Pin
|
cs machine.Pin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new Device to read from a MAX6675 thermocouple.
|
// Create a new Device to read from a MAX6675 thermocouple.
|
||||||
// Pins must be configured before use. Frequency for SPI
|
// Pins must be configured before use. Frequency for SPI
|
||||||
// should be 4.3MHz maximum.
|
// should be 4.3MHz maximum.
|
||||||
func NewDevice(bus drivers.SPI, cs drivers.Pin) *Device {
|
func NewDevice(bus drivers.SPI, cs machine.Pin) *Device {
|
||||||
return &Device{
|
return &Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
cs: cs,
|
cs: cs,
|
||||||
|
|||||||
+8
-3
@@ -3,26 +3,31 @@
|
|||||||
package max72xx
|
package max72xx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
cs drivers.Pin
|
cs machine.Pin
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDriver creates a new max7219 connection. The SPI wire must already be configured
|
// NewDriver creates a new max7219 connection. The SPI wire must already be configured
|
||||||
// The SPI frequency must not be higher than 10MHz.
|
// The SPI frequency must not be higher than 10MHz.
|
||||||
// parameter cs: the datasheet also refers to this pin as "load" pin.
|
// parameter cs: the datasheet also refers to this pin as "load" pin.
|
||||||
func NewDevice(bus drivers.SPI, cs drivers.Pin) *Device {
|
func NewDevice(bus drivers.SPI, cs machine.Pin) *Device {
|
||||||
return &Device{
|
return &Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
cs: cs,
|
cs: cs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure expects that the pin of the Device has already been configured by the user as output.
|
// Configure setups the pins.
|
||||||
func (driver *Device) Configure() {
|
func (driver *Device) Configure() {
|
||||||
|
outPutConfig := machine.PinConfig{Mode: machine.PinOutput}
|
||||||
|
|
||||||
|
driver.cs.Configure(outPutConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetScanLimit sets the scan limit. Maximum is 8.
|
// SetScanLimit sets the scan limit. Maximum is 8.
|
||||||
|
|||||||
+5
-4
@@ -8,6 +8,7 @@ package mcp2515 // import "tinygo.org/x/drivers/mcp2515"
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
@@ -16,7 +17,7 @@ import (
|
|||||||
// Device wraps MCP2515 SPI CAN Module.
|
// Device wraps MCP2515 SPI CAN Module.
|
||||||
type Device struct {
|
type Device struct {
|
||||||
spi SPI
|
spi SPI
|
||||||
cs drivers.Pin
|
cs machine.Pin
|
||||||
msg *CANMsg
|
msg *CANMsg
|
||||||
mcpMode byte
|
mcpMode byte
|
||||||
}
|
}
|
||||||
@@ -35,7 +36,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// New returns a new MCP2515 driver. Pass in a fully configured SPI bus.
|
// New returns a new MCP2515 driver. Pass in a fully configured SPI bus.
|
||||||
func New(b drivers.SPI, csPin drivers.Pin) *Device {
|
func New(b drivers.SPI, csPin machine.Pin) *Device {
|
||||||
d := &Device{
|
d := &Device{
|
||||||
spi: SPI{
|
spi: SPI{
|
||||||
bus: b,
|
bus: b,
|
||||||
@@ -49,9 +50,9 @@ func New(b drivers.SPI, csPin drivers.Pin) *Device {
|
|||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure sets up the device for communication. It expects the SPI interface to be already
|
// Configure sets up the device for communication.
|
||||||
// configured, and the CS configured as output.
|
|
||||||
func (d *Device) Configure() {
|
func (d *Device) Configure() {
|
||||||
|
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
}
|
}
|
||||||
|
|
||||||
const beginTimeoutValue int = 10
|
const beginTimeoutValue int = 10
|
||||||
|
|||||||
+6
-5
@@ -6,6 +6,7 @@ package pcd8544 // import "tinygo.org/x/drivers/pcd8544"
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
@@ -14,9 +15,9 @@ import (
|
|||||||
// Device wraps an SPI connection.
|
// Device wraps an SPI connection.
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
dcPin drivers.Pin
|
dcPin machine.Pin
|
||||||
rstPin drivers.Pin
|
rstPin machine.Pin
|
||||||
scePin drivers.Pin
|
scePin machine.Pin
|
||||||
buffer []byte
|
buffer []byte
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
@@ -28,8 +29,8 @@ type Config struct {
|
|||||||
Height int16
|
Height int16
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new PCD8544 connection. The SPI bus and pins must already be configured.
|
// New creates a new PCD8544 connection. The SPI bus must already be configured.
|
||||||
func New(bus drivers.SPI, dcPin, rstPin, scePin drivers.Pin) *Device {
|
func New(bus drivers.SPI, dcPin, rstPin, scePin machine.Pin) *Device {
|
||||||
return &Device{
|
return &Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
dcPin: dcPin,
|
dcPin: dcPin,
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package drivers
|
|
||||||
|
|
||||||
// Pin is a digital pin interface. It is notably implemented by the
|
|
||||||
// machine.Pin type.
|
|
||||||
type Pin interface {
|
|
||||||
Get() bool
|
|
||||||
High()
|
|
||||||
Low()
|
|
||||||
Set(high bool)
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
package shiftregister
|
package shiftregister
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"tinygo.org/x/drivers"
|
"machine"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NumberBit int8
|
type NumberBit int8
|
||||||
@@ -16,20 +16,20 @@ const (
|
|||||||
|
|
||||||
// Device holds pin number
|
// Device holds pin number
|
||||||
type Device struct {
|
type Device struct {
|
||||||
latch, clock, out drivers.Pin // IC wiring
|
latch, clock, out machine.Pin // IC wiring
|
||||||
bits NumberBit // Pin number
|
bits NumberBit // Pin number
|
||||||
mask uint32 // keep all pins state
|
mask uint32 // keep all pins state
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShiftPin is the implementation of the ShiftPin interface.
|
// ShiftPin is the implementation of the ShiftPin interface.
|
||||||
// ShiftPin provide an interface like regular drivers.Pin
|
// ShiftPin provide an interface like regular machine.Pin
|
||||||
type ShiftPin struct {
|
type ShiftPin struct {
|
||||||
mask uint32 // Bit representing the pin
|
mask uint32 // Bit representing the pin
|
||||||
d *Device // Reference to the register
|
d *Device // Reference to the register
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new shift output register device
|
// New returns a new shift output register device
|
||||||
func New(Bits NumberBit, Latch, Clock, Out drivers.Pin) *Device {
|
func New(Bits NumberBit, Latch, Clock, Out machine.Pin) *Device {
|
||||||
return &Device{
|
return &Device{
|
||||||
latch: Latch,
|
latch: Latch,
|
||||||
clock: Clock,
|
clock: Clock,
|
||||||
@@ -38,9 +38,11 @@ func New(Bits NumberBit, Latch, Clock, Out drivers.Pin) *Device {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure set hardware configuration. Make sure that the pins are already configured
|
// Configure set hardware configuration
|
||||||
// as output.
|
|
||||||
func (d *Device) Configure() {
|
func (d *Device) Configure() {
|
||||||
|
d.latch.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.clock.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.out.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
d.latch.High()
|
d.latch.High()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -65,8 +65,8 @@ tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/shifter/
|
|||||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht3x/main.go
|
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht3x/main.go
|
||||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht4x/main.go
|
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht4x/main.go
|
||||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/shtc3/main.go
|
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/shtc3/main.go
|
||||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1306/i2c_128x32/main.go
|
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1306/
|
||||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1306/spi_128x64/main.go
|
tinygo build -size short -o ./build/test.hex -target=thumby ./examples/ssd1306/
|
||||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1331/main.go
|
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1331/main.go
|
||||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7735/main.go
|
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7735/main.go
|
||||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7789/main.go
|
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7789/main.go
|
||||||
|
|||||||
+11
-7
@@ -5,9 +5,8 @@ package ssd1289
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Bus interface {
|
type Bus interface {
|
||||||
@@ -15,17 +14,17 @@ type Bus interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
rs drivers.Pin
|
rs machine.Pin
|
||||||
wr drivers.Pin
|
wr machine.Pin
|
||||||
cs drivers.Pin
|
cs machine.Pin
|
||||||
rst drivers.Pin
|
rst machine.Pin
|
||||||
bus Bus
|
bus Bus
|
||||||
}
|
}
|
||||||
|
|
||||||
const width = int16(240)
|
const width = int16(240)
|
||||||
const height = int16(320)
|
const height = int16(320)
|
||||||
|
|
||||||
func New(rs drivers.Pin, wr drivers.Pin, cs drivers.Pin, rst drivers.Pin, bus Bus) Device {
|
func New(rs machine.Pin, wr machine.Pin, cs machine.Pin, rst machine.Pin, bus Bus) Device {
|
||||||
d := Device{
|
d := Device{
|
||||||
rs: rs,
|
rs: rs,
|
||||||
wr: wr,
|
wr: wr,
|
||||||
@@ -34,6 +33,11 @@ func New(rs drivers.Pin, wr drivers.Pin, cs drivers.Pin, rst drivers.Pin, bus Bu
|
|||||||
bus: bus,
|
bus: bus,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rs.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
wr.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
|
||||||
cs.High()
|
cs.High()
|
||||||
rst.High()
|
rst.High()
|
||||||
wr.High()
|
wr.High()
|
||||||
|
|||||||
+9
-5
@@ -6,6 +6,7 @@ package ssd1306 // import "tinygo.org/x/drivers/ssd1306"
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
@@ -57,9 +58,9 @@ type I2CBus struct {
|
|||||||
|
|
||||||
type SPIBus struct {
|
type SPIBus struct {
|
||||||
wire drivers.SPI
|
wire drivers.SPI
|
||||||
dcPin drivers.Pin
|
dcPin machine.Pin
|
||||||
resetPin drivers.Pin
|
resetPin machine.Pin
|
||||||
csPin drivers.Pin
|
csPin machine.Pin
|
||||||
}
|
}
|
||||||
|
|
||||||
type Buser interface {
|
type Buser interface {
|
||||||
@@ -80,8 +81,11 @@ func NewI2C(bus drivers.I2C) Device {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSPI creates a new SSD1306 connection. The SPI wire and pins must already be configured.
|
// NewSPI creates a new SSD1306 connection. The SPI wire must already be configured.
|
||||||
func NewSPI(bus drivers.SPI, dcPin, resetPin, csPin drivers.Pin) Device {
|
func NewSPI(bus drivers.SPI, dcPin, resetPin, csPin machine.Pin) Device {
|
||||||
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
return Device{
|
return Device{
|
||||||
bus: &SPIBus{
|
bus: &SPIBus{
|
||||||
wire: bus,
|
wire: bus,
|
||||||
|
|||||||
+9
-5
@@ -5,6 +5,7 @@ package ssd1331 // import "tinygo.org/x/drivers/ssd1331"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
|
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
@@ -18,9 +19,9 @@ type Rotation uint8
|
|||||||
// Device wraps an SPI connection.
|
// Device wraps an SPI connection.
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
dcPin drivers.Pin
|
dcPin machine.Pin
|
||||||
resetPin drivers.Pin
|
resetPin machine.Pin
|
||||||
csPin drivers.Pin
|
csPin machine.Pin
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
batchLength int16
|
batchLength int16
|
||||||
@@ -34,8 +35,11 @@ type Config struct {
|
|||||||
Height int16
|
Height int16
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new SSD1331 connection. The SPI wire and pins must already be configured.
|
// New creates a new SSD1331 connection. The SPI wire must already be configured.
|
||||||
func New(bus drivers.SPI, resetPin, dcPin, csPin drivers.Pin) Device {
|
func New(bus drivers.SPI, resetPin, dcPin, csPin machine.Pin) Device {
|
||||||
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
return Device{
|
return Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
dcPin: dcPin,
|
dcPin: dcPin,
|
||||||
|
|||||||
+14
-6
@@ -6,6 +6,7 @@ package ssd1351 // import "tinygo.org/x/drivers/ssd1351"
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
@@ -19,11 +20,11 @@ var (
|
|||||||
// Device wraps an SPI connection.
|
// Device wraps an SPI connection.
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
dcPin drivers.Pin
|
dcPin machine.Pin
|
||||||
resetPin drivers.Pin
|
resetPin machine.Pin
|
||||||
csPin drivers.Pin
|
csPin machine.Pin
|
||||||
enPin drivers.Pin
|
enPin machine.Pin
|
||||||
rwPin drivers.Pin
|
rwPin machine.Pin
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
rowOffset int16
|
rowOffset int16
|
||||||
@@ -40,7 +41,7 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new SSD1351 connection. The SPI wire must already be configured.
|
// New creates a new SSD1351 connection. The SPI wire must already be configured.
|
||||||
func New(bus drivers.SPI, resetPin, dcPin, csPin, enPin, rwPin drivers.Pin) Device {
|
func New(bus drivers.SPI, resetPin, dcPin, csPin, enPin, rwPin machine.Pin) Device {
|
||||||
return Device{
|
return Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
dcPin: dcPin,
|
dcPin: dcPin,
|
||||||
@@ -71,6 +72,13 @@ func (d *Device) Configure(cfg Config) {
|
|||||||
d.bufferLength = d.height
|
d.bufferLength = d.height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// configure GPIO pins
|
||||||
|
d.dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.enPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.rwPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
|
||||||
// reset the device
|
// reset the device
|
||||||
d.resetPin.High()
|
d.resetPin.High()
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|||||||
+12
-7
@@ -5,6 +5,7 @@ package st7735 // import "tinygo.org/x/drivers/st7735"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"errors"
|
"errors"
|
||||||
@@ -38,10 +39,10 @@ type Device = DeviceOf[pixel.RGB565BE]
|
|||||||
// formats.
|
// formats.
|
||||||
type DeviceOf[T Color] struct {
|
type DeviceOf[T Color] struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
dcPin drivers.Pin
|
dcPin machine.Pin
|
||||||
resetPin drivers.Pin
|
resetPin machine.Pin
|
||||||
csPin drivers.Pin
|
csPin machine.Pin
|
||||||
blPin drivers.Pin
|
blPin machine.Pin
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
columnOffset int16
|
columnOffset int16
|
||||||
@@ -64,13 +65,17 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new ST7735 connection. The SPI wire must already be configured.
|
// New creates a new ST7735 connection. The SPI wire must already be configured.
|
||||||
func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.Pin) Device {
|
func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin machine.Pin) Device {
|
||||||
return NewOf[pixel.RGB565BE](bus, resetPin, dcPin, csPin, blPin)
|
return NewOf[pixel.RGB565BE](bus, resetPin, dcPin, csPin, blPin)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOf creates a new ST7735 connection with a particular pixel format. The SPI
|
// NewOf creates a new ST7735 connection with a particular pixel format. The SPI
|
||||||
// wire and pins must already be configured.
|
// wire must already be configured.
|
||||||
func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.Pin) DeviceOf[T] {
|
func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin machine.Pin) DeviceOf[T] {
|
||||||
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
blPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
return DeviceOf[T]{
|
return DeviceOf[T]{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
dcPin: dcPin,
|
dcPin: dcPin,
|
||||||
|
|||||||
+11
-7
@@ -46,10 +46,10 @@ type Device = DeviceOf[pixel.RGB565BE]
|
|||||||
// formats.
|
// formats.
|
||||||
type DeviceOf[T Color] struct {
|
type DeviceOf[T Color] struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
dcPin drivers.Pin
|
dcPin machine.Pin
|
||||||
resetPin drivers.Pin
|
resetPin machine.Pin
|
||||||
csPin drivers.Pin
|
csPin machine.Pin
|
||||||
blPin drivers.Pin
|
blPin machine.Pin
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
columnOffsetCfg int16
|
columnOffsetCfg int16
|
||||||
@@ -83,13 +83,17 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new ST7789 connection. The SPI wire must already be configured.
|
// New creates a new ST7789 connection. The SPI wire must already be configured.
|
||||||
func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.Pin) Device {
|
func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin machine.Pin) Device {
|
||||||
return NewOf[pixel.RGB565BE](bus, resetPin, dcPin, csPin, blPin)
|
return NewOf[pixel.RGB565BE](bus, resetPin, dcPin, csPin, blPin)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOf creates a new ST7789 connection with a particular pixel format. The SPI
|
// NewOf creates a new ST7789 connection with a particular pixel format. The SPI
|
||||||
// wire and pins must already be configured.
|
// wire must already be configured.
|
||||||
func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.Pin) DeviceOf[T] {
|
func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin machine.Pin) DeviceOf[T] {
|
||||||
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
blPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
return DeviceOf[T]{
|
return DeviceOf[T]{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
dcPin: dcPin,
|
dcPin: dcPin,
|
||||||
|
|||||||
+3
-2
@@ -6,6 +6,7 @@ package sx127x
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
@@ -21,7 +22,7 @@ const (
|
|||||||
// Device wraps an SPI connection to a SX127x device.
|
// Device wraps an SPI connection to a SX127x device.
|
||||||
type Device struct {
|
type Device struct {
|
||||||
spi drivers.SPI // SPI bus for module communication
|
spi drivers.SPI // SPI bus for module communication
|
||||||
rstPin drivers.Pin // GPIO for reset
|
rstPin machine.Pin // GPIO for reset
|
||||||
radioEventChan chan lora.RadioEvent // Channel for Receiving events
|
radioEventChan chan lora.RadioEvent // Channel for Receiving events
|
||||||
loraConf lora.Config // Current Lora configuration
|
loraConf lora.Config // Current Lora configuration
|
||||||
controller RadioController // to manage interactions with the radio
|
controller RadioController // to manage interactions with the radio
|
||||||
@@ -42,7 +43,7 @@ func (d *Device) GetRadioEventChan() chan lora.RadioEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new SX127x connection. The SPI bus must already be configured.
|
// New creates a new SX127x connection. The SPI bus must already be configured.
|
||||||
func New(spi drivers.SPI, rstPin drivers.Pin) *Device {
|
func New(spi drivers.SPI, rstPin machine.Pin) *Device {
|
||||||
k := Device{
|
k := Device{
|
||||||
spi: spi,
|
spi: spi,
|
||||||
rstPin: rstPin,
|
rstPin: rstPin,
|
||||||
|
|||||||
+11
-7
@@ -8,6 +8,7 @@ package uc8151 // import "tinygo.org/x/drivers/uc8151"
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
@@ -30,10 +31,10 @@ type Config struct {
|
|||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
cs drivers.Pin
|
cs machine.Pin
|
||||||
dc drivers.Pin
|
dc machine.Pin
|
||||||
rst drivers.Pin
|
rst machine.Pin
|
||||||
busy drivers.Pin
|
busy machine.Pin
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
buffer []uint8
|
buffer []uint8
|
||||||
@@ -47,9 +48,12 @@ type Device struct {
|
|||||||
|
|
||||||
type Speed uint8
|
type Speed uint8
|
||||||
|
|
||||||
// New returns a new uc8151 driver. Pass in a fully configured SPI bus and pins.
|
// New returns a new uc8151 driver. Pass in a fully configured SPI bus.
|
||||||
// busyPin should be set and input, the others as outputs.
|
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
|
||||||
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
|
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||||
return Device{
|
return Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
cs: csPin,
|
cs: csPin,
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import (
|
|||||||
"image/color"
|
"image/color"
|
||||||
"machine"
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -25,10 +23,10 @@ type Config struct {
|
|||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus *machine.SPI
|
bus *machine.SPI
|
||||||
cs drivers.Pin
|
cs machine.Pin
|
||||||
dc drivers.Pin
|
dc machine.Pin
|
||||||
rst drivers.Pin
|
rst machine.Pin
|
||||||
busy drivers.Pin
|
busy machine.Pin
|
||||||
|
|
||||||
buffer []uint8
|
buffer []uint8
|
||||||
rotation Rotation
|
rotation Rotation
|
||||||
@@ -81,7 +79,7 @@ var partialRefresh = [159]uint8{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new epd1in54 driver. Pass in a fully configured SPI bus.
|
// New returns a new epd1in54 driver. Pass in a fully configured SPI bus.
|
||||||
func New(bus *machine.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
|
func New(bus *machine.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
|
||||||
return Device{
|
return Device{
|
||||||
buffer: make([]uint8, (uint32(Width)*uint32(Height))/8),
|
buffer: make([]uint8, (uint32(Width)*uint32(Height))/8),
|
||||||
bus: bus,
|
bus: bus,
|
||||||
@@ -93,6 +91,11 @@ func New(bus *machine.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) LDirInit(cfg Config) {
|
func (d *Device) LDirInit(cfg Config) {
|
||||||
|
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.busy.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||||
|
|
||||||
d.bus.Configure(machine.SPIConfig{
|
d.bus.Configure(machine.SPIConfig{
|
||||||
Frequency: 2000000,
|
Frequency: 2000000,
|
||||||
Mode: 0,
|
Mode: 0,
|
||||||
@@ -147,6 +150,11 @@ func (d *Device) LDirInit(cfg Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) HDirInit(cfg Config) {
|
func (d *Device) HDirInit(cfg Config) {
|
||||||
|
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.busy.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||||
|
|
||||||
d.bus.Configure(machine.SPIConfig{
|
d.bus.Configure(machine.SPIConfig{
|
||||||
Frequency: 2000000,
|
Frequency: 2000000,
|
||||||
Mode: 0,
|
Mode: 0,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package epd2in13 // import "tinygo.org/x/drivers/waveshare-epd/epd2in13"
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
@@ -20,10 +21,10 @@ type Config struct {
|
|||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
cs drivers.Pin
|
cs machine.Pin
|
||||||
dc drivers.Pin
|
dc machine.Pin
|
||||||
rst drivers.Pin
|
rst machine.Pin
|
||||||
busy drivers.Pin
|
busy machine.Pin
|
||||||
logicalWidth int16
|
logicalWidth int16
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
@@ -51,9 +52,12 @@ var lutPartialUpdate = [30]uint8{
|
|||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus and pins.
|
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus.
|
||||||
// Busy pin should input, the rest should be output.
|
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
|
||||||
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
|
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||||
return Device{
|
return Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
cs: csPin,
|
cs: csPin,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package epd2in13x // import "tinygo.org/x/drivers/waveshare-epd/epd2in13x"
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
@@ -19,10 +20,10 @@ type Config struct {
|
|||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
cs drivers.Pin
|
cs machine.Pin
|
||||||
dc drivers.Pin
|
dc machine.Pin
|
||||||
rst drivers.Pin
|
rst machine.Pin
|
||||||
busy drivers.Pin
|
busy machine.Pin
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
buffer [][]uint8
|
buffer [][]uint8
|
||||||
@@ -31,9 +32,12 @@ type Device struct {
|
|||||||
|
|
||||||
type Color uint8
|
type Color uint8
|
||||||
|
|
||||||
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus and pins.
|
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus.
|
||||||
// Busy pin should input, the rest should be output.
|
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
|
||||||
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
|
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||||
return Device{
|
return Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
cs: csPin,
|
cs: csPin,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package epd2in66b
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
@@ -18,18 +19,18 @@ const (
|
|||||||
const Baudrate = 4_000_000 // 4 MHz
|
const Baudrate = 4_000_000 // 4 MHz
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ResetPin drivers.Pin
|
ResetPin machine.Pin
|
||||||
DataPin drivers.Pin
|
DataPin machine.Pin
|
||||||
ChipSelectPin drivers.Pin
|
ChipSelectPin machine.Pin
|
||||||
BusyPin drivers.Pin
|
BusyPin machine.Pin
|
||||||
}
|
}
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
cs drivers.Pin
|
cs machine.Pin
|
||||||
dc drivers.Pin
|
dc machine.Pin
|
||||||
rst drivers.Pin
|
rst machine.Pin
|
||||||
busy drivers.Pin
|
busy machine.Pin
|
||||||
|
|
||||||
blackBuffer []byte
|
blackBuffer []byte
|
||||||
redBuffer []byte
|
redBuffer []byte
|
||||||
@@ -49,14 +50,18 @@ func New(bus drivers.SPI) Device {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure configures the device. Note that pins should already
|
// Configure configures the device and its pins.
|
||||||
// be configured. Busy pin should be input, the rest should be output.
|
|
||||||
func (d *Device) Configure(c Config) error {
|
func (d *Device) Configure(c Config) error {
|
||||||
d.cs = c.ChipSelectPin
|
d.cs = c.ChipSelectPin
|
||||||
d.dc = c.DataPin
|
d.dc = c.DataPin
|
||||||
d.rst = c.ResetPin
|
d.rst = c.ResetPin
|
||||||
d.busy = c.BusyPin
|
d.busy = c.BusyPin
|
||||||
|
|
||||||
|
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
d.busy.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ package epd2in9 // import "tinygo.org/x/drivers/waveshare-epd/epd2in9"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
@@ -27,10 +28,10 @@ type Config struct {
|
|||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
cs drivers.Pin
|
cs machine.Pin
|
||||||
dc drivers.Pin
|
dc machine.Pin
|
||||||
rst drivers.Pin
|
rst machine.Pin
|
||||||
busy drivers.Pin
|
busy machine.Pin
|
||||||
logicalWidth int16
|
logicalWidth int16
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
@@ -59,9 +60,12 @@ var lutPartialUpdate = [30]uint8{
|
|||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new epd2in9 driver. Pass in a fully configured SPI bus and pins.
|
// New returns a new epd2in9 driver. Pass in a fully configured SPI bus.
|
||||||
// Busy pin should input, the rest should be output.
|
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
|
||||||
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
|
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||||
return Device{
|
return Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
cs: csPin,
|
cs: csPin,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ package epd4in2
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
@@ -24,10 +25,10 @@ type Config struct {
|
|||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus drivers.SPI
|
bus drivers.SPI
|
||||||
cs drivers.Pin
|
cs machine.Pin
|
||||||
dc drivers.Pin
|
dc machine.Pin
|
||||||
rst drivers.Pin
|
rst machine.Pin
|
||||||
busy drivers.Pin
|
busy machine.Pin
|
||||||
logicalWidth int16
|
logicalWidth int16
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
@@ -38,9 +39,12 @@ type Device struct {
|
|||||||
|
|
||||||
type Rotation uint8
|
type Rotation uint8
|
||||||
|
|
||||||
// New returns a new epd4in2 driver. Pass in a fully configured SPI bus and pins.
|
// New returns a new epd4in2 driver. Pass in a fully configured SPI bus.
|
||||||
// Busy pin should input, the rest should be output.
|
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
|
||||||
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
|
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||||
return Device{
|
return Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
cs: csPin,
|
cs: csPin,
|
||||||
|
|||||||
Reference in New Issue
Block a user