@@ -14,7 +14,11 @@ import (
1414)
1515
1616type Model uint8
17- type Rotation uint8
17+
18+ // Rotation controls the rotation used by the display.
19+ //
20+ // Deprecated: use drivers.Rotation instead.
21+ type Rotation = drivers.Rotation
1822
1923var (
2024 errOutOfBounds = errors .New ("rectangle coordinates outside display area" )
@@ -31,7 +35,7 @@ type Device struct {
3135 height int16
3236 columnOffset int16
3337 rowOffset int16
34- rotation Rotation
38+ rotation drivers. Rotation
3539 batchLength int16
3640 model Model
3741 isBGR bool
@@ -42,7 +46,7 @@ type Device struct {
4246type Config struct {
4347 Width int16
4448 Height int16
45- Rotation Rotation
49+ Rotation drivers. Rotation
4650 Model Model
4751 RowOffset int16
4852 ColumnOffset int16
@@ -215,7 +219,7 @@ func (d *Device) SetPixel(x int16, y int16, c color.RGBA) {
215219
216220// setWindow prepares the screen to be modified at a given rectangle
217221func (d * Device ) setWindow (x , y , w , h int16 ) {
218- if d .rotation == NO_ROTATION || d .rotation == ROTATION_180 {
222+ if d .rotation == drivers . Rotation0 || d .rotation == drivers . Rotation180 {
219223 x += d .columnOffset
220224 y += d .rowOffset
221225 } else {
@@ -345,35 +349,38 @@ func (d *Device) DrawFastHLine(x0, x1, y int16, c color.RGBA) {
345349
346350// FillScreen fills the screen with a given color
347351func (d * Device ) FillScreen (c color.RGBA ) {
348- if d .rotation == NO_ROTATION || d .rotation == ROTATION_180 {
352+ if d .rotation == drivers . Rotation0 || d .rotation == drivers . Rotation180 {
349353 d .FillRectangle (0 , 0 , d .width , d .height , c )
350354 } else {
351355 d .FillRectangle (0 , 0 , d .height , d .width , c )
352356 }
353357}
354358
359+ // Rotation returns the currently configured rotation.
360+ func (d * Device ) Rotation () drivers.Rotation {
361+ return d .rotation
362+ }
363+
355364// SetRotation changes the rotation of the device (clock-wise)
356- func (d * Device ) SetRotation (rotation Rotation ) {
365+ func (d * Device ) SetRotation (rotation drivers.Rotation ) error {
366+ d .rotation = rotation
357367 madctl := uint8 (0 )
358368 switch rotation % 4 {
359- case 0 :
369+ case drivers . Rotation0 :
360370 madctl = MADCTL_MX | MADCTL_MY
361- break
362- case 1 :
371+ case drivers .Rotation90 :
363372 madctl = MADCTL_MY | MADCTL_MV
364- break
365- case 2 :
366- break
367- case 3 :
373+ case drivers .Rotation180 :
374+ // nothing to do
375+ case drivers .Rotation270 :
368376 madctl = MADCTL_MX | MADCTL_MV
369- break
370377 }
371378 if d .isBGR {
372379 madctl |= MADCTL_BGR
373380 }
374381 d .Command (MADCTL )
375382 d .Data (madctl )
376-
383+ return nil
377384}
378385
379386// Command sends a command to the display
@@ -394,7 +401,7 @@ func (d *Device) Tx(data []byte, isCommand bool) {
394401
395402// Size returns the current size of the display.
396403func (d * Device ) Size () (w , h int16 ) {
397- if d .rotation == NO_ROTATION || d .rotation == ROTATION_180 {
404+ if d .rotation == drivers . Rotation0 || d .rotation == drivers . Rotation180 {
398405 return d .width , d .height
399406 }
400407 return d .height , d .width
0 commit comments