Skip to content

Commit 391fc80

Browse files
sandeepmistrycmaglie
authored andcommitted
Rename disable_battery_charging to disable_battery_fet and always call, update comment
1 parent 21ccbc9 commit 391fc80

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

variants/mkrgsm1400/variant.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,35 +193,38 @@ static inline void enable_battery_charging() {
193193
PERIPH_WIRE.disableWIRE();
194194
}
195195

196-
static inline void disable_battery_charging() {
196+
static inline void disable_battery_fet(bool disabled) {
197197
PERIPH_WIRE.initMasterWIRE(100000);
198198
PERIPH_WIRE.enableWIRE();
199199
pinPeripheral(PIN_WIRE_SDA, g_APinDescription[PIN_WIRE_SDA].ulPinType);
200200
pinPeripheral(PIN_WIRE_SCL, g_APinDescription[PIN_WIRE_SCL].ulPinType);
201201

202202
PERIPH_WIRE.startTransmissionWIRE( PMIC_ADDRESS, WIRE_WRITE_FLAG );
203203
PERIPH_WIRE.sendDataMasterWIRE(PMIC_REG07);
204-
PERIPH_WIRE.sendDataMasterWIRE(0x2B); // Charge Battery + Minimum System Voltage 3.5V
204+
// No D+/D– detection + Safety timer not slowed by 2X during input DPM or thermal regulation +
205+
// BAT fet disabled/enabled + charge and bat fault INT
206+
PERIPH_WIRE.sendDataMasterWIRE(0x0B | (disabled ? 0x20 : 0x00));
205207
PERIPH_WIRE.prepareCommandBitsWire(WIRE_MASTER_ACT_STOP);
206208

207209
PERIPH_WIRE.disableWIRE();
208210
}
209-
#else
210211

211212
#endif
212213

213214
void initVariant() {
215+
#if defined(USE_BQ24195L_PMIC)
214216
pinMode(ADC_BATTERY, OUTPUT);
215217
digitalWrite(ADC_BATTERY, LOW);
216218
delay(10);
217219
pinMode(ADC_BATTERY, INPUT);
218220
delay(100);
219221

220-
if (analogRead(ADC_BATTERY) > 600) {
222+
bool batteryPresent = analogRead(ADC_BATTERY) > 600;
223+
if (batteryPresent) {
221224
enable_battery_charging();
222-
} else {
223-
disable_battery_charging();
224225
}
226+
disable_battery_fet(!batteryPresent);
227+
#endif
225228

226229
// Workaround for RTS not being controlled correctly
227230
pinMode(GSM_RTS, OUTPUT);

0 commit comments

Comments
 (0)