Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 8th, 2010  |  syntax: None  |  size: 10.19 KB  |  views: 153  |  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/apps/gui/usb_screen.c b/apps/gui/usb_screen.c
  2. index 019aec6..bbca8b0 100644
  3. --- a/apps/gui/usb_screen.c
  4. +++ b/apps/gui/usb_screen.c
  5. @@ -37,7 +37,8 @@
  6.  #include "led.h"
  7.  #include "appevents.h"
  8.  #include "usb_screen.h"
  9. -
  10. +#include "icon.h"
  11. +#include "list.h"
  12.  #ifdef HAVE_LCD_BITMAP
  13.  #include "bitmaps/usblogo.h"
  14.  #endif
  15. @@ -326,3 +327,131 @@ void gui_usb_screen_run(void)
  16.  
  17.  }
  18.  
  19. +struct usbmenuitem {
  20. +    bool enabled;
  21. +    char *text;
  22. +};
  23. +
  24. +static struct usbmenuitem items[] = {
  25. +    [0] = { true,  "Connect" },
  26. +    [1] = { false, "Battery Charge Only" },
  27. +    [2] = { true,  " -- Storage Drivers -- " },
  28. +    [3] = { true,  "Mass Storage" },
  29. +    [4] = { false, "MTP" },
  30. +    [5] = { true,  "-- HID Drivers -- " },
  31. +    [6] = { false, "Desktop mode" },
  32. +    [7] = { false, "Presentation mode" },
  33. +    [8] = { true,  "Media Player mode" },
  34. +    [9] = { false, "Battery Charge Only" },
  35. +};
  36. +const char * usblist_get_name(int selected_item, void * data,
  37. +                              char * buffer, size_t buffer_len)
  38. +{
  39. +    return items[selected_item].text;
  40. +}
  41. +enum themable_icons usblist_get_icon(int selected_item, void * data)
  42. +{
  43. +    switch (selected_item)
  44. +    {
  45. +        /* no icons ever */
  46. +        case 0:
  47. +        case 1:
  48. +        case 2:
  49. +        case 5:
  50. +            return Icon_Submenu;
  51. +        default:
  52. +            return items[selected_item].enabled ? Icon_Cursor : Icon_NOICON;
  53. +    }
  54. +}
  55. +void usb_connection_gui(void)
  56. +{
  57. +    bool done = false;
  58. +    struct gui_synclist lists;
  59. +    int i, action, selection;
  60. +    FOR_NB_SCREENS(i)
  61. +        viewportmanager_theme_enable(i, true, NULL);
  62. +        
  63. +        
  64. +    gui_synclist_init(&lists, usblist_get_name,  NULL,
  65. +                      false, 1, NULL);
  66. +    gui_synclist_set_title(&lists, "Usb Connection Menu", Icon_Rockbox);
  67. +    gui_synclist_set_icon_callback(&lists, usblist_get_icon);
  68. +    gui_synclist_set_nb_items(&lists, 10);
  69. +    gui_synclist_select_item(&lists, 0);
  70. +
  71. +    
  72. +    while (!done)
  73. +    {
  74. +        gui_synclist_draw(&lists);
  75. +        list_do_action(CONTEXT_STD, HZ,
  76. +                       &lists, &action, LIST_WRAP_UNLESS_HELD);
  77. +        switch (action)
  78. +        {
  79. +            case ACTION_STD_OK:        
  80. +                /* fix the toggles or run the screen */
  81. +                selection = gui_synclist_get_sel_pos(&lists);
  82. +                switch (selection)
  83. +                {
  84. +                    case 0: /* run! */
  85. +                        done = true;
  86. +                        break;
  87. +                    case 1: /* battery only */
  88. +                        break;
  89. +                    case 2: /* headers, do nothing */
  90. +                    case 5:
  91. +                        break;
  92. +                    case 3: /* storage modes */
  93. +                    case 4:
  94. +                        if (!items[selection].enabled)
  95. +                        {
  96. +                            items[selection==3?4:3].enabled = false;
  97. +                            items[selection].enabled = true;
  98. +                        }
  99. +                        else
  100. +                            items[selection].enabled = false;
  101. +                        break;
  102. +                    case 6: /* HID modes */
  103. +                    case 7:
  104. +                    case 8:
  105. +                    case 9:
  106. +                        if (!items[selection].enabled)
  107. +                        {
  108. +                            for (i=6;i<=9;i++)
  109. +                            {
  110. +                                if (i == selection)
  111. +                                    items[i].enabled = true;
  112. +                                else
  113. +                                    items[i].enabled = false;
  114. +                            }
  115. +                        }
  116. +                        else
  117. +                            items[selection].enabled = false;
  118. +                        break;
  119. +                } /* switch() */
  120. +                break;
  121. +        } /* switch(action) */
  122. +    }
  123. +#ifdef USB_ENABLE_STORAGE
  124. +    usb_core_enable_driver(USB_DRIVER_MASS_STORAGE, items[3].enabled);
  125. +    splashf(HZ, "MSC %s", items[3].enabled?"Yes":"no");
  126. +#endif
  127. +#ifdef USB_ENABLE_HID
  128. +    bool hid_enabled = false;
  129. +    for (i=6;i<=9;i++)
  130. +    {
  131. +        if (items[i].enabled)
  132. +            hid_enabled = true;
  133. +    }
  134. +    usb_core_enable_driver(USB_DRIVER_HID, hid_enabled);
  135. +    splashf(HZ, "HID %s", hid_enabled?"Yes":"no");
  136. +#endif
  137. +#ifdef USB_ENABLE_CHARGING_ONLY
  138. +    usb_core_enable_driver(USB_DRIVER_CHARGING_ONLY, false);
  139. +#endif
  140. +    usb_core_enable_driver(USB_DRIVER_MTP, items[4].enabled);
  141. +    splashf(HZ, "MTP %s", items[4].enabled?"Yes":"no");
  142. +    
  143. +    FOR_NB_SCREENS(i)
  144. +        viewportmanager_theme_undo(i, true);  
  145. +    usb_allow_connection();
  146. +}
  147. diff --git a/apps/misc.c b/apps/misc.c
  148. index f9c6116..55c7660 100644
  149. --- a/apps/misc.c
  150. +++ b/apps/misc.c
  151. @@ -29,6 +29,7 @@
  152.  #include <stdarg.h>
  153.  #include <stdio.h>
  154.  #else
  155. +#include "usb.h"
  156.  #include "sprintf.h"
  157.  #include "lang.h"
  158.  #include "dir.h"
  159. @@ -567,6 +568,9 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame
  160.                  talk_force_enqueue_next();
  161.              }
  162.              break;
  163. +        case SYS_USB_ATTACHED:
  164. +            usb_connection_gui();
  165. +            break;
  166.          case SYS_USB_CONNECTED:
  167.              if (callback != NULL)
  168.                  callback(parameter);
  169. diff --git a/apps/settings.h b/apps/settings.h
  170. index fc44caa..98f60d3 100644
  171. --- a/apps/settings.h
  172. +++ b/apps/settings.h
  173. @@ -109,6 +109,26 @@ enum
  174.      TRIG_TYPE_NEW_FILE
  175.  };
  176.  
  177. +#ifdef HAVE_USBSTACK
  178. +enum {
  179. +    USB_SCREENSHOT = 0,
  180. +    USB_MENU,
  181. +#ifdef USB_ENABLE_STORAGE
  182. +    USB_MSC,
  183. +#endif
  184. +#ifdef USB_ENABLE_MTP
  185. +    USB_MTP,
  186. +#endif
  187. +#ifdef USB_ENABLE_HID
  188. +    USB_HID,
  189. +#endif
  190. +#ifdef USB_ENABLE_CHARGING_ONLY
  191. +    USB_BATTERYONLY,
  192. +#endif
  193. +    USB_NUM_OPTIONS
  194. +}
  195. +#endif
  196. +
  197.  #ifdef HAVE_CROSSFADE
  198.  enum {
  199.      CROSSFADE_ENABLE_OFF = 0,
  200. @@ -139,7 +159,6 @@ enum
  201.      NUM_REPEAT_MODES
  202.  };
  203.  
  204. -
  205.  /* dir filter options */
  206.  /* Note: Any new filter modes need to be added before NUM_FILTER_MODES.
  207.   *       Any new rockbox browse filter modes (accessible through the menu)
  208. diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h
  209. index a476130..42827e4 100644
  210. --- a/firmware/export/kernel.h
  211. +++ b/firmware/export/kernel.h
  212. @@ -61,13 +61,14 @@
  213.  #define SYS_EVENT_ID(e)           ((e) & ~(SYS_EVENT|SYS_EVENT_CLS_MASK))
  214.  
  215.  #define SYS_TIMEOUT               MAKE_SYS_EVENT(SYS_EVENT_CLS_QUEUE, 0)
  216. -#define SYS_USB_CONNECTED         MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 0)
  217. -#define SYS_USB_CONNECTED_ACK     MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 1)
  218. -#define SYS_USB_DISCONNECTED      MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 2)
  219. -#define SYS_USB_DISCONNECTED_ACK  MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 3)
  220. -#define SYS_USB_LUN_LOCKED        MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 4)
  221. -#define SYS_USB_READ_DATA         MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 5)
  222. -#define SYS_USB_WRITE_DATA        MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 6)
  223. +#define SYS_USB_ATTACHED          MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 0)
  224. +#define SYS_USB_CONNECTED         MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 1)
  225. +#define SYS_USB_CONNECTED_ACK     MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 2)
  226. +#define SYS_USB_DISCONNECTED      MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 3)
  227. +#define SYS_USB_DISCONNECTED_ACK  MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 4)
  228. +#define SYS_USB_LUN_LOCKED        MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 5)
  229. +#define SYS_USB_READ_DATA         MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 6)
  230. +#define SYS_USB_WRITE_DATA        MAKE_SYS_EVENT(SYS_EVENT_CLS_USB, 7)
  231.  #define SYS_POWEROFF              MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 0)
  232.  #define SYS_CHARGER_CONNECTED     MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 1)
  233.  #define SYS_CHARGER_DISCONNECTED  MAKE_SYS_EVENT(SYS_EVENT_CLS_POWER, 2)
  234. diff --git a/firmware/usb.c b/firmware/usb.c
  235. index 13e273a..96269f4 100644
  236. --- a/firmware/usb.c
  237. +++ b/firmware/usb.c
  238. @@ -222,6 +222,13 @@ static inline bool usb_reboot_button(void)
  239.  static bool usb_hid = true;
  240.  #endif
  241.  
  242. +extern struct event_queue button_queue;
  243. +static bool ready_for_connect;
  244. +void usb_allow_connection(void)
  245. +{
  246. +    ready_for_connect = true;
  247. +}
  248. +
  249.  static void usb_thread(void)
  250.  {
  251.      int num_acks_to_expect = 0;
  252. @@ -263,43 +270,17 @@ static void usb_thread(void)
  253.                  break;
  254.  #endif /* USB_DETECT_BY_DRV */
  255.              case USB_INSERTED:
  256. -#ifdef HAVE_LCD_BITMAP
  257. -                if(do_screendump_instead_of_usb)
  258. -                {
  259. -                    usb_state = USB_SCREENDUMP;
  260. -                    screen_dump();
  261. -#ifdef HAVE_REMOTE_LCD
  262. -                    remote_screen_dump();
  263. -#endif
  264. -                    break;
  265. -                }
  266. -#endif
  267. -#ifdef HAVE_USB_POWER
  268. -                if(usb_power_button())
  269. +                /* inject an event into the button queue so the main thread
  270. +                 * will run the USB-UI code and return after the desired
  271. +                 * drivers are enabled */
  272. +                ready_for_connect = false;
  273. +                queue_send(&button_queue, SYS_USB_ATTACHED, NULL);
  274. +                usb_state = USB_POWERED;
  275. +                while (!ready_for_connect)
  276.                  {
  277. -                    /* Only charging is desired */
  278. -                    usb_state = USB_POWERED;
  279. +                    sleep(HZ/10);
  280.                  }
  281. -                else
  282. -#endif /* HAVE_USB_POWER */
  283.  #ifdef HAVE_USBSTACK
  284. -                {
  285. -#ifdef HAVE_USB_POWER
  286. -                /* Set the state to USB_POWERED for now. If permission to connect
  287. -                 * by threads and storage is granted it will be changed to
  288. -                 * USB_CONNECTED. */
  289. -                usb_state = USB_POWERED;
  290. -#endif
  291. -#ifdef USB_ENABLE_STORAGE
  292. -                usb_core_enable_driver(USB_DRIVER_MASS_STORAGE, true);
  293. -#endif
  294. -#ifdef USB_ENABLE_HID
  295. -                usb_core_enable_driver(USB_DRIVER_HID, usb_hid);
  296. -#endif
  297. -#ifdef USB_ENABLE_CHARGING_ONLY
  298. -                usb_core_enable_driver(USB_DRIVER_CHARGING_ONLY, false);
  299. -#endif
  300. -                }
  301.                  /* Check any drivers enabled at this point for exclusive storage
  302.                   * access requirements. */
  303.                  exclusive_storage_access = usb_core_any_exclusive_storage();