Skip to content

Commit 8665e85

Browse files
authored
Merge pull request #6424 from ladyada/main
add esp32s3 tft
2 parents 0ea72d6 + 99d7d0d commit 8665e85

File tree

5 files changed

+347
-0
lines changed

5 files changed

+347
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#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-bindings/microcontroller/Pin.h"
32+
#include "shared-module/displayio/__init__.h"
33+
#include "shared-module/displayio/mipi_constants.h"
34+
#include "shared-bindings/board/__init__.h"
35+
36+
displayio_fourwire_obj_t board_display_obj;
37+
38+
#define DELAY 0x80
39+
40+
// display init sequence according to LilyGO example app
41+
uint8_t display_init_sequence[] = {
42+
// sw reset
43+
0x01, 0 | DELAY, 150,
44+
// sleep out
45+
0x11, 0 | DELAY, 255,
46+
// normal display mode on
47+
0x13, 0,
48+
// display and color format settings
49+
0x36, 1, 0x68,
50+
0xB6, 2, 0x0A, 0x82,
51+
0x3A, 1 | DELAY, 0x55, 10,
52+
// ST7789V frame rate setting
53+
0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33,
54+
// voltages: VGH / VGL
55+
0xB7, 1, 0x35,
56+
// ST7789V power setting
57+
0xBB, 1, 0x28,
58+
0xC0, 1, 0x0C,
59+
0xC2, 2, 0x01, 0xFF,
60+
0xC3, 1, 0x10,
61+
0xC4, 1, 0x20,
62+
0xC6, 1, 0x0F,
63+
0xD0, 2, 0xA4, 0xA1,
64+
// ST7789V gamma setting
65+
0xE0, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x32, 0x44, 0x42, 0x06, 0x0E, 0x12, 0x14, 0x17,
66+
0xE1, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x31, 0x54, 0x47, 0x0E, 0x1C, 0x17, 0x1B, 0x1E,
67+
0x21, 0,
68+
// display on
69+
0x29, 0 | DELAY, 255,
70+
};
71+
72+
73+
void board_init(void) {
74+
// THIS SHOULD BE HANDLED BY espressif_board_reset_pin_number(), but it is not working.
75+
// TEMPORARY FIX UNTIL IT'S DIAGNOSED.
76+
common_hal_never_reset_pin(&pin_GPIO21);
77+
gpio_set_direction(21, GPIO_MODE_DEF_OUTPUT);
78+
gpio_set_level(21, true);
79+
80+
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
81+
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
82+
bus->base.type = &displayio_fourwire_type;
83+
84+
common_hal_displayio_fourwire_construct(
85+
bus,
86+
spi,
87+
&pin_GPIO39, // DC
88+
&pin_GPIO7, // CS
89+
&pin_GPIO40, // RST
90+
40000000, // baudrate
91+
0, // polarity
92+
0 // phase
93+
);
94+
displayio_display_obj_t *display = &displays[0].display;
95+
display->base.type = &displayio_display_type;
96+
97+
// workaround as board_init() is called before reset_port() in main.c
98+
pwmout_reset();
99+
100+
common_hal_displayio_display_construct(
101+
display,
102+
bus,
103+
240, // width (after rotation)
104+
135, // height (after rotation)
105+
40, // column start
106+
53, // row start
107+
0, // rotation
108+
16, // color depth
109+
false, // grayscale
110+
false, // pixels in a byte share a row. Only valid for depths < 8
111+
1, // bytes per cell. Only valid for depths < 8
112+
false, // reverse_pixels_in_byte. Only valid for depths < 8
113+
true, // reverse_pixels_in_word
114+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
115+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
116+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
117+
display_init_sequence,
118+
sizeof(display_init_sequence),
119+
&pin_GPIO45, // backlight pin
120+
NO_BRIGHTNESS_COMMAND,
121+
1.0f, // brightness (ignored)
122+
false, // auto_brightness
123+
false, // single_byte_bounds
124+
false, // data_as_commands
125+
true, // auto_refresh
126+
60, // native_frames_per_second
127+
true, // backlight_on_high
128+
false // SH1107_addressing
129+
);
130+
131+
common_hal_never_reset_pin(&pin_GPIO45); // backlight pin
132+
}
133+
134+
bool board_requests_safe_mode(void) {
135+
return false;
136+
}
137+
138+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
139+
// Override the I2C/TFT power pin reset to prevent resetting the display.
140+
if (pin_number == 21) {
141+
// Turn on TFT and I2C
142+
gpio_set_direction(21, GPIO_MODE_DEF_OUTPUT);
143+
gpio_set_level(21, true);
144+
return true;
145+
}
146+
return false;
147+
}
148+
149+
void reset_board(void) {
150+
}
151+
152+
void board_deinit(void) {
153+
// TODO: Should we turn off the display when asleep?
154+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
// Micropython setup
28+
29+
#define MICROPY_HW_BOARD_NAME "Adafruit Feather ESP32-S3 TFT"
30+
#define MICROPY_HW_MCU_NAME "ESP32S3"
31+
32+
#define MICROPY_HW_NEOPIXEL (&pin_GPIO33)
33+
#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO34)
34+
35+
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO41)
36+
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO42)
37+
38+
#define DEFAULT_SPI_BUS_SCK (&pin_GPIO36)
39+
#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO35)
40+
#define DEFAULT_SPI_BUS_MISO (&pin_GPIO37)
41+
42+
#define DEFAULT_UART_BUS_RX (&pin_GPIO2)
43+
#define DEFAULT_UART_BUS_TX (&pin_GPIO1)
44+
45+
#define DOUBLE_TAP_PIN (&pin_GPIO38)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
USB_VID = 0x239A
2+
USB_PID = 0x811E
3+
4+
USB_PRODUCT = "Feather ESP32-S3 TFT"
5+
USB_MANUFACTURER = "Adafruit"
6+
7+
IDF_TARGET = esp32s3
8+
9+
# Make room for build
10+
CIRCUITPY_ULAB = 0
11+
12+
INTERNAL_FLASH_FILESYSTEM = 1
13+
LONGINT_IMPL = MPZ
14+
15+
# The default queue depth of 16 overflows on release builds,
16+
# so increase it to 32.
17+
CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32
18+
19+
CIRCUITPY_ESP_FLASH_MODE=dio
20+
CIRCUITPY_ESP_FLASH_FREQ=40m
21+
CIRCUITPY_ESP_FLASH_SIZE=4MB
22+
23+
CIRCUITPY_MODULE=wroom
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include "shared-bindings/board/__init__.h"
2+
3+
#include "shared-module/displayio/__init__.h"
4+
5+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
6+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
7+
8+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO1) },
9+
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) },
10+
11+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO2) },
12+
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) },
13+
14+
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO5) },
15+
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO6) },
16+
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO9) },
17+
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO10) },
18+
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO11) },
19+
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12) },
20+
21+
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) },
22+
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) },
23+
{ MP_ROM_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_GPIO13) },
24+
25+
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO8) },
26+
{ MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO8) },
27+
28+
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO14) },
29+
{ MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO14) },
30+
31+
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO15) },
32+
{ MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO15) },
33+
34+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO16) },
35+
{ MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_GPIO16) },
36+
37+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO17) },
38+
{ MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO17) },
39+
40+
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO18) },
41+
{ MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_GPIO18) },
42+
43+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO33) },
44+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO34) },
45+
46+
{ MP_ROM_QSTR(MP_QSTR_TFT_I2C_POWER), MP_ROM_PTR(&pin_GPIO21) },
47+
48+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO35) },
49+
{ MP_ROM_QSTR(MP_QSTR_D35), MP_ROM_PTR(&pin_GPIO35) },
50+
51+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO36) },
52+
{ MP_ROM_QSTR(MP_QSTR_D36), MP_ROM_PTR(&pin_GPIO36) },
53+
54+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO37) },
55+
{ MP_ROM_QSTR(MP_QSTR_D37), MP_ROM_PTR(&pin_GPIO37) },
56+
57+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO41) },
58+
{ MP_ROM_QSTR(MP_QSTR_D41), MP_ROM_PTR(&pin_GPIO41) },
59+
60+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO42) },
61+
{ MP_ROM_QSTR(MP_QSTR_D42), MP_ROM_PTR(&pin_GPIO42) },
62+
63+
{ MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO7) },
64+
{ MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO39) },
65+
{ MP_ROM_QSTR(MP_QSTR_TFT_RESET), MP_ROM_PTR(&pin_GPIO40) },
66+
{ MP_ROM_QSTR(MP_QSTR_TFT_BACKLIGHT), MP_ROM_PTR(&pin_GPIO45) },
67+
68+
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO0) },
69+
{ MP_ROM_QSTR(MP_QSTR_BOOT0), MP_ROM_PTR(&pin_GPIO0) },
70+
71+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
72+
{ MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) },
73+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
74+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
75+
76+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
77+
};
78+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#
2+
# Component config
3+
#
4+
#
5+
# ESP32S3-Specific
6+
#
7+
CONFIG_ESP32S3_SPIRAM_SUPPORT=y
8+
#
9+
# SPI RAM config
10+
#
11+
CONFIG_SPIRAM_MODE_QUAD=y
12+
# CONFIG_SPIRAM_MODE_OCT is not set
13+
CONFIG_SPIRAM_TYPE_AUTO=y
14+
# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set
15+
# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set
16+
# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set
17+
CONFIG_SPIRAM_SIZE=2097152
18+
#
19+
# PSRAM Clock and CS IO for ESP32S3
20+
#
21+
CONFIG_DEFAULT_PSRAM_CLK_IO=30
22+
CONFIG_DEFAULT_PSRAM_CS_IO=26
23+
# end of PSRAM Clock and CS IO for ESP32S3
24+
25+
# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set
26+
# CONFIG_SPIRAM_RODATA is not set
27+
# CONFIG_SPIRAM_SPEED_120M is not set
28+
CONFIG_SPIRAM_SPEED_80M=y
29+
# CONFIG_SPIRAM_SPEED_40M is not set
30+
CONFIG_SPIRAM=y
31+
CONFIG_SPIRAM_BOOT_INIT=y
32+
# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set
33+
CONFIG_SPIRAM_USE_MEMMAP=y
34+
# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set
35+
# CONFIG_SPIRAM_USE_MALLOC is not set
36+
CONFIG_SPIRAM_MEMTEST=y
37+
# end of SPI RAM config
38+
39+
# end of ESP32S3-Specific
40+
41+
#
42+
# LWIP
43+
#
44+
CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3"
45+
# end of LWIP
46+
47+
# end of Component config

0 commit comments

Comments
 (0)