mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-20 06:28:59 +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
|
||||
|
||||
+10
-8
@@ -1,5 +1,7 @@
|
||||
package ili9341
|
||||
|
||||
import "tinygo.org/x/drivers"
|
||||
|
||||
type Rotation uint8
|
||||
|
||||
const (
|
||||
@@ -77,13 +79,13 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
Rotation0 Rotation = 0
|
||||
Rotation90 Rotation = 1 // 90 degrees clock-wise rotation
|
||||
Rotation180 Rotation = 2
|
||||
Rotation270 Rotation = 3
|
||||
Rotation0 = drivers.Rotation0
|
||||
Rotation90 = drivers.Rotation90 // 90 degrees clock-wise rotation
|
||||
Rotation180 = drivers.Rotation180
|
||||
Rotation270 = drivers.Rotation270
|
||||
|
||||
Rotation0Mirror Rotation = 4
|
||||
Rotation90Mirror Rotation = 5
|
||||
Rotation180Mirror Rotation = 6
|
||||
Rotation270Mirror Rotation = 7
|
||||
Rotation0Mirror = drivers.Rotation0Mirror
|
||||
Rotation90Mirror = drivers.Rotation90Mirror
|
||||
Rotation180Mirror = drivers.Rotation180Mirror
|
||||
Rotation270Mirror = drivers.Rotation270Mirror
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user