epd2in13: unify rotation configuration with other displays

This commit updates rotation behavior to match other displays.
For more information, see: https://github.com/tinygo-org/drivers/pull/550

This changes the signature of `SetRotation` but I don't think any
existing code will be affected by this change.
This commit is contained in:
Ayke van Laethem
2023-11-06 18:17:51 +01:00
committed by Ron Evans
parent 47dfeb9e94
commit 14994a3f31
2 changed files with 27 additions and 18 deletions
+21 -14
View File
@@ -15,8 +15,8 @@ import (
type Config struct {
Width int16 // Width is the display resolution
Height int16
LogicalWidth int16 // LogicalWidth must be a multiple of 8 and same size or bigger than Width
Rotation Rotation // Rotation is clock-wise
LogicalWidth int16 // LogicalWidth must be a multiple of 8 and same size or bigger than Width
Rotation drivers.Rotation
}
type Device struct {
@@ -30,10 +30,11 @@ type Device struct {
height int16
buffer []uint8
bufferLength uint32
rotation Rotation
rotation drivers.Rotation
}
type Rotation uint8
// Deprecated: use drivers.Rotation instead.
type Rotation = drivers.Rotation
// Look up table for full updates
var lutFullUpdate = [30]uint8{
@@ -209,13 +210,13 @@ func (d *Device) DisplayRect(x int16, y int16, width int16, height int16) error
if x < 0 || y < 0 || x >= d.logicalWidth || y >= d.height || width < 0 || height < 0 {
return errors.New("wrong rectangle")
}
if d.rotation == ROTATION_90 {
if d.rotation == drivers.Rotation90 {
width, height = height, width
x -= width
} else if d.rotation == ROTATION_180 {
} else if d.rotation == drivers.Rotation180 {
x -= width - 1
y -= height - 1
} else if d.rotation == ROTATION_270 {
} else if d.rotation == drivers.Rotation270 {
width, height = height, width
y -= height
}
@@ -301,27 +302,33 @@ func (d *Device) ClearBuffer() {
// Size returns the current size of the display.
func (d *Device) Size() (w, h int16) {
if d.rotation == ROTATION_90 || d.rotation == ROTATION_270 {
if d.rotation == drivers.Rotation90 || d.rotation == drivers.Rotation270 {
return d.height, d.logicalWidth
}
return d.logicalWidth, d.height
}
// SetRotation changes the rotation (clock-wise) of the device
func (d *Device) SetRotation(rotation 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.
func (d *Device) SetRotation(rotation drivers.Rotation) error {
d.rotation = rotation
return nil
}
// xy chages the coordinates according to the rotation
func (d *Device) xy(x, y int16) (int16, int16) {
switch d.rotation {
case NO_ROTATION:
case drivers.Rotation0:
return x, y
case ROTATION_90:
case drivers.Rotation90:
return d.width - y - 1, x
case ROTATION_180:
case drivers.Rotation180:
return d.width - x - 1, d.height - y - 1
case ROTATION_270:
case drivers.Rotation270:
return y, d.height - x - 1
}
return x, y
+6 -4
View File
@@ -1,5 +1,7 @@
package epd2in13
import "tinygo.org/x/drivers"
// Registers
const (
DRIVER_OUTPUT_CONTROL = 0x01
@@ -24,8 +26,8 @@ const (
SET_RAM_Y_ADDRESS_COUNTER = 0x4F
TERMINATE_FRAME_READ_WRITE = 0xFF
NO_ROTATION Rotation = 0
ROTATION_90 Rotation = 1 // 90 degrees clock-wise rotation
ROTATION_180 Rotation = 2
ROTATION_270 Rotation = 3
NO_ROTATION = drivers.Rotation0
ROTATION_90 = drivers.Rotation90 // 90 degrees clock-wise rotation
ROTATION_180 = drivers.Rotation180
ROTATION_270 = drivers.Rotation270
)