-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
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 |
@anatoliy6 please have a look at our coding conventions and adapt your PR accordingly. Furthermore you might want to run |
@anatoliy6 did you have a chance to check our conventions? |
Hey Peter,
Yes I did. My C programming skills are a bit rusty and i had a little
progress beyond the uncrustify script. My colleague is pushing me to finish
the work this week, so I'm back on it.
Apologize for the delay, I'm looking forward to get the patch into a better
shape shortly.
Regards, Anatoliy
…On Tue, 21 May 2019 at 17:54, Peter Kietzmann ***@***.***> wrote:
@anatoliy6 <https://github.com/anatoliy6> did you have a chance to check
our conventions?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10882?email_source=notifications&email_token=ALGCNKAOMTR73ZUG5GGEYELPWQEJFA5CNFSM4GSS5LV2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODV4FR3Q#issuecomment-494426350>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALGCNKFOQZU35UGO3LPP6D3PWQEJFANCNFSM4GSS5LVQ>
.
|
@anatoliy6 no worries! Please ping @MichelRottleuthner and me once done |
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 |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
@anatoliy6 do you still want to work on this? |
Yes. I am. Almost ready with refactoring. |
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) |
@anatoliy6 any progress? |
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 |
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. |
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.