mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-08 08:53:40 +00:00
ili9341, ili9342: add support for m5stack-core2
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
//go:build m5stack_core2
|
||||
// +build m5stack_core2
|
||||
|
||||
package initdisplay
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"machine"
|
||||
|
||||
axp192 "tinygo.org/x/drivers/axp192/m5stack-core2-axp192"
|
||||
"tinygo.org/x/drivers/i2csoft"
|
||||
"tinygo.org/x/drivers/ili9341"
|
||||
)
|
||||
|
||||
// InitDisplay initializes the display of each board.
|
||||
func InitDisplay() *ili9341.Device {
|
||||
machine.SPI2.Configure(machine.SPIConfig{
|
||||
SCK: machine.LCD_SCK_PIN,
|
||||
SDO: machine.LCD_SDO_PIN,
|
||||
SDI: machine.LCD_SDI_PIN,
|
||||
Frequency: 40e6,
|
||||
})
|
||||
|
||||
i2c := i2csoft.New(machine.SCL0_PIN, machine.SDA0_PIN)
|
||||
i2c.Configure(i2csoft.I2CConfig{Frequency: 100e3})
|
||||
|
||||
axp := axp192.New(i2c)
|
||||
led := axp.LED
|
||||
led.Low()
|
||||
|
||||
display := ili9341.NewSPI(
|
||||
machine.SPI2,
|
||||
machine.LCD_DC_PIN,
|
||||
machine.LCD_SS_PIN,
|
||||
machine.NoPin,
|
||||
)
|
||||
|
||||
// configure display
|
||||
display.Configure(ili9341.Config{
|
||||
Width: 320,
|
||||
Height: 240,
|
||||
DisplayInversion: true,
|
||||
})
|
||||
display.FillScreen(color.RGBA{255, 255, 255, 255})
|
||||
|
||||
display.SetRotation(ili9341.Rotation0Mirror)
|
||||
|
||||
return display
|
||||
}
|
||||
+27
-9
@@ -8,9 +8,10 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Width int16
|
||||
Height int16
|
||||
Rotation Rotation
|
||||
Width int16
|
||||
Height int16
|
||||
Rotation Rotation
|
||||
DisplayInversion bool
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
@@ -103,10 +104,19 @@ func (d *Device) Configure(config Config) {
|
||||
0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
|
||||
GMCTRN1, 15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, // Set Gamma
|
||||
0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
|
||||
}
|
||||
|
||||
if config.DisplayInversion {
|
||||
initCmd = append(initCmd, []byte{
|
||||
INVON, 0x80,
|
||||
}...)
|
||||
}
|
||||
|
||||
initCmd = append(initCmd, []byte{
|
||||
SLPOUT, 0x80, // Exit Sleep
|
||||
DISPON, 0x80, // Display on
|
||||
0x00, // End of list
|
||||
}
|
||||
}...)
|
||||
for i, c := 0, len(initCmd); i < c; {
|
||||
cmd := initCmd[i]
|
||||
if cmd == 0x00 {
|
||||
@@ -239,14 +249,22 @@ func (d *Device) GetRotation() Rotation {
|
||||
// SetRotation changes the rotation of the device (clock-wise)
|
||||
func (d *Device) SetRotation(rotation Rotation) {
|
||||
madctl := uint8(0)
|
||||
switch rotation % 4 {
|
||||
case 0:
|
||||
switch rotation % 8 {
|
||||
case Rotation0:
|
||||
madctl = MADCTL_MX | MADCTL_BGR
|
||||
case 1:
|
||||
case Rotation90:
|
||||
madctl = MADCTL_MV | MADCTL_BGR
|
||||
case 2:
|
||||
case Rotation180:
|
||||
madctl = MADCTL_MY | MADCTL_BGR
|
||||
case 3:
|
||||
case Rotation270:
|
||||
madctl = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR
|
||||
case Rotation0Mirror:
|
||||
madctl = MADCTL_BGR
|
||||
case Rotation90Mirror:
|
||||
madctl = MADCTL_MY | MADCTL_MV | MADCTL_BGR
|
||||
case Rotation180Mirror:
|
||||
madctl = MADCTL_MX | MADCTL_MY | MADCTL_BGR
|
||||
case Rotation270Mirror:
|
||||
madctl = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR
|
||||
}
|
||||
d.sendCommand(MADCTL, []uint8{madctl})
|
||||
|
||||
@@ -81,4 +81,9 @@ const (
|
||||
Rotation90 Rotation = 1 // 90 degrees clock-wise rotation
|
||||
Rotation180 Rotation = 2
|
||||
Rotation270 Rotation = 3
|
||||
|
||||
Rotation0Mirror Rotation = 4
|
||||
Rotation90Mirror Rotation = 5
|
||||
Rotation180Mirror Rotation = 6
|
||||
Rotation270Mirror Rotation = 7
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user