@@ -10,7 +10,6 @@ import (
10
10
"time"
11
11
12
12
"tinygo.org/x/drivers"
13
- "tinygo.org/x/drivers/internal/legacy"
14
13
"tinygo.org/x/drivers/pixel"
15
14
)
16
15
@@ -128,7 +127,7 @@ func (d *Device) Configure(cfg Config) {
128
127
d .resetPage = ResetValue {0 , uint8 (d .height / 8 ) - 1 }
129
128
}
130
129
d .bufferSize = d .width * d .height / 8
131
- d .buffer = make ([]byte , d .bufferSize )
130
+ d .buffer = make ([]byte , d .bufferSize + 1 ) // +1 for the I2C command byte
132
131
d .canReset = cfg .Address != 0 || d .width != 128 || d .height != 64 // I2C or not 128x64
133
132
134
133
d .bus .configure ()
@@ -268,7 +267,8 @@ func (d *Device) GetBuffer() []byte {
268
267
269
268
// Command sends a command to the display
270
269
func (d * Device ) Command (command uint8 ) {
271
- d .bus .tx ([]byte {command }, true )
270
+ d .buffer [1 ] = command // The second byte is the actual command
271
+ d .bus .tx (d .buffer [0 :2 ], true )
272
272
}
273
273
274
274
// setAddress sets the address to the I2C bus
@@ -310,32 +310,24 @@ func (d *Device) Tx(data []byte, isCommand bool) error {
310
310
// tx sends data to the display (I2CBus implementation)
311
311
func (b * I2CBus ) tx (data []byte , isCommand bool ) error {
312
312
if isCommand {
313
- return legacy . WriteRegister ( b . wire , uint8 ( b . Address ), 0x00 , data )
313
+ data [ 0 ] = 0x00 // Command mode
314
314
} else {
315
- return legacy . WriteRegister ( b . wire , uint8 ( b . Address ), 0x40 , data )
315
+ data [ 0 ] = 0x40 // Data mode
316
316
}
317
+ return b .wire .Tx (uint16 (b .Address ), data , nil )
317
318
}
318
319
319
320
// tx sends data to the display (SPIBus implementation)
320
321
func (b * SPIBus ) tx (data []byte , isCommand bool ) error {
321
- var err error
322
-
322
+ b .csPin .High ()
323
323
if isCommand {
324
- b .csPin .High ()
325
324
b .dcPin .Low ()
326
- b .csPin .Low ()
327
-
328
- err = b .wire .Tx (data , nil )
329
- b .csPin .High ()
330
325
} else {
331
- b .csPin .High ()
332
326
b .dcPin .High ()
333
- b .csPin .Low ()
334
-
335
- err = b .wire .Tx (data , nil )
336
- b .csPin .High ()
337
327
}
338
-
328
+ b .csPin .Low ()
329
+ err := b .wire .Tx (data [1 :], nil ) // The first byte is reserved for I2C communcation, strip it
330
+ b .csPin .High ()
339
331
return err
340
332
}
341
333
0 commit comments