Introduce displayio to render graphics to displays.
It's designed to minimize RAM footprint by using Sprites to represent objects on the screen. The object model also facilitates partial screen updating which reduces the bandwidth needed to display. This is all handled in C. Python simply manipulates the objects with the ability to synchronize to frame timing.
This commit is contained in:
parent
9b98ad7794
commit
6697544cdf
|
@ -2022,6 +2022,64 @@ msgstr ""
|
|||
msgid "Unsupported pull value."
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:66
|
||||
msgid "value_size must be power of two"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:85
|
||||
msgid "y should be an int"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:90
|
||||
msgid "row buffer must be a bytearray or array of type 'b' or 'B'"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:95
|
||||
msgid "row data must be a buffer"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/FourWire.c:55
|
||||
#: shared-bindings/displayio/FourWire.c:64
|
||||
msgid "displayio is a work in progress"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Group.c:65
|
||||
msgid "Group must have size at least 1"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:94
|
||||
msgid "color buffer must be a bytearray or array of type 'b' or 'B'"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:100
|
||||
msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGBA)"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:104
|
||||
msgid "color must be between 0x000000 and 0xffffff"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:108
|
||||
msgid "color buffer must be a buffer or int"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:124
|
||||
#: shared-bindings/displayio/Palette.c:138
|
||||
msgid "value should be an int"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Sprite.c:44
|
||||
msgid "position must be 2-tuple"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Sprite.c:86
|
||||
msgid "unsupported bitmap type"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Sprite.c:151
|
||||
msgid "palette must be displayio.Palette"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c:100
|
||||
msgid "too many arguments"
|
||||
msgstr ""
|
||||
|
@ -2236,6 +2294,14 @@ msgstr ""
|
|||
msgid "Cannot transfer without MOSI and MISO pins."
|
||||
msgstr ""
|
||||
|
||||
#: shared-module/displayio/Bitmap.c:60
|
||||
msgid "row must be packed and word aligned"
|
||||
msgstr ""
|
||||
|
||||
#: shared-module/displayio/Group.c:39
|
||||
msgid "Group full"
|
||||
msgstr ""
|
||||
|
||||
#: shared-module/struct/__init__.c:39
|
||||
msgid "'S' and 'O' are not supported format types"
|
||||
msgstr ""
|
||||
|
|
|
@ -2022,6 +2022,64 @@ msgstr ""
|
|||
msgid "Unsupported pull value."
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:66
|
||||
msgid "value_size must be power of two"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:85
|
||||
msgid "y should be an int"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:90
|
||||
msgid "row buffer must be a bytearray or array of type 'b' or 'B'"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:95
|
||||
msgid "row data must be a buffer"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/FourWire.c:55
|
||||
#: shared-bindings/displayio/FourWire.c:64
|
||||
msgid "displayio is a work in progress"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Group.c:65
|
||||
msgid "Group must have size at least 1"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:94
|
||||
msgid "color buffer must be a bytearray or array of type 'b' or 'B'"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:100
|
||||
msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGBA)"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:104
|
||||
msgid "color must be between 0x000000 and 0xffffff"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:108
|
||||
msgid "color buffer must be a buffer or int"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:124
|
||||
#: shared-bindings/displayio/Palette.c:138
|
||||
msgid "value should be an int"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Sprite.c:44
|
||||
msgid "position must be 2-tuple"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Sprite.c:86
|
||||
msgid "unsupported bitmap type"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Sprite.c:151
|
||||
msgid "palette must be displayio.Palette"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c:100
|
||||
msgid "too many arguments"
|
||||
msgstr ""
|
||||
|
@ -2236,6 +2294,14 @@ msgstr ""
|
|||
msgid "Cannot transfer without MOSI and MISO pins."
|
||||
msgstr ""
|
||||
|
||||
#: shared-module/displayio/Bitmap.c:60
|
||||
msgid "row must be packed and word aligned"
|
||||
msgstr ""
|
||||
|
||||
#: shared-module/displayio/Group.c:39
|
||||
msgid "Group full"
|
||||
msgstr ""
|
||||
|
||||
#: shared-module/struct/__init__.c:39
|
||||
msgid "'S' and 'O' are not supported format types"
|
||||
msgstr ""
|
||||
|
|
66
locale/es.po
66
locale/es.po
|
@ -2068,6 +2068,64 @@ msgstr ""
|
|||
msgid "Unsupported pull value."
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:66
|
||||
msgid "value_size must be power of two"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:85
|
||||
msgid "y should be an int"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:90
|
||||
msgid "row buffer must be a bytearray or array of type 'b' or 'B'"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:95
|
||||
msgid "row data must be a buffer"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/FourWire.c:55
|
||||
#: shared-bindings/displayio/FourWire.c:64
|
||||
msgid "displayio is a work in progress"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Group.c:65
|
||||
msgid "Group must have size at least 1"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:94
|
||||
msgid "color buffer must be a bytearray or array of type 'b' or 'B'"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:100
|
||||
msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGBA)"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:104
|
||||
msgid "color must be between 0x000000 and 0xffffff"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:108
|
||||
msgid "color buffer must be a buffer or int"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:124
|
||||
#: shared-bindings/displayio/Palette.c:138
|
||||
msgid "value should be an int"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Sprite.c:44
|
||||
msgid "position must be 2-tuple"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Sprite.c:86
|
||||
msgid "unsupported bitmap type"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Sprite.c:151
|
||||
msgid "palette must be displayio.Palette"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c:100
|
||||
msgid "too many arguments"
|
||||
msgstr ""
|
||||
|
@ -2283,6 +2341,14 @@ msgstr ""
|
|||
msgid "Cannot transfer without MOSI and MISO pins."
|
||||
msgstr ""
|
||||
|
||||
#: shared-module/displayio/Bitmap.c:60
|
||||
msgid "row must be packed and word aligned"
|
||||
msgstr ""
|
||||
|
||||
#: shared-module/displayio/Group.c:39
|
||||
msgid "Group full"
|
||||
msgstr ""
|
||||
|
||||
#: shared-module/struct/__init__.c:39
|
||||
msgid "'S' and 'O' are not supported format types"
|
||||
msgstr ""
|
||||
|
|
82
locale/fr.po
82
locale/fr.po
|
@ -2051,6 +2051,80 @@ msgstr "Le tirage 'pull' n'est pas utilisé quand la direction est 'output'"
|
|||
msgid "Unsupported pull value."
|
||||
msgstr "Valeur de 'pull' non supportée"
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:66
|
||||
#, fuzzy
|
||||
msgid "value_size must be power of two"
|
||||
msgstr "'len' doit être un multiple de 4"
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:85
|
||||
#, fuzzy
|
||||
msgid "y should be an int"
|
||||
msgstr "La longueur doit être entière"
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:90
|
||||
#, fuzzy
|
||||
msgid "row buffer must be a bytearray or array of type 'b' or 'B'"
|
||||
msgstr ""
|
||||
"le tampon de sample_source doit être un bytearray ou un tableau de type "
|
||||
"'h','H', 'b' ou 'B'"
|
||||
|
||||
#: shared-bindings/displayio/Bitmap.c:95
|
||||
#, fuzzy
|
||||
msgid "row data must be a buffer"
|
||||
msgstr "les constantes doivent être des entiers"
|
||||
|
||||
#: shared-bindings/displayio/FourWire.c:55
|
||||
#: shared-bindings/displayio/FourWire.c:64
|
||||
msgid "displayio is a work in progress"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Group.c:65
|
||||
#, fuzzy
|
||||
msgid "Group must have size at least 1"
|
||||
msgstr "Le tampon doit être de longueur au moins 1"
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:94
|
||||
#, fuzzy
|
||||
msgid "color buffer must be a bytearray or array of type 'b' or 'B'"
|
||||
msgstr ""
|
||||
"le tampon de sample_source doit être un bytearray ou un tableau de type "
|
||||
"'h','H', 'b' ou 'B'"
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:100
|
||||
msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGBA)"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:104
|
||||
#, fuzzy
|
||||
msgid "color must be between 0x000000 and 0xffffff"
|
||||
msgstr "Les octets 'bytes' doivent être entre 0 et 255"
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:108
|
||||
#, fuzzy
|
||||
msgid "color buffer must be a buffer or int"
|
||||
msgstr "le tampon doit être un objet bytes-like"
|
||||
|
||||
#: shared-bindings/displayio/Palette.c:124
|
||||
#: shared-bindings/displayio/Palette.c:138
|
||||
#, fuzzy
|
||||
msgid "value should be an int"
|
||||
msgstr "Les valeurs du tableau doivent être des octets simples 'bytes'"
|
||||
|
||||
#: shared-bindings/displayio/Sprite.c:44
|
||||
#, fuzzy
|
||||
msgid "position must be 2-tuple"
|
||||
msgstr "stop doit être 1 ou 2"
|
||||
|
||||
#: shared-bindings/displayio/Sprite.c:86
|
||||
#, fuzzy
|
||||
msgid "unsupported bitmap type"
|
||||
msgstr "Débit non supporté"
|
||||
|
||||
#: shared-bindings/displayio/Sprite.c:151
|
||||
#, fuzzy
|
||||
msgid "palette must be displayio.Palette"
|
||||
msgstr "la palette doit être longue de 32 octets"
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c:100
|
||||
msgid "too many arguments"
|
||||
msgstr "trop d'arguments"
|
||||
|
@ -2272,6 +2346,14 @@ msgstr "Impossible de lire sans broche MISO."
|
|||
msgid "Cannot transfer without MOSI and MISO pins."
|
||||
msgstr "Pas de transfert sans broches MOSI et MISO"
|
||||
|
||||
#: shared-module/displayio/Bitmap.c:60
|
||||
msgid "row must be packed and word aligned"
|
||||
msgstr ""
|
||||
|
||||
#: shared-module/displayio/Group.c:39
|
||||
msgid "Group full"
|
||||
msgstr ""
|
||||
|
||||
#: shared-module/struct/__init__.c:39
|
||||
msgid "'S' and 'O' are not supported format types"
|
||||
msgstr "'S' et 'O' ne sont pas des types de format supportés"
|
||||
|
|
|
@ -308,6 +308,7 @@ SRC_COMMON_HAL = \
|
|||
busio/UART.c \
|
||||
digitalio/__init__.c \
|
||||
digitalio/DigitalInOut.c \
|
||||
displayio/FourWire.c \
|
||||
i2cslave/__init__.c \
|
||||
i2cslave/I2CSlave.c \
|
||||
microcontroller/__init__.c \
|
||||
|
@ -381,6 +382,11 @@ SRC_SHARED_MODULE = \
|
|||
bitbangio/OneWire.c \
|
||||
bitbangio/SPI.c \
|
||||
busio/OneWire.c \
|
||||
displayio/__init__.c \
|
||||
displayio/Bitmap.c \
|
||||
displayio/Group.c \
|
||||
displayio/Palette.c \
|
||||
displayio/Sprite.c \
|
||||
gamepad/__init__.c \
|
||||
gamepad/GamePad.c \
|
||||
_stage/__init__.c \
|
||||
|
|
|
@ -30,12 +30,17 @@
|
|||
#include "usb.h"
|
||||
#include "usb_mass_storage.h"
|
||||
|
||||
#include "shared-module/displayio/__init__.h"
|
||||
|
||||
volatile uint64_t last_finished_tick = 0;
|
||||
|
||||
void run_background_tasks(void) {
|
||||
#if (defined(SAMD21) && defined(PIN_PA02)) || defined(SAMD51)
|
||||
audio_dma_background();
|
||||
#endif
|
||||
#ifdef CIRCUITPY_DISPLAYIO
|
||||
displayio_refresh_display();
|
||||
#endif
|
||||
usb_msc_background();
|
||||
usb_cdc_background();
|
||||
last_finished_tick = ticks_ms;
|
||||
|
|
|
@ -31,6 +31,14 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "py/mpconfig.h"
|
||||
|
||||
#ifdef CIRCUITPY_DISPLAYIO
|
||||
#include "common-hal/displayio/FourWire.h"
|
||||
|
||||
extern displayio_fourwire_obj_t board_display_obj;
|
||||
#endif
|
||||
|
||||
// Initializes board related state once on start up.
|
||||
void board_init(void);
|
||||
|
||||
|
|
|
@ -26,8 +26,72 @@
|
|||
|
||||
#include "boards/board.h"
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
#include "shared-bindings/displayio/FourWire.h"
|
||||
|
||||
#include "tick.h"
|
||||
|
||||
displayio_fourwire_obj_t board_display_obj;
|
||||
|
||||
uint8_t display_init_sequence[] = {
|
||||
0x01, 0, // SWRESET
|
||||
0x11, 0, // SLPOUT
|
||||
0xb1, 3, 0x01, 0x2C, 0x2D, // _FRMCTR1
|
||||
0xb2, 3, 0x01, 0x2C, 0x2D, //
|
||||
0xb3, 6, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D,
|
||||
0xb4, 1, 0x07, // _INVCTR line inversion
|
||||
0xc0, 3, 0xa2, 0x02, 0x84, // _PWCTR1 GVDD = 4.7V, 1.0uA
|
||||
0xc1, 1, 0xc5, // _PWCTR2 VGH=14.7V, VGL=-7.35V
|
||||
0xc2, 2, 0x0a, 0x00, // _PWCTR3 Opamp current small, Boost frequency
|
||||
0xc3, 2, 0x8a, 0x2a,
|
||||
0xc4, 2, 0x8a, 0xee,
|
||||
0xc5, 1, 0x0e, // _VMCTR1 VCOMH = 4V, VOML = -1.1V
|
||||
0x2a, 0, // _INVOFF
|
||||
0x36, 1, 0x18, // _MADCTL bottom to top refresh
|
||||
// 1 clk cycle nonoverlap, 2 cycle gate rise, 3 sycle osc equalie,
|
||||
// fix on VTL
|
||||
0x3a, 1, 0x05, // COLMOD - 16bit color
|
||||
0xe0, 16, 0x02, 0x1c, 0x07, 0x12, // _GMCTRP1 Gamma
|
||||
0x37, 0x32, 0x29, 0x2d,
|
||||
0x29, 0x25, 0x2B, 0x39,
|
||||
0x00, 0x01, 0x03, 0x10,
|
||||
0xe1, 16, 0x03, 0x1d, 0x07, 0x06, // _GMCTRN1
|
||||
0x2E, 0x2C, 0x29, 0x2D,
|
||||
0x2E, 0x2E, 0x37, 0x3F,
|
||||
0x00, 0x00, 0x02, 0x10,
|
||||
0x2a, 3, 0x02, 0x00, 0x81, // _CASET XSTART = 2, XEND = 129
|
||||
0x2b, 3, 0x02, 0x00, 0x81, // _RASET XSTART = 2, XEND = 129
|
||||
0x13, 0, // _NORON
|
||||
0x29, 0, // _DISPON
|
||||
};
|
||||
|
||||
void board_init(void) {
|
||||
board_display_obj.base.type = &displayio_fourwire_type;
|
||||
common_hal_displayio_fourwire_construct(&board_display_obj,
|
||||
&pin_PB23, &pin_PB22, &pin_PA28, &pin_PA01, &pin_PA27,
|
||||
128, 128, 2, 0, 16, 0x2a, 0x2b, 0x2c);
|
||||
|
||||
uint32_t i = 0;
|
||||
common_hal_displayio_fourwire_begin_transaction(&board_display_obj);
|
||||
while (i < sizeof(display_init_sequence)) {
|
||||
uint8_t *cmd = display_init_sequence + i;
|
||||
uint8_t data_size = *(cmd + 1);
|
||||
uint8_t *data = cmd + 2;
|
||||
common_hal_displayio_fourwire_send(&board_display_obj, true, cmd, 1);
|
||||
common_hal_displayio_fourwire_send(&board_display_obj, false, data, data_size);
|
||||
if (*cmd == 0x01) {
|
||||
uint64_t start = ticks_ms;
|
||||
while (ticks_ms - start < 120) {}
|
||||
} else if (*cmd == 0x11) {
|
||||
uint64_t start = ticks_ms;
|
||||
while (ticks_ms - start < 500) {}
|
||||
} {
|
||||
uint64_t start = ticks_ms;
|
||||
while (ticks_ms - start < 10) {}
|
||||
}
|
||||
i += 2 + data_size;
|
||||
|
||||
}
|
||||
common_hal_displayio_fourwire_end_transaction(&board_display_obj);
|
||||
}
|
||||
|
||||
bool board_requests_safe_mode(void) {
|
||||
|
@ -35,4 +99,5 @@ bool board_requests_safe_mode(void) {
|
|||
}
|
||||
|
||||
void reset_board(void) {
|
||||
common_hal_displayio_fourwire_show(&board_display_obj, NULL);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_PA12)
|
||||
|
||||
// Clock rates are off: Salae reads 12MHz which is the limit even though we set it to the safer 8MHz.
|
||||
// Clock rates are off: Saleae reads 12MHz which is the limit even though we set it to the safer 8MHz.
|
||||
#define SPI_FLASH_BAUDRATE (8000000)
|
||||
|
||||
#define SPI_FLASH_MOSI_PIN PIN_PB10
|
||||
|
@ -27,8 +27,8 @@
|
|||
#define SPI_FLASH_DIPO 1 // same as MISO pad
|
||||
|
||||
// These are pins not to reset.
|
||||
#define MICROPY_PORT_A (PORT_PA07 | PORT_PA12 | PORT_PA13 | PORT_PA24 | PORT_PA25)
|
||||
#define MICROPY_PORT_B ( PORT_PB10 | PORT_PB11 )
|
||||
#define MICROPY_PORT_A ( PORT_PA01 | PORT_PA07 | PORT_PA12 | PORT_PA13 | PORT_PA24 | PORT_PA25 | PORT_PA27 | PORT_PA28)
|
||||
#define MICROPY_PORT_B ( PORT_PB10 | PORT_PB11 | PORT_PB22 | PORT_PB23 )
|
||||
#define MICROPY_PORT_C ( 0 )
|
||||
|
||||
#include "external_flash/external_flash.h"
|
||||
|
@ -61,3 +61,5 @@
|
|||
// USB is always used internally so skip the pin objects for it.
|
||||
#define IGNORE_PIN_PA24 1
|
||||
#define IGNORE_PIN_PA25 1
|
||||
|
||||
#define CIRCUITPY_DISPLAYIO
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "shared-bindings/board/__init__.h"
|
||||
|
||||
#include "boards/board.h"
|
||||
#include "board_busses.h"
|
||||
|
||||
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
|
||||
|
@ -56,5 +57,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_display), MP_ROM_PTR(&board_display_obj)}
|
||||
};
|
||||
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/displayio/FourWire.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "shared-bindings/busio/SPI.h"
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
|
||||
#include "tick.h"
|
||||
|
||||
void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
|
||||
const mcu_pin_obj_t* clock, const mcu_pin_obj_t* data, const mcu_pin_obj_t* command,
|
||||
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, uint16_t width,
|
||||
uint16_t height, int16_t colstart, int16_t rowstart, uint16_t color_depth,
|
||||
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command) {
|
||||
|
||||
common_hal_busio_spi_construct(&self->bus, clock, data, mp_const_none);
|
||||
common_hal_digitalio_digitalinout_construct(&self->command, command);
|
||||
common_hal_digitalio_digitalinout_switch_to_output(&self->command, true, DRIVE_MODE_PUSH_PULL);
|
||||
common_hal_digitalio_digitalinout_construct(&self->chip_select, chip_select);
|
||||
common_hal_digitalio_digitalinout_switch_to_output(&self->chip_select, true, DRIVE_MODE_PUSH_PULL);
|
||||
|
||||
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
|
||||
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
|
||||
|
||||
self->width = width;
|
||||
self->height = height;
|
||||
self->color_depth = color_depth;
|
||||
self->set_column_command = set_column_command;
|
||||
self->set_row_command = set_row_command;
|
||||
self->write_ram_command = write_ram_command;
|
||||
self->current_group = NULL;
|
||||
self->colstart = colstart;
|
||||
self->rowstart = rowstart;
|
||||
}
|
||||
|
||||
bool common_hal_displayio_fourwire_begin_transaction(displayio_fourwire_obj_t* self) {
|
||||
if (!common_hal_busio_spi_try_lock(&self->bus)) {
|
||||
return false;
|
||||
}
|
||||
common_hal_busio_spi_configure(&self->bus, 12000000, 0, 0, 8);
|
||||
common_hal_digitalio_digitalinout_set_value(&self->chip_select, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void common_hal_displayio_fourwire_wait_for_send(displayio_fourwire_obj_t* self) {
|
||||
}
|
||||
|
||||
void common_hal_displayio_fourwire_send(displayio_fourwire_obj_t* self, bool command, uint8_t *data, uint32_t data_length) {
|
||||
common_hal_displayio_fourwire_wait_for_send(self);
|
||||
common_hal_digitalio_digitalinout_set_value(&self->command, !command);
|
||||
common_hal_busio_spi_write(&self->bus, data, data_length);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void common_hal_displayio_fourwire_end_transaction(displayio_fourwire_obj_t* self) {
|
||||
common_hal_digitalio_digitalinout_set_value(&self->chip_select, true);
|
||||
common_hal_busio_spi_unlock(&self->bus);
|
||||
}
|
||||
|
||||
void common_hal_displayio_fourwire_show(displayio_fourwire_obj_t* self, displayio_group_t* root_group) {
|
||||
self->current_group = root_group;
|
||||
common_hal_displayio_fourwire_refresh_soon(self);
|
||||
}
|
||||
|
||||
void common_hal_displayio_fourwire_refresh_soon(displayio_fourwire_obj_t* self) {
|
||||
self->refresh = true;
|
||||
}
|
||||
|
||||
int32_t common_hal_displayio_fourwire_wait_for_frame(displayio_fourwire_obj_t* self) {
|
||||
uint64_t last_refresh = self->last_refresh;
|
||||
while (last_refresh == self->last_refresh) {
|
||||
MICROPY_VM_HOOK_LOOP
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint16_t swap(uint16_t x) {
|
||||
return (x & 0x00ff) << 8 | x >> 8;
|
||||
}
|
||||
|
||||
void displayio_fourwire_start_region_update(displayio_fourwire_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||
common_hal_displayio_fourwire_begin_transaction(self);
|
||||
uint16_t data[2];
|
||||
common_hal_displayio_fourwire_send(self, true, &self->set_column_command, 1);
|
||||
data[0] = swap(x0 + self->colstart);
|
||||
data[1] = swap(x1-1 + self->colstart);
|
||||
common_hal_displayio_fourwire_send(self, false, (uint8_t*) data, 4);
|
||||
common_hal_displayio_fourwire_send(self, true, &self->set_row_command, 1);
|
||||
data[0] = swap(y0 + 1 + self->rowstart);
|
||||
data[1] = swap(y1 + self->rowstart);
|
||||
common_hal_displayio_fourwire_send(self, false, (uint8_t*) data, 4);
|
||||
common_hal_displayio_fourwire_send(self, true, &self->write_ram_command, 1);
|
||||
}
|
||||
|
||||
bool displayio_fourwire_send_pixels(displayio_fourwire_obj_t* self, uint32_t* pixels, uint32_t length) {
|
||||
// TODO: Set this up so its async and 32 bit DMA transfers.
|
||||
common_hal_displayio_fourwire_send(self, false, (uint8_t*) pixels, length*4);
|
||||
return true;
|
||||
}
|
||||
|
||||
void displayio_fourwire_finish_region_update(displayio_fourwire_obj_t* self) {
|
||||
common_hal_displayio_fourwire_end_transaction(self);
|
||||
}
|
||||
|
||||
bool displayio_fourwire_frame_queued(displayio_fourwire_obj_t* self) {
|
||||
// Refresh at ~30 fps.
|
||||
return (ticks_ms - self->last_refresh) > 32;
|
||||
}
|
||||
|
||||
bool displayio_fourwire_refresh_queued(displayio_fourwire_obj_t* self) {
|
||||
return self->refresh || (self->current_group != NULL && displayio_group_needs_refresh(self->current_group));
|
||||
}
|
||||
|
||||
void displayio_fourwire_finish_refresh(displayio_fourwire_obj_t* self) {
|
||||
if (self->current_group != NULL) {
|
||||
displayio_group_finish_refresh(self->current_group);
|
||||
}
|
||||
self->refresh = false;
|
||||
self->last_refresh = ticks_ms;
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_FOURWIRE_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_FOURWIRE_H
|
||||
|
||||
#include "common-hal/busio/SPI.h"
|
||||
#include "common-hal/digitalio/DigitalInOut.h"
|
||||
#include "shared-module/displayio/Group.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
busio_spi_obj_t bus;
|
||||
digitalio_digitalinout_obj_t command;
|
||||
digitalio_digitalinout_obj_t chip_select;
|
||||
digitalio_digitalinout_obj_t reset;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint16_t color_depth;
|
||||
uint8_t set_column_command;
|
||||
uint8_t set_row_command;
|
||||
uint8_t write_ram_command;
|
||||
displayio_group_t *current_group;
|
||||
bool refresh;
|
||||
uint64_t last_refresh;
|
||||
int16_t colstart;
|
||||
int16_t rowstart;
|
||||
} displayio_fourwire_obj_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_FOURWIRE_H
|
|
@ -171,6 +171,7 @@ extern const struct _mp_obj_module_t audioio_module;
|
|||
extern const struct _mp_obj_module_t audiobusio_module;
|
||||
extern const struct _mp_obj_module_t analogio_module;
|
||||
extern const struct _mp_obj_module_t digitalio_module;
|
||||
extern const struct _mp_obj_module_t displayio_module;
|
||||
extern const struct _mp_obj_module_t pulseio_module;
|
||||
extern const struct _mp_obj_module_t busio_module;
|
||||
extern const struct _mp_obj_module_t board_module;
|
||||
|
@ -232,11 +233,20 @@ extern const struct _mp_obj_module_t usb_hid_module;
|
|||
#define I2CSLAVE_MODULE
|
||||
#endif
|
||||
|
||||
#ifdef CIRCUITPY_DISPLAYIO
|
||||
#define DISPLAYIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_displayio), (mp_obj_t)&displayio_module },
|
||||
#else
|
||||
#define DISPLAYIO_MODULE
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef EXTRA_BUILTIN_MODULES
|
||||
#define EXTRA_BUILTIN_MODULES \
|
||||
AUDIOIO_MODULE \
|
||||
AUDIOBUSIO_MODULE \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_bitbangio), (mp_obj_t)&bitbangio_module }, \
|
||||
DISPLAYIO_MODULE \
|
||||
I2CSLAVE_MODULE \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_rotaryio), (mp_obj_t)&rotaryio_module }, \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_gamepad),(mp_obj_t)&gamepad_module }
|
||||
|
|
|
@ -186,8 +186,6 @@ safe_mode_t port_init(void) {
|
|||
#endif
|
||||
clock_init();
|
||||
|
||||
board_init();
|
||||
|
||||
// Configure millisecond timer initialization.
|
||||
tick_init();
|
||||
|
||||
|
@ -196,6 +194,10 @@ safe_mode_t port_init(void) {
|
|||
#endif
|
||||
|
||||
init_shared_dma();
|
||||
|
||||
// Init the board last so everything else is ready
|
||||
board_init();
|
||||
|
||||
#ifdef CIRCUITPY_CANARY_WORD
|
||||
// Run in safe mode if the canary is corrupt.
|
||||
if (_ezero != CIRCUITPY_CANARY_WORD) {
|
||||
|
@ -234,6 +236,12 @@ void reset_port(void) {
|
|||
if (sercom_instances[i] == MICROPY_HW_APA102_SERCOM) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
#ifdef CIRCUITPY_DISPLAYIO
|
||||
// TODO(tannewt): Make this dynamic.
|
||||
if (sercom_instances[i] == board_display_obj.bus.spi_desc.dev.prvt) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
// SWRST is same for all modes of SERCOMs.
|
||||
sercom_instances[i]->SPI.CTRLA.bit.SWRST = 1;
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/displayio/Bitmap.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lib/utils/context_manager_helpers.h"
|
||||
#include "py/binary.h"
|
||||
#include "py/objproperty.h"
|
||||
#include "py/runtime.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//|
|
||||
//| :class:`Bitmap` -- Stores values in a 2D array
|
||||
//| ==========================================================================
|
||||
//|
|
||||
//| Stores values of a certain size in a 2D array
|
||||
//|
|
||||
//| .. warning:: This will likely be changed before 4.0.0. Consider it very experimental.
|
||||
//|
|
||||
//| .. class:: Bitmap(width, height, value_size)
|
||||
//|
|
||||
//| Create a Bitmap object with the given fixed size.
|
||||
//|
|
||||
//| :param int width: The number of values wide
|
||||
//| :param int height: The number of values high
|
||||
//| :param int value_size: The value size in bits. Must be power of 2.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 3, 3, false);
|
||||
uint32_t width = mp_obj_get_int(pos_args[0]);
|
||||
uint32_t height = mp_obj_get_int(pos_args[1]);
|
||||
uint32_t value_size = mp_obj_get_int(pos_args[2]);
|
||||
uint32_t power_of_two = 1;
|
||||
while (value_size > power_of_two) {
|
||||
power_of_two <<= 1;
|
||||
}
|
||||
if (value_size != power_of_two) {
|
||||
mp_raise_ValueError(translate("value_size must be power of two"));
|
||||
}
|
||||
|
||||
displayio_bitmap_t *self = m_new_obj(displayio_bitmap_t);
|
||||
self->base.type = &displayio_bitmap_type;
|
||||
common_hal_displayio_bitmap_construct(self, width, height, value_size);
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
|
||||
//| .. method:: _load_row(y, data)
|
||||
//|
|
||||
//| Loads pre-packed data into the given row.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_bitmap_obj__load_row(mp_obj_t self_in, mp_obj_t y_in, mp_obj_t data_in) {
|
||||
displayio_bitmap_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_int_t y;
|
||||
if (!mp_obj_get_int_maybe(y_in, &y)) {
|
||||
mp_raise_ValueError(translate("y should be an int"));
|
||||
}
|
||||
mp_buffer_info_t bufinfo;
|
||||
if (mp_get_buffer(data_in, &bufinfo, MP_BUFFER_READ)) {
|
||||
if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) {
|
||||
mp_raise_ValueError(translate("row buffer must be a bytearray or array of type 'b' or 'B'"));
|
||||
}
|
||||
uint8_t* buf = bufinfo.buf;
|
||||
common_hal_displayio_bitmap_load_row(self, y, buf, bufinfo.len);
|
||||
} else {
|
||||
mp_raise_TypeError(translate("row data must be a buffer"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(displayio_bitmap__load_row_obj, displayio_bitmap_obj__load_row);
|
||||
|
||||
STATIC const mp_rom_map_elem_t displayio_bitmap_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR__load_row), MP_ROM_PTR(&displayio_bitmap__load_row_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(displayio_bitmap_locals_dict, displayio_bitmap_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t displayio_bitmap_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Bitmap,
|
||||
.make_new = displayio_bitmap_make_new,
|
||||
// TODO(tannewt): Implement subscr after slices support start, stop and step tuples.
|
||||
// .subscr = displayio_bitmap_subscr,
|
||||
.locals_dict = (mp_obj_dict_t*)&displayio_bitmap_locals_dict,
|
||||
};
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_BITMAP_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_BITMAP_H
|
||||
|
||||
#include "shared-module/displayio/Bitmap.h"
|
||||
|
||||
extern const mp_obj_type_t displayio_bitmap_type;
|
||||
|
||||
void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t width,
|
||||
uint32_t height, uint32_t value_size);
|
||||
|
||||
void common_hal_displayio_bitmap_load_row(displayio_bitmap_t *self, uint16_t y, uint8_t* data,
|
||||
uint16_t len);
|
||||
uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_BITMAP_H
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/displayio/FourWire.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lib/utils/context_manager_helpers.h"
|
||||
#include "py/binary.h"
|
||||
#include "py/objproperty.h"
|
||||
#include "py/runtime.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//|
|
||||
//| :class:`FourWire` -- Manage updating a display over SPI four wire protocol
|
||||
//| ==========================================================================
|
||||
//|
|
||||
//| Manage updating a display over SPI four wire protocol in the background while Python code runs.
|
||||
//| It doesn't handle display initialization.
|
||||
//|
|
||||
//| .. warning:: This will be changed before 4.0.0. Consider it very experimental.
|
||||
//|
|
||||
//| .. class:: FourWire(*, clock, data, command, chip_select, width, height, colstart, rowstart,
|
||||
//| color_depth, set_column_command, set_row_command, write_ram_command)
|
||||
//|
|
||||
//| Create a FourWire object associated with the given pins.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_raise_NotImplementedError(translate("displayio is a work in progress"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
||||
//| .. method:: send(command, data)
|
||||
//|
|
||||
//|
|
||||
STATIC mp_obj_t displayio_fourwire_obj_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_raise_NotImplementedError(translate("displayio is a work in progress"));
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_fourwire_send_obj, 1, displayio_fourwire_obj_send);
|
||||
|
||||
//| .. method:: show(group)
|
||||
//|
|
||||
//| Switches do displaying the given group of elements.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_fourwire_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
|
||||
displayio_fourwire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
displayio_group_t* group = MP_OBJ_TO_PTR(group_in);
|
||||
common_hal_displayio_fourwire_show(self, group);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_fourwire_show_obj, displayio_fourwire_obj_show);
|
||||
|
||||
//| .. method:: refresh_soon()
|
||||
//|
|
||||
//| Queues up a display refresh that happens in the background.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_fourwire_obj_refresh_soon(mp_obj_t self_in) {
|
||||
displayio_fourwire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
common_hal_displayio_fourwire_refresh_soon(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(displayio_fourwire_refresh_soon_obj, displayio_fourwire_obj_refresh_soon);
|
||||
|
||||
//| .. method:: wait_for_frame()
|
||||
//|
|
||||
//| Waits until the next frame has been transmitted to the display unless the wait count is
|
||||
//| behind the rendered frames. In that case, this will return immediately with the wait count.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_fourwire_obj_wait_for_frame(mp_obj_t self_in) {
|
||||
displayio_fourwire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_fourwire_wait_for_frame(self));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(displayio_fourwire_wait_for_frame_obj, displayio_fourwire_obj_wait_for_frame);
|
||||
|
||||
|
||||
STATIC const mp_rom_map_elem_t displayio_fourwire_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&displayio_fourwire_send_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&displayio_fourwire_show_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_refresh_soon), MP_ROM_PTR(&displayio_fourwire_refresh_soon_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_wait_for_frame), MP_ROM_PTR(&displayio_fourwire_wait_for_frame_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(displayio_fourwire_locals_dict, displayio_fourwire_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t displayio_fourwire_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_FourWire,
|
||||
.make_new = displayio_fourwire_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&displayio_fourwire_locals_dict,
|
||||
};
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017, 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_FOURWIRE_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_FOURWIRE_H
|
||||
|
||||
#include "common-hal/displayio/FourWire.h"
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
|
||||
#include "shared-module/displayio/Group.h"
|
||||
|
||||
extern const mp_obj_type_t displayio_fourwire_type;
|
||||
|
||||
// TODO(tannewt): Split this apart into FourWire and a Display object because the dimensions and
|
||||
// commands are also used for the parallel buses.
|
||||
void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
|
||||
const mcu_pin_obj_t* clock, const mcu_pin_obj_t* data, const mcu_pin_obj_t* command,
|
||||
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, uint16_t width, uint16_t height,
|
||||
int16_t colstart, int16_t rowstart, uint16_t color_depth,
|
||||
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command);
|
||||
|
||||
int32_t common_hal_displayio_fourwire_wait_for_frame(displayio_fourwire_obj_t* self);
|
||||
|
||||
bool common_hal_displayio_fourwire_begin_transaction(displayio_fourwire_obj_t* self);
|
||||
|
||||
void common_hal_displayio_fourwire_send(displayio_fourwire_obj_t* self, bool command, uint8_t *data, uint32_t data_length);
|
||||
|
||||
void common_hal_displayio_fourwire_end_transaction(displayio_fourwire_obj_t* self);
|
||||
|
||||
void common_hal_displayio_fourwire_show(displayio_fourwire_obj_t* self, displayio_group_t* root_group);
|
||||
|
||||
void common_hal_displayio_fourwire_refresh_soon(displayio_fourwire_obj_t* self);
|
||||
|
||||
void displayio_fourwire_start_region_update(displayio_fourwire_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
|
||||
void displayio_fourwire_finish_region_update(displayio_fourwire_obj_t* self);
|
||||
bool displayio_fourwire_frame_queued(displayio_fourwire_obj_t* self);
|
||||
|
||||
bool displayio_fourwire_refresh_queued(displayio_fourwire_obj_t* self);
|
||||
void displayio_fourwire_finish_refresh(displayio_fourwire_obj_t* self);
|
||||
bool displayio_fourwire_send_pixels(displayio_fourwire_obj_t* self, uint32_t* pixels, uint32_t length);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_FOURWIRE_H
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/displayio/Group.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lib/utils/context_manager_helpers.h"
|
||||
#include "py/binary.h"
|
||||
#include "py/objproperty.h"
|
||||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//|
|
||||
//| :class:`Group` -- Group together sprites and subgroups
|
||||
//| ==========================================================================
|
||||
//|
|
||||
//| Manage a group of sprites and groups and how they are inter-related.
|
||||
//|
|
||||
//| .. warning:: This will be changed before 4.0.0. Consider it very experimental.
|
||||
//|
|
||||
//| .. class:: Group(*, max_size=4)
|
||||
//|
|
||||
//| Create a Group of a given size.
|
||||
//|
|
||||
//| :param int max_size: The maximum group size.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
enum { ARG_max_size };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_max_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 4} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mp_int_t max_size = args[ARG_max_size].u_int;
|
||||
if (max_size < 1) {
|
||||
mp_raise_ValueError(translate("Group must have size at least 1"));
|
||||
}
|
||||
|
||||
displayio_group_t *self = m_new_obj(displayio_group_t);
|
||||
self->base.type = &displayio_group_type;
|
||||
common_hal_displayio_group_construct(self, max_size);
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: append(layer)
|
||||
//|
|
||||
//| Switches do displaying the given group of elements.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_group_obj_append(mp_obj_t self_in, mp_obj_t layer) {
|
||||
displayio_group_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
common_hal_displayio_group_append(self, layer);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_group_append_obj, displayio_group_obj_append);
|
||||
|
||||
STATIC const mp_rom_map_elem_t displayio_group_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_append), MP_ROM_PTR(&displayio_group_append_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(displayio_group_locals_dict, displayio_group_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t displayio_group_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Group,
|
||||
.make_new = displayio_group_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&displayio_group_locals_dict,
|
||||
};
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_GROUP_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_GROUP_H
|
||||
|
||||
#include "shared-module/displayio/Group.h"
|
||||
|
||||
extern const mp_obj_type_t displayio_group_type;
|
||||
|
||||
|
||||
void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size);
|
||||
void common_hal_displayio_group_append(displayio_group_t* self, mp_obj_t layer);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_GROUP_H
|
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/displayio/Palette.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lib/utils/context_manager_helpers.h"
|
||||
#include "py/binary.h"
|
||||
#include "py/objproperty.h"
|
||||
#include "py/runtime.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//|
|
||||
//| :class:`Palette` -- Stores a mapping from bitmap pixel values to display colors
|
||||
//| ===============================================================================
|
||||
//|
|
||||
//| Manage updating a display over SPI four wire protocol in the background while Python code runs.
|
||||
//| It doesn't handle display initialization.
|
||||
//|
|
||||
//| .. warning:: This will be changed before 4.0.0. Consider it very experimental.
|
||||
//|
|
||||
//| .. class:: Palette(color_count)
|
||||
//|
|
||||
//| Create a Palette object to store a set number of colors.
|
||||
//|
|
||||
//| :param int color_count: The number of colors in the Palette
|
||||
// TODO(tannewt): Add support for other color formats.
|
||||
// TODO(tannewt): Add support for 8-bit alpha blending.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
enum { ARG_color_count };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_color_count, MP_ARG_INT | MP_ARG_REQUIRED },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
displayio_palette_t *self = m_new_obj(displayio_palette_t);
|
||||
self->base.type = &displayio_palette_type;
|
||||
common_hal_displayio_palette_construct(self, args[ARG_color_count].u_int);
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
|
||||
if (value == MP_OBJ_NULL) {
|
||||
// delete item
|
||||
return MP_OBJ_NULL; // op not supported
|
||||
} else {
|
||||
displayio_palette_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
|
||||
return MP_OBJ_NULL; // Slicing not supported. Use a duplicate Palette to swap multiple colors atomically.
|
||||
} else {
|
||||
if (value == MP_OBJ_SENTINEL) {
|
||||
return MP_OBJ_NULL; // index read is not supported
|
||||
} else {
|
||||
size_t index = mp_get_index(&displayio_palette_type, self->max_value, index_in, false);
|
||||
|
||||
uint32_t color;
|
||||
mp_int_t int_value;
|
||||
mp_buffer_info_t bufinfo;
|
||||
if (mp_get_buffer(value, &bufinfo, MP_BUFFER_READ)) {
|
||||
if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) {
|
||||
mp_raise_ValueError(translate("color buffer must be a bytearray or array of type 'b' or 'B'"));
|
||||
}
|
||||
uint8_t* buf = bufinfo.buf;
|
||||
if (bufinfo.len == 3 || bufinfo.len == 4) {
|
||||
color = buf[0] << 16 | buf[1] << 8 | buf[2];
|
||||
} else {
|
||||
mp_raise_ValueError(translate("color buffer must be 3 bytes (RGB) or 4 bytes (RGBA)"));
|
||||
}
|
||||
} else if (mp_obj_get_int_maybe(value, &int_value)) {
|
||||
if (int_value < 0 || int_value > 0xffffff) {
|
||||
mp_raise_TypeError(translate("color must be between 0x000000 and 0xffffff"));
|
||||
}
|
||||
color = int_value;
|
||||
} else {
|
||||
mp_raise_TypeError(translate("color buffer must be a buffer or int"));
|
||||
}
|
||||
common_hal_displayio_palette_set_color(self, index, color);
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//| .. method:: make_transparent(value)
|
||||
//|
|
||||
STATIC mp_obj_t displayio_palette_obj_make_transparent(mp_obj_t self_in, mp_obj_t value_obj) {
|
||||
displayio_palette_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
mp_int_t value;
|
||||
if (!mp_obj_get_int_maybe(value_obj, &value)) {
|
||||
mp_raise_ValueError(translate("value should be an int"));
|
||||
}
|
||||
common_hal_displayio_palette_make_transparent(self, value);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_palette_make_transparent_obj, displayio_palette_obj_make_transparent);
|
||||
|
||||
//| .. method:: make_opaque(value)
|
||||
//|
|
||||
STATIC mp_obj_t displayio_palette_obj_make_opaque(mp_obj_t self_in, mp_obj_t value_obj) {
|
||||
displayio_palette_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
mp_int_t value;
|
||||
if (!mp_obj_get_int_maybe(value_obj, &value)) {
|
||||
mp_raise_ValueError(translate("value should be an int"));
|
||||
}
|
||||
common_hal_displayio_palette_make_opaque(self, value);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_palette_make_opaque_obj, displayio_palette_obj_make_opaque);
|
||||
|
||||
STATIC const mp_rom_map_elem_t displayio_palette_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_make_transparent), MP_ROM_PTR(&displayio_palette_make_transparent_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_make_opaque), MP_ROM_PTR(&displayio_palette_make_opaque_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(displayio_palette_locals_dict, displayio_palette_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t displayio_palette_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Palette,
|
||||
.make_new = displayio_palette_make_new,
|
||||
.subscr = palette_subscr,
|
||||
.locals_dict = (mp_obj_dict_t*)&displayio_palette_locals_dict,
|
||||
};
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_PALETTE_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_PALETTE_H
|
||||
|
||||
#include "shared-module/displayio/Palette.h"
|
||||
|
||||
extern const mp_obj_type_t displayio_palette_type;
|
||||
|
||||
void common_hal_displayio_palette_construct(displayio_palette_t* self, uint16_t color_count);
|
||||
void common_hal_displayio_palette_set_color(displayio_palette_t* self, uint32_t value, uint32_t color);
|
||||
|
||||
void common_hal_displayio_palette_make_opaque(displayio_palette_t* self, uint32_t value);
|
||||
void common_hal_displayio_palette_make_transparent(displayio_palette_t* self, uint32_t value);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_PALETTE_H
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/displayio/Sprite.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lib/utils/context_manager_helpers.h"
|
||||
#include "py/binary.h"
|
||||
#include "py/objproperty.h"
|
||||
#include "py/runtime.h"
|
||||
#include "shared-bindings/displayio/Bitmap.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
void parse_position(mp_obj_t position_obj, int16_t* x, int16_t* y) {
|
||||
mp_obj_tuple_t *position = MP_OBJ_TO_PTR(position_obj);
|
||||
if (MP_OBJ_IS_TYPE(position_obj, &mp_type_tuple) && position->len == 2) {
|
||||
*x = mp_obj_get_int(position->items[0]);
|
||||
*y = mp_obj_get_int(position->items[1]);
|
||||
} else if (position != mp_const_none) {
|
||||
mp_raise_TypeError(translate("position must be 2-tuple"));
|
||||
}
|
||||
}
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//|
|
||||
//| :class:`Sprite` -- A particular copy of an image to display
|
||||
//| ==========================================================================
|
||||
//|
|
||||
//| Position a particular image and palette combination.
|
||||
//|
|
||||
//| .. warning:: This will be changed before 4.0.0. Consider it very experimental.
|
||||
//|
|
||||
//| .. class:: Sprite(bitmap, *, palette, position, width, height)
|
||||
//|
|
||||
//| Create a Sprite object
|
||||
//|
|
||||
//|
|
||||
STATIC mp_obj_t displayio_sprite_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 4, true);
|
||||
mp_map_t kw_args;
|
||||
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
|
||||
enum { ARG_bitmap, ARG_palette, ARG_position, ARG_width, ARG_height };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_bitmap, MP_ARG_OBJ | MP_ARG_REQUIRED },
|
||||
{ MP_QSTR_palette, MP_ARG_OBJ | MP_ARG_KW_ONLY },
|
||||
{ MP_QSTR_position, MP_ARG_OBJ | MP_ARG_KW_ONLY },
|
||||
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
|
||||
{ MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mp_obj_t bitmap = args[ARG_bitmap].u_obj;
|
||||
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
if (MP_OBJ_IS_TYPE(bitmap, &displayio_bitmap_type)) {
|
||||
displayio_bitmap_t* bmp = MP_OBJ_TO_PTR(bitmap);
|
||||
width = bmp->width;
|
||||
height = bmp->height;
|
||||
} else {
|
||||
mp_raise_TypeError(translate("unsupported bitmap type"));
|
||||
}
|
||||
int16_t x = 0;
|
||||
int16_t y = 0;
|
||||
mp_obj_t position_obj = args[ARG_position].u_obj;
|
||||
parse_position(position_obj, &x, &y);
|
||||
|
||||
displayio_sprite_t *self = m_new_obj(displayio_sprite_t);
|
||||
self->base.type = &displayio_sprite_type;
|
||||
common_hal_displayio_sprite_construct(self, bitmap, args[ARG_palette].u_obj,
|
||||
width, height, x, y);
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. attribute:: position
|
||||
//|
|
||||
//| The position of the top-left corner of the sprite.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_sprite_obj_get_position(mp_obj_t self_in) {
|
||||
displayio_sprite_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
common_hal_displayio_sprite_get_position(self, &x, &y);
|
||||
|
||||
mp_obj_t coords[2];
|
||||
coords[0] = mp_obj_new_int(x);
|
||||
coords[1] = mp_obj_new_int(y);
|
||||
|
||||
return mp_obj_new_tuple(2, coords);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(displayio_sprite_get_position_obj, displayio_sprite_obj_get_position);
|
||||
|
||||
STATIC mp_obj_t displayio_sprite_obj_set_position(mp_obj_t self_in, mp_obj_t value) {
|
||||
displayio_sprite_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
int16_t x = 0;
|
||||
int16_t y = 0;
|
||||
parse_position(value, &x, &y);
|
||||
|
||||
common_hal_displayio_sprite_set_position(self, x, y);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_sprite_set_position_obj, displayio_sprite_obj_set_position);
|
||||
|
||||
const mp_obj_property_t displayio_sprite_position_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&displayio_sprite_get_position_obj,
|
||||
(mp_obj_t)&displayio_sprite_set_position_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: palette
|
||||
//|
|
||||
//| The color palette of the sprite.
|
||||
//|
|
||||
STATIC mp_obj_t displayio_sprite_obj_get_palette(mp_obj_t self_in) {
|
||||
displayio_sprite_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return common_hal_displayio_sprite_get_palette(self);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(displayio_sprite_get_palette_obj, displayio_sprite_obj_get_palette);
|
||||
|
||||
STATIC mp_obj_t displayio_sprite_obj_set_palette(mp_obj_t self_in, mp_obj_t palette_in) {
|
||||
displayio_sprite_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (!MP_OBJ_IS_TYPE(palette_in, &displayio_palette_type)) {
|
||||
mp_raise_TypeError(translate("palette must be displayio.Palette"));
|
||||
}
|
||||
displayio_palette_t *palette = MP_OBJ_TO_PTR(palette_in);
|
||||
|
||||
common_hal_displayio_sprite_set_palette(self, palette);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_sprite_set_palette_obj, displayio_sprite_obj_set_palette);
|
||||
|
||||
const mp_obj_property_t displayio_sprite_palette_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&displayio_sprite_get_palette_obj,
|
||||
(mp_obj_t)&displayio_sprite_set_palette_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
STATIC const mp_rom_map_elem_t displayio_sprite_locals_dict_table[] = {
|
||||
// Properties
|
||||
{ MP_ROM_QSTR(MP_QSTR_position), MP_ROM_PTR(&displayio_sprite_position_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_palette), MP_ROM_PTR(&displayio_sprite_palette_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(displayio_sprite_locals_dict, displayio_sprite_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t displayio_sprite_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Sprite,
|
||||
.make_new = displayio_sprite_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&displayio_sprite_locals_dict,
|
||||
};
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_SPRITE_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_SPRITE_H
|
||||
|
||||
#include "shared-module/displayio/Sprite.h"
|
||||
|
||||
extern const mp_obj_type_t displayio_sprite_type;
|
||||
|
||||
void common_hal_displayio_sprite_construct(displayio_sprite_t *self, mp_obj_t bitmap,
|
||||
mp_obj_t palette, uint16_t width, uint16_t height, uint16_t x, uint16_t y);
|
||||
|
||||
void common_hal_displayio_sprite_get_position(displayio_sprite_t *self, int16_t* x, int16_t* y);
|
||||
void common_hal_displayio_sprite_set_position(displayio_sprite_t *self, int16_t x, int16_t y);
|
||||
|
||||
displayio_palette_t* common_hal_displayio_sprite_get_palette(displayio_sprite_t *self);
|
||||
void common_hal_displayio_sprite_set_palette(displayio_sprite_t *self, displayio_palette_t* palette);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_SPRITE_H
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/displayio/__init__.h"
|
||||
#include "shared-bindings/displayio/Bitmap.h"
|
||||
#include "shared-bindings/displayio/FourWire.h"
|
||||
#include "shared-bindings/displayio/Group.h"
|
||||
#include "shared-bindings/displayio/Palette.h"
|
||||
#include "shared-bindings/displayio/Sprite.h"
|
||||
|
||||
//| :mod:`displayio` --- Native display driving
|
||||
//| =========================================================================
|
||||
//|
|
||||
//| .. module:: displayio
|
||||
//| :synopsis: Native helpers for driving displays
|
||||
//| :platform: SAMD21, SAMD51
|
||||
//|
|
||||
//| The `displayio` module contains classes to manage display output
|
||||
//| including synchronizing with refresh rates and partial updating. It does
|
||||
//| not include display initialization commands. It should live in a Python
|
||||
//| driver for use when a display is connected to a board. It should also be
|
||||
//| built into the board init when the board has the display on it.
|
||||
//|
|
||||
//| .. warning:: This will be changed before 4.0.0. Consider it very experimental.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| Bitmap
|
||||
//| FourWire
|
||||
//| Group
|
||||
//| Palette
|
||||
//| Sprite
|
||||
//|
|
||||
//| All libraries change hardware state but are never deinit
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t displayio_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_displayio) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Bitmap), MP_ROM_PTR(&displayio_bitmap_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Group), MP_ROM_PTR(&displayio_group_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Palette), MP_ROM_PTR(&displayio_palette_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Sprite), MP_ROM_PTR(&displayio_sprite_type) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_FourWire), MP_ROM_PTR(&displayio_fourwire_type) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(displayio_module_globals, displayio_module_globals_table);
|
||||
|
||||
const mp_obj_module_t displayio_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&displayio_module_globals,
|
||||
};
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
// Nothing now.
|
||||
|
||||
// typedef enum {
|
||||
// PIXEL_
|
||||
// } displayio_pixel_format;
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/displayio/Bitmap.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t width,
|
||||
uint32_t height, uint32_t value_size) {
|
||||
uint32_t row_width = width * value_size;
|
||||
// word align
|
||||
if (row_width % 32 != 0) {
|
||||
self->stride = (row_width / 32 + 1);
|
||||
} else {
|
||||
self->stride = row_width / 32;
|
||||
}
|
||||
self->width = width;
|
||||
self->height = height;
|
||||
self->data = m_malloc(self->stride * height * sizeof(uint32_t), false);
|
||||
|
||||
self->bits_per_value = value_size;
|
||||
|
||||
self->x_shift = 0;
|
||||
uint32_t power_of_two = 1;
|
||||
while (power_of_two < 32 / value_size ) {
|
||||
self->x_shift++;
|
||||
power_of_two <<= 1;
|
||||
}
|
||||
self->x_mask = (1 << self->x_shift) - 1; // Used as a modulus on the x value
|
||||
self->bitmask = (1 << value_size) - 1;
|
||||
}
|
||||
|
||||
void common_hal_displayio_bitmap_load_row(displayio_bitmap_t *self, uint16_t y, uint8_t* data, uint16_t len) {
|
||||
if (len != self->stride * 4) {
|
||||
mp_raise_ValueError(translate("row must be packed and word aligned"));
|
||||
}
|
||||
uint32_t* row_value = self->data + (y * self->stride);
|
||||
// Do the memcpy ourselves since we may want to flip endianness.
|
||||
for (uint32_t i = 0; i < self->stride; i++) {
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
uint32_t value = ((uint32_t *)data)[i];
|
||||
#pragma GCC diagnostic pop
|
||||
if (self->bits_per_value < 16) {
|
||||
value = ((value >> 24) & 0xff) |
|
||||
((value << 8) & 0xff0000) |
|
||||
((value >> 8) & 0xff00) |
|
||||
((value << 24) & 0xff000000);
|
||||
}
|
||||
*row_value = value;
|
||||
row_value++;
|
||||
}
|
||||
}
|
||||
uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t x, int16_t y) {
|
||||
int32_t row_start = y * self->stride;
|
||||
if (self->bits_per_value < 8) {
|
||||
uint32_t word = self->data[row_start + (x >> self->x_shift)];
|
||||
|
||||
return (word >> (32 - ((x & self->x_mask) + 1) * self->bits_per_value)) & self->bitmask;
|
||||
} else {
|
||||
uint32_t bytes_per_value = self->bits_per_value / 8;
|
||||
return self->data[row_start + x * bytes_per_value];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_BITMAP_H
|
||||
#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_BITMAP_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint32_t* data;
|
||||
uint16_t stride; // words
|
||||
uint8_t bits_per_value;
|
||||
uint8_t x_shift;
|
||||
uint8_t x_mask;
|
||||
uint16_t bitmask;
|
||||
} displayio_bitmap_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_BITMAP_H
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/displayio/Group.h"
|
||||
|
||||
#include "py/runtime.h"
|
||||
#include "shared-bindings/displayio/Sprite.h"
|
||||
|
||||
void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size) {
|
||||
mp_obj_t* children = m_new(mp_obj_t, max_size);
|
||||
displayio_group_construct(self, children, max_size);
|
||||
}
|
||||
|
||||
void common_hal_displayio_group_append(displayio_group_t* self, mp_obj_t layer) {
|
||||
if (self->size == self->max_size) {
|
||||
mp_raise_RuntimeError(translate("Group full"));
|
||||
}
|
||||
self->children[self->size] = layer;
|
||||
self->size++;
|
||||
}
|
||||
|
||||
void displayio_group_construct(displayio_group_t* self, mp_obj_t* child_array, uint32_t max_size) {
|
||||
self->x = 0;
|
||||
self->y = 1;
|
||||
self->children = child_array;
|
||||
self->max_size = max_size;
|
||||
}
|
||||
|
||||
bool displayio_group_get_pixel(displayio_group_t *self, int16_t x, int16_t y, uint16_t* pixel) {
|
||||
x -= self->x;
|
||||
y -= self->y;
|
||||
for (int32_t i = self->size - 1; i >= 0 ; i--) {
|
||||
mp_obj_t layer = self->children[i];
|
||||
if (MP_OBJ_IS_TYPE(layer, &displayio_sprite_type)) {
|
||||
if (displayio_sprite_get_pixel(layer, x, y, pixel)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// TODO: Tiled layer
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool displayio_group_needs_refresh(displayio_group_t *self) {
|
||||
for (int32_t i = self->size - 1; i >= 0 ; i--) {
|
||||
mp_obj_t layer = self->children[i];
|
||||
if (MP_OBJ_IS_TYPE(layer, &displayio_sprite_type)) {
|
||||
if (displayio_sprite_needs_refresh(layer)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// TODO: Tiled layer
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void displayio_group_finish_refresh(displayio_group_t *self) {
|
||||
for (int32_t i = self->size - 1; i >= 0 ; i--) {
|
||||
mp_obj_t layer = self->children[i];
|
||||
if (MP_OBJ_IS_TYPE(layer, &displayio_sprite_type)) {
|
||||
displayio_sprite_finish_refresh(layer);
|
||||
}
|
||||
// TODO: Tiled layer
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_GROUP_H
|
||||
#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_GROUP_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
uint16_t size;
|
||||
uint16_t max_size;
|
||||
mp_obj_t* children;
|
||||
} displayio_group_t;
|
||||
|
||||
|
||||
void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size);
|
||||
void common_hal_displayio_group_append(displayio_group_t* self, mp_obj_t layer);
|
||||
|
||||
void displayio_group_construct(displayio_group_t* self, mp_obj_t* child_array, uint32_t max_size);
|
||||
bool displayio_group_get_pixel(displayio_group_t *group, int16_t x, int16_t y, uint16_t *pixel);
|
||||
bool displayio_group_needs_refresh(displayio_group_t *self);
|
||||
void displayio_group_finish_refresh(displayio_group_t *self);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_GROUP_H
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/displayio/Palette.h"
|
||||
|
||||
void common_hal_displayio_palette_construct(displayio_palette_t* self, uint16_t color_count) {
|
||||
self->max_value = color_count;
|
||||
self->colors = (uint32_t *) m_malloc(color_count * sizeof(uint16_t), false);
|
||||
uint32_t opaque_byte_count = color_count / 8;
|
||||
if (color_count % 8 > 0) {
|
||||
opaque_byte_count += 1;
|
||||
}
|
||||
self->opaque = (uint32_t *) m_malloc(opaque_byte_count, false);
|
||||
}
|
||||
|
||||
void common_hal_displayio_palette_make_opaque(displayio_palette_t* self, uint32_t value) {
|
||||
self->opaque[value / 32] &= ~(0x1 << (value % 32));
|
||||
}
|
||||
|
||||
void common_hal_displayio_palette_make_transparent(displayio_palette_t* self, uint32_t value) {
|
||||
self->opaque[value / 32] |= (0x1 << (value % 32));
|
||||
}
|
||||
|
||||
void common_hal_displayio_palette_set_color(displayio_palette_t* self, uint32_t value, uint32_t color) {
|
||||
uint32_t shift = (value % 2) * 16;
|
||||
uint32_t masked = self->colors[value / 2] & ~(0xffff << shift);
|
||||
uint32_t b5 = (color >> 19);
|
||||
uint32_t g6 = (color >> 10) & 0x3f;
|
||||
uint32_t r5 = (color >> 3) & 0x1f;
|
||||
uint32_t packed = r5 << 11 | g6 << 5 | b5;
|
||||
// swap bytes
|
||||
packed = ((packed >> 8) & 0xff) | ((packed & 0xff) << 8);
|
||||
self->colors[value / 2] = masked | packed << shift;
|
||||
self->needs_refresh = true;
|
||||
}
|
||||
|
||||
bool displayio_palette_get_color(displayio_palette_t *self, uint32_t value, uint16_t* color) {
|
||||
if (value > self->max_value) {
|
||||
return false;
|
||||
}
|
||||
if ((self->opaque[value / 32] & (0x1 << (value % 32))) != 0) {
|
||||
return false;
|
||||
}
|
||||
*color = (self->colors[value / 2] >> (16 * (value % 2))) & 0xffff;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool displayio_palette_needs_refresh(displayio_palette_t *self) {
|
||||
return self->needs_refresh;
|
||||
}
|
||||
|
||||
void displayio_palette_finish_refresh(displayio_palette_t *self) {
|
||||
self->needs_refresh = false;
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_PALETTE_H
|
||||
#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_PALETTE_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
uint32_t* opaque;
|
||||
uint32_t* colors;
|
||||
uint8_t max_value;
|
||||
bool needs_refresh;
|
||||
} displayio_palette_t;
|
||||
|
||||
bool displayio_palette_get_color(displayio_palette_t *palette, uint32_t value, uint16_t* color);
|
||||
bool displayio_palette_needs_refresh(displayio_palette_t *self);
|
||||
void displayio_palette_finish_refresh(displayio_palette_t *self);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_PALLETE_H
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/displayio/Sprite.h"
|
||||
|
||||
|
||||
#include "shared-bindings/displayio/Bitmap.h"
|
||||
|
||||
void common_hal_displayio_sprite_construct(displayio_sprite_t *self, mp_obj_t bitmap,
|
||||
mp_obj_t palette, uint16_t width, uint16_t height, uint16_t x, uint16_t y) {
|
||||
self->width = width;
|
||||
self->height = height;
|
||||
self->bitmap = bitmap;
|
||||
self->palette = palette;
|
||||
self->x = x;
|
||||
self->y = y;
|
||||
}
|
||||
|
||||
void common_hal_displayio_sprite_get_position(displayio_sprite_t *self, int16_t* x, int16_t* y) {
|
||||
*x = self->x;
|
||||
*y = self->y;
|
||||
}
|
||||
|
||||
void common_hal_displayio_sprite_set_position(displayio_sprite_t *self, int16_t x, int16_t y) {
|
||||
self->x = x;
|
||||
self->y = y;
|
||||
self->needs_refresh = true;
|
||||
}
|
||||
|
||||
|
||||
displayio_palette_t* common_hal_displayio_sprite_get_palette(displayio_sprite_t *self) {
|
||||
return self->palette;
|
||||
}
|
||||
|
||||
void common_hal_displayio_sprite_set_palette(displayio_sprite_t *self, displayio_palette_t* palette) {
|
||||
self->palette = palette;
|
||||
self->needs_refresh = true;
|
||||
}
|
||||
|
||||
bool displayio_sprite_get_pixel(displayio_sprite_t *self, int16_t x, int16_t y, uint16_t* pixel) {
|
||||
x -= self->x;
|
||||
y -= self->y;
|
||||
if (y < 0 || y >= self->height || x >= self->width || x < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t value = common_hal_displayio_bitmap_get_pixel(self->bitmap, x, y);
|
||||
if (self->palette == mp_const_none) {
|
||||
*pixel = value;
|
||||
return true;
|
||||
} else if (MP_OBJ_IS_TYPE(self->palette, &displayio_palette_type) && displayio_palette_get_color(self->palette, value, pixel)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool displayio_sprite_needs_refresh(displayio_sprite_t *self) {
|
||||
return self->needs_refresh || displayio_palette_needs_refresh(self->palette);
|
||||
}
|
||||
|
||||
void displayio_sprite_finish_refresh(displayio_sprite_t *self) {
|
||||
self->needs_refresh = false;
|
||||
displayio_palette_finish_refresh(self->palette);
|
||||
// TODO(tannewt): We could double buffer changes to position and move them over here.
|
||||
// That way they won't change during a refresh and tear.
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_SPRITE_H
|
||||
#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_SPRITE_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "shared-bindings/displayio/Palette.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
mp_obj_t bitmap;
|
||||
displayio_palette_t* palette;
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
bool needs_refresh;
|
||||
} displayio_sprite_t;
|
||||
|
||||
bool displayio_sprite_get_pixel(displayio_sprite_t *sprite, int16_t x, int16_t y, uint16_t *pixel);
|
||||
bool displayio_sprite_needs_refresh(displayio_sprite_t *self);
|
||||
void displayio_sprite_finish_refresh(displayio_sprite_t *self);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_SPRITE_H
|
|
@ -0,0 +1,80 @@
|
|||
#include "shared-bindings/displayio/FourWire.h"
|
||||
|
||||
extern displayio_fourwire_obj_t board_display_obj;
|
||||
|
||||
void start_region_update(displayio_fourwire_obj_t* display, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||
// TODO delegate between different display types
|
||||
displayio_fourwire_start_region_update(display, x0, y0, x1, y1);
|
||||
}
|
||||
|
||||
void finish_region_update(displayio_fourwire_obj_t* display) {
|
||||
// TODO delegate between different display types
|
||||
displayio_fourwire_finish_region_update(display);
|
||||
}
|
||||
|
||||
void finish_refresh(displayio_fourwire_obj_t* display) {
|
||||
// TODO delegate between different display types
|
||||
displayio_fourwire_finish_refresh(display);
|
||||
}
|
||||
|
||||
bool frame_queued(displayio_fourwire_obj_t* display) {
|
||||
// TODO delegate between different display types
|
||||
return displayio_fourwire_frame_queued(display);
|
||||
}
|
||||
|
||||
bool refresh_queued(displayio_fourwire_obj_t* display) {
|
||||
// TODO delegate between different display types
|
||||
return displayio_fourwire_refresh_queued(display);
|
||||
}
|
||||
|
||||
bool send_pixels(displayio_fourwire_obj_t* display, uint32_t* pixels, uint32_t length) {
|
||||
// TODO delegate between different display types
|
||||
return displayio_fourwire_send_pixels(display, pixels, length);
|
||||
}
|
||||
|
||||
void displayio_refresh_display(void) {
|
||||
displayio_fourwire_obj_t* display = &board_display_obj;
|
||||
|
||||
if (!frame_queued(display)) {
|
||||
return;
|
||||
}
|
||||
if (refresh_queued(display)) {
|
||||
// We compute the pixels
|
||||
uint16_t x0 = 0;
|
||||
uint16_t y0 = 0;
|
||||
uint16_t x1 = display->width;
|
||||
uint16_t y1 = display->height;
|
||||
size_t index = 0;
|
||||
//size_t row_size = (x1 - x0);
|
||||
uint16_t buffer_size = 256;
|
||||
uint32_t buffer[buffer_size / 2];
|
||||
start_region_update(display, x0, y0, x1, y1);
|
||||
for (uint16_t y = y0; y < y1; ++y) {
|
||||
for (uint16_t x = x0; x < x1; ++x) {
|
||||
uint16_t* pixel = &(((uint16_t*)buffer)[index]);
|
||||
*pixel = 0;
|
||||
if (display->current_group != NULL) {
|
||||
displayio_group_get_pixel(display->current_group, x, y, pixel);
|
||||
}
|
||||
|
||||
|
||||
index += 1;
|
||||
// The buffer is full, send it.
|
||||
if (index >= buffer_size) {
|
||||
if (!send_pixels(display, buffer, buffer_size / 2)) {
|
||||
finish_region_update(display);
|
||||
return;
|
||||
}
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Send the remaining data.
|
||||
if (index && !send_pixels(display, buffer, index * 2)) {
|
||||
finish_region_update(display);
|
||||
return;
|
||||
}
|
||||
finish_region_update(display);
|
||||
}
|
||||
finish_refresh(display);
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H
|
||||
|
||||
void displayio_refresh_display(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H
|
Loading…
Reference in New Issue