forked from len0rd/rockbox
New USB charging system, part 2 - "Force" charging mode
Enable support for the "force" mode of USB charging. This should work on Gigabeat S and Nano2g (and any other future target which has a RB usb stack and supports charging) - if a host connection is not detected within 10 seconds of USB insertion, assume that the connected device is an AC charger and charge anyway, if the user has specified "force" as the mode. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26594 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
47181b8b9b
commit
2eb0142587
4 changed files with 56 additions and 7 deletions
|
@ -169,6 +169,16 @@ static enum { DEFAULT, ADDRESS, CONFIGURED } usb_state;
|
|||
#ifdef HAVE_USB_CHARGING_ENABLE
|
||||
static int usb_charging_mode = USB_CHARGING_DISABLE;
|
||||
static int usb_charging_current_requested = 500;
|
||||
static struct timeout usb_no_host_timeout;
|
||||
static bool usb_no_host = false;
|
||||
|
||||
static int usb_no_host_callback(struct timeout *tmo)
|
||||
{
|
||||
(void)tmo;
|
||||
usb_no_host = true;
|
||||
usb_charger_update();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int usb_core_num_interfaces;
|
||||
|
@ -365,6 +375,10 @@ void usb_core_init(void)
|
|||
|
||||
initialized = true;
|
||||
usb_state = DEFAULT;
|
||||
#ifdef HAVE_USB_CHARGING_ENABLE
|
||||
usb_no_host = false;
|
||||
timeout_register(&usb_no_host_timeout, usb_no_host_callback, HZ*10, 0);
|
||||
#endif
|
||||
logf("usb_core_init() finished");
|
||||
}
|
||||
|
||||
|
@ -384,6 +398,7 @@ void usb_core_exit(void)
|
|||
}
|
||||
usb_state = DEFAULT;
|
||||
#ifdef HAVE_USB_CHARGING_ENABLE
|
||||
usb_no_host = false;
|
||||
usb_charging_maxcurrent_change(usb_charging_maxcurrent());
|
||||
#endif
|
||||
logf("usb_core_exit() finished");
|
||||
|
@ -800,6 +815,13 @@ static void request_handler_endpoint(struct usb_ctrlrequest* req)
|
|||
/* Handling USB requests starts here */
|
||||
static void usb_core_control_request_handler(struct usb_ctrlrequest* req)
|
||||
{
|
||||
#ifdef HAVE_USB_CHARGING_ENABLE
|
||||
timeout_cancel(&usb_no_host_timeout);
|
||||
if(usb_no_host) {
|
||||
usb_no_host = false;
|
||||
usb_charging_maxcurrent_change(usb_charging_maxcurrent());
|
||||
}
|
||||
#endif
|
||||
if(usb_state == DEFAULT) {
|
||||
set_serial_descriptor();
|
||||
usb_core_set_serial_function_id();
|
||||
|
@ -882,11 +904,12 @@ void usb_charging_enable(int state)
|
|||
|
||||
int usb_charging_maxcurrent()
|
||||
{
|
||||
if (!initialized
|
||||
|| usb_charging_mode == USB_CHARGING_DISABLE
|
||||
|| usb_state != CONFIGURED)
|
||||
if (!initialized || usb_charging_mode == USB_CHARGING_DISABLE)
|
||||
return 100;
|
||||
/* usb_state == CONFIGURED, charging enabled/forced */
|
||||
return usb_charging_current_requested;
|
||||
if (usb_state == CONFIGURED)
|
||||
return usb_charging_current_requested;
|
||||
if (usb_charging_mode == USB_CHARGING_FORCE && usb_no_host)
|
||||
return 500;
|
||||
return 100;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue