mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
ssd1306: Add function SetFlip and GetFlip (#702)
* ssd1306: Add SetRotation function
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package ssd1306
|
package ssd1306
|
||||||
|
|
||||||
|
import "tinygo.org/x/drivers"
|
||||||
|
|
||||||
// Registers
|
// Registers
|
||||||
const (
|
const (
|
||||||
Address = 0x3D
|
Address = 0x3D
|
||||||
@@ -38,4 +40,7 @@ const (
|
|||||||
|
|
||||||
EXTERNALVCC VccMode = 0x1
|
EXTERNALVCC VccMode = 0x1
|
||||||
SWITCHCAPVCC VccMode = 0x2
|
SWITCHCAPVCC VccMode = 0x2
|
||||||
|
|
||||||
|
NO_ROTATION = drivers.Rotation0
|
||||||
|
ROTATION_180 = drivers.Rotation180
|
||||||
)
|
)
|
||||||
|
|||||||
+21
-8
@@ -15,9 +15,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errBufferSize = errors.New("invalid size buffer")
|
errBufferSize = errors.New("invalid size buffer")
|
||||||
errOutOfRange = errors.New("out of screen range")
|
errOutOfRange = errors.New("out of screen range")
|
||||||
errNotImplemented = errors.New("not implemented")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ResetValue [2]byte
|
type ResetValue [2]byte
|
||||||
@@ -33,6 +32,7 @@ type Device struct {
|
|||||||
canReset bool
|
canReset bool
|
||||||
resetCol ResetValue
|
resetCol ResetValue
|
||||||
resetPage ResetValue
|
resetPage ResetValue
|
||||||
|
rotation drivers.Rotation
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config is the configuration for the display
|
// Config is the configuration for the display
|
||||||
@@ -48,6 +48,7 @@ type Config struct {
|
|||||||
// If you're using a different size, you might need to set these values manually.
|
// If you're using a different size, you might need to set these values manually.
|
||||||
ResetCol ResetValue
|
ResetCol ResetValue
|
||||||
ResetPage ResetValue
|
ResetPage ResetValue
|
||||||
|
Rotation drivers.Rotation
|
||||||
}
|
}
|
||||||
|
|
||||||
type I2CBus struct {
|
type I2CBus struct {
|
||||||
@@ -149,8 +150,8 @@ func (d *Device) Configure(cfg Config) {
|
|||||||
}
|
}
|
||||||
d.Command(MEMORYMODE)
|
d.Command(MEMORYMODE)
|
||||||
d.Command(0x00)
|
d.Command(0x00)
|
||||||
d.Command(SEGREMAP | 0x1)
|
|
||||||
d.Command(COMSCANDEC)
|
d.SetRotation(cfg.Rotation)
|
||||||
|
|
||||||
if (d.width == 128 && d.height == 64) || (d.width == 64 && d.height == 48) { // 128x64 or 64x48
|
if (d.width == 128 && d.height == 64) || (d.width == 64 && d.height == 48) { // 128x64 or 64x48
|
||||||
d.Command(SETCOMPINS)
|
d.Command(SETCOMPINS)
|
||||||
@@ -363,13 +364,25 @@ func (d *Device) DrawBitmap(x, y int16, bitmap pixel.Image[pixel.Monochrome]) er
|
|||||||
|
|
||||||
// Rotation returns the currently configured rotation.
|
// Rotation returns the currently configured rotation.
|
||||||
func (d *Device) Rotation() drivers.Rotation {
|
func (d *Device) Rotation() drivers.Rotation {
|
||||||
return drivers.Rotation0
|
return d.rotation
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetRotation changes the rotation of the device (clock-wise).
|
// SetRotation changes the rotation of the device (clock-wise).
|
||||||
// Would have to be implemented in software for this device.
|
|
||||||
func (d *Device) SetRotation(rotation drivers.Rotation) error {
|
func (d *Device) SetRotation(rotation drivers.Rotation) error {
|
||||||
return errNotImplemented
|
d.rotation = rotation
|
||||||
|
switch d.rotation {
|
||||||
|
case drivers.Rotation0:
|
||||||
|
d.Command(SEGREMAP | 0x1) // Reverse horizontal mapping
|
||||||
|
d.Command(COMSCANDEC) // Reverse vertical mapping
|
||||||
|
case drivers.Rotation180:
|
||||||
|
d.Command(SEGREMAP) // Normal horizontal mapping
|
||||||
|
d.Command(COMSCANINC) // Normal vertical mapping
|
||||||
|
// nothing to do
|
||||||
|
default:
|
||||||
|
d.Command(SEGREMAP | 0x1) // Reverse horizontal mapping
|
||||||
|
d.Command(COMSCANDEC) // Reverse vertical mapping
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the sleep mode for this display. When sleeping, the panel uses a lot
|
// Set the sleep mode for this display. When sleeping, the panel uses a lot
|
||||||
|
|||||||
Reference in New Issue
Block a user