summaryrefslogtreecommitdiff
path: root/firmware/usbstack
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/usbstack')
-rw-r--r--firmware/usbstack/usb_core.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c
index dfcce05064..d6c8c6e5cc 100644
--- a/firmware/usbstack/usb_core.c
+++ b/firmware/usbstack/usb_core.c
@@ -169,6 +169,16 @@ static enum { DEFAULT, ADDRESS, CONFIGURED } usb_state;
169#ifdef HAVE_USB_CHARGING_ENABLE 169#ifdef HAVE_USB_CHARGING_ENABLE
170static int usb_charging_mode = USB_CHARGING_DISABLE; 170static int usb_charging_mode = USB_CHARGING_DISABLE;
171static int usb_charging_current_requested = 500; 171static int usb_charging_current_requested = 500;
172static struct timeout usb_no_host_timeout;
173static bool usb_no_host = false;
174
175static int usb_no_host_callback(struct timeout *tmo)
176{
177 (void)tmo;
178 usb_no_host = true;
179 usb_charger_update();
180 return 0;
181}
172#endif 182#endif
173 183
174static int usb_core_num_interfaces; 184static int usb_core_num_interfaces;
@@ -365,6 +375,10 @@ void usb_core_init(void)
365 375
366 initialized = true; 376 initialized = true;
367 usb_state = DEFAULT; 377 usb_state = DEFAULT;
378#ifdef HAVE_USB_CHARGING_ENABLE
379 usb_no_host = false;
380 timeout_register(&usb_no_host_timeout, usb_no_host_callback, HZ*10, 0);
381#endif
368 logf("usb_core_init() finished"); 382 logf("usb_core_init() finished");
369} 383}
370 384
@@ -384,6 +398,7 @@ void usb_core_exit(void)
384 } 398 }
385 usb_state = DEFAULT; 399 usb_state = DEFAULT;
386#ifdef HAVE_USB_CHARGING_ENABLE 400#ifdef HAVE_USB_CHARGING_ENABLE
401 usb_no_host = false;
387 usb_charging_maxcurrent_change(usb_charging_maxcurrent()); 402 usb_charging_maxcurrent_change(usb_charging_maxcurrent());
388#endif 403#endif
389 logf("usb_core_exit() finished"); 404 logf("usb_core_exit() finished");
@@ -800,6 +815,13 @@ static void request_handler_endpoint(struct usb_ctrlrequest* req)
800/* Handling USB requests starts here */ 815/* Handling USB requests starts here */
801static void usb_core_control_request_handler(struct usb_ctrlrequest* req) 816static void usb_core_control_request_handler(struct usb_ctrlrequest* req)
802{ 817{
818#ifdef HAVE_USB_CHARGING_ENABLE
819 timeout_cancel(&usb_no_host_timeout);
820 if(usb_no_host) {
821 usb_no_host = false;
822 usb_charging_maxcurrent_change(usb_charging_maxcurrent());
823 }
824#endif
803 if(usb_state == DEFAULT) { 825 if(usb_state == DEFAULT) {
804 set_serial_descriptor(); 826 set_serial_descriptor();
805 usb_core_set_serial_function_id(); 827 usb_core_set_serial_function_id();
@@ -882,11 +904,12 @@ void usb_charging_enable(int state)
882 904
883int usb_charging_maxcurrent() 905int usb_charging_maxcurrent()
884{ 906{
885 if (!initialized 907 if (!initialized || usb_charging_mode == USB_CHARGING_DISABLE)
886 || usb_charging_mode == USB_CHARGING_DISABLE
887 || usb_state != CONFIGURED)
888 return 100; 908 return 100;
889 /* usb_state == CONFIGURED, charging enabled/forced */ 909 if (usb_state == CONFIGURED)
890 return usb_charging_current_requested; 910 return usb_charging_current_requested;
911 if (usb_charging_mode == USB_CHARGING_FORCE && usb_no_host)
912 return 500;
913 return 100;
891} 914}
892#endif 915#endif