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

feat(drivers): add driver for MAX17048 fuel gauge #1301

Merged
merged 13 commits into from
Sep 26, 2023

Conversation

zhiayang
Copy link
Contributor

@zhiayang zhiayang commented May 14, 2022

Adds a driver for MAX17048 I2C fuel gauge. Works on real hardware.

@zhiayang zhiayang force-pushed the sensor-driver-max17048 branch from 5e4bffe to c03ef6b Compare May 14, 2022 18:33
@zhiayang
Copy link
Contributor Author

zhiayang commented Jun 4, 2022

I'll incorporate the changes noted in the review for #1295 in the near future

@caksoylar caksoylar added enhancement New feature or request core Core functionality/behavior of ZMK labels Jul 4, 2022
struct max17048_drv_data *const drv_data = dev->data;
uint16_t dev_addr = ((struct max17048_config *)dev->config)->device_addr;

uint16_t data = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

some people on the discord have noted that this code doesn't work very well, and should be changed to uint8_t[2] instead. will fix soon.

Copy link
Contributor

@petejohanson petejohanson left a comment

Choose a reason for hiding this comment

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

One other item needs fixing.

app/drivers/sensor/max17048/max17048.c Outdated Show resolved Hide resolved
@zhiayang zhiayang force-pushed the sensor-driver-max17048 branch from d439287 to afc7187 Compare December 21, 2022 09:22
@zhiayang
Copy link
Contributor Author

Addressed the comments, including the bogus 16-bit register read/write routines -- they should be actually correct now.

@zhiayang
Copy link
Contributor Author

zhiayang commented Jan 9, 2023

fixed formatting

@ebastler
Copy link
Contributor

ebastler commented Mar 30, 2023

Any news on this one? Did I make a mistake in my implementation, or is the driver in its current state softbricking other boards too? Couldn't get my Osprey to work with the current state anymore. Can't really debug as it doesn't even enumerate over USB.

Not sure if something about config syntax changed, or the driver itself has a problem.

EDIT: Just tried off the latest master branch again, no chance :/

@zhiayang
Copy link
Contributor Author

zhiayang commented Apr 5, 2023

sorry, i haven't had much time to look at this recentl ><

@ebastler
Copy link
Contributor

ebastler commented Apr 5, 2023

Haha, I just had it open when your answer popped up few seconds later.

Sorry, I didn't want to rush you - you're doing this in your spare time and I can fully understand not spending countless hours on it! Just thought maybe you had a local dev branch that hadn't been pushed or something!

I rolled back to the older version, works fine again for me.

ebastler added a commit to ebastler/zmk that referenced this pull request May 8, 2023
@ebastler
Copy link
Contributor

ebastler commented May 8, 2023

I've been trying to find out just what was wrong with the driver for me and ended up debugging a few things. This branch had the latest driver of yours added (I added files manually since I didn't know how to properly cherry-pic a commit). https://github.com/ebastler/zmk/tree/MAX17048_tempfix

I then changed everything that was needed to get it to compile with the latest zephyr 3.2 based ZMK (not much, a few includes needed zephyr/ as part of their path) and then tried to line by line add stuff from the latest driver to the older driver (that worked on my hardware) until I narrowed the issues down - see third commit in the linked repo.

This was as far as I could get by just testing code, to write a proper fix that's not just "I comment the stuff out that breaks my board" I lack C knowledge.

I do not know why the semaphores work flawlessly in other functions, but break set_rcomp_value() and set_sleep_enabled().

Maybe my narrowing down helps you find the actual cause of the issues, and saves you some work. For now I'm happy I managed a workaround for my boards.

@zhiayang
Copy link
Contributor Author

zhiayang commented May 10, 2023

I know what's the problem — I'm using the semaphore before I initialise it, in the driver init function. Silly me 🤡

I'll fix up this PR this week. Thanks for doing the investigation legwork!

@ebastler
Copy link
Contributor

Oh, I did not realize it was initialized after those two functions are/may be called! Glad I could help, thank you very much for your work on this driver. It's awesome.

@zhiayang zhiayang force-pushed the sensor-driver-max17048 branch from 412d075 to 1275419 Compare May 16, 2023 13:25
@zhiayang zhiayang force-pushed the sensor-driver-max17048 branch from 1275419 to c6f1429 Compare September 3, 2023 20:11
@zhiayang zhiayang requested a review from a team as a code owner September 3, 2023 20:11
@zhiayang
Copy link
Contributor Author

zhiayang commented Sep 3, 2023

I've updated the code so it compiles with the latest ZMK/Zephyr. Appreciate if this could be looked at again soon!

@ebastler
Copy link
Contributor

ebastler commented Sep 3, 2023

Thanks for the update! I'll be away from home for another 1-2 weeks, once I return I will try the updated version on hardware. I have 2 different boards with this chip to test it.

@ebastler
Copy link
Contributor

image

Compiles and works fine for me, tested on 2 different PCBs. I'll keep an eye open for glitches and will report back, but seems to be working well!

@ebastler
Copy link
Contributor

Tested your latest changes, still works as intended on my hardware.

@xudongzheng
Copy link
Contributor

Zephyr 3.4 added its own MAX17048 driver https://github.com/zephyrproject-rtos/zephyr/tree/main/drivers/fuel_gauge/max17048.

I would suggest incorporating that if possible, rather than maintaining a separate driver within ZMK.

@zhiayang zhiayang force-pushed the sensor-driver-max17048 branch 2 times, most recently from a8f6d96 to d12a41d Compare September 24, 2023 14:55
Copy link
Contributor

@petejohanson petejohanson left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks!

@petejohanson petejohanson merged commit 8abc449 into zmkfirmware:main Sep 26, 2023
@zhiayang zhiayang deleted the sensor-driver-max17048 branch September 30, 2023 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core functionality/behavior of ZMK enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants