Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mongoose-os-libs/bq27421
Mongoose OS Driver for TI BQ27421 Fuel Gauge
https://github.com/mongoose-os-libs/bq27421
Last synced: 3 months ago
JSON representation
Mongoose OS Driver for TI BQ27421 Fuel Gauge
- Host: GitHub
- URL: https://github.com/mongoose-os-libs/bq27421
- Owner: mongoose-os-libs
- License: other
- Created: 2019-07-08T15:40:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-12-15T00:16:59.000Z (about 3 years ago)
- Last Synced: 2024-07-31T21:51:46.551Z (6 months ago)
- Language: C
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-mongoose-os - bq27421 - Mongoose OS Driver for TI BQ27421 Fuel Gauge (Awesome Mongoose OS [![Awesome](https://awesome.re/badge.svg)](https://awesome.re) / Official Libraries)
README
# Mongoose OS Driver for TI BQ27421 Fuel Gauge
## Overview
This library contains driver for the [TI BQ27421](http://www.ti.com/product/BQ27421-G1) li-ion battery fuel gauge.
## Example usage
Initialize and read some registers:
```c
#include "mgos.h"
#include "mgos_bq27421.h"struct mgos_bq27421 *g = mgos_bq27421_create(mgos_i2c_get_global());
uint16_t dt = 0, fwv = 0, dcap = 0;
if (!mgos_bq27421_ctl_read(g, MGOS_BQ27421_CTL_DEVICE_TYPE, &dt) ||
!mgos_bq27421_ctl_read(g, MGOS_BQ27421_CTL_FW_VERSION, &fwv) ||
!mgos_bq27421_reg_read(g, MGOS_BQ27421_REG_CAP_DESIGN, &dcap)) {
// Error
}LOG(LL_INFO, ("Gauge type 0x%x, fw version 0x%x, battery design capacity %u mAh", dt, fwv, dcap));
```Update battery design capacity (signed 16-bit integer in data class 82 at offset 10):
```
if (!mgos_bq27421_data_write_i2(g, 82, 10, 1234 /* mAh */)) {
// Error
}
```The rest of the API is documented in the [include/mgos_bq27421.h](header file).
## Acknowledgements
This driver is contributed by [Watchdog System](https://www.watchdog-system.com/).
## License
Released under Apache License 2.0, see [LICENSE](LICENSE) file.