@@ -15,9 +15,8 @@ import (
1515)
1616
1717var (
18- errBufferSize = errors .New ("invalid size buffer" )
19- errOutOfRange = errors .New ("out of screen range" )
20- errNotImplemented = errors .New ("not implemented" )
18+ errBufferSize = errors .New ("invalid size buffer" )
19+ errOutOfRange = errors .New ("out of screen range" )
2120)
2221
2322type ResetValue [2 ]byte
@@ -33,6 +32,7 @@ type Device struct {
3332 canReset bool
3433 resetCol ResetValue
3534 resetPage ResetValue
35+ rotation drivers.Rotation
3636}
3737
3838// Config is the configuration for the display
@@ -48,6 +48,7 @@ type Config struct {
4848 // If you're using a different size, you might need to set these values manually.
4949 ResetCol ResetValue
5050 ResetPage ResetValue
51+ Rotation drivers.Rotation
5152}
5253
5354type I2CBus struct {
@@ -149,8 +150,8 @@ func (d *Device) Configure(cfg Config) {
149150 }
150151 d .Command (MEMORYMODE )
151152 d .Command (0x00 )
152- d . Command ( SEGREMAP | 0x1 )
153- d .Command ( COMSCANDEC )
153+
154+ d .SetRotation ( cfg . Rotation )
154155
155156 if (d .width == 128 && d .height == 64 ) || (d .width == 64 && d .height == 48 ) { // 128x64 or 64x48
156157 d .Command (SETCOMPINS )
@@ -363,13 +364,25 @@ func (d *Device) DrawBitmap(x, y int16, bitmap pixel.Image[pixel.Monochrome]) er
363364
364365// Rotation returns the currently configured rotation.
365366func (d * Device ) Rotation () drivers.Rotation {
366- return drivers . Rotation0
367+ return d . rotation
367368}
368369
369370// SetRotation changes the rotation of the device (clock-wise).
370- // Would have to be implemented in software for this device.
371371func (d * Device ) SetRotation (rotation drivers.Rotation ) error {
372- return errNotImplemented
372+ d .rotation = rotation
373+ switch d .rotation {
374+ case drivers .Rotation0 :
375+ d .Command (SEGREMAP | 0x1 ) // Reverse horizontal mapping
376+ d .Command (COMSCANDEC ) // Reverse vertical mapping
377+ case drivers .Rotation180 :
378+ d .Command (SEGREMAP ) // Normal horizontal mapping
379+ d .Command (COMSCANINC ) // Normal vertical mapping
380+ // nothing to do
381+ default :
382+ d .Command (SEGREMAP | 0x1 ) // Reverse horizontal mapping
383+ d .Command (COMSCANDEC ) // Reverse vertical mapping
384+ }
385+ return nil
373386}
374387
375388// Set the sleep mode for this display. When sleeping, the panel uses a lot
0 commit comments