2828#include "py/mperrno.h"
2929#include "py/runtime.h"
3030#include "shared-bindings/busio/SPI.h"
31- #include "shared-bindings/displayio/FourWire .h"
31+ #include "shared-bindings/displayio/Display .h"
3232#include "shared-module/_stage/__init__.h"
3333#include "Layer.h"
3434#include "Text.h"
5050//| Layer
5151//| Text
5252//|
53- //| .. function:: render(x0, y0, x1, y1, layers, buffer, spi )
53+ //| .. function:: render(x0, y0, x1, y1, layers, buffer, display )
5454//|
5555//| Render and send to the display a fragment of the screen.
5656//|
6060//| :param int y1: Bottom edge of the fragment.
6161//| :param list layers: A list of the :py:class:`~_stage.Layer` objects.
6262//| :param bytearray buffer: A buffer to use for rendering.
63- //| :param ~busio.SPI spi : The SPI bus to use.
63+ //| :param ~displayio.Display display : The display to use.
6464//|
65- //| Note that this function only sends the raw pixel data. Setting up
66- //| the display for receiving it and handling the chip-select and
67- //| data-command pins has to be done outside of it.
6865//| There are also no sanity checks, outside of the basic overflow
6966//| checking. The caller is responsible for making the passed parameters
7067//| valid.
@@ -86,18 +83,19 @@ STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) {
8683 uint16_t * buffer = bufinfo .buf ;
8784 size_t buffer_size = bufinfo .len / 2 ; // 16-bit indexing
8885
89- displayio_fourwire_obj_t * bus = MP_OBJ_TO_PTR (args [6 ]);
86+ if (!MP_OBJ_IS_TYPE (args [6 ], & displayio_display_type )) {
87+ mp_raise_TypeError (translate ("expected displayio.Display" ));
88+ }
89+ displayio_display_obj_t * display = MP_OBJ_TO_PTR (args [6 ]);
9090
91- while (!common_hal_displayio_fourwire_begin_transaction ( bus )) {
91+ while (!displayio_display_begin_transaction ( display )) {
9292#ifdef MICROPY_VM_HOOK_LOOP
9393 MICROPY_VM_HOOK_LOOP ;
9494#endif
9595 }
96- if (!render_stage (x0 , y0 , x1 , y1 , layers , layers_size ,
97- buffer , buffer_size , bus -> bus )) {
98- mp_raise_OSError (MP_EIO );
99- }
100- common_hal_displayio_fourwire_end_transaction (bus );
96+ displayio_display_set_region_to_update (display , x0 , y0 , x1 , y1 );
97+ render_stage (x0 , y0 , x1 , y1 , layers , layers_size , buffer , buffer_size , display );
98+ displayio_display_end_transaction (display );
10199
102100 return mp_const_none ;
103101}
0 commit comments