47
47
//| objects in CircuitPython, Display objects live until `displayio.release_displays()`
48
48
//| is called. This is done so that CircuitPython can use the display itself.
49
49
//|
50
+ //| Most people should not use this class directly. Use a specific display driver instead that will
51
+ //| contain the initialization sequence at minimum.
52
+ //|
50
53
//| .. warning:: This will be changed before 4.0.0. Consider it very experimental.
51
54
//|
52
- //| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c)
55
+ //| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None )
53
56
//|
54
57
//| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
55
58
//|
56
- //| The ``init_sequence`` is bitbacked to minimize the ram impact. Every command begins with a
59
+ //| The ``init_sequence`` is bitpacked to minimize the ram impact. Every command begins with a
57
60
//| command byte followed by a byte to determine the parameter count and if a delay is need after.
58
61
//| When the top bit of the second byte is 1, the next byte will be the delay time in milliseconds.
59
62
//| The remaining 7 bits are the parameter count excluding any delay byte. The third through final
73
76
//| (b"") are merged together on load. The parens are needed to allow byte literals on subsequent
74
77
//| lines.
75
78
//|
79
+ //| The initialization sequence should always leave the display memory access inline with the scan
80
+ //| of the display to minimize tearing artifacts.
81
+ //|
76
82
//| :param displayio.FourWire or displayio.ParallelBus display_bus: The bus that the display is connected to
77
83
//| :param buffer init_sequence: Byte-packed initialization sequence.
78
84
//| :param int width: Width in pixels
79
85
//| :param int height: Height in pixels
80
86
//| :param int colstart: The index if the first visible column
81
87
//| :param int rowstart: The index if the first visible row
88
+ //| :param int rotation: The rotation of the display in 90 degree increments
82
89
//| :param int color_depth: The number of bits of color per pixel transmitted. (Some displays
83
90
//| support 18 bit but 16 is easier to transmit. The last bit is extrapolated.)
84
91
//| :param int set_column_command: Command used to set the start and end columns to update
85
92
//| :param int set_row_command: Command used so set the start and end rows to update
86
93
//| :param int write_ram_command: Command used to write pixels values into the update region
94
+ //| :param int set_vertical_scroll: Command used to set the first row to show
87
95
//| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight
88
96
//|
89
97
STATIC mp_obj_t displayio_display_make_new (const mp_obj_type_t * type , size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
90
- enum { ARG_display_bus , ARG_init_sequence , ARG_width , ARG_height , ARG_colstart , ARG_rowstart , ARG_color_depth , ARG_set_column_command , ARG_set_row_command , ARG_write_ram_command , ARG_backlight_pin };
98
+ enum { ARG_display_bus , ARG_init_sequence , ARG_width , ARG_height , ARG_colstart , ARG_rowstart , ARG_rotation , ARG_color_depth , ARG_set_column_command , ARG_set_row_command , ARG_write_ram_command , ARG_set_vertical_scroll , ARG_backlight_pin };
91
99
static const mp_arg_t allowed_args [] = {
92
100
{ MP_QSTR_display_bus , MP_ARG_REQUIRED | MP_ARG_OBJ },
93
101
{ MP_QSTR_init_sequence , MP_ARG_REQUIRED | MP_ARG_OBJ },
94
102
{ MP_QSTR_width , MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED , },
95
103
{ MP_QSTR_height , MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED , },
96
104
{ MP_QSTR_colstart , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0 } },
97
105
{ MP_QSTR_rowstart , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0 } },
106
+ { MP_QSTR_rotation , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0 } },
98
107
{ MP_QSTR_color_depth , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 16 } },
99
108
{ MP_QSTR_set_column_command , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0x2a } },
100
109
{ MP_QSTR_set_row_command , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0x2b } },
101
110
{ MP_QSTR_write_ram_command , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0x2c } },
111
+ { MP_QSTR_set_vertical_scroll , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0x0 } },
102
112
{ MP_QSTR_backlight_pin , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = mp_const_none } },
103
113
};
104
114
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
@@ -116,6 +126,10 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
116
126
backlight_pin = MP_OBJ_TO_PTR (backlight_pin_obj );
117
127
assert_pin_free (backlight_pin );
118
128
}
129
+ mp_int_t rotation = args [ARG_rotation ].u_int ;
130
+ if (rotation % 90 != 0 ) {
131
+ mp_raise_ValueError (translate ("Display rotation must be in 90 degree increments" ));
132
+ }
119
133
120
134
displayio_display_obj_t * self = NULL ;
121
135
for (uint8_t i = 0 ; i < CIRCUITPY_DISPLAY_LIMIT ; i ++ ) {
@@ -130,9 +144,11 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
130
144
}
131
145
self -> base .type = & displayio_display_type ;
132
146
common_hal_displayio_display_construct (self ,
133
- display_bus , args [ARG_width ].u_int , args [ARG_height ].u_int , args [ARG_colstart ].u_int , args [ARG_rowstart ].u_int ,
147
+ display_bus , args [ARG_width ].u_int , args [ARG_height ].u_int , args [ARG_colstart ].u_int , args [ARG_rowstart ].u_int , rotation ,
134
148
args [ARG_color_depth ].u_int , args [ARG_set_column_command ].u_int , args [ARG_set_row_command ].u_int ,
135
- args [ARG_write_ram_command ].u_int , bufinfo .buf , bufinfo .len , MP_OBJ_TO_PTR (backlight_pin ));
149
+ args [ARG_write_ram_command ].u_int ,
150
+ args [ARG_set_vertical_scroll ].u_int ,
151
+ bufinfo .buf , bufinfo .len , MP_OBJ_TO_PTR (backlight_pin ));
136
152
137
153
return self ;
138
154
}
0 commit comments