Skip to content

Commit bcec249

Browse files
committed
displaaaaaaaaay
1 parent d30c3ba commit bcec249

File tree

2 files changed

+82
-46
lines changed

2 files changed

+82
-46
lines changed

ports/espressif/boards/adafruit_feather_esp32s2_tft/board.c

Lines changed: 81 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,76 +32,112 @@
3232
#include "shared-module/displayio/__init__.h"
3333
#include "shared-module/displayio/mipi_constants.h"
3434

35-
/*
3635
displayio_fourwire_obj_t board_display_obj;
3736

3837
#define DELAY 0x80
3938

39+
// display init sequence according to LilyGO example app
4040
uint8_t display_init_sequence[] = {
41-
0x01, 0 | DELAY, 150, // SWRESET
42-
0x11, 0 | DELAY, 255, // SLPOUT
43-
0x36, 1, 0x00, // _MADCTL bottom to top refresh in vsync aligned order.
44-
0x3a, 1, 0x55, // COLMOD - 16bit color
45-
0x21, 0 | DELAY, 10, // _INVON
46-
0x13, 0 | DELAY, 10, // _NORON
47-
0x29, 0 | DELAY, 255, // _DISPON
41+
// sw reset
42+
0x01, 0 | DELAY, 150,
43+
// sleep out
44+
0x11, 0 | DELAY, 255,
45+
// normal display mode on
46+
0x13, 0,
47+
// display and color format settings
48+
0x36, 1, 0x08,
49+
0xB6, 2, 0x0A, 0x82,
50+
0x3A, 1 | DELAY, 0x55, 10,
51+
// ST7789V frame rate setting
52+
0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33,
53+
// voltages: VGH / VGL
54+
0xB7, 1, 0x35,
55+
// ST7789V power setting
56+
0xBB, 1, 0x28,
57+
0xC0, 1, 0x0C,
58+
0xC2, 2, 0x01, 0xFF,
59+
0xC3, 1, 0x10,
60+
0xC4, 1, 0x20,
61+
0xC6, 1, 0x0F,
62+
0xD0, 2, 0xA4, 0xA1,
63+
// ST7789V gamma setting
64+
0xE0, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x32, 0x44, 0x42, 0x06, 0x0E, 0x12, 0x14, 0x17,
65+
0xE1, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x31, 0x54, 0x47, 0x0E, 0x1C, 0x17, 0x1B, 0x1E,
66+
0x21, 0,
67+
// display on
68+
0x29, 0 | DELAY, 255,
4869
};
4970

50-
*/
5171

5272
void board_init(void) {
5373
// USB
5474
common_hal_never_reset_pin(&pin_GPIO19);
5575
common_hal_never_reset_pin(&pin_GPIO20);
5676

5777

58-
/*
59-
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
60-
common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL);
78+
busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus;
79+
80+
common_hal_busio_spi_construct(
81+
spi,
82+
&pin_GPIO36, // CLK
83+
&pin_GPIO35, // MOSI
84+
NULL // MISO not connected
85+
);
86+
6187
common_hal_busio_spi_never_reset(spi);
6288

6389
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
6490
bus->base.type = &displayio_fourwire_type;
65-
common_hal_displayio_fourwire_construct(bus,
66-
spi,
67-
&pin_GPIO40, // TFT_DC Command or data
68-
&pin_GPIO42, // TFT_CS Chip select
69-
&pin_GPIO41, // TFT_RST Reset
70-
4000000, // Baudrate
71-
0, // Polarity
72-
0); // Phase
7391

92+
common_hal_displayio_fourwire_construct(
93+
bus,
94+
spi,
95+
&pin_GPIO39, // DC
96+
&pin_GPIO21, // CS
97+
&pin_GPIO40, // RST
98+
40000000, // baudrate
99+
0, // polarity
100+
0 // phase
101+
);
74102
displayio_display_obj_t* display = &displays[0].display;
75103
display->base.type = &displayio_display_type;
76-
common_hal_displayio_display_construct(display,
104+
105+
// workaround as board_init() is called before reset_port() in main.c
106+
pwmout_reset();
107+
108+
109+
common_hal_displayio_display_construct(
110+
display,
77111
bus,
78-
240, // Width (after rotation)
79-
135, // Height (after rotation)
80-
0, // column start
81-
0, // row start
82-
0, // rotation
83-
16, // Color depth
84-
false, // Grayscale
85-
false, // Pixels in a byte share a row. Only used for depth < 8
86-
1, // bytes per cell. Only valid for depths < 8
87-
false, // reverse_pixels_in_byte. Only valid for depths < 8
88-
true, // reverse_pixels_in_word
89-
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
90-
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
91-
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
112+
240, // width (after rotation)
113+
135, // height (after rotation)
114+
52, // column start
115+
40, // row start
116+
90, // rotation
117+
16, // color depth
118+
false, // grayscale
119+
false, // pixels in a byte share a row. Only valid for depths < 8
120+
1, // bytes per cell. Only valid for depths < 8
121+
false, // reverse_pixels_in_byte. Only valid for depths < 8
122+
true, // reverse_pixels_in_word
123+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
124+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
125+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
92126
display_init_sequence,
93127
sizeof(display_init_sequence),
94-
&pin_GPIO7, // backlight pin
128+
&pin_GPIO45, // backlight pin
95129
NO_BRIGHTNESS_COMMAND,
96-
1.0f, // brightness (ignored)
97-
true, // auto_brightness
98-
false, // single_byte_bounds
99-
false, // data_as_commands
100-
true, // auto_refresh
101-
60, // native_frames_per_second
102-
true, // backlight_on_high
103-
false); // not SH1107
104-
*/
130+
1.0f, // brightness (ignored)
131+
false, // auto_brightness
132+
false, // single_byte_bounds
133+
false, // data_as_commands
134+
true, // auto_refresh
135+
60, // native_frames_per_second
136+
true, // backlight_on_high
137+
false // SH1107_addressing
138+
);
139+
140+
common_hal_never_reset_pin(&pin_GPIO45); // backlight pin
105141
}
106142

107143
bool board_requests_safe_mode(void) {

ports/espressif/boards/adafruit_feather_esp32s2_tft/pins.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
6868
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
6969
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }
7070

71-
// { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
71+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
7272
};
7373
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

0 commit comments

Comments
 (0)