Skip to content

Commit fe87403

Browse files
authored
Merge pull request #1153 from fdlamotte/thinknode_m5
Thinknode m5 support
2 parents 0307b64 + 1c0017b commit fe87403

File tree

10 files changed

+492
-3
lines changed

10 files changed

+492
-3
lines changed

examples/companion_radio/ui-new/UITask.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,24 @@ class HomeScreen : public UIScreen {
260260
#if ENV_INCLUDE_GPS == 1
261261
} else if (_page == HomePage::GPS) {
262262
LocationProvider* nmea = sensors.getLocationProvider();
263+
char buf[50];
263264
int y = 18;
264-
display.drawTextLeftAlign(0, y, _task->getGPSState() ? "gps on" : "gps off");
265+
bool gps_state = _task->getGPSState();
266+
#ifdef PIN_GPS_SWITCH
267+
bool hw_gps_state = digitalRead(PIN_GPS_SWITCH);
268+
if (gps_state != hw_gps_state) {
269+
strcpy(buf, gps_state ? "gps off(hw)" : "gps off(sw)");
270+
} else {
271+
strcpy(buf, gps_state ? "gps on" : "gps off");
272+
}
273+
#else
274+
strcpy(buf, gps_state ? "gps on" : "gps off");
275+
#endif
276+
display.drawTextLeftAlign(0, y, buf);
265277
if (nmea == NULL) {
266278
y = y + 12;
267279
display.drawTextLeftAlign(0, y, "Can't access GPS");
268280
} else {
269-
char buf[50];
270281
strcpy(buf, nmea->isValid()?"fix":"no fix");
271282
display.drawTextRightAlign(display.width()-1, y, buf);
272283
y = y + 12;
@@ -716,10 +727,14 @@ void UITask::loop() {
716727
_analogue_pin_read_millis = millis();
717728
}
718729
#endif
719-
#if defined(DISP_BACKLIGHT) && defined(BACKLIGHT_BTN)
730+
#if defined(BACKLIGHT_BTN)
720731
if (millis() > next_backlight_btn_check) {
721732
bool touch_state = digitalRead(PIN_BUTTON2);
733+
#if defined(DISP_BACKLIGHT)
722734
digitalWrite(DISP_BACKLIGHT, !touch_state);
735+
#elif defined(EXP_PIN_BACKLIGHT)
736+
expander.digitalWrite(EXP_PIN_BACKLIGHT, !touch_state);
737+
#endif
723738
next_backlight_btn_check = millis() + 300;
724739
}
725740
#endif

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,11 @@ void EnvironmentSensorManager::initBasicGPS() {
548548
delay(1000);
549549

550550
// We'll consider GPS detected if we see any data on Serial1
551+
#ifdef ENV_SKIP_GPS_DETECT
552+
gps_detected = true;
553+
#else
551554
gps_detected = (Serial1.available() > 0);
555+
#endif
552556

553557
if (gps_detected) {
554558
MESH_DEBUG_PRINTLN("GPS detected");

src/helpers/ui/GxEPDDisplay.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11

22
#include "GxEPDDisplay.h"
33

4+
#ifdef EXP_PIN_BACKLIGHT
5+
#include <PCA9557.h>
6+
extern PCA9557 expander;
7+
#endif
8+
49
#ifndef DISPLAY_ROTATION
510
#define DISPLAY_ROTATION 3
611
#endif
712

13+
#ifdef ESP32
14+
SPIClass SPI1 = SPIClass(FSPI);
15+
#endif
16+
817
bool GxEPDDisplay::begin() {
918
display.epd2.selectSPI(SPI1, SPISettings(4000000, MSBFIRST, SPI_MODE0));
19+
#ifdef ESP32
20+
SPI1.begin(PIN_DISPLAY_SCLK, PIN_DISPLAY_MISO, PIN_DISPLAY_MOSI, PIN_DISPLAY_CS);
21+
#else
1022
SPI1.begin();
23+
#endif
1124
display.init(115200, true, 2, false);
1225
display.setRotation(DISPLAY_ROTATION);
1326
setTextSize(1); // Default to size 1
@@ -27,13 +40,17 @@ void GxEPDDisplay::turnOn() {
2740
if (!_init) begin();
2841
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
2942
digitalWrite(DISP_BACKLIGHT, HIGH);
43+
#elif defined(EXP_PIN_BACKLIGHT) && !defined(BACKLIGHT_BTN)
44+
expander.digitalWrite(EXP_PIN_BACKLIGHT, HIGH);
3045
#endif
3146
_isOn = true;
3247
}
3348

3449
void GxEPDDisplay::turnOff() {
3550
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
3651
digitalWrite(DISP_BACKLIGHT, LOW);
52+
#elif defined(EXP_PIN_BACKLIGHT) && !defined(BACKLIGHT_BTN)
53+
expander.digitalWrite(EXP_PIN_BACKLIGHT, LOW);
3754
#endif
3855
_isOn = false;
3956
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "ThinknodeM5Board.h"
2+
3+
PCA9557 expander (0x18, &Wire1);
4+
5+
void ThinknodeM5Board::begin() {
6+
// Start expander and configure pins
7+
Wire1.begin(48, 47);
8+
expander.pinMode(EXP_PIN_POWER, OUTPUT); // eink
9+
expander.pinMode(EXP_PIN_BACKLIGHT, OUTPUT); // peripherals
10+
expander.pinMode(EXP_PIN_LED, OUTPUT); // peripherals
11+
expander.digitalWrite(EXP_PIN_POWER, HIGH);
12+
expander.digitalWrite(EXP_PIN_BACKLIGHT, LOW);
13+
expander.digitalWrite(EXP_PIN_LED, LOW);
14+
15+
#ifdef PIN_GPS_SWITCH
16+
pinMode(PIN_GPS_SWITCH, INPUT);
17+
#endif
18+
19+
ESP32Board::begin();
20+
}
21+
22+
void ThinknodeM5Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) {
23+
esp_deep_sleep_start();
24+
}
25+
26+
void ThinknodeM5Board::powerOff() {
27+
enterDeepSleep(0);
28+
}
29+
30+
uint16_t ThinknodeM5Board::getBattMilliVolts() {
31+
analogReadResolution(12);
32+
analogSetPinAttenuation(PIN_VBAT_READ, ADC_11db);
33+
34+
uint32_t mv = 0;
35+
for (int i = 0; i < 8; ++i) {
36+
mv += analogReadMilliVolts(PIN_VBAT_READ);
37+
delayMicroseconds(200);
38+
}
39+
mv /= 8;
40+
41+
analogReadResolution(10);
42+
return static_cast<uint16_t>(mv * ADC_MULTIPLIER );
43+
}
44+
45+
const char* ThinknodeM5Board::getManufacturerName() const {
46+
return "Elecrow ThinkNode M2";
47+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include <Arduino.h>
4+
#include <helpers/RefCountedDigitalPin.h>
5+
#include <helpers/ESP32Board.h>
6+
#include <driver/rtc_io.h>
7+
#include <PCA9557.h>
8+
9+
extern PCA9557 expander;
10+
11+
class ThinknodeM5Board : public ESP32Board {
12+
13+
public:
14+
15+
void begin();
16+
void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1);
17+
void powerOff() override;
18+
uint16_t getBattMilliVolts() override;
19+
const char* getManufacturerName() const override ;
20+
21+
void onBeforeTransmit() override {
22+
expander.digitalWrite(EXP_PIN_LED, HIGH); // turn TX LED on
23+
}
24+
void onAfterTransmit() override {
25+
expander.digitalWrite(EXP_PIN_LED, LOW); // turn TX LED off
26+
}
27+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Need this file for ESP32-S3
2+
// No need to modify this file, changes to pins imported from variant.h
3+
// Most is similar to https://github.com/espressif/arduino-esp32/blob/master/variants/esp32s3/pins_arduino.h
4+
5+
#ifndef Pins_Arduino_h
6+
#define Pins_Arduino_h
7+
8+
#include <stdint.h>
9+
#include <variant.h>
10+
11+
#define USB_VID 0x303a
12+
#define USB_PID 0x1001
13+
14+
// Serial
15+
static const uint8_t TX = PIN_GPS_TX;
16+
static const uint8_t RX = PIN_GPS_RX;
17+
18+
// Default SPI will be mapped to Radio
19+
static const uint8_t SS = P_LORA_NSS;
20+
static const uint8_t SCK = P_LORA_SCLK;
21+
static const uint8_t MOSI = P_LORA_MISO;
22+
static const uint8_t MISO = P_LORA_MOSI;
23+
24+
// The default Wire will be mapped to PMU and RTC
25+
static const uint8_t SCL = PIN_BOARD_SCL;
26+
static const uint8_t SDA = PIN_BOARD_SDA;
27+
28+
#endif /* Pins_Arduino_h */

0 commit comments

Comments
 (0)