Skip to content

Commit 444afcf

Browse files
committed
Add support for LILYGO T-Dongle S3.
1 parent e5e7c9e commit 444afcf

File tree

5 files changed

+219
-0
lines changed

5 files changed

+219
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "supervisor/board.h"
8+
#include "mpconfigboard.h"
9+
#include "shared-bindings/microcontroller/Pin.h"
10+
#include "shared-module/displayio/__init__.h"
11+
#include "shared-module/displayio/mipi_constants.h"
12+
13+
#define DELAY 0x80
14+
15+
// display init sequence according to Adafruit_CircuitPython_ST7735R
16+
// https://github.com/adafruit/Adafruit_CircuitPython_ST7735R
17+
uint8_t display_init_sequence[] = {
18+
// sw reset
19+
0x01, 0 | DELAY, 0x96,
20+
// SLPOUT and Delay
21+
0x11, 0 | DELAY, 0xFF,
22+
0xB1, 0x03, 0x01, 0x2C, 0x2D, // _FRMCTR1
23+
0xB3, 0x06, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D, // _FRMCTR3
24+
0xB4, 0x01, 0x07, // _INVCTR line inversion
25+
0xC0, 0x03, 0xA2, 0x02, 0x84, // _PWCTR1 GVDD = 4.7V, 1.0uA
26+
0xC1, 0x01, 0xC5, // _PWCTR2 VGH=14.7V, VGL=-7.35V
27+
0xC2, 0x02, 0x0A, 0x00, // _PWCTR3 Opamp current small, Boost frequency
28+
0xC3, 0x02, 0x8A, 0x2A,
29+
0xC4, 0x02, 0x8A, 0xEE,
30+
0xC5, 0x01, 0x0E, // _VMCTR1 VCOMH = 4V, VOML = -1.1V
31+
0x20, 0x00, // _INVOFF
32+
0x36, 0x01, 0x18, // _MADCTL bottom to top refresh
33+
// 1 clk cycle nonoverlap, 2 cycle gate rise, 3 cycle osc equalie,
34+
// fix on VTL
35+
0x3A, 0x01, 0x05, // COLMOD - 16bit color
36+
0xE0, 0x10, 0x02, 0x1C, 0x07, 0x12, 0x37, 0x32, 0x29, 0x2D, 0x29, 0x25, 0x2B, 0x39, 0x00, 0x01, 0x03, 0x10, // _GMCTRP1 Gamma
37+
0xE1, 0x10, 0x03, 0x1D, 0x07, 0x06, 0x2E, 0x2C, 0x29, 0x2D, 0x2E, 0x2E, 0x37, 0x3F, 0x00, 0x00, 0x02, 0x10, // _GMCTRN1
38+
0x13, 0 | DELAY, 0x0A, // _NORON
39+
0x29, 0 | DELAY, 0x64, // _DISPON
40+
// 0x36, 0x01, 0xC0, // _MADCTL Default rotation plus BGR encoding
41+
0x36, 0x01, 0xC8, // _MADCTL Default rotation plus RGB encoding
42+
0x21, 0x00, // _INVON
43+
};
44+
45+
static void display_init(void) {
46+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
47+
busio_spi_obj_t *spi = &bus->inline_bus;
48+
49+
common_hal_busio_spi_construct(
50+
spi,
51+
&pin_GPIO5, // CLK
52+
&pin_GPIO3, // MOSI
53+
NULL, // MISO not connected
54+
false); // Not half-duplex
55+
56+
common_hal_busio_spi_never_reset(spi);
57+
58+
bus->base.type = &fourwire_fourwire_type;
59+
60+
common_hal_fourwire_fourwire_construct(
61+
bus,
62+
spi,
63+
&pin_GPIO2, // DC
64+
&pin_GPIO4, // CS
65+
&pin_GPIO1, // RST
66+
10000000, // baudrate
67+
0, // polarity
68+
0 // phase
69+
);
70+
71+
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
72+
display->base.type = &busdisplay_busdisplay_type;
73+
74+
common_hal_busdisplay_busdisplay_construct(
75+
display,
76+
bus,
77+
160, // width (after rotation)
78+
80, // height (after rotation)
79+
26, // column start
80+
1, // row start
81+
90, // rotation
82+
16, // color depth
83+
false, // grayscale
84+
false, // pixels in a byte share a row. Only valid for depths < 8
85+
1, // bytes per cell. Only valid for depths < 8
86+
false, // reverse_pixels_in_byte. Only valid for depths < 8
87+
true, // reverse_pixels_in_word
88+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
89+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
90+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
91+
display_init_sequence,
92+
sizeof(display_init_sequence),
93+
&pin_GPIO38, // backlight pin
94+
NO_BRIGHTNESS_COMMAND,
95+
1.0f, // brightness
96+
false, // single_byte_bounds
97+
false, // data_as_commands
98+
true, // auto_refresh
99+
60, // native_frames_per_second
100+
true, // backlight_on_high
101+
false, // SH1107_addressing
102+
50000 // backlight pwm frequency
103+
);
104+
}
105+
106+
void board_init(void) {
107+
// Display
108+
display_init();
109+
}
110+
111+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
// Micropython setup
10+
11+
#define MICROPY_HW_BOARD_NAME "LILYGO T-Dongle S3"
12+
#define MICROPY_HW_MCU_NAME "ESP32S3"
13+
14+
#define DEFAULT_UART_BUS_RX (&pin_GPIO44)
15+
#define DEFAULT_UART_BUS_TX (&pin_GPIO43)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
USB_VID = 0x303a
2+
USB_PID = 0x82C2
3+
USB_PRODUCT = "T-Dongle S3"
4+
USB_MANUFACTURER = "LILYGO"
5+
6+
IDF_TARGET = esp32s3
7+
8+
CIRCUITPY_ESP_FLASH_SIZE = 16MB
9+
CIRCUITPY_ESP_FLASH_MODE = qio
10+
CIRCUITPY_ESP_FLASH_FREQ = 80m
11+
12+
CIRCUITPY_ESP_PSRAM_SIZE = 8MB
13+
CIRCUITPY_ESP_PSRAM_MODE = opi
14+
CIRCUITPY_ESP_PSRAM_FREQ = 80m
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "shared-bindings/board/__init__.h"
8+
#include "shared-module/displayio/__init__.h"
9+
10+
static const mp_rom_map_elem_t board_module_globals_table[] = {
11+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
12+
13+
// 1 to 1 mappings
14+
{ MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) },
15+
{ MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) },
16+
{ MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) },
17+
{ MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) },
18+
{ MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) },
19+
{ MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) },
20+
{ MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) },
21+
{ MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) },
22+
{ MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) },
23+
{ MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) },
24+
{ MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) },
25+
{ MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) },
26+
{ MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) },
27+
{ MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) },
28+
{ MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) },
29+
{ MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) },
30+
{ MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) },
31+
32+
// Reset Button
33+
{ MP_ROM_QSTR(MP_QSTR_BUTTON0), MP_ROM_PTR(&pin_GPIO0) },
34+
35+
// RX and TX
36+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) },
37+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) },
38+
39+
// Stemma port (if available)
40+
{ MP_ROM_QSTR(MP_QSTR_STEMMA_SDA), MP_ROM_PTR(&pin_GPIO43) },
41+
{ MP_ROM_QSTR(MP_QSTR_STEMMA_SCL), MP_ROM_PTR(&pin_GPIO44) },
42+
{ MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) },
43+
44+
// 0.96 inch LCD ST7735
45+
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO2) },
46+
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO4) },
47+
{ MP_ROM_QSTR(MP_QSTR_LCD_CLK), MP_ROM_PTR(&pin_GPIO5) },
48+
{ MP_ROM_QSTR(MP_QSTR_LCD_DIN), MP_ROM_PTR(&pin_GPIO3) },
49+
{ MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO1) },
50+
{ MP_ROM_QSTR(MP_QSTR_LCD_BCKL), MP_ROM_PTR(&pin_GPIO38) },
51+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display) },
52+
53+
// APA102 control pins (Leds)
54+
{ MP_ROM_QSTR(MP_QSTR_APA102_CLK), MP_ROM_PTR(&pin_GPIO39) },
55+
{ MP_ROM_QSTR(MP_QSTR_APA102_DI), MP_ROM_PTR(&pin_GPIO40) },
56+
57+
// SD card control pins
58+
{ MP_ROM_QSTR(MP_QSTR_SD_D0), MP_ROM_PTR(&pin_GPIO14) },
59+
{ MP_ROM_QSTR(MP_QSTR_SD_D1), MP_ROM_PTR(&pin_GPIO17) },
60+
{ MP_ROM_QSTR(MP_QSTR_SD_D2), MP_ROM_PTR(&pin_GPIO21) },
61+
{ MP_ROM_QSTR(MP_QSTR_SD_D3), MP_ROM_PTR(&pin_GPIO18) },
62+
{ MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO12) },
63+
{ MP_ROM_QSTR(MP_QSTR_SD_CMD), MP_ROM_PTR(&pin_GPIO16) },
64+
};
65+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Espressif IoT Development Framework Configuration
3+
#
4+
#
5+
# Component config
6+
#
7+
#
8+
# LWIP
9+
#
10+
# end of LWIP
11+
12+
# end of Component config
13+
14+
# end of Espressif IoT Development Framework Configuration

0 commit comments

Comments
 (0)