Merge pull request #1936 from lewisxhe/master

Update tbeam-s3 variant
This commit is contained in:
Thomas Göttgens 2022-11-12 14:12:11 +01:00 committed by GitHub
commit 4f60fad3f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 150 additions and 20 deletions

View File

@ -1,6 +1,18 @@
#include "configuration.h" #include "configuration.h"
#include "FSCommon.h" #include "FSCommon.h"
#ifdef HAS_SDCARD
#include <SPI.h>
#include <SD.h>
#ifdef SDCARD_USE_SPI1
SPIClass SPI1(HSPI);
#define SDHandler SPI1
#endif
#endif //HAS_SDCARD
bool copyFile(const char* from, const char* to) bool copyFile(const char* from, const char* to)
{ {
@ -169,3 +181,39 @@ void fsInit()
listDir("/", 10); listDir("/", 10);
#endif #endif
} }
void setupSDCard()
{
#ifdef HAS_SDCARD
SDHandler.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
if (!SD.begin(SDCARD_CS, SDHandler)) {
DEBUG_MSG("No SD_MMC card detected\n");
return ;
}
uint8_t cardType = SD.cardType();
if (cardType == CARD_NONE) {
DEBUG_MSG("No SD_MMC card attached\n");
return ;
}
DEBUG_MSG("SD_MMC Card Type: ");
if (cardType == CARD_MMC) {
DEBUG_MSG("MMC\n");
} else if (cardType == CARD_SD) {
DEBUG_MSG("SDSC\n");
} else if (cardType == CARD_SDHC) {
DEBUG_MSG("SDHC\n");
} else {
DEBUG_MSG("UNKNOWN\n");
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
DEBUG_MSG("SD Card Size: %lluMB\n", cardSize);
DEBUG_MSG("Total space: %llu MB\n", SD.totalBytes() / (1024 * 1024));
DEBUG_MSG("Used space: %llu MB\n", SD.usedBytes() / (1024 * 1024));
#endif
}

View File

@ -44,3 +44,4 @@ bool copyFile(const char* from, const char* to);
bool renameFile(const char* pathFrom, const char* pathTo); bool renameFile(const char* pathFrom, const char* pathTo);
void listDir(const char * dirname, uint8_t levels, boolean del); void listDir(const char * dirname, uint8_t levels, boolean del);
void rmDir(const char * dirname); void rmDir(const char * dirname);
void setupSDCard();

View File

@ -44,7 +44,11 @@ void readFromRTC()
if(rtc_found == PCF8563_RTC) { if(rtc_found == PCF8563_RTC) {
uint32_t now = millis(); uint32_t now = millis();
PCF8563_Class rtc; PCF8563_Class rtc;
#ifdef RTC_USE_WIRE1
rtc.begin(Wire1);
#else
rtc.begin(); rtc.begin();
#endif
auto tc = rtc.getDateTime(); auto tc = rtc.getDateTime();
tm t; tm t;
t.tm_year = tc.year - 1900; t.tm_year = tc.year - 1900;
@ -110,7 +114,11 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv)
#elif defined(PCF8563_RTC) #elif defined(PCF8563_RTC)
if(rtc_found == PCF8563_RTC) { if(rtc_found == PCF8563_RTC) {
PCF8563_Class rtc; PCF8563_Class rtc;
rtc.begin(); #ifdef RTC_USE_WIRE1
rtc.begin(Wire1);
#else
rtc.begin();
#endif
tm *t = localtime(&tv->tv_sec); tm *t = localtime(&tv->tv_sec);
rtc.setDateTime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); rtc.setDateTime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
DEBUG_MSG("PCF8563_RTC setDateTime %02d-%02d-%02d %02d:%02d:%02d %ld\n", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv->tv_sec); DEBUG_MSG("PCF8563_RTC setDateTime %02d-%02d-%02d %02d:%02d:%02d %ld\n", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv->tv_sec);

View File

@ -246,8 +246,32 @@ void setup()
digitalWrite(PIN_3V3_EN, 1); digitalWrite(PIN_3V3_EN, 1);
#endif #endif
// Currently only the tbeam has a PMU
// PMU initialization needs to be placed before scanI2Cdevice
power = new Power();
power->setStatusHandler(powerStatus);
powerStatus->observe(&power->newStatus);
power->setup(); // Must be after status handler is installed, so that handler gets notified of the initial configuration
#ifdef LILYGO_TBEAM_S3_CORE
// In T-Beam-S3-core, the I2C device cannot be scanned before power initialization, otherwise the device will be stuck
// PCF8563 RTC in tbeam-s3 uses Wire1 to share I2C bus
Wire1.beginTransmission(PCF8563_RTC);
if (Wire1.endTransmission() == 0){
rtc_found = PCF8563_RTC;
DEBUG_MSG("PCF8563 RTC found\n");
}
#endif
// We need to scan here to decide if we have a screen for nodeDB.init() // We need to scan here to decide if we have a screen for nodeDB.init()
scanI2Cdevice(); scanI2Cdevice();
#ifdef HAS_SDCARD
setupSDCard();
#endif
#ifdef RAK4630 #ifdef RAK4630
// scanEInkDevice(); // scanEInkDevice();
#endif #endif
@ -282,17 +306,12 @@ void setup()
playStartMelody(); playStartMelody();
// Currently only the tbeam has a PMU
power = new Power();
power->setStatusHandler(powerStatus);
powerStatus->observe(&power->newStatus);
power->setup(); // Must be after status handler is installed, so that handler gets notified of the initial configuration
/* /*
* Repeat the scanning for I2C devices after power initialization or look for 'latecomers'. * Repeat the scanning for I2C devices after power initialization or look for 'latecomers'.
* Boards with an PMU need to be powered on to correctly scan to the device address, such as t-beam-s3-core * Boards with an PMU need to be powered on to correctly scan to the device address, such as t-beam-s3-core
*/ */
scanI2Cdevice(); // scanI2Cdevice();
// fixed screen override? // fixed screen override?
if (config.display.oled != Config_DisplayConfig_OledType_OLED_AUTO) if (config.display.oled != Config_DisplayConfig_OledType_OLED_AUTO)

View File

@ -14,6 +14,7 @@
#include <driver/rtc_io.h> #include <driver/rtc_io.h>
#include <nvs.h> #include <nvs.h>
#include <nvs_flash.h> #include <nvs_flash.h>
#include "soc/rtc.h"
NimbleBluetooth *nimbleBluetooth; NimbleBluetooth *nimbleBluetooth;
@ -36,6 +37,44 @@ void setBluetoothEnable(bool on) {
} }
} }
#ifdef HAS_32768HZ
#define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk)
static uint32_t calibrate_one(rtc_cal_sel_t cal_clk, const char *name)
{
const uint32_t cal_count = 1000;
const float factor = (1 << 19) * 1000.0f;
uint32_t cali_val;
for (int i = 0; i < 5; ++i) {
cali_val = rtc_clk_cal(cal_clk, cal_count);
}
return cali_val;
}
void enableSlowCLK()
{
rtc_clk_32k_enable(true);
CALIBRATE_ONE(RTC_CAL_RTC_MUX);
uint32_t cal_32k = CALIBRATE_ONE(RTC_CAL_32K_XTAL);
if (cal_32k == 0) {
DEBUG_MSG("32K XTAL OSC has not started up\n");
} else {
rtc_clk_slow_freq_set(RTC_SLOW_FREQ_32K_XTAL);
DEBUG_MSG("Switching RTC Source to 32.768Khz succeeded, using 32K XTAL\n");
CALIBRATE_ONE(RTC_CAL_RTC_MUX);
CALIBRATE_ONE(RTC_CAL_32K_XTAL);
}
CALIBRATE_ONE(RTC_CAL_RTC_MUX);
CALIBRATE_ONE(RTC_CAL_32K_XTAL);
if (rtc_clk_slow_freq_get() != RTC_SLOW_FREQ_32K_XTAL) {
DEBUG_MSG("Warning: Failed to switch 32K XTAL RTC source to 32.768Khz !!! \n"); return;
}
}
#endif
void esp32Setup() void esp32Setup()
{ {
uint32_t seed = esp_random(); uint32_t seed = esp_random();
@ -83,6 +122,10 @@ void esp32Setup()
res = esp_task_wdt_add(NULL); res = esp_task_wdt_add(NULL);
assert(res == ESP_OK); assert(res == ESP_OK);
#ifdef HAS_32768HZ
enableSlowCLK();
#endif
} }
#if 0 #if 0

View File

@ -17,20 +17,28 @@
static const uint8_t TX = 43; static const uint8_t TX = 43;
static const uint8_t RX = 44; static const uint8_t RX = 44;
// The default Wire will be mapped to PMU and RTC
static const uint8_t SDA = 42; static const uint8_t SDA = 42;
static const uint8_t SCL = 41; static const uint8_t SCL = 41;
// Default SPI will be mapped to Radio
static const uint8_t SS = 10; static const uint8_t SS = 10;
static const uint8_t MOSI = 11; static const uint8_t MOSI = 11;
static const uint8_t MISO = 13; static const uint8_t MISO = 13;
static const uint8_t SCK = 12; static const uint8_t SCK = 12;
#define SDMMC_CMD (35) // Another SPI bus shares SD card and QMI8653 inertial measurement sensor
#define SDMMC_CLK (36) #define SPI_MOSI (35)
#define SDMMC_DATA (37) #define SPI_SCK (36)
#define SPI_MISO (37)
#define SPI_CS (47)
#define IMU_CS (34)
#define ACCEL_INT1 (34) #define SDCARD_CS SPI_CS
#define ACCEL_INT2 (33) #define IMU_INT (33)
// #define PMU_IRQ (40)
#define RTC_INT (14) #define RTC_INT (14)
#endif /* Pins_Arduino_h */ #endif /* Pins_Arduino_h */

View File

@ -1,20 +1,18 @@
// #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep // #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep
#define I2C_SDA1 42 //Used for PMU management #define I2C_SDA1 42 //Used for PMU management and PCF8563
#define I2C_SCL1 41 //Used for PMU management #define I2C_SCL1 41 //Used for PMU management and PCF8563
#define I2C_SDA 17 //For sensors and screens #define I2C_SDA 17 //For QMC6310 sensors and screens
#define I2C_SCL 18 //For sensors and screens #define I2C_SCL 18 //For QMC6310 sensors and screens
#define BUTTON_PIN 0 // The middle button GPIO on the T-Beam S3 #define BUTTON_PIN 0 // The middle button GPIO on the T-Beam S3
//#define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented anywhere. //#define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented anywhere.
// #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. // #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module.
#define BUTTON1_PIN 47 //Additional keys
#define LED_INVERTED 1 #define LED_INVERTED 1
// #define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4
// TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if // TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if
// not found then probe for SX1262 // not found then probe for SX1262
@ -42,8 +40,9 @@
// #define PMU_IRQ 40 // #define PMU_IRQ 40
#define HAS_AXP2101 #define HAS_AXP2101
// Specify the PMU as Wire1. In the t-beam-s3-core, the PMU enjoys a separate bus // Specify the PMU as Wire1. In the t-beam-s3 core, PCF8563 and PMU share the bus
#define PMU_USE_WIRE1 #define PMU_USE_WIRE1
#define RTC_USE_WIRE1
#define RF95_SCK 12 #define RF95_SCK 12
#define RF95_MISO 13 #define RF95_MISO 13
@ -56,10 +55,14 @@
#define GPS_1PPS_PIN 6 #define GPS_1PPS_PIN 6
#define HAS_SDCARD //Have 3-bit SDMMC interface SD card slot #define HAS_SDCARD //Have SPI interface SD card slot
#define SDCARD_USE_SPI1
// PCF8563 RTC Module // PCF8563 RTC Module
// #define PCF8563_RTC 0x51 //Putting definitions in variant. h does not compile correctly // #define PCF8563_RTC 0x51 //Putting definitions in variant. h does not compile correctly
#define HAS_RTC 1 #define HAS_RTC 1
//has 32768 Hz crystal
#define HAS_32768HZ