Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new functions for max #2202

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
56 changes: 55 additions & 1 deletion firmware/common/max17055.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool MAX17055::detect() {

// Get Data from IC
if (readMultipleRegister(0x00, _MAX17055_Data, 2, false)) {
if (((_MAX17055_Data[0] != 0x00) && (_MAX17055_Data[0] != 0x02)) || (_MAX17055_Data[1] != 0x00)) {
if (_MAX17055_Data[0] != 0x02) {
// validate result, since i2c gives a bit of power to the ic, and sometimes it sets the init value.
// this will return false when the ic is in init state (0x0002), but on the next iteration it'll give the good value
if (detected_ == false) {
Expand Down Expand Up @@ -343,6 +343,60 @@ bool MAX17055::setDesignCapacity(const uint16_t _Capacity) {
return _Result;
}

bool MAX17055::setFullCapRep(const uint16_t _Capacity) {
// Set Raw
uint16_t _Raw_Cap = (uint16_t)_Capacity * 2;

// Declare Default Data Array
uint8_t _Data[2];

// Set Data Low/High Byte
_Data[0] = ((_Raw_Cap & (uint16_t)0x00FF));
_Data[1] = ((_Raw_Cap & (uint16_t)0xFF00) >> 8);

// Set Register
bool _Result = writeMultipleRegister(0x10, _Data, 2);

// End Function
return _Result;
}

bool MAX17055::setFullCapNom(const uint16_t _Capacity) {
// Set Raw
uint16_t _Raw_Cap = (uint16_t)_Capacity * 2;

// Declare Default Data Array
uint8_t _Data[2];

// Set Data Low/High Byte
_Data[0] = ((_Raw_Cap & (uint16_t)0x00FF));
_Data[1] = ((_Raw_Cap & (uint16_t)0xFF00) >> 8);

// Set Register
bool _Result = writeMultipleRegister(0x23, _Data, 2);

// End Function
return _Result;
}

bool MAX17055::setRepCap(const uint16_t _Capacity) {
// Set Raw
uint16_t _Raw_Cap = (uint16_t)_Capacity * 2;

// Declare Default Data Array
uint8_t _Data[2];

// Set Data Low/High Byte
_Data[0] = ((_Raw_Cap & (uint16_t)0x00FF));
_Data[1] = ((_Raw_Cap & (uint16_t)0xFF00) >> 8);

// Set Register
bool _Result = writeMultipleRegister(0x05, _Data, 2);

// End Function
return _Result;
}

bool MAX17055::setMinSOC(uint8_t _Minimum_SOC) {
// Define Data Variable
uint8_t MAX17055_Current_Data[2];
Expand Down
11 changes: 7 additions & 4 deletions firmware/common/max17055.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

// Define Maximum Voltage
#ifndef __MAX17055_Max_Voltage__
#define __MAX17055_Max_Voltage__ 4.175 // Maximum Voltage
#define __MAX17055_Max_Voltage__ 4.17 // Maximum Voltage
#endif

// Define Empty Voltage
Expand All @@ -72,7 +72,7 @@

// Define Recovery Voltage
#ifndef __MAX17055_Recovery_Voltage__
#define __MAX17055_Recovery_Voltage__ 3.7 // Recovery Voltage
#define __MAX17055_Recovery_Voltage__ 3.1 // Recovery Voltage
#endif

// Define Maximum Current
Expand Down Expand Up @@ -105,12 +105,12 @@

// Define Minimum SOC
#ifndef __MAX17055_Min_SOC__
#define __MAX17055_Min_SOC__ 20 // Minimum SOC
#define __MAX17055_Min_SOC__ 0 // Minimum SOC
#endif

// Define Maximum SOC
#ifndef __MAX17055_Max_SOC__
#define __MAX17055_Max_SOC__ 90 // Maximum SOC
#define __MAX17055_Max_SOC__ 100 // Maximum SOC
#endif

// Config1 (0x1D) Configuration
Expand Down Expand Up @@ -303,6 +303,9 @@ class MAX17055 {
bool setMaxCurrent(uint16_t _Maximum_Current);
bool setChargeTerminationCurrent(uint16_t _Charge_Termination_Current);
bool setDesignCapacity(const uint16_t _Capacity);
bool setFullCapRep(const uint16_t _Capacity);
bool setFullCapNom(const uint16_t _Capacity);
bool setRepCap(const uint16_t _Capacity);
bool setMinSOC(uint8_t _Minimum_SOC);
bool setMaxSOC(uint8_t _Maximum_SOC);
bool setMinTemperature(uint8_t _Minimum_Temperature);
Expand Down
Loading