mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-09-10 08:39:27 +00:00
ili9341: st7735: st7789: unify rotation support
* Unify the Rotation type, so that SetRotation can be used in
interfaces.
* Add Rotation() method to these displays, so that the current
rotation can be read.
* Change SetRotation() so that it can return an error (if the given
rotation isn't supported).
This commit is contained in:
committed by
Ron Evans
parent
59d66d1e73
commit
c689c11838
+16
-6
@@ -5,19 +5,21 @@ import (
|
||||
"image/color"
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Width int16
|
||||
Height int16
|
||||
Rotation Rotation
|
||||
Rotation drivers.Rotation
|
||||
DisplayInversion bool
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
width int16
|
||||
height int16
|
||||
rotation Rotation
|
||||
rotation drivers.Rotation
|
||||
driver driver
|
||||
|
||||
x0, x1 int16 // cached address window; prevents useless/expensive
|
||||
@@ -262,13 +264,20 @@ func (d *Device) Sleep(sleepEnabled bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetRotation returns the current rotation of the device
|
||||
func (d *Device) GetRotation() Rotation {
|
||||
// Rotation returns the current rotation of the device.
|
||||
func (d *Device) Rotation() drivers.Rotation {
|
||||
return d.rotation
|
||||
}
|
||||
|
||||
// SetRotation changes the rotation of the device (clock-wise)
|
||||
func (d *Device) SetRotation(rotation Rotation) {
|
||||
// GetRotation returns the current rotation of the device.
|
||||
//
|
||||
// Deprecated: use Rotation instead.
|
||||
func (d *Device) GetRotation() drivers.Rotation {
|
||||
return d.rotation
|
||||
}
|
||||
|
||||
// SetRotation changes the rotation of the device (clock-wise).
|
||||
func (d *Device) SetRotation(rotation drivers.Rotation) error {
|
||||
madctl := uint8(0)
|
||||
switch rotation % 8 {
|
||||
case Rotation0:
|
||||
@@ -291,6 +300,7 @@ func (d *Device) SetRotation(rotation Rotation) {
|
||||
cmdBuf[0] = madctl
|
||||
d.sendCommand(MADCTL, cmdBuf[:1])
|
||||
d.rotation = rotation
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetScrollArea sets an area to scroll with fixed top/bottom or left/right parts of the display
|
||||
|
||||
Reference in New Issue
Block a user