feat(travelers): enable GPS with GP-02 module support

- Add HAS_GPS=1, GPS_RX_PIN=20, GPS_TX_PIN=21
- Add TCA9535 P1.6 (GPS RST) and P1.7 (GPS EN) control via I2C
- GPS power on at boot: P1.6 and P1.7 default HIGH in init
- Bridge gps->enablePin to TCA9535 via GpioUnaryTransformer
- Add tca9535GpsReset() and tca9535GpsEn() static functions
- Update CHANGELOG with GPS support details
This commit is contained in:
2026-03-29 07:28:58 +08:00
parent 6f51e8ff83
commit 311232c9b9
5 changed files with 93 additions and 8 deletions
@@ -58,11 +58,12 @@ bool TCA9535ButtonThread::init()
{
// ===================================================================
// 第一步:配置 P1 口方向
// P1.2 = 输出POWER_EN),P1.3 = 输入POWER_BOOT),P1.4 = 输出LoRa RST),P1.5 = 输出(状态灯)
// P1.2=输出(POWER_EN), P1.3=输入(POWER_BOOT), P1.4=输出(LoRa RST),
// P1.5=输出(状态灯), P1.6=输出(GPS RST), P1.7=输出(GPS EN)
// Configuration 寄存器:1=input, 0=output
// P1.2=bit2=0, P1.3=bit3=1, P1.4=bit4=0, P1.5=bit5=0 → 0xCB (1100 1011)
// P1.2=0, P1.3=1, P1.4=0, P1.5=0, P1.6=0, P1.7=0 → 0x8B (1000 1011)
// ===================================================================
if (!writeReg(TCA9535_REG_CONFIG_P1, 0xCB)) {
if (!writeReg(TCA9535_REG_CONFIG_P1, 0x8B)) {
LOG_WARN("TCA9535: P1 config write failed");
return false;
}
@@ -74,6 +75,12 @@ bool TCA9535ButtonThread::init()
// P1.5 状态灯默认熄灭(高电平)
tca9535StatusLed(false);
// P1.6 GPS RST 默认释放(高电平 = 正常工作)
tca9535GpsReset(true);
// P1.7 GPS EN 默认打开(高电平 = GPS 上电)
tca9535GpsEn(true);
// ===================================================================
// 第二步:开机检测 — 等待用户持续按住 P1.3 达 2 秒
// 物理按键已使 MOS 导通(ESP32 得电),但 POWER_EN 尚未拉高
@@ -85,6 +85,8 @@
#define TCA9535_BIT_P13 (1u << 3) // POWER_BOOT 输入
#define TCA9535_BIT_P14 (1u << 4) // LoRa RST 输出
#define TCA9535_BIT_P15 (1u << 5) // 状态指示灯输出(低电平点亮)
#define TCA9535_BIT_P16 (1u << 6) // GPS RST 输出
#define TCA9535_BIT_P17 (1u << 7) // GPS EN 输出(高电平有效)
/**
* 通过 I²C 控制 TCA9535 P1.2 上的电源使能(POWER_EN)。
@@ -189,6 +191,57 @@ static inline bool tca9535StatusLed(bool on)
return (Wire.endTransmission() == 0);
}
/**
* 通过 I²C 控制 TCA9535 P1.6 上的 GPS RST。
* @param high true=释放复位(高电平),false=触发复位(低电平)
*/
static inline bool tca9535GpsReset(bool high)
{
Wire.beginTransmission(TCA9535_I2C_ADDR);
Wire.write(TCA9535_REG_OUTPUT_P1);
if (Wire.endTransmission(false) != 0)
return false;
if (Wire.requestFrom((uint8_t)TCA9535_I2C_ADDR, (uint8_t)1) != 1)
return false;
uint8_t p1Out = Wire.read();
if (high)
p1Out |= TCA9535_BIT_P16; // 拉高 = 释放复位
else
p1Out &= ~TCA9535_BIT_P16; // 拉低 = 触发复位
Wire.beginTransmission(TCA9535_I2C_ADDR);
Wire.write(TCA9535_REG_OUTPUT_P1);
Wire.write(p1Out);
return (Wire.endTransmission() == 0);
}
/**
* 通过 I²C 控制 TCA9535 P1.7 上的 GPS EN。
* 高电平有效:拉高 = GPS 上电,拉低 = GPS 断电。
* @param on true=上电(高电平),false=断电(低电平)
*/
static inline bool tca9535GpsEn(bool on)
{
Wire.beginTransmission(TCA9535_I2C_ADDR);
Wire.write(TCA9535_REG_OUTPUT_P1);
if (Wire.endTransmission(false) != 0)
return false;
if (Wire.requestFrom((uint8_t)TCA9535_I2C_ADDR, (uint8_t)1) != 1)
return false;
uint8_t p1Out = Wire.read();
if (on)
p1Out |= TCA9535_BIT_P17; // 拉高 = GPS 上电
else
p1Out &= ~TCA9535_BIT_P17; // 拉低 = GPS 断电
Wire.beginTransmission(TCA9535_I2C_ADDR);
Wire.write(TCA9535_REG_OUTPUT_P1);
Wire.write(p1Out);
return (Wire.endTransmission() == 0);
}
/**
* 电源管理状态机
*/
+10
View File
@@ -955,6 +955,16 @@ void setup()
gps = GPS::createGps();
if (gps) {
gpsStatus->observe(&gps->newStatus);
#ifdef TCA9535_GPS_HAS_CTRL
// 替换 enablePin 为 TCA9535 P1.7GPS EN),I²C 控制
// createGps() 创建了空的 GpioVirtPin,替换为实际的 TCA9535 驱动
class GpioTca9535GpsEnPin : public GpioPin {
public:
void set(bool value) override { tca9535GpsEn(value); }
} *tca9535GpsEnPin = new GpioTca9535GpsEnPin();
new GpioUnaryTransformer(gps->enablePin, tca9535GpsEnPin);
// GPS 已在 TCA9535 init 中上电(P1.7=高),无需额外操作
#endif
} else {
LOG_DEBUG("Run without GPS");
}