-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
firmware: devices: battery_monitor: Added functions to read missing r…
…esult registers #157
- Loading branch information
1 parent
ca59618
commit 2d82374
Showing
2 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,9 @@ | |
* \brief Battery Monitor device implementation. | ||
* | ||
* \author Vinicius Pimenta Bernardo <[email protected]> | ||
* \author Ramon de Araujo Borba <[email protected]> | ||
* | ||
* \version 0.1.12 | ||
* \version 0.4.0 | ||
* | ||
* \date 2021/09/18 | ||
* | ||
|
@@ -120,15 +121,15 @@ int bm_get_raac_mah(uint16_t *data) | |
{ | ||
uint8_t rd_buf[2] = {0}; | ||
if (ds277Xg_read_data(&battery_monitor_config, DS277XG_RAAC_REGISTER_MSB, rd_buf, 2) != 0) {return -1;} | ||
*data = (uint16_t)((rd_buf[1] << 8) + rd_buf[0]); | ||
*data = (uint16_t)(((rd_buf[0] << 8) + rd_buf[1]) * 1.6); | ||
return 0; | ||
} | ||
|
||
int bm_get_rsac_mah(uint16_t *data) | ||
{ | ||
uint8_t rd_buf[2] = {0}; | ||
if (ds277Xg_read_data(&battery_monitor_config, DS277XG_RSAC_REGISTER_MSB, rd_buf, 2) != 0) {return -1;} | ||
*data = (uint16_t)((rd_buf[1] << 8) + rd_buf[0]); | ||
*data = (uint16_t)(((rd_buf[0] << 8) + rd_buf[1]) * 1.6); | ||
return 0; | ||
} | ||
|
||
|
@@ -143,3 +144,35 @@ int bm_get_rsrc_percent(uint8_t *data) | |
if (ds277Xg_read_data(&battery_monitor_config, DS277XG_RSRC_REGISTER, data, 1) != 0) {return -1;} | ||
return 0; | ||
} | ||
|
||
int bm_get_acc_current_mah(uint16_t *data) | ||
{ | ||
uint8_t rd_buf[2] = {0}; | ||
if (ds277Xg_read_data(&battery_monitor_config, DS277XG_ACCUMULATED_CURRENT_MSB, rd_buf, 2) != 0) { return -1; } | ||
*data = ds277Xg_accumulated_current_raw_to_mah((uint16_t)((rd_buf[0] << 8) + rd_buf[1])); | ||
return 0; | ||
} | ||
|
||
int bm_get_full_capacity_ppm(uint32_t *data) | ||
{ | ||
uint8_t rd_buf[2] = {0}; | ||
if (ds277Xg_read_data(&battery_monitor_config, DS277XG_FULL_REGISTER_MSB, rd_buf, 2) != 0) { return -1; } | ||
*data = ((uint32_t)(((rd_buf[0] << 8) + rd_buf[1]) >> 1) * 61); | ||
return 0; | ||
} | ||
|
||
int bm_get_active_empty_capacity_ppm(uint32_t *data) | ||
{ | ||
uint8_t rd_buf[2] = {0}; | ||
if (ds277Xg_read_data(&battery_monitor_config, DS277XG_ACTIVE_EMPTY_REGISTER_MSB, rd_buf, 2) != 0) { return -1; } | ||
*data = ((uint32_t)(((rd_buf[0] << 8) + rd_buf[1]) >> 1) * 61); | ||
return 0; | ||
} | ||
|
||
int bm_get_standby_empty_capacity_ppm(uint32_t *data) | ||
{ | ||
uint8_t rd_buf[2] = {0}; | ||
if (ds277Xg_read_data(&battery_monitor_config, DS277XG_STANDBY_EMPTY_REGISTER_MSB, rd_buf, 2) != 0) { return -1; } | ||
*data = ((uint32_t)(((rd_buf[0] << 8) + rd_buf[1]) >> 1) * 61); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,9 @@ | |
* \brief Battery Monitor device definition. | ||
* | ||
* \author Vinicius Pimenta Bernardo <[email protected]> | ||
* \author Ramon de Araujo Borba <[email protected]> | ||
* | ||
* \version 0.1.12 | ||
* \version 0.4.0 | ||
* | ||
* \date 2021/09/18 | ||
* | ||
|
@@ -148,6 +149,38 @@ int bm_get_rarc_percent(uint8_t *data); | |
*/ | ||
int bm_get_rsrc_percent(uint8_t *data); | ||
|
||
/** | ||
* \brief Get the battery monitor accumulated current in mAh. | ||
* | ||
* \param[in,out] data Register data. | ||
* \return int The status/error code. | ||
*/ | ||
int bm_get_acc_current_mah(uint16_t *data); | ||
|
||
/** | ||
* \brief Get the battery monitor full capacity result register in ppm. | ||
* | ||
* \param[in,out] data Register data. | ||
* \return int The status/error code. | ||
*/ | ||
int bm_get_full_capacity_ppm(uint32_t *data); | ||
|
||
/** | ||
* \brief Get the battery monitor active empty capacity result register in ppm. | ||
* | ||
* \param[in,out] data Register data. | ||
* \return int The status/error code. | ||
*/ | ||
int bm_get_active_empty_capacity_ppm(uint32_t *data); | ||
|
||
/** | ||
* \brief Get the battery monitor standby empty capacity result register in ppm. | ||
* | ||
* \param[in,out] data Register data. | ||
* \return int The status/error code. | ||
*/ | ||
int bm_get_standby_empty_capacity_ppm(uint32_t *data); | ||
|
||
#endif /* BATTERY_MONITOR_H_ */ | ||
|
||
/** \} End of battery_monitor group */ |