Update SensorsLib
This commit is contained in:
parent
672a563dc3
commit
3d5db1dac5
14 changed files with 1888 additions and 4 deletions
|
|
@ -0,0 +1,196 @@
|
|||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2022 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file PCF8563_AlarmByUnits.ino
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2022-12-11
|
||||
*
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#include <Arduino.h>
|
||||
#include <time.h>
|
||||
#include "SensorPCF8563.tpp"
|
||||
|
||||
#ifdef ESP32
|
||||
#define I2C_SDA 42
|
||||
#define I2C_SCL 41
|
||||
#define RTC_IRQ 14
|
||||
#else
|
||||
#define _PINNUM(port, pin) ((port)*32 + (pin))
|
||||
#define I2C_SDA _PINNUM(0,26)
|
||||
#define I2C_SCL _PINNUM(0,27)
|
||||
#define RTC_IRQ _PINNUM(0,16)
|
||||
#endif
|
||||
|
||||
|
||||
SensorPCF8563 rtc;
|
||||
|
||||
|
||||
uint32_t lastMillis = 0;
|
||||
uint8_t nextHour = 22;
|
||||
uint8_t nextMonth = 1;
|
||||
uint8_t nextDay = 1;
|
||||
uint8_t nextMinute = 59;
|
||||
uint8_t nextSecond = 55;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
#ifdef LILYGO_TBEAM_SUPREME_V3_0
|
||||
extern bool setupPower();
|
||||
setupPower();
|
||||
#endif
|
||||
|
||||
if (!rtc.begin(Wire, PCF8563_SLAVE_ADDRESS, I2C_SDA, I2C_SCL)) {
|
||||
Serial.println("Failed to find PCF8563 - check your wiring!");
|
||||
while (1) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
pinMode(RTC_IRQ, INPUT_PULLUP);
|
||||
|
||||
rtc.setDateTime(2022, nextMonth, nextDay, nextHour, nextMinute, nextSecond);
|
||||
|
||||
// From minute timer
|
||||
rtc.setAlarmByMinutes(0);
|
||||
|
||||
rtc.enableAlarm();
|
||||
|
||||
}
|
||||
|
||||
void printDateTime()
|
||||
{
|
||||
if (millis() - lastMillis > 1000) {
|
||||
/**
|
||||
/// Format output time*
|
||||
Option:
|
||||
DATETIME_FORMAT_HM
|
||||
DATETIME_FORMAT_HMS
|
||||
DATETIME_FORMAT_YYYY_MM_DD
|
||||
DATETIME_FORMAT_MM_DD_YYYY
|
||||
DATETIME_FORMAT_DD_MM_YYYY
|
||||
DATETIME_FORMAT_YYYY_MM_DD_H_M_S
|
||||
default: DATETIME_FORMAT_YYYY_MM_DD_H_M_S_WEEK
|
||||
*/
|
||||
Serial.println(rtc.strftime());
|
||||
|
||||
lastMillis = millis();
|
||||
}
|
||||
}
|
||||
|
||||
// Test minute timing
|
||||
void testAlarmMinute()
|
||||
{
|
||||
while (1) {
|
||||
if (digitalRead(RTC_IRQ) == LOW) {
|
||||
Serial.println("testAlarmMinute Interrupt .... ");
|
||||
if (rtc.isAlarmActive()) {
|
||||
Serial.println("Alarm active");
|
||||
rtc.resetAlarm();
|
||||
rtc.setDateTime(2022, nextMonth, nextDay, nextHour, nextMinute, nextSecond);
|
||||
nextHour++;
|
||||
if (nextHour >= 24) {
|
||||
nextHour = 23;
|
||||
nextDay = 25;
|
||||
rtc.setAlarmByHours(0);
|
||||
Serial.println("setAlarmByHours");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
printDateTime();
|
||||
}
|
||||
}
|
||||
|
||||
// Test hour timing
|
||||
void testAlarmHour()
|
||||
{
|
||||
while (1) {
|
||||
if (digitalRead(RTC_IRQ) == LOW) {
|
||||
Serial.println("testAlarmHour Interrupt .... ");
|
||||
if (rtc.isAlarmActive()) {
|
||||
Serial.println("Alarm active");
|
||||
rtc.resetAlarm();
|
||||
rtc.setDateTime(2022, nextMonth, nextDay, nextHour, nextMinute, nextSecond);
|
||||
nextDay++;
|
||||
if (nextDay >= 30) {
|
||||
nextMonth = 1;
|
||||
nextHour = 23;
|
||||
nextMinute = 59;
|
||||
nextSecond = 55;
|
||||
nextDay = rtc.getDaysInMonth(nextMonth, 2022);
|
||||
rtc.setDateTime(2022, nextMonth, nextDay, nextHour, nextMinute, nextSecond);
|
||||
rtc.setAlarmByDays(1);
|
||||
Serial.println("setAlarmByDays");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
printDateTime();
|
||||
}
|
||||
}
|
||||
|
||||
// Test day timing
|
||||
void testAlarmDay()
|
||||
{
|
||||
while (1) {
|
||||
if (digitalRead(RTC_IRQ) == LOW) {
|
||||
Serial.println("testAlarmDay Interrupt .... ");
|
||||
if (rtc.isAlarmActive()) {
|
||||
Serial.println("Alarm active");
|
||||
rtc.resetAlarm();
|
||||
nextDay = rtc.getDaysInMonth(nextMonth, 2022);
|
||||
rtc.setDateTime(2022, nextMonth, nextDay, nextHour, nextMinute, nextSecond);
|
||||
nextMonth++;
|
||||
if (nextMonth >= 12) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
printDateTime();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
testAlarmMinute();
|
||||
testAlarmHour();
|
||||
testAlarmDay();
|
||||
|
||||
Serial.println("Test done ...");
|
||||
while (1) {
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
167
lib/SensorsLib/examples/PCF8563_AlarmByUnits/power.cpp
Normal file
167
lib/SensorsLib/examples/PCF8563_AlarmByUnits/power.cpp
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
/**
|
||||
* @file power.cpp
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @license MIT
|
||||
* @copyright Copyright (c) 2022
|
||||
* @date 2022-10-25
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LILYGO_TBEAM_SUPREME_V3_0
|
||||
#include <Wire.h>
|
||||
#include "XPowersAXP2101.tpp"
|
||||
#include "XPowersAXP192.tpp"
|
||||
|
||||
|
||||
|
||||
#define I2C_SDA 42
|
||||
#define I2C_SCL 41
|
||||
#define PMU_IRQ 40
|
||||
|
||||
XPowersLibInterface *PMU = NULL;
|
||||
|
||||
bool setupPower()
|
||||
{
|
||||
Serial.println("setupPower");
|
||||
|
||||
if (!PMU) {
|
||||
PMU = new XPowersAXP2101(Wire, I2C_SDA, I2C_SCL);
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PMU->getChipModel() == XPOWERS_AXP2101) {
|
||||
|
||||
#if defined(LILYGO_TBEAM_V1_2)
|
||||
|
||||
PMU->setProtectedChannel(XPOWERS_DCDC1);
|
||||
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC2);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC3);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC4);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC5);
|
||||
|
||||
// PMU->disablePowerOutput(XPOWERS_ALDO1);
|
||||
// PMU->disablePowerOutput(XPOWERS_ALDO2);
|
||||
// PMU->disablePowerOutput(XPOWERS_ALDO3);
|
||||
PMU->disablePowerOutput(XPOWERS_ALDO4);
|
||||
|
||||
PMU->disablePowerOutput(XPOWERS_BLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_BLDO2);
|
||||
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO2);
|
||||
|
||||
PMU->enablePowerOutput(XPOWERS_VBACKUP);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO1);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO2);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO3);
|
||||
|
||||
PMU->setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V4);
|
||||
|
||||
#elif defined(LILYGO_TBEAM_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);
|
||||
|
||||
// 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);
|
||||
|
||||
//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);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
PMU->enableSystemVoltageMeasure();
|
||||
PMU->enableVbusVoltageMeasure();
|
||||
PMU->enableBattVoltageMeasure();
|
||||
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");
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2022 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file PCF8563_SimpleTime.ino
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2022-12-12
|
||||
*
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#include <Arduino.h>
|
||||
#include "SensorPCF8563.tpp"
|
||||
|
||||
// lilygo t-beam-s3-core pin
|
||||
#define I2C_SDA 42
|
||||
#define I2C_SCL 41
|
||||
#define RTC_IRQ 14
|
||||
|
||||
SensorPCF8563 rtc;
|
||||
uint32_t lastMillis;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
#ifdef LILYGO_TBEAM_SUPREME_V3_0
|
||||
extern bool setupPower();
|
||||
setupPower();
|
||||
#endif
|
||||
|
||||
pinMode(RTC_IRQ, INPUT_PULLUP);
|
||||
|
||||
if (!rtc.begin(Wire, PCF8563_SLAVE_ADDRESS, I2C_SDA, I2C_SCL)) {
|
||||
Serial.println("Failed to find PCF8563 - check your wiring!");
|
||||
while (1) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t year = 2022;
|
||||
uint8_t month = 12;
|
||||
uint8_t day = 12;
|
||||
uint8_t hour = 21;
|
||||
uint8_t minute = 00;
|
||||
uint8_t second = 30;
|
||||
|
||||
rtc.setDateTime(year, month, day, hour, minute, second);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (millis() - lastMillis > 1000) {
|
||||
lastMillis = millis();
|
||||
RTC_DateTime datetime = rtc.getDateTime();
|
||||
Serial.printf(" Year :"); Serial.print(datetime.year);
|
||||
Serial.printf(" Month:"); Serial.print(datetime.month);
|
||||
Serial.printf(" Day :"); Serial.print(datetime.day);
|
||||
Serial.printf(" Hour:"); Serial.print(datetime.hour);
|
||||
Serial.printf(" Minute:"); Serial.print(datetime.minute);
|
||||
Serial.printf(" Sec :"); Serial.println(datetime.second);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
167
lib/SensorsLib/examples/PCF8563_SimpleTime/power.cpp
Normal file
167
lib/SensorsLib/examples/PCF8563_SimpleTime/power.cpp
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
/**
|
||||
* @file power.cpp
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @license MIT
|
||||
* @copyright Copyright (c) 2022
|
||||
* @date 2022-10-25
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LILYGO_TBEAM_SUPREME_V3_0
|
||||
#include <Wire.h>
|
||||
#include "XPowersAXP2101.tpp"
|
||||
#include "XPowersAXP192.tpp"
|
||||
|
||||
|
||||
|
||||
#define I2C_SDA 42
|
||||
#define I2C_SCL 41
|
||||
#define PMU_IRQ 40
|
||||
|
||||
XPowersLibInterface *PMU = NULL;
|
||||
|
||||
bool setupPower()
|
||||
{
|
||||
Serial.println("setupPower");
|
||||
|
||||
if (!PMU) {
|
||||
PMU = new XPowersAXP2101(Wire, I2C_SDA, I2C_SCL);
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PMU->getChipModel() == XPOWERS_AXP2101) {
|
||||
|
||||
#if defined(LILYGO_TBEAM_V1_2)
|
||||
|
||||
PMU->setProtectedChannel(XPOWERS_DCDC1);
|
||||
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC2);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC3);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC4);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC5);
|
||||
|
||||
// PMU->disablePowerOutput(XPOWERS_ALDO1);
|
||||
// PMU->disablePowerOutput(XPOWERS_ALDO2);
|
||||
// PMU->disablePowerOutput(XPOWERS_ALDO3);
|
||||
PMU->disablePowerOutput(XPOWERS_ALDO4);
|
||||
|
||||
PMU->disablePowerOutput(XPOWERS_BLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_BLDO2);
|
||||
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO2);
|
||||
|
||||
PMU->enablePowerOutput(XPOWERS_VBACKUP);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO1);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO2);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO3);
|
||||
|
||||
PMU->setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V4);
|
||||
|
||||
#elif defined(LILYGO_TBEAM_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);
|
||||
|
||||
// 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);
|
||||
|
||||
//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);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
PMU->enableSystemVoltageMeasure();
|
||||
PMU->enableVbusVoltageMeasure();
|
||||
PMU->enableBattVoltageMeasure();
|
||||
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");
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
101
lib/SensorsLib/examples/PCF8563_TimeLib/PCF8563_TimeLib.ino
Normal file
101
lib/SensorsLib/examples/PCF8563_TimeLib/PCF8563_TimeLib.ino
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2022 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file PCF8563_TimeLib.ino
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2022-12-12
|
||||
*
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#include <Arduino.h>
|
||||
#include "SensorPCF8563.tpp"
|
||||
#include <time.h>
|
||||
|
||||
// lilygo t-beam-s3-core pin
|
||||
#define I2C_SDA 42
|
||||
#define I2C_SCL 41
|
||||
#define RTC_IRQ 14
|
||||
|
||||
SensorPCF8563 rtc;
|
||||
uint32_t lastMillis;
|
||||
char buf[64];
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
#ifdef LILYGO_TBEAM_SUPREME_V3_0
|
||||
extern bool setupPower();
|
||||
setupPower();
|
||||
#endif
|
||||
|
||||
pinMode(RTC_IRQ, INPUT_PULLUP);
|
||||
|
||||
if (!rtc.begin(Wire, PCF8563_SLAVE_ADDRESS, I2C_SDA, I2C_SCL)) {
|
||||
Serial.println("Failed to find PCF8563 - check your wiring!");
|
||||
while (1) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (millis() - lastMillis > 1000) {
|
||||
|
||||
lastMillis = millis();
|
||||
|
||||
struct tm timeinfo;
|
||||
// Get the time C library structure
|
||||
rtc.getDateTime(&timeinfo);
|
||||
|
||||
// Format the output using the strftime function
|
||||
// For more formats, please refer to :
|
||||
// https://man7.org/linux/man-pages/man3/strftime.3.html
|
||||
|
||||
size_t written = strftime(buf, 64, "%A, %B %d %Y %H:%M:%S", &timeinfo);
|
||||
|
||||
if (written != 0) {
|
||||
Serial.println(buf);
|
||||
}
|
||||
|
||||
written = strftime(buf, 64, "%b %d %Y %H:%M:%S", &timeinfo);
|
||||
if (written != 0) {
|
||||
Serial.println(buf);
|
||||
}
|
||||
|
||||
|
||||
written = strftime(buf, 64, "%A, %d. %B %Y %I:%M%p", &timeinfo);
|
||||
if (written != 0) {
|
||||
Serial.println(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
167
lib/SensorsLib/examples/PCF8563_TimeLib/power.cpp
Normal file
167
lib/SensorsLib/examples/PCF8563_TimeLib/power.cpp
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
/**
|
||||
* @file power.cpp
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @license MIT
|
||||
* @copyright Copyright (c) 2022
|
||||
* @date 2022-10-25
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LILYGO_TBEAM_SUPREME_V3_0
|
||||
#include <Wire.h>
|
||||
#include "XPowersAXP2101.tpp"
|
||||
#include "XPowersAXP192.tpp"
|
||||
|
||||
|
||||
|
||||
#define I2C_SDA 42
|
||||
#define I2C_SCL 41
|
||||
#define PMU_IRQ 40
|
||||
|
||||
XPowersLibInterface *PMU = NULL;
|
||||
|
||||
bool setupPower()
|
||||
{
|
||||
Serial.println("setupPower");
|
||||
|
||||
if (!PMU) {
|
||||
PMU = new XPowersAXP2101(Wire, I2C_SDA, I2C_SCL);
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PMU->getChipModel() == XPOWERS_AXP2101) {
|
||||
|
||||
#if defined(LILYGO_TBEAM_V1_2)
|
||||
|
||||
PMU->setProtectedChannel(XPOWERS_DCDC1);
|
||||
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC2);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC3);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC4);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC5);
|
||||
|
||||
// PMU->disablePowerOutput(XPOWERS_ALDO1);
|
||||
// PMU->disablePowerOutput(XPOWERS_ALDO2);
|
||||
// PMU->disablePowerOutput(XPOWERS_ALDO3);
|
||||
PMU->disablePowerOutput(XPOWERS_ALDO4);
|
||||
|
||||
PMU->disablePowerOutput(XPOWERS_BLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_BLDO2);
|
||||
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO2);
|
||||
|
||||
PMU->enablePowerOutput(XPOWERS_VBACKUP);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO1);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO2);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO3);
|
||||
|
||||
PMU->setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V4);
|
||||
|
||||
#elif defined(LILYGO_TBEAM_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);
|
||||
|
||||
// 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);
|
||||
|
||||
//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);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
PMU->enableSystemVoltageMeasure();
|
||||
PMU->enableVbusVoltageMeasure();
|
||||
PMU->enableBattVoltageMeasure();
|
||||
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");
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
/**
|
||||
*
|
||||
* @license MIT License
|
||||
*
|
||||
* Copyright (c) 2022 lewis he
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @file PCF8563_TimeSynchronization.ino
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @date 2022-12-12
|
||||
*
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#include <Arduino.h>
|
||||
#include <time.h>
|
||||
#include <WiFi.h>
|
||||
#include <sntp.h>
|
||||
#include "SensorPCF8563.tpp"
|
||||
|
||||
// lilygo t-beam-s3-core pin
|
||||
#define I2C_SDA 42
|
||||
#define I2C_SCL 41
|
||||
#define RTC_IRQ 14
|
||||
|
||||
const char *ssid = "YOUR_SSID";
|
||||
const char *password = "YOUR_PASS";
|
||||
|
||||
const char *ntpServer1 = "pool.ntp.org";
|
||||
const char *ntpServer2 = "time.nist.gov";
|
||||
const long gmtOffset_sec = 3600;
|
||||
const int daylightOffset_sec = 3600;
|
||||
|
||||
const char *time_zone = "CST-8"; // TimeZone rule for Europe/Rome including daylight adjustment rules (optional)
|
||||
|
||||
SensorPCF8563 rtc;
|
||||
uint32_t lastMillis;
|
||||
|
||||
|
||||
// Callback function (get's called when time adjusts via NTP)
|
||||
void timeavailable(struct timeval *t)
|
||||
{
|
||||
Serial.println("Got time adjustment from NTP, Write the hardware clock");
|
||||
|
||||
// Write synchronization time to hardware
|
||||
rtc.hwClockWrite();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
#ifdef LILYGO_TBEAM_SUPREME_V3_0
|
||||
extern bool setupPower();
|
||||
setupPower();
|
||||
#endif
|
||||
|
||||
pinMode(RTC_IRQ, INPUT_PULLUP);
|
||||
|
||||
if (!rtc.begin(Wire, PCF8563_SLAVE_ADDRESS, I2C_SDA, I2C_SCL)) {
|
||||
Serial.println("Failed to find PCF8563 - check your wiring!");
|
||||
while (1) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
// set notification call-back function
|
||||
sntp_set_time_sync_notification_cb( timeavailable );
|
||||
|
||||
/**
|
||||
* NTP server address could be aquired via DHCP,
|
||||
*
|
||||
* NOTE: This call should be made BEFORE esp32 aquires IP address via DHCP,
|
||||
* otherwise SNTP option 42 would be rejected by default.
|
||||
* NOTE: configTime() function call if made AFTER DHCP-client run
|
||||
* will OVERRIDE aquired NTP server address
|
||||
*/
|
||||
sntp_servermode_dhcp(1); // (optional)
|
||||
|
||||
/**
|
||||
* This will set configured ntp servers and constant TimeZone/daylightOffset
|
||||
* should be OK if your time zone does not need to adjust daylightOffset twice a year,
|
||||
* in such a case time adjustment won't be handled automagicaly.
|
||||
*/
|
||||
// configTime(gmtOffset_sec, daylightOffset_sec, ntpServer1, ntpServer2);
|
||||
|
||||
/**
|
||||
* A more convenient approach to handle TimeZones with daylightOffset
|
||||
* would be to specify a environmnet variable with TimeZone definition including daylight adjustmnet rules.
|
||||
* A list of rules for your zone could be obtained from https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TZ.h
|
||||
*/
|
||||
configTzTime(time_zone, ntpServer1, ntpServer2);
|
||||
|
||||
//connect to WiFi
|
||||
Serial.printf("Connecting to %s ", ssid);
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println(" CONNECTED");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (millis() - lastMillis > 1000) {
|
||||
|
||||
lastMillis = millis();
|
||||
|
||||
// hardware clock
|
||||
struct tm hwTimeinfo;
|
||||
rtc.getDateTime(&hwTimeinfo);
|
||||
Serial.print("Hardware clock :");
|
||||
Serial.println(&hwTimeinfo, "%A, %B %d %Y %H:%M:%S");
|
||||
|
||||
// system clock
|
||||
struct tm timeinfo;
|
||||
if (!getLocalTime(&timeinfo)) {
|
||||
Serial.println("No time available (yet)");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print("System clock :");
|
||||
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
167
lib/SensorsLib/examples/PCF8563_TimeSynchronization/power.cpp
Normal file
167
lib/SensorsLib/examples/PCF8563_TimeSynchronization/power.cpp
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
/**
|
||||
* @file power.cpp
|
||||
* @author Lewis He (lewishe@outlook.com)
|
||||
* @license MIT
|
||||
* @copyright Copyright (c) 2022
|
||||
* @date 2022-10-25
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LILYGO_TBEAM_SUPREME_V3_0
|
||||
#include <Wire.h>
|
||||
#include "XPowersAXP2101.tpp"
|
||||
#include "XPowersAXP192.tpp"
|
||||
|
||||
|
||||
|
||||
#define I2C_SDA 42
|
||||
#define I2C_SCL 41
|
||||
#define PMU_IRQ 40
|
||||
|
||||
XPowersLibInterface *PMU = NULL;
|
||||
|
||||
bool setupPower()
|
||||
{
|
||||
Serial.println("setupPower");
|
||||
|
||||
if (!PMU) {
|
||||
PMU = new XPowersAXP2101(Wire, I2C_SDA, I2C_SCL);
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PMU->getChipModel() == XPOWERS_AXP2101) {
|
||||
|
||||
#if defined(LILYGO_TBEAM_V1_2)
|
||||
|
||||
PMU->setProtectedChannel(XPOWERS_DCDC1);
|
||||
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC2);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC3);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC4);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC5);
|
||||
|
||||
// PMU->disablePowerOutput(XPOWERS_ALDO1);
|
||||
// PMU->disablePowerOutput(XPOWERS_ALDO2);
|
||||
// PMU->disablePowerOutput(XPOWERS_ALDO3);
|
||||
PMU->disablePowerOutput(XPOWERS_ALDO4);
|
||||
|
||||
PMU->disablePowerOutput(XPOWERS_BLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_BLDO2);
|
||||
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO2);
|
||||
|
||||
PMU->enablePowerOutput(XPOWERS_VBACKUP);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO1);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO2);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO3);
|
||||
|
||||
PMU->setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V4);
|
||||
|
||||
#elif defined(LILYGO_TBEAM_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);
|
||||
|
||||
// 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);
|
||||
|
||||
//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);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
PMU->enableSystemVoltageMeasure();
|
||||
PMU->enableVbusVoltageMeasure();
|
||||
PMU->enableBattVoltageMeasure();
|
||||
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");
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue