mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Add LilyGo T-ETH-Elite support (SX1262 and SX1276)
This commit is contained in:
parent
dee3e26ac0
commit
de00cebbbb
10 changed files with 895 additions and 0 deletions
162
src/helpers/esp32/TEthEliteBoard.cpp
Normal file
162
src/helpers/esp32/TEthEliteBoard.cpp
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
#if defined(T_ETH_ELITE_SX1262) || defined(T_ETH_ELITE_SX1276)
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
#include "driver/spi_common.h"
|
||||
#include "driver/gpio.h"
|
||||
#include <ETHClass2.h>
|
||||
#include "TEthEliteBoard.h"
|
||||
#include "target.h"
|
||||
#include "helpers/ui/MomentaryButton.h"
|
||||
|
||||
extern MomentaryButton user_btn;
|
||||
|
||||
uint32_t deviceOnline = 0x00;
|
||||
static SPIClass spi_eth(FSPI);
|
||||
static ETHClass2 ETH;
|
||||
|
||||
void TEthEliteBoard::begin() {
|
||||
ESP32Board::begin();
|
||||
user_btn.begin();
|
||||
Wire1.begin(PIN_BOARD_SDA1, PIN_BOARD_SCL1);
|
||||
#if ENV_INCLUDE_GPS
|
||||
Serial1.begin(9600, SERIAL_8N1, PIN_GPS_RX, PIN_GPS_TX);
|
||||
#endif
|
||||
|
||||
#ifdef USE_ETHERNET
|
||||
WiFi.mode(WIFI_OFF);
|
||||
#endif
|
||||
startNetwork();
|
||||
|
||||
pinMode(P_LORA_TX_LED, OUTPUT);
|
||||
digitalWrite(P_LORA_TX_LED, LOW);
|
||||
|
||||
esp_reset_reason_t reason = esp_reset_reason();
|
||||
if (reason == ESP_RST_DEEPSLEEP) {
|
||||
#if defined(T_ETH_ELITE_SX1262)
|
||||
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
|
||||
if (wakeup_source & (1 << P_LORA_DIO_1)) {
|
||||
startup_reason = BD_STARTUP_RX_PACKET;
|
||||
}
|
||||
rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
|
||||
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
|
||||
#elif defined(T_ETH_ELITE_SX1276)
|
||||
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
|
||||
if (wakeup_source & (1 << P_LORA_DIO_0)) {
|
||||
startup_reason = BD_STARTUP_RX_PACKET;
|
||||
}
|
||||
rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
|
||||
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MESH_DEBUG
|
||||
void TEthEliteBoard::scanDevices(TwoWire *w)
|
||||
{
|
||||
uint8_t err, addr;
|
||||
int nDevices = 0;
|
||||
|
||||
Serial.println("Scanning I2C for Devices");
|
||||
for (addr = 1; addr < 127; addr++) {
|
||||
w->beginTransmission(addr); delay(2);
|
||||
err = w->endTransmission();
|
||||
if (err == 0) {
|
||||
nDevices++;
|
||||
switch (addr) {
|
||||
case 0x77:
|
||||
case 0x76:
|
||||
Serial.println("\tFound BME280 Sensor");
|
||||
deviceOnline |= BME280_ONLINE;
|
||||
break;
|
||||
case 0x34:
|
||||
Serial.println("\tFound AXP192/AXP2101 PMU");
|
||||
deviceOnline |= POWERMANAGE_ONLINE;
|
||||
break;
|
||||
case 0x3C:
|
||||
Serial.println("\tFound SSD1306/SH1106 display");
|
||||
deviceOnline |= DISPLAY_ONLINE;
|
||||
break;
|
||||
case 0x51:
|
||||
Serial.println("\tFound PCF8563 RTC");
|
||||
deviceOnline |= PCF8563_ONLINE;
|
||||
break;
|
||||
case 0x1C:
|
||||
Serial.println("\tFound QMC6310 MAG Sensor");
|
||||
deviceOnline |= QMC6310_ONLINE;
|
||||
break;
|
||||
default:
|
||||
Serial.printf("\tI2C device found at address 0x%02X\n", addr);
|
||||
break;
|
||||
}
|
||||
} else if (err == 4) {
|
||||
Serial.printf("Unknown error at address 0x%02X\n", addr);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found");
|
||||
|
||||
Serial.println("Scan complete.");
|
||||
Serial.printf("GPS RX pin: %d, GPS TX pin: %d\n", PIN_GPS_RX, PIN_GPS_TX);
|
||||
}
|
||||
|
||||
void TEthEliteBoard::printPMU()
|
||||
{
|
||||
Serial.print("isCharging:"); Serial.println(PMU->isCharging() ? "YES" : "NO");
|
||||
Serial.print("isDischarge:"); Serial.println(PMU->isDischarge() ? "YES" : "NO");
|
||||
Serial.print("isVbusIn:"); Serial.println(PMU->isVbusIn() ? "YES" : "NO");
|
||||
Serial.print("getBattVoltage:"); Serial.print(PMU->getBattVoltage()); Serial.println("mV");
|
||||
Serial.print("getVbusVoltage:"); Serial.print(PMU->getVbusVoltage()); Serial.println("mV");
|
||||
Serial.print("getSystemVoltage:"); Serial.print(PMU->getSystemVoltage()); Serial.println("mV");
|
||||
if (PMU->isBatteryConnect()) {
|
||||
Serial.print("getBatteryPercent:"); Serial.print(PMU->getBatteryPercent()); Serial.println("%");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void TEthEliteBoard::startNetwork() {
|
||||
#ifdef USE_ETHERNET
|
||||
startEthernet();
|
||||
#elif defined(WIFI_SSID)
|
||||
startWifi();
|
||||
#endif
|
||||
}
|
||||
|
||||
void TEthEliteBoard::startEthernet() {
|
||||
pinMode(ETH_CS, OUTPUT);
|
||||
digitalWrite(ETH_CS, HIGH);
|
||||
|
||||
ETH.begin(ETH_PHY_W5500, ETH_ADDR, ETH_CS, ETH_INT, -1, SPI2_HOST, ETH_SCLK, ETH_MISO, ETH_MOSI);
|
||||
delay(100);
|
||||
|
||||
#ifdef ETH_STATIC_IP
|
||||
IPAddress ip(ETH_STATIC_IP);
|
||||
IPAddress gw(ETH_GATEWAY);
|
||||
IPAddress mask(ETH_SUBNET);
|
||||
IPAddress dns(ETH_DNS);
|
||||
ETH.config(ip, gw, mask, dns);
|
||||
#endif
|
||||
|
||||
unsigned long t0 = millis();
|
||||
while (!ETH.linkUp() && millis() - t0 < 5000) {
|
||||
delay(100);
|
||||
}
|
||||
|
||||
t0 = millis();
|
||||
while (ETH.localIP() == IPAddress(0, 0, 0, 0) && millis() - t0 < 5000) {
|
||||
delay(100);
|
||||
}
|
||||
|
||||
if (ETH.localIP() == IPAddress(0, 0, 0, 0)) {
|
||||
Serial.println("DHCP timeout, using fallback IP");
|
||||
ETH.config(IPAddress(192, 168, 4, 2), IPAddress(192, 168, 4, 1), IPAddress(255, 255, 255, 0));
|
||||
}
|
||||
|
||||
uint8_t mac[6];
|
||||
ETH.macAddress(mac);
|
||||
Serial.printf("ETH MAC %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
Serial.print("ETH IP "); Serial.println(ETH.localIP());
|
||||
Serial.println(ETH.linkUp() ? "ETH LINK UP" : "ETH LINK DOWN");
|
||||
}
|
||||
|
||||
#endif
|
||||
7
src/helpers/esp32/TEthEliteBoard.h
Normal file
7
src/helpers/esp32/TEthEliteBoard.h
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#if defined(T_ETH_ELITE_SX1262)
|
||||
#include "TEthEliteBoard_SX1262.h"
|
||||
#elif defined(T_ETH_ELITE_SX1276)
|
||||
#include "TEthEliteBoard_SX1276.h"
|
||||
#endif
|
||||
102
src/helpers/esp32/TEthEliteBoard_SX1262.h
Normal file
102
src/helpers/esp32/TEthEliteBoard_SX1262.h
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
#pragma once
|
||||
|
||||
#if defined(T_ETH_ELITE_SX1262)
|
||||
|
||||
// Define pin mappings BEFORE including ESP32Board.h so sleep() can use P_LORA_DIO_1
|
||||
|
||||
// LoRa SX1262 pins (T-ETH Elite LoRa Shield)
|
||||
#define P_LORA_NSS 40 // CS
|
||||
#define P_LORA_RESET 46 // RESET
|
||||
#define P_LORA_BUSY 16 // BUSY
|
||||
#define P_LORA_DIO_0 -1 // NC
|
||||
#define P_LORA_DIO_1 8 // IRQ
|
||||
#define P_LORA_TX_LED 38
|
||||
#define P_LORA_SCLK 10
|
||||
#define P_LORA_MISO 9
|
||||
#define P_LORA_MOSI 11
|
||||
|
||||
// ETH W5500 pins (T-ETH Elite main board)
|
||||
#define ETH_MISO 47
|
||||
#define ETH_MOSI 21
|
||||
#define ETH_SCLK 48
|
||||
#define ETH_CS 45
|
||||
#define ETH_INT 14
|
||||
#define ETH_RST -1
|
||||
#define ETH_ADDR 1
|
||||
|
||||
// I2C bus (Wire1)
|
||||
#define PIN_BOARD_SDA1 17
|
||||
#define PIN_BOARD_SCL1 18
|
||||
|
||||
// GPS pins (LoRa Shield)
|
||||
#define PIN_GPS_RX 39
|
||||
#define PIN_GPS_TX 42
|
||||
#define PIN_GPS_EN -1
|
||||
|
||||
// Analog button
|
||||
#define PIN_USER_BTN_ANA 7
|
||||
|
||||
// Include headers AFTER pin definitions so ESP32Board::sleep() can use P_LORA_DIO_1
|
||||
#include <Wire.h>
|
||||
#include <Arduino.h>
|
||||
#include "XPowersLib.h"
|
||||
#include "helpers/ESP32Board.h"
|
||||
#include <driver/rtc_io.h>
|
||||
|
||||
class TEthEliteBoard : public ESP32Board {
|
||||
XPowersLibInterface *PMU = NULL;
|
||||
|
||||
enum {
|
||||
POWERMANAGE_ONLINE = _BV(0),
|
||||
DISPLAY_ONLINE = _BV(1),
|
||||
RADIO_ONLINE = _BV(2),
|
||||
GPS_ONLINE = _BV(3),
|
||||
PSRAM_ONLINE = _BV(4),
|
||||
SDCARD_ONLINE = _BV(5),
|
||||
AXDL345_ONLINE = _BV(6),
|
||||
BME280_ONLINE = _BV(7),
|
||||
BMP280_ONLINE = _BV(8),
|
||||
BME680_ONLINE = _BV(9),
|
||||
QMC6310_ONLINE = _BV(10),
|
||||
QMI8658_ONLINE = _BV(11),
|
||||
PCF8563_ONLINE = _BV(12),
|
||||
OSC32768_ONLINE = _BV(13),
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
#ifdef MESH_DEBUG
|
||||
void printPMU();
|
||||
void scanDevices(TwoWire *w);
|
||||
#endif
|
||||
void begin();
|
||||
void startNetwork();
|
||||
void startEthernet();
|
||||
void startWifi();
|
||||
|
||||
void enterDeepSleep(uint32_t secs, int pin_wake_btn) {
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
|
||||
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);
|
||||
} else {
|
||||
esp_sleep_enable_ext1_wakeup((1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH);
|
||||
}
|
||||
|
||||
if (secs > 0) {
|
||||
esp_sleep_enable_timer_wakeup(secs * 1000000);
|
||||
}
|
||||
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
uint16_t getBattMilliVolts() { return 0; }
|
||||
|
||||
const char* getManufacturerName() const { return "LilyGo T-ETH-Elite"; }
|
||||
};
|
||||
|
||||
#endif
|
||||
102
src/helpers/esp32/TEthEliteBoard_SX1276.h
Normal file
102
src/helpers/esp32/TEthEliteBoard_SX1276.h
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
#pragma once
|
||||
|
||||
#if defined(T_ETH_ELITE_SX1276)
|
||||
|
||||
// Define pin mappings BEFORE including ESP32Board.h so sleep() can use P_LORA_DIO_0
|
||||
|
||||
// LoRa SX1276 pins (T-ETH Elite LoRa Shield)
|
||||
#define P_LORA_DIO_0 8 // IRQ (DIO0 on SX1276)
|
||||
#define P_LORA_DIO_1 16 // DIO1
|
||||
#define P_LORA_NSS 40 // CS
|
||||
#define P_LORA_RESET 46 // RESET
|
||||
#define P_LORA_BUSY -1 // SX1276 has no BUSY pin
|
||||
#define P_LORA_TX_LED 38
|
||||
#define P_LORA_SCLK 10
|
||||
#define P_LORA_MISO 9
|
||||
#define P_LORA_MOSI 11
|
||||
|
||||
// ETH W5500 pins (T-ETH Elite main board)
|
||||
#define ETH_MISO 47
|
||||
#define ETH_MOSI 21
|
||||
#define ETH_SCLK 48
|
||||
#define ETH_CS 45
|
||||
#define ETH_INT 14
|
||||
#define ETH_RST -1
|
||||
#define ETH_ADDR 1
|
||||
|
||||
// I2C bus (Wire1)
|
||||
#define PIN_BOARD_SDA1 17
|
||||
#define PIN_BOARD_SCL1 18
|
||||
|
||||
// GPS pins (LoRa Shield)
|
||||
#define PIN_GPS_RX 39
|
||||
#define PIN_GPS_TX 42
|
||||
#define PIN_GPS_EN -1
|
||||
|
||||
// Analog button
|
||||
#define PIN_USER_BTN_ANA 7
|
||||
|
||||
// Include headers AFTER pin definitions so ESP32Board::sleep() can use P_LORA_DIO_0
|
||||
#include <Wire.h>
|
||||
#include <Arduino.h>
|
||||
#include "XPowersLib.h"
|
||||
#include "helpers/ESP32Board.h"
|
||||
#include <driver/rtc_io.h>
|
||||
|
||||
class TEthEliteBoard : public ESP32Board {
|
||||
XPowersLibInterface *PMU = NULL;
|
||||
|
||||
enum {
|
||||
POWERMANAGE_ONLINE = _BV(0),
|
||||
DISPLAY_ONLINE = _BV(1),
|
||||
RADIO_ONLINE = _BV(2),
|
||||
GPS_ONLINE = _BV(3),
|
||||
PSRAM_ONLINE = _BV(4),
|
||||
SDCARD_ONLINE = _BV(5),
|
||||
AXDL345_ONLINE = _BV(6),
|
||||
BME280_ONLINE = _BV(7),
|
||||
BMP280_ONLINE = _BV(8),
|
||||
BME680_ONLINE = _BV(9),
|
||||
QMC6310_ONLINE = _BV(10),
|
||||
QMI8658_ONLINE = _BV(11),
|
||||
PCF8563_ONLINE = _BV(12),
|
||||
OSC32768_ONLINE = _BV(13),
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
#ifdef MESH_DEBUG
|
||||
void printPMU();
|
||||
void scanDevices(TwoWire *w);
|
||||
#endif
|
||||
void begin();
|
||||
void startNetwork();
|
||||
void startEthernet();
|
||||
void startWifi();
|
||||
|
||||
void enterDeepSleep(uint32_t secs, int pin_wake_btn) {
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
|
||||
rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_0, RTC_GPIO_MODE_INPUT_ONLY);
|
||||
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_0);
|
||||
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
|
||||
|
||||
if (pin_wake_btn < 0) {
|
||||
esp_sleep_enable_ext1_wakeup((1L << P_LORA_DIO_0), ESP_EXT1_WAKEUP_ANY_HIGH);
|
||||
} else {
|
||||
esp_sleep_enable_ext1_wakeup((1L << P_LORA_DIO_0) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH);
|
||||
}
|
||||
|
||||
if (secs > 0) {
|
||||
esp_sleep_enable_timer_wakeup(secs * 1000000);
|
||||
}
|
||||
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
uint16_t getBattMilliVolts() { return 0; }
|
||||
|
||||
const char* getManufacturerName() const { return "LilyGo T-ETH-Elite"; }
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue