From 448ae64d8e2eb0cce9c5bd9dabd7f2354bb48682 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 1 Feb 2019 00:32:03 -0800 Subject: Add support for display rotation and raw commands Display rotation is relative to the scan order of the display. The scan order can be found by scrolling the display with command 0x37 `display_bus.send(0x37, struct.pack(">H", i % 128))` Fixes #1504 --- shared-bindings/displayio/ParallelBus.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'shared-bindings/displayio/ParallelBus.c') diff --git a/shared-bindings/displayio/ParallelBus.c b/shared-bindings/displayio/ParallelBus.c index 1ce1e2aff..abae114e2 100644 --- a/shared-bindings/displayio/ParallelBus.c +++ b/shared-bindings/displayio/ParallelBus.c @@ -102,7 +102,31 @@ STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t return self; } +//| .. method:: send(command, data) +//| +//| Sends the given command value followed by the full set of data. Display state, such as +//| vertical scroll, set via ``send`` may or may not be reset once the code is done. +//| +STATIC mp_obj_t displayio_parallelbus_obj_send(mp_obj_t self, mp_obj_t command_obj, mp_obj_t data_obj) { + mp_int_t command_int = MP_OBJ_SMALL_INT_VALUE(command_obj); + if (!MP_OBJ_IS_SMALL_INT(command_obj) || command_int > 255 || command_int < 0) { + mp_raise_ValueError(translate("Command must be an int between 0 and 255")); + } + uint8_t command = command_int; + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(data_obj, &bufinfo, MP_BUFFER_READ); + + common_hal_displayio_parallelbus_begin_transaction(self); + common_hal_displayio_parallelbus_send(self, true, &command, 1); + common_hal_displayio_parallelbus_send(self, false, ((uint8_t*) bufinfo.buf), bufinfo.len); + common_hal_displayio_parallelbus_end_transaction(self); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_3(displayio_parallelbus_send_obj, displayio_parallelbus_obj_send); + STATIC const mp_rom_map_elem_t displayio_parallelbus_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&displayio_parallelbus_send_obj) }, }; STATIC MP_DEFINE_CONST_DICT(displayio_parallelbus_locals_dict, displayio_parallelbus_locals_dict_table); -- cgit v1.2.3