Skip to content

Commit

Permalink
Merge pull request #9480 from bill88t/tws3
Browse files Browse the repository at this point in the history
LILYGO T-Watch-S3
  • Loading branch information
tannewt authored Aug 12, 2024
2 parents 69ae421 + 9b98039 commit f064354
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,15 @@
[submodule "frozen/Adafruit_CircuitPython_LED_Animation"]
path = frozen/Adafruit_CircuitPython_LED_Animation
url = https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation
[submodule "frozen/CircuitPython_AXP2101"]
path = frozen/CircuitPython_AXP2101
url = https://github.com/CDarius/CircuitPython_AXP2101
[submodule "frozen/CircuitPython_BMA423"]
path = frozen/CircuitPython_BMA423
url = https://github.com/jposada202020/CircuitPython_BMA423
[submodule "frozen/Adafruit_CircuitPython_PCF8563"]
path = frozen/Adafruit_CircuitPython_PCF8563
url = https://github.com/adafruit/Adafruit_CircuitPython_PCF8563
[submodule "frozen/Adafruit_CircuitPython_Wiznet5k"]
path = frozen/Adafruit_CircuitPython_Wiznet5k
url = https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k
1 change: 1 addition & 0 deletions frozen/Adafruit_CircuitPython_PCF8563
1 change: 1 addition & 0 deletions frozen/CircuitPython_AXP2101
Submodule CircuitPython_AXP2101 added at f89fc3
1 change: 1 addition & 0 deletions frozen/CircuitPython_BMA423
Submodule CircuitPython_BMA423 added at d6446c
104 changes: 104 additions & 0 deletions ports/espressif/boards/lilygo_twatch_s3/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2024 Bill Sideris, independently providing these changes
//
// SPDX-License-Identifier: MIT

#include "supervisor/board.h"
#include "mpconfigboard.h"
#include "shared-bindings/busio/SPI.h"
#include "shared-bindings/fourwire/FourWire.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-module/displayio/__init__.h"
#include "shared-module/displayio/mipi_constants.h"
#include "shared-bindings/board/__init__.h"


#define DELAY 0x80

// Display init sequence according to LILYGO factory firmware
uint8_t display_init_sequence[] = {
// sw reset
0x01, 0 | DELAY, 150,
// sleep out
0x11, 0 | DELAY, 255,
// normal display mode on
0x13, 0,
// display and color format settings
0x36, 1, 0x68,
0xB6, 2, 0x0A, 0x82,
0x3A, 1 | DELAY, 0x55, 10,
// ST7789V frame rate setting
0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33,
// voltages: VGH / VGL
0xB7, 1, 0x35,
// ST7789V power setting
0xBB, 1, 0x28,
0xC0, 1, 0x0C,
0xC2, 2, 0x01, 0xFF,
0xC3, 1, 0x10,
0xC4, 1, 0x20,
0xC6, 1, 0x0F,
0xD0, 2, 0xA4, 0xA1,
// ST7789V gamma setting
0xE0, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x32, 0x44, 0x42, 0x06, 0x0E, 0x12, 0x14, 0x17,
0xE1, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x31, 0x54, 0x47, 0x0E, 0x1C, 0x17, 0x1B, 0x1E,
0x21, 0,
// display on
0x29, 0 | DELAY, 255,
};


void board_init(void) {
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
bus->base.type = &fourwire_fourwire_type;

common_hal_fourwire_fourwire_construct(
bus,
spi,
&pin_GPIO38, // DC
&pin_GPIO12, // CS
NULL, // RST
40000000, // baudrate
0, // polarity
0 // phase
);
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
display->base.type = &busdisplay_busdisplay_type;

common_hal_busdisplay_busdisplay_construct(
display,
bus,
240, // width (after rotation)
240, // height (after rotation)
0, // column start
0, // row start
90, // rotation
16, // color depth
false, // grayscale
false, // pixels in a byte share a row. Only valid for depths < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
display_init_sequence,
sizeof(display_init_sequence),
&pin_GPIO45, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true, // backlight_on_high
false, // SH1107_addressing
50000 // backlight pwm frequency
);
}

// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

// TODO: Should we turn off the display when asleep, in board_deinit() ?
23 changes: 23 additions & 0 deletions ports/espressif/boards/lilygo_twatch_s3/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2024 Bill Sideris, independently providing these changes
//
// SPDX-License-Identifier: MIT

#pragma once

// Micropython setup

#define MICROPY_HW_BOARD_NAME "LILYGO T-Watch-S3"
#define MICROPY_HW_MCU_NAME "ESP32S3"

#define CIRCUITPY_BOARD_I2C (2)
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO11, .sda = &pin_GPIO10}, \
{.scl = &pin_GPIO40, .sda = &pin_GPIO39}}

#define CIRCUITPY_BOARD_SPI (2)
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO18, .mosi = &pin_GPIO13}, \
{.clock = &pin_GPIO3, .mosi = &pin_GPIO1, .miso = &pin_GPIO4}}
// LCD then LORA

#define DOUBLE_TAP_PIN (&pin_GPIO21)
34 changes: 34 additions & 0 deletions ports/espressif/boards/lilygo_twatch_s3/mpconfigboard.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
USB_VID = 0x303A
USB_PID = 0x821C

USB_PRODUCT = "T-Watch-S3"
USB_MANUFACTURER = "LILYGO"

IDF_TARGET = esp32s3

CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 16MB

CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_PARALLELDISPLAYBUS = 0
CIRCUITPY_MAX3421E = 0
CIRCUITPY_CANIO = 0
CIRCUITPY_COUNTIO = 0
CIRCUITPY_PS2IO = 0
CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_ROTARYIO = 0

CIRCUITPY_ESP_PSRAM_SIZE = 8MB
CIRCUITPY_ESP_PSRAM_MODE = opi
CIRCUITPY_ESP_PSRAM_FREQ = 80m

# Include these Python libraries in firmware.
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_FocalTouch
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_IRRemote
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Register
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_DRV2605
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_PCF8563
FROZEN_MPY_DIRS += $(TOP)/frozen/CircuitPython_AXP2101
FROZEN_MPY_DIRS += $(TOP)/frozen/CircuitPython_BMA423
# FROZEN_MPY_DIRS += $(TOP)/frozen/CircuitPython_SX126X # To be added in the future
71 changes: 71 additions & 0 deletions ports/espressif/boards/lilygo_twatch_s3/pins.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2024 Bill Sideris, independently providing these changes
//
// SPDX-License-Identifier: MIT

#include "shared-bindings/board/__init__.h"
#include "shared-module/displayio/__init__.h"

CIRCUITPY_BOARD_BUS_SINGLETON(tft_spi, spi, 0)
CIRCUITPY_BOARD_BUS_SINGLETON(radio_spi, spi, 1)
CIRCUITPY_BOARD_BUS_SINGLETON(touch_i2c, i2c, 1)

static const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS

// DISPLAY
{ MP_ROM_QSTR(MP_QSTR_TFT_MOSI), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_TFT_SCLK), MP_ROM_PTR(&pin_GPIO18) },
{ MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO38) },
{ MP_ROM_QSTR(MP_QSTR_TFT_BL), MP_ROM_PTR(&pin_GPIO45) },
{ MP_ROM_QSTR(MP_QSTR_TFT_SPI), MP_ROM_PTR(&board_tft_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)},

// TOUCH
{ MP_ROM_QSTR(MP_QSTR_TOUCH_INT), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_SCL), MP_ROM_PTR(&pin_GPIO40) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_SDA), MP_ROM_PTR(&pin_GPIO39) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_I2C), MP_ROM_PTR(&board_touch_i2c_obj) },

// RTC
{ MP_ROM_QSTR(MP_QSTR_RTC_INT), MP_ROM_PTR(&pin_GPIO17) },

// IR
{ MP_ROM_QSTR(MP_QSTR_IR_LED), MP_ROM_PTR(&pin_GPIO2) },

// AXP2101 PMU
{ MP_ROM_QSTR(MP_QSTR_PMU_INT), MP_ROM_PTR(&pin_GPIO21) },

// RADIO
{ MP_ROM_QSTR(MP_QSTR_RADIO_SCK), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_RADIO_MISO), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_RADIO_MOSI), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_RADIO_SS), MP_ROM_PTR(&pin_GPIO5) },
{ MP_ROM_QSTR(MP_QSTR_RADIO_DIO1), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_RADIO_RST), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_RADIO_BUSY), MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_RADIO_SPI), MP_ROM_PTR(&board_radio_spi_obj) },

// MIC
{ MP_ROM_QSTR(MP_QSTR_MIC_DATA), MP_ROM_PTR(&pin_GPIO47) },
{ MP_ROM_QSTR(MP_QSTR_MIC_SCLK), MP_ROM_PTR(&pin_GPIO44) },

// MAX98357A SPK
{ MP_ROM_QSTR(MP_QSTR_I2S_BCK), MP_ROM_PTR(&pin_GPIO48) },
{ MP_ROM_QSTR(MP_QSTR_I2S_WS), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_I2S_DOUT), MP_ROM_PTR(&pin_GPIO46) },

// BMA423 AXIS SENSOR
{ MP_ROM_QSTR(MP_QSTR_AXIS_INT), MP_ROM_PTR(&pin_GPIO14) },

// I2C, AXP2101, BMA423, RTC, DRV2605
{ MP_ROM_QSTR(MP_QSTR_I2C_SCL), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_I2C_SDA), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },

// MISC
{ MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO0) }
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
15 changes: 15 additions & 0 deletions ports/espressif/boards/lilygo_twatch_s3/sdkconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Espressif IoT Development Framework Configuration
#
#
# Component config
#
#
# LWIP
#
CONFIG_LWIP_LOCAL_HOSTNAME="t-watch-s3"
# end of LWIP

# end of Component config

# end of Espressif IoT Development Framework Configuration

0 comments on commit f064354

Please sign in to comment.