Skip to content

Commit b11f084

Browse files
add T-Echo-Lite Device Variant
1 parent db40a9c commit b11f084

File tree

7 files changed

+529
-0
lines changed

7 files changed

+529
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include <Arduino.h>
2+
#include "TechoBoard.h"
3+
4+
#ifdef LILYGO_TECHO
5+
6+
#include <bluefruit.h>
7+
#include <Wire.h>
8+
9+
static BLEDfu bledfu;
10+
11+
static void connect_callback(uint16_t conn_handle) {
12+
(void)conn_handle;
13+
MESH_DEBUG_PRINTLN("BLE client connected");
14+
}
15+
16+
static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
17+
(void)conn_handle;
18+
(void)reason;
19+
20+
MESH_DEBUG_PRINTLN("BLE client disconnected");
21+
}
22+
23+
void TechoBoard::begin() {
24+
// for future use, sub-classes SHOULD call this from their begin()
25+
startup_reason = BD_STARTUP_NORMAL;
26+
27+
Wire.begin();
28+
29+
pinMode(SX126X_POWER_EN, OUTPUT);
30+
digitalWrite(SX126X_POWER_EN, HIGH);
31+
delay(10); // give sx1262 some time to power up
32+
}
33+
34+
uint16_t TechoBoard::getBattMilliVolts() {
35+
int adcvalue = 0;
36+
37+
analogReference(AR_INTERNAL_3_0);
38+
analogReadResolution(12);
39+
delay(10);
40+
41+
// ADC range is 0..3000mV and resolution is 12-bit (0..4095)
42+
adcvalue = analogRead(PIN_VBAT_READ);
43+
// Convert the raw value to compensated mv, taking the resistor-
44+
// divider into account (providing the actual LIPO voltage)
45+
return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB);
46+
}
47+
48+
bool TechoBoard::startOTAUpdate(const char* id, char reply[]) {
49+
// Config the peripheral connection with maximum bandwidth
50+
// more SRAM required by SoftDevice
51+
// Note: All config***() function must be called before begin()
52+
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
53+
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16);
54+
55+
Bluefruit.begin(1, 0);
56+
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
57+
Bluefruit.setTxPower(4);
58+
// Set the BLE device name
59+
Bluefruit.setName("TECHO_OTA");
60+
61+
Bluefruit.Periph.setConnectCallback(connect_callback);
62+
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
63+
64+
// To be consistent OTA DFU should be added first if it exists
65+
bledfu.begin();
66+
67+
// Set up and start advertising
68+
// Advertising packet
69+
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
70+
Bluefruit.Advertising.addTxPower();
71+
Bluefruit.Advertising.addName();
72+
73+
/* Start Advertising
74+
- Enable auto advertising if disconnected
75+
- Interval: fast mode = 20 ms, slow mode = 152.5 ms
76+
- Timeout for fast mode is 30 seconds
77+
- Start(timeout) with timeout = 0 will advertise forever (until connected)
78+
79+
For recommended advertising interval
80+
https://developer.apple.com/library/content/qa/qa1931/_index.html
81+
*/
82+
Bluefruit.Advertising.restartOnDisconnect(true);
83+
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
84+
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
85+
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
86+
87+
strcpy(reply, "OK - started");
88+
return true;
89+
}
90+
#endif
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#pragma once
2+
3+
#include <MeshCore.h>
4+
#include <Arduino.h>
5+
6+
// built-ins
7+
#define VBAT_MV_PER_LSB (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096
8+
9+
#define VBAT_DIVIDER (0.5F) // 150K + 150K voltage divider on VBAT
10+
#define VBAT_DIVIDER_COMP (2.0F) // Compensation factor for the VBAT divider
11+
12+
#define PIN_VBAT_READ (4)
13+
#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
14+
15+
class TechoBoard : public mesh::MainBoard {
16+
protected:
17+
uint8_t startup_reason;
18+
19+
public:
20+
21+
void begin();
22+
uint16_t getBattMilliVolts() override;
23+
bool startOTAUpdate(const char* id, char reply[]) override;
24+
25+
uint8_t getStartupReason() const override {
26+
return startup_reason;
27+
}
28+
29+
const char* getManufacturerName() const override {
30+
return "LilyGo T-Echo";
31+
}
32+
33+
void powerOff() override {
34+
#ifdef LED_RED
35+
digitalWrite(LED_RED, LOW);
36+
#endif
37+
#ifdef LED_GREEN
38+
digitalWrite(LED_GREEN, LOW);
39+
#endif
40+
#ifdef LED_BLUE
41+
digitalWrite(LED_BLUE, LOW);
42+
#endif
43+
#ifdef DISP_BACKLIGHT
44+
digitalWrite(DISP_BACKLIGHT, LOW);
45+
#endif
46+
#ifdef PIN_PWR_EN
47+
digitalWrite(PIN_PWR_EN, LOW);
48+
#endif
49+
sd_power_system_off();
50+
}
51+
52+
void reboot() override {
53+
NVIC_SystemReset();
54+
}
55+
};
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
[LilyGo_T-Echo-Lite]
2+
extends = nrf52_base
3+
board = t-echo
4+
board_build.ldscript = boards/nrf52840_s140_v6.ld
5+
build_flags = ${nrf52_base.build_flags}
6+
-I variants/lilygo_techo_lite
7+
-I src/helpers/nrf52
8+
-I lib/nrf52/s140_nrf52_6.1.1_API/include
9+
-I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52
10+
-D LILYGO_TECHO
11+
-D RADIO_CLASS=CustomSX1262
12+
-D WRAPPER_CLASS=CustomSX1262Wrapper
13+
-D LORA_TX_POWER=22
14+
-D P_LORA_DIO_1=40
15+
-D P_LORA_NSS=11
16+
-D P_LORA_RESET=7
17+
-D P_LORA_BUSY=14
18+
-D P_LORA_SCLK=13
19+
-D P_LORA_MISO=17
20+
-D P_LORA_MOSI=15
21+
-D SX126X_POWER_EN=30
22+
-D SX126X_CURRENT_LIMIT=140
23+
-D SX126X_RX_BOOSTED_GAIN=1
24+
-D P_LORA_TX_LED=LED_GREEN
25+
-D DISABLE_DIAGNOSTIC_OUTPUT
26+
-D ENV_INCLUDE_GPS=1
27+
; -D ENV_INCLUDE_BME280=1
28+
-D GPS_BAUD_RATE=9600
29+
-D PIN_GPS_EN=GPS_EN
30+
; -D TELEM_BME280_ADDRESS=0x77
31+
-D DISPLAY_CLASS=GxEPDDisplay
32+
-D EINK_DISPLAY_MODEL=GxEPD2_122_T61
33+
-D EINK_SCALE_X=1.0f
34+
-D EINK_SCALE_Y=2.0f
35+
-D EINK_X_OFFSET=0
36+
-D EINK_Y_OFFSET=10
37+
-D DISPLAY_ROTATION=4
38+
-D AUTO_OFF_MILLIS=0
39+
build_src_filter = ${nrf52_base.build_src_filter}
40+
+<helpers/*.cpp>
41+
+<TechoBoard.cpp>
42+
+<helpers/sensors/EnvironmentSensorManager.cpp>
43+
+<helpers/ui/GxEPDDisplay.cpp>
44+
+<helpers/ui/MomentaryButton.cpp>
45+
+<../variants/lilygo_techo_lite>
46+
lib_deps =
47+
${nrf52_base.lib_deps}
48+
stevemarple/MicroNMEA @ ^2.0.6
49+
adafruit/Adafruit BME280 Library @ ^2.3.0
50+
zinggjm/GxEPD2 @ 1.6.2
51+
bakercp/CRC32 @ ^2.0.0
52+
debug_tool = jlink
53+
upload_protocol = nrfutil
54+
55+
[env:LilyGo_T-Echo-Lite_repeater]
56+
extends = LilyGo_T-Echo-Lite
57+
build_src_filter = ${LilyGo_T-Echo-Lite.build_src_filter}
58+
+<../examples/simple_repeater>
59+
build_flags =
60+
${LilyGo_T-Echo-Lite.build_flags}
61+
-D ADVERT_NAME='"T-Echo-Lite Repeater"'
62+
-D ADVERT_LAT=0.0
63+
-D ADVERT_LON=0.0
64+
-D ADMIN_PASSWORD='"password"'
65+
-D MAX_NEIGHBOURS=8
66+
; -D MESH_PACKET_LOGGING=1
67+
; -D MESH_DEBUG=1
68+
69+
[env:LilyGo_T-Echo-Lite_room_server]
70+
extends = LilyGo_T-Echo-Lite
71+
build_src_filter = ${LilyGo_T-Echo-Lite.build_src_filter}
72+
+<../examples/simple_room_server>
73+
build_flags =
74+
${LilyGo_T-Echo-Lite.build_flags}
75+
-D ADVERT_NAME='"T-Echo-Lite Room"'
76+
-D ADVERT_LAT=0.0
77+
-D ADVERT_LON=0.0
78+
-D ADMIN_PASSWORD='"password"'
79+
; -D MESH_PACKET_LOGGING=1
80+
; -D MESH_DEBUG=1
81+
82+
[env:LilyGo_T-Echo-Lite_companion_radio_ble]
83+
extends = LilyGo_T-Echo-Lite
84+
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
85+
board_upload.maximum_size = 712704
86+
build_flags =
87+
${LilyGo_T-Echo-Lite.build_flags}
88+
-I src/helpers/ui
89+
-I examples/companion_radio/ui-new
90+
-D MAX_CONTACTS=350
91+
-D MAX_GROUP_CHANNELS=40
92+
; -D QSPIFLASH=1
93+
-D BLE_PIN_CODE=123456
94+
; -D BLE_DEBUG_LOGGING=1
95+
-D OFFLINE_QUEUE_SIZE=256
96+
-D UI_RECENT_LIST_SIZE=9
97+
-D UI_SENSORS_PAGE=1
98+
; -D MESH_PACKET_LOGGING=1
99+
; -D MESH_DEBUG=1
100+
-D AUTO_SHUTDOWN_MILLIVOLTS=3300
101+
build_src_filter = ${LilyGo_T-Echo-Lite.build_src_filter}
102+
+<helpers/nrf52/SerialBLEInterface.cpp>
103+
+<../examples/companion_radio/*.cpp>
104+
+<../examples/companion_radio/ui-new/*.cpp>
105+
lib_deps =
106+
${LilyGo_T-Echo-Lite.lib_deps}
107+
densaugeo/base64 @ ~1.4.0
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <Arduino.h>
2+
#include "target.h"
3+
#include <helpers/ArduinoHelpers.h>
4+
#include <helpers/sensors/MicroNMEALocationProvider.h>
5+
6+
TechoBoard board;
7+
8+
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
9+
10+
WRAPPER_CLASS radio_driver(radio, board);
11+
12+
VolatileRTCClock fallback_clock;
13+
AutoDiscoverRTCClock rtc_clock(fallback_clock);
14+
15+
#ifdef ENV_INCLUDE_GPS
16+
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
17+
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
18+
#else
19+
EnvironmentSensorManager sensors = EnvironmentSensorManager();
20+
#endif
21+
22+
#ifdef DISPLAY_CLASS
23+
DISPLAY_CLASS display;
24+
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
25+
#endif
26+
27+
bool radio_init() {
28+
rtc_clock.begin(Wire);
29+
30+
// pinMode(SX126X_RF_VC1, OUTPUT);
31+
// pinMode(SX126X_RF_VC2, OUTPUT);
32+
// set_SX126X_RF_Transmitter_Switch(false);
33+
34+
return radio.std_init(&SPI);
35+
}
36+
37+
uint32_t radio_get_rng_seed() {
38+
return radio.random(0x7FFFFFFF);
39+
}
40+
41+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
42+
radio.setFrequency(freq);
43+
radio.setSpreadingFactor(sf);
44+
radio.setBandwidth(bw);
45+
radio.setCodingRate(cr);
46+
}
47+
48+
void radio_set_tx_power(uint8_t dbm) {
49+
radio.setOutputPower(dbm);
50+
// set_SX126X_RF_Transmitter_Switch(true);
51+
}
52+
53+
mesh::LocalIdentity radio_new_identity() {
54+
RadioNoiseListener rng(radio);
55+
return mesh::LocalIdentity(&rng); // create new random identity
56+
}
57+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#define RADIOLIB_STATIC_ONLY 1
4+
#include <RadioLib.h>
5+
#include <helpers/radiolib/RadioLibWrappers.h>
6+
#include <TechoBoard.h>
7+
#include <helpers/radiolib/CustomSX1262Wrapper.h>
8+
#include <helpers/AutoDiscoverRTCClock.h>
9+
#include <helpers/SensorManager.h>
10+
#include <helpers/sensors/EnvironmentSensorManager.h>
11+
#include <helpers/sensors/LocationProvider.h>
12+
#ifdef DISPLAY_CLASS
13+
#include <helpers/ui/GxEPDDisplay.h>
14+
#include <helpers/ui/MomentaryButton.h>
15+
#endif
16+
17+
extern TechoBoard board;
18+
extern WRAPPER_CLASS radio_driver;
19+
extern AutoDiscoverRTCClock rtc_clock;
20+
extern EnvironmentSensorManager sensors;
21+
22+
#ifdef DISPLAY_CLASS
23+
extern DISPLAY_CLASS display;
24+
extern MomentaryButton user_btn;
25+
#endif
26+
27+
bool radio_init();
28+
uint32_t radio_get_rng_seed();
29+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
30+
void radio_set_tx_power(uint8_t dbm);
31+
mesh::LocalIdentity radio_new_identity();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "variant.h"
2+
#include "wiring_constants.h"
3+
#include "wiring_digital.h"
4+
5+
const int MISO = PIN_SPI1_MISO;
6+
const int MOSI = PIN_SPI1_MOSI;
7+
const int SCK = PIN_SPI1_SCK;
8+
9+
const uint32_t g_ADigitalPinMap[] = {
10+
0xff, 0xff, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
11+
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
12+
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
13+
40, 41, 42, 43, 44, 45, 46, 47
14+
};
15+
16+
void initVariant() {
17+
pinMode(PIN_PWR_EN, OUTPUT);
18+
digitalWrite(PIN_PWR_EN, HIGH);
19+
20+
pinMode(PIN_BUTTON1, INPUT_PULLUP);
21+
pinMode(PIN_BUTTON2, INPUT_PULLUP);
22+
23+
pinMode(LED_RED, OUTPUT);
24+
pinMode(LED_GREEN, OUTPUT);
25+
pinMode(LED_BLUE, OUTPUT);
26+
digitalWrite(LED_BLUE, HIGH);
27+
digitalWrite(LED_GREEN, HIGH);
28+
digitalWrite(LED_RED, HIGH);
29+
30+
// pinMode(PIN_TXCO, OUTPUT);
31+
// digitalWrite(PIN_TXCO, HIGH);
32+
33+
pinMode(DISP_POWER, OUTPUT);
34+
digitalWrite(DISP_POWER, LOW);
35+
36+
// shutdown gps
37+
pinMode(GPS_EN, OUTPUT);
38+
digitalWrite(GPS_EN, LOW);
39+
}

0 commit comments

Comments
 (0)