From 80f4baa7656fd7167c70ab25f977490eee76d4cc Mon Sep 17 00:00:00 2001 From: lewishe Date: Fri, 4 Aug 2023 09:24:02 +0800 Subject: [PATCH] Added PMU Example --- examples/PMU/PMU.ino | 90 ++++++++ examples/PMU/boards.h | 435 +++++++++++++++++++++++++++++++++++++++ examples/PMU/utilities.h | 272 ++++++++++++++++++++++++ platformio.ini | 3 +- 4 files changed, 799 insertions(+), 1 deletion(-) create mode 100644 examples/PMU/PMU.ino create mode 100644 examples/PMU/boards.h create mode 100644 examples/PMU/utilities.h diff --git a/examples/PMU/PMU.ino b/examples/PMU/PMU.ino new file mode 100644 index 0000000..40526e0 --- /dev/null +++ b/examples/PMU/PMU.ino @@ -0,0 +1,90 @@ +/** + * @file PMU.ino + * @author Lewis He (lewishe@outlook.com) + * @license MIT + * @copyright Copyright (c) 2023 Shenzhen Xin Yuan Electronic Technology Co., Ltd + * @date 2023-08-04 + * @note The sketch is only suitable for boards carrying AXP192 or AXP2101 chips + */ + + +#include "boards.h" + + +#if !defined(LILYGO_TBeamS3_SUPREME_V3_0) && !defined(LILYGO_TBeam_V1_X) +#error "The sketch is only suitable for boards carrying AXP192 or AXP2101 chips!" +#endif + + +uint32_t startMillis; + +void setup() +{ + // Init PMU + initBoard(); +} + + +void loop() +{ + if (millis() > startMillis) { + 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"); + // The battery percentage may be inaccurate at first use, the PMU will automatically + // learn the battery curve and will automatically calibrate the battery percentage + // after a charge and discharge cycle + if (PMU->isBatteryConnect()) { + Serial.print("getBatteryPercent:"); Serial.print(PMU->getBatteryPercent()); Serial.println("%"); + } + Serial.println(); + + startMillis += millis() + 1000; + } + + + if (pmuInterrupt) { + + pmuInterrupt = false; + + // Get PMU Interrupt Status Register + uint32_t status = PMU->getIrqStatus(); + Serial.print("STATUS => HEX:"); + Serial.print(status, HEX); + Serial.print(" BIN:"); + Serial.println(status, BIN); + + if (PMU->isVbusInsertIrq()) { + Serial.println("isVbusInsert"); + } + if (PMU->isVbusRemoveIrq()) { + Serial.println("isVbusRemove"); + } + if (PMU->isBatInsertIrq()) { + Serial.println("isBatInsert"); + } + if (PMU->isBatRemoveIrq()) { + Serial.println("isBatRemove"); + } + if (PMU->isPekeyShortPressIrq()) { + Serial.println("isPekeyShortPress"); + } + if (PMU->isPekeyLongPressIrq()) { + Serial.println("isPekeyLongPress"); + } + if (PMU->isBatChagerDoneIrq()) { + Serial.println("isBatChagerDone"); + } + if (PMU->isBatChagerStartIrq()) { + Serial.println("isBatChagerStart"); + } + // Clear PMU Interrupt Status Register + PMU->clearIrqStatus(); + + } + delay(10); + +} diff --git a/examples/PMU/boards.h b/examples/PMU/boards.h new file mode 100644 index 0000000..7c9c823 --- /dev/null +++ b/examples/PMU/boards.h @@ -0,0 +1,435 @@ +#include +#include +#include +#include "utilities.h" + +#ifdef HAS_SDCARD +#include +#include +#endif + +#ifdef HAS_DISPLAY +#include + +#ifndef DISPLAY_MODEL +#define DISPLAY_MODEL U8G2_SSD1306_128X64_NONAME_F_HW_I2C +#endif + +DISPLAY_MODEL *u8g2 = nullptr; +#endif + +#ifndef OLED_WIRE_PORT +#define OLED_WIRE_PORT Wire +#endif + +#if defined(HAS_PMU) +#include "XPowersLib.h" + + +XPowersLibInterface *PMU = NULL; + +#ifndef PMU_WIRE_PORT +#define PMU_WIRE_PORT Wire +#endif + + + +bool pmuInterrupt; + +void setPmuFlag() +{ + pmuInterrupt = true; +} + + +bool initPMU() +{ + if (!PMU) { + PMU = new XPowersAXP2101(PMU_WIRE_PORT); + if (!PMU->init()) { + Serial.println("Warning: Failed to find AXP2101 power management"); + delete PMU; + PMU = NULL; + } else { + Serial.println("AXP2101 PMU init succeeded, using AXP2101 PMU"); + } + } + + if (!PMU) { + PMU = new XPowersAXP192(PMU_WIRE_PORT); + if (!PMU->init()) { + Serial.println("Warning: Failed to find AXP192 power management"); + delete PMU; + PMU = NULL; + } else { + Serial.println("AXP192 PMU init succeeded, using AXP192 PMU"); + } + } + + if (!PMU) { + return false; + } + + PMU->setChargingLedMode(XPOWERS_CHG_LED_BLINK_1HZ); + + pinMode(PMU_IRQ, INPUT_PULLUP); + attachInterrupt(PMU_IRQ, setPmuFlag, FALLING); + + if (PMU->getChipModel() == XPOWERS_AXP192) { + + PMU->setProtectedChannel(XPOWERS_DCDC3); + + // lora + PMU->setPowerChannelVoltage(XPOWERS_LDO2, 3300); + // gps + PMU->setPowerChannelVoltage(XPOWERS_LDO3, 3300); + // oled + PMU->setPowerChannelVoltage(XPOWERS_DCDC1, 3300); + + PMU->enablePowerOutput(XPOWERS_LDO2); + PMU->enablePowerOutput(XPOWERS_LDO3); + + //protected oled power source + PMU->setProtectedChannel(XPOWERS_DCDC1); + //protected esp32 power source + PMU->setProtectedChannel(XPOWERS_DCDC3); + // enable oled power + PMU->enablePowerOutput(XPOWERS_DCDC1); + + //disable not use channel + PMU->disablePowerOutput(XPOWERS_DCDC2); + + PMU->disableIRQ(XPOWERS_AXP192_ALL_IRQ); + + PMU->enableIRQ(XPOWERS_AXP192_VBUS_REMOVE_IRQ | + XPOWERS_AXP192_VBUS_INSERT_IRQ | + XPOWERS_AXP192_BAT_CHG_DONE_IRQ | + XPOWERS_AXP192_BAT_CHG_START_IRQ | + XPOWERS_AXP192_BAT_REMOVE_IRQ | + XPOWERS_AXP192_BAT_INSERT_IRQ | + XPOWERS_AXP192_PKEY_SHORT_IRQ + ); + + } else if (PMU->getChipModel() == XPOWERS_AXP2101) { + +#if defined(CONFIG_IDF_TARGET_ESP32) + //Unuse power channel + PMU->disablePowerOutput(XPOWERS_DCDC2); + PMU->disablePowerOutput(XPOWERS_DCDC3); + PMU->disablePowerOutput(XPOWERS_DCDC4); + PMU->disablePowerOutput(XPOWERS_DCDC5); + PMU->disablePowerOutput(XPOWERS_ALDO1); + PMU->disablePowerOutput(XPOWERS_ALDO4); + PMU->disablePowerOutput(XPOWERS_BLDO1); + PMU->disablePowerOutput(XPOWERS_BLDO2); + PMU->disablePowerOutput(XPOWERS_DLDO1); + PMU->disablePowerOutput(XPOWERS_DLDO2); + + // GNSS RTC PowerVDD 3300mV + PMU->setPowerChannelVoltage(XPOWERS_VBACKUP, 3300); + PMU->enablePowerOutput(XPOWERS_VBACKUP); + + //ESP32 VDD 3300mV + // ! No need to set, automatically open , Don't close it + // PMU->setPowerChannelVoltage(XPOWERS_DCDC1, 3300); + // PMU->setProtectedChannel(XPOWERS_DCDC1); + PMU->setProtectedChannel(XPOWERS_DCDC1); + + // LoRa VDD 3300mV + PMU->setPowerChannelVoltage(XPOWERS_ALDO2, 3300); + PMU->enablePowerOutput(XPOWERS_ALDO2); + + //GNSS VDD 3300mV + PMU->setPowerChannelVoltage(XPOWERS_ALDO3, 3300); + PMU->enablePowerOutput(XPOWERS_ALDO3); + +#endif /*CONFIG_IDF_TARGET_ESP32*/ + + +#if defined(LILYGO_TBeamS3_SUPREME_V3_0) + + //t-beam m.2 inface + //gps + PMU->setPowerChannelVoltage(XPOWERS_ALDO4, 3300); + PMU->enablePowerOutput(XPOWERS_ALDO4); + + // lora + PMU->setPowerChannelVoltage(XPOWERS_ALDO3, 3300); + PMU->enablePowerOutput(XPOWERS_ALDO3); + + // In order to avoid bus occupation, during initialization, the SD card and QMC sensor are powered off and restarted + if (ESP_SLEEP_WAKEUP_UNDEFINED == esp_sleep_get_wakeup_cause()) { + Serial.println("Power off and restart ALDO BLDO.."); + PMU->disablePowerOutput(XPOWERS_ALDO1); + PMU->disablePowerOutput(XPOWERS_ALDO2); + PMU->disablePowerOutput(XPOWERS_BLDO1); + delay(250); + } + + // Sensor + PMU->setPowerChannelVoltage(XPOWERS_ALDO1, 3300); + PMU->enablePowerOutput(XPOWERS_ALDO1); + + PMU->setPowerChannelVoltage(XPOWERS_ALDO2, 3300); + PMU->enablePowerOutput(XPOWERS_ALDO2); + + //Sdcard + + PMU->setPowerChannelVoltage(XPOWERS_BLDO1, 3300); + PMU->enablePowerOutput(XPOWERS_BLDO1); + + PMU->setPowerChannelVoltage(XPOWERS_BLDO2, 3300); + PMU->enablePowerOutput(XPOWERS_BLDO2); + + //face m.2 + PMU->setPowerChannelVoltage(XPOWERS_DCDC3, 3300); + PMU->enablePowerOutput(XPOWERS_DCDC3); + + PMU->setPowerChannelVoltage(XPOWERS_DCDC4, XPOWERS_AXP2101_DCDC4_VOL2_MAX); + PMU->enablePowerOutput(XPOWERS_DCDC4); + + PMU->setPowerChannelVoltage(XPOWERS_DCDC5, 3300); + PMU->enablePowerOutput(XPOWERS_DCDC5); + + + //not use channel + PMU->disablePowerOutput(XPOWERS_DCDC2); + // PMU->disablePowerOutput(XPOWERS_DCDC4); + // PMU->disablePowerOutput(XPOWERS_DCDC5); + PMU->disablePowerOutput(XPOWERS_DLDO1); + PMU->disablePowerOutput(XPOWERS_DLDO2); + PMU->disablePowerOutput(XPOWERS_VBACKUP); + + // Set constant current charge current limit + PMU->setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_500MA); + + // Set charge cut-off voltage + PMU->setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V2); + + // Disable all interrupts + PMU->disableIRQ(XPOWERS_AXP2101_ALL_IRQ); + // Clear all interrupt flags + PMU->clearIrqStatus(); + // Enable the required interrupt function + PMU->enableIRQ( + XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_BAT_REMOVE_IRQ | //BATTERY + XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | //VBUS + XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_LONG_IRQ | //POWER KEY + XPOWERS_AXP2101_BAT_CHG_DONE_IRQ | XPOWERS_AXP2101_BAT_CHG_START_IRQ //CHARGE + // XPOWERS_AXP2101_PKEY_NEGATIVE_IRQ | XPOWERS_AXP2101_PKEY_POSITIVE_IRQ | //POWER KEY + ); + +#endif + } + + PMU->enableSystemVoltageMeasure(); + PMU->enableVbusVoltageMeasure(); + PMU->enableBattVoltageMeasure(); + // It is necessary to disable the detection function of the TS pin on the board + // without the battery temperature detection function, otherwise it will cause abnormal charging + PMU->disableTSPinMeasure(); + + Serial.printf("=========================================\n"); + if (PMU->isChannelAvailable(XPOWERS_DCDC1)) { + Serial.printf("DC1 : %s Voltage: %04u mV \n", PMU->isPowerChannelEnable(XPOWERS_DCDC1) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_DCDC1)); + } + if (PMU->isChannelAvailable(XPOWERS_DCDC2)) { + Serial.printf("DC2 : %s Voltage: %04u mV \n", PMU->isPowerChannelEnable(XPOWERS_DCDC2) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_DCDC2)); + } + if (PMU->isChannelAvailable(XPOWERS_DCDC3)) { + Serial.printf("DC3 : %s Voltage: %04u mV \n", PMU->isPowerChannelEnable(XPOWERS_DCDC3) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_DCDC3)); + } + if (PMU->isChannelAvailable(XPOWERS_DCDC4)) { + Serial.printf("DC4 : %s Voltage: %04u mV \n", PMU->isPowerChannelEnable(XPOWERS_DCDC4) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_DCDC4)); + } + if (PMU->isChannelAvailable(XPOWERS_DCDC5)) { + Serial.printf("DC5 : %s Voltage: %04u mV \n", PMU->isPowerChannelEnable(XPOWERS_DCDC5) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_DCDC5)); + } + if (PMU->isChannelAvailable(XPOWERS_LDO2)) { + Serial.printf("LDO2 : %s Voltage: %04u mV \n", PMU->isPowerChannelEnable(XPOWERS_LDO2) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_LDO2)); + } + if (PMU->isChannelAvailable(XPOWERS_LDO3)) { + Serial.printf("LDO3 : %s Voltage: %04u mV \n", PMU->isPowerChannelEnable(XPOWERS_LDO3) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_LDO3)); + } + if (PMU->isChannelAvailable(XPOWERS_ALDO1)) { + Serial.printf("ALDO1: %s Voltage: %04u mV \n", PMU->isPowerChannelEnable(XPOWERS_ALDO1) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_ALDO1)); + } + if (PMU->isChannelAvailable(XPOWERS_ALDO2)) { + Serial.printf("ALDO2: %s Voltage: %04u mV \n", PMU->isPowerChannelEnable(XPOWERS_ALDO2) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_ALDO2)); + } + if (PMU->isChannelAvailable(XPOWERS_ALDO3)) { + Serial.printf("ALDO3: %s Voltage: %04u mV \n", PMU->isPowerChannelEnable(XPOWERS_ALDO3) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_ALDO3)); + } + if (PMU->isChannelAvailable(XPOWERS_ALDO4)) { + Serial.printf("ALDO4: %s Voltage: %04u mV \n", PMU->isPowerChannelEnable(XPOWERS_ALDO4) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_ALDO4)); + } + if (PMU->isChannelAvailable(XPOWERS_BLDO1)) { + Serial.printf("BLDO1: %s Voltage: %04u mV \n", PMU->isPowerChannelEnable(XPOWERS_BLDO1) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_BLDO1)); + } + if (PMU->isChannelAvailable(XPOWERS_BLDO2)) { + Serial.printf("BLDO2: %s Voltage: %04u mV \n", PMU->isPowerChannelEnable(XPOWERS_BLDO2) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_BLDO2)); + } + Serial.printf("=========================================\n"); + + + // Set the time of pressing the button to turn off + PMU->setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S); + uint8_t opt = PMU->getPowerKeyPressOffTime(); + Serial.print("PowerKeyPressOffTime:"); + switch (opt) { + case XPOWERS_POWEROFF_4S: Serial.println("4 Second"); + break; + case XPOWERS_POWEROFF_6S: Serial.println("6 Second"); + break; + case XPOWERS_POWEROFF_8S: Serial.println("8 Second"); + break; + case XPOWERS_POWEROFF_10S: Serial.println("10 Second"); + break; + default: + break; + } + + return true; +} + +void disablePeripherals() +{ +} +#else +#define initPMU() +#define disablePeripherals() +#endif + +SPIClass SDSPI(HSPI); + + +void initBoard() +{ + Serial.begin(115200); + Serial.println("initBoard"); + SPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN); + + + Wire.begin(I2C_SDA, I2C_SCL); + + +#ifdef I2C1_SDA + Wire1.begin(I2C1_SDA, I2C1_SCL); +#endif + + +#ifdef RADIO_TCXO_EN_PIN + pinMode(RADIO_TCXO_EN_PIN, OUTPUT); + digitalWrite(RADIO_TCXO_EN_PIN, HIGH); +#endif + +#ifdef HAS_GPS + Serial1.begin(GPS_BAUD_RATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN); +#endif + +#if OLED_RST + pinMode(OLED_RST, OUTPUT); + digitalWrite(OLED_RST, HIGH); delay(20); + digitalWrite(OLED_RST, LOW); delay(20); + digitalWrite(OLED_RST, HIGH); delay(20); +#endif + + initPMU(); + + +#ifdef BOARD_LED + /* + * T-BeamV1.0, V1.1 LED defaults to low level as trun on, + * so it needs to be forced to pull up + * * * * */ +#if LED_ON == LOW + gpio_hold_dis(GPIO_NUM_4); +#endif + pinMode(BOARD_LED, OUTPUT); + digitalWrite(BOARD_LED, LED_ON); +#endif + + +#ifdef HAS_DISPLAY + Wire.beginTransmission(0x3C); + if (Wire.endTransmission() == 0) { + Serial.println("Started OLED"); + u8g2 = new DISPLAY_MODEL(U8G2_R0, U8X8_PIN_NONE); + u8g2->begin(); + u8g2->clearBuffer(); + u8g2->setFlipMode(0); + u8g2->setFontMode(1); // Transparent + u8g2->setDrawColor(1); + u8g2->setFontDirection(0); + u8g2->firstPage(); + do { + u8g2->setFont(u8g2_font_inb19_mr); + u8g2->drawStr(0, 30, "LilyGo"); + u8g2->drawHLine(2, 35, 47); + u8g2->drawHLine(3, 36, 47); + u8g2->drawVLine(45, 32, 12); + u8g2->drawVLine(46, 33, 12); + u8g2->setFont(u8g2_font_inb19_mf); + u8g2->drawStr(58, 60, "LoRa"); + } while ( u8g2->nextPage() ); + u8g2->sendBuffer(); + u8g2->setFont(u8g2_font_fur11_tf); + delay(3000); + } +#endif + + +#ifdef HAS_SDCARD + if (u8g2) { + u8g2->setFont(u8g2_font_ncenB08_tr); + } + pinMode(SDCARD_MISO, INPUT_PULLUP); + SDSPI.begin(SDCARD_SCLK, SDCARD_MISO, SDCARD_MOSI, SDCARD_CS); + if (u8g2) { + u8g2->clearBuffer(); + } + + if (!SD.begin(SDCARD_CS, SDSPI)) { + + Serial.println("setupSDCard FAIL"); + if (u8g2) { + do { + u8g2->setCursor(0, 16); + u8g2->println( "SDCard FAILED");; + } while ( u8g2->nextPage() ); + } + + } else { + uint32_t cardSize = SD.cardSize() / (1024 * 1024); + if (u8g2) { + do { + u8g2->setCursor(0, 16); + u8g2->print( "SDCard:");; + u8g2->print(cardSize / 1024.0);; + u8g2->println(" GB");; + } while ( u8g2->nextPage() ); + } + + Serial.print("setupSDCard PASS . SIZE = "); + Serial.print(cardSize / 1024.0); + Serial.println(" GB"); + } + if (u8g2) { + u8g2->sendBuffer(); + } + delay(3000); +#endif + +#ifdef HAS_DISPLAY + if (u8g2) { + u8g2->clearBuffer(); + do { + u8g2->setCursor(0, 16); + u8g2->println( "Waiting to receive data");; + } while ( u8g2->nextPage() ); + } +#endif + +} + + diff --git a/examples/PMU/utilities.h b/examples/PMU/utilities.h new file mode 100644 index 0000000..5b8d83a --- /dev/null +++ b/examples/PMU/utilities.h @@ -0,0 +1,272 @@ + +#pragma once + +/* +* This sample program only supports SX1262 +* */ +// #define LILYGO_TBeam_V0_7 +// #define LILYGO_TBeam_V1_X +// #define LILYGO_TBeamS3_SUPREME_V3_0 +// #define LILYGO_T3_V1_0 +// #define LILYGO_T3_V1_3 +// #define LILYGO_T3_V1_6 +// #define LILYGO_T3_V2_0 +// #define LILYGO_T3_S3_V1_0 +/* +* The default program uses 868MHz, +* if you need to change it, +* please open this note and change to the frequency you need to test +* */ + +#ifndef LoRa_frequency +#define LoRa_frequency 868.0 +#endif + + +#define UNUSE_PIN (0) + +#if defined(LILYGO_TBeam_V0_7) +#define GPS_RX_PIN 12 +#define GPS_TX_PIN 15 +#define BUTTON_PIN 39 +#define BUTTON_PIN_MASK GPIO_SEL_39 +#define I2C_SDA 21 +#define I2C_SCL 22 + +#define RADIO_SCLK_PIN 5 +#define RADIO_MISO_PIN 19 +#define RADIO_MOSI_PIN 27 +#define RADIO_CS_PIN 18 +#define RADIO_DIO0_PIN 26 +#define RADIO_RST_PIN 23 +#define RADIO_DIO1_PIN 33 +#define RADIO_BUSY_PIN 32 + +#define BOARD_LED 14 +#define LED_ON HIGH +#define LED_OFF LOW + +#define GPS_BAUD_RATE 9600 +#define HAS_GPS +#define HAS_DISPLAY //Optional, bring your own board, no OLED !! + +#elif defined(LILYGO_TBeam_V1_X) + +#define GPS_RX_PIN 34 +#define GPS_TX_PIN 12 +#define BUTTON_PIN 38 +#define BUTTON_PIN_MASK GPIO_SEL_38 +#define I2C_SDA 21 +#define I2C_SCL 22 +#define PMU_IRQ 35 + +#define RADIO_SCLK_PIN 5 +#define RADIO_MISO_PIN 19 +#define RADIO_MOSI_PIN 27 +#define RADIO_CS_PIN 18 +#define RADIO_DIO0_PIN 26 +#define RADIO_RST_PIN 23 +#define RADIO_DIO1_PIN 33 +#define RADIO_BUSY_PIN 32 + +#define BOARD_LED 4 +#define LED_ON LOW +#define LED_OFF HIGH + +#define GPS_BAUD_RATE 9600 +#define HAS_GPS +#define HAS_DISPLAY //Optional, bring your own board, no OLED !! +#define HAS_PMU + + +#elif defined(LILYGO_TBeamS3_SUPREME_V3_0) + +#define I2C_SDA 17 +#define I2C_SCL 18 + +#define I2C1_SDA 42 +#define I2C1_SCL 41 +#define PMU_IRQ 40 + +#define GPS_RX_PIN 9 +#define GPS_TX_PIN 8 +#define GPS_WAKEUP_PIN 7 +#define GPS_1PPS_PIN 6 + +#define BUTTON_PIN 0 +#define BUTTON_PIN_MASK GPIO_SEL_0 +#define BUTTON_CONUT (1) +#define BUTTON_ARRAY {BUTTON_PIN} + +#define RADIO_SCLK_PIN (12) +#define RADIO_MISO_PIN (13) +#define RADIO_MOSI_PIN (11) +#define RADIO_CS_PIN (10) +#define RADIO_DIO0_PIN (-1) +#define RADIO_RST_PIN (5) +#define RADIO_DIO1_PIN (1) +#define RADIO_BUSY_PIN (4) + +#define SPI_MOSI (35) +#define SPI_SCK (36) +#define SPI_MISO (37) +#define SPI_CS (47) +#define IMU_CS (34) +#define IMU_INT (33) + +#define SDCARD_MOSI SPI_MOSI +#define SDCARD_MISO SPI_MISO +#define SDCARD_SCLK SPI_SCK +#define SDCARD_CS SPI_CS + +#define PIN_NONE (-1) +#define RTC_INT (14) + +#define GPS_BAUD_RATE 9600 + +#define HAS_SDCARD +#define HAS_GPS +#define HAS_DISPLAY +#define HAS_PMU + +#define __HAS_SPI1__ +#define __HAS_SENSOR__ + +#define PMU_WIRE_PORT Wire1 +#define DISPLAY_MODEL U8G2_SH1106_128X64_NONAME_F_HW_I2C + +#elif defined(LILYGO_T3_V1_0) +#define I2C_SDA 4 +#define I2C_SCL 15 +#define OLED_RST 16 + +#define RADIO_SCLK_PIN 5 +#define RADIO_MISO_PIN 19 +#define RADIO_MOSI_PIN 27 +#define RADIO_CS_PIN 18 +#define RADIO_DIO0_PIN 26 +#define RADIO_RST_PIN 14 +#define RADIO_DIO1_PIN 33 +#define RADIO_BUSY_PIN 32 + +#define HAS_DISPLAY + +#elif defined(LILYGO_T3_V1_3) + +#define I2C_SDA 21 +#define I2C_SCL 22 +#define OLED_RST UNUSE_PIN + +#define RADIO_SCLK_PIN 5 +#define RADIO_MISO_PIN 19 +#define RADIO_MOSI_PIN 27 +#define RADIO_CS_PIN 18 +#define RADIO_DIO0_PIN 26 +#define RADIO_RST_PIN 14 +#define RADIO_DIO1_PIN 33 +#define RADIO_BUSY_PIN 32 + +#define ADC_PIN 35 + +#define HAS_DISPLAY +#elif defined(LILYGO_T3_V1_6) +#define I2C_SDA 21 +#define I2C_SCL 22 +#define OLED_RST UNUSE_PIN + +#define RADIO_SCLK_PIN 5 +#define RADIO_MISO_PIN 19 +#define RADIO_MOSI_PIN 27 +#define RADIO_CS_PIN 18 +#define RADIO_DIO0_PIN 26 +#define RADIO_RST_PIN 23 +#define RADIO_DIO1_PIN 33 +#define RADIO_BUSY_PIN 32 + +#define SDCARD_MOSI 15 +#define SDCARD_MISO 2 +#define SDCARD_SCLK 14 +#define SDCARD_CS 13 + +#define BOARD_LED 25 +#define LED_ON HIGH + +#define ADC_PIN 35 + +#define HAS_SDCARD +#define HAS_DISPLAY + +#elif defined(LILYGO_T3_V2_0) +#define I2C_SDA 21 +#define I2C_SCL 22 +#define OLED_RST UNUSE_PIN + +#define RADIO_SCLK_PIN 5 +#define RADIO_MISO_PIN 19 +#define RADIO_MOSI_PIN 27 +#define RADIO_CS_PIN 18 +#define RADIO_DIO0_PIN 26 +#define RADIO_RST_PIN 14 +#define RADIO_DIO1_PIN UNUSE_PIN +#define RADIO_BUSY_PIN UNUSE_PIN + +#define SDCARD_MOSI 15 +#define SDCARD_MISO 2 +#define SDCARD_SCLK 14 +#define SDCARD_CS 13 + +#define BOARD_LED 0 +#define LED_ON LOW + +#define HAS_DISPLAY +#define HAS_SDCARD + + +#elif defined(LILYGO_T3_S3_V1_0) || defined(LILYGO_T3_S3_V1_2) + +#define I2C_SDA 18 +#define I2C_SCL 17 +#define OLED_RST UNUSE_PIN + +#define RADIO_SCLK_PIN 5 +#define RADIO_MISO_PIN 3 +#define RADIO_MOSI_PIN 6 +#define RADIO_CS_PIN 7 +#define RADIO_DIO1_PIN 33 +#define RADIO_BUSY_PIN 34 +#define RADIO_RST_PIN 8 + +//!SX1276/78 module only +#define RADIO_DIO0_PIN 9 +#define RADIO_DIO3_PIN 21 +#define RADIO_DIO4_PIN 10 +#define RADIO_DIO5_PIN 36 +//! end + +#define SDCARD_MOSI 11 +#define SDCARD_MISO 2 +#define SDCARD_SCLK 14 +#define SDCARD_CS 13 + +#define BOARD_LED 37 +#define LED_ON HIGH + +#define BAT_ADC_PIN 1 +#define BUTTON_PIN 0 + +#define HAS_SDCARD +#define HAS_DISPLAY + + +#else +#error "For the first use, please define the board version and model in " +#endif + + + + + + + + + diff --git a/platformio.ini b/platformio.ini index a4998c5..eb887c3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -59,7 +59,7 @@ default_envs = T_BEAM_V1_x ; src_dir = examples/OLED/SH1106IconMenu ; src_dir = examples/Display/Free_Font_Demo ; src_dir = examples/Display/TFT_Char_times -src_dir = examples/Display/UTFT_demo +; src_dir = examples/Display/UTFT_demo @@ -110,6 +110,7 @@ src_dir = examples/Display/UTFT_demo ; src_dir = examples/Sensor/QMI8658_WakeOnMotion ; src_dir = examples/SleepTest ; src_dir = examples/TTN/TTN_OTTA +src_dir = examples/PMU ; src_dir = examples/T3S3Factory