Browse Source

Actually support alternative SPI ports

master
maze 2 years ago
parent
commit
477856dfb6
1 changed files with 15 additions and 16 deletions
  1. +15
    -16
      driver/oled/ssd1305.go

+ 15
- 16
driver/oled/ssd1305.go View File

@ -15,7 +15,6 @@ import (
"periph.io/x/periph/conn/physic"
"periph.io/x/periph/conn/spi"
"periph.io/x/periph/conn/spi/spireg"
"periph.io/x/periph/devices/ssd1306"
"periph.io/x/periph/host"
"maze.io/matrix/driver"
@ -39,7 +38,7 @@ func NewSSD1305(config *driver.Config, index int) (driver.Matrix, error) {
return nil, err
}
port, err := spireg.Open("")
port, err := spireg.Open(fmt.Sprintf("/dev/spidev0.%d", index))
if err != nil {
return nil, err
}
@ -49,7 +48,7 @@ func NewSSD1305(config *driver.Config, index int) (driver.Matrix, error) {
rst = gpioreg.ByName("GPIO25")
w, h = config.Geometry()
)
return newSSD1305SPI(port, dc, rst, &ssd1306.Opts{W: w, H: h})
return newSSD1305SPI(port, dc, rst, w, h)
}
func (ssd1305) ColorDepth() int {
@ -116,7 +115,7 @@ func (d *ssd1305) Render() error {
return nil
}
func newSSD1305SPI(p spi.Port, dc, rst gpio.PinOut, opts *ssd1306.Opts) (*ssd1305, error) {
func newSSD1305SPI(p spi.Port, dc, rst gpio.PinOut, w, h int) (*ssd1305, error) {
if dc == gpio.INVALID {
dc = nil
}
@ -135,25 +134,25 @@ func newSSD1305SPI(p spi.Port, dc, rst gpio.PinOut, opts *ssd1306.Opts) (*ssd130
if err != nil {
return nil, err
}
return newSSD1305(c, opts, dc, rst)
return newSSD1305(c, dc, rst, w, h)
}
func newSSD1305(c spi.Conn, opts *ssd1306.Opts, dc, rst gpio.PinOut) (*ssd1305, error) {
if opts.W < 8 || opts.W > ssd1305Width || opts.W&7 != 0 {
return nil, fmt.Errorf("ssd1305: invalid width %d", opts.W)
func newSSD1305(c spi.Conn, dc, rst gpio.PinOut, w, h int) (*ssd1305, error) {
if w < 8 || w > ssd1305Width || w&7 != 0 {
return nil, fmt.Errorf("ssd1305: invalid width %d", w)
}
if opts.H < 8 || opts.H > ssd1305Height || opts.H&7 != 0 {
return nil, fmt.Errorf("ssd1305: invalid height %d", opts.H)
if h < 8 || h > ssd1305Height || h&7 != 0 {
return nil, fmt.Errorf("ssd1305: invalid height %d", h)
}
d := &ssd1305{
Bitmap: pixel.NewBitmap(opts.W, opts.H),
Bitmap: pixel.NewBitmap(w, h),
c: c,
dc: dc,
rst: rst,
width: opts.W,
height: opts.H,
pages: opts.H / 8,
width: w,
height: h,
pages: h / 8,
}
// Power on display
@ -167,7 +166,7 @@ func newSSD1305(c spi.Conn, opts *ssd1306.Opts, dc, rst gpio.PinOut) (*ssd1305,
}
// Setup display
if err := d.sendCommand(getInitCmd(opts)); err != nil {
if err := d.sendCommand(getInitCmd(w, h)); err != nil {
return nil, err
}
@ -190,7 +189,7 @@ func (d *ssd1305) sendData(c []byte) error {
return d.c.Tx(c, nil)
}
func getInitCmd(opts *ssd1306.Opts) []byte {
func getInitCmd(w, h int) []byte {
return []byte{
ssd1305SetDisplay | 0x00, // off
ssd1305SetDisplayClockDiv, 0x80, // timing and driving scheme


Loading…
Cancel
Save