Enable displayio for uGame10 board

Also, make the _stage library work with the fourwire bus, to re-use the
display.
This commit is contained in:
Radomir Dopieralski 2019-04-06 14:02:18 +02:00
parent 121d532a0e
commit c3136f4f32
6 changed files with 95 additions and 12 deletions

@ -1 +1 @@
Subproject commit d8a9d8c1d73041e4cc5669c5441f531ecba517fc Subproject commit 347b02095449075d3e9bb1b7bac6d3a8a2151df2

View File

@ -26,7 +26,80 @@
#include "boards/board.h" #include "boards/board.h"
#include "shared-bindings/board/__init__.h"
#include "shared-bindings/displayio/FourWire.h"
#include "shared-module/displayio/__init__.h"
#include "shared-module/displayio/mipi_constants.h"
#include "shared-bindings/busio/SPI.h"
#include "tick.h"
displayio_fourwire_obj_t board_display_obj;
#define DELAY 0x80
uint8_t display_init_sequence[] = {
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,
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, 0xa8, // _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 | DELAY, 10, // _NORON
0x29, 0 | DELAY, 100, // _DISPON
};
void board_init(void) { void board_init(void) {
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
bus->base.type = &displayio_fourwire_type;
busio_spi_obj_t *spi = common_hal_board_create_spi();
common_hal_busio_spi_configure(spi, 24000000, 0, 0, 8);
common_hal_displayio_fourwire_construct(bus,
spi,
&pin_PA09, // Command or data
&pin_PA08, // Chip select
NULL); // Reset
displayio_display_obj_t* display = &displays[0].display;
display->base.type = &displayio_display_type;
common_hal_displayio_display_construct(display,
bus,
128, // Width
128, // Height
3, // column start
2, // row start
0, // rotation
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
0x37, // set vertical scroll command
display_init_sequence,
sizeof(display_init_sequence),
NULL,
false, // single_byte_bounds
false); // data as commands
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -7,7 +7,7 @@
#define SPI_FLASH_CS_PIN &pin_PA18 #define SPI_FLASH_CS_PIN &pin_PA18
// These are pins not to reset. // These are pins not to reset.
#define MICROPY_PORT_A (0) #define MICROPY_PORT_A (PORT_PA06 | PORT_PA07 | PORT_PA08 | PORT_PA09)
#define MICROPY_PORT_B (0) #define MICROPY_PORT_B (0)
#define MICROPY_PORT_C (0) #define MICROPY_PORT_C (0)
@ -19,10 +19,9 @@
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE) #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - CIRCUITPY_INTERNAL_NVM_SIZE)
#define EXTRA_BUILTIN_MODULES \ #define DEFAULT_SPI_BUS_SCK (&pin_PA07)
{ MP_OBJ_NEW_QSTR(MP_QSTR_audioio), (mp_obj_t)&audioio_module }, \ #define DEFAULT_SPI_BUS_MISO (&pin_PA11)
{ MP_OBJ_NEW_QSTR(MP_QSTR_gamepad),(mp_obj_t)&gamepad_module }, \ #define DEFAULT_SPI_BUS_MOSI (&pin_PA06)
{ MP_OBJ_NEW_QSTR(MP_QSTR__stage), (mp_obj_t)&stage_module }
#define IGNORE_PIN_PB00 1 #define IGNORE_PIN_PB00 1
#define IGNORE_PIN_PB01 1 #define IGNORE_PIN_PB01 1

View File

@ -17,13 +17,16 @@ CIRCUITPY_MATH = 1
CIRCUITPY_AUDIOIO = 1 CIRCUITPY_AUDIOIO = 1
CIRCUITPY_ANALOGIO = 1 CIRCUITPY_ANALOGIO = 1
CIRCUITPY_GAMEPAD = 1 CIRCUITPY_GAMEPAD = 1
CIRCUITPY_DISPLAYIO = 1
CIRCUITPY_TOUCHIO = 0 CIRCUITPY_TOUCHIO = 0
CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_RTC = 0 CIRCUITPY_RTC = 0
CIRCUITPY_SAMD = 0
CIRCUITPY_USB_MIDI = 0 CIRCUITPY_USB_MIDI = 0
CIRCUITPY_USB_HID = 0 CIRCUITPY_USB_HID = 0
CIRCUITPY_I2CSLAVE = 0
CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_SMALL_BUILD = 1 CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_PIXELBUF = 0
FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage

View File

@ -1,4 +1,5 @@
#include "shared-bindings/board/__init__.h" #include "shared-bindings/board/__init__.h"
#include "shared-module/displayio/__init__.h"
STATIC const mp_rom_map_elem_t board_global_dict_table[] = { STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_X), MP_ROM_PTR(&pin_PA00) }, { MP_ROM_QSTR(MP_QSTR_X), MP_ROM_PTR(&pin_PA00) },
@ -23,8 +24,8 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_B), MP_ROM_PTR(&pin_PA14) }, { MP_ROM_QSTR(MP_QSTR_B), MP_ROM_PTR(&pin_PA14) },
{ MP_ROM_QSTR(MP_QSTR_C), MP_ROM_PTR(&pin_PA15) }, { MP_ROM_QSTR(MP_QSTR_C), MP_ROM_PTR(&pin_PA15) },
{ MP_ROM_QSTR(MP_QSTR_D), MP_ROM_PTR(&pin_PA28) }, { MP_ROM_QSTR(MP_QSTR_D), MP_ROM_PTR(&pin_PA28) },
{ 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_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(&displays[0].display)}
}; };
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

View File

@ -28,6 +28,7 @@
#include "py/mperrno.h" #include "py/mperrno.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "shared-bindings/busio/SPI.h" #include "shared-bindings/busio/SPI.h"
#include "shared-bindings/displayio/FourWire.h"
#include "shared-module/_stage/__init__.h" #include "shared-module/_stage/__init__.h"
#include "Layer.h" #include "Layer.h"
#include "Text.h" #include "Text.h"
@ -85,12 +86,18 @@ STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) {
uint16_t *buffer = bufinfo.buf; uint16_t *buffer = bufinfo.buf;
size_t buffer_size = bufinfo.len / 2; // 16-bit indexing size_t buffer_size = bufinfo.len / 2; // 16-bit indexing
busio_spi_obj_t *spi = MP_OBJ_TO_PTR(args[6]); displayio_fourwire_obj_t *bus = MP_OBJ_TO_PTR(args[6]);
while (!common_hal_displayio_fourwire_begin_transaction(bus)) {
#ifdef MICROPY_VM_HOOK_LOOP
MICROPY_VM_HOOK_LOOP ;
#endif
}
if (!render_stage(x0, y0, x1, y1, layers, layers_size, if (!render_stage(x0, y0, x1, y1, layers, layers_size,
buffer, buffer_size, spi)) { buffer, buffer_size, bus->bus)) {
mp_raise_OSError(MP_EIO); mp_raise_OSError(MP_EIO);
} }
common_hal_displayio_fourwire_end_transaction(bus);
return mp_const_none; return mp_const_none;
} }