Skip to content

Commit

Permalink
make defaults pico specific
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrichner-oviva committed May 3, 2024
1 parent d0e4400 commit a0d2f65
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 35 deletions.
12 changes: 11 additions & 1 deletion examples/waveshare-epd/epd2in66b/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,18 @@ func main() {

println("started")

// in case you have a Pico module, you can directly use
// dev, err := epd2in66b.NewPicoModule()

display := epd2in66b.New(machine.SPI1)
err := display.Configure(epd2in66b.Config{})

cfg := epd2in66b.Config{
DataPin: machine.GP8,
ChipSelectPin: machine.GP9,
ResetPin: machine.GP12,
BusyPin: machine.GP13,
}
err := display.Configure(cfg)
if err != nil {
panic(err)
}
Expand Down
40 changes: 6 additions & 34 deletions waveshare-epd/epd2in66b/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ import (
const (
displayWidth = 152
displayHeight = 296

// using numerical values to enable generic tinygo compilation
dcPin = 8
csPin = 9
rstPin = 12
busyPin = 13
)

const Baudrate = 4_000_000 // 4 MHz
Expand All @@ -42,48 +36,26 @@ type Device struct {
redBuffer []byte
}

// New allocates a new device. The SPI for the built-in header to be used is picos machine.SPI1 at 4 MHz baudrate.
// New allocates a new device.
// The bus is expected to be configured and ready for use.
func New(bus drivers.SPI) Device {
pixelCount := displayWidth * displayHeight

bufLen := pixelCount / 8

return Device{
bus: bus,
cs: csPin,
dc: dcPin,
rst: rstPin,
busy: busyPin,

bus: bus,
blackBuffer: make([]byte, bufLen),
redBuffer: make([]byte, bufLen),
}
}

// Configure configures the device and its pins. The 'zero' config will fall back to the defaults.
//
// Default pins are:
//
// Data = GP8
// ChipSelect = GP9
// Reset = GP12
// Busy = GP13
func (d *Device) Configure(c Config) error {
if c.ChipSelectPin > 0 {
d.cs = c.ChipSelectPin
}
if c.DataPin > 0 {
d.dc = c.DataPin
}

if c.ResetPin > 0 {
d.rst = c.ResetPin
}

if c.BusyPin > 0 {
d.busy = c.BusyPin
}
d.cs = c.ChipSelectPin
d.dc = c.DataPin
d.rst = c.ResetPin
d.busy = c.BusyPin

d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
Expand Down
34 changes: 34 additions & 0 deletions waveshare-epd/epd2in66b/dev_pico.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//go:build pico

package epd2in66b

import (
"machine"
)

// DefaultConfig contains the default config for the https://www.waveshare.com/wiki/Pico-ePaper-2.66 module
var DefaultConfig = Config{
DataPin: machine.GP8,
ChipSelectPin: machine.GP9,
ResetPin: machine.GP12,
BusyPin: machine.GP13,
}

// NewPicoModule allocates a new device backed by the https://www.waveshare.com/wiki/Pico-ePaper-2.66 module
// This will also configure the SPI1 bus and configure the device with the DefaultConfig
func NewPicoModule() (Device, error) {
spi := machine.SPI1

if err := spi.Configure(machine.SPIConfig{
Frequency: Baudrate,
}); err != nil {
return Device{}, err
}

dev := New(spi)
if err := dev.Configure(DefaultConfig); err != nil {
return dev, err
}

return dev, nil
}

0 comments on commit a0d2f65

Please sign in to comment.