Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sebromero committed May 10, 2024
1 parent 8d761e7 commit 1d6b39b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/Charger/Charger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Usage:
1. Connect the Battery:
1. Connect a Battery to the board
2. Upload the Sketch:
- Open the provided sketch in the Arduino IDE.
Expand Down
3 changes: 2 additions & 1 deletion examples/Standby_WakeFromPin/Standby_WakeFromPin.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ void setup() {
board.enableWakeupFromPin();
#endif

// TODO why is this needed? Why true?
// TODO why is this needed? Why true? -> Peripherals still off after reset?
// only necessary for C33
board.setAllPeripheralsPower(true);
// TODO why is this needed?
charger.setEnabled(false);
Expand Down
2 changes: 2 additions & 0 deletions src/Battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Battery::Battery(BatteryCharacteristics batteryCharacteristics) : characteristic
}

bool Battery::begin(bool enforceReload) {
// PMIC already initializes the I2C bus, so no need to call Wire.begin() for the fuel gauge
if(PMIC.begin() != 0){
return false;
}
Expand Down Expand Up @@ -72,6 +73,7 @@ void Battery::configureBatteryCharacteristics(){

void Battery::releaseFromHibernation(){
// See section "Soft-Wakeup" in user manual https://www.analog.com/media/en/technical-documentation/user-guides/max1726x-modelgauge-m5-ez-user-guide.pdf
// TODO to preserve the hiberation config, probably better to only set bit 15 to 0
writeRegister16Bits(this->wire, FUEL_GAUGE_ADDRESS, HIB_CFG_REG, 0x0); // Exit Hibernate Mode
writeRegister16Bits(this->wire, FUEL_GAUGE_ADDRESS, SOFT_WAKEUP_REG, 0x90); // Wakes up the fuel gauge from hibernate mode to reduce the response time of the IC to configuration changes
writeRegister16Bits(this->wire, FUEL_GAUGE_ADDRESS, SOFT_WAKEUP_REG, 0x0); // This command must be manually cleared (0x0000) afterward to keep proper fuel gauge timing
Expand Down
2 changes: 2 additions & 0 deletions src/WireUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ static inline uint8_t getBit(TwoWire *wire, uint8_t address, uint8_t reg, uint8_
* @param indexFrom The index of the first bit to replace starting from LSB (0)
* @param indexTo The index of the last bit (included) to replace starting from LSB (0)
*/
// TODO switch order of parameters to conform with bitWrite()
static inline void replaceRegisterBits(TwoWire *wire, uint8_t address, uint8_t reg, uint16_t data, uint16_t indexFrom, uint8_t indexTo) {
uint16_t registerValue = readRegister16Bits(wire, address, reg);

Expand All @@ -126,6 +127,7 @@ static inline void replaceRegisterBits(TwoWire *wire, uint8_t address, uint8_t r
* @param data The new data (1 bit) to write to the register.
* @param index The index of the bit to replace.
*/
// TODO switch order of parameters to conform with bitWrite()
static inline void replaceRegisterBit(TwoWire *wire, uint8_t address, uint8_t reg, uint16_t data, uint16_t index) {
replaceRegisterBits(wire, address, reg, data, index, index);
}
Expand Down

0 comments on commit 1d6b39b

Please sign in to comment.