Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions boards/t-connect-pro.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"build": {
"arduino": {
"ldscript": "esp32s3_out.ld",
"partitions": "default_16MB.csv",
"memory_type": "qio_opi"
},
"core": "esp32",
"extra_flags": [
"-DARDUINO_USB_MODE=1",
"-DARDUINO_RUNNING_CORE=1",
"-DARDUINO_EVENT_RUNNING_CORE=1"
],
"f_cpu": "240000000L",
"f_flash": "80000000L",
"flash_mode": "qio",
"hwids": [["0x303A", "0x1001"]],
"mcu": "esp32s3",
"variant": "esp32s3"
},
"connectivity": ["wifi", "bluetooth"],
"debug": {
"default_tool": "esp-builtin",
"onboard_tools": ["esp-builtin"],
"openocd_target": "esp32s3.cfg"
},
"frameworks": ["arduino", "espidf"],
"name": "LilyGo T-Connect Pro (16M Flash 8M PSRAM)",
"upload": {
"flash_size": "16MB",
"maximum_ram_size": 327680,
"maximum_size": 16777216,
"require_upload_port": true,
"speed": 921600
},
"url": "https://www.lilygo.cc",
"vendor": "LilyGo"
}
170 changes: 170 additions & 0 deletions src/helpers/ui/ST7796LCDDisplay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#include "ST7796LCDDisplay.h"

#ifndef DISPLAY_ROTATION
#define DISPLAY_ROTATION 3
#endif

#ifndef DISPLAY_SCALE_X
#define DISPLAY_SCALE_X 2.5f // 320 / 128
#endif

#ifndef DISPLAY_SCALE_Y
#define DISPLAY_SCALE_Y 3.75f // 240 / 64
#endif

#ifndef DISPLAY_WIDTH
#define DISPLAY_WIDTH 222
#endif

#ifndef DISPLAY_HEIGHT
#define DISPLAY_HEIGHT 480
#endif


bool ST7796LCDDisplay::i2c_probe(TwoWire& wire, uint8_t addr) {
return true;
}

bool ST7796LCDDisplay::begin() {
if (!_isOn) {
if (_peripher_power) _peripher_power->claim();

if (PIN_TFT_LEDA_CTL != -1) {
pinMode(PIN_TFT_LEDA_CTL, OUTPUT);
digitalWrite(PIN_TFT_LEDA_CTL, HIGH);
}
if (PIN_TFT_RST != -1) {
pinMode(PIN_TFT_RST, OUTPUT);
digitalWrite(PIN_TFT_RST, LOW);
delay(10);
digitalWrite(PIN_TFT_RST, HIGH);
}

display.init(DISPLAY_WIDTH, DISPLAY_HEIGHT, 0, 49, ST7796S_BGR); // width, height, row offset, column offset, colour mode
display.setRotation(DISPLAY_ROTATION);

display.setSPISpeed(40e6);

display.fillScreen(ST77XX_BLACK);
display.setTextColor(ST77XX_WHITE);
display.setTextSize(2 * DISPLAY_SCALE_X);
display.cp437(true); // Use full 256 char 'Code Page 437' font

_isOn = true;
}

return true;
}

void ST7796LCDDisplay::turnOn() {
ST7796LCDDisplay::begin();
}

void ST7796LCDDisplay::turnOff() {
if (_isOn) {
if (PIN_TFT_LEDA_CTL != -1) {
digitalWrite(PIN_TFT_LEDA_CTL, HIGH);
}
if (PIN_TFT_RST != -1) {
digitalWrite(PIN_TFT_RST, LOW);
}
if (PIN_TFT_LEDA_CTL != -1) {
digitalWrite(PIN_TFT_LEDA_CTL, LOW);
}
_isOn = false;

if (_peripher_power) _peripher_power->release();
}
}

void ST7796LCDDisplay::clear() {
display.fillScreen(ST77XX_BLACK);
}

void ST7796LCDDisplay::startFrame(Color bkg) {
display.fillScreen(ST77XX_BLACK);
display.setTextColor(ST77XX_WHITE);
display.setTextSize(1 * DISPLAY_SCALE_X); // This one affects size of Please wait... message
display.cp437(true); // Use full 256 char 'Code Page 437' font
}

void ST7796LCDDisplay::setTextSize(int sz) {
display.setTextSize(sz * DISPLAY_SCALE_X);
}

void ST7796LCDDisplay::setColor(Color c) {
switch (c) {
case DisplayDriver::DARK :
_color = ST77XX_BLACK;
break;
case DisplayDriver::LIGHT :
_color = ST77XX_WHITE;
break;
case DisplayDriver::RED :
_color = ST77XX_RED;
break;
case DisplayDriver::GREEN :
_color = ST77XX_GREEN;
break;
case DisplayDriver::BLUE :
_color = ST77XX_BLUE;
break;
case DisplayDriver::YELLOW :
_color = ST77XX_YELLOW;
break;
case DisplayDriver::ORANGE :
_color = ST77XX_ORANGE;
break;
default:
_color = ST77XX_WHITE;
break;
}
display.setTextColor(_color);
}

void ST7796LCDDisplay::setCursor(int x, int y) {
display.setCursor(x * DISPLAY_SCALE_X, y * DISPLAY_SCALE_Y);
}

void ST7796LCDDisplay::print(const char* str) {
display.print(str);
}

void ST7796LCDDisplay::fillRect(int x, int y, int w, int h) {
display.fillRect(x * DISPLAY_SCALE_X, y * DISPLAY_SCALE_Y, w * DISPLAY_SCALE_X, h * DISPLAY_SCALE_Y, _color);
}

void ST7796LCDDisplay::drawRect(int x, int y, int w, int h) {
display.drawRect(x * DISPLAY_SCALE_X, y * DISPLAY_SCALE_Y, w * DISPLAY_SCALE_X, h * DISPLAY_SCALE_Y, _color);
}

void ST7796LCDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
uint8_t byteWidth = (w + 7) / 8;

for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
uint8_t byte = bits[j * byteWidth + i / 8];
bool pixelOn = byte & (0x80 >> (i & 7));

if (pixelOn) {
for (int dy = 0; dy < DISPLAY_SCALE_X; dy++) {
for (int dx = 0; dx < DISPLAY_SCALE_X; dx++) {
display.drawPixel(x * DISPLAY_SCALE_X + i * DISPLAY_SCALE_X + dx, y * DISPLAY_SCALE_Y + j * DISPLAY_SCALE_X + dy, _color);
}
}
}
}
}
}

uint16_t ST7796LCDDisplay::getTextWidth(const char* str) {
int16_t x1, y1;
uint16_t w, h;
display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h);

return w / DISPLAY_SCALE_X;
}

void ST7796LCDDisplay::endFrame() {
// display.display();
}
49 changes: 49 additions & 0 deletions src/helpers/ui/ST7796LCDDisplay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#include "DisplayDriver.h"
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7796S.h>
#include <helpers/RefCountedDigitalPin.h>

class ST7796LCDDisplay : public DisplayDriver {
Adafruit_ST7796S display;
bool _isOn;
uint16_t _color;
RefCountedDigitalPin* _peripher_power;

bool i2c_probe(TwoWire& wire, uint8_t addr);
public:
#ifdef USE_PIN_TFT
ST7796LCDDisplay(RefCountedDigitalPin* peripher_power=NULL) : DisplayDriver(128, 64),
display(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_SDA, PIN_TFT_SCL, PIN_TFT_RST),
_peripher_power(peripher_power)
{
_isOn = false;
}
#else
ST7796LCDDisplay(RefCountedDigitalPin* peripher_power=NULL) : DisplayDriver(128, 64),
display(&SPI, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST),
_peripher_power(peripher_power)
{
_isOn = false;
}
#endif
bool begin();

bool isOn() override { return _isOn; }
void turnOn() override;
void turnOff() override;
void clear() override;
void startFrame(Color bkg = DARK) override;
void setTextSize(int sz) override;
void setColor(Color c) override;
void setCursor(int x, int y) override;
void print(const char* str) override;
void fillRect(int x, int y, int w, int h) override;
void drawRect(int x, int y, int w, int h) override;
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
uint16_t getTextWidth(const char* str) override;
void endFrame() override;
};
31 changes: 31 additions & 0 deletions variants/lilygo_tconnect_pro/TConnectProBoard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <Arduino.h>
#include "TConnectProBoard.h"

uint32_t deviceOnline = 0x00;

void TConnectProBoard::begin() {

ESP32Board::begin();

// Configure user button
pinMode(PIN_USER_BTN, INPUT);

// Configure LoRa Pins
pinMode(P_LORA_MISO, INPUT_PULLUP);
// pinMode(P_LORA_DIO_1, INPUT_PULLUP);

#ifdef P_LORA_TX_LED
digitalWrite(P_LORA_TX_LED, HIGH); // inverted pin for SX1276 - HIGH for off
#endif

esp_reset_reason_t reason = esp_reset_reason();
if (reason == ESP_RST_DEEPSLEEP) {
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
if (wakeup_source & (1 << P_LORA_DIO_1)) {
startup_reason = BD_STARTUP_RX_PACKET; // received a LoRa packet (while in deep sleep)
}

rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
}
}
49 changes: 49 additions & 0 deletions variants/lilygo_tconnect_pro/TConnectProBoard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#include <Wire.h>
#include <Arduino.h>
#include "helpers/ESP32Board.h"
#include <driver/rtc_io.h>


class TConnectProBoard : public ESP32Board {
public:
void begin();

#ifdef P_LORA_TX_LED
void onBeforeTransmit() override{
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED on - invert pin for SX1276
}

void onAfterTransmit() override{
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED off - invert pin for SX1276
}
#endif

void enterDeepSleep(uint32_t secs, int pin_wake_btn) {
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);

// Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep
rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);

rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);

if (pin_wake_btn < 0) {
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
} else {
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn
}

if (secs > 0) {
esp_sleep_enable_timer_wakeup(secs * 1000000);
}

// Finally set ESP32 into sleep
esp_deep_sleep_start(); // CPU halts here and never returns!
}

const char* getManufacturerName() const{
return "LilyGo T-Connect-Pro";
}
};
Loading