Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
965fb69
nicla-system: Rework battery API.
sebromero Apr 26, 2023
d8fc798
nicla-sense-pmic: Use function to toggle Hi-Z mode.
sebromero Apr 26, 2023
20ee494
nicla-system: Add battery monitor web app.
sebromero Apr 27, 2023
864d9a3
nicla-system: Add battery check sketch for Nicla Sense.
sebromero Apr 27, 2023
bd0ee3e
nicla-system: Add function for toggling battery NTC.
sebromero Apr 28, 2023
a47ec88
nicla-system: Refactor names.
sebromero Apr 28, 2023
254eecb
nicla-system: Remove duplicate functionality.
sebromero May 2, 2023
66bc141
nicla-system: Add API for operating system.
sebromero May 2, 2023
3b0af63
nicla-system: Rename function.
sebromero May 2, 2023
edaf109
nicla-system: Use getFaultsRegister to query faults register.
sebromero May 2, 2023
03cbd92
nicla-system: Add documentation.
sebromero May 2, 2023
1c55bb5
nicla-system: Remove battery status function.
sebromero May 2, 2023
c29e363
nicla-system: Replace defines with enum for battery level.
sebromero May 2, 2023
9f7b9a9
nicla-system: Add getter for fast charge register.
sebromero May 2, 2023
f14d519
nicla-system: Replace battery temperature with enum.
sebromero May 2, 2023
6e8f454
nicla-system: Add API to set regulated battery voltage.
sebromero May 2, 2023
d2c93a0
nicla-system: Move function to read LDO register to pmic driver.
sebromero May 2, 2023
56b67be
nicla-system: Catch error case.
sebromero May 3, 2023
d69d3ad
nicla-system: Rename function name.
sebromero May 3, 2023
444a74d
nicla-system: Improve efficiency of voltage calculation.
sebromero May 3, 2023
0708980
nicla-system: Fix incorrect INT disable.
sebromero May 3, 2023
e6ff5c5
nicla-system: Add documentation to charging function.
sebromero May 3, 2023
6d8c08a
nicla-system: Rename charging function.
sebromero May 3, 2023
9f1b6cc
nicla-system: Avoid High-Z mode when powered from VIN.
sebromero May 3, 2023
ad89fb1
nicla-system: Add function to check if board runs on battery.
sebromero May 3, 2023
6ab5b66
nicla-system: Add documentation to LDO functions.
sebromero May 4, 2023
6286728
nicla-system: Add function to disable charging.
sebromero May 4, 2023
abbc54f
nicla-system: Disable charging while taking a battery reading.
sebromero May 4, 2023
2871417
nicla-system: Display charging and power status.
sebromero May 4, 2023
de371ef
nicla-system: Make BLE updates more robust.
sebromero May 4, 2023
4dee246
nicla-system: Add documentation to the web app.
sebromero May 4, 2023
48fb48e
nicla-system: Change order of setup instructions.
sebromero May 4, 2023
cea8fa2
nicla-system: Add function for backwards compatibility.
sebromero May 4, 2023
b16d5ea
nicla-system: Give PMIC more time to wake up.
sebromero May 5, 2023
b3d7f82
nicla-system: Add error messages to sketch.
sebromero May 5, 2023
f7845c2
nicla-system: Fix incorrect battery voltage reading.
sebromero May 9, 2023
d47a6db
nicla-system: Add documentation about charging rate.
sebromero May 9, 2023
a0b13de
nicla-system: Remove NTC toggling from charge function.
sebromero May 9, 2023
f5e6718
nicla-system: Add more documentation.
sebromero May 10, 2023
d2271c1
nicla-system: Simplify the watchdog reset machanism.
sebromero May 10, 2023
14117b6
nicla-system: Remove unused code.
sebromero May 10, 2023
d399ee3
nicla-system: Increase safety charge time from 3 to 9 hours.
sebromero May 10, 2023
9bce6e8
nicla-system: Add more documentation.
sebromero May 11, 2023
c316d06
nicla-system: Add sketch that shows how to charge the battery.
sebromero May 11, 2023
21a7c56
nicla-system: Add new measurement of charge current to docs.
sebromero May 11, 2023
e51a021
nicla-system: Add option to configure safety timer.
sebromero May 11, 2023
5fff648
nicla-system: Make the safety timer configuration explicit.
sebromero May 11, 2023
1ca6fc3
nicla-system: Apply suggestions from Ali's code review.
sebromero May 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
nicla-sense-pmic: Use function to toggle Hi-Z mode.
  • Loading branch information
sebromero committed Apr 28, 2023
commit d8fc79883820416d2a89f28451e6a60649c81c90
19 changes: 17 additions & 2 deletions libraries/Nicla_System/src/BQ25120A.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#define BQ25120A_ADDRESS 0x6A

// Register Map
// https://www.ti.com/lit/ds/symlink/bq25120a.pdf?ts=1610608851953&ref_url=https%253A%252F%252Fwww.startpage.com%252F
// https://www.ti.com/lit/ds/symlink/bq25120a.pdf
#define BQ25120A_STATUS 0x00
#define BQ25120A_FAULTS 0x01
#define BQ25120A_TS_CONTROL 0x02
#define BQ25120A_FAST_CHG 0x03
#define BQ25120A_TERMINATION_CURR 0x04
#define BQ25120A_BATTERY_CTRL 0x05
#define BQ25120A_BATTERY_CTRL 0x05 // Battery Voltage Control Register
#define BQ25120A_SYS_VOUT_CTRL 0x06
#define BQ25120A_LDO_CTRL 0x07
#define BQ25120A_PUSH_BUTT_CTRL 0x08
Expand All @@ -29,6 +29,21 @@ class BQ25120A
void writeByte(uint8_t address, uint8_t subAddress, uint8_t data);
uint8_t readByte(uint8_t address, uint8_t subAddress);

private:
/**
* @brief Set the High Impedance Mode Enabled or Disabled.
* When enabled, drives the CD pin low to enter high impedance mode.
* Note that this only applies when powered with a battery and the condition VIN < VUVLO is met.
* When VIN > VUVLO this enables charging instead.
*
* When disabled, drives the CD pin high to exit high impedance mode (Active Battery).
* When VIN > VUVLO this disables charging.
* When exiting this mode, charging resumes if VIN is present, CD is low and charging is enabled.
*
* @note The CD pin is internally pulled down.
* @param enabled Defines if the high impedance mode should be enabled or disabled.
*/
void setHighImpedanceModeEnabled(bool enabled);
};

#endif
23 changes: 18 additions & 5 deletions libraries/Nicla_System/src/pmic_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
#include "Nicla_System.h"
#include "DigitalOut.h"

static mbed::DigitalOut cd(p25);
// Set the CD pin to low to enter high impedance mode
// Note that this only applies when powered with a battery
// and the condition VIN < VUVLO is met.
// When VIN > VUVLO this enables charging.
static mbed::DigitalOut cd(p25, 0);

uint8_t BQ25120A::getStatus()
{
Expand All @@ -14,19 +18,19 @@ uint8_t BQ25120A::getStatus()

void BQ25120A::writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
{
cd = 1;
setHighImpedanceModeEnabled(false);
nicla::i2c_mutex.lock();
Wire1.beginTransmission(address);
Wire1.write(subAddress);
Wire1.write(data);
Wire1.endTransmission();
nicla::i2c_mutex.unlock();
cd = 0;
setHighImpedanceModeEnabled(true);
}

uint8_t BQ25120A::readByte(uint8_t address, uint8_t subAddress)
{
cd = 1;
setHighImpedanceModeEnabled(false);
nicla::i2c_mutex.lock();
Wire1.beginTransmission(address);
Wire1.write(subAddress);
Expand All @@ -37,6 +41,15 @@ uint8_t BQ25120A::readByte(uint8_t address, uint8_t subAddress)
while(!Wire1.available() && (millis() - start_time) < timeout) {}
uint8_t ret = Wire1.read();
nicla::i2c_mutex.unlock();
cd = 0;
setHighImpedanceModeEnabled(true);
return ret;
}

void BQ25120A::setHighImpedanceModeEnabled(bool enabled) {
if(enabled){
cd = 0;
} else {
cd = 1;
delayMicroseconds(64); // Give some time to the BQ25120A to wake up
}
}