Skip to content

Commit f61f8f9

Browse files
committed
EPaperDisplay: add rotation property
untested, because I don't want to mess my magtag demo up :) but it builds
1 parent 8ac9b17 commit f61f8f9

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

shared-bindings/displayio/EPaperDisplay.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,29 @@ const mp_obj_property_t displayio_epaperdisplay_height_obj = {
294294
(mp_obj_t)&mp_const_none_obj},
295295
};
296296

297+
//| rotation: int
298+
//| """The rotation of the display as an int in degrees."""
299+
//|
300+
STATIC mp_obj_t displayio_epaperdisplay_obj_get_rotation(mp_obj_t self_in) {
301+
displayio_epaperdisplay_obj_t *self = native_display(self_in);
302+
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_epaperdisplay_get_rotation(self));
303+
}
304+
MP_DEFINE_CONST_FUN_OBJ_1(displayio_epaperdisplay_get_rotation_obj, displayio_epaperdisplay_obj_get_rotation);
305+
STATIC mp_obj_t displayio_epaperdisplay_obj_set_rotation(mp_obj_t self_in, mp_obj_t value) {
306+
displayio_epaperdisplay_obj_t *self = native_display(self_in);
307+
common_hal_displayio_epaperdisplay_set_rotation(self, mp_obj_get_int(value));
308+
return mp_const_none;
309+
}
310+
MP_DEFINE_CONST_FUN_OBJ_2(displayio_epaperdisplay_set_rotation_obj, displayio_epaperdisplay_obj_set_rotation);
311+
312+
313+
const mp_obj_property_t displayio_epaperdisplay_rotation_obj = {
314+
.base.type = &mp_type_property,
315+
.proxy = {(mp_obj_t)&displayio_epaperdisplay_get_rotation_obj,
316+
(mp_obj_t)&displayio_epaperdisplay_set_rotation_obj,
317+
(mp_obj_t)&mp_const_none_obj},
318+
};
319+
297320
//| bus: _DisplayBus
298321
//| """The bus being used by the display"""
299322
//|
@@ -317,6 +340,7 @@ STATIC const mp_rom_map_elem_t displayio_epaperdisplay_locals_dict_table[] = {
317340

318341
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_epaperdisplay_width_obj) },
319342
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_epaperdisplay_height_obj) },
343+
{ MP_ROM_QSTR(MP_QSTR_rotation), MP_ROM_PTR(&displayio_epaperdisplay_rotation_obj) },
320344
{ MP_ROM_QSTR(MP_QSTR_bus), MP_ROM_PTR(&displayio_epaperdisplay_bus_obj) },
321345
{ MP_ROM_QSTR(MP_QSTR_busy), MP_ROM_PTR(&displayio_epaperdisplay_busy_obj) },
322346
{ MP_ROM_QSTR(MP_QSTR_time_to_refresh), MP_ROM_PTR(&displayio_epaperdisplay_time_to_refresh_obj) },

shared-bindings/displayio/EPaperDisplay.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ bool common_hal_displayio_epaperdisplay_get_busy(displayio_epaperdisplay_obj_t*
5656

5757
uint16_t common_hal_displayio_epaperdisplay_get_width(displayio_epaperdisplay_obj_t* self);
5858
uint16_t common_hal_displayio_epaperdisplay_get_height(displayio_epaperdisplay_obj_t* self);
59+
uint16_t common_hal_displayio_epaperdisplay_get_rotation(displayio_epaperdisplay_obj_t* self);
60+
void common_hal_displayio_epaperdisplay_set_rotation(displayio_epaperdisplay_obj_t* self, int rotation);
5961

6062
mp_obj_t common_hal_displayio_epaperdisplay_get_bus(displayio_epaperdisplay_obj_t* self);
6163

shared-module/displayio/EPaperDisplay.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,29 @@ mp_obj_t common_hal_displayio_epaperdisplay_get_bus(displayio_epaperdisplay_obj_
198198
return self->core.bus;
199199
}
200200

201+
void common_hal_displayio_epaperdisplay_set_rotation(displayio_epaperdisplay_obj_t* self, int rotation){
202+
bool transposed = (self->core.rotation == 90 || self->core.rotation == 270);
203+
bool will_transposed = (rotation == 90 || rotation == 270);
204+
if(transposed != will_transposed) {
205+
int tmp = self->core.width;
206+
self->core.width = self->core.height;
207+
self->core.height = tmp;
208+
}
209+
displayio_display_core_set_rotation(&self->core, rotation);
210+
if (self == &displays[0].epaper_display) {
211+
supervisor_stop_terminal();
212+
supervisor_start_terminal(self->core.width, self->core.height);
213+
}
214+
if (self->core.current_group != NULL) {
215+
displayio_group_update_transform(self->core.current_group, &self->core.transform);
216+
}
217+
}
218+
219+
uint16_t common_hal_displayio_epaperdisplay_get_rotation(displayio_epaperdisplay_obj_t* self){
220+
return self->core.rotation;
221+
}
222+
223+
201224
bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t* self, const displayio_area_t* area) {
202225
uint16_t buffer_size = 128; // In uint32_ts
203226

0 commit comments

Comments
 (0)