Added OLED examples

This commit is contained in:
lewishe 2022-12-09 18:21:55 +08:00
commit 3427d105e4
13 changed files with 3510 additions and 4 deletions

View file

@ -1,6 +1,13 @@
## Install the following dependency library files:
## TBEAM-S3-CORE
- `TBEAM-S3-CORE` uses `SH1106` by default. Please do not run the `SSD1306` example on `TBEAM-S3-CORE`
- For more examples, please refer to U8g2/examples
## Other model uses SSD1306 display model
- [esp8266-oled-ssd1306](https://github.com/ThingPulse/esp8266-oled-ssd1306)
- For more examples, please refer to esp8266-oled-ssd1306/examples
- For more examples, please refer to esp8266-oled-ssd1306/examples

View file

@ -0,0 +1,291 @@
/*
FontUsage.ino
How to overwrite previous text with a new text.
How to avoid the buffer clear command.
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
Copyright (c) 2016, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Usually, a sequence like this is used:
u8g2->clearBuffer(); // clear the internal memory
u8g2->setFont(u8g2_font_ncenB08_tr); // choose a suitable font
u8g2->setCursor(0,20) // set write position
u8g2->print("Hello World!"); // write something to the internal memory
u8g2->sendBuffer(); // transfer internal memory to the display
In order to speed up the display content rendering for any modified text,
we could drop the clearBuffer command and just overwrite the previous string:
u8g2->setFont(u8g2_font_ncenB08_tr); // choose a suitable font
u8g2->setCursor(0,20) // set write position
u8g2->print("hello there"); // write something to the internal memory
u8g2->sendBuffer(); // transfer internal memory to the display
This will only work if:
- Background is drawn
- All gylphs have the same height
Additionally some extra spaces are required of the new text is shorter than the
previous one.
To draw the background: use font mode 0
To ensure that all glyphs have the same height, use h or m fonts.
u8g2->setFontMode(0); // write solid glyphs
u8g2->setFont(u8g2_font_ncenB08_hr); // choose a suitable h font
u8g2->setCursor(0,20) // set write position
u8g2->print("hello there "); // use extra spaces here
u8g2->sendBuffer(); // transfer internal memory to the display
*/
#include <Arduino.h>
#include "boards.h"
#define INFO_SCREEN_DELAY 3000
/*
Linear Congruential Generator (LCG)
z = (a*z + c) % m;
m = 256 (8 Bit)
for period:
a-1: dividable by 2
a-1: multiple of 4
c: not dividable by 2
c = 17
a-1 = 64 --> a = 65
*/
uint8_t z = 127; // start value
uint32_t lcg_rnd(void)
{
z = (uint8_t)((uint16_t)65 * (uint16_t)z + (uint16_t)17);
return (uint32_t)z;
}
void setup(void)
{
initBoard();
if (!u8g2) {
Serial.println("No find SH1106 display!Please check whether the connection is normal");
while (1);
}
}
void draw(int is_blank)
{
int i, j;
int n;
char s[4];
for ( j = 0; j < 20; j++ ) {
// random number
n = lcg_rnd();
// random string
for ( i = 0; i < 3; i++ ) {
s[i] = lcg_rnd() >> 3;
if ( s[i] < 16 )
s[i] += 'a';
else
s[i] += 'A';
}
s[3] = '\0';
// print number
u8g2->setCursor(0, 15);
u8g2->print("Number: ");
if ( is_blank )
u8g2->print(" ");
u8g2->setCursor(70, 15);
u8g2->print(n);
// print string
u8g2->setCursor(0, 30);
u8g2->print("Text: ");
u8g2->setCursor(70, 30);
u8g2->print(s);
if ( is_blank )
u8g2->print(" ");
// make the result visible
u8g2->sendBuffer();
// delay, so that the user can see the result
delay(200);
}
}
void draw_m1_t()
{
u8g2->clearBuffer();
u8g2->setFontMode(1);
u8g2->setFont(u8g2_font_cu12_tr);
u8g2->setCursor(0, 15);
u8g2->print(F("setFontMode(1);"));
u8g2->setCursor(0, 30);
u8g2->print(F("setFont(..._tr);"));
u8g2->setCursor(0, 55);
u8g2->print(F("Very Bad"));
u8g2->sendBuffer();
delay(INFO_SCREEN_DELAY);
u8g2->setFontMode(1);
u8g2->setFont(u8g2_font_cu12_tr);
u8g2->clearBuffer(); // clear the internal memory once
draw(0);
}
void draw_m0_t()
{
u8g2->clearBuffer();
u8g2->setFontMode(1);
u8g2->setFont(u8g2_font_cu12_tr);
u8g2->setCursor(0, 15);
u8g2->print(F("setFontMode(0);"));
u8g2->setCursor(0, 30);
u8g2->print(F("setFont(.._tr);"));
u8g2->setCursor(0, 55);
u8g2->print(F("Wrong"));
u8g2->sendBuffer();
delay(INFO_SCREEN_DELAY);
u8g2->setFontMode(0);
u8g2->setFont(u8g2_font_cu12_tr);
u8g2->clearBuffer(); // clear the internal memory once
draw(0);
}
void draw_m1_h()
{
u8g2->clearBuffer();
u8g2->setFontMode(1);
u8g2->setFont(u8g2_font_cu12_tr);
u8g2->setCursor(0, 15);
u8g2->print(F("setFontMode(0);"));
u8g2->setCursor(0, 30);
u8g2->print(F("setFont(.._hr);"));
u8g2->setCursor(0, 55);
u8g2->print(F("Still bad"));
u8g2->sendBuffer();
delay(INFO_SCREEN_DELAY);
u8g2->setFontMode(1);
u8g2->setFont(u8g2_font_cu12_hr);
u8g2->clearBuffer(); // clear the internal memory once
draw(0);
}
void draw_m0_h()
{
u8g2->clearBuffer();
u8g2->setFontMode(1);
u8g2->setFont(u8g2_font_cu12_tr);
u8g2->setCursor(0, 15);
u8g2->print(F("setFontMode(0);"));
u8g2->setCursor(0, 30);
u8g2->print(F("setFont(.._hr);"));
u8g2->setCursor(0, 55);
u8g2->print(F("Almost ok"));
u8g2->sendBuffer();
delay(INFO_SCREEN_DELAY);
u8g2->setFontMode(0);
u8g2->setFont(u8g2_font_cu12_hr);
u8g2->clearBuffer(); // clear the internal memory once
draw(0);
}
void draw_m0_h_with_extra_blank()
{
u8g2->clearBuffer();
u8g2->setFontMode(1);
u8g2->setFont(u8g2_font_cu12_tr);
u8g2->setCursor(0, 15);
u8g2->print(F("setFontMode(0);"));
u8g2->setCursor(0, 30);
u8g2->print(F("setFont(.._hr);"));
u8g2->setCursor(0, 55);
u8g2->print(F("Extra blank --> Ok"));
u8g2->sendBuffer();
delay(INFO_SCREEN_DELAY);
u8g2->setFontMode(0);
u8g2->setFont(u8g2_font_cu12_hr);
u8g2->clearBuffer(); // clear the internal memory once
draw(1);
}
void loop(void)
{
// This problem applies only to full buffer mode
u8g2->clearBuffer();
u8g2->setFontMode(1);
u8g2->setFont(u8g2_font_cu12_tr);
u8g2->setCursor(0, 15);
u8g2->print(F("Problems with"));
u8g2->setCursor(0, 30);
u8g2->print(F("full buffer mode"));
u8g2->setCursor(0, 45);
u8g2->print(F("and skipped clear."));
u8g2->sendBuffer();
delay(INFO_SCREEN_DELAY);
draw_m1_t(); // fontmode 1, t font --> wrong
draw_m1_h(); // fontmode 1, h font --> wrong
draw_m0_t(); // fontmode 0, t font --> wrong
draw_m0_h(); // fontmode 1, h font --> ok
draw_m0_h_with_extra_blank(); // fontmode 1, h font with extra blank --> correct
delay(1000);
}

View file

@ -0,0 +1,401 @@
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include "utilities.h"
#ifdef HAS_SDCARD
#include <SD.h>
#include <FS.h>
#endif
#ifdef HAS_DISPLAY
#include <U8g2lib.h>
#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 "XPowersAXP2101.tpp"
#include "XPowersAXP192.tpp"
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(LILYGO_TBeam_S3_Core_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 LILYGO_T3_S3_V1_0
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
}

View file

@ -0,0 +1,270 @@
#pragma once
// #define LILYGO_TBeam_V0_7
// #define LILYGO_TBeam_V1_X
// #define LILYGO_TBeam_S3_Core_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_DI0_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_DI0_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_TBeam_S3_Core_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_DI0_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_DI0_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_DI0_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_DI0_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_DI0_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)
#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_DIO0_PIN 9
#define RADIO_TCXO_EN_PIN 33
#define RADIO_DIO1_PIN 33
#define RADIO_BUSY_PIN 36
#define RADIO_RST_PIN 8
#define RADIO_DIO2_PIN 34
#define RADIO_DIO5_PIN 36
#define RADIO_RX_PIN 21
#define RADIO_TX_PIN 10
#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 <utilities. h>"
#endif

View file

@ -0,0 +1,275 @@
/*
GraphicsTest.ino
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
Copyright (c) 2016, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <Arduino.h>
#include "boards.h"
void u8g2_prepare(void)
{
u8g2->setFont(u8g2_font_6x10_tf);
u8g2->setFontRefHeightExtendedText();
u8g2->setDrawColor(1);
u8g2->setFontPosTop();
u8g2->setFontDirection(0);
}
void u8g2_box_frame(uint8_t a)
{
u8g2->drawStr( 0, 0, "drawBox");
u8g2->drawBox(5, 10, 20, 10);
u8g2->drawBox(10 + a, 15, 30, 7);
u8g2->drawStr( 0, 30, "drawFrame");
u8g2->drawFrame(5, 10 + 30, 20, 10);
u8g2->drawFrame(10 + a, 15 + 30, 30, 7);
}
void u8g2_disc_circle(uint8_t a)
{
u8g2->drawStr( 0, 0, "drawDisc");
u8g2->drawDisc(10, 18, 9);
u8g2->drawDisc(24 + a, 16, 7);
u8g2->drawStr( 0, 30, "drawCircle");
u8g2->drawCircle(10, 18 + 30, 9);
u8g2->drawCircle(24 + a, 16 + 30, 7);
}
void u8g2_r_frame(uint8_t a)
{
u8g2->drawStr( 0, 0, "drawRFrame/Box");
u8g2->drawRFrame(5, 10, 40, 30, a + 1);
u8g2->drawRBox(50, 10, 25, 40, a + 1);
}
void u8g2_string(uint8_t a)
{
u8g2->setFontDirection(0);
u8g2->drawStr(30 + a, 31, " 0");
u8g2->setFontDirection(1);
u8g2->drawStr(30, 31 + a, " 90");
u8g2->setFontDirection(2);
u8g2->drawStr(30 - a, 31, " 180");
u8g2->setFontDirection(3);
u8g2->drawStr(30, 31 - a, " 270");
}
void u8g2_line(uint8_t a)
{
u8g2->drawStr( 0, 0, "drawLine");
u8g2->drawLine(7 + a, 10, 40, 55);
u8g2->drawLine(7 + a * 2, 10, 60, 55);
u8g2->drawLine(7 + a * 3, 10, 80, 55);
u8g2->drawLine(7 + a * 4, 10, 100, 55);
}
void u8g2_triangle(uint8_t a)
{
uint16_t offset = a;
u8g2->drawStr( 0, 0, "drawTriangle");
u8g2->drawTriangle(14, 7, 45, 30, 10, 40);
u8g2->drawTriangle(14 + offset, 7 - offset, 45 + offset, 30 - offset, 57 + offset, 10 - offset);
u8g2->drawTriangle(57 + offset * 2, 10, 45 + offset * 2, 30, 86 + offset * 2, 53);
u8g2->drawTriangle(10 + offset, 40 + offset, 45 + offset, 30 + offset, 86 + offset, 53 + offset);
}
void u8g2_ascii_1()
{
char s[2] = " ";
uint8_t x, y;
u8g2->drawStr( 0, 0, "ASCII page 1");
for ( y = 0; y < 6; y++ ) {
for ( x = 0; x < 16; x++ ) {
s[0] = y * 16 + x + 32;
u8g2->drawStr(x * 7, y * 10 + 10, s);
}
}
}
void u8g2_ascii_2()
{
char s[2] = " ";
uint8_t x, y;
u8g2->drawStr( 0, 0, "ASCII page 2");
for ( y = 0; y < 6; y++ ) {
for ( x = 0; x < 16; x++ ) {
s[0] = y * 16 + x + 160;
u8g2->drawStr(x * 7, y * 10 + 10, s);
}
}
}
void u8g2_extra_page(uint8_t a)
{
u8g2->drawStr( 0, 0, "Unicode");
u8g2->setFont(u8g2_font_unifont_t_symbols);
u8g2->setFontPosTop();
u8g2->drawUTF8(0, 24, "☀ ☁");
switch (a) {
case 0:
case 1:
case 2:
case 3:
u8g2->drawUTF8(a * 3, 36, "");
break;
case 4:
case 5:
case 6:
case 7:
u8g2->drawUTF8(a * 3, 36, "");
break;
}
}
#define cross_width 24
#define cross_height 24
static const unsigned char cross_bits[] U8X8_PROGMEM = {
0x00, 0x18, 0x00, 0x00, 0x24, 0x00, 0x00, 0x24, 0x00, 0x00, 0x42, 0x00,
0x00, 0x42, 0x00, 0x00, 0x42, 0x00, 0x00, 0x81, 0x00, 0x00, 0x81, 0x00,
0xC0, 0x00, 0x03, 0x38, 0x3C, 0x1C, 0x06, 0x42, 0x60, 0x01, 0x42, 0x80,
0x01, 0x42, 0x80, 0x06, 0x42, 0x60, 0x38, 0x3C, 0x1C, 0xC0, 0x00, 0x03,
0x00, 0x81, 0x00, 0x00, 0x81, 0x00, 0x00, 0x42, 0x00, 0x00, 0x42, 0x00,
0x00, 0x42, 0x00, 0x00, 0x24, 0x00, 0x00, 0x24, 0x00, 0x00, 0x18, 0x00,
};
#define cross_fill_width 24
#define cross_fill_height 24
static const unsigned char cross_fill_bits[] U8X8_PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x64, 0x00, 0x26,
0x84, 0x00, 0x21, 0x08, 0x81, 0x10, 0x08, 0x42, 0x10, 0x10, 0x3C, 0x08,
0x20, 0x00, 0x04, 0x40, 0x00, 0x02, 0x80, 0x00, 0x01, 0x80, 0x18, 0x01,
0x80, 0x18, 0x01, 0x80, 0x00, 0x01, 0x40, 0x00, 0x02, 0x20, 0x00, 0x04,
0x10, 0x3C, 0x08, 0x08, 0x42, 0x10, 0x08, 0x81, 0x10, 0x84, 0x00, 0x21,
0x64, 0x00, 0x26, 0x18, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
#define cross_block_width 14
#define cross_block_height 14
static const unsigned char cross_block_bits[] U8X8_PROGMEM = {
0xFF, 0x3F, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20,
0xC1, 0x20, 0xC1, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20,
0x01, 0x20, 0xFF, 0x3F,
};
void u8g2_bitmap_overlay(uint8_t a)
{
uint8_t frame_size = 28;
u8g2->drawStr(0, 0, "Bitmap overlay");
u8g2->drawStr(0, frame_size + 12, "Solid / transparent");
u8g2->setBitmapMode(false /* solid */);
u8g2->drawFrame(0, 10, frame_size, frame_size);
u8g2->drawXBMP(2, 12, cross_width, cross_height, cross_bits);
if (a & 4)
u8g2->drawXBMP(7, 17, cross_block_width, cross_block_height, cross_block_bits);
u8g2->setBitmapMode(true /* transparent*/);
u8g2->drawFrame(frame_size + 5, 10, frame_size, frame_size);
u8g2->drawXBMP(frame_size + 7, 12, cross_width, cross_height, cross_bits);
if (a & 4)
u8g2->drawXBMP(frame_size + 12, 17, cross_block_width, cross_block_height, cross_block_bits);
}
void u8g2_bitmap_modes(uint8_t transparent)
{
const uint8_t frame_size = 24;
u8g2->drawBox(0, frame_size * 0.5, frame_size * 5, frame_size);
u8g2->drawStr(frame_size * 0.5, 50, "Black");
u8g2->drawStr(frame_size * 2, 50, "White");
u8g2->drawStr(frame_size * 3.5, 50, "XOR");
if (!transparent) {
u8g2->setBitmapMode(false /* solid */);
u8g2->drawStr(0, 0, "Solid bitmap");
} else {
u8g2->setBitmapMode(true /* transparent*/);
u8g2->drawStr(0, 0, "Transparent bitmap");
}
u8g2->setDrawColor(0);// Black
u8g2->drawXBMP(frame_size * 0.5, 24, cross_width, cross_height, cross_bits);
u8g2->setDrawColor(1); // White
u8g2->drawXBMP(frame_size * 2, 24, cross_width, cross_height, cross_bits);
u8g2->setDrawColor(2); // XOR
u8g2->drawXBMP(frame_size * 3.5, 24, cross_width, cross_height, cross_bits);
}
uint8_t draw_state = 0;
void draw(void)
{
u8g2_prepare();
switch (draw_state >> 3) {
case 0: u8g2_box_frame(draw_state & 7); break;
case 1: u8g2_disc_circle(draw_state & 7); break;
case 2: u8g2_r_frame(draw_state & 7); break;
case 3: u8g2_string(draw_state & 7); break;
case 4: u8g2_line(draw_state & 7); break;
case 5: u8g2_triangle(draw_state & 7); break;
case 6: u8g2_ascii_1(); break;
case 7: u8g2_ascii_2(); break;
case 8: u8g2_extra_page(draw_state & 7); break;
case 9: u8g2_bitmap_modes(0); break;
case 10: u8g2_bitmap_modes(1); break;
case 11: u8g2_bitmap_overlay(draw_state & 7); break;
}
}
void setup(void)
{
initBoard();
if (!u8g2) {
Serial.println("No find SH1106 display!Please check whether the connection is normal");
while (1);
}
}
void loop(void)
{
// picture loop
u8g2->clearBuffer();
draw();
u8g2->sendBuffer();
// increase the state
draw_state++;
if ( draw_state >= 12 * 8 )
draw_state = 0;
// deley between each page
delay(100);
}

View file

@ -0,0 +1,401 @@
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include "utilities.h"
#ifdef HAS_SDCARD
#include <SD.h>
#include <FS.h>
#endif
#ifdef HAS_DISPLAY
#include <U8g2lib.h>
#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 "XPowersAXP2101.tpp"
#include "XPowersAXP192.tpp"
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(LILYGO_TBeam_S3_Core_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 LILYGO_T3_S3_V1_0
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
}

View file

@ -0,0 +1,270 @@
#pragma once
// #define LILYGO_TBeam_V0_7
// #define LILYGO_TBeam_V1_X
// #define LILYGO_TBeam_S3_Core_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_DI0_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_DI0_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_TBeam_S3_Core_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_DI0_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_DI0_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_DI0_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_DI0_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_DI0_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)
#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_DIO0_PIN 9
#define RADIO_TCXO_EN_PIN 33
#define RADIO_DIO1_PIN 33
#define RADIO_BUSY_PIN 36
#define RADIO_RST_PIN 8
#define RADIO_DIO2_PIN 34
#define RADIO_DIO5_PIN 36
#define RADIO_RX_PIN 21
#define RADIO_TX_PIN 10
#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 <utilities. h>"
#endif

View file

@ -0,0 +1,184 @@
/*
IconMenu.ino
This is an interactive demo and requires "next", "prev" and "select" button.
Minimum height of the display should be 64.
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
Copyright (c) 2016, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <Arduino.h>
#include "boards.h"
void setup(void)
{
initBoard();
if (!u8g2) {
Serial.println("No find SH1106 display!Please check whether the connection is normal");
while (1);
}
u8g2->setFont(u8g2_font_6x12_tr);
}
struct menu_entry_type {
const uint8_t *font;
uint16_t icon;
const char *name;
};
struct menu_state {
int16_t menu_start; /* in pixel */
int16_t frame_position; /* in pixel */
uint8_t position; /* position, array index */
};
/*
Icon configuration
Width and height must match the icon font size
GAP: Space between the icons
BGAP: Gap between the display border and the cursor.
*/
#define ICON_WIDTH 32
#define ICON_HEIGHT 32
#define ICON_GAP 4
#define ICON_BGAP 16
#define ICON_Y 32+ ICON_GAP
struct menu_entry_type menu_entry_list[] = {
{ u8g2_font_open_iconic_embedded_4x_t, 65, "Clock Setup"},
{ u8g2_font_open_iconic_embedded_4x_t, 66, "Gear Game"},
{ u8g2_font_open_iconic_embedded_4x_t, 67, "Flash Light"},
{ u8g2_font_open_iconic_embedded_4x_t, 68, "Home"},
{ u8g2_font_open_iconic_embedded_4x_t, 72, "Configuration"},
{ NULL, 0, NULL }
};
void draw(struct menu_state *state)
{
int16_t x;
uint8_t i;
x = state->menu_start;
i = 0;
while ( menu_entry_list[i].icon > 0 ) {
if ( x >= -ICON_WIDTH && x < u8g2->getDisplayWidth() ) {
u8g2->setFont(menu_entry_list[i].font);
u8g2->drawGlyph(x, ICON_Y, menu_entry_list[i].icon );
}
i++;
x += ICON_WIDTH + ICON_GAP;
}
u8g2->drawFrame(state->frame_position - 1, ICON_Y - ICON_HEIGHT - 1, ICON_WIDTH + 2, ICON_WIDTH + 2);
u8g2->drawFrame(state->frame_position - 2, ICON_Y - ICON_HEIGHT - 2, ICON_WIDTH + 4, ICON_WIDTH + 4);
u8g2->drawFrame(state->frame_position - 3, ICON_Y - ICON_HEIGHT - 3, ICON_WIDTH + 6, ICON_WIDTH + 6);
}
void to_right(struct menu_state *state)
{
if ( menu_entry_list[state->position + 1].font != NULL ) {
if ( (int16_t)state->frame_position + 2 * (int16_t)ICON_WIDTH + (int16_t)ICON_BGAP < (int16_t)u8g2->getDisplayWidth() ) {
state->position++;
state->frame_position += ICON_WIDTH + (int16_t)ICON_GAP;
} else {
state->position++;
state->frame_position = (int16_t)u8g2->getDisplayWidth() - (int16_t)ICON_WIDTH - (int16_t)ICON_BGAP;
state->menu_start = state->frame_position - state->position * ((int16_t)ICON_WIDTH + (int16_t)ICON_GAP);
}
}
}
void to_left(struct menu_state *state)
{
if ( state->position > 0 ) {
if ( (int16_t)state->frame_position >= (int16_t)ICON_BGAP + (int16_t)ICON_WIDTH + (int16_t)ICON_GAP ) {
state->position--;
state->frame_position -= ICON_WIDTH + (int16_t)ICON_GAP;
} else {
state->position--;
state->frame_position = ICON_BGAP;
state->menu_start = state->frame_position - state->position * ((int16_t)ICON_WIDTH + (int16_t)ICON_GAP);
}
}
}
uint8_t towards_int16(int16_t *current, int16_t dest)
{
if ( *current < dest ) {
(*current)++;
return 1;
} else if ( *current > dest ) {
(*current)--;
return 1;
}
return 0;
}
uint8_t towards(struct menu_state *current, struct menu_state *destination)
{
uint8_t r = 0;
r |= towards_int16( &(current->frame_position), destination->frame_position);
r |= towards_int16( &(current->frame_position), destination->frame_position);
r |= towards_int16( &(current->menu_start), destination->menu_start);
r |= towards_int16( &(current->menu_start), destination->menu_start);
return r;
}
struct menu_state current_state = { ICON_BGAP, ICON_BGAP, 0 };
struct menu_state destination_state = { ICON_BGAP, ICON_BGAP, 0 };
void loop(void)
{
int8_t event;
do {
u8g2->clearBuffer();
draw(&current_state);
u8g2->setFont(u8g2_font_helvB10_tr);
u8g2->setCursor((u8g2->getDisplayWidth() - u8g2->getStrWidth(menu_entry_list[destination_state.position].name)) / 2, u8g2->getDisplayHeight() - 5);
u8g2->print(menu_entry_list[destination_state.position].name);
u8g2->sendBuffer();
delay(10);
event = u8g2->getMenuEvent();
if ( event == U8X8_MSG_GPIO_MENU_NEXT )
to_right(&destination_state);
if ( event == U8X8_MSG_GPIO_MENU_PREV )
to_left(&destination_state);
if ( event == U8X8_MSG_GPIO_MENU_SELECT ) {
u8g2->setFont(u8g2_font_helvB10_tr);
u8g2->userInterfaceMessage("Selection:", menu_entry_list[destination_state.position].name, "", " Ok ");
}
} while ( towards(&current_state, &destination_state) );
}

View file

@ -0,0 +1,401 @@
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include "utilities.h"
#ifdef HAS_SDCARD
#include <SD.h>
#include <FS.h>
#endif
#ifdef HAS_DISPLAY
#include <U8g2lib.h>
#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 "XPowersAXP2101.tpp"
#include "XPowersAXP192.tpp"
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(LILYGO_TBeam_S3_Core_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 LILYGO_T3_S3_V1_0
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
}

View file

@ -0,0 +1,270 @@
#pragma once
// #define LILYGO_TBeam_V0_7
// #define LILYGO_TBeam_V1_X
// #define LILYGO_TBeam_S3_Core_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_DI0_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_DI0_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_TBeam_S3_Core_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_DI0_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_DI0_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_DI0_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_DI0_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_DI0_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)
#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_DIO0_PIN 9
#define RADIO_TCXO_EN_PIN 33
#define RADIO_DIO1_PIN 33
#define RADIO_BUSY_PIN 36
#define RADIO_RST_PIN 8
#define RADIO_DIO2_PIN 34
#define RADIO_DIO5_PIN 36
#define RADIO_RX_PIN 21
#define RADIO_TX_PIN 10
#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 <utilities. h>"
#endif

View file

@ -0,0 +1,65 @@
/*
PrintUTF8.ino
Use the (Arduino compatible) u8g2 function "print" to draw a text.
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
Copyright (c) 2016, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <Arduino.h>
#include "boards.h"
void setup(void)
{
initBoard();
if (!u8g2) {
Serial.println("No find SH1106 display!Please check whether the connection is normal");
while (1);
}
u8g2->enableUTF8Print(); // enable UTF8 support for the Arduino print() function
}
void loop(void)
{
u8g2->setFont(u8g2_font_unifont_t_chinese2); // use chinese2 for all the glyphs of "你好世界"
u8g2->setFontDirection(0);
u8g2->clearBuffer();
u8g2->setCursor(0, 15);
u8g2->print("Hello World!");
u8g2->setCursor(0, 40);
u8g2->print("你好世界"); // Chinese "Hello World"
u8g2->sendBuffer();
delay(1000);
}

View file

@ -0,0 +1,401 @@
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include "utilities.h"
#ifdef HAS_SDCARD
#include <SD.h>
#include <FS.h>
#endif
#ifdef HAS_DISPLAY
#include <U8g2lib.h>
#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 "XPowersAXP2101.tpp"
#include "XPowersAXP192.tpp"
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(LILYGO_TBeam_S3_Core_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 LILYGO_T3_S3_V1_0
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
}

View file

@ -0,0 +1,270 @@
#pragma once
// #define LILYGO_TBeam_V0_7
// #define LILYGO_TBeam_V1_X
// #define LILYGO_TBeam_S3_Core_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_DI0_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_DI0_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_TBeam_S3_Core_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_DI0_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_DI0_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_DI0_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_DI0_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_DI0_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)
#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_DIO0_PIN 9
#define RADIO_TCXO_EN_PIN 33
#define RADIO_DIO1_PIN 33
#define RADIO_BUSY_PIN 36
#define RADIO_RST_PIN 8
#define RADIO_DIO2_PIN 34
#define RADIO_DIO5_PIN 36
#define RADIO_RX_PIN 21
#define RADIO_TX_PIN 10
#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 <utilities. h>"
#endif