Skip to content

Commit 4b1d1fd

Browse files
authored
Merge pull request #6768 from mayrhomar/main
Add Waveshare ESP32-S2-Pico-LCD
2 parents 3fbddfd + 528da05 commit 4b1d1fd

File tree

5 files changed

+327
-0
lines changed

5 files changed

+327
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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+
#include "shared-module/displayio/__init__.h"
31+
#include "shared-module/displayio/mipi_constants.h"
32+
33+
#define DELAY 0x80
34+
35+
36+
// display init sequence according to Adafruit_CircuitPython_ST7735R
37+
// https://github.com/adafruit/Adafruit_CircuitPython_ST7735R
38+
uint8_t display_init_sequence[] = {
39+
// sw reset
40+
0x01, 0 | DELAY, 0x96,
41+
// SLPOUT and Delay
42+
0x11, 0 | DELAY, 0xFF,
43+
0xB1, 0x03, 0x01, 0x2C, 0x2D, // _FRMCTR1
44+
0xB3, 0x06, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D, // _FRMCTR3
45+
0xB4, 0x01, 0x07, // _INVCTR line inversion
46+
0xC0, 0x03, 0xA2, 0x02, 0x84, // _PWCTR1 GVDD = 4.7V, 1.0uA
47+
0xC1, 0x01, 0xC5, // _PWCTR2 VGH=14.7V, VGL=-7.35V
48+
0xC2, 0x02, 0x0A, 0x00, // _PWCTR3 Opamp current small, Boost frequency
49+
0xC3, 0x02, 0x8A, 0x2A,
50+
0xC4, 0x02, 0x8A, 0xEE,
51+
0xC5, 0x01, 0x0E, // _VMCTR1 VCOMH = 4V, VOML = -1.1V
52+
0x20, 0x00, // _INVOFF
53+
0x36, 0x01, 0x18, // _MADCTL bottom to top refresh
54+
// 1 clk cycle nonoverlap, 2 cycle gate rise, 3 sycle osc equalie,
55+
// fix on VTL
56+
0x3A, 0x01, 0x05, // COLMOD - 16bit color
57+
0xE0, 0x10, 0x02, 0x1C, 0x07, 0x12, 0x37, 0x32, 0x29, 0x2D, 0x29, 0x25, 0x2B, 0x39, 0x00, 0x01, 0x03, 0x10, // _GMCTRP1 Gamma
58+
0xE1, 0x10, 0x03, 0x1D, 0x07, 0x06, 0x2E, 0x2C, 0x29, 0x2D, 0x2E, 0x2E, 0x37, 0x3F, 0x00, 0x00, 0x02, 0x10, // _GMCTRN1
59+
0x13, 0 | DELAY, 0x0A, // _NORON
60+
0x29, 0 | DELAY, 0x64, // _DISPON
61+
// 0x36, 0x01, 0xC0, // _MADCTL Default rotation plus BGR encoding
62+
0x36, 0x01, 0xC8, // _MADCTL Default rotation plus RGB encoding
63+
0x21, 0x00, // _INVON
64+
};
65+
66+
static void display_init(void) {
67+
busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus;
68+
69+
common_hal_busio_spi_construct(
70+
spi,
71+
&pin_GPIO10, // CLK
72+
&pin_GPIO11, // MOSI
73+
NULL, // MISO not connected
74+
false); // Not half-duplex
75+
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+
81+
common_hal_displayio_fourwire_construct(
82+
bus,
83+
spi,
84+
&pin_GPIO18, // DC
85+
&pin_GPIO9, // CS
86+
&pin_GPIO21, // RST
87+
40000000, // baudrate
88+
0, // polarity
89+
0 // phase
90+
);
91+
92+
displayio_display_obj_t *display = &displays[0].display;
93+
display->base.type = &displayio_display_type;
94+
95+
// workaround as board_init() is called before reset_port() in main.c
96+
pwmout_reset();
97+
98+
common_hal_displayio_display_construct(
99+
display,
100+
bus,
101+
160, // width (after rotation)
102+
80, // height (after rotation)
103+
26, // column start
104+
1, // row start
105+
90, // rotation
106+
16, // color depth
107+
false, // grayscale
108+
false, // pixels in a byte share a row. Only valid for depths < 8
109+
1, // bytes per cell. Only valid for depths < 8
110+
false, // reverse_pixels_in_byte. Only valid for depths < 8
111+
true, // reverse_pixels_in_word
112+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
113+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
114+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
115+
display_init_sequence,
116+
sizeof(display_init_sequence),
117+
&pin_GPIO45, // backlight pin
118+
NO_BRIGHTNESS_COMMAND,
119+
1.0f, // brightness
120+
false, // single_byte_bounds
121+
false, // data_as_commands
122+
true, // auto_refresh
123+
60, // native_frames_per_second
124+
true, // backlight_on_high
125+
false, // SH1107_addressing
126+
50000 // backlight pwm frequency
127+
);
128+
129+
common_hal_never_reset_pin(&pin_GPIO45); // backlight pin
130+
}
131+
132+
133+
void board_init(void) {
134+
// Debug UART
135+
#ifdef DEBUG
136+
common_hal_never_reset_pin(&pin_GPIO43);
137+
common_hal_never_reset_pin(&pin_GPIO44);
138+
#endif /* DEBUG */
139+
140+
// Display
141+
display_init();
142+
}
143+
144+
bool board_requests_safe_mode(void) {
145+
return false;
146+
}
147+
148+
void reset_board(void) {
149+
150+
}
151+
152+
void board_deinit(void) {
153+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 "Waveshare ESP32-S2-Pico-LCD"
30+
#define MICROPY_HW_MCU_NAME "ESP32S2"
31+
32+
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO41)
33+
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO40)
34+
35+
#define DEFAULT_SPI_BUS_SCK (&pin_GPIO10)
36+
#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO11)
37+
#define DEFAULT_SPI_BUS_MISO (&pin_GPIO12)
38+
39+
#define DEFAULT_UART_BUS_RX (&pin_GPIO44)
40+
#define DEFAULT_UART_BUS_TX (&pin_GPIO43)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
USB_VID = 0x303a
2+
USB_PID = 0x810c
3+
4+
USB_PRODUCT = "ESP32-S2-Pico-LCD"
5+
USB_MANUFACTURER = "Waveshare Electronics"
6+
7+
IDF_TARGET = esp32s2
8+
9+
INTERNAL_FLASH_FILESYSTEM = 1
10+
LONGINT_IMPL = MPZ
11+
12+
# The default queue depth of 16 overflows on release builds,
13+
# so increase it to 32.
14+
CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32
15+
16+
CIRCUITPY_ESP_FLASH_MODE=dio
17+
CIRCUITPY_ESP_FLASH_FREQ=80m
18+
CIRCUITPY_ESP_FLASH_SIZE=4MB
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include "shared-bindings/board/__init__.h"
2+
#include "shared-module/displayio/__init__.h"
3+
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_BUTTON), MP_ROM_PTR(&pin_GPIO0) },
9+
{ MP_ROM_QSTR(MP_QSTR_BOOT0), MP_ROM_PTR(&pin_GPIO0) },
10+
{ MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) },
11+
12+
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO1) },
13+
{ MP_ROM_QSTR(MP_QSTR_USB_IN), MP_ROM_PTR(&pin_GPIO1) },
14+
{ MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) },
15+
{ MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) },
16+
{ MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) },
17+
{ MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO5) },
18+
19+
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO6) },
20+
{ MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) },
21+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO7) },
22+
{ MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) },
23+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO8) },
24+
{ MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO8) },
25+
26+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO10) },
27+
{ MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO10) },
28+
29+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO11) },
30+
{ MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO11) },
31+
32+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO12) },
33+
{ MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) },
34+
35+
{ MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_GPIO13) },
36+
{ MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) },
37+
38+
{ MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) },
39+
{ MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) },
40+
{ MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) },
41+
{ MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) },
42+
43+
{ MP_ROM_QSTR(MP_QSTR_GP34), MP_ROM_PTR(&pin_GPIO34) },
44+
{ MP_ROM_QSTR(MP_QSTR_GP35), MP_ROM_PTR(&pin_GPIO35) },
45+
{ MP_ROM_QSTR(MP_QSTR_GP36), MP_ROM_PTR(&pin_GPIO36) },
46+
{ MP_ROM_QSTR(MP_QSTR_GP37), MP_ROM_PTR(&pin_GPIO37) },
47+
{ MP_ROM_QSTR(MP_QSTR_GP38), MP_ROM_PTR(&pin_GPIO38) },
48+
{ MP_ROM_QSTR(MP_QSTR_GP39), MP_ROM_PTR(&pin_GPIO39) },
49+
50+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO40) },
51+
{ MP_ROM_QSTR(MP_QSTR_GP40), MP_ROM_PTR(&pin_GPIO40) },
52+
53+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO41) },
54+
{ MP_ROM_QSTR(MP_QSTR_GP41), MP_ROM_PTR(&pin_GPIO41) },
55+
56+
{ MP_ROM_QSTR(MP_QSTR_GP42), MP_ROM_PTR(&pin_GPIO42) },
57+
58+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) },
59+
{ MP_ROM_QSTR(MP_QSTR_GP43), MP_ROM_PTR(&pin_GPIO43) },
60+
61+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) },
62+
{ MP_ROM_QSTR(MP_QSTR_GP44), MP_ROM_PTR(&pin_GPIO44) },
63+
64+
// 0.96 inch LCD ST7735s
65+
{ MP_ROM_QSTR(MP_QSTR_LCD_MOSI), MP_ROM_PTR(&pin_GPIO11) },
66+
{ MP_ROM_QSTR(MP_QSTR_LCD_CLK), MP_ROM_PTR(&pin_GPIO10) },
67+
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO9) },
68+
{ MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO21) },
69+
{ MP_ROM_QSTR(MP_QSTR_LCD_BACKLIGHT), MP_ROM_PTR(&pin_GPIO45) },
70+
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO18) },
71+
72+
{ MP_ROM_QSTR(MP_QSTR_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+
};
79+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
CONFIG_ESP32S2_SPIRAM_SUPPORT=y
2+
#
3+
# SPI RAM config
4+
#
5+
# CONFIG_SPIRAM_TYPE_AUTO is not set
6+
# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set
7+
# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set
8+
CONFIG_SPIRAM_TYPE_ESPPSRAM64=y
9+
CONFIG_SPIRAM_SIZE=8388608
10+
# end of SPI RAM config
11+
12+
CONFIG_DEFAULT_PSRAM_CLK_IO=30
13+
#
14+
# PSRAM clock and cs IO for ESP32S2
15+
#
16+
CONFIG_DEFAULT_PSRAM_CS_IO=26
17+
# end of PSRAM clock and cs IO for ESP32S2
18+
19+
# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set
20+
# CONFIG_SPIRAM_RODATA is not set
21+
CONFIG_SPIRAM_SPEED_80M=y
22+
# CONFIG_SPIRAM_SPEED_40M is not set
23+
# CONFIG_SPIRAM_SPEED_26M is not set
24+
# CONFIG_SPIRAM_SPEED_20M is not set
25+
CONFIG_SPIRAM=y
26+
CONFIG_SPIRAM_BOOT_INIT=y
27+
# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set
28+
CONFIG_SPIRAM_USE_MEMMAP=y
29+
# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set
30+
# CONFIG_SPIRAM_USE_MALLOC is not set
31+
CONFIG_SPIRAM_MEMTEST=y
32+
# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set
33+
#
34+
# LWIP
35+
#
36+
CONFIG_LWIP_LOCAL_HOSTNAME="waveshare"
37+
# end of LWIP

0 commit comments

Comments
 (0)