mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-17 21:23:58 +00:00
Fix setWindow bug, add CS pin for Clue compatibility. (#180)
* Fix setWindow bug, add CS pin for Clue compatibility. - corrected bit shift in setWindow that broke high addresses - added csPin to constructor (will now work with adafruit clue) - small adjustments and comments to init routine based on working arduino driver * Update main.go Updated test example with CS pin. * Reverting unnecessary (no-effect) change in setRotation.
This commit is contained in:
@@ -13,7 +13,7 @@ func main() {
|
|||||||
Frequency: 8000000,
|
Frequency: 8000000,
|
||||||
Mode: 3,
|
Mode: 3,
|
||||||
})
|
})
|
||||||
display := st7789.New(machine.SPI0, machine.P6, machine.P7, machine.P8)
|
display := st7789.New(machine.SPI0, machine.P6, machine.P7, machine.P8, machine.P9)
|
||||||
display.Configure(st7789.Config{Rotation: st7789.NO_ROTATION})
|
display.Configure(st7789.Config{Rotation: st7789.NO_ROTATION})
|
||||||
|
|
||||||
width, height := display.Size()
|
width, height := display.Size()
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ const (
|
|||||||
PWCTR4 = 0xC3
|
PWCTR4 = 0xC3
|
||||||
PWCTR5 = 0xC4
|
PWCTR5 = 0xC4
|
||||||
VMCTR1 = 0xC5
|
VMCTR1 = 0xC5
|
||||||
|
FRCTRL2 = 0xC6
|
||||||
PWCTR6 = 0xFC
|
PWCTR6 = 0xFC
|
||||||
GMCTRP1 = 0xE0
|
GMCTRP1 = 0xE0
|
||||||
GMCTRN1 = 0xE1
|
GMCTRN1 = 0xE1
|
||||||
|
|||||||
+44
-16
@@ -19,6 +19,7 @@ type Device struct {
|
|||||||
bus machine.SPI
|
bus machine.SPI
|
||||||
dcPin machine.Pin
|
dcPin machine.Pin
|
||||||
resetPin machine.Pin
|
resetPin machine.Pin
|
||||||
|
csPin machine.Pin
|
||||||
blPin machine.Pin
|
blPin machine.Pin
|
||||||
width int16
|
width int16
|
||||||
height int16
|
height int16
|
||||||
@@ -41,14 +42,16 @@ 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 machine.SPI, resetPin, dcPin, blPin machine.Pin) Device {
|
func New(bus machine.SPI, resetPin, dcPin, csPin, blPin machine.Pin) Device {
|
||||||
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
resetPin.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})
|
blPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
return Device{
|
return Device{
|
||||||
bus: bus,
|
bus: bus,
|
||||||
dcPin: dcPin,
|
dcPin: dcPin,
|
||||||
resetPin: resetPin,
|
resetPin: resetPin,
|
||||||
|
csPin: csPin,
|
||||||
blPin: blPin,
|
blPin: blPin,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,6 +68,7 @@ func (d *Device) Configure(cfg Config) {
|
|||||||
} else {
|
} else {
|
||||||
d.height = 240
|
d.height = 240
|
||||||
}
|
}
|
||||||
|
|
||||||
d.rotation = cfg.Rotation
|
d.rotation = cfg.Rotation
|
||||||
d.rowOffsetCfg = cfg.RowOffset
|
d.rowOffsetCfg = cfg.RowOffset
|
||||||
d.columnOffsetCfg = cfg.ColumnOffset
|
d.columnOffsetCfg = cfg.ColumnOffset
|
||||||
@@ -77,28 +81,50 @@ func (d *Device) Configure(cfg Config) {
|
|||||||
|
|
||||||
// reset the device
|
// reset the device
|
||||||
d.resetPin.High()
|
d.resetPin.High()
|
||||||
time.Sleep(5 * time.Millisecond)
|
time.Sleep(50 * time.Millisecond)
|
||||||
d.resetPin.Low()
|
d.resetPin.Low()
|
||||||
time.Sleep(20 * time.Millisecond)
|
time.Sleep(50 * time.Millisecond)
|
||||||
d.resetPin.High()
|
d.resetPin.High()
|
||||||
time.Sleep(150 * time.Millisecond)
|
time.Sleep(50 * time.Millisecond)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Common initialization
|
// Common initialization
|
||||||
d.Command(SWRESET)
|
d.Command(SWRESET) // Soft reset
|
||||||
time.Sleep(150 * time.Millisecond)
|
time.Sleep(150 * time.Millisecond)
|
||||||
d.Command(SLPOUT)
|
|
||||||
|
d.Command(SLPOUT) // Exit sleep mode
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
d.Command(COLMOD)
|
|
||||||
d.Data(0x55)
|
d.Command(COLMOD) // Set color mode
|
||||||
|
d.Data(0x55) // 16-bit color
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
|
||||||
|
d.Command(MADCTL) // Memory orientation
|
||||||
|
d.Data(0x08) // row/col bottom to top refresh
|
||||||
|
|
||||||
|
d.Command(CASET) // Column addr range set
|
||||||
|
d.Data(0x00)
|
||||||
|
d.Data(0x00) // xstart (0) 2 bytes
|
||||||
|
d.Data(240 >> 8)
|
||||||
|
d.Data(240 & 0xFF) // xend (240) 2 bytes
|
||||||
|
|
||||||
|
d.Command(RASET) // Row addr range set
|
||||||
|
d.Data(0x00)
|
||||||
|
d.Data(0x00) // ystart (0) 2 bytes
|
||||||
|
d.Data(320 >> 8)
|
||||||
|
d.Data(320 & 0xFF) // yend (320) 2 bytes
|
||||||
|
|
||||||
|
d.Command(INVON) // Inversion ON
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
|
||||||
|
d.Command(NORON) // Normal mode ON
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
|
||||||
|
d.Command(DISPON) // Screen ON
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
|
||||||
d.SetRotation(d.rotation)
|
d.SetRotation(d.rotation)
|
||||||
d.InvertColors(true)
|
|
||||||
|
|
||||||
d.Command(NORON)
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
d.Command(DISPON)
|
|
||||||
time.Sleep(500 * time.Millisecond)
|
|
||||||
|
|
||||||
d.blPin.High()
|
d.blPin.High()
|
||||||
}
|
}
|
||||||
@@ -123,12 +149,14 @@ func (d *Device) setWindow(x, y, w, h int16) {
|
|||||||
x += d.columnOffset
|
x += d.columnOffset
|
||||||
y += d.rowOffset
|
y += d.rowOffset
|
||||||
d.Tx([]uint8{CASET}, true)
|
d.Tx([]uint8{CASET}, true)
|
||||||
d.Tx([]uint8{uint8(x << 8), uint8(x), uint8((x + w - 1) >> 8), uint8(x + w - 1)}, false)
|
d.Tx([]uint8{uint8(x >> 8), uint8(x), uint8((x + w - 1) >> 8), uint8(x + w - 1)}, false)
|
||||||
d.Tx([]uint8{RASET}, true)
|
d.Tx([]uint8{RASET}, true)
|
||||||
d.Tx([]uint8{uint8(y >> 8), uint8(y), uint8((y + h - 1) >> 8), uint8(y + h - 1)}, false)
|
d.Tx([]uint8{uint8(y >> 8), uint8(y), uint8((y + h - 1) >> 8), uint8(y + h - 1)}, false)
|
||||||
d.Command(RAMWR)
|
d.Command(RAMWR)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// FillRectangle fills a rectangle at a given coordinates with a color
|
// FillRectangle fills a rectangle at a given coordinates with a color
|
||||||
func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
|
func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
|
||||||
k, i := d.Size()
|
k, i := d.Size()
|
||||||
@@ -158,6 +186,7 @@ func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FillRectangle fills a rectangle at a given coordinates with a buffer
|
// FillRectangle fills a rectangle at a given coordinates with a buffer
|
||||||
func (d *Device) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error {
|
func (d *Device) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error {
|
||||||
i, j := d.Size()
|
i, j := d.Size()
|
||||||
@@ -248,7 +277,6 @@ func (d *Device) SetRotation(rotation Rotation) {
|
|||||||
}
|
}
|
||||||
d.Command(MADCTL)
|
d.Command(MADCTL)
|
||||||
d.Data(madctl)
|
d.Data(madctl)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command sends a command to the display
|
// Command sends a command to the display
|
||||||
|
|||||||
Reference in New Issue
Block a user