Skip to content

Commit 95e69cf

Browse files
committed
RadioWrapper::std_init: add tbeam, unify coding style
1 parent f666b8c commit 95e69cf

File tree

1 file changed

+29
-51
lines changed

1 file changed

+29
-51
lines changed

variants/lilygo_tbeam/target.cpp

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
TBeamBoard board;
55

66
// Using PMU AXP2102
7-
#define PMU_WIRE_PORT Wire
7+
#define PMU_WIRE_PORT Wire
88

99
bool pmuIntFlag = false;
1010
static void setPMUIntFlag(){
@@ -32,47 +32,38 @@ SensorManager sensors;
3232
#define LORA_CR 5
3333
#endif
3434

35-
bool TBeamBoard::power_init()
36-
{
37-
if (!PMU)
38-
{
35+
bool TBeamBoard::power_init() {
36+
if (!PMU) {
3937
PMU = new XPowersAXP2101(PMU_WIRE_PORT);
40-
if (!PMU->init())
41-
{
38+
if (!PMU->init()) {
4239
// Serial.println("Warning: Failed to find AXP2101 power management");
4340
delete PMU;
4441
PMU = NULL;
4542
}
46-
else
47-
{
43+
else {
4844
// Serial.println("AXP2101 PMU init succeeded, using AXP2101 PMU");
4945
}
5046
}
51-
if (!PMU)
52-
{
47+
if (!PMU) {
5348
PMU = new XPowersAXP192(PMU_WIRE_PORT);
54-
if (!PMU->init())
55-
{
49+
if (!PMU->init()) {
5650
// Serial.println("Warning: Failed to find AXP192 power management");
5751
delete PMU;
5852
PMU = NULL;
5953
}
60-
else
61-
{
54+
else {
6255
// Serial.println("AXP192 PMU init succeeded, using AXP192 PMU");
6356
}
6457
}
6558

66-
if (!PMU)
67-
{
59+
if (!PMU) {
6860
MESH_DEBUG_PRINTLN("PMU init failed.");
6961
return false;
7062
}
7163

7264
// Serial.printf("PMU ID:0x%x\n", PMU->getChipID());
7365
// printPMU();
74-
if (PMU->getChipModel() == XPOWERS_AXP192)
75-
{
66+
if (PMU->getChipModel() == XPOWERS_AXP192) {
7667
// lora radio power channel
7768
PMU->setPowerChannelVoltage(XPOWERS_LDO2, 3300);
7869
PMU->enablePowerOutput(XPOWERS_LDO2);
@@ -95,8 +86,7 @@ bool TBeamBoard::power_init()
9586
PMU->disableIRQ(XPOWERS_AXP192_ALL_IRQ);
9687
PMU->setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_550MA);
9788
}
98-
else if (PMU->getChipModel() == XPOWERS_AXP2101)
99-
{
89+
else if (PMU->getChipModel() == XPOWERS_AXP2101) {
10090
// gnss module power channel
10191
PMU->setPowerChannelVoltage(XPOWERS_ALDO4, 3300);
10292
PMU->enablePowerOutput(XPOWERS_ALDO4);
@@ -144,21 +134,10 @@ bool radio_init() {
144134

145135
#if defined(P_LORA_SCLK)
146136
spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
137+
return radio.std_init(&spi);
138+
#else
139+
return radio.std_init();
147140
#endif
148-
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8);
149-
if (status != RADIOLIB_ERR_NONE) {
150-
Serial.print("ERROR: radio init failed: ");
151-
Serial.println(status);
152-
return false; // fail
153-
}
154-
155-
#ifdef SX127X_CURRENT_LIMIT
156-
radio.setCurrentLimit(SX127X_CURRENT_LIMIT);
157-
#endif
158-
159-
radio.setCRC(1);
160-
161-
return true; // success
162141
}
163142

164143
uint32_t radio_get_rng_seed() {
@@ -182,22 +161,21 @@ mesh::LocalIdentity radio_new_identity() {
182161
}
183162

184163
#ifdef MESH_DEBUG
185-
void TBeamBoard::printPMU()
186-
{
187-
Serial.print("isCharging:"); Serial.println(PMU->isCharging() ? "YES" : "NO");
188-
Serial.print("isDischarge:"); Serial.println(PMU->isDischarge() ? "YES" : "NO");
189-
Serial.print("isVbusIn:"); Serial.println(PMU->isVbusIn() ? "YES" : "NO");
190-
Serial.print("getBattVoltage:"); Serial.print(PMU->getBattVoltage()); Serial.println("mV");
191-
Serial.print("getVbusVoltage:"); Serial.print(PMU->getVbusVoltage()); Serial.println("mV");
192-
Serial.print("getSystemVoltage:"); Serial.print(PMU->getSystemVoltage()); Serial.println("mV");
193-
194-
// The battery percentage may be inaccurate at first use, the PMU will automatically
195-
// learn the battery curve and will automatically calibrate the battery percentage
196-
// after a charge and discharge cycle
197-
if (PMU->isBatteryConnect()) {
198-
Serial.print("getBatteryPercent:"); Serial.print(PMU->getBatteryPercent()); Serial.println("%");
199-
}
164+
void TBeamBoard::printPMU() {
165+
Serial.print("isCharging:"); Serial.println(PMU->isCharging() ? "YES" : "NO");
166+
Serial.print("isDischarge:"); Serial.println(PMU->isDischarge() ? "YES" : "NO");
167+
Serial.print("isVbusIn:"); Serial.println(PMU->isVbusIn() ? "YES" : "NO");
168+
Serial.print("getBattVoltage:"); Serial.print(PMU->getBattVoltage()); Serial.println("mV");
169+
Serial.print("getVbusVoltage:"); Serial.print(PMU->getVbusVoltage()); Serial.println("mV");
170+
Serial.print("getSystemVoltage:"); Serial.print(PMU->getSystemVoltage()); Serial.println("mV");
171+
172+
// The battery percentage may be inaccurate at first use, the PMU will automatically
173+
// learn the battery curve and will automatically calibrate the battery percentage
174+
// after a charge and discharge cycle
175+
if (PMU->isBatteryConnect()) {
176+
Serial.print("getBatteryPercent:"); Serial.print(PMU->getBatteryPercent()); Serial.println("%");
177+
}
200178

201-
Serial.println();
179+
Serial.println();
202180
}
203181
#endif

0 commit comments

Comments
 (0)