Skip to content

Commit 36014c0

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents b2d3fd7 + dd73182 commit 36014c0

File tree

5 files changed

+247
-0
lines changed

5 files changed

+247
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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/microcontroller/Pin.h"
30+
31+
#include "shared-bindings/busio/SPI.h"
32+
#include "shared-bindings/displayio/FourWire.h"
33+
#include "shared-module/displayio/__init__.h"
34+
#include "shared-module/displayio/mipi_constants.h"
35+
36+
#define DELAY 0x80
37+
38+
// Init sequence from:
39+
// https://github.com/espressif/esp-dev-kits/blob/26ad8c9070b717da9fa06ce480099b7826761c2a/esp32-s3-usb-otg/components/display_screen/controller_driver/st7789/st7789.c#L75
40+
41+
// display init sequence according to LilyGO example app
42+
uint8_t display_init_sequence[] = {
43+
// sw reset
44+
0x01, 0 | DELAY, 150,
45+
// normal display mode on
46+
0x13, 0,
47+
// display and color format settings
48+
// 0x36, 1, 0x68,
49+
// 0xB6, 2, 0x0A, 0x82,
50+
0x3A, 1 | DELAY, 0x05, 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, 0x19,
57+
0xC0, 1, 0x2C,
58+
0xC2, 1, 0x01,
59+
0xC3, 1, 0x12,
60+
0xC4, 1, 0x20,
61+
0xC6, 1, 0x0F,
62+
0xD0, 2, 0xA4, 0xA1,
63+
// ST7789V gamma setting
64+
0xE0, 14, 0xD0, 0x04, 0x0D, 0x11, 0x13, 0x2B, 0x3F, 0x54, 0x4C, 0x18, 0x0D, 0x0B, 0x1F, 0x23,
65+
0xE1, 14, 0xD0, 0x04, 0x0C, 0x11, 0x13, 0x2C, 0x3F, 0x44, 0x51, 0x2F, 0x1F, 0x1F, 0x20, 0x23,
66+
0x21, 0,
67+
// sleep out
68+
0x11, 0 | DELAY, 255,
69+
// display on
70+
0x29, 0 | DELAY, 255,
71+
};
72+
73+
void board_init(void) {
74+
busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus;
75+
common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, false);
76+
common_hal_busio_spi_never_reset(spi);
77+
78+
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
79+
bus->base.type = &displayio_fourwire_type;
80+
common_hal_displayio_fourwire_construct(bus,
81+
spi,
82+
&pin_GPIO4, // TFT_DC Command or data
83+
&pin_GPIO5, // TFT_CS Chip select
84+
&pin_GPIO8, // TFT_RST Reset
85+
60000000, // Baudrate
86+
0, // Polarity
87+
0); // Phase
88+
89+
displayio_display_obj_t *display = &displays[0].display;
90+
display->base.type = &displayio_display_type;
91+
common_hal_displayio_display_construct(display,
92+
bus,
93+
240, // Width
94+
240, // Height
95+
0, // column start
96+
0, // row start
97+
0, // rotation
98+
16, // Color depth
99+
false, // Grayscale
100+
false, // pixels in a byte share a row. Only valid for depths < 8
101+
1, // bytes per cell. Only valid for depths < 8
102+
false, // reverse_pixels_in_byte. Only valid for depths < 8
103+
true, // reverse_pixels_in_word
104+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
105+
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
106+
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
107+
display_init_sequence,
108+
sizeof(display_init_sequence),
109+
&pin_GPIO9, // backlight pin
110+
NO_BRIGHTNESS_COMMAND,
111+
1.0f, // brightness (ignored)
112+
true, // auto_brightness
113+
false, // single_byte_bounds
114+
false, // data_as_commands
115+
true, // auto_refresh
116+
60, // native_frames_per_second
117+
true, // backlight_on_high
118+
false); // SH1107_addressing
119+
}
120+
121+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
122+
// Override the USB_SEL, LED_GREEN, LED_YELLOW and BOOST_EN pins.
123+
if (pin_number == 18 || pin_number == 15 || pin_number == 16 || pin_number == 13) {
124+
gpio_reset_pin(pin_number);
125+
gpio_pullup_dis(pin_number);
126+
gpio_pulldown_en(pin_number);
127+
return true;
128+
}
129+
return false;
130+
}
131+
132+
bool board_requests_safe_mode(void) {
133+
return false;
134+
}
135+
136+
void reset_board(void) {
137+
138+
}
139+
140+
void board_deinit(void) {
141+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 "ESP32-S3-USB-OTG-N8"
30+
#define MICROPY_HW_MCU_NAME "ESP32S3"
31+
32+
#define MICROPY_HW_LED_STATUS (&pin_GPIO15)
33+
34+
#define DEFAULT_UART_BUS_RX (&pin_GPIO44)
35+
#define DEFAULT_UART_BUS_TX (&pin_GPIO43)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
USB_VID = 0x303A
2+
USB_PID = 0x700B
3+
USB_PRODUCT = "ESP32-S3-USB-OTG-N8"
4+
USB_MANUFACTURER = "Espressif"
5+
6+
IDF_TARGET = esp32s3
7+
8+
INTERNAL_FLASH_FILESYSTEM = 1
9+
LONGINT_IMPL = MPZ
10+
11+
# The default queue depth of 16 overflows on release builds,
12+
# so increase it to 32.
13+
CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32
14+
15+
CIRCUITPY_ESP_FLASH_MODE=dio
16+
CIRCUITPY_ESP_FLASH_FREQ=80m
17+
CIRCUITPY_ESP_FLASH_SIZE=8MB
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include "shared-bindings/board/__init__.h"
2+
3+
// Pin names from:
4+
// https://espressif-docs.readthedocs-hosted.com/projects/espressif-esp-dev-kits/en/latest/esp32s3/esp32-s3-usb-otg/user_guide.html#pin-layout
5+
6+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
7+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
8+
9+
{ MP_ROM_QSTR(MP_QSTR_USB_SEL), MP_ROM_PTR(&pin_GPIO18) },
10+
11+
{ MP_ROM_QSTR(MP_QSTR_LED_GREEN), MP_ROM_PTR(&pin_GPIO15) },
12+
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO15) },
13+
{ MP_ROM_QSTR(MP_QSTR_LED_YELLOW), MP_ROM_PTR(&pin_GPIO16) },
14+
15+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_OK), MP_ROM_PTR(&pin_GPIO0) },
16+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_UP), MP_ROM_PTR(&pin_GPIO10) },
17+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_DW), MP_ROM_PTR(&pin_GPIO11) },
18+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_DOWN), MP_ROM_PTR(&pin_GPIO11) },
19+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_MENU), MP_ROM_PTR(&pin_GPIO14) },
20+
21+
{ MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO8) },
22+
{ MP_ROM_QSTR(MP_QSTR_LCD_EN), MP_ROM_PTR(&pin_GPIO5) },
23+
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO4) },
24+
{ MP_ROM_QSTR(MP_QSTR_LCD_SCLK), MP_ROM_PTR(&pin_GPIO6) },
25+
{ MP_ROM_QSTR(MP_QSTR_LCD_SDA), MP_ROM_PTR(&pin_GPIO7) },
26+
{ MP_ROM_QSTR(MP_QSTR_LCD_BL), MP_ROM_PTR(&pin_GPIO9) },
27+
28+
{ MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO36) },
29+
{ MP_ROM_QSTR(MP_QSTR_SD_D0), MP_ROM_PTR(&pin_GPIO37) },
30+
{ MP_ROM_QSTR(MP_QSTR_SD_D1), MP_ROM_PTR(&pin_GPIO38) },
31+
{ MP_ROM_QSTR(MP_QSTR_SD_D2), MP_ROM_PTR(&pin_GPIO33) },
32+
{ MP_ROM_QSTR(MP_QSTR_SD_D3), MP_ROM_PTR(&pin_GPIO34) },
33+
34+
{ MP_ROM_QSTR(MP_QSTR_HOST_VOL), MP_ROM_PTR(&pin_GPIO1) },
35+
{ MP_ROM_QSTR(MP_QSTR_BAT_VOL), MP_ROM_PTR(&pin_GPIO2) },
36+
{ MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO2) },
37+
{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO2) },
38+
{ MP_ROM_QSTR(MP_QSTR_LIMIT_EN), MP_ROM_PTR(&pin_GPIO17) },
39+
{ MP_ROM_QSTR(MP_QSTR_OVER_CURRENT), MP_ROM_PTR(&pin_GPIO21) },
40+
{ MP_ROM_QSTR(MP_QSTR_DEV_VBUS_EN), MP_ROM_PTR(&pin_GPIO12) },
41+
{ MP_ROM_QSTR(MP_QSTR_BOOST_EN), MP_ROM_PTR(&pin_GPIO13) },
42+
43+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) },
44+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) },
45+
46+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
47+
};
48+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# CONFIG_ESP32S3_SPIRAM_SUPPORT is not set
2+
#
3+
# LWIP
4+
#
5+
CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3"
6+
# end of LWIP

0 commit comments

Comments
 (0)