Initial Arduino library for BQ25628E I2C Battery Charger
- Add basic library structure with constructor, destructor, and begin() - Include chip ID verification (0x22) in begin() function - Add register address definitions for all BQ25628E registers - Include test example sketch with basic functionality verification - Add GitHub CI workflow and clang-format configuration - Set up project structure following Adafruit library conventions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
commit
f45c1521a4
7 changed files with 316 additions and 0 deletions
13
.clang-format
Normal file
13
.clang-format
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Language: Cpp
|
||||
BasedOnStyle: Google
|
||||
IndentWidth: 2
|
||||
ColumnLimit: 80
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BreakBeforeBraces: Attach
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
||||
SpacesBeforeTrailingComments: 1
|
||||
32
.github/workflows/githubci.yml
vendored
Normal file
32
.github/workflows/githubci.yml
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
name: Arduino Library CI
|
||||
|
||||
on: [pull_request, push, repository_dispatch]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: '3.x'
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
repository: adafruit/ci-arduino
|
||||
path: ci
|
||||
|
||||
- name: pre-install
|
||||
run: bash ci/actions_install.sh
|
||||
|
||||
- name: clang
|
||||
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
|
||||
|
||||
- name: test platforms
|
||||
run: python3 ci/build_platform.py main_platforms
|
||||
|
||||
- name: doxygen
|
||||
env:
|
||||
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
|
||||
PRETTYNAME : "Adafruit BQ25628E Arduino Library"
|
||||
run: bash ci/doxy_gen_and_deploy.sh
|
||||
48
.gitignore
vendored
Normal file
48
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# Datasheet files
|
||||
*.pdf
|
||||
*.txt
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
# IDE files
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# OS generated files
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
75
Adafruit_BQ25628E.cpp
Normal file
75
Adafruit_BQ25628E.cpp
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*!
|
||||
* @file Adafruit_BQ25628E.cpp
|
||||
*
|
||||
* @mainpage Adafruit BQ25628E I2C Battery Charger
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
* This is a library for the BQ25628E I2C Battery Charger
|
||||
*
|
||||
* Designed specifically to work with the Adafruit BQ25628E Breakout
|
||||
* ----> http://www.adafruit.com/products/
|
||||
*
|
||||
* Pick one up today in the adafruit shop!
|
||||
*
|
||||
* These chips use I2C to communicate, 2 pins are required to interface.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing products
|
||||
* from Adafruit!
|
||||
*
|
||||
* @section author Author
|
||||
*
|
||||
* Limor 'ladyada' Fried with assistance from Claude Code
|
||||
*
|
||||
* @section license License
|
||||
*
|
||||
* MIT (see license.txt)
|
||||
*/
|
||||
|
||||
#include "Adafruit_BQ25628E.h"
|
||||
|
||||
/*!
|
||||
* @brief Instantiates a new BQ25628E class
|
||||
*/
|
||||
Adafruit_BQ25628E::Adafruit_BQ25628E() {}
|
||||
|
||||
/*!
|
||||
* @brief Cleans up the BQ25628E
|
||||
*/
|
||||
Adafruit_BQ25628E::~Adafruit_BQ25628E() {
|
||||
if (i2c_dev) {
|
||||
delete i2c_dev;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets up the hardware and initializes I2C
|
||||
* @param i2c_addr
|
||||
* The I2C address to be used.
|
||||
* @param wire
|
||||
* The Wire object to be used for I2C connections.
|
||||
* @return True if initialization was successful, otherwise false.
|
||||
*/
|
||||
bool Adafruit_BQ25628E::begin(uint8_t i2c_addr, TwoWire *wire) {
|
||||
if (i2c_dev) {
|
||||
delete i2c_dev;
|
||||
}
|
||||
|
||||
i2c_dev = new Adafruit_I2CDevice(i2c_addr, wire);
|
||||
|
||||
if (!i2c_dev->begin()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify chip connection by reading part information register
|
||||
Adafruit_BusIO_Register part_info_reg = Adafruit_BusIO_Register(i2c_dev, BQ25628E_REG_PART_INFORMATION);
|
||||
uint8_t part_info = part_info_reg.read();
|
||||
|
||||
// Check for valid BQ25628E part ID (0x22)
|
||||
if (part_info != 0x22) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
83
Adafruit_BQ25628E.h
Normal file
83
Adafruit_BQ25628E.h
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/*!
|
||||
* @file Adafruit_BQ25628E.h
|
||||
*
|
||||
* This is a library for the BQ25628E I2C Battery Charger
|
||||
*
|
||||
* Designed specifically to work with the Adafruit BQ25628E Breakout
|
||||
* ----> http://www.adafruit.com/products/
|
||||
*
|
||||
* Pick one up today in the adafruit shop!
|
||||
*
|
||||
* These displays use I2C to communicate, 2 pins are required to interface.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing products
|
||||
* from Adafruit!
|
||||
*
|
||||
* @author Limor 'ladyada' Fried with assistance from Claude Code
|
||||
* @license MIT (see license.txt)
|
||||
*/
|
||||
|
||||
#ifndef _ADAFRUIT_BQ25628E_H
|
||||
#define _ADAFRUIT_BQ25628E_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <Adafruit_BusIO_Register.h>
|
||||
#include <Adafruit_I2CDevice.h>
|
||||
|
||||
/*! Default I2C address for the BQ25628E */
|
||||
#define BQ25628E_DEFAULT_ADDR 0x6A
|
||||
|
||||
/*! Register addresses for the BQ25628E */
|
||||
#define BQ25628E_REG_CHARGE_CURRENT_LIMIT 0x02
|
||||
#define BQ25628E_REG_CHARGE_VOLTAGE_LIMIT 0x04
|
||||
#define BQ25628E_REG_INPUT_CURRENT_LIMIT 0x06
|
||||
#define BQ25628E_REG_INPUT_VOLTAGE_LIMIT 0x08
|
||||
#define BQ25628E_REG_MINIMAL_SYSTEM_VOLTAGE 0x0E
|
||||
#define BQ25628E_REG_PRECHARGE_CONTROL 0x10
|
||||
#define BQ25628E_REG_TERMINATION_CONTROL 0x12
|
||||
#define BQ25628E_REG_CHARGE_CONTROL 0x14
|
||||
#define BQ25628E_REG_CHARGE_TIMER_CONTROL 0x15
|
||||
#define BQ25628E_REG_CHARGER_CONTROL_0 0x16
|
||||
#define BQ25628E_REG_CHARGER_CONTROL_1 0x17
|
||||
#define BQ25628E_REG_CHARGER_CONTROL_2 0x18
|
||||
#define BQ25628E_REG_CHARGER_CONTROL_3 0x19
|
||||
#define BQ25628E_REG_NTC_CONTROL_0 0x1A
|
||||
#define BQ25628E_REG_NTC_CONTROL_1 0x1B
|
||||
#define BQ25628E_REG_NTC_CONTROL_2 0x1C
|
||||
#define BQ25628E_REG_CHARGER_STATUS_0 0x1D
|
||||
#define BQ25628E_REG_CHARGER_STATUS_1 0x1E
|
||||
#define BQ25628E_REG_FAULT_STATUS_0 0x1F
|
||||
#define BQ25628E_REG_CHARGER_FLAG_0 0x20
|
||||
#define BQ25628E_REG_CHARGER_FLAG_1 0x21
|
||||
#define BQ25628E_REG_FAULT_FLAG_0 0x22
|
||||
#define BQ25628E_REG_CHARGER_MASK_0 0x23
|
||||
#define BQ25628E_REG_CHARGER_MASK_1 0x24
|
||||
#define BQ25628E_REG_FAULT_MASK_0 0x25
|
||||
#define BQ25628E_REG_ADC_CONTROL 0x26
|
||||
#define BQ25628E_REG_ADC_FUNCTION_DISABLE_0 0x27
|
||||
#define BQ25628E_REG_IBUS_ADC 0x28
|
||||
#define BQ25628E_REG_IBAT_ADC 0x2A
|
||||
#define BQ25628E_REG_VBUS_ADC 0x2C
|
||||
#define BQ25628E_REG_VPMID_ADC 0x2E
|
||||
#define BQ25628E_REG_VBAT_ADC 0x30
|
||||
#define BQ25628E_REG_VSYS_ADC 0x32
|
||||
#define BQ25628E_REG_TS_ADC 0x34
|
||||
#define BQ25628E_REG_TDIE_ADC 0x36
|
||||
#define BQ25628E_REG_PART_INFORMATION 0x38
|
||||
|
||||
/*!
|
||||
* @brief Class that stores state and functions for interacting with
|
||||
* the BQ25628E I2C Battery Charger
|
||||
*/
|
||||
class Adafruit_BQ25628E {
|
||||
public:
|
||||
Adafruit_BQ25628E();
|
||||
~Adafruit_BQ25628E();
|
||||
bool begin(uint8_t i2c_addr = BQ25628E_DEFAULT_ADDR, TwoWire *wire = &Wire);
|
||||
|
||||
private:
|
||||
Adafruit_I2CDevice *i2c_dev; /*!< Pointer to I2C bus interface */
|
||||
};
|
||||
|
||||
#endif
|
||||
34
README.md
Normal file
34
README.md
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Adafruit BQ25628E Library [](https://github.com/adafruit/Adafruit_BQ25628E/actions)[](http://adafruit.github.io/Adafruit_BQ25628E/html/index.html)
|
||||
|
||||
Arduino library for the BQ25628E I2C Battery Charger with Power Path Management
|
||||
|
||||
## About the BQ25628E
|
||||
|
||||
The BQ25628E is a 1-cell Li-Ion battery charger with power path management:
|
||||
- 2A charging current capability
|
||||
- I2C interface for control and monitoring
|
||||
- Power path management for seamless operation
|
||||
- Integrated ADC for voltage and current monitoring
|
||||
- Configurable charging parameters
|
||||
- Safety features including thermal regulation
|
||||
|
||||
## Installation
|
||||
|
||||
Download and install the library using the Arduino Library Manager or by downloading the latest release from GitHub.
|
||||
|
||||
### Dependencies
|
||||
|
||||
This library requires:
|
||||
- [Adafruit BusIO](https://github.com/adafruit/Adafruit_BusIO)
|
||||
|
||||
## Hardware
|
||||
|
||||
Connect the BQ25628E to your microcontroller via I2C. The default I2C address is 0x6A.
|
||||
|
||||
## License
|
||||
|
||||
MIT License. See LICENSE file for details.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Please read the contributing guidelines and submit pull requests to the main repository.
|
||||
31
examples/test_BQ25628E/test_BQ25628E.ino
Normal file
31
examples/test_BQ25628E/test_BQ25628E.ino
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*!
|
||||
* Test sketch for the Adafruit BQ25628E I2C Battery Charger library
|
||||
*
|
||||
* Designed specifically to work with the Adafruit BQ25628E Breakout
|
||||
* Pick one up today in the adafruit shop!
|
||||
*
|
||||
* Author: Limor 'ladyada' Fried with assistance from Claude Code
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
#include "Adafruit_BQ25628E.h"
|
||||
|
||||
Adafruit_BQ25628E bq;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial) delay(10);
|
||||
|
||||
Serial.println("Adafruit BQ25628E Test!");
|
||||
|
||||
if (!bq.begin()) {
|
||||
Serial.println("Failed to find BQ25628E chip");
|
||||
while (1) delay(10);
|
||||
}
|
||||
|
||||
Serial.println("BQ25628E Found!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(1000);
|
||||
}
|
||||
Loading…
Reference in a new issue