@@ -177,6 +177,7 @@ SERCOM sercom5(SERCOM5);
177177
178178#define PMIC_ADDRESS 0x6B
179179#define PMIC_REG01 0x01
180+ #define PMIC_REG07 0x07
180181
181182static inline void enable_battery_charging () {
182183 PERIPH_WIRE.initMasterWIRE (100000 );
@@ -192,21 +193,36 @@ static inline void enable_battery_charging() {
192193 PERIPH_WIRE.disableWIRE ();
193194}
194195
195- #else
196+ static inline void disable_battery_charging () {
197+ PERIPH_WIRE.initMasterWIRE (100000 );
198+ PERIPH_WIRE.enableWIRE ();
199+ pinPeripheral (PIN_WIRE_SDA, g_APinDescription[PIN_WIRE_SDA].ulPinType );
200+ pinPeripheral (PIN_WIRE_SCL, g_APinDescription[PIN_WIRE_SCL].ulPinType );
196201
197- static inline void disable_battery_charging () {}
202+ PERIPH_WIRE.startTransmissionWIRE ( PMIC_ADDRESS, WIRE_WRITE_FLAG );
203+ PERIPH_WIRE.sendDataMasterWIRE (PMIC_REG07);
204+ PERIPH_WIRE.sendDataMasterWIRE (0x2B ); // Charge Battery + Minimum System Voltage 3.5V
205+ PERIPH_WIRE.prepareCommandBitsWire (WIRE_MASTER_ACT_STOP);
206+
207+ PERIPH_WIRE.disableWIRE ();
208+ }
209+ #else
198210
199211#endif
200212
201213void initVariant () {
202214 pinMode (ADC_BATTERY, OUTPUT);
203215 digitalWrite (ADC_BATTERY, LOW);
204- delay (1 );
216+ delay (10 );
205217 pinMode (ADC_BATTERY, INPUT);
206- delay (1 );
207- if (analogRead (ADC_BATTERY) > 100 ) {
218+ delay (100 );
219+
220+ if (analogRead (ADC_BATTERY) > 800 ) {
208221 enable_battery_charging ();
209222 }
223+ else {
224+ disable_battery_charging ();
225+ }
210226
211227 // Workaround for RTS not being controlled correctly
212228 pinMode (GSM_RTS, OUTPUT);
0 commit comments