mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-12 02:43:42 +00:00
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:
committed by
Ron Evans
parent
47dfeb9e94
commit
14994a3f31
@@ -15,8 +15,8 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
Width int16 // Width is the display resolution
|
Width int16 // Width is the display resolution
|
||||||
Height int16
|
Height int16
|
||||||
LogicalWidth int16 // LogicalWidth must be a multiple of 8 and same size or bigger than Width
|
LogicalWidth int16 // LogicalWidth must be a multiple of 8 and same size or bigger than Width
|
||||||
Rotation Rotation // Rotation is clock-wise
|
Rotation drivers.Rotation
|
||||||
}
|
}
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
@@ -30,10 +30,11 @@ type Device struct {
|
|||||||
height int16
|
height int16
|
||||||
buffer []uint8
|
buffer []uint8
|
||||||
bufferLength uint32
|
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
|
// Look up table for full updates
|
||||||
var lutFullUpdate = [30]uint8{
|
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 {
|
if x < 0 || y < 0 || x >= d.logicalWidth || y >= d.height || width < 0 || height < 0 {
|
||||||
return errors.New("wrong rectangle")
|
return errors.New("wrong rectangle")
|
||||||
}
|
}
|
||||||
if d.rotation == ROTATION_90 {
|
if d.rotation == drivers.Rotation90 {
|
||||||
width, height = height, width
|
width, height = height, width
|
||||||
x -= width
|
x -= width
|
||||||
} else if d.rotation == ROTATION_180 {
|
} else if d.rotation == drivers.Rotation180 {
|
||||||
x -= width - 1
|
x -= width - 1
|
||||||
y -= height - 1
|
y -= height - 1
|
||||||
} else if d.rotation == ROTATION_270 {
|
} else if d.rotation == drivers.Rotation270 {
|
||||||
width, height = height, width
|
width, height = height, width
|
||||||
y -= height
|
y -= height
|
||||||
}
|
}
|
||||||
@@ -301,27 +302,33 @@ func (d *Device) ClearBuffer() {
|
|||||||
|
|
||||||
// Size returns the current size of the display.
|
// Size returns the current size of the display.
|
||||||
func (d *Device) Size() (w, h int16) {
|
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.height, d.logicalWidth
|
||||||
}
|
}
|
||||||
return d.logicalWidth, d.height
|
return d.logicalWidth, d.height
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetRotation changes the rotation (clock-wise) of the device
|
// Rotation returns the current rotation of the device.
|
||||||
func (d *Device) SetRotation(rotation Rotation) {
|
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
|
d.rotation = rotation
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// xy chages the coordinates according to the rotation
|
// xy chages the coordinates according to the rotation
|
||||||
func (d *Device) xy(x, y int16) (int16, int16) {
|
func (d *Device) xy(x, y int16) (int16, int16) {
|
||||||
switch d.rotation {
|
switch d.rotation {
|
||||||
case NO_ROTATION:
|
case drivers.Rotation0:
|
||||||
return x, y
|
return x, y
|
||||||
case ROTATION_90:
|
case drivers.Rotation90:
|
||||||
return d.width - y - 1, x
|
return d.width - y - 1, x
|
||||||
case ROTATION_180:
|
case drivers.Rotation180:
|
||||||
return d.width - x - 1, d.height - y - 1
|
return d.width - x - 1, d.height - y - 1
|
||||||
case ROTATION_270:
|
case drivers.Rotation270:
|
||||||
return y, d.height - x - 1
|
return y, d.height - x - 1
|
||||||
}
|
}
|
||||||
return x, y
|
return x, y
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package epd2in13
|
package epd2in13
|
||||||
|
|
||||||
|
import "tinygo.org/x/drivers"
|
||||||
|
|
||||||
// Registers
|
// Registers
|
||||||
const (
|
const (
|
||||||
DRIVER_OUTPUT_CONTROL = 0x01
|
DRIVER_OUTPUT_CONTROL = 0x01
|
||||||
@@ -24,8 +26,8 @@ const (
|
|||||||
SET_RAM_Y_ADDRESS_COUNTER = 0x4F
|
SET_RAM_Y_ADDRESS_COUNTER = 0x4F
|
||||||
TERMINATE_FRAME_READ_WRITE = 0xFF
|
TERMINATE_FRAME_READ_WRITE = 0xFF
|
||||||
|
|
||||||
NO_ROTATION Rotation = 0
|
NO_ROTATION = drivers.Rotation0
|
||||||
ROTATION_90 Rotation = 1 // 90 degrees clock-wise rotation
|
ROTATION_90 = drivers.Rotation90 // 90 degrees clock-wise rotation
|
||||||
ROTATION_180 Rotation = 2
|
ROTATION_180 = drivers.Rotation180
|
||||||
ROTATION_270 Rotation = 3
|
ROTATION_270 = drivers.Rotation270
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user