Skip to content

Commit d39e7e7

Browse files
committed
Use displayio.Display directly
1 parent dabbded commit d39e7e7

5 files changed

Lines changed: 20 additions & 28 deletions

File tree

shared-bindings/_stage/__init__.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
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"
@@ -50,7 +50,7 @@
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
//|
@@ -60,11 +60,8 @@
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
}

shared-module/_stage/__init__.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
#include "shared-bindings/_stage/Text.h"
3232

3333

34-
bool render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
34+
void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
3535
mp_obj_t *layers, size_t layers_size,
3636
uint16_t *buffer, size_t buffer_size,
37-
busio_spi_obj_t *spi) {
37+
displayio_display_obj_t *display) {
3838

3939
size_t index = 0;
4040
for (uint16_t y = y0; y < y1; ++y) {
@@ -55,19 +55,13 @@ bool render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
5555
index += 1;
5656
// The buffer is full, send it.
5757
if (index >= buffer_size) {
58-
if (!common_hal_busio_spi_write(spi,
59-
((uint8_t*)buffer), buffer_size * 2)) {
60-
return false;
61-
}
58+
display->send(display->bus, false, ((uint8_t*)buffer), buffer_size * 2);
6259
index = 0;
6360
}
6461
}
6562
}
6663
// Send the remaining data.
6764
if (index) {
68-
if (!common_hal_busio_spi_write(spi, ((uint8_t*)buffer), index * 2)) {
69-
return false;
70-
}
65+
display->send(display->bus, false, ((uint8_t*)buffer), index * 2);
7166
}
72-
return true;
7367
}

shared-module/_stage/__init__.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
#ifndef MICROPY_INCLUDED_SHARED_MODULE__STAGE_H
2828
#define MICROPY_INCLUDED_SHARED_MODULE__STAGE_H
2929

30-
#include "shared-bindings/busio/SPI.h"
30+
#include "shared-bindings/displayio/Display.h"
3131
#include <stdint.h>
3232
#include <stdbool.h>
3333
#include "py/obj.h"
3434

3535
#define TRANSPARENT (0x1ff8)
3636

37-
bool render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
37+
void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
3838
mp_obj_t *layers, size_t layers_size,
3939
uint16_t *buffer, size_t buffer_size,
40-
busio_spi_obj_t *spi);
40+
displayio_display_obj_t *display);
4141

4242
#endif // MICROPY_INCLUDED_SHARED_MODULE__STAGE

supervisor/supervisor.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile
101101
--output_c_file $(BUILD)/autogen_usb_descriptor.c\
102102
--output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h
103103

104-
CIRCUITPY_DISPLAY_FONT = "../../tools/Tecate-bitmap-fonts/bitmap/terminus-font-4.39/ter-u12n.bdf"
104+
CIRCUITPY_DISPLAY_FONT ?= "../../tools/Tecate-bitmap-fonts/bitmap/terminus-font-4.39/ter-u12n.bdf"
105105

106106
$(BUILD)/autogen_display_resources.c: ../../tools/gen_display_resources.py $(HEADER_BUILD)/qstrdefs.generated.h Makefile | $(HEADER_BUILD)
107107
$(STEPECHO) "GEN $@"

0 commit comments

Comments
 (0)