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

drivers: new driver for TI BQ27441 Lithium Battery Fuel Gauge #10882

Closed
wants to merge 3 commits into from

Conversation

anatoliy6
Copy link

Contribution description

BQ27441 fuel gauge for single-cell Li-Ion batteries.
This work is port of https://github.com/sparkfun/Battery_Babysitter code

Testing procedure

We are using custom hardware with bq27441-G1 that is connected to a STM32F446RE, but the setup can be replicated with any MCU and SparkFun's Battery Babysitter, or any other board that has bq27441-G1.

Issues/PRs references

No issues, no references. New driver v1.

@aabadie aabadie added Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: drivers Area: Device drivers Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties labels Jan 29, 2019
@anatoliy6
Copy link
Author

Hey @PeterKietzmann @MichelRottleuthner,

It's been a while since i've submitter this PR and i see a lot of request have been piling up, so i guess you're quite busy. Is there anything i can do or clarify to help with the review of this PR? If not i won't be bothering you soon.

Regards, Anatoliy

@PeterKietzmann
Copy link
Member

@anatoliy6 please have a look at our coding conventions and adapt your PR accordingly. Furthermore you might want to run uncrustify which is explained in more detail in there.

@PeterKietzmann
Copy link
Member

@anatoliy6 did you have a chance to check our conventions?

@anatoliy6
Copy link
Author

anatoliy6 commented May 21, 2019 via email

@PeterKietzmann
Copy link
Member

@anatoliy6 no worries! Please ping @MichelRottleuthner and me once done

@anatoliy6
Copy link
Author

Dear @PeterKietzmann @MichelRottleuthner,

I've managed to run the uncrustify script and put the last patch. I read through the coding guidelines in an effort to be compliant, but i'm not that good with the language to really determine additional changes. Please let me know if this needs more work.

Regards, Anatoliy

Copy link
Contributor

@MichelRottleuthner MichelRottleuthner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing with this PR @anatoliy6 !
I did a first review round. There are still style and doc issues and some things related to the code/functionality.
General remarks: the interface is pretty huge. For the feature completeness that is great, but adding separate calls for reading single flags seems a bit convoluted. Returning a status register value and using that value in combination with bitmasks could help here. Multiple functions could be replaced by single parameterized implementations. See below for details.
I have the hardware at hand so I can help with testing once the code is ready :)

#include "debug.h"

#ifndef I2C_ACK
#define I2C_ACK (0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicky, but please align defined values whenever possible

#endif

#include "periph/gpio.h"
#include "xtimer.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move all include lines together (these two up to the others) and please don't mix the different include types. I.e. group them into system/toolchain headers (#include <foo.h>) and other includes (include "bar.h")

#include "xtimer.h"

#define BQ72441_I2C_TIMEOUT 2000
#define BQ72441_I2C_BUFSIZE (128U)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be consistent with the style here and add parentheses to the upper one - the timeout is probably also an unsigned?

}


// Initializes I2C and verifies communication with the BQ27441.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove all of these comments from the c file. The documentation should be only be in the header.

// Configures the design capacity of the connected battery.
bool bq27441_set_capacity(bq27441_t *dev, uint16_t capacity)
{
// Write to STATE subclass (82) of BQ27441 extended memory.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For comments describing details inline please always use the multi-line format: /* this is a comment */

const unsigned int BATTERY_CAPACITY = 850;
gpio_t out_pin = GPIO_PIN(3, 3); // TODO: DEFINE CORRECTLY

i2c_acquire(params_default[0].bus);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our convention is to handle acquire and release inside of the driver functions

printf("Testing GPOUT Pulse\n");

bq27441_pulse_gpout(&dev);
int timeout = 10000; // The pulse can take a while to occur. Set max to 10s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid magic numbers

if (timeout > 0) {
// If GPOUT pulsed, print success message.
printf("GPOUT test successful!");
printf("( %d )", (10000 - timeout));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

// Exit configuration mode with the option to perform a resimulation
bool bq27441_exit_config_mode(const bq27441_t *dev, bool resim)
{
// There are two methods for exiting config mode:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is helpful documentation but should be moved to the header file so a developer using the api actually sees it.

// Get SOC1_Set Threshold - threshold to set the alert flag
uint8_t bq27441_get_soc1_set_threshold(bq27441_t *dev)
{
return _bq27441_read_extended_data(dev, BQ27441_ID_DISCHARGE, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use defines for the magic numbers here and below

@MichelRottleuthner
Copy link
Contributor

@anatoliy6 do you still want to work on this?

@anatoliy6
Copy link
Author

@anatoliy6 do you still want to work on this?

Yes. I am. Almost ready with refactoring.

@daexel
Copy link
Contributor

daexel commented Nov 4, 2019

I have tested the code and it looks like the command sequence to modify a Data Memory parameters is not working. In the code its this function: bool bq27441_enter_config_mode(bq27441_t *dev, bool userControl)

@PeterKietzmann PeterKietzmann removed the Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties label Feb 25, 2020
@PeterKietzmann
Copy link
Member

@anatoliy6 any progress?

@jeandudey
Copy link
Contributor

If wanted I could continue/test this driver if needed.

@miri64
Copy link
Member

miri64 commented Jun 24, 2020

If wanted I could continue/test this driver if needed.

@jeandudey did you?

@jeandudey
Copy link
Contributor

If wanted I could continue/test this driver if needed.

@jeandudey did you?

I have a stripped down version of this driver, no config (yet) and with the correct timing requirements for the device, would be glad to open a PR once configuration part is done

@stale
Copy link

stale bot commented Dec 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Dec 26, 2020
@stale stale bot closed this Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers State: stale State: The issue / PR has no activity for >185 days Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants