This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 7th, 2012  |  syntax: Diff  |  size: 6.11 KB  |  views: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff --git a/firmware/export/usb.h b/firmware/export/usb.h
  2. index 8954e9c..13ef398 100644
  3. --- a/firmware/export/usb.h
  4. +++ b/firmware/export/usb.h
  5. @@ -44,6 +44,8 @@ enum
  6.  #endif
  7.  #ifdef HAVE_USBSTACK
  8.      USB_TRANSFER_COMPLETION, /* Event */
  9. +    USB_NOTIFY_SET_ADDR,     /* Event */
  10. +    USB_NOTIFY_SET_CONFIG,   /* Event */
  11.  #endif
  12.  #ifdef USB_FIREWIRE_HANDLING
  13.      USB_REQUEST_REBOOT,      /* Event */
  14. @@ -130,6 +132,7 @@ void usb_charger_update(void);
  15.  #ifdef HAVE_USBSTACK
  16.  void usb_signal_transfer_completion(
  17.      struct usb_transfer_completion_event_data *event_data);
  18. +void usb_signal_notify(long id, intptr_t data);
  19.  bool usb_driver_enabled(int driver);
  20.  bool usb_exclusive_storage(void); /* storage is available for usb */
  21.  #endif
  22. diff --git a/firmware/export/usb_core.h b/firmware/export/usb_core.h
  23. index 6405aa4..91bf88e 100644
  24. --- a/firmware/export/usb_core.h
  25. +++ b/firmware/export/usb_core.h
  26. @@ -51,6 +51,10 @@ void usb_core_enable_driver(int driver,bool enabled);
  27.  bool usb_core_driver_enabled(int driver);
  28.  void usb_core_handle_transfer_completion(
  29.          struct usb_transfer_completion_event_data* event);
  30. +void usb_core_handle_notify(long id, intptr_t data);
  31. +/* For controllers which handle SET ADDR and/or SET CONFIG in harware */
  32. +void usb_core_notify_set_address(uint8_t addr);
  33. +void usb_core_notify_set_config(uint8_t config);
  34.  
  35.  int usb_core_request_endpoint(int type, int dir,struct usb_class_driver* drv);
  36.  void usb_core_release_endpoint(int dir);
  37. diff --git a/firmware/usb.c b/firmware/usb.c
  38. index 6823851..b8c9822 100644
  39. --- a/firmware/usb.c
  40. +++ b/firmware/usb.c
  41. @@ -270,6 +270,11 @@ void usb_signal_transfer_completion(
  42.      queue_post(&usb_queue, USB_TRANSFER_COMPLETION, (intptr_t)event_data);
  43.  }
  44.  
  45. +void usb_signal_notify(long id, intptr_t data)
  46. +{
  47. +    queue_post(&usb_queue, id, data);
  48. +}
  49. +
  50.  #else  /* !HAVE_USBSTACK */
  51.  
  52.  static inline void usb_stack_enable(bool enable)
  53. @@ -431,6 +436,12 @@ static void NORETURN_ATTR usb_thread(void)
  54.          /*** Main USB thread duties ***/
  55.  
  56.  #ifdef HAVE_USBSTACK
  57. +        case USB_NOTIFY_SET_ADDR:
  58. +        case USB_NOTIFY_SET_CONFIG:
  59. +            if(usb_state <= USB_EXTRACTED)
  60. +                break;
  61. +            usb_core_handle_notify(ev.id, ev.data);
  62. +            break;
  63.          case USB_TRANSFER_COMPLETION:
  64.              if(usb_state <= USB_EXTRACTED)
  65.                  break;
  66. diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c
  67. index 801325b..2a3cc1c 100644
  68. --- a/firmware/usbstack/usb_core.c
  69. +++ b/firmware/usbstack/usb_core.c
  70. @@ -663,10 +663,31 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req)
  71.      }
  72.  }
  73.  
  74. -static void request_handler_device(struct usb_ctrlrequest* req)
  75. +static void usb_core_do_set_addr(uint8_t address)
  76.  {
  77. -    int i;
  78. +    logf("usb_core: SET_ADR %d", address);
  79. +    usb_address = address;
  80. +    usb_state = ADDRESS;
  81. +}
  82. +
  83. +static void usb_core_do_set_config(uint8_t config)
  84. +{
  85. +    logf("usb_core: SET_CONFIG");
  86. +    if(config) {
  87. +        usb_state = CONFIGURED;
  88. +        for(int i = 0; i < USB_NUM_DRIVERS; i++)
  89. +            if(drivers[i].enabled && drivers[i].init_connection)
  90. +                drivers[i].init_connection();
  91. +    }
  92. +    else
  93. +        usb_state = ADDRESS;
  94. +    #ifdef HAVE_USB_CHARGING_ENABLE
  95. +    usb_charging_maxcurrent_change(usb_charging_maxcurrent());
  96. +    #endif
  97. +}
  98.  
  99. +static void request_handler_device(struct usb_ctrlrequest* req)
  100. +{
  101.      switch(req->bRequest) {
  102.          case USB_REQ_GET_CONFIGURATION: {
  103.                  logf("usb_core: GET_CONFIG");
  104. @@ -676,20 +697,9 @@ static void request_handler_device(struct usb_ctrlrequest* req)
  105.                  break;
  106.              }
  107.          case USB_REQ_SET_CONFIGURATION: {
  108. -                logf("usb_core: SET_CONFIG");
  109.                  usb_drv_cancel_all_transfers();
  110. -                if(req->wValue) {
  111. -                    usb_state = CONFIGURED;
  112. -                    for(i = 0; i < USB_NUM_DRIVERS; i++)
  113. -                        if(drivers[i].enabled && drivers[i].init_connection)
  114. -                            drivers[i].init_connection();
  115. -                }
  116. -                else
  117. -                    usb_state = ADDRESS;
  118. +                usb_core_do_set_config(req->wValue);
  119.                  usb_drv_send(EP_CONTROL, NULL, 0);
  120. -#ifdef HAVE_USB_CHARGING_ENABLE
  121. -                usb_charging_maxcurrent_change(usb_charging_maxcurrent());
  122. -#endif
  123.                  break;
  124.              }
  125.          case USB_REQ_SET_ADDRESS: {
  126. @@ -697,9 +707,8 @@ static void request_handler_device(struct usb_ctrlrequest* req)
  127.                  logf("usb_core: SET_ADR %d", address);
  128.                  usb_drv_send(EP_CONTROL, NULL, 0);
  129.                  usb_drv_cancel_all_transfers();
  130. -                usb_address = address;
  131. -                usb_drv_set_address(usb_address);
  132. -                usb_state = ADDRESS;
  133. +                usb_drv_set_address(address);
  134. +                usb_core_do_set_addr(address);
  135.                  break;
  136.              }
  137.          case USB_REQ_GET_DESCRIPTOR:
  138. @@ -913,6 +922,21 @@ void usb_core_transfer_complete(int endpoint, int dir, int status, int length)
  139.      }
  140.  }
  141.  
  142. +void usb_core_handle_notify(long id, intptr_t data)
  143. +{
  144. +    switch(id)
  145. +    {
  146. +        case USB_NOTIFY_SET_ADDR:
  147. +            usb_core_do_set_addr(data);
  148. +            break;
  149. +        case USB_NOTIFY_SET_CONFIG:
  150. +            usb_core_do_set_config(data);
  151. +            break;
  152. +        default:
  153. +            break;
  154. +    }
  155. +}
  156. +
  157.  /* called by usb_drv_int() */
  158.  void usb_core_control_request(struct usb_ctrlrequest* req)
  159.  {
  160. @@ -928,6 +952,18 @@ void usb_core_control_request(struct usb_ctrlrequest* req)
  161.      usb_signal_transfer_completion(completion_event);
  162.  }
  163.  
  164. +void usb_core_notify_set_address(uint8_t addr)
  165. +{
  166. +    logf("notify set addr received %ld", current_tick);
  167. +    usb_signal_notify(USB_NOTIFY_SET_ADDR, addr);
  168. +}
  169. +
  170. +void usb_core_notify_set_config(uint8_t config)
  171. +{
  172. +    logf("notify set config received %ld", current_tick);
  173. +    usb_signal_notify(USB_NOTIFY_SET_CONFIG, config);
  174. +}
  175. +
  176.  #ifdef HAVE_USB_CHARGING_ENABLE
  177.  void usb_charging_enable(int state)
  178.  {
clone this paste RAW Paste Data