Skip to content

Commit 0b21755

Browse files
committed
initial commit
1 parent c978768 commit 0b21755

File tree

5 files changed

+323
-0
lines changed

5 files changed

+323
-0
lines changed
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
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+
/* All init code scraped from Adafruit_GC9A01A driver */
36+
#define GC9A01A_SWRESET 0x01 ///< Software Reset (maybe, not documented)
37+
#define GC9A01A_INREGEN1 0xFE ///< Inter register enable 1
38+
#define GC9A01A_INREGEN2 0xEF ///< Inter register enable 2
39+
#define GC9A01A_MADCTL 0x36 ///< Memory Access Control
40+
#define GC9A01A_COLMOD 0x3A ///< Pixel Format Set
41+
#define GC9A01A1_POWER2 0xC3 ///< Power Control 2
42+
#define GC9A01A1_POWER3 0xC4 ///< Power Control 3
43+
#define GC9A01A1_POWER4 0xC9 ///< Power Control 4
44+
#define GC9A01A_GAMMA1 0xF0 ///< Set gamma 1
45+
#define GC9A01A_GAMMA2 0xF1 ///< Set gamma 2
46+
#define GC9A01A_GAMMA3 0xF2 ///< Set gamma 3
47+
#define GC9A01A_GAMMA4 0xF3 ///< Set gamma 4
48+
#define GC9A01A_TEON 0x35 ///< Tearing Effect Line ON
49+
#define GC9A01A_INVON 0x21 ///< Display Inversion ON
50+
#define GC9A01A_SLPOUT 0x11 ///< Sleep Out
51+
#define GC9A01A_DISPON 0x29 ///< Display ON
52+
#define GC9A01A_FRAMERATE 0xE8 ///< Frame rate control
53+
54+
#define MADCTL_MX 0x40 ///< Right to left
55+
#define MADCTL_BGR 0x08 ///< Blue-Green-Red pixel order
56+
57+
uint8_t display_init_sequence[] = {
58+
GC9A01A_SWRESET, DELAY, 150,
59+
GC9A01A_INREGEN2, 0,
60+
0xEB, 1, 0x14,
61+
GC9A01A_INREGEN1, 0,
62+
GC9A01A_INREGEN2, 0,
63+
0xEB, 1, 0x14,
64+
0x84, 1, 0x40,
65+
0x85, 1, 0xFF,
66+
0x86, 1, 0xFF,
67+
0x87, 1, 0xFF,
68+
0x88, 1, 0x0A,
69+
0x89, 1, 0x21,
70+
0x8A, 1, 0x00,
71+
0x8B, 1, 0x80,
72+
0x8C, 1, 0x01,
73+
0x8D, 1, 0x01,
74+
0x8E, 1, 0xFF,
75+
0x8F, 1, 0xFF,
76+
0xB6, 2, 0x00, 0x00,
77+
GC9A01A_MADCTL, 1, MADCTL_MX | MADCTL_BGR,
78+
GC9A01A_COLMOD, 1, 0x05,
79+
0x90, 4, 0x08, 0x08, 0x08, 0x08,
80+
0xBD, 1, 0x06,
81+
0xBC, 1, 0x00,
82+
0xFF, 3, 0x60, 0x01, 0x04,
83+
GC9A01A1_POWER2, 1, 0x13,
84+
GC9A01A1_POWER3, 1, 0x13,
85+
GC9A01A1_POWER4, 1, 0x22,
86+
0xBE, 1, 0x11,
87+
0xE1, 2, 0x10, 0x0E,
88+
0xDF, 3, 0x21, 0x0c, 0x02,
89+
GC9A01A_GAMMA1, 6, 0x45, 0x09, 0x08, 0x08, 0x26, 0x2A,
90+
GC9A01A_GAMMA2, 6, 0x43, 0x70, 0x72, 0x36, 0x37, 0x6F,
91+
GC9A01A_GAMMA3, 6, 0x45, 0x09, 0x08, 0x08, 0x26, 0x2A,
92+
GC9A01A_GAMMA4, 6, 0x43, 0x70, 0x72, 0x36, 0x37, 0x6F,
93+
0xED, 2, 0x1B, 0x0B,
94+
0xAE, 1, 0x77,
95+
0xCD, 1, 0x63,
96+
// Unsure what this line (from manufacturer's boilerplate code) is
97+
// meant to do, but users reported issues, seems to work OK without:
98+
// 0x70, 9, 0x07, 0x07, 0x04, 0x0E, 0x0F, 0x09, 0x07, 0x08, 0x03, // ?
99+
GC9A01A_FRAMERATE, 1, 0x34,
100+
0x62, 12, 0x18, 0x0D, 0x71, 0xED, 0x70, 0x70, 0x18, 0x0F, 0x71, 0xEF, 0x70, 0x70,
101+
0x63, 12, 0x18, 0x11, 0x71, 0xF1, 0x70, 0x70, 0x18, 0x13, 0x71, 0xF3, 0x70, 0x70,
102+
0x64, 7, 0x28, 0x29, 0xF1, 0x01, 0xF1, 0x00, 0x07,
103+
0x66, 10, 0x3C, 0x00, 0xCD, 0x67, 0x45, 0x45, 0x10, 0x00, 0x00, 0x00,
104+
0x67, 10, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x01, 0x54, 0x10, 0x32, 0x98,
105+
0x74, 7, 0x10, 0x85, 0x80, 0x00, 0x00, 0x4E, 0x00,
106+
0x98, 2, 0x3e, 0x07,
107+
GC9A01A_TEON, 0,
108+
GC9A01A_INVON, 0,
109+
GC9A01A_SLPOUT, DELAY, 10, // Exit sleep
110+
GC9A01A_DISPON, DELAY, 150, // Display on
111+
};
112+
113+
static void display_init(void) {
114+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
115+
busio_spi_obj_t *spi = &bus->inline_bus;
116+
common_hal_busio_spi_construct(
117+
spi,
118+
&pin_GPIO10, // CLK
119+
&pin_GPIO11, // MOSI
120+
NULL, // MISO not connected
121+
false // Not half-duplex
122+
);
123+
common_hal_busio_spi_never_reset(spi);
124+
bus->base.type = &fourwire_fourwire_type;
125+
common_hal_fourwire_fourwire_construct(
126+
bus,
127+
spi,
128+
&pin_GPIO8, // DC
129+
&pin_GPIO9, // CS
130+
&pin_GPIO12, // RST
131+
80000000, // baudrate
132+
0, // polarity
133+
0 // phase
134+
);
135+
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
136+
display->base.type = &busdisplay_busdisplay_type;
137+
common_hal_busdisplay_busdisplay_construct(
138+
display,
139+
bus,
140+
240, // width (after rotation)
141+
240, // height (after rotation)
142+
0, // column start
143+
0, // row start
144+
0, // rotation
145+
16, // color depth
146+
false, // grayscale
147+
false, // pixels in a byte share a row. Only valid for depths < 8
148+
1, // bytes per cell. Only valid for depths < 8
149+
false, // reverse_pixels_in_byte. Only valid for depths < 8
150+
true, // reverse_pixels_in_word
151+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
152+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
153+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
154+
display_init_sequence,
155+
sizeof(display_init_sequence),
156+
&pin_GPIO40, // backlight pin
157+
NO_BRIGHTNESS_COMMAND,
158+
1.0f, // brightness
159+
false, // single_byte_bounds
160+
false, // data_as_commands
161+
true, // auto_refresh
162+
60, // native_frames_per_second
163+
true, // backlight_on_high
164+
false, // SH1107_addressing
165+
5000 // backlight pwm frequency
166+
);
167+
}
168+
169+
void board_init(void) {
170+
// Display
171+
display_init();
172+
}
173+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 ESP32S3 LCD 1.28"
30+
#define MICROPY_HW_MCU_NAME "ESP32S3"
31+
32+
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO6)
33+
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO7)
34+
35+
#define DEFAULT_SPI_BUS_SCK (&pin_GPIO10)
36+
#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO11)
37+
#define DEFAULT_SPI_BUS_MISO (&pin_GPIO13)
38+
39+
#define DEFAULT_UART_BUS_RX (&pin_GPIO44)
40+
#define DEFAULT_UART_BUS_TX (&pin_GPIO43)
41+
42+
#define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX
43+
#define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CIRCUITPY_CREATOR_ID = 0x1BBB0000
2+
CIRCUITPY_CREATION_ID = 0x00AB0001
3+
4+
# This board doesn't have USB by default, it
5+
# instead uses a CH340C USB-to-Serial chip
6+
CIRCUITPY_USB = 0
7+
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0
8+
9+
IDF_TARGET = esp32s3
10+
11+
# This flash lives outside the module.
12+
CIRCUITPY_ESP_FLASH_MODE = qio
13+
CIRCUITPY_ESP_FLASH_FREQ = 80m
14+
CIRCUITPY_ESP_FLASH_SIZE = 16MB
15+
16+
CIRCUITPY_ESP_PSRAM_SIZE = 2MB
17+
CIRCUITPY_ESP_PSRAM_MODE = qio
18+
CIRCUITPY_ESP_PSRAM_FREQ = 80m
19+
20+
INTERNAL_FLASH_FILESYSTEM = 0
21+
QSPI_FLASH_FILESYSTEM = 1
22+
EXTERNAL_FLASH_DEVICES = W25Q128JVxQ
23+
24+
CIRCUITPY_ESPCAMERA = 0
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include "shared-bindings/board/__init__.h"
2+
#include "shared-module/displayio/__init__.h"
3+
4+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
5+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
6+
7+
// User accessible GPIO
8+
{ MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) },
9+
{ MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) },
10+
{ MP_ROM_QSTR(MP_QSTR_IO34), MP_ROM_PTR(&pin_GPIO34) },
11+
{ MP_ROM_QSTR(MP_QSTR_IO33), MP_ROM_PTR(&pin_GPIO33) },
12+
{ MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) },
13+
{ MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) },
14+
{ MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) },
15+
{ MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) },
16+
{ MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) },
17+
{ MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) },
18+
{ MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) },
19+
{ MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) },
20+
{ MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) },
21+
{ MP_ROM_QSTR(MP_QSTR_IO41), MP_ROM_PTR(&pin_GPIO41) },
22+
{ MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) },
23+
{ MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) },
24+
{ MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) },
25+
{ MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) },
26+
{ MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) },
27+
{ MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) },
28+
{ MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) },
29+
{ MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) },
30+
{ MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) },
31+
32+
// User button
33+
{ MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO0) },
34+
{ MP_ROM_QSTR(MP_QSTR_BUTTON0), MP_ROM_PTR(&pin_GPIO0) },
35+
36+
// Battery ADC
37+
{ MP_ROM_QSTR(MP_QSTR_BAT_ADC), MP_ROM_PTR(&pin_GPIO1) },
38+
39+
// I2C
40+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO7) },
41+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO6) },
42+
43+
// SPI
44+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO10) },
45+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO11) },
46+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO13) },
47+
48+
// LCD
49+
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO8) },
50+
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO9) },
51+
{ MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO12) },
52+
{ MP_ROM_QSTR(MP_QSTR_LCD_BACKLIGHT), MP_ROM_PTR(&pin_GPIO40) },
53+
54+
// QMI8658C IMU
55+
{ MP_ROM_QSTR(MP_QSTR_IMU_INT1), MP_ROM_PTR(&pin_GPIO47) },
56+
{ MP_ROM_QSTR(MP_QSTR_IMU_INT2), MP_ROM_PTR(&pin_GPIO48) },
57+
58+
// UART
59+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) },
60+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) },
61+
62+
// Objects
63+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
64+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
65+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
66+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)},
67+
};
68+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Espressif IoT Development Framework Configuration
3+
#
4+
#
5+
# Component config
6+
#
7+
#
8+
# LWIP
9+
#
10+
CONFIG_LWIP_LOCAL_HOSTNAME="waveshare-esp32-s3-lcd-1-28"
11+
# end of LWIP
12+
13+
# end of Component config
14+
15+
# end of Espressif IoT Development Framework Configuration

0 commit comments

Comments
 (0)