Thanks to your replies, and sorry for the late reply, I was busy with university stuff
So to summarize things:
If a computer is connected- Most computers will have 15kOhm resistors connected from the data lines to GND
- Apple uses some resistive divider which puts a weak voltage on the data pins
If a Charger/Wall- adapter is connected- Most chargers will short the data lines together
- Some also let them open
Ok so far so good.
Then there is still the (problem) with the 500mA current draw from a USB port without previous enumeration. I imho think that this is only a problem on paper and not so much in the real world. As nearly every "dumb" gadget, without a bigass processor in it, will violate the spec. It's simply not up for debate to invest a couple of bucks for a processor, which can handle USB communication, only to correctly enumerate the device to the USB host. µC's with built in USB are most of the time really expensive and come in huge pincount packages, which are complete useless, if the USB powered device in question doesn't need a processor at all.
If that would've been a big problem in the past, chip manufactures would have added a USB controller to their products. So f.e. a Li-IOn battery charger would then automatically enumerate itself to the USB host and requesting to draw 500mA.
Even Maxim on their page on "Charging batteries using USB Power" write about it.
http://www.maximintegrated.com/app-notes/index.mvp/id/3241What Your Mom Didn't Tell You About USB
With any standard, it's interesting to see how actual practice diverges from the printed spec or how undefined parts of the spec take shape. Though USB is, with little doubt, one of the best thought out, reliable, and useful standards efforts in quite some time, it has not been immune to the impact of the real world. Some observed USB characteristics that may not be obvious, yet can influence power designs, are:
- USB ports do NOT limit current. Though the USB spec provides details about how much current a USB port must supply, there are mile-wide limits on how much it might supply. Though the upper limit specifies that the current never exceed 5A, but a wise designer should not rely on that. In any case, a USB port can never be counted on to limit its output current to 500mA, or any amount near that. In fact, output current from a port often exceeds several Amps since multi-port systems (like PCs) frequently have only one protection device for all ports in the system. The protection device is set above the TOTAL power rating of all the ports. So a four-port system may supply over 2A from one port if the other ports are not loaded. Furthermore, while some PCs use 10-20% accurate IC-based protection, other will use much less accurate poly-fuses (fuses that reset themselves) that will not trip until the load is 100% or more above the rating.
- USB Ports rarely (never) turn off power: The USB spec is not specific about this, but it is sometimes believed that USB power may be disconnected as a result of failed enumeration, or other software or firmware problems. In actual practice, no USB host shuts off USB power for anything other that an electrical fault (like a short). There may an exception to this statement, but I have yet to see it. Notebook and motherboard makers are barely willing to pay for fault protection, let alone smart power switching. So no matter what dialog takes place (or does not take place) between a USB peripheral and host, 5V (at either 500mA or 100mA, or even maybe 2A or more) will be available. This is born out by the appearance in the market of USB powered reading lights, coffee mug warmers, and other similar items that have no communication capability. They may not be "compliant," but they do function.
Ok now back to my project:
As I can't go without a little microcontroller on my PCB (ATTiny10) I have tought up the following scenario.
One of the Data Lines is pulled up to +5V via a 100kOhm resistor. The Data pin is also connected to a ADC pin of the ATTiny.
If a computer is connected the 100kOhm pullup resistor and 15kOhm pulldown resistor in the computers USB hub form a voltage divider which gives out voltage of around 700mV. If a mac is connected it's voltage level on the data- line could also be detected as the 100kOhm pullup is really weak.
If now a Walladapter is connected and the datalines are shorted or open, the 100kOhm pullup ties the voltage on the data- line up to +5V which the µC can measure and recognize.
And now I can hear you ask why I have to use a µC for that, becaus that could also be achieved using a handful of discrete parts?
Now I need the µC to ajust the charging current when using a walladapter. Because you can't assume that every walladapter a user can plug into the charger can supply the full 1A of charging current. Therfore I use another ADC pin of the Tiny10 which is connected to the USB bus voltage and a PWM pin to set the current of the charging chip. The PWM gets filtered trough a 2nd order low pass filter, gets decoupled with a diode and then put on the current set pin of the charging chip. The µC then increases the PWM DC thus increasing the charging current. While doing so it measures the USB bus voltage coming from the wall- adapter. If it detects a significant voltage drop, that means that the walladapter is near overload, and so it stops increasing the charge current. The current where the USB voltage started to drop is going to be decreased 10% and then used for charging.