Skip to content

Commit 6bdf06c

Browse files
authored
Merge pull request #8787 from kreier/lilygo_ttgo_tdisplay_esp32_4m
Add support for Lilygo TTGO T-Display ESP32 with 4Mbyte flash chip
2 parents 2a766c8 + 662c168 commit 6bdf06c

File tree

5 files changed

+215
-0
lines changed

5 files changed

+215
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
// display init sequence according to LilyGO example app
36+
uint8_t display_init_sequence[] = {
37+
0x01, DELAY, 0x96, // _SWRESET and Delay 150ms
38+
0x11, DELAY, 0xFF, // _SLPOUT and Delay 500ms
39+
0x3A, DELAY | 1, 0x55, 0x0A, // _COLMOD and Delay 10ms
40+
0x21, DELAY, 0x0A, // _INVON Hack and Delay 10ms
41+
0x13, DELAY, 0x0A, // _NORON and Delay 10ms
42+
0x36, 0x01, 0x60, // _MADCTL
43+
0x29, DELAY, 0xFF, // _DISPON and Delay 500ms
44+
};
45+
46+
static void display_init(void) {
47+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
48+
busio_spi_obj_t *spi = &bus->inline_bus;
49+
50+
common_hal_busio_spi_construct(
51+
spi,
52+
&pin_GPIO18, // CLK
53+
&pin_GPIO19, // MOSI
54+
NULL, // MISO not connected
55+
false); // Not half-duplex
56+
57+
common_hal_busio_spi_never_reset(spi);
58+
59+
bus->base.type = &fourwire_fourwire_type;
60+
61+
common_hal_fourwire_fourwire_construct(
62+
bus,
63+
spi,
64+
&pin_GPIO16, // DC
65+
&pin_GPIO5, // CS
66+
&pin_GPIO23, // RST
67+
24000000, // baudrate (default from the driver)
68+
// 40000000,
69+
0, // polarity
70+
0 // phase
71+
);
72+
73+
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
74+
display->base.type = &busdisplay_busdisplay_type;
75+
76+
common_hal_busdisplay_busdisplay_construct(
77+
display,
78+
bus,
79+
240, // width (after rotation)
80+
135, // height (after rotation)
81+
40, // column start
82+
53, // row start
83+
0, // rotation
84+
16, // color depth
85+
false, // grayscale
86+
false, // pixels in a byte share a row. Only valid for depths < 8
87+
1, // bytes per cell. Only valid for depths < 8
88+
false, // reverse_pixels_in_byte. Only valid for depths < 8
89+
true, // reverse_pixels_in_word
90+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
91+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
92+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
93+
display_init_sequence,
94+
sizeof(display_init_sequence),
95+
&pin_GPIO4, // backlight pin
96+
NO_BRIGHTNESS_COMMAND,
97+
1.0f, // brightness
98+
false, // single_byte_bounds
99+
false, // data_as_commands
100+
true, // auto_refresh
101+
60, // native_frames_per_second
102+
true, // backlight_on_high
103+
false, // SH1107_addressing
104+
50000 // backlight pwm frequency
105+
);
106+
}
107+
108+
void board_init(void) {
109+
// Display
110+
display_init();
111+
}
112+
113+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 "LILYGO TTGO T-DISPLAY v1.1 4M"
30+
#define MICROPY_HW_MCU_NAME "ESP32"
31+
32+
// UART pins attached to the USB-serial converter chip
33+
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1)
34+
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO3)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CIRCUITPY_CREATOR_ID = 0xC3C30000
2+
CIRCUITPY_CREATION_ID = 0x00320004
3+
4+
IDF_TARGET = esp32
5+
6+
CIRCUITPY_ESP_FLASH_MODE = qio
7+
CIRCUITPY_ESP_FLASH_FREQ = 80m
8+
CIRCUITPY_ESP_FLASH_SIZE = 4MB
9+
10+
CIRCUITPY_ESPCAMERA = 0
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
{ MP_ROM_QSTR(MP_QSTR_BUTTON0), MP_ROM_PTR(&pin_GPIO0) },
8+
{ MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) },
9+
10+
{ MP_ROM_QSTR(MP_QSTR_BUTTON1), MP_ROM_PTR(&pin_GPIO35) },
11+
{ MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) },
12+
13+
{ MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) },
14+
{ MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) },
15+
{ MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) },
16+
{ MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) },
17+
{ MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) },
18+
{ MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) },
19+
{ MP_ROM_QSTR(MP_QSTR_IO22), MP_ROM_PTR(&pin_GPIO22) },
20+
{ MP_ROM_QSTR(MP_QSTR_IO25), MP_ROM_PTR(&pin_GPIO25) },
21+
{ MP_ROM_QSTR(MP_QSTR_IO26), MP_ROM_PTR(&pin_GPIO26) },
22+
{ MP_ROM_QSTR(MP_QSTR_IO27), MP_ROM_PTR(&pin_GPIO27) },
23+
24+
{ MP_ROM_QSTR(MP_QSTR_IO32), MP_ROM_PTR(&pin_GPIO32) },
25+
{ MP_ROM_QSTR(MP_QSTR_IO33), MP_ROM_PTR(&pin_GPIO33) },
26+
{ MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) },
27+
{ MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) },
28+
{ MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) },
29+
{ MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) },
30+
31+
// 1.14 inch LCD ST7789
32+
{ MP_ROM_QSTR(MP_QSTR_LCD_MOSI), MP_ROM_PTR(&pin_GPIO19) },
33+
{ MP_ROM_QSTR(MP_QSTR_LCD_CLK), MP_ROM_PTR(&pin_GPIO18) },
34+
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO5) },
35+
{ MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO23) },
36+
{ MP_ROM_QSTR(MP_QSTR_LCD_BCKL), MP_ROM_PTR(&pin_GPIO4) },
37+
{ MP_ROM_QSTR(MP_QSTR_LCD_D_C), MP_ROM_PTR(&pin_GPIO16) },
38+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display) },
39+
40+
// Battery Sense
41+
{ MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO34) },
42+
};
43+
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="TTGO-TDISPLAY"
11+
# end of LWIP
12+
13+
# end of Component config
14+
15+
# end of Espressif IoT Development Framework Configuration

0 commit comments

Comments
 (0)