mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-30 03:19:02 +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
+23
-16
@@ -14,7 +14,11 @@ import (
|
||||
)
|
||||
|
||||
type Model uint8
|
||||
type Rotation uint8
|
||||
|
||||
// Rotation controls the rotation used by the display.
|
||||
//
|
||||
// Deprecated: use drivers.Rotation instead.
|
||||
type Rotation = drivers.Rotation
|
||||
|
||||
var (
|
||||
errOutOfBounds = errors.New("rectangle coordinates outside display area")
|
||||
@@ -31,7 +35,7 @@ type Device struct {
|
||||
height int16
|
||||
columnOffset int16
|
||||
rowOffset int16
|
||||
rotation Rotation
|
||||
rotation drivers.Rotation
|
||||
batchLength int16
|
||||
model Model
|
||||
isBGR bool
|
||||
@@ -42,7 +46,7 @@ type Device struct {
|
||||
type Config struct {
|
||||
Width int16
|
||||
Height int16
|
||||
Rotation Rotation
|
||||
Rotation drivers.Rotation
|
||||
Model Model
|
||||
RowOffset int16
|
||||
ColumnOffset int16
|
||||
@@ -215,7 +219,7 @@ func (d *Device) SetPixel(x int16, y int16, c color.RGBA) {
|
||||
|
||||
// setWindow prepares the screen to be modified at a given rectangle
|
||||
func (d *Device) setWindow(x, y, w, h int16) {
|
||||
if d.rotation == NO_ROTATION || d.rotation == ROTATION_180 {
|
||||
if d.rotation == drivers.Rotation0 || d.rotation == drivers.Rotation180 {
|
||||
x += d.columnOffset
|
||||
y += d.rowOffset
|
||||
} else {
|
||||
@@ -345,35 +349,38 @@ func (d *Device) DrawFastHLine(x0, x1, y int16, c color.RGBA) {
|
||||
|
||||
// FillScreen fills the screen with a given color
|
||||
func (d *Device) FillScreen(c color.RGBA) {
|
||||
if d.rotation == NO_ROTATION || d.rotation == ROTATION_180 {
|
||||
if d.rotation == drivers.Rotation0 || d.rotation == drivers.Rotation180 {
|
||||
d.FillRectangle(0, 0, d.width, d.height, c)
|
||||
} else {
|
||||
d.FillRectangle(0, 0, d.height, d.width, c)
|
||||
}
|
||||
}
|
||||
|
||||
// Rotation returns the currently configured rotation.
|
||||
func (d *Device) Rotation() drivers.Rotation {
|
||||
return d.rotation
|
||||
}
|
||||
|
||||
// SetRotation changes the rotation of the device (clock-wise)
|
||||
func (d *Device) SetRotation(rotation Rotation) {
|
||||
func (d *Device) SetRotation(rotation drivers.Rotation) error {
|
||||
d.rotation = rotation
|
||||
madctl := uint8(0)
|
||||
switch rotation % 4 {
|
||||
case 0:
|
||||
case drivers.Rotation0:
|
||||
madctl = MADCTL_MX | MADCTL_MY
|
||||
break
|
||||
case 1:
|
||||
case drivers.Rotation90:
|
||||
madctl = MADCTL_MY | MADCTL_MV
|
||||
break
|
||||
case 2:
|
||||
break
|
||||
case 3:
|
||||
case drivers.Rotation180:
|
||||
// nothing to do
|
||||
case drivers.Rotation270:
|
||||
madctl = MADCTL_MX | MADCTL_MV
|
||||
break
|
||||
}
|
||||
if d.isBGR {
|
||||
madctl |= MADCTL_BGR
|
||||
}
|
||||
d.Command(MADCTL)
|
||||
d.Data(madctl)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Command sends a command to the display
|
||||
@@ -394,7 +401,7 @@ func (d *Device) Tx(data []byte, isCommand bool) {
|
||||
|
||||
// Size returns the current size of the display.
|
||||
func (d *Device) Size() (w, h int16) {
|
||||
if d.rotation == NO_ROTATION || d.rotation == ROTATION_180 {
|
||||
if d.rotation == drivers.Rotation0 || d.rotation == drivers.Rotation180 {
|
||||
return d.width, d.height
|
||||
}
|
||||
return d.height, d.width
|
||||
|
||||
Reference in New Issue
Block a user