Use displayio.Display directly

This commit is contained in:
Radomir Dopieralski 2019-04-12 11:56:23 +02:00
parent dabbded622
commit d39e7e7dd5
5 changed files with 20 additions and 28 deletions

@ -1 +1 @@
Subproject commit a7b3295ff573ce03cd7111a6cf7bf9cfe1e4f657
Subproject commit 069fad8357623f5ea2ff3c865a5b8ed54608afd7

View File

@ -28,7 +28,7 @@
#include "py/mperrno.h"
#include "py/runtime.h"
#include "shared-bindings/busio/SPI.h"
#include "shared-bindings/displayio/FourWire.h"
#include "shared-bindings/displayio/Display.h"
#include "shared-module/_stage/__init__.h"
#include "Layer.h"
#include "Text.h"
@ -50,7 +50,7 @@
//| Layer
//| Text
//|
//| .. function:: render(x0, y0, x1, y1, layers, buffer, spi)
//| .. function:: render(x0, y0, x1, y1, layers, buffer, display)
//|
//| Render and send to the display a fragment of the screen.
//|
@ -60,11 +60,8 @@
//| :param int y1: Bottom edge of the fragment.
//| :param list layers: A list of the :py:class:`~_stage.Layer` objects.
//| :param bytearray buffer: A buffer to use for rendering.
//| :param ~busio.SPI spi: The SPI bus to use.
//| :param ~displayio.Display display: The display to use.
//|
//| Note that this function only sends the raw pixel data. Setting up
//| the display for receiving it and handling the chip-select and
//| data-command pins has to be done outside of it.
//| There are also no sanity checks, outside of the basic overflow
//| checking. The caller is responsible for making the passed parameters
//| valid.
@ -86,18 +83,19 @@ STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) {
uint16_t *buffer = bufinfo.buf;
size_t buffer_size = bufinfo.len / 2; // 16-bit indexing
displayio_fourwire_obj_t *bus = MP_OBJ_TO_PTR(args[6]);
if (!MP_OBJ_IS_TYPE(args[6], &displayio_display_type)) {
mp_raise_TypeError(translate("expected displayio.Display"));
}
displayio_display_obj_t *display = MP_OBJ_TO_PTR(args[6]);
while (!common_hal_displayio_fourwire_begin_transaction(bus)) {
while (!displayio_display_begin_transaction(display)) {
#ifdef MICROPY_VM_HOOK_LOOP
MICROPY_VM_HOOK_LOOP ;
#endif
}
if (!render_stage(x0, y0, x1, y1, layers, layers_size,
buffer, buffer_size, bus->bus)) {
mp_raise_OSError(MP_EIO);
}
common_hal_displayio_fourwire_end_transaction(bus);
displayio_display_set_region_to_update(display, x0, y0, x1, y1);
render_stage(x0, y0, x1, y1, layers, layers_size, buffer, buffer_size, display);
displayio_display_end_transaction(display);
return mp_const_none;
}

View File

@ -31,10 +31,10 @@
#include "shared-bindings/_stage/Text.h"
bool render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
mp_obj_t *layers, size_t layers_size,
uint16_t *buffer, size_t buffer_size,
busio_spi_obj_t *spi) {
displayio_display_obj_t *display) {
size_t index = 0;
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,
index += 1;
// The buffer is full, send it.
if (index >= buffer_size) {
if (!common_hal_busio_spi_write(spi,
((uint8_t*)buffer), buffer_size * 2)) {
return false;
}
display->send(display->bus, false, ((uint8_t*)buffer), buffer_size * 2);
index = 0;
}
}
}
// Send the remaining data.
if (index) {
if (!common_hal_busio_spi_write(spi, ((uint8_t*)buffer), index * 2)) {
return false;
}
display->send(display->bus, false, ((uint8_t*)buffer), index * 2);
}
return true;
}

View File

@ -27,16 +27,16 @@
#ifndef MICROPY_INCLUDED_SHARED_MODULE__STAGE_H
#define MICROPY_INCLUDED_SHARED_MODULE__STAGE_H
#include "shared-bindings/busio/SPI.h"
#include "shared-bindings/displayio/Display.h"
#include <stdint.h>
#include <stdbool.h>
#include "py/obj.h"
#define TRANSPARENT (0x1ff8)
bool render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
mp_obj_t *layers, size_t layers_size,
uint16_t *buffer, size_t buffer_size,
busio_spi_obj_t *spi);
displayio_display_obj_t *display);
#endif // MICROPY_INCLUDED_SHARED_MODULE__STAGE

View File

@ -101,7 +101,7 @@ autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile
--output_c_file $(BUILD)/autogen_usb_descriptor.c\
--output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h
CIRCUITPY_DISPLAY_FONT = "../../tools/Tecate-bitmap-fonts/bitmap/terminus-font-4.39/ter-u12n.bdf"
CIRCUITPY_DISPLAY_FONT ?= "../../tools/Tecate-bitmap-fonts/bitmap/terminus-font-4.39/ter-u12n.bdf"
$(BUILD)/autogen_display_resources.c: ../../tools/gen_display_resources.py $(HEADER_BUILD)/qstrdefs.generated.h Makefile | $(HEADER_BUILD)
$(STEPECHO) "GEN $@"