Skip to content

Commit 2186673

Browse files
authored
Merge pull request #5398 from Gadgetoid/patch-picosystem-displayio
PicoSystem: Add DisplayIO to board config
2 parents 3988670 + 2fc6a72 commit 2186673

File tree

3 files changed

+97
-3
lines changed

3 files changed

+97
-3
lines changed

ports/raspberrypi/boards/pimoroni_picosystem/board.c

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,93 @@
2525
*/
2626

2727
#include "supervisor/board.h"
28+
#include "mpconfigboard.h"
29+
#include "shared-bindings/busio/SPI.h"
30+
#include "shared-bindings/displayio/FourWire.h"
31+
#include "shared-module/displayio/__init__.h"
32+
#include "shared-module/displayio/mipi_constants.h"
33+
#include "supervisor/shared/board.h"
34+
35+
displayio_fourwire_obj_t board_display_obj;
36+
37+
#define DELAY 0x80
38+
39+
uint8_t display_init_sequence[] = {
40+
0x01, 0 | DELAY, 150, // SWRESET
41+
42+
0x36, 1, 0x04, // MADCTL
43+
0x35, 1, 0x00, // TEON
44+
0xB2, 5, 0x0c, 0x0c, 0x00, 0x33, 0x33, // FRMCTR2
45+
0x3A, 1, 0x05, // COLMOD
46+
0xB7, 1, 0x14, // GCTRL
47+
0xBB, 1, 0x37, // VCOMS
48+
0xC0, 1, 0x2c, // LCMCTRL
49+
0xC2, 1, 0x01, // VDVVRHEN
50+
0xC3, 1, 0x12, // VRHS
51+
0xC4, 1, 0x20, // VDVS
52+
0xD0, 2, 0xa4, 0xa1, // PWRCTRL1
53+
0xC6, 1, 0x0f, // FRCTRL2
54+
0xE0, 14, 0xd0, 0x04, 0x0d, 0x11, 0x13, 0x2b, 0x3f, 0x54, 0x4c, 0x18, 0x0d, 0x0b, 0x1f, 0x23, // GMCTRP1
55+
0xE1, 14, 0xd0, 0x04, 0x0c, 0x11, 0x13, 0x2c, 0x3f, 0x44, 0x51, 0x2f, 0x1f, 0x1f, 0x20, 0x23, // GMCTRN1
56+
0x21, 0, // INVON
57+
58+
0x11, 0 | DELAY, 255, // SLPOUT
59+
0x29, 0 | DELAY, 100, // DISPON
60+
61+
0x2a, 4, 0x00, 0, 0x00, 0xfe, // CASET
62+
0x2b, 4, 0x00, 0, 0x00, 0xfe, // RASET
63+
0x2c, 0, // RAMWR
64+
};
2865

2966
void board_init(void) {
67+
busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus;
68+
common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL);
69+
common_hal_busio_spi_never_reset(spi);
70+
71+
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
72+
bus->base.type = &displayio_fourwire_type;
73+
common_hal_displayio_fourwire_construct(bus,
74+
spi,
75+
&pin_GPIO9, // TFT_DC Command or data
76+
&pin_GPIO5, // TFT_CS Chip select
77+
&pin_GPIO4, // TFT_RST Reset
78+
60000000, // Baudrate
79+
0, // Polarity
80+
0); // Phase
81+
82+
displayio_display_obj_t *display = &displays[0].display;
83+
display->base.type = &displayio_display_type;
84+
common_hal_displayio_display_construct(display,
85+
bus,
86+
240, // Width
87+
240, // Height
88+
0, // column start
89+
0, // row start
90+
0, // rotation
91+
16, // Color depth
92+
false, // Grayscale
93+
false, // pixels in a byte share a row. Only valid for depths < 8
94+
1, // bytes per cell. Only valid for depths < 8
95+
false, // reverse_pixels_in_byte. Only valid for depths < 8
96+
true, // reverse_bytes_in_word
97+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
98+
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
99+
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
100+
display_init_sequence,
101+
sizeof(display_init_sequence),
102+
&pin_GPIO12, // backlight pin
103+
NO_BRIGHTNESS_COMMAND,
104+
1.0f, // brightness (ignored)
105+
true, // auto_brightness
106+
false, // single_byte_bounds
107+
false, // data_as_commands
108+
true, // auto_refresh
109+
60, // native_frames_per_second
110+
true, // backlight_on_high
111+
false); // SH1107_addressing
112+
}
113+
114+
void board_deinit(void) {
30115
}
31116

32117
bool board_requests_safe_mode(void) {
@@ -35,6 +120,3 @@ bool board_requests_safe_mode(void) {
35120

36121
void reset_board(void) {
37122
}
38-
39-
void board_deinit(void) {
40-
}

ports/raspberrypi/boards/pimoroni_picosystem/mpconfigboard.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ CHIP_FAMILY = rp2
99
EXTERNAL_FLASH_DEVICES = "W25Q128JVxQ"
1010

1111
CIRCUITPY__EVE = 1
12+
13+
CIRCUITPY_KEYPAD = 1
14+
CIRCUITPY_STAGE = 1
15+
16+
CIRCUITPY_AUDIOIO = 1
17+
18+
# TODO: how do we get stage.py and ugame.py on PicoSystem?
19+
# FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/picosystem

ports/raspberrypi/boards/pimoroni_picosystem/pins.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "shared-bindings/board/__init__.h"
2+
#include "shared-module/displayio/__init__.h"
23

34
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
45
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
@@ -41,5 +42,8 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
4142

4243
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
4344
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
45+
46+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
4447
};
48+
4549
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

0 commit comments

Comments
 (0)