zmk icon indicating copy to clipboard operation
zmk copied to clipboard

feat(drivers): add driver for MAX17048 fuel gauge

Open zhiayang opened this issue 2 years ago • 1 comments

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

zhiayang avatar May 14 '22 18:05 zhiayang

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

zhiayang avatar Jun 04 '22 09:06 zhiayang

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

zhiayang avatar Dec 21 '22 09:12 zhiayang

fixed formatting

zhiayang avatar Jan 09 '23 06:01 zhiayang

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 :/

ebastler avatar Mar 30 '23 15:03 ebastler

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

zhiayang avatar Apr 05 '23 12:04 zhiayang

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 avatar Apr 05 '23 12:04 ebastler

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.

ebastler avatar May 08 '23 16:05 ebastler

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!

zhiayang avatar May 10 '23 14:05 zhiayang

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.

ebastler avatar May 10 '23 14:05 ebastler

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

zhiayang avatar Sep 03 '23 20:09 zhiayang

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 avatar Sep 03 '23 20:09 ebastler

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 avatar Sep 14 '23 22:09 ebastler

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

ebastler avatar Sep 15 '23 10:09 ebastler

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.

xudongzheng avatar Sep 24 '23 14:09 xudongzheng