Skip to content

Commit bf961e1

Browse files
committed
feat: nesso_n1: enable battery
only charging for now
1 parent c2b13eb commit bf961e1

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

variants/arduino_nesso_n1/expander.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,37 @@ int digitalRead(ExpanderPin pin) {
8585
return readBitRegister(pin.address, 0xF, pin.pin);
8686
}
8787

88+
void NessoBattery::enableCharge() {
89+
// AW32001E - address 0x49
90+
// set CEB bit low (charge enable)
91+
if (!wireInitialized) {
92+
WireInternal.begin(SDA, SCL);
93+
wireInitialized = true;
94+
}
95+
writeBitRegister(0x49, 0x1, 3, false);
96+
}
97+
98+
float NessoBattery::getVoltage() {
99+
// BQ27220 - address 0x55
100+
if (!wireInitialized) {
101+
WireInternal.begin(SDA, SCL);
102+
wireInitialized = true;
103+
}
104+
uint16_t voltage = (readRegister(0x55, 0x9) << 8) | readRegister(0x55, 0x8);
105+
return (float)voltage / 1000.0f;
106+
}
107+
108+
uint16_t NessoBattery::getChargeLevel() {
109+
// BQ27220 - address 0x55
110+
if (!wireInitialized) {
111+
WireInternal.begin(SDA, SCL);
112+
wireInitialized = true;
113+
}
114+
uint16_t current_capacity = readRegister(0x55, 0x11) << 8 | readRegister(0x55, 0x10);
115+
uint16_t total_capacity = readRegister(0x55, 0x13) << 8 | readRegister(0x55, 0x12);
116+
return (current_capacity * 100) / total_capacity;
117+
}
118+
88119
ExpanderPin LORA_LNA_ENABLE(5);
89120
ExpanderPin LORA_ANTENNA_SWITCH(6);
90121
ExpanderPin LORA_ENABLE(7);

variants/arduino_nesso_n1/pins_arduino.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ class ExpanderPin {
4949
uint8_t address;
5050
};
5151

52+
class NessoBattery {
53+
public:
54+
NessoBattery() {};
55+
void enableCharge(); // enable charging
56+
float getVoltage(); // get battery voltage in Volts
57+
uint16_t getChargeLevel(); // get battery charge level in percents
58+
};
59+
5260
extern ExpanderPin LORA_LNA_ENABLE;
5361
extern ExpanderPin LORA_ANTENNA_SWITCH;
5462
extern ExpanderPin LORA_ENABLE;

0 commit comments

Comments
 (0)