File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -13,14 +13,15 @@ import (
1313 "tinygo.org/x/drivers"
1414)
1515
16- // Device wraps an SPI connection.
16+ // Device wraps I2C or SPI connection.
1717type Device struct {
1818 bus Buser
1919 buffer []byte
2020 width int16
2121 height int16
2222 bufferSize int16
2323 vccState VccMode
24+ canReset bool
2425}
2526
2627// Config is the configuration for the display
@@ -98,6 +99,7 @@ func (d *Device) Configure(cfg Config) {
9899 }
99100 d .bufferSize = d .width * d .height / 8
100101 d .buffer = make ([]byte , d .bufferSize )
102+ d .canReset = cfg .Address != 0 || d .width != 128 || d .height != 64 // I2C or not 128x64
101103
102104 d .bus .configure ()
103105
@@ -178,9 +180,11 @@ func (d *Device) ClearDisplay() {
178180
179181// Display sends the whole buffer to the screen
180182func (d * Device ) Display () error {
183+ // Reset the screen to 0x0
184+ // This works fine with I2C
181185 // In the 128x64 (SPI) screen resetting to 0x0 after 128 times corrupt the buffer
182- // Since we're printing the whole buffer, avoid resetting it
183- if d .width != 128 || d . height != 64 {
186+ // Since we're printing the whole buffer, avoid resetting it in this case
187+ if d .canReset {
184188 d .Command (COLUMNADDR )
185189 d .Command (0 )
186190 d .Command (uint8 (d .width - 1 ))
You can’t perform that action at this time.
0 commit comments