mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-15 04:13:40 +00:00
Enable reset screen for SSD1306 via I2C
This commit is contained in:
+7
-3
@@ -13,7 +13,7 @@ import (
|
|||||||
"tinygo.org/x/drivers"
|
"tinygo.org/x/drivers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Device wraps an SPI connection.
|
// Device wraps I2C or SPI connection.
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus Buser
|
bus Buser
|
||||||
buffer []byte
|
buffer []byte
|
||||||
@@ -21,6 +21,7 @@ type Device struct {
|
|||||||
height int16
|
height int16
|
||||||
bufferSize int16
|
bufferSize int16
|
||||||
vccState VccMode
|
vccState VccMode
|
||||||
|
canReset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config is the configuration for the display
|
// Config is the configuration for the display
|
||||||
@@ -98,6 +99,7 @@ func (d *Device) Configure(cfg Config) {
|
|||||||
}
|
}
|
||||||
d.bufferSize = d.width * d.height / 8
|
d.bufferSize = d.width * d.height / 8
|
||||||
d.buffer = make([]byte, d.bufferSize)
|
d.buffer = make([]byte, d.bufferSize)
|
||||||
|
d.canReset = cfg.Address != 0 || d.width != 128 || d.height != 64 // I2C or not 128x64
|
||||||
|
|
||||||
d.bus.configure()
|
d.bus.configure()
|
||||||
|
|
||||||
@@ -178,9 +180,11 @@ func (d *Device) ClearDisplay() {
|
|||||||
|
|
||||||
// Display sends the whole buffer to the screen
|
// Display sends the whole buffer to the screen
|
||||||
func (d *Device) Display() error {
|
func (d *Device) Display() error {
|
||||||
|
// Reset the screen to 0x0
|
||||||
|
// This works fine with I2C
|
||||||
// In the 128x64 (SPI) screen resetting to 0x0 after 128 times corrupt the buffer
|
// In the 128x64 (SPI) screen resetting to 0x0 after 128 times corrupt the buffer
|
||||||
// Since we're printing the whole buffer, avoid resetting it
|
// Since we're printing the whole buffer, avoid resetting it in this case
|
||||||
if d.width != 128 || d.height != 64 {
|
if d.canReset {
|
||||||
d.Command(COLUMNADDR)
|
d.Command(COLUMNADDR)
|
||||||
d.Command(0)
|
d.Command(0)
|
||||||
d.Command(uint8(d.width - 1))
|
d.Command(uint8(d.width - 1))
|
||||||
|
|||||||
Reference in New Issue
Block a user