From 6697544cdf87d0df5b761d401ad6ffe3a8d752fc Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 15 Aug 2018 11:01:01 -0700 Subject: [PATCH 1/4] 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. --- locale/circuitpython.pot | 66 +++++++ locale/en_US.po | 66 +++++++ locale/es.po | 66 +++++++ locale/fr.po | 82 ++++++++ ports/atmel-samd/Makefile | 6 + ports/atmel-samd/background.c | 5 + ports/atmel-samd/boards/board.h | 8 + .../boards/hallowing_m0_express/board.c | 69 ++++++- .../hallowing_m0_express/mpconfigboard.h | 8 +- .../boards/hallowing_m0_express/pins.c | 3 + .../common-hal/displayio/FourWire.c | 147 ++++++++++++++ .../common-hal/displayio/FourWire.h | 53 ++++++ ports/atmel-samd/mpconfigport.h | 10 + ports/atmel-samd/supervisor/port.c | 12 +- shared-bindings/displayio/Bitmap.c | 113 +++++++++++ shared-bindings/displayio/Bitmap.h | 41 ++++ shared-bindings/displayio/FourWire.c | 118 ++++++++++++ shared-bindings/displayio/FourWire.h | 65 +++++++ shared-bindings/displayio/Group.c | 96 ++++++++++ shared-bindings/displayio/Group.h | 38 ++++ shared-bindings/displayio/Palette.c | 157 +++++++++++++++ shared-bindings/displayio/Palette.h | 40 ++++ shared-bindings/displayio/Sprite.c | 180 ++++++++++++++++++ shared-bindings/displayio/Sprite.h | 43 +++++ shared-bindings/displayio/__init__.c | 83 ++++++++ shared-bindings/displayio/__init__.h | 38 ++++ shared-module/displayio/Bitmap.c | 89 +++++++++ shared-module/displayio/Bitmap.h | 47 +++++ shared-module/displayio/Group.c | 88 +++++++++ shared-module/displayio/Group.h | 53 ++++++ shared-module/displayio/Palette.c | 78 ++++++++ shared-module/displayio/Palette.h | 47 +++++ shared-module/displayio/Sprite.c | 90 +++++++++ shared-module/displayio/Sprite.h | 51 +++++ shared-module/displayio/__init__.c | 80 ++++++++ shared-module/displayio/__init__.h | 32 ++++ 36 files changed, 2261 insertions(+), 7 deletions(-) create mode 100644 ports/atmel-samd/common-hal/displayio/FourWire.c create mode 100644 ports/atmel-samd/common-hal/displayio/FourWire.h create mode 100644 shared-bindings/displayio/Bitmap.c create mode 100644 shared-bindings/displayio/Bitmap.h create mode 100644 shared-bindings/displayio/FourWire.c create mode 100644 shared-bindings/displayio/FourWire.h create mode 100644 shared-bindings/displayio/Group.c create mode 100644 shared-bindings/displayio/Group.h create mode 100644 shared-bindings/displayio/Palette.c create mode 100644 shared-bindings/displayio/Palette.h create mode 100644 shared-bindings/displayio/Sprite.c create mode 100644 shared-bindings/displayio/Sprite.h create mode 100644 shared-bindings/displayio/__init__.c create mode 100644 shared-bindings/displayio/__init__.h create mode 100644 shared-module/displayio/Bitmap.c create mode 100644 shared-module/displayio/Bitmap.h create mode 100644 shared-module/displayio/Group.c create mode 100644 shared-module/displayio/Group.h create mode 100644 shared-module/displayio/Palette.c create mode 100644 shared-module/displayio/Palette.h create mode 100644 shared-module/displayio/Sprite.c create mode 100644 shared-module/displayio/Sprite.h create mode 100644 shared-module/displayio/__init__.c create mode 100644 shared-module/displayio/__init__.h diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index ddf3ce98fd..c7b7085b71 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -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 "" diff --git a/locale/en_US.po b/locale/en_US.po index 439b67a0ab..78e32cc823 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -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 "" diff --git a/locale/es.po b/locale/es.po index 19d2830ad9..c9de75c382 100644 --- a/locale/es.po +++ b/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 "" diff --git a/locale/fr.po b/locale/fr.po index 732e663f23..3bbd779693 100644 --- a/locale/fr.po +++ b/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" diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index e1634a1b9b..9c94e442f0 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -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 \ diff --git a/ports/atmel-samd/background.c b/ports/atmel-samd/background.c index 62d891b15a..f25ec7200d 100644 --- a/ports/atmel-samd/background.c +++ b/ports/atmel-samd/background.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; diff --git a/ports/atmel-samd/boards/board.h b/ports/atmel-samd/boards/board.h index a2a73cfab4..61acc730ef 100644 --- a/ports/atmel-samd/boards/board.h +++ b/ports/atmel-samd/boards/board.h @@ -31,6 +31,14 @@ #include +#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); diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index c8e20206a1..69d7ecd37a 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -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); } diff --git a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h index 34e9ac3279..977ba183f6 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h @@ -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 diff --git a/ports/atmel-samd/boards/hallowing_m0_express/pins.c b/ports/atmel-samd/boards/hallowing_m0_express/pins.c index 8d6f9431e4..28c3d6a5ca 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/pins.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/pins.c @@ -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); diff --git a/ports/atmel-samd/common-hal/displayio/FourWire.c b/ports/atmel-samd/common-hal/displayio/FourWire.c new file mode 100644 index 0000000000..42038a58e0 --- /dev/null +++ b/ports/atmel-samd/common-hal/displayio/FourWire.c @@ -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 + +#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; +} diff --git a/ports/atmel-samd/common-hal/displayio/FourWire.h b/ports/atmel-samd/common-hal/displayio/FourWire.h new file mode 100644 index 0000000000..b997176701 --- /dev/null +++ b/ports/atmel-samd/common-hal/displayio/FourWire.h @@ -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 diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index 5763254619..58f74d7ec8 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.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 } diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index 9576422693..f6d968a1cb 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -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; diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c new file mode 100644 index 0000000000..b01fe0e0cf --- /dev/null +++ b/shared-bindings/displayio/Bitmap.c @@ -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 + +#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, +}; diff --git a/shared-bindings/displayio/Bitmap.h b/shared-bindings/displayio/Bitmap.h new file mode 100644 index 0000000000..2ae4684818 --- /dev/null +++ b/shared-bindings/displayio/Bitmap.h @@ -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 diff --git a/shared-bindings/displayio/FourWire.c b/shared-bindings/displayio/FourWire.c new file mode 100644 index 0000000000..c0d60bd3b4 --- /dev/null +++ b/shared-bindings/displayio/FourWire.c @@ -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 + +#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, +}; diff --git a/shared-bindings/displayio/FourWire.h b/shared-bindings/displayio/FourWire.h new file mode 100644 index 0000000000..fc51f558dd --- /dev/null +++ b/shared-bindings/displayio/FourWire.h @@ -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 diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c new file mode 100644 index 0000000000..a2a8799875 --- /dev/null +++ b/shared-bindings/displayio/Group.c @@ -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 + +#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, +}; diff --git a/shared-bindings/displayio/Group.h b/shared-bindings/displayio/Group.h new file mode 100644 index 0000000000..aeb5a7b545 --- /dev/null +++ b/shared-bindings/displayio/Group.h @@ -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 diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c new file mode 100644 index 0000000000..bb2af94105 --- /dev/null +++ b/shared-bindings/displayio/Palette.c @@ -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 + +#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, +}; diff --git a/shared-bindings/displayio/Palette.h b/shared-bindings/displayio/Palette.h new file mode 100644 index 0000000000..fde6ab7d38 --- /dev/null +++ b/shared-bindings/displayio/Palette.h @@ -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 diff --git a/shared-bindings/displayio/Sprite.c b/shared-bindings/displayio/Sprite.c new file mode 100644 index 0000000000..25ea79f5c2 --- /dev/null +++ b/shared-bindings/displayio/Sprite.c @@ -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 + +#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, +}; diff --git a/shared-bindings/displayio/Sprite.h b/shared-bindings/displayio/Sprite.h new file mode 100644 index 0000000000..0bfa400446 --- /dev/null +++ b/shared-bindings/displayio/Sprite.h @@ -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 diff --git a/shared-bindings/displayio/__init__.c b/shared-bindings/displayio/__init__.c new file mode 100644 index 0000000000..73f12db955 --- /dev/null +++ b/shared-bindings/displayio/__init__.c @@ -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 + +#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, +}; diff --git a/shared-bindings/displayio/__init__.h b/shared-bindings/displayio/__init__.h new file mode 100644 index 0000000000..5c3fc2b55c --- /dev/null +++ b/shared-bindings/displayio/__init__.h @@ -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 diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c new file mode 100644 index 0000000000..7c6a2ee806 --- /dev/null +++ b/shared-module/displayio/Bitmap.c @@ -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 + +#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]; + } +} diff --git a/shared-module/displayio/Bitmap.h b/shared-module/displayio/Bitmap.h new file mode 100644 index 0000000000..781a4d12a3 --- /dev/null +++ b/shared-module/displayio/Bitmap.h @@ -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 +#include + +#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 diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c new file mode 100644 index 0000000000..885131d47c --- /dev/null +++ b/shared-module/displayio/Group.c @@ -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 + } +} diff --git a/shared-module/displayio/Group.h b/shared-module/displayio/Group.h new file mode 100644 index 0000000000..7f3e5646a6 --- /dev/null +++ b/shared-module/displayio/Group.h @@ -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 +#include + +#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 diff --git a/shared-module/displayio/Palette.c b/shared-module/displayio/Palette.c new file mode 100644 index 0000000000..e2ec6e0572 --- /dev/null +++ b/shared-module/displayio/Palette.c @@ -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; +} diff --git a/shared-module/displayio/Palette.h b/shared-module/displayio/Palette.h new file mode 100644 index 0000000000..22c737c9db --- /dev/null +++ b/shared-module/displayio/Palette.h @@ -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 +#include + +#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 diff --git a/shared-module/displayio/Sprite.c b/shared-module/displayio/Sprite.c new file mode 100644 index 0000000000..b584c05690 --- /dev/null +++ b/shared-module/displayio/Sprite.c @@ -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. +} diff --git a/shared-module/displayio/Sprite.h b/shared-module/displayio/Sprite.h new file mode 100644 index 0000000000..213130af83 --- /dev/null +++ b/shared-module/displayio/Sprite.h @@ -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 +#include + +#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 diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c new file mode 100644 index 0000000000..df9c2963ab --- /dev/null +++ b/shared-module/displayio/__init__.c @@ -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); +} diff --git a/shared-module/displayio/__init__.h b/shared-module/displayio/__init__.h new file mode 100644 index 0000000000..556af430d5 --- /dev/null +++ b/shared-module/displayio/__init__.h @@ -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 From 121903b6eeb9712cae86a24c5fe82cb7b144e504 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 31 Aug 2018 14:21:48 -0700 Subject: [PATCH 2/4] Tweaks based on feedback --- .../boards/hallowing_m0_express/board.c | 2 +- .../common-hal/displayio/FourWire.c | 8 +- ports/atmel-samd/mpconfigport.h | 2 - shared-bindings/displayio/Bitmap.c | 17 ++--- shared-bindings/displayio/Group.c | 2 +- shared-bindings/displayio/Palette.c | 73 +++++++++---------- shared-bindings/displayio/__init__.h | 4 - shared-module/displayio/Bitmap.c | 5 +- 8 files changed, 52 insertions(+), 61 deletions(-) diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index 69d7ecd37a..85bcaabc7e 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -84,7 +84,7 @@ void board_init(void) { } else if (*cmd == 0x11) { uint64_t start = ticks_ms; while (ticks_ms - start < 500) {} - } { + } else { uint64_t start = ticks_ms; while (ticks_ms - start < 10) {} } diff --git a/ports/atmel-samd/common-hal/displayio/FourWire.c b/ports/atmel-samd/common-hal/displayio/FourWire.c index 42038a58e0..033970c77d 100644 --- a/ports/atmel-samd/common-hal/displayio/FourWire.c +++ b/ports/atmel-samd/common-hal/displayio/FourWire.c @@ -63,22 +63,17 @@ bool common_hal_displayio_fourwire_begin_transaction(displayio_fourwire_obj_t* s if (!common_hal_busio_spi_try_lock(&self->bus)) { return false; } + // TODO(tannewt): Stop hardcoding SPI frequency, polarity and phase. 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); @@ -106,6 +101,7 @@ static uint16_t swap(uint16_t x) { } void displayio_fourwire_start_region_update(displayio_fourwire_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { + // TODO(tannewt): Handle displays with single byte bounds. common_hal_displayio_fourwire_begin_transaction(self); uint16_t data[2]; common_hal_displayio_fourwire_send(self, true, &self->set_column_command, 1); diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index 58f74d7ec8..14f72ccfb0 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.h @@ -239,8 +239,6 @@ extern const struct _mp_obj_module_t usb_hid_module; #define DISPLAYIO_MODULE #endif - - #ifndef EXTRA_BUILTIN_MODULES #define EXTRA_BUILTIN_MODULES \ AUDIOIO_MODULE \ diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index b01fe0e0cf..d415127d2f 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -45,30 +45,29 @@ //| //| .. warning:: This will likely be changed before 4.0.0. Consider it very experimental. //| -//| .. class:: Bitmap(width, height, value_size) +//| .. class:: Bitmap(width, height, value_count) //| -//| Create a Bitmap object with the given fixed size. +//| Create a Bitmap object with the given fixed size. Each pixel stores a value that is used to +//| index into a corresponding palette. This enables differently colored sprites to share the +//| underlying Bitmap. value_count is used to minimize the memory used to store the Bitmap. //| //| :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. +//| :param int value_count: The number of possible pixel values. //| 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 value_count = mp_obj_get_int(pos_args[2]); uint32_t power_of_two = 1; - while (value_size > power_of_two) { + while (value_count > (1U << 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); + common_hal_displayio_bitmap_construct(self, width, height, power_of_two); return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index a2a8799875..e6f1fbbf5d 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -74,7 +74,7 @@ STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_arg //| .. method:: append(layer) //| -//| Switches do displaying the given group of elements. +//| Append a layer to the group. It will be drawn above other layers. //| 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); diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index bb2af94105..99963f131c 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -41,8 +41,8 @@ //| :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. +//| Map a pixel value to a full color. Colors are transformed to the display's format internally to +//| save memory. //| //| .. warning:: This will be changed before 4.0.0. Consider it very experimental. //| @@ -76,42 +76,41 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val 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; - } - } } + // Slicing not supported. Use a duplicate Palette to swap multiple colors atomically. + if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) { + return MP_OBJ_NULL; + } + // index read is not supported + if (value == MP_OBJ_SENTINEL) { + return MP_OBJ_NULL; + } + displayio_palette_t *self = MP_OBJ_TO_PTR(self_in); + 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) diff --git a/shared-bindings/displayio/__init__.h b/shared-bindings/displayio/__init__.h index 5c3fc2b55c..a6663bf572 100644 --- a/shared-bindings/displayio/__init__.h +++ b/shared-bindings/displayio/__init__.h @@ -31,8 +31,4 @@ // Nothing now. -// typedef enum { -// PIXEL_ -// } displayio_pixel_format; - #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index 7c6a2ee806..453dc1c59e 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -56,7 +56,7 @@ void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t wi } 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) { + if (len != self->stride * sizeof(uint32_t)) { mp_raise_ValueError(translate("row must be packed and word aligned")); } uint32_t* row_value = self->data + (y * self->stride); @@ -77,6 +77,9 @@ void common_hal_displayio_bitmap_load_row(displayio_bitmap_t *self, uint16_t y, } } uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t x, int16_t y) { + if (x >= self->width || x < 0 || y >= self->height || y < 0) { + return 0; + } int32_t row_start = y * self->stride; if (self->bits_per_value < 8) { uint32_t word = self->data[row_start + (x >> self->x_shift)]; From 1683eb913d5bfb4265df56bf286d9971185a3a82 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 6 Sep 2018 14:49:49 -0700 Subject: [PATCH 3/4] Minor tweaks based on feedback --- locale/circuitpython.pot | 40 ++++----- locale/en_US.po | 40 ++++----- locale/es.po | 40 ++++----- locale/fil.po | 82 ++++++++++++++++++- locale/fr.po | 45 +++++----- .../boards/hallowing_m0_express/board.c | 41 +++++++--- .../boards/hallowing_m0_express/pins.c | 2 +- .../common-hal/displayio/FourWire.c | 12 +-- shared-bindings/displayio/Bitmap.h | 2 +- shared-bindings/displayio/Palette.c | 32 ++++---- shared-bindings/displayio/Palette.h | 6 +- shared-bindings/displayio/Sprite.c | 7 +- shared-module/displayio/Bitmap.c | 21 +++-- shared-module/displayio/Palette.c | 28 +++---- shared-module/displayio/Palette.h | 4 +- shared-module/displayio/mipi_constants.h | 37 +++++++++ 16 files changed, 291 insertions(+), 148 deletions(-) create mode 100644 shared-module/displayio/mipi_constants.h diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index c7b7085b71..1d94dccaed 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-30 23:06-0700\n" +"POT-Creation-Date: 2018-09-06 14:49-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -2022,19 +2022,15 @@ 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 +#: shared-bindings/displayio/Bitmap.c:84 msgid "y should be an int" msgstr "" -#: shared-bindings/displayio/Bitmap.c:90 +#: shared-bindings/displayio/Bitmap.c:89 msgid "row buffer must be a bytearray or array of type 'b' or 'B'" msgstr "" -#: shared-bindings/displayio/Bitmap.c:95 +#: shared-bindings/displayio/Bitmap.c:94 msgid "row data must be a buffer" msgstr "" @@ -2047,36 +2043,36 @@ msgstr "" msgid "Group must have size at least 1" msgstr "" -#: shared-bindings/displayio/Palette.c:94 +#: shared-bindings/displayio/Palette.c:96 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)" +#: shared-bindings/displayio/Palette.c:102 +msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)" msgstr "" -#: shared-bindings/displayio/Palette.c:104 +#: shared-bindings/displayio/Palette.c:106 msgid "color must be between 0x000000 and 0xffffff" msgstr "" -#: shared-bindings/displayio/Palette.c:108 +#: shared-bindings/displayio/Palette.c:110 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" +#: shared-bindings/displayio/Palette.c:123 +#: shared-bindings/displayio/Palette.c:137 +msgid "palette_index should be an int" msgstr "" -#: shared-bindings/displayio/Sprite.c:44 +#: shared-bindings/displayio/Sprite.c:45 msgid "position must be 2-tuple" msgstr "" -#: shared-bindings/displayio/Sprite.c:86 +#: shared-bindings/displayio/Sprite.c:87 msgid "unsupported bitmap type" msgstr "" -#: shared-bindings/displayio/Sprite.c:151 +#: shared-bindings/displayio/Sprite.c:152 msgid "palette must be displayio.Palette" msgstr "" @@ -2294,7 +2290,11 @@ msgstr "" msgid "Cannot transfer without MOSI and MISO pins." msgstr "" -#: shared-module/displayio/Bitmap.c:60 +#: shared-module/displayio/Bitmap.c:49 +msgid "Only bit maps of 8 bit color or less are supported" +msgstr "" + +#: shared-module/displayio/Bitmap.c:69 msgid "row must be packed and word aligned" msgstr "" diff --git a/locale/en_US.po b/locale/en_US.po index 78e32cc823..c310ea920d 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-30 16:12-0700\n" +"POT-Creation-Date: 2018-09-06 14:49-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -2022,19 +2022,15 @@ 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 +#: shared-bindings/displayio/Bitmap.c:84 msgid "y should be an int" msgstr "" -#: shared-bindings/displayio/Bitmap.c:90 +#: shared-bindings/displayio/Bitmap.c:89 msgid "row buffer must be a bytearray or array of type 'b' or 'B'" msgstr "" -#: shared-bindings/displayio/Bitmap.c:95 +#: shared-bindings/displayio/Bitmap.c:94 msgid "row data must be a buffer" msgstr "" @@ -2047,36 +2043,36 @@ msgstr "" msgid "Group must have size at least 1" msgstr "" -#: shared-bindings/displayio/Palette.c:94 +#: shared-bindings/displayio/Palette.c:96 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)" +#: shared-bindings/displayio/Palette.c:102 +msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)" msgstr "" -#: shared-bindings/displayio/Palette.c:104 +#: shared-bindings/displayio/Palette.c:106 msgid "color must be between 0x000000 and 0xffffff" msgstr "" -#: shared-bindings/displayio/Palette.c:108 +#: shared-bindings/displayio/Palette.c:110 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" +#: shared-bindings/displayio/Palette.c:123 +#: shared-bindings/displayio/Palette.c:137 +msgid "palette_index should be an int" msgstr "" -#: shared-bindings/displayio/Sprite.c:44 +#: shared-bindings/displayio/Sprite.c:45 msgid "position must be 2-tuple" msgstr "" -#: shared-bindings/displayio/Sprite.c:86 +#: shared-bindings/displayio/Sprite.c:87 msgid "unsupported bitmap type" msgstr "" -#: shared-bindings/displayio/Sprite.c:151 +#: shared-bindings/displayio/Sprite.c:152 msgid "palette must be displayio.Palette" msgstr "" @@ -2294,7 +2290,11 @@ msgstr "" msgid "Cannot transfer without MOSI and MISO pins." msgstr "" -#: shared-module/displayio/Bitmap.c:60 +#: shared-module/displayio/Bitmap.c:49 +msgid "Only bit maps of 8 bit color or less are supported" +msgstr "" + +#: shared-module/displayio/Bitmap.c:69 msgid "row must be packed and word aligned" msgstr "" diff --git a/locale/es.po b/locale/es.po index c9de75c382..f7e0ed4e4c 100644 --- a/locale/es.po +++ b/locale/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-30 16:12-0700\n" +"POT-Creation-Date: 2018-09-06 14:49-0700\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -2068,19 +2068,15 @@ 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 +#: shared-bindings/displayio/Bitmap.c:84 msgid "y should be an int" msgstr "" -#: shared-bindings/displayio/Bitmap.c:90 +#: shared-bindings/displayio/Bitmap.c:89 msgid "row buffer must be a bytearray or array of type 'b' or 'B'" msgstr "" -#: shared-bindings/displayio/Bitmap.c:95 +#: shared-bindings/displayio/Bitmap.c:94 msgid "row data must be a buffer" msgstr "" @@ -2093,36 +2089,36 @@ msgstr "" msgid "Group must have size at least 1" msgstr "" -#: shared-bindings/displayio/Palette.c:94 +#: shared-bindings/displayio/Palette.c:96 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)" +#: shared-bindings/displayio/Palette.c:102 +msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)" msgstr "" -#: shared-bindings/displayio/Palette.c:104 +#: shared-bindings/displayio/Palette.c:106 msgid "color must be between 0x000000 and 0xffffff" msgstr "" -#: shared-bindings/displayio/Palette.c:108 +#: shared-bindings/displayio/Palette.c:110 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" +#: shared-bindings/displayio/Palette.c:123 +#: shared-bindings/displayio/Palette.c:137 +msgid "palette_index should be an int" msgstr "" -#: shared-bindings/displayio/Sprite.c:44 +#: shared-bindings/displayio/Sprite.c:45 msgid "position must be 2-tuple" msgstr "" -#: shared-bindings/displayio/Sprite.c:86 +#: shared-bindings/displayio/Sprite.c:87 msgid "unsupported bitmap type" msgstr "" -#: shared-bindings/displayio/Sprite.c:151 +#: shared-bindings/displayio/Sprite.c:152 msgid "palette must be displayio.Palette" msgstr "" @@ -2341,7 +2337,11 @@ msgstr "" msgid "Cannot transfer without MOSI and MISO pins." msgstr "" -#: shared-module/displayio/Bitmap.c:60 +#: shared-module/displayio/Bitmap.c:49 +msgid "Only bit maps of 8 bit color or less are supported" +msgstr "" + +#: shared-module/displayio/Bitmap.c:69 msgid "row must be packed and word aligned" msgstr "" diff --git a/locale/fil.po b/locale/fil.po index 7e8b9c7a3a..8f681bcb49 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-30 18:29-0700\n" +"POT-Creation-Date: 2018-09-06 14:49-0700\n" "PO-Revision-Date: 2018-08-30 23:04-0700\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -2060,6 +2060,74 @@ msgstr "Pull hindi ginagamit kapag ang direksyon ay output." msgid "Unsupported pull value." msgstr "Hindi suportado ang pull value." +#: shared-bindings/displayio/Bitmap.c:84 +#, fuzzy +msgid "y should be an int" +msgstr "Haba ay dapat int" + +#: shared-bindings/displayio/Bitmap.c:89 +#, fuzzy +msgid "row buffer must be a bytearray or array of type 'b' or 'B'" +msgstr "" +"ang sample_source buffer ay dapat na isang bytearray o array ng uri na 'h', " +"'H', 'b' o'B'" + +#: shared-bindings/displayio/Bitmap.c:94 +#, fuzzy +msgid "row data must be a buffer" +msgstr "constant ay dapat na integer" + +#: 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 "Buffer dapat ay hindi baba sa 1 na haba" + +#: shared-bindings/displayio/Palette.c:96 +#, fuzzy +msgid "color buffer must be a bytearray or array of type 'b' or 'B'" +msgstr "" +"ang sample_source buffer ay dapat na isang bytearray o array ng uri na 'h', " +"'H', 'b' o'B'" + +#: shared-bindings/displayio/Palette.c:102 +msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)" +msgstr "" + +#: shared-bindings/displayio/Palette.c:106 +#, fuzzy +msgid "color must be between 0x000000 and 0xffffff" +msgstr "Sa gitna ng 0 o 255 dapat ang bytes." + +#: shared-bindings/displayio/Palette.c:110 +#, fuzzy +msgid "color buffer must be a buffer or int" +msgstr "buffer ay dapat bytes-like object" + +#: shared-bindings/displayio/Palette.c:123 +#: shared-bindings/displayio/Palette.c:137 +msgid "palette_index should be an int" +msgstr "" + +#: shared-bindings/displayio/Sprite.c:45 +#, fuzzy +msgid "position must be 2-tuple" +msgstr "stop dapat 1 o 2" + +#: shared-bindings/displayio/Sprite.c:87 +#, fuzzy +msgid "unsupported bitmap type" +msgstr "Hindi supportadong baudrate" + +#: shared-bindings/displayio/Sprite.c:152 +#, fuzzy +msgid "palette must be displayio.Palette" +msgstr "ang palette ay dapat 32 bytes ang haba" + #: shared-bindings/gamepad/GamePad.c:100 msgid "too many arguments" msgstr "masyadong maraming argumento" @@ -2277,6 +2345,18 @@ msgstr "Hindi maaring mabasa kapag walang MISO pin." msgid "Cannot transfer without MOSI and MISO pins." msgstr "Hindi maaaring ilipat kapag walang MOSI at MISO pin." +#: shared-module/displayio/Bitmap.c:49 +msgid "Only bit maps of 8 bit color or less are supported" +msgstr "" + +#: shared-module/displayio/Bitmap.c:69 +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 "Ang 'S' at 'O' ay hindi suportadong uri ng format" diff --git a/locale/fr.po b/locale/fr.po index 3bbd779693..740830e108 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-30 16:12-0700\n" +"POT-Creation-Date: 2018-09-06 14:49-0700\n" "PO-Revision-Date: 2018-08-14 11:01+0200\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -2051,24 +2051,19 @@ 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 +#: shared-bindings/displayio/Bitmap.c:84 #, fuzzy msgid "y should be an int" msgstr "La longueur doit être entière" -#: shared-bindings/displayio/Bitmap.c:90 +#: shared-bindings/displayio/Bitmap.c:89 #, 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 +#: shared-bindings/displayio/Bitmap.c:94 #, fuzzy msgid "row data must be a buffer" msgstr "les constantes doivent être des entiers" @@ -2083,44 +2078,44 @@ msgstr "" msgid "Group must have size at least 1" msgstr "Le tampon doit être de longueur au moins 1" -#: shared-bindings/displayio/Palette.c:94 +#: shared-bindings/displayio/Palette.c:96 #, 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)" +#: shared-bindings/displayio/Palette.c:102 +msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)" msgstr "" -#: shared-bindings/displayio/Palette.c:104 +#: shared-bindings/displayio/Palette.c:106 #, 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 +#: shared-bindings/displayio/Palette.c:110 #, 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 +#: shared-bindings/displayio/Palette.c:123 +#: shared-bindings/displayio/Palette.c:137 #, fuzzy -msgid "value should be an int" +msgid "palette_index should be an int" msgstr "Les valeurs du tableau doivent être des octets simples 'bytes'" -#: shared-bindings/displayio/Sprite.c:44 +#: shared-bindings/displayio/Sprite.c:45 #, fuzzy msgid "position must be 2-tuple" msgstr "stop doit être 1 ou 2" -#: shared-bindings/displayio/Sprite.c:86 +#: shared-bindings/displayio/Sprite.c:87 #, fuzzy msgid "unsupported bitmap type" msgstr "Débit non supporté" -#: shared-bindings/displayio/Sprite.c:151 +#: shared-bindings/displayio/Sprite.c:152 #, fuzzy msgid "palette must be displayio.Palette" msgstr "la palette doit être longue de 32 octets" @@ -2346,7 +2341,11 @@ 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 +#: shared-module/displayio/Bitmap.c:49 +msgid "Only bit maps of 8 bit color or less are supported" +msgstr "" + +#: shared-module/displayio/Bitmap.c:69 msgid "row must be packed and word aligned" msgstr "" @@ -2361,3 +2360,7 @@ msgstr "'S' et 'O' ne sont pas des types de format supportés" #: shared-module/struct/__init__.c:83 msgid "too many arguments provided with the given format" msgstr "trop d'arguments fournis avec ce format" + +#, fuzzy +#~ msgid "value_size must be power of two" +#~ msgstr "'len' doit être un multiple de 4" diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index 85bcaabc7e..b47c5fbb22 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -27,14 +27,17 @@ #include "boards/board.h" #include "shared-bindings/displayio/FourWire.h" +#include "shared-module/displayio/mipi_constants.h" #include "tick.h" displayio_fourwire_obj_t board_display_obj; +#define DELAY 0x80 + uint8_t display_init_sequence[] = { - 0x01, 0, // SWRESET - 0x11, 0, // SLPOUT + 0x01, 0 | DELAY, 150, // SWRESET + 0x11, 0 | DELAY, 255, // SLPOUT 0xb1, 3, 0x01, 0x2C, 0x2D, // _FRMCTR1 0xb2, 3, 0x01, 0x2C, 0x2D, // 0xb3, 6, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D, @@ -60,36 +63,50 @@ uint8_t display_init_sequence[] = { 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 + 0x13, 0 | DELAY, 10, // _NORON + 0x29, 0 | DELAY, 100, // _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); + &pin_PB23, // Clock + &pin_PB22, // Data + &pin_PA28, // Command or data + &pin_PA01, // Chip select + &pin_PA27, // Reset + 128, // Width + 128, // Height + 2, // column start + 0, // row start + 16, // Color depth + MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command + MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command + MIPI_COMMAND_WRITE_MEMORY_START); // Write memory command 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); + bool delay = (data_size & DELAY) != 0; + data_size &= ~DELAY; 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) { + if (delay) { + data_size++; + uint16_t delay_length_ms = *(cmd + 1 + data_size); + if (delay_length_ms == 255) { + delay_length_ms = 500; + } uint64_t start = ticks_ms; - while (ticks_ms - start < 120) {} - } else if (*cmd == 0x11) { - uint64_t start = ticks_ms; - while (ticks_ms - start < 500) {} + while (ticks_ms - start < delay_length_ms) {} } else { uint64_t start = ticks_ms; while (ticks_ms - start < 10) {} } i += 2 + data_size; - } common_hal_displayio_fourwire_end_transaction(&board_display_obj); } diff --git a/ports/atmel-samd/boards/hallowing_m0_express/pins.c b/ports/atmel-samd/boards/hallowing_m0_express/pins.c index 28c3d6a5ca..7d4afc7a41 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/pins.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/pins.c @@ -58,6 +58,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { 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_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&board_display_obj)} }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/common-hal/displayio/FourWire.c b/ports/atmel-samd/common-hal/displayio/FourWire.c index 033970c77d..6c3b75a85b 100644 --- a/ports/atmel-samd/common-hal/displayio/FourWire.c +++ b/ports/atmel-samd/common-hal/displayio/FourWire.c @@ -96,21 +96,17 @@ int32_t common_hal_displayio_fourwire_wait_for_frame(displayio_fourwire_obj_t* s 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) { // TODO(tannewt): Handle displays with single byte bounds. 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); + data[0] = __builtin_bswap16(x0 + self->colstart); + data[1] = __builtin_bswap16(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); + data[0] = __builtin_bswap16(y0 + 1 + self->rowstart); + data[1] = __builtin_bswap16(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); } diff --git a/shared-bindings/displayio/Bitmap.h b/shared-bindings/displayio/Bitmap.h index 2ae4684818..b736f9459c 100644 --- a/shared-bindings/displayio/Bitmap.h +++ b/shared-bindings/displayio/Bitmap.h @@ -32,7 +32,7 @@ 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); + uint32_t height, uint32_t bits_per_value); void common_hal_displayio_bitmap_load_row(displayio_bitmap_t *self, uint16_t y, uint8_t* data, uint16_t len); diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 99963f131c..21744f947b 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -38,10 +38,10 @@ //| .. currentmodule:: displayio //| -//| :class:`Palette` -- Stores a mapping from bitmap pixel values to display colors +//| :class:`Palette` -- Stores a mapping from bitmap pixel palette_indexes to display colors //| =============================================================================== //| -//| Map a pixel value to a full color. Colors are transformed to the display's format internally to +//| Map a pixel palette_index to a full color. Colors are transformed to the display's format internally to //| save memory. //| //| .. warning:: This will be changed before 4.0.0. Consider it very experimental. @@ -86,7 +86,7 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val return MP_OBJ_NULL; } displayio_palette_t *self = MP_OBJ_TO_PTR(self_in); - size_t index = mp_get_index(&displayio_palette_type, self->max_value, index_in, false); + size_t index = mp_get_index(&displayio_palette_type, self->color_count, index_in, false); uint32_t color; mp_int_t int_value; @@ -99,7 +99,7 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val 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)")); + mp_raise_ValueError(translate("color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)")); } } else if (mp_obj_get_int_maybe(value, &int_value)) { if (int_value < 0 || int_value > 0xffffff) { @@ -113,30 +113,30 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val return mp_const_none; } -//| .. method:: make_transparent(value) +//| .. method:: make_transparent(palette_index) //| -STATIC mp_obj_t displayio_palette_obj_make_transparent(mp_obj_t self_in, mp_obj_t value_obj) { +STATIC mp_obj_t displayio_palette_obj_make_transparent(mp_obj_t self_in, mp_obj_t palette_index_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")); + mp_int_t palette_index; + if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) { + mp_raise_ValueError(translate("palette_index should be an int")); } - common_hal_displayio_palette_make_transparent(self, value); + common_hal_displayio_palette_make_transparent(self, palette_index); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(displayio_palette_make_transparent_obj, displayio_palette_obj_make_transparent); -//| .. method:: make_opaque(value) +//| .. method:: make_opaque(palette_index) //| -STATIC mp_obj_t displayio_palette_obj_make_opaque(mp_obj_t self_in, mp_obj_t value_obj) { +STATIC mp_obj_t displayio_palette_obj_make_opaque(mp_obj_t self_in, mp_obj_t palette_index_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")); + mp_int_t palette_index; + if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) { + mp_raise_ValueError(translate("palette_index should be an int")); } - common_hal_displayio_palette_make_opaque(self, value); + common_hal_displayio_palette_make_opaque(self, palette_index); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(displayio_palette_make_opaque_obj, displayio_palette_obj_make_opaque); diff --git a/shared-bindings/displayio/Palette.h b/shared-bindings/displayio/Palette.h index fde6ab7d38..767fc7b636 100644 --- a/shared-bindings/displayio/Palette.h +++ b/shared-bindings/displayio/Palette.h @@ -32,9 +32,9 @@ 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_set_color(displayio_palette_t* self, uint32_t palette_index, 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); +void common_hal_displayio_palette_make_opaque(displayio_palette_t* self, uint32_t palette_index); +void common_hal_displayio_palette_make_transparent(displayio_palette_t* self, uint32_t palette_index); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_PALETTE_H diff --git a/shared-bindings/displayio/Sprite.c b/shared-bindings/displayio/Sprite.c index 25ea79f5c2..223a8a394c 100644 --- a/shared-bindings/displayio/Sprite.c +++ b/shared-bindings/displayio/Sprite.c @@ -35,7 +35,8 @@ #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) { +void unpack_position(mp_obj_t position_obj, int16_t* x, int16_t* y) { + // TODO(tannewt): Support any value sequence such as bytearray or bytes. 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]); @@ -88,7 +89,7 @@ STATIC mp_obj_t displayio_sprite_make_new(const mp_obj_type_t *type, size_t n_ar int16_t x = 0; int16_t y = 0; mp_obj_t position_obj = args[ARG_position].u_obj; - parse_position(position_obj, &x, &y); + unpack_position(position_obj, &x, &y); displayio_sprite_t *self = m_new_obj(displayio_sprite_t); self->base.type = &displayio_sprite_type; @@ -120,7 +121,7 @@ STATIC mp_obj_t displayio_sprite_obj_set_position(mp_obj_t self_in, mp_obj_t val int16_t x = 0; int16_t y = 0; - parse_position(value, &x, &y); + unpack_position(value, &x, &y); common_hal_displayio_sprite_set_position(self, x, y); diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index 453dc1c59e..addc341a7e 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -31,8 +31,8 @@ #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; + uint32_t height, uint32_t bits_per_value) { + uint32_t row_width = width * bits_per_value; // word align if (row_width % 32 != 0) { self->stride = (row_width / 32 + 1); @@ -43,16 +43,25 @@ void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t wi self->height = height; self->data = m_malloc(self->stride * height * sizeof(uint32_t), false); - self->bits_per_value = value_size; + self->bits_per_value = bits_per_value; - self->x_shift = 0; + if (bits_per_value > 8) { + mp_raise_NotImplementedError(translate("Only bit maps of 8 bit color or less are supported")); + } + + // Division and modulus can be slow because it has to handle any integer. We know bits_per_value + // is a power of two. We divide and mod by bits_per_value to compute the offset into the byte + // array. So, we can the offset computation to simplify to a shift for division and mask for mod. + + self->x_shift = 0; // Used to divide the index by the number of pixels per word. Its used in a + // shift which effectively divides by 2 ** x_shift. uint32_t power_of_two = 1; - while (power_of_two < 32 / value_size ) { + while (power_of_two < 32 / bits_per_value ) { 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; + self->bitmask = (1 << bits_per_value) - 1; } void common_hal_displayio_bitmap_load_row(displayio_bitmap_t *self, uint16_t y, uint8_t* data, uint16_t len) { diff --git a/shared-module/displayio/Palette.c b/shared-module/displayio/Palette.c index e2ec6e0572..5f410d7869 100644 --- a/shared-module/displayio/Palette.c +++ b/shared-module/displayio/Palette.c @@ -27,7 +27,7 @@ #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->color_count = 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) { @@ -36,35 +36,35 @@ void common_hal_displayio_palette_construct(displayio_palette_t* self, uint16_t 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_opaque(displayio_palette_t* self, uint32_t palette_index) { + self->opaque[palette_index / 32] &= ~(0x1 << (palette_index % 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_make_transparent(displayio_palette_t* self, uint32_t palette_index) { + self->opaque[palette_index / 32] |= (0x1 << (palette_index % 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); +void common_hal_displayio_palette_set_color(displayio_palette_t* self, uint32_t palette_index, uint32_t color) { + uint32_t shift = (palette_index % 2) * 16; + uint32_t masked = self->colors[palette_index / 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; + packed = __builtin_bswap16(packed); + self->colors[palette_index / 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) { +bool displayio_palette_get_color(displayio_palette_t *self, uint32_t palette_index, uint16_t* color) { + if (palette_index > self->color_count) { return false; } - if ((self->opaque[value / 32] & (0x1 << (value % 32))) != 0) { + if ((self->opaque[palette_index / 32] & (0x1 << (palette_index % 32))) != 0) { return false; } - *color = (self->colors[value / 2] >> (16 * (value % 2))) & 0xffff; + *color = (self->colors[palette_index / 2] >> (16 * (palette_index % 2))) & 0xffff; return true; } diff --git a/shared-module/displayio/Palette.h b/shared-module/displayio/Palette.h index 22c737c9db..5a5f1d2874 100644 --- a/shared-module/displayio/Palette.h +++ b/shared-module/displayio/Palette.h @@ -36,11 +36,11 @@ typedef struct { mp_obj_base_t base; uint32_t* opaque; uint32_t* colors; - uint8_t max_value; + uint8_t color_count; bool needs_refresh; } displayio_palette_t; -bool displayio_palette_get_color(displayio_palette_t *palette, uint32_t value, uint16_t* color); +bool displayio_palette_get_color(displayio_palette_t *palette, uint32_t palette_index, uint16_t* color); bool displayio_palette_needs_refresh(displayio_palette_t *self); void displayio_palette_finish_refresh(displayio_palette_t *self); diff --git a/shared-module/displayio/mipi_constants.h b/shared-module/displayio/mipi_constants.h new file mode 100644 index 0000000000..3cb7e4292f --- /dev/null +++ b/shared-module/displayio/mipi_constants.h @@ -0,0 +1,37 @@ +/* + * 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_MIPI_CONSTANTS_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_MIPI_CONSTANTS_H + +// More info here: https://www.tonylabs.com/wp-content/uploads/MIPI_DCS_specification_v1.02.00.pdf +enum mipi_command { + MIPI_COMMAND_SET_COLUMN_ADDRESS = 0x2a, + MIPI_COMMAND_SET_PAGE_ADDRESS = 0x2b, + MIPI_COMMAND_WRITE_MEMORY_START = 0x2c, +}; + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_MIPI_CONSTANTS_H From 86288f14f1312c6b65ac7f268a3ecf093b0aaed9 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 6 Sep 2018 14:56:26 -0700 Subject: [PATCH 4/4] Merge translations and update title underline --- locale/circuitpython.pot | 28 +++--- locale/de_DE.po | 132 +++++++++++++++++++++------- locale/en_US.po | 28 +++--- locale/es.po | 28 +++--- locale/fil.po | 28 +++--- locale/fr.po | 28 +++--- shared-bindings/displayio/Palette.c | 2 +- 7 files changed, 173 insertions(+), 101 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 1d94dccaed..c2ebcf176d 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-09-06 14:49-0700\n" +"POT-Creation-Date: 2018-09-06 14:55-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -231,15 +231,15 @@ msgstr "" msgid "calibration is out of range" msgstr "" -#: ports/atmel-samd/board_busses.c:39 +#: ports/atmel-samd/board_busses.c:39 ports/nrf/board_busses.c:39 msgid "No default I2C bus" msgstr "" -#: ports/atmel-samd/board_busses.c:64 +#: ports/atmel-samd/board_busses.c:64 ports/nrf/board_busses.c:64 msgid "No default SPI bus" msgstr "" -#: ports/atmel-samd/board_busses.c:91 +#: ports/atmel-samd/board_busses.c:91 ports/nrf/board_busses.c:91 msgid "No default UART bus" msgstr "" @@ -388,12 +388,12 @@ msgstr "" msgid "No RX pin" msgstr "" -#: ports/atmel-samd/common-hal/busio/UART.c:284 +#: ports/atmel-samd/common-hal/busio/UART.c:288 msgid "No TX pin" msgstr "" -#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c:168 -#: ports/nrf/common-hal/digitalio/DigitalInOut.c:158 +#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c:170 +#: ports/nrf/common-hal/digitalio/DigitalInOut.c:153 msgid "Cannot get pull while in output mode" msgstr "" @@ -426,12 +426,12 @@ msgstr "" msgid "Failed to allocate RX buffer of %d bytes" msgstr "" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:203 +#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:205 #: ports/esp8266/common-hal/pulseio/PulseIn.c:151 msgid "pop from an empty PulseIn" msgstr "" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:235 +#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:237 #: ports/esp8266/common-hal/pulseio/PulseIn.c:182 py/obj.c:420 msgid "index out of range" msgstr "" @@ -685,11 +685,11 @@ msgstr "" msgid "AnalogOut functionality not supported" msgstr "" -#: ports/nrf/common-hal/busio/UART.c:45 ports/nrf/common-hal/busio/UART.c:49 -#: ports/nrf/common-hal/busio/UART.c:53 ports/nrf/common-hal/busio/UART.c:62 -#: ports/nrf/common-hal/busio/UART.c:68 ports/nrf/common-hal/busio/UART.c:73 -#: ports/nrf/common-hal/busio/UART.c:78 ports/nrf/common-hal/busio/UART.c:83 -#: ports/nrf/common-hal/busio/UART.c:88 +#: ports/nrf/common-hal/busio/UART.c:43 ports/nrf/common-hal/busio/UART.c:47 +#: ports/nrf/common-hal/busio/UART.c:51 ports/nrf/common-hal/busio/UART.c:60 +#: ports/nrf/common-hal/busio/UART.c:66 ports/nrf/common-hal/busio/UART.c:71 +#: ports/nrf/common-hal/busio/UART.c:76 ports/nrf/common-hal/busio/UART.c:81 +#: ports/nrf/common-hal/busio/UART.c:86 msgid "busio.UART not yet implemented" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index c3883a7db7..5e69c1479c 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-20 09:37-0700\n" +"POT-Creation-Date: 2018-09-06 14:55-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Sebastian Plamauer\n" "Language-Team: \n" @@ -159,7 +159,8 @@ msgstr " Ausgabe:\n" msgid "" "Auto-reload is on. Simply save files over USB to run them or enter REPL to " "disable.\n" -msgstr "Automatisches Neuladen ist aktiv. Speichere Dateien über USB um sie " +msgstr "" +"Automatisches Neuladen ist aktiv. Speichere Dateien über USB um sie " "auszuführen oder verbinde dich mit der REPL um zu deaktivieren.\n" #: main.c:159 @@ -197,26 +198,30 @@ msgstr "CircuitPython ist abgestürzt. Ups!\n" #: main.c:252 msgid "Please file an issue here with the contents of your CIRCUITPY drive:\n" -msgstr "Bitte erstelle ein issue hier mit dem Inhalt deines CIRCUITPY-speichers:\n" +msgstr "" +"Bitte erstelle ein issue hier mit dem Inhalt deines CIRCUITPY-speichers:\n" #: main.c:255 msgid "" "The microcontroller's power dipped. Please make sure your power supply " "provides\n" -msgstr "Die Stromversorgung des Mikrocontrollers ist eingebrochen. Stelle sicher," +msgstr "" +"Die Stromversorgung des Mikrocontrollers ist eingebrochen. Stelle sicher," "dass deine Stromversorgung\n" #: main.c:256 msgid "" "enough power for the whole circuit and press reset (after ejecting " "CIRCUITPY).\n" -msgstr "genug Strom für den ganzen Schaltkreis liefert und drücke reset (nach dem" -"sicheren Auswerfen von CIRCUITPY.)\n" +msgstr "" +"genug Strom für den ganzen Schaltkreis liefert und drücke reset (nach " +"demsicheren Auswerfen von CIRCUITPY.)\n" #: main.c:260 msgid "Press any key to enter the REPL. Use CTRL-D to reload." -msgstr "Drücke eine Taste um dich mit der REPL zu verbinden. Drücke Strg-D zum neu" -" laden" +msgstr "" +"Drücke eine Taste um dich mit der REPL zu verbinden. Drücke Strg-D zum neu " +"laden" #: main.c:415 msgid "soft reboot\n" @@ -235,15 +240,15 @@ msgstr "Kalibrierung ist Schreibgeschützt" msgid "calibration is out of range" msgstr "Kalibrierung ist außerhalb der Reichweite" -#: ports/atmel-samd/board_busses.c:39 +#: ports/atmel-samd/board_busses.c:39 ports/nrf/board_busses.c:39 msgid "No default I2C bus" msgstr "Kein Standard I2C Bus" -#: ports/atmel-samd/board_busses.c:64 +#: ports/atmel-samd/board_busses.c:64 ports/nrf/board_busses.c:64 msgid "No default SPI bus" msgstr "Kein Standard SPI Bus" -#: ports/atmel-samd/board_busses.c:91 +#: ports/atmel-samd/board_busses.c:91 ports/nrf/board_busses.c:91 msgid "No default UART bus" msgstr "Kein Standard UART Bus" @@ -392,12 +397,12 @@ msgstr "Konnte UART nicht initialisieren" msgid "No RX pin" msgstr "Kein RX Pin" -#: ports/atmel-samd/common-hal/busio/UART.c:284 +#: ports/atmel-samd/common-hal/busio/UART.c:288 msgid "No TX pin" msgstr "Kein TX Pin" -#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c:168 -#: ports/nrf/common-hal/digitalio/DigitalInOut.c:158 +#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c:170 +#: ports/nrf/common-hal/digitalio/DigitalInOut.c:153 msgid "Cannot get pull while in output mode" msgstr "Pull up im Ausgabemodus nicht möglich" @@ -430,12 +435,12 @@ msgstr "EXTINT Kanal wird benutzt" msgid "Failed to allocate RX buffer of %d bytes" msgstr "Konnte keine RX Buffer mit %d allozieren" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:203 +#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:205 #: ports/esp8266/common-hal/pulseio/PulseIn.c:151 msgid "pop from an empty PulseIn" msgstr "pop von einem leeren PulseIn" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:235 +#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:237 #: ports/esp8266/common-hal/pulseio/PulseIn.c:182 py/obj.c:420 msgid "index out of range" msgstr "index außerhalb der Reichweite" @@ -614,11 +619,11 @@ msgid "frequency can only be either 80Mhz or 160MHz" msgstr "" #: ports/esp8266/modnetwork.c:61 -msgid "STA required" +msgid "AP required" msgstr "" #: ports/esp8266/modnetwork.c:61 -msgid "AP required" +msgid "STA required" msgstr "" #: ports/esp8266/modnetwork.c:87 @@ -689,11 +694,11 @@ msgstr "" msgid "AnalogOut functionality not supported" msgstr "" -#: ports/nrf/common-hal/busio/UART.c:45 ports/nrf/common-hal/busio/UART.c:49 -#: ports/nrf/common-hal/busio/UART.c:53 ports/nrf/common-hal/busio/UART.c:62 -#: ports/nrf/common-hal/busio/UART.c:68 ports/nrf/common-hal/busio/UART.c:73 -#: ports/nrf/common-hal/busio/UART.c:78 ports/nrf/common-hal/busio/UART.c:83 -#: ports/nrf/common-hal/busio/UART.c:88 +#: ports/nrf/common-hal/busio/UART.c:43 ports/nrf/common-hal/busio/UART.c:47 +#: ports/nrf/common-hal/busio/UART.c:51 ports/nrf/common-hal/busio/UART.c:60 +#: ports/nrf/common-hal/busio/UART.c:66 ports/nrf/common-hal/busio/UART.c:71 +#: ports/nrf/common-hal/busio/UART.c:76 ports/nrf/common-hal/busio/UART.c:81 +#: ports/nrf/common-hal/busio/UART.c:86 msgid "busio.UART not yet implemented" msgstr "" @@ -2026,6 +2031,61 @@ msgstr "" msgid "Unsupported pull value." msgstr "" +#: shared-bindings/displayio/Bitmap.c:84 +msgid "y should be an int" +msgstr "" + +#: shared-bindings/displayio/Bitmap.c:89 +msgid "row buffer must be a bytearray or array of type 'b' or 'B'" +msgstr "" + +#: shared-bindings/displayio/Bitmap.c:94 +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:96 +msgid "color buffer must be a bytearray or array of type 'b' or 'B'" +msgstr "" + +#: shared-bindings/displayio/Palette.c:102 +msgid "color buffer must be 3 bytes (RGB) or 4 bytes (RGB + pad byte)" +msgstr "" + +#: shared-bindings/displayio/Palette.c:106 +msgid "color must be between 0x000000 and 0xffffff" +msgstr "" + +#: shared-bindings/displayio/Palette.c:110 +msgid "color buffer must be a buffer or int" +msgstr "" + +#: shared-bindings/displayio/Palette.c:123 +#: shared-bindings/displayio/Palette.c:137 +msgid "palette_index should be an int" +msgstr "" + +#: shared-bindings/displayio/Sprite.c:45 +msgid "position must be 2-tuple" +msgstr "" + +#: shared-bindings/displayio/Sprite.c:87 +#, fuzzy +msgid "unsupported bitmap type" +msgstr "Baudrate wird nicht unterstütz" + +#: shared-bindings/displayio/Sprite.c:152 +msgid "palette must be displayio.Palette" +msgstr "" + #: shared-bindings/gamepad/GamePad.c:100 msgid "too many arguments" msgstr "" @@ -2131,7 +2191,7 @@ msgid "empty sequence" msgstr "" #: shared-bindings/rtc/RTC.c:40 shared-bindings/rtc/RTC.c:44 -#: shared-bindings/time/__init__.c:192 +#: shared-bindings/time/__init__.c:190 msgid "RTC is not supported on this board" msgstr "" @@ -2151,27 +2211,27 @@ msgstr "" msgid "Stack size must be at least 256" msgstr "" -#: shared-bindings/time/__init__.c:80 +#: shared-bindings/time/__init__.c:78 msgid "sleep length must be non-negative" msgstr "" -#: shared-bindings/time/__init__.c:90 +#: shared-bindings/time/__init__.c:88 msgid "time.struct_time() takes exactly 1 argument" msgstr "" -#: shared-bindings/time/__init__.c:93 +#: shared-bindings/time/__init__.c:91 msgid "time.struct_time() takes a 9-sequence" msgstr "" -#: shared-bindings/time/__init__.c:171 shared-bindings/time/__init__.c:252 +#: shared-bindings/time/__init__.c:169 shared-bindings/time/__init__.c:250 msgid "Tuple or struct_time argument required" msgstr "" -#: shared-bindings/time/__init__.c:176 shared-bindings/time/__init__.c:257 +#: shared-bindings/time/__init__.c:174 shared-bindings/time/__init__.c:255 msgid "function takes exactly 9 arguments" msgstr "" -#: shared-bindings/time/__init__.c:228 shared-bindings/time/__init__.c:261 +#: shared-bindings/time/__init__.c:226 shared-bindings/time/__init__.c:259 msgid "timestamp out of range for platform time_t" msgstr "" @@ -2240,6 +2300,18 @@ msgstr "" msgid "Cannot transfer without MOSI and MISO pins." msgstr "" +#: shared-module/displayio/Bitmap.c:49 +msgid "Only bit maps of 8 bit color or less are supported" +msgstr "" + +#: shared-module/displayio/Bitmap.c:69 +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 "" diff --git a/locale/en_US.po b/locale/en_US.po index c310ea920d..a38e88276e 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-09-06 14:49-0700\n" +"POT-Creation-Date: 2018-09-06 14:55-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -231,15 +231,15 @@ msgstr "" msgid "calibration is out of range" msgstr "" -#: ports/atmel-samd/board_busses.c:39 +#: ports/atmel-samd/board_busses.c:39 ports/nrf/board_busses.c:39 msgid "No default I2C bus" msgstr "" -#: ports/atmel-samd/board_busses.c:64 +#: ports/atmel-samd/board_busses.c:64 ports/nrf/board_busses.c:64 msgid "No default SPI bus" msgstr "" -#: ports/atmel-samd/board_busses.c:91 +#: ports/atmel-samd/board_busses.c:91 ports/nrf/board_busses.c:91 msgid "No default UART bus" msgstr "" @@ -388,12 +388,12 @@ msgstr "" msgid "No RX pin" msgstr "" -#: ports/atmel-samd/common-hal/busio/UART.c:284 +#: ports/atmel-samd/common-hal/busio/UART.c:288 msgid "No TX pin" msgstr "" -#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c:168 -#: ports/nrf/common-hal/digitalio/DigitalInOut.c:158 +#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c:170 +#: ports/nrf/common-hal/digitalio/DigitalInOut.c:153 msgid "Cannot get pull while in output mode" msgstr "" @@ -426,12 +426,12 @@ msgstr "" msgid "Failed to allocate RX buffer of %d bytes" msgstr "" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:203 +#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:205 #: ports/esp8266/common-hal/pulseio/PulseIn.c:151 msgid "pop from an empty PulseIn" msgstr "" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:235 +#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:237 #: ports/esp8266/common-hal/pulseio/PulseIn.c:182 py/obj.c:420 msgid "index out of range" msgstr "" @@ -685,11 +685,11 @@ msgstr "" msgid "AnalogOut functionality not supported" msgstr "" -#: ports/nrf/common-hal/busio/UART.c:45 ports/nrf/common-hal/busio/UART.c:49 -#: ports/nrf/common-hal/busio/UART.c:53 ports/nrf/common-hal/busio/UART.c:62 -#: ports/nrf/common-hal/busio/UART.c:68 ports/nrf/common-hal/busio/UART.c:73 -#: ports/nrf/common-hal/busio/UART.c:78 ports/nrf/common-hal/busio/UART.c:83 -#: ports/nrf/common-hal/busio/UART.c:88 +#: ports/nrf/common-hal/busio/UART.c:43 ports/nrf/common-hal/busio/UART.c:47 +#: ports/nrf/common-hal/busio/UART.c:51 ports/nrf/common-hal/busio/UART.c:60 +#: ports/nrf/common-hal/busio/UART.c:66 ports/nrf/common-hal/busio/UART.c:71 +#: ports/nrf/common-hal/busio/UART.c:76 ports/nrf/common-hal/busio/UART.c:81 +#: ports/nrf/common-hal/busio/UART.c:86 msgid "busio.UART not yet implemented" msgstr "" diff --git a/locale/es.po b/locale/es.po index f7e0ed4e4c..bd4feef0a2 100644 --- a/locale/es.po +++ b/locale/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-09-06 14:49-0700\n" +"POT-Creation-Date: 2018-09-06 14:55-0700\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -246,15 +246,15 @@ msgstr "" msgid "calibration is out of range" msgstr "" -#: ports/atmel-samd/board_busses.c:39 +#: ports/atmel-samd/board_busses.c:39 ports/nrf/board_busses.c:39 msgid "No default I2C bus" msgstr "" -#: ports/atmel-samd/board_busses.c:64 +#: ports/atmel-samd/board_busses.c:64 ports/nrf/board_busses.c:64 msgid "No default SPI bus" msgstr "" -#: ports/atmel-samd/board_busses.c:91 +#: ports/atmel-samd/board_busses.c:91 ports/nrf/board_busses.c:91 msgid "No default UART bus" msgstr "" @@ -404,12 +404,12 @@ msgstr "" msgid "No RX pin" msgstr "" -#: ports/atmel-samd/common-hal/busio/UART.c:284 +#: ports/atmel-samd/common-hal/busio/UART.c:288 msgid "No TX pin" msgstr "" -#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c:168 -#: ports/nrf/common-hal/digitalio/DigitalInOut.c:158 +#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c:170 +#: ports/nrf/common-hal/digitalio/DigitalInOut.c:153 msgid "Cannot get pull while in output mode" msgstr "" @@ -442,12 +442,12 @@ msgstr "El canal EXTINT ya esta siendo usado" msgid "Failed to allocate RX buffer of %d bytes" msgstr "Fallo la asignación del buffer RX de %d bytes" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:203 +#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:205 #: ports/esp8266/common-hal/pulseio/PulseIn.c:151 msgid "pop from an empty PulseIn" msgstr "" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:235 +#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:237 #: ports/esp8266/common-hal/pulseio/PulseIn.c:182 py/obj.c:420 msgid "index out of range" msgstr "" @@ -703,11 +703,11 @@ msgstr "" msgid "AnalogOut functionality not supported" msgstr "" -#: ports/nrf/common-hal/busio/UART.c:45 ports/nrf/common-hal/busio/UART.c:49 -#: ports/nrf/common-hal/busio/UART.c:53 ports/nrf/common-hal/busio/UART.c:62 -#: ports/nrf/common-hal/busio/UART.c:68 ports/nrf/common-hal/busio/UART.c:73 -#: ports/nrf/common-hal/busio/UART.c:78 ports/nrf/common-hal/busio/UART.c:83 -#: ports/nrf/common-hal/busio/UART.c:88 +#: ports/nrf/common-hal/busio/UART.c:43 ports/nrf/common-hal/busio/UART.c:47 +#: ports/nrf/common-hal/busio/UART.c:51 ports/nrf/common-hal/busio/UART.c:60 +#: ports/nrf/common-hal/busio/UART.c:66 ports/nrf/common-hal/busio/UART.c:71 +#: ports/nrf/common-hal/busio/UART.c:76 ports/nrf/common-hal/busio/UART.c:81 +#: ports/nrf/common-hal/busio/UART.c:86 msgid "busio.UART not yet implemented" msgstr "" diff --git a/locale/fil.po b/locale/fil.po index 8f681bcb49..7d5102d480 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-09-06 14:49-0700\n" +"POT-Creation-Date: 2018-09-06 14:55-0700\n" "PO-Revision-Date: 2018-08-30 23:04-0700\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -243,15 +243,15 @@ msgstr "pagkakalibrate ay basahin lamang" msgid "calibration is out of range" msgstr "kalibrasion ay wala sa sakop" -#: ports/atmel-samd/board_busses.c:39 +#: ports/atmel-samd/board_busses.c:39 ports/nrf/board_busses.c:39 msgid "No default I2C bus" msgstr "Walang default na I2C bus" -#: ports/atmel-samd/board_busses.c:64 +#: ports/atmel-samd/board_busses.c:64 ports/nrf/board_busses.c:64 msgid "No default SPI bus" msgstr "Walang default SPI bus" -#: ports/atmel-samd/board_busses.c:91 +#: ports/atmel-samd/board_busses.c:91 ports/nrf/board_busses.c:91 msgid "No default UART bus" msgstr "Walang default UART bus" @@ -400,12 +400,12 @@ msgstr "Hindi ma-initialize ang UART" msgid "No RX pin" msgstr "Walang RX pin" -#: ports/atmel-samd/common-hal/busio/UART.c:284 +#: ports/atmel-samd/common-hal/busio/UART.c:288 msgid "No TX pin" msgstr "Walang TX pin" -#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c:168 -#: ports/nrf/common-hal/digitalio/DigitalInOut.c:158 +#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c:170 +#: ports/nrf/common-hal/digitalio/DigitalInOut.c:153 msgid "Cannot get pull while in output mode" msgstr "Hindi makakakuha ng pull habang nasa output mode" @@ -438,12 +438,12 @@ msgstr "Ginagamit na ang EXTINT channel" msgid "Failed to allocate RX buffer of %d bytes" msgstr "Nabigong ilaan ang RX buffer ng %d bytes" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:203 +#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:205 #: ports/esp8266/common-hal/pulseio/PulseIn.c:151 msgid "pop from an empty PulseIn" msgstr "pop mula sa walang laman na PulseIn" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:235 +#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:237 #: ports/esp8266/common-hal/pulseio/PulseIn.c:182 py/obj.c:420 msgid "index out of range" msgstr "index wala sa sakop" @@ -700,11 +700,11 @@ msgstr "hindi alam na config param" msgid "AnalogOut functionality not supported" msgstr "Hindi supportado ang AnalogOut" -#: ports/nrf/common-hal/busio/UART.c:45 ports/nrf/common-hal/busio/UART.c:49 -#: ports/nrf/common-hal/busio/UART.c:53 ports/nrf/common-hal/busio/UART.c:62 -#: ports/nrf/common-hal/busio/UART.c:68 ports/nrf/common-hal/busio/UART.c:73 -#: ports/nrf/common-hal/busio/UART.c:78 ports/nrf/common-hal/busio/UART.c:83 -#: ports/nrf/common-hal/busio/UART.c:88 +#: ports/nrf/common-hal/busio/UART.c:43 ports/nrf/common-hal/busio/UART.c:47 +#: ports/nrf/common-hal/busio/UART.c:51 ports/nrf/common-hal/busio/UART.c:60 +#: ports/nrf/common-hal/busio/UART.c:66 ports/nrf/common-hal/busio/UART.c:71 +#: ports/nrf/common-hal/busio/UART.c:76 ports/nrf/common-hal/busio/UART.c:81 +#: ports/nrf/common-hal/busio/UART.c:86 msgid "busio.UART not yet implemented" msgstr "hindi pa implemented ang busio.UART" diff --git a/locale/fr.po b/locale/fr.po index 740830e108..5ef13110b6 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-09-06 14:49-0700\n" +"POT-Creation-Date: 2018-09-06 14:55-0700\n" "PO-Revision-Date: 2018-08-14 11:01+0200\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -238,15 +238,15 @@ msgstr "la calibration est en lecture seule" msgid "calibration is out of range" msgstr "la calibration est hors gamme" -#: ports/atmel-samd/board_busses.c:39 +#: ports/atmel-samd/board_busses.c:39 ports/nrf/board_busses.c:39 msgid "No default I2C bus" msgstr "Pas de bus I2C par défaut" -#: ports/atmel-samd/board_busses.c:64 +#: ports/atmel-samd/board_busses.c:64 ports/nrf/board_busses.c:64 msgid "No default SPI bus" msgstr "Pas de bus SPI par défaut" -#: ports/atmel-samd/board_busses.c:91 +#: ports/atmel-samd/board_busses.c:91 ports/nrf/board_busses.c:91 msgid "No default UART bus" msgstr "Pas de bus UART par défaut" @@ -395,12 +395,12 @@ msgstr "L'UART n'a pu être initialisé" msgid "No RX pin" msgstr "Pas de broche RX" -#: ports/atmel-samd/common-hal/busio/UART.c:284 +#: ports/atmel-samd/common-hal/busio/UART.c:288 msgid "No TX pin" msgstr "Pas de broche TX" -#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c:168 -#: ports/nrf/common-hal/digitalio/DigitalInOut.c:158 +#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c:170 +#: ports/nrf/common-hal/digitalio/DigitalInOut.c:153 msgid "Cannot get pull while in output mode" msgstr "Ne peux être tirer ('pull') en mode 'output'" @@ -434,12 +434,12 @@ msgstr "Canal EXTINT déjà utilisé" msgid "Failed to allocate RX buffer of %d bytes" msgstr "Echec de l'allocation de %d octets du tampon RX" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:203 +#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:205 #: ports/esp8266/common-hal/pulseio/PulseIn.c:151 msgid "pop from an empty PulseIn" msgstr "'pop' d'une entrée PulseIn vide" -#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:235 +#: ports/atmel-samd/common-hal/pulseio/PulseIn.c:237 #: ports/esp8266/common-hal/pulseio/PulseIn.c:182 py/obj.c:420 msgid "index out of range" msgstr "index hors gamme" @@ -696,11 +696,11 @@ msgstr "paramètre de config. inconnu" msgid "AnalogOut functionality not supported" msgstr "AnalogOut non supporté" -#: ports/nrf/common-hal/busio/UART.c:45 ports/nrf/common-hal/busio/UART.c:49 -#: ports/nrf/common-hal/busio/UART.c:53 ports/nrf/common-hal/busio/UART.c:62 -#: ports/nrf/common-hal/busio/UART.c:68 ports/nrf/common-hal/busio/UART.c:73 -#: ports/nrf/common-hal/busio/UART.c:78 ports/nrf/common-hal/busio/UART.c:83 -#: ports/nrf/common-hal/busio/UART.c:88 +#: ports/nrf/common-hal/busio/UART.c:43 ports/nrf/common-hal/busio/UART.c:47 +#: ports/nrf/common-hal/busio/UART.c:51 ports/nrf/common-hal/busio/UART.c:60 +#: ports/nrf/common-hal/busio/UART.c:66 ports/nrf/common-hal/busio/UART.c:71 +#: ports/nrf/common-hal/busio/UART.c:76 ports/nrf/common-hal/busio/UART.c:81 +#: ports/nrf/common-hal/busio/UART.c:86 msgid "busio.UART not yet implemented" msgstr "busio.UART pas encore implémenté" diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 21744f947b..7086d0ab11 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -39,7 +39,7 @@ //| .. currentmodule:: displayio //| //| :class:`Palette` -- Stores a mapping from bitmap pixel palette_indexes to display colors -//| =============================================================================== +//| ========================================================================================= //| //| Map a pixel palette_index to a full color. Colors are transformed to the display's format internally to //| save memory.