@@ -13,6 +13,8 @@ import (
1313 "tinygo.org/x/drivers/internal/legacy"
1414)
1515
16+ type ResetValue [2 ]byte
17+
1618// Device wraps I2C or SPI connection.
1719type Device struct {
1820 bus Buser
@@ -22,6 +24,8 @@ type Device struct {
2224 bufferSize int16
2325 vccState VccMode
2426 canReset bool
27+ resetCol ResetValue
28+ resetPage ResetValue
2529}
2630
2731// Config is the configuration for the display
@@ -30,6 +34,13 @@ type Config struct {
3034 Height int16
3135 VccState VccMode
3236 Address uint16
37+ // ResetCol and ResetPage are used to reset the screen to 0x0
38+ // This is useful for some screens that have a different size than 128x64
39+ // For example, the Thumby's screen is 72x40
40+ // The default values are normally set automatically based on the size.
41+ // If you're using a different size, you might need to set these values manually.
42+ ResetCol ResetValue
43+ ResetPage ResetValue
3344}
3445
3546type I2CBus struct {
@@ -79,6 +90,7 @@ func NewSPI(bus drivers.SPI, dcPin, resetPin, csPin machine.Pin) Device {
7990
8091// Configure initializes the display with default configuration
8192func (d * Device ) Configure (cfg Config ) {
93+ var zeroReset ResetValue
8294 if cfg .Width != 0 {
8395 d .width = cfg .Width
8496 } else {
@@ -97,6 +109,16 @@ func (d *Device) Configure(cfg Config) {
97109 } else {
98110 d .vccState = SWITCHCAPVCC
99111 }
112+ if cfg .ResetCol != zeroReset {
113+ d .resetCol = cfg .ResetCol
114+ } else {
115+ d .resetCol = ResetValue {0 , uint8 (d .width - 1 )}
116+ }
117+ if cfg .ResetPage != zeroReset {
118+ d .resetPage = cfg .ResetPage
119+ } else {
120+ d .resetPage = ResetValue {0 , uint8 (d .height / 8 ) - 1 }
121+ }
100122 d .bufferSize = d .width * d .height / 8
101123 d .buffer = make ([]byte , d .bufferSize )
102124 d .canReset = cfg .Address != 0 || d .width != 128 || d .height != 64 // I2C or not 128x64
@@ -186,11 +208,11 @@ func (d *Device) Display() error {
186208 // Since we're printing the whole buffer, avoid resetting it in this case
187209 if d .canReset {
188210 d .Command (COLUMNADDR )
189- d .Command (0 )
190- d .Command (uint8 ( d . width - 1 ) )
211+ d .Command (d . resetCol [ 0 ] )
212+ d .Command (d . resetCol [ 1 ] )
191213 d .Command (PAGEADDR )
192- d .Command (0 )
193- d .Command (uint8 ( d . height / 8 ) - 1 )
214+ d .Command (d . resetPage [ 0 ] )
215+ d .Command (d . resetPage [ 1 ] )
194216 }
195217
196218 return d .Tx (d .buffer , false )
0 commit comments