Skip to content

Commit b75d99c

Browse files
authored
Merge pull request #7745 from Neradoc/lilygo-twatch-v3-MAIN
Add Lilygo T-Watch 2020 V3 (ESP32)
2 parents 3ac696e + f1b7612 commit b75d99c

File tree

5 files changed

+298
-0
lines changed

5 files changed

+298
-0
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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 for ST7789 (works in python)
36+
uint8_t display_init_sequence[] = {
37+
// sw reset
38+
0x01, 0 | DELAY, 0x96,
39+
// sleep out
40+
0x11, 0 | DELAY, 0xFF,
41+
0x3A, 1 | DELAY, 0x55, 10,
42+
0x36, 1, 0x08,
43+
0x21, 0 | DELAY, 10,
44+
0x13, 0 | DELAY, 10,
45+
0x36, 1, 0xC0,
46+
// display on
47+
0x29, 0 | DELAY, 255,
48+
};
49+
50+
static void display_init(void) {
51+
busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus;
52+
53+
common_hal_busio_spi_construct(
54+
spi,
55+
&pin_GPIO18, // CLK
56+
&pin_GPIO19, // MOSI
57+
NULL, // MISO not connected
58+
false // Not half-duplex
59+
);
60+
61+
common_hal_busio_spi_never_reset(spi);
62+
63+
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
64+
bus->base.type = &displayio_fourwire_type;
65+
66+
common_hal_displayio_fourwire_construct(
67+
bus,
68+
spi,
69+
&pin_GPIO27, // DC
70+
&pin_GPIO5, // CS
71+
NULL, // RST
72+
24000000, // baudrate
73+
0, // polarity
74+
0 // phase
75+
);
76+
77+
displayio_display_obj_t *display = &displays[0].display;
78+
display->base.type = &displayio_display_type;
79+
80+
common_hal_displayio_display_construct(
81+
display,
82+
bus,
83+
240, // width (after rotation)
84+
240, // height (after rotation)
85+
0, // column start
86+
80, // row start
87+
0, // rotation
88+
16, // color depth
89+
false, // grayscale
90+
false, // pixels in a byte share a row. Only valid for depths < 8
91+
1, // bytes per cell. Only valid for depths < 8
92+
false, // reverse_pixels_in_byte. Only valid for depths < 8
93+
true, // reverse_pixels_in_word
94+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
95+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
96+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
97+
display_init_sequence,
98+
sizeof(display_init_sequence),
99+
&pin_GPIO15, // backlight pin
100+
NO_BRIGHTNESS_COMMAND,
101+
1.0f, // brightness
102+
false, // single_byte_bounds
103+
false, // data_as_commands
104+
true, // auto_refresh
105+
60, // native_frames_per_second
106+
true, // backlight_on_high
107+
false, // SH1107_addressing
108+
5000 // backlight pwm frequency
109+
);
110+
}
111+
112+
/*
113+
#define APX202_ADDRESS (0x35)
114+
#define AXP202_LDO2 (2)
115+
#define AXP202_ON (1)
116+
#define AXP202_OFF (0)
117+
#define AXP202_DCDC3 (1)
118+
#define AXP202_IC_TYPE (0x03)
119+
#define AXP202_LDO234_DC23_CTL (0x12)
120+
#define AXP_PASS (1)
121+
#define AXP_FAIL (-1)
122+
#define AXP202_CHIP_ID (0x41)
123+
#define AXP192_CHIP_ID (0x03)
124+
#define FORCED_OPEN_DCDC3(x) (x |= (AXP202_ON << AXP202_DCDC3))
125+
126+
static void backlight_init(void) {
127+
// Turn LDO2 on for display
128+
busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0);
129+
uint8_t data = 0;
130+
uint8_t outputReg = 0;
131+
uint8_t read = 0;
132+
// lock
133+
// _readByte(AXP202_LDO234_DC23_CTL, 1, &outputReg)
134+
// time.sleep(0.001)
135+
// _readByte(AXP202_LDO234_DC23_CTL, 1, &data)
136+
// time.sleep(0.001)
137+
// data |= 1 << AXP202_LDO2
138+
// FORCED_OPEN_DCDC3(data)
139+
// _writeByte(AXP202_LDO234_DC23_CTL, 1, &data)
140+
// time.sleep(0.001)
141+
// unlock
142+
}
143+
*/
144+
145+
void board_init(void) {
146+
// Display
147+
display_init();
148+
// backlight_init();
149+
}
150+
151+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
152+
if (pin_number == MOTOR_PIN) {
153+
// no motor
154+
gpio_set_direction(pin_number, GPIO_MODE_DEF_OUTPUT);
155+
gpio_set_level(pin_number, false);
156+
return true;
157+
}
158+
return false;
159+
}
160+
161+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2022 Dan Halbert 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 T-watch 2020 V3"
30+
#define MICROPY_HW_MCU_NAME "ESP32"
31+
32+
#define MOTOR_PIN (4)
33+
#define MICROPY_HW_LED_STATUS (&pin_GPIO4)
34+
35+
#define CIRCUITPY_BOARD_I2C (2)
36+
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO22, .sda = &pin_GPIO21}, \
37+
{.scl = &pin_GPIO32, .sda = &pin_GPIO23}}
38+
39+
#define CIRCUITPY_BOARD_SPI (1)
40+
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO18, .mosi = &pin_GPIO19, .miso = NULL}}
41+
42+
// UART pins attached to the USB-serial converter chip
43+
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1)
44+
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO3)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CIRCUITPY_CREATOR_ID = 0xC3C30000
2+
CIRCUITPY_CREATION_ID = 0x00320001
3+
4+
IDF_TARGET = esp32
5+
6+
CIRCUITPY_ESP_FLASH_MODE = dio
7+
CIRCUITPY_ESP_FLASH_FREQ = 80m
8+
CIRCUITPY_ESP_FLASH_SIZE = 16MB
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "shared-bindings/board/__init__.h"
2+
#include "shared-module/displayio/__init__.h"
3+
4+
CIRCUITPY_BOARD_BUS_SINGLETON(touch_i2c, i2c, 1)
5+
6+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
7+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
8+
9+
// buzz buzz
10+
{ MP_ROM_QSTR(MP_QSTR_VIBRATE), MP_ROM_PTR(&pin_GPIO4) },
11+
12+
// I2S out
13+
{ MP_ROM_QSTR(MP_QSTR_I2S_SCK), MP_ROM_PTR(&pin_GPIO26) },
14+
{ MP_ROM_QSTR(MP_QSTR_I2S_WS), MP_ROM_PTR(&pin_GPIO25) },
15+
{ MP_ROM_QSTR(MP_QSTR_I2S_OUT), MP_ROM_PTR(&pin_GPIO33) },
16+
17+
// PDM in
18+
{ MP_ROM_QSTR(MP_QSTR_PDM_CLK), MP_ROM_PTR(&pin_GPIO0) },
19+
{ MP_ROM_QSTR(MP_QSTR_PDM_DATA), MP_ROM_PTR(&pin_GPIO2) },
20+
21+
// IR send
22+
{ MP_ROM_QSTR(MP_QSTR_IR_LED), MP_ROM_PTR(&pin_GPIO13) },
23+
24+
// main I2C port, for the AXP202, and 2 others
25+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO22) },
26+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO21) },
27+
28+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
29+
30+
// interrupt pins for sensors
31+
{ MP_ROM_QSTR(MP_QSTR_BMA423_INT), MP_ROM_PTR(&pin_GPIO39) },
32+
{ MP_ROM_QSTR(MP_QSTR_PCF8563_INT), MP_ROM_PTR(&pin_GPIO37) },
33+
{ MP_ROM_QSTR(MP_QSTR_AXP202_INT), MP_ROM_PTR(&pin_GPIO35) },
34+
35+
// I2C port for the FT6336 touch sensor
36+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_SCL), MP_ROM_PTR(&pin_GPIO32) },
37+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_SDA), MP_ROM_PTR(&pin_GPIO23) },
38+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_RST), MP_ROM_PTR(&pin_GPIO14) },
39+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_INT), MP_ROM_PTR(&pin_GPIO38) },
40+
41+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_I2C), MP_ROM_PTR(&board_touch_i2c_obj) },
42+
43+
// LCD display
44+
{ MP_ROM_QSTR(MP_QSTR_LCD_CLK), MP_ROM_PTR(&pin_GPIO18) },
45+
{ MP_ROM_QSTR(MP_QSTR_LCD_MOSI), MP_ROM_PTR(&pin_GPIO19) },
46+
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO27) },
47+
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO5) },
48+
{ MP_ROM_QSTR(MP_QSTR_LCD_BRIGHTNESS), MP_ROM_PTR(&pin_GPIO15) },
49+
50+
{ MP_ROM_QSTR(MP_QSTR_LCD_SPI), MP_ROM_PTR(&board_spi_obj) },
51+
52+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
53+
};
54+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPI RAM config
2+
#
3+
CONFIG_ESP32_SPIRAM_SUPPORT=y
4+
CONFIG_SPIRAM_MODE_OCT=y
5+
CONFIG_SPIRAM_TYPE_ESPPSRAM64=y
6+
CONFIG_SPIRAM_SIZE=8388608
7+
CONFIG_SPIRAM_SPEED_80M=y
8+
CONFIG_SPIRAM=y
9+
CONFIG_SPIRAM_BOOT_INIT=y
10+
# CONFIG_SPIRAM_IGNORE_NOTFOUND=y
11+
CONFIG_SPIRAM_USE_MEMMAP=y
12+
CONFIG_SPIRAM_MEMTEST=y
13+
CONFIG_SPIRAM_CACHE_WORKAROUND=y
14+
15+
# Uncomment (remove ###) to send ESP_LOG output to TX/RX pins
16+
#
17+
# ESP System Settings
18+
#
19+
CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y
20+
# CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT is not set
21+
CONFIG_ESP_CONSOLE_UART_CUSTOM=y
22+
# CONFIG_ESP_CONSOLE_NONE is not set
23+
CONFIG_ESP_CONSOLE_UART=y
24+
CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_0=y
25+
# CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_1 is not set
26+
CONFIG_ESP_CONSOLE_UART_NUM=0
27+
CONFIG_ESP_CONSOLE_UART_TX_GPIO=1
28+
CONFIG_ESP_CONSOLE_UART_RX_GPIO=3
29+
CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200
30+
# CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_5 is not set
31+
# end of ESP System Settings

0 commit comments

Comments
 (0)