Skip to content

Commit f9c8150

Browse files
facchinmcmaglie
authored andcommitted
TEST: disable battery charging if no battery is connected at startup
This helps removing the flicker, but if the battery is connected AFTER connecting the USB it will be unavailable. A complete power cycle needs to be performed to recover charging/battery functionality.
1 parent 9a80642 commit f9c8150

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

variants/mkrgsm1400/variant.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ SERCOM sercom5(SERCOM5);
173173

174174
#define PMIC_ADDRESS 0x6B
175175
#define PMIC_REG02 0x02
176-
#define PMIC_REG00 0x00
176+
#define PMIC_REG07 0x07
177177
#define INPUT_CURRENT_LIMIT_0A1 (0x0)
178178
#define INPUT_CURRENT_LIMIT_0A9 (0x3)
179179
#define INPUT_CURRENT_LIMIT_1A5 (0x5)
@@ -194,9 +194,24 @@ static inline void set_pmic_safe_defaults() {
194194
PERIPH_WIRE.disableWIRE();
195195
}
196196

197+
static inline void disable_battery_charging() {
198+
PERIPH_WIRE.initMasterWIRE(100000);
199+
PERIPH_WIRE.enableWIRE();
200+
pinPeripheral(PIN_WIRE_SDA, g_APinDescription[PIN_WIRE_SDA].ulPinType);
201+
pinPeripheral(PIN_WIRE_SCL, g_APinDescription[PIN_WIRE_SCL].ulPinType);
202+
203+
PERIPH_WIRE.startTransmissionWIRE( PMIC_ADDRESS, WIRE_WRITE_FLAG );
204+
PERIPH_WIRE.sendDataMasterWIRE(PMIC_REG07);
205+
PERIPH_WIRE.sendDataMasterWIRE(1 << 5 | 0x0B);
206+
PERIPH_WIRE.prepareCommandBitsWire(WIRE_MASTER_ACT_STOP);
207+
208+
PERIPH_WIRE.disableWIRE();
209+
}
210+
197211
#else
198212

199213
static inline void set_pmic_safe_defaults() {}
214+
static inline void disable_battery_charging() {}
200215

201216
#endif
202217

@@ -209,6 +224,10 @@ void initVariant() {
209224
digitalWrite(31, HIGH);
210225
delay(100);
211226
digitalWrite(31, LOW);
227+
pinMode(32, INPUT_PULLDOWN);
228+
if (analogRead(32) < 800) {
229+
disable_battery_charging();
230+
}
212231
}
213232

214233
// Serial1

0 commit comments

Comments
 (0)