diff options
author | Torne Wuff <torne@wolfpuppy.org.uk> | 2010-06-05 10:05:27 +0000 |
---|---|---|
committer | Torne Wuff <torne@wolfpuppy.org.uk> | 2010-06-05 10:05:27 +0000 |
commit | 991e92fd3dc15f1e365761264c26305559ddb0a4 (patch) | |
tree | ac6d18cf1a803c416c0dbc8f61f521444d265ec9 /firmware/usbstack/usb_core.c | |
parent | e49464b38735585eaa0ce01f5734c0bcfad851dd (diff) | |
download | rockbox-991e92fd3dc15f1e365761264c26305559ddb0a4.tar.gz rockbox-991e92fd3dc15f1e365761264c26305559ddb0a4.zip |
New USB charging system, part 1 - API rework and user-visible setting update
1) "Charge during USB connection" option is now tristate: off/on/force. Currently "force" behaves just like "on", but in future it will allow charging even when it was not possible to positively identify a charger.
2) The H300 code has been adjusted to use the new system but there should be no functional differences, it already had the USB charging option and its USB/charging support is hardware controlled.
3) The Gigabeat S code has been adjusted to use the new system: the player now has the USB charging option, which wasn't previously available. The player will only charge at full speed when allowed to do so by a working USB host, so USB AC adapters won't work very well; however, they didn't work before either, so this is not a change in functionality.
4) The iPod Nano 2G code has been adjusted to use the new system: it already had the USB charging option. Using a USB AC adapter won't charge at full speed any more (it did before) - the old implementation was equivalent to the not-yet-implemented "force" option in the new system.
No other target should be affected. Support for the "force" mode and support for at least some other iPod models will come in a future commit :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26570 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/usbstack/usb_core.c')
-rw-r--r-- | firmware/usbstack/usb_core.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c index a2e2b5f063..dfcce05064 100644 --- a/firmware/usbstack/usb_core.c +++ b/firmware/usbstack/usb_core.c | |||
@@ -166,6 +166,11 @@ static int usb_address = 0; | |||
166 | static bool initialized = false; | 166 | static bool initialized = false; |
167 | static enum { DEFAULT, ADDRESS, CONFIGURED } usb_state; | 167 | static enum { DEFAULT, ADDRESS, CONFIGURED } usb_state; |
168 | 168 | ||
169 | #ifdef HAVE_USB_CHARGING_ENABLE | ||
170 | static int usb_charging_mode = USB_CHARGING_DISABLE; | ||
171 | static int usb_charging_current_requested = 500; | ||
172 | #endif | ||
173 | |||
169 | static int usb_core_num_interfaces; | 174 | static int usb_core_num_interfaces; |
170 | 175 | ||
171 | typedef void (*completion_handler_t)(int ep, int dir, int status, int length); | 176 | typedef void (*completion_handler_t)(int ep, int dir, int status, int length); |
@@ -378,6 +383,9 @@ void usb_core_exit(void) | |||
378 | initialized = false; | 383 | initialized = false; |
379 | } | 384 | } |
380 | usb_state = DEFAULT; | 385 | usb_state = DEFAULT; |
386 | #ifdef HAVE_USB_CHARGING_ENABLE | ||
387 | usb_charging_maxcurrent_change(usb_charging_maxcurrent()); | ||
388 | #endif | ||
381 | logf("usb_core_exit() finished"); | 389 | logf("usb_core_exit() finished"); |
382 | } | 390 | } |
383 | 391 | ||
@@ -552,6 +560,16 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req) | |||
552 | config_descriptor.bDescriptorType = | 560 | config_descriptor.bDescriptorType = |
553 | USB_DT_OTHER_SPEED_CONFIG; | 561 | USB_DT_OTHER_SPEED_CONFIG; |
554 | } | 562 | } |
563 | #ifdef HAVE_USB_CHARGING_ENABLE | ||
564 | if (usb_charging_mode == USB_CHARGING_DISABLE) { | ||
565 | config_descriptor.bMaxPower = (100+1)/2; | ||
566 | usb_charging_current_requested = 100; | ||
567 | } | ||
568 | else { | ||
569 | config_descriptor.bMaxPower = (500+1)/2; | ||
570 | usb_charging_current_requested = 500; | ||
571 | } | ||
572 | #endif | ||
555 | size = sizeof(struct usb_config_descriptor); | 573 | size = sizeof(struct usb_config_descriptor); |
556 | 574 | ||
557 | for(i = 0; i < USB_NUM_DRIVERS; i++) | 575 | for(i = 0; i < USB_NUM_DRIVERS; i++) |
@@ -628,8 +646,10 @@ static void request_handler_device(struct usb_ctrlrequest* req) | |||
628 | } | 646 | } |
629 | else | 647 | else |
630 | usb_state = ADDRESS; | 648 | usb_state = ADDRESS; |
631 | |||
632 | usb_drv_send(EP_CONTROL, NULL, 0); | 649 | usb_drv_send(EP_CONTROL, NULL, 0); |
650 | #ifdef HAVE_USB_CHARGING_ENABLE | ||
651 | usb_charging_maxcurrent_change(usb_charging_maxcurrent()); | ||
652 | #endif | ||
633 | break; | 653 | break; |
634 | } | 654 | } |
635 | case USB_REQ_SET_ADDRESS: { | 655 | case USB_REQ_SET_ADDRESS: { |
@@ -809,6 +829,9 @@ void usb_core_bus_reset(void) | |||
809 | { | 829 | { |
810 | usb_address = 0; | 830 | usb_address = 0; |
811 | usb_state = DEFAULT; | 831 | usb_state = DEFAULT; |
832 | #ifdef HAVE_USB_CHARGING_ENABLE | ||
833 | usb_charging_maxcurrent_change(usb_charging_maxcurrent()); | ||
834 | #endif | ||
812 | } | 835 | } |
813 | 836 | ||
814 | /* called by usb_drv_transfer_completed() */ | 837 | /* called by usb_drv_transfer_completed() */ |
@@ -850,9 +873,20 @@ void usb_core_control_request(struct usb_ctrlrequest* req) | |||
850 | usb_signal_transfer_completion(completion_event); | 873 | usb_signal_transfer_completion(completion_event); |
851 | } | 874 | } |
852 | 875 | ||
853 | #ifdef HAVE_USB_POWER | 876 | #ifdef HAVE_USB_CHARGING_ENABLE |
854 | unsigned short usb_allowed_current() | 877 | void usb_charging_enable(int state) |
878 | { | ||
879 | usb_charging_mode = state; | ||
880 | usb_charging_maxcurrent_change(usb_charging_maxcurrent()); | ||
881 | } | ||
882 | |||
883 | int usb_charging_maxcurrent() | ||
855 | { | 884 | { |
856 | return (usb_state == CONFIGURED) ? MAX(USB_MAX_CURRENT, 100) : 100; | 885 | if (!initialized |
886 | || usb_charging_mode == USB_CHARGING_DISABLE | ||
887 | || usb_state != CONFIGURED) | ||
888 | return 100; | ||
889 | /* usb_state == CONFIGURED, charging enabled/forced */ | ||
890 | return usb_charging_current_requested; | ||
857 | } | 891 | } |
858 | #endif | 892 | #endif |