From 9635c3e5ed12ab5c15fb233aea6e24da13f45a1e Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Tue, 12 Jun 2018 18:12:35 +0300 Subject: [PATCH] Support for ESP32 TTGO T-Beam --- .../firmware/source/SoftRF/Platform_ESP32.cpp | 51 +++++++++++++++++++ .../firmware/source/SoftRF/Platform_ESP32.h | 11 ++++ 2 files changed, 62 insertions(+) diff --git a/software/firmware/source/SoftRF/Platform_ESP32.cpp b/software/firmware/source/SoftRF/Platform_ESP32.cpp index cc915e291..aa7c121a7 100644 --- a/software/firmware/source/SoftRF/Platform_ESP32.cpp +++ b/software/firmware/source/SoftRF/Platform_ESP32.cpp @@ -59,6 +59,7 @@ U8X8_SSD1306_128X64_NONAME_2ND_HW_I2C u8x8_heltec(HELTEC_OLED_PIN_RST, static U8X8_SSD1306_128X64_NONAME_2ND_HW_I2C *u8x8 = NULL; +static int esp32_board = ESP32_DEVKIT; /* default */ static void ESP32_setup() { @@ -80,6 +81,7 @@ static void ESP32_setup() Wire1.beginTransmission(SSD1306_OLED_I2C_ADDR); if (Wire1.endTransmission() == 0) { u8x8 = &u8x8_ttgo; + esp32_board = ESP32_TTGO_V2_OLED; } else { /* * This does NOT work well with "stock" ESP32 Arduino Core's TwoWire implementation yet. @@ -90,6 +92,7 @@ static void ESP32_setup() Wire1.beginTransmission(SSD1306_OLED_I2C_ADDR); if (Wire1.endTransmission() == 0) { u8x8 = &u8x8_heltec; + esp32_board = ESP32_HELTEC_OLED; } } @@ -299,6 +302,54 @@ static void ESP32_SPI_begin() static void ESP32_swSer_begin(unsigned long baud) { + if ((esp32_board != ESP32_TTGO_V2_OLED) && (esp32_board != ESP32_HELTEC_OLED)) { + + unsigned long startTime = millis(); + char c1, c2; + c1 = c2 = 0; + + /* try to detect TTGO T-Beam built-in GPS module */ + swSer.begin(baud, SERIAL_8N1, SOC_GPIO_PIN_TBEAM_RX, SOC_GPIO_PIN_TBEAM_TX); + + // clean any leftovers + swSer.flush(); + + // Serial.println(F("INFO: Waiting for NMEA data from TTGO T-Beam GPS module...")); + + // Timeout if no valid response in 3 seconds + while (millis() - startTime < 3000) { + + if (swSer.available() > 0) { + c1 = swSer.read(); + if ((c1 == '$') && (c2 == 0)) { c2 = c1; continue; } + if ((c2 == '$') && (c1 == 'G')) { + /* got $G */ + Serial.println(F("INFO: TTGO T-Beam GPS module is detected.")); + + esp32_board = ESP32_TTGO_T_BEAM; + + /* leave the function with TTGO port opened */ + return; + } else { + c2 = 0; + } + } + + delay(1); + } + + /* release UART and pins */ + swSer.end(); + } + +#if 0 + if (esp32_board == ESP32_TTGO_V2_OLED) Serial.println(F("INFO: TTGO+OLED is detected.")); + if (esp32_board == ESP32_HELTEC_OLED) Serial.println(F("INFO: HELTEC+OLED is detected.")); + Serial.print(F("INFO: esp32_board = ")); + Serial.println(esp32_board, HEX); +#endif + + /* open Standalone's GNSS port */ swSer.begin(baud, SERIAL_8N1, SOC_GPIO_PIN_GNSS_RX, SOC_GPIO_PIN_GNSS_TX); } diff --git a/software/firmware/source/SoftRF/Platform_ESP32.h b/software/firmware/source/SoftRF/Platform_ESP32.h index 5c82a4613..0690d5b55 100644 --- a/software/firmware/source/SoftRF/Platform_ESP32.h +++ b/software/firmware/source/SoftRF/Platform_ESP32.h @@ -56,6 +56,10 @@ #define SOC_GPIO_PIN_SDA 14 #define SOC_GPIO_PIN_SCL 2 +/* TTGO T-BEAM GPS module */ +#define SOC_GPIO_PIN_TBEAM_RX 12 +#define SOC_GPIO_PIN_TBEAM_TX 15 + #define SSD1306_OLED_I2C_ADDR 0x3C // Hardware pin definitions for TTGO V2 Board with OLED SSD1306 0,96" I2C Display @@ -80,6 +84,13 @@ enum rst_reason { REASON_EXT_SYS_RST = 6 /* external system reset */ }; +enum esp32_board_id { + ESP32_DEVKIT, + ESP32_TTGO_V2_OLED, + ESP32_HELTEC_OLED, + ESP32_TTGO_T_BEAM +}; + struct rst_info { uint32_t reason; uint32_t exccause;