mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-06 07:53:41 +00:00
all: add sleep mode to various SPI displays
The API looks like this and is based on the PCA9685 PWM chip:
Sleep(sleepEnabled bool) error
It will set the LCD panel to a low power state (not displaying any
image) but memory contents will be preserved.
This commit is contained in:
committed by
Daniel Esteban
parent
5c06b82b27
commit
d3022e7d6e
@@ -241,6 +241,27 @@ func (d *Device) FillScreen(c color.RGBA) {
|
||||
}
|
||||
}
|
||||
|
||||
// Set the sleep mode for this LCD panel. When sleeping, the panel uses a lot
|
||||
// less power. The LCD won't display an image anymore, but the memory contents
|
||||
// will be kept.
|
||||
func (d *Device) Sleep(sleepEnabled bool) error {
|
||||
if sleepEnabled {
|
||||
// Shut down LCD panel.
|
||||
d.sendCommand(SLPIN, nil)
|
||||
time.Sleep(5 * time.Millisecond) // 5ms required by the datasheet
|
||||
} else {
|
||||
// Turn the LCD panel back on.
|
||||
d.sendCommand(SLPOUT, nil)
|
||||
// Note: the ili9341 documentation says that it is needed to wait at
|
||||
// least 120ms before going to sleep again. Sleeping here would not be
|
||||
// practical (delays turning on the screen too much), so just hope the
|
||||
// screen won't need to sleep again for at least 120ms.
|
||||
// In practice, it's unlikely the user will set the display to sleep
|
||||
// again within 120ms.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetRotation returns the current rotation of the device
|
||||
func (d *Device) GetRotation() Rotation {
|
||||
return d.rotation
|
||||
|
||||
@@ -409,6 +409,24 @@ func (d *Device) EnableBacklight(enable bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// Set the sleep mode for this LCD panel. When sleeping, the panel uses a lot
|
||||
// less power. The LCD won't display an image anymore, but the memory contents
|
||||
// will be kept.
|
||||
func (d *Device) Sleep(sleepEnabled bool) error {
|
||||
if sleepEnabled {
|
||||
// Shut down LCD panel.
|
||||
d.Command(SLPIN)
|
||||
time.Sleep(5 * time.Millisecond) // 5ms required by the datasheet
|
||||
} else {
|
||||
// Turn the LCD panel back on.
|
||||
d.Command(SLPOUT)
|
||||
// The st7735 datasheet says it is necessary to wait 120ms before
|
||||
// sending another command.
|
||||
time.Sleep(120 * time.Millisecond)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InverColors inverts the colors of the screen
|
||||
func (d *Device) InvertColors(invert bool) {
|
||||
if invert {
|
||||
|
||||
+21
-2
@@ -125,8 +125,7 @@ func (d *Device) Configure(cfg Config) {
|
||||
d.Command(SWRESET) // Soft reset
|
||||
time.Sleep(150 * time.Millisecond) //
|
||||
|
||||
d.Command(SLPOUT) // Exit sleep mode
|
||||
time.Sleep(500 * time.Millisecond) //
|
||||
d.Sleep(false) // Exit sleep mode
|
||||
|
||||
// Memory initialization
|
||||
d.Command(COLMOD) // Set color mode
|
||||
@@ -458,6 +457,26 @@ func (d *Device) EnableBacklight(enable bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// Set the sleep mode for this LCD panel. When sleeping, the panel uses a lot
|
||||
// less power. The LCD won't display an image anymore, but the memory contents
|
||||
// will be kept.
|
||||
func (d *Device) Sleep(sleepEnabled bool) error {
|
||||
if sleepEnabled {
|
||||
d.Command(SLPIN)
|
||||
time.Sleep(5 * time.Millisecond) // 5ms required by the datasheet
|
||||
} else {
|
||||
// Turn the LCD panel back on.
|
||||
d.Command(SLPOUT)
|
||||
// Note: the st7789 documentation says that it is needed to wait at
|
||||
// least 120ms before going to sleep again. Sleeping here would not be
|
||||
// practical (delays turning on the screen too much), so just hope the
|
||||
// screen won't need to sleep again for at least 120ms.
|
||||
// In practice, it's unlikely the user will set the display to sleep
|
||||
// again within 120ms.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InvertColors inverts the colors of the screen
|
||||
func (d *Device) InvertColors(invert bool) {
|
||||
if invert {
|
||||
|
||||
Reference in New Issue
Block a user