Rockbox

Tasklist

FS#4770 - H3x0: New USB Charging Functionality

Attached to Project: Rockbox
Opened by pyro (dohanc) - Saturday, 04 March 2006, 20:26 GMT
Task Type Patches
Category Battery/Charging
Status Closed
Assigned To No-one
Operating System Iriver H300 series
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

1.) USB charging for h3x0 by turning on MOSFET in PCF50606 initialization.
2.) USB_inserted also supplies the h300 with power as well as charges it. Before only USB_powered state was known to power/charge device. Added to powermanagement.
3.) Battery symbol in statusbar now animates while charging on USB_inserted. This changed USB_powered to
USB_inserted in statusbar info. *
4.) Added USB Inserted line to Debug Menu --> View Battery menu. This isn't necessary, just maybe nice to have.

* Note when USB and Power Charger are both plugged in, statusbar symbol will show USB plugged in. It has to show one or the other, and it was easiest to leave it showing USB.

Hopefully we can get the boot loader to boot Rockbox on AC now that this is solved :P Unfortunetly, I am not brave enough to try it without a GDB to reprogram.
This task depends upon

Closed by  Steve Bavin (pondlife)
Thursday, 01 February 2007, 10:49 GMT
Reason for closing:  Accepted
Additional comments about closing:  Committed. Thanks pyro.
Comment by Benoit-Pierre Guay (benacool) - Monday, 06 March 2006, 04:03 GMT
Good job for your patch pyro, thank you!

But I think I found a bug. After I had recharged my player, I plugued it to my computer to transfer some files. So it started to charge normally. I unpluged it and repluged it by holding REC to let it continue to charge without going in USB mode. It stopped charging few minutes later but I had started playing a file in the mainwhile. So when the hard drive started to spin after some time, it started to charge again for few minutes and stopped again. And it do this again and again everytime the hard drive spins.

I don't think it's a good thing for the battery... No ?
Comment by pyro (dohanc) - Monday, 06 March 2006, 17:14 GMT
I have not tested this while the battery was 100% full. However, I believe this is normal and to be expected. The LX2201 charging IC (hardware charges the H3x0 series, not software) will go into a Voltage Monitoring Mode when the battery has reached 97% of full charge. Above 97% the battery will not charge. You should however see the small USB plug symbol when the battery is above 97% meaning the device is still partially powered from USB. When you run the hard disk the battery probably falls briefly under 97% and starts charging. We are simply reading the status of the hardware charging circuit.

I am curious if the iriver firmware does not do this? If it does not, I'm not sure why or how. I don't believe this is bad for the battery.
Comment by Benoit-Pierre Guay (benacool) - Monday, 06 March 2006, 18:14 GMT
In iriver firmware, after a completed charge, the player never start to charge again untill you unplug and plug again the USB or the AC adapter. So after it finish recharging, it only use power from the AC Adapter or USB insteed of using the battery, untill you unplug them.
Comment by Benoit-Pierre Guay (benacool) - Monday, 06 March 2006, 18:35 GMT
By the way thanks for the clarification! :-) So if I well uderstood, when it "seems" to start charging again it only read the status of the charging circuit and don't really start to charge again.
Comment by Linus Nielsen Feltzing (linusnielsen) - Monday, 06 March 2006, 19:03 GMT
You said "In iriver firmware, after a completed charge, the player never start to charge again untill you unplug and plug again the USB or the AC adapter. So after it finish recharging, it only use power from the AC Adapter or USB insteed of using the battery, untill you unplug them."

How do you know this? have you disassembled the iriver firmware?

I'm pretty sure it keeps maintaining the battery charge, just like Rockbox does.
Comment by Benoit-Pierre Guay (benacool) - Monday, 06 March 2006, 19:12 GMT
I only said this by what I saw in the original firmware. Obviously I never disassembled the iriver firmware! I just tried to help... So I imagine that the iriver firmware just don't show it.
Comment by Linus Nielsen Feltzing (linusnielsen) - Tuesday, 07 March 2006, 07:35 GMT
pyro, I need your real name for the credits.

I wonder why you changed the statusbar code in that way? Is it compatible with the Archos Ondio, which doesn't have rechargeable batteries, but can be powered by USB?

Also, I believe we need to have an option for the USB charging mode, since having it always enabled might cause problems when connecting to an unpowered USB hub.
Comment by pyro (dohanc) - Tuesday, 07 March 2006, 16:14 GMT
Real name is Chris Dohan.

I only have basic c knowledge and therefore there very well may be much better ways to program these changes. Let me try to explain my reasoning to see if you agree. in powermgmt.c the charger_input_state (0-No Charger, 1-Charge Unplugged, 2-Charger Plugged, 3-Charger) variable is determined by whether or not the AC/DC charger is plugged in or not. Lostlogic recently submitted and comitted a patch that added an OR statement to this variable. It now read charger_input_state got updated if charger_input_state || usb_powered. What is kind of misleading is that usb_powered mode does not mean the device is powered from USB. It is only active if you hold down the REC button. Regular USB transfer mode is considered usb_inserted and not usb_powered.

The question is whether to have the charger_input_state variable reflect (AC/DC charger || Power from USB) or just AC/DC Charger and have the usb charging modes handled seperatly.

But to directly answer your question, I only changed the usb_powered to usb_inserted in statusbar.c because the device is also charging in usb_inserted mode. The battery symbol would only animate in usb_powered mode before. Again, realize usb_powered is NOT "Powered from USB" but instead the mode when you hold the REC while inserting USB.

I am not 100% sure about if the Ondio will be affected by the change since the code still checks charging_state==CHARGING in which the Ondio should report back it is not charging. I would feel most confortable if someone could test it. I admit I have a hard time trying to distinguish between the different features of all the players.

We can add the option for USB charging mode = On/Off. Perhaps we'll wait to commit until that option is included in this patch? I also wish I could trace the signal from that LX2201 USB Hi/Low pin to maybe a GPIO pin. Lostlogic might be sending me a dead PCB to simply trace signals which would be helpful.

Feel free to change, modify, fix or recommend some other way to do it.
Comment by pyro (dohanc) - Thursday, 09 March 2006, 04:19 GMT
In case anyone cares, I will be away and most likely will not be able to do anything further with this until starting around March 20th.
Comment by Jason Bolger (galapogos01) - Monday, 20 March 2006, 23:22 GMT
I would like to add/ask: does this patch affect Firmware USB mode? It would be nice if it could charge the iriver without booting; this would make charging a completely flat iriver via USB possible, something you cant do with the iriver firmware.
Comment by Paul van der Heu (paulheu) - Tuesday, 21 March 2006, 20:50 GMT
As far as I can see this patch should behave like if the charger is plugged in as far as the backlight setting goes, but it does not. backlight stays on all the time when USB is plugged in
Comment by Paul van der Heu (paulheu) - Tuesday, 21 March 2006, 21:03 GMT
Had the last remark the wrong way around.. When USB is in, the non-plugged setting is used instead of the plugged time..
Comment by Paul van der Heu (paulheu) - Saturday, 25 March 2006, 20:52 GMT
I modified the patch to work with the current CVS..
Comment by Linus Nielsen Feltzing (linusnielsen) - Sunday, 26 March 2006, 22:44 GMT
I believe we need an option for this, otherwise the player will attempt to draw too much power from an unpowered hub.
Comment by Matthias Mohr (aka Massa) (mmohr) - Sunday, 02 April 2006, 19:58 GMT
I just tested the patch.

It's really good and I wonder why it did not get committed to the CVS???

One thing I noticed: when you set your config to see the battery numerical
in your status bar it still displays it graphical when you charge it via
USB.
Is this on intend or is this a bug?
Comment by Linus Nielsen Feltzing (linusnielsen) - Sunday, 02 April 2006, 22:48 GMT
The reason it isn't committed is that it always charges, and then the USB mode might not work on unpowered hubs, or any other USB host that doesn't give more than 100mA.
Comment by Jason Bolger (galapogos01) - Sunday, 02 April 2006, 22:59 GMT
Has anyone else noticed how slow RockBox is to charge in comparison to the iriver firmware? It took over 12 hours to charge my player (not being used). Also, USB charge mode does not seem to switch off when the player is eventually full. I checked this by swapping DC input with USB. DC would show 100% and no charge indicator, USB would show 98% and a 1px charge indicator in the graphical display.
Comment by Matthias Mohr (aka Massa) (mmohr) - Tuesday, 11 April 2006, 10:55 GMT
pyro, are you still working on this?

Could you please extend it to make it optional with an extra option to set?

And maybe fix the problem, where it still displays a graphical symbol even
when it's configured to be numerical?

I also noticed something else which I believe it has something to do with
that code.
I had problems with my date/time settings (iRiver H300) which vanishes suddenly.
Now it reappears - and I'm nearly sure it vanishes because I didn't use
this patch and reappeared after I used it again...
Please have a look at the (now closed) bug #4906:
http://www.rockbox.org/tracker/task/4906

Jason, I noticed that USB loading takes longer than loading with AC adaptor,
but I'm not sure if it's longer than with the original firmware
- I don't use it anymore :-D
Comment by Matthias Mohr (aka Massa) (mmohr) - Sunday, 23 April 2006, 22:17 GMT
O.K. I produced a new patch.

This one adds an option (General/System/Battery/Charge During USB connection)
to switch the USB charging during disk mode on or off.
As the originally patch it only works with pcf50606 based devices
(is there any other device beneath iRiver's H3x0?).

Would be nice if some persons could test it -
I put it on my H340 and it seems to work but it's not very well tested...
(actually I have no deep knowledge about the low level addresses
and settings and such, so there may be some problems which I don't see).

I also don't know how to add implementation for other targets
(BTW, for which is this useful and possible?)

Any comments are appreciated!
Comment by Matthias Mohr (aka Massa) (mmohr) - Sunday, 23 April 2006, 23:16 GMT
Warning!
It seems my above patch has a secret problem!

My device hangs at the initial rockbox splash screen
when rebooting after I enabled and saved the settings
for the USB charging!

I have no idea why - maybe somebody else can have a look
at the sources and give me a hint what's going on...

[EDIT - 20060424:] Now it no longer hangs!
I had to reset the settings by clearing them inside
the old (working) version. Pressing "REC" during
startup made the device hang with "Clearing" message :-(

Anyway - the hanging has nothing to do with the patch!
Comment by Paul van der Heu (paulheu) - Sunday, 23 April 2006, 23:26 GMT
Works fine here
Comment by Matthias Mohr (aka Massa) (mmohr) - Monday, 24 April 2006, 07:38 GMT
Hmm - even an unpatched CVS build does hang my device now :(

Only if I go back to my previous version which is based on
a 20060418 CVS and includes a lot patches does work.

I'm not sure what's going on, but it seems it has nothing to do with the USB patch...
(I already cleared my settings and deleted the tagcache files
- nothing helped...)

[EDIT: 20060424] Hanging is no longer a problem (see above)
Comment by Paul van der Heu (paulheu) - Monday, 24 April 2006, 09:08 GMT
try my latest experimental build, www.paulgeluid.nl/rockbox/rb-exp-2.4.17.zip .. it contains your patch and I have had no problems with it
Comment by Matthias Mohr (aka Massa) (mmohr) - Monday, 24 April 2006, 12:07 GMT
Here is an updated patch which removes some codelines from another patch
which accident found their way into this...

I didn't change any functionality!
Comment by Paul van der Heu (paulheu) - Tuesday, 02 May 2006, 12:25 GMT
It appears the patch does not function, no matter what setting you try, the 'power inserted' icons comes on, but no charging. original patch is fine..
Comment by Matthias Mohr (aka Massa) (mmohr) - Tuesday, 02 May 2006, 15:17 GMT
Here is a new version of the patch.
It changes two things:
- it makes sure, the IRQ is correctly set (thanks to amiconn for this)
- and it does (currently) not directly read the PCF50606 register,
this should fix the problem with wrong detection...

So please try it again and tell me if it works now!
Comment by Matthias Mohr (aka Massa) (mmohr) - Tuesday, 02 May 2006, 16:07 GMT
Another update - now it should **really** fix the above issue.
It also adds some more entries to the "Info/Debug/View Battery"
and to the "Info/Debug/View I/O ports" screens.
(just for debugging purposes)
Comment by Paul van der Heu (paulheu) - Tuesday, 02 May 2006, 17:01 GMT
Appears to work now..
Comment by Norbert Preining (norbusan) - Wednesday, 07 June 2006, 11:49 GMT
Hi all!
With the new changes in the cvs, is this patch still necessary? The code was heavily reorganized, so patching the last version of the h300-usb-charge patch doesn't work, even trying to fix the rejects seems to be be non trivial.
Thanks a lot and all the best
Norbert
Comment by Matthias Mohr (aka Massa) (mmohr) - Sunday, 11 June 2006, 14:33 GMT
Here is an updated patch for today's CVS
And yes, it's still needed - USB charging is not enabled in official CVS!
Comment by dwayne (dfpp) - Friday, 23 June 2006, 14:08 GMT
Is it possible with this patch to disable the USB connect mode in some way or have an option? I'd rather it to go into charge mode when usb is connected rather than connect mode by default as I often connect it to a USB charging device but it thinks its a PC and goes to connect mode. I know you can hold down rec to disable the connect but my preference would to have an option to disable USB connect mode entirely by default as USB power is often taken on and off (From a car usb charger)
Comment by Matthias Mohr (aka Massa) (mmohr) - Sunday, 30 July 2006, 13:14 GMT
dwayne: I added an additional patch where you can choose
how the button press during plugging in your USB chord works.
Look at " FS#5744  — Button press for USB connection or USB power only" for further information.
(this one not only works for H300 devices, it should work for
alls devices which support USB power)

Unfortunately that patch overlapps in some lines with
this patch here, so if you try to include both, you'll
get patch failures :-(

Here is another patch which combines both patches:
Comment by dwayne (dfpp) - Wednesday, 02 August 2006, 11:25 GMT
Good work, works extremely well!

Comment by Sander Sweers (infirit) - Monday, 28 August 2006, 18:10 GMT
USB charging works great for me.

One small thing that I noticed. Appart from the battery icon there is little feedback indicating it is charging. I'll make a feature request for this as it is not just for USB charging.

Anyway, thanks for the patch :-)
Comment by Matthias Mohr (aka Massa) (mmohr) - Wednesday, 30 August 2006, 23:33 GMT
Sync with todays CVS...
Comment by Brian Hall (brihall) - Wednesday, 06 September 2006, 16:19 GMT
Works great, can we please have this added to CVS so we can have it included in the CVS or daily builds? Thanks!
Comment by Matthias Mohr (aka Massa) (mmohr) - Sunday, 10 September 2006, 16:25 GMT
Well, I really don't know why this doesn't gets committed.
Ask Linus or some other core dev politely for inclusion...

BTW, if somebody can give me information which pins/levels are
used for the iAudio X5 I could add it as well
- but currently I miss that (and I don't own such a device ;)
Comment by Linus Nielsen Feltzing (linusnielsen) - Sunday, 10 September 2006, 21:55 GMT
I'll have a look at it ASAP. I'm a little busy with Real Life (tm) at the moment. The X5 is totally different when it comes to charging, so this patch only applies to the H300.
Comment by Matthias Mohr (aka Massa) (mmohr) - Sunday, 17 September 2006, 18:29 GMT
Synched to today's CVS...
Comment by dwayne (dfpp) - Tuesday, 19 September 2006, 13:02 GMT
This is working quite well for me, but was also wondering if theres a way for this to disable it at USB bootloader level as well. When I apply power via usb from power off it would be great to not go to USB bootloader mode and directly to resuming audio playback.
Comment by Jason Bolger (galapogos01) - Wednesday, 20 September 2006, 11:13 GMT
That would be a good replacement for the DC charge port boot loader functionality... any takers? Would allow for a nice car mode startup/shutdown via DC.
Comment by Matthias Mohr (aka Massa) (mmohr) - Sunday, 15 October 2006, 10:05 GMT
@dfpp: yes, it would be nice to also have it for the bootlader;
but I'm unable to do it (at least I fear to brick my device when trying ;)
-> some core dev should do it!

Here's another sync for today's CVS...
Comment by Norbert Preining (norbusan) - Friday, 27 October 2006, 10:39 GMT
Umpf, firmware/drivers/pcf50606.c is gone, can you please resync the patches. Thanks a lot!

Bye, Norbert
Comment by Matthias Mohr (aka Massa) (mmohr) - Saturday, 28 October 2006, 21:25 GMT
Another sync for today's CVS...
(I hope it will last a bit longer than the last one...)
Comment by Matthias Mohr (aka Massa) (mmohr) - Saturday, 28 October 2006, 21:44 GMT
Sorry, the last patches had a small mistake.
Now (hopefully) fixed...
Comment by Sander Sweers (infirit) - Thursday, 16 November 2006, 23:33 GMT
Unfortunately not that long...
In firmware/target/coldfire/iriver/h300/pcf50606-h300.c
+#include "logf.h"
+
+static bool usb_ch_enabled = false;

Fails because another include was added but this is an easy fix. The button press patch fails in many places which is to much for me to figure out.

It works very well thanks again for the patch :-)
Comment by Matthias Mohr (aka Massa) (mmohr) - Monday, 22 January 2007, 22:48 GMT
Sorry - I forgot to resync it :-(
Here's the sync to today's repository...

And I _REALLY_ hope that it finally got included in the SVN -
or that someone tells me what's wrong with the patch.
I'm really bored to always resync it (for nine months now)...
Comment by Steve Bavin (pondlife) - Tuesday, 23 January 2007, 12:16 GMT
Hi Matthias,

I've been testing the first patch on my H340 with a view to committing it. It seems that even with a fairly flat battery (e.g. reported at 40%), the USB current drain doesn't exceed 100mA. I know very little about the innards, but was expecting 500mA to be drawn. If this can be resolved or explained, I'll commit it.
Comment by Steve Bavin (pondlife) - Tuesday, 23 January 2007, 15:13 GMT
I've resynced it to the new settings code and attached here.
Comment by Matthias Mohr (aka Massa) (mmohr) - Wednesday, 24 January 2007, 17:04 GMT
Hi Steve,

it would really be great if this patch finally got committed!

Actually, I only set the GPOOD2 to High-Z for USB charging at the PCF50606
and set it back to pulled down for disabling USB charging.
Everything else is done by the hardware...

Did you do tests with USB charging when using the original firmware?
If the original firmware is able to charge it better, we miss something :-(
Comment by Steve Bavin (pondlife) - Thursday, 25 January 2007, 11:57 GMT
Hi Matthias,

I'm only using Windows 2000 Device Manager to read current draw, but I'm not convinced it's telling the truth! I get the following figures:
Rockbox, USB Charging ON - 100mA
Rockbox, USB Charging OFF - 100mA
RetailOS, USB Charging ON - no connection is made, no figure available
RetailOS, USB Charging OFF - 100mA

Perhaps there is some better software available, or maybe some kind soul can put a meter in series and report back here (hint!).
Comment by Steve Bavin (pondlife) - Friday, 26 January 2007, 10:53 GMT
Resync to SVN.

Loading...