summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomer Shalev <shalev.tomer@gmail.com>2009-10-23 13:29:19 +0000
committerTomer Shalev <shalev.tomer@gmail.com>2009-10-23 13:29:19 +0000
commit83d24f89df743452512357b11f4331c17f5bd6f4 (patch)
tree90d8f29da59dd91fb7fab748607eec96df30ca04
parent6314952ff1b49372635fd972c887d4e3ba860705 (diff)
downloadrockbox-83d24f89df743452512357b11f4331c17f5bd6f4.tar.gz
rockbox-83d24f89df743452512357b11f4331c17f5bd6f4.zip
FS#10704 - Make a configuration option to disable USB HID
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23322 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/gui/usb_screen.c41
-rw-r--r--apps/lang/english.lang17
-rw-r--r--apps/menus/settings_menu.c2
-rw-r--r--apps/misc.c12
-rw-r--r--apps/misc.h7
-rw-r--r--apps/screens.c12
-rw-r--r--apps/settings.h1
-rw-r--r--apps/settings_list.c2
-rw-r--r--apps/usb_keymaps.c62
-rw-r--r--firmware/export/usb.h4
-rw-r--r--firmware/usb.c16
-rw-r--r--manual/appendix/config_file_options.tex5
-rw-r--r--manual/configure_rockbox/system_options.tex8
-rw-r--r--manual/rockbox_interface/main.tex5
14 files changed, 137 insertions, 57 deletions
diff --git a/apps/gui/usb_screen.c b/apps/gui/usb_screen.c
index f2c25554df..50188274d2 100644
--- a/apps/gui/usb_screen.c
+++ b/apps/gui/usb_screen.c
@@ -49,6 +49,7 @@
49 49
50#ifdef USB_ENABLE_HID 50#ifdef USB_ENABLE_HID
51int usb_keypad_mode; 51int usb_keypad_mode;
52static bool usb_hid;
52#endif 53#endif
53 54
54#ifndef SIMULATOR 55#ifndef SIMULATOR
@@ -64,7 +65,7 @@ static int handle_usb_events(void)
64 { 65 {
65 int button; 66 int button;
66#ifdef USB_ENABLE_HID 67#ifdef USB_ENABLE_HID
67 if (usb_core_driver_enabled(USB_DRIVER_HID)) 68 if (usb_hid)
68 { 69 {
69 button = get_hid_usb_action(); 70 button = get_hid_usb_action();
70 71
@@ -157,20 +158,24 @@ static void usb_screen_fix_viewports(struct screen *screen,
157 logo->height = logo_height; 158 logo->height = logo_height;
158 159
159#ifdef USB_ENABLE_HID 160#ifdef USB_ENABLE_HID
160 struct viewport *title = &usb_screen_vps->title; 161 if (usb_hid)
161 int char_height, nb_lines; 162 {
163 struct viewport *title = &usb_screen_vps->title;
164 int char_height, nb_lines;
162 165
163 /* nb_lines only returns the number of fully visible lines, small screens 166 /* nb_lines only returns the number of fully visible lines, small
164 or really large fonts could cause problems with the calculation below. 167 * screens or really large fonts could cause problems with the
165 */ 168 * calculation below.
166 nb_lines = viewport_get_nb_lines(parent); 169 */
167 if (nb_lines == 0) 170 nb_lines = viewport_get_nb_lines(parent);
168 nb_lines++; 171 if (nb_lines == 0)
172 nb_lines++;
169 173
170 char_height = parent->height/nb_lines; 174 char_height = parent->height/nb_lines;
171 175
172 *title = *parent; 176 *title = *parent;
173 title->y = logo->y + logo->height + char_height; 177 title->y = logo->y + logo->height + char_height;
178 }
174#endif 179#endif
175} 180}
176#endif 181#endif
@@ -209,9 +214,12 @@ static void usb_screens_draw(struct usb_screen_vps_t *usb_screen_vps_ar)
209 screen->transparent_bitmap(usblogo, 0, 0, logo->width, 214 screen->transparent_bitmap(usblogo, 0, 0, logo->width,
210 logo->height); 215 logo->height);
211#ifdef USB_ENABLE_HID 216#ifdef USB_ENABLE_HID
212 screen->set_viewport(&usb_screen_vps->title); 217 if (usb_hid)
213 usb_screen_vps->title.flags |= VP_FLAG_ALIGN_CENTER; 218 {
214 screen->puts_scroll(0, 0, str(keypad_mode_name_get())); 219 screen->set_viewport(&usb_screen_vps->title);
220 usb_screen_vps->title.flags |= VP_FLAG_ALIGN_CENTER;
221 screen->puts_scroll(0, 0, str(keypad_mode_name_get()));
222 }
215#endif /* USB_ENABLE_HID */ 223#endif /* USB_ENABLE_HID */
216 } 224 }
217 screen->set_viewport(parent); 225 screen->set_viewport(parent);
@@ -252,6 +260,7 @@ void gui_usb_screen_run(void)
252#endif 260#endif
253 261
254#ifdef USB_ENABLE_HID 262#ifdef USB_ENABLE_HID
263 usb_hid = global_settings.usb_hid;
255 usb_keypad_mode = global_settings.usb_keypad_mode; 264 usb_keypad_mode = global_settings.usb_keypad_mode;
256#endif 265#endif
257 266
@@ -283,7 +292,7 @@ void gui_usb_screen_run(void)
283 const struct viewport* vp = NULL; 292 const struct viewport* vp = NULL;
284 293
285#if defined(HAVE_LCD_BITMAP) && defined(USB_ENABLE_HID) 294#if defined(HAVE_LCD_BITMAP) && defined(USB_ENABLE_HID)
286 vp = &usb_screen_vps_ar[i].title; 295 vp = usb_hid ? &usb_screen_vps_ar[i].title : NULL;
287#elif !defined(HAVE_LCD_BITMAP) 296#elif !defined(HAVE_LCD_BITMAP)
288 vp = &usb_screen_vps_ar[i].parent; 297 vp = &usb_screen_vps_ar[i].parent;
289#endif 298#endif
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index 16fc022af6..d7dba2f3c0 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -13165,3 +13165,20 @@
13165 remote: "Remote Custom Statusbar" 13165 remote: "Remote Custom Statusbar"
13166 </voice> 13166 </voice>
13167</phrase> 13167</phrase>
13168<phrase>
13169 id: LANG_USB_HID
13170 desc: in settings_menu
13171 user: core
13172 <source>
13173 *: none
13174 usb_hid: "USB HID"
13175 </source>
13176 <dest>
13177 *: none
13178 usb_hid: "USB HID"
13179 </dest>
13180 <voice>
13181 *: none
13182 usb_hid: "USB Human Interface Device"
13183 </voice>
13184</phrase>
diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c
index 71a6089e68..c11bf0eb3d 100644
--- a/apps/menus/settings_menu.c
+++ b/apps/menus/settings_menu.c
@@ -253,6 +253,7 @@ MENUITEM_SETTING(accessory_supply, &global_settings.accessory_supply, NULL);
253#endif 253#endif
254MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL); 254MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL);
255#ifdef USB_ENABLE_HID 255#ifdef USB_ENABLE_HID
256MENUITEM_SETTING(usb_hid, &global_settings.usb_hid, NULL);
256MENUITEM_SETTING(usb_keypad_mode, &global_settings.usb_keypad_mode, NULL); 257MENUITEM_SETTING(usb_keypad_mode, &global_settings.usb_keypad_mode, NULL);
257#endif 258#endif
258 259
@@ -304,6 +305,7 @@ MAKE_MENU(system_menu, ID2P(LANG_SYSTEM),
304 &touchpad_sensitivity, 305 &touchpad_sensitivity,
305#endif 306#endif
306#ifdef USB_ENABLE_HID 307#ifdef USB_ENABLE_HID
308 &usb_hid,
307 &usb_keypad_mode, 309 &usb_keypad_mode,
308#endif 310#endif
309 ); 311 );
diff --git a/apps/misc.c b/apps/misc.c
index 47ebf58080..5af57feb11 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -1047,4 +1047,16 @@ err:
1047 va_end(ap); 1047 va_end(ap);
1048 return 0; 1048 return 0;
1049} 1049}
1050
1051/* only used in USB HID and set_time screen */
1052#if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0)
1053int clamp_value_wrap(int value, int max, int min)
1054{
1055 if (value > max)
1056 return min;
1057 if (value < min)
1058 return max;
1059 return value;
1060}
1061#endif
1050#endif 1062#endif
diff --git a/apps/misc.h b/apps/misc.h
index a8ed6029a3..857d9ab4da 100644
--- a/apps/misc.h
+++ b/apps/misc.h
@@ -92,6 +92,7 @@ bool dir_exists(const char *path);
92 */ 92 */
93char *strip_extension(char* buffer, int buffer_size, const char *filename); 93char *strip_extension(char* buffer, int buffer_size, const char *filename);
94 94
95#ifdef HAVE_LCD_BITMAP
95/* A simplified scanf */ 96/* A simplified scanf */
96/* 97/*
97 * Checks whether the value at position 'position' was really read 98 * Checks whether the value at position 'position' was really read
@@ -103,4 +104,10 @@ char *strip_extension(char* buffer, int buffer_size, const char *filename);
103const char* parse_list(const char *fmt, uint32_t *set_vals, 104const char* parse_list(const char *fmt, uint32_t *set_vals,
104 const char sep, const char* str, ...); 105 const char sep, const char* str, ...);
105 106
107/* only used in USB HID and set_time screen */
108#if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0)
109int clamp_value_wrap(int value, int max, int min);
110#endif
111#endif
112
106#endif /* MISC_H */ 113#endif /* MISC_H */
diff --git a/apps/screens.c b/apps/screens.c
index ab721a8654..5f84830c00 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -60,18 +60,6 @@
60#include "dsp.h" 60#include "dsp.h"
61#endif 61#endif
62 62
63/* only used in set_time screen */
64#if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
65static int clamp_value_wrap(int value, int max, int min)
66{
67 if (value > max)
68 return min;
69 if (value < min)
70 return max;
71 return value;
72}
73#endif
74
75#if (CONFIG_STORAGE & STORAGE_MMC) 63#if (CONFIG_STORAGE & STORAGE_MMC)
76int mmc_remove_request(void) 64int mmc_remove_request(void)
77{ 65{
diff --git a/apps/settings.h b/apps/settings.h
index d1179ed5bc..c9ff3f9dd3 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -781,6 +781,7 @@ struct user_settings
781 /* new stuff to be added at the end */ 781 /* new stuff to be added at the end */
782 782
783#ifdef USB_ENABLE_HID 783#ifdef USB_ENABLE_HID
784 bool usb_hid;
784 int usb_keypad_mode; 785 int usb_keypad_mode;
785#endif 786#endif
786 787
diff --git a/apps/settings_list.c b/apps/settings_list.c
index 5bfce331cd..5a0e05d7d2 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -31,6 +31,7 @@
31#include "backlight.h" 31#include "backlight.h"
32#include "settings.h" 32#include "settings.h"
33#include "settings_list.h" 33#include "settings_list.h"
34#include "usb.h"
34#include "sound.h" 35#include "sound.h"
35#include "dsp.h" 36#include "dsp.h"
36#include "mpeg.h" 37#include "mpeg.h"
@@ -1623,6 +1624,7 @@ const struct settings_list settings[] = {
1623#endif 1624#endif
1624 1625
1625#ifdef USB_ENABLE_HID 1626#ifdef USB_ENABLE_HID
1627 OFFON_SETTING(0, usb_hid, LANG_USB_HID, true, "usb hid", usb_set_hid),
1626 CHOICE_SETTING(0, usb_keypad_mode, LANG_USB_KEYPAD_MODE, 0, 1628 CHOICE_SETTING(0, usb_keypad_mode, LANG_USB_KEYPAD_MODE, 0,
1627 "usb keypad mode", "multimedia,presentation,browser" 1629 "usb keypad mode", "multimedia,presentation,browser"
1628#ifdef HAVE_USB_HID_MOUSE 1630#ifdef HAVE_USB_HID_MOUSE
diff --git a/apps/usb_keymaps.c b/apps/usb_keymaps.c
index f787de692f..f04fa54c3d 100644
--- a/apps/usb_keymaps.c
+++ b/apps/usb_keymaps.c
@@ -23,6 +23,7 @@
23#ifdef USB_ENABLE_HID 23#ifdef USB_ENABLE_HID
24#include "action.h" 24#include "action.h"
25#include "lang.h" 25#include "lang.h"
26#include "misc.h"
26#include "usbstack/usb_hid.h" 27#include "usbstack/usb_hid.h"
27//#define LOGF_ENABLE 28//#define LOGF_ENABLE
28#include "logf.h" 29#include "logf.h"
@@ -174,40 +175,47 @@ extern int usb_keypad_mode;
174 175
175int get_hid_usb_action(void) 176int get_hid_usb_action(void)
176{ 177{
177 int action; 178 int action, step;
178 const hid_key_mapping_t *key_mapping = hid_key_mappings[usb_keypad_mode]; 179 const hid_key_mapping_t *key_mapping = hid_key_mappings[usb_keypad_mode];
179 180
181 step = -1;
180 action = get_action(key_mapping->context, HZ/4); 182 action = get_action(key_mapping->context, HZ/4);
181 /* Skip key mappings in a cyclic way */ 183 switch (action)
182 if (action == ACTION_USB_HID_MODE_SWITCH_NEXT)
183 {
184 /* TODO: Use clamp_value_wrap() */
185 usb_keypad_mode = (usb_keypad_mode + 1) % NUM_KEY_MAPPINGS;
186 }
187 else if (action == ACTION_USB_HID_MODE_SWITCH_PREV)
188 {
189 /* TODO: Use clamp_value_wrap() */
190 usb_keypad_mode = (usb_keypad_mode - 1) % NUM_KEY_MAPPINGS;
191 }
192 else if (action > ACTION_USB_HID_FIRST && action < ACTION_USB_HID_LAST)
193 { 184 {
194 const mapping_t *mapping; 185 case ACTION_USB_HID_MODE_SWITCH_NEXT:
195 const hid_key_mapping_t *key_mapping = 186 step = 1;
196 hid_key_mappings[usb_keypad_mode]; 187 case ACTION_USB_HID_MODE_SWITCH_PREV:
197 188 /* Switch key mappings in a cyclic way */
198 for (mapping = key_mapping->mapping; mapping->action; mapping++) 189 usb_keypad_mode = clamp_value_wrap(usb_keypad_mode + step,
199 { 190 NUM_KEY_MAPPINGS - 1, 0);
200 if (action == mapping->action) 191 break;
192 default:
201 { 193 {
202 logf("Action %d", action); 194 const mapping_t *mapping;
203 usb_hid_send(key_mapping->usage_page, mapping->id); 195 const hid_key_mapping_t *key_mapping =
204 break; 196 hid_key_mappings[usb_keypad_mode];
205 } 197
206 } 198 if (action <= ACTION_USB_HID_FIRST ||
199 action >= ACTION_USB_HID_LAST)
200 {
201 break;
202 }
203
204 for (mapping = key_mapping->mapping; mapping->action; mapping++)
205 {
206 if (action == mapping->action)
207 {
208 logf("Action %d", action);
209 usb_hid_send(key_mapping->usage_page, mapping->id);
210 break;
211 }
212 }
207#ifdef DEBUG 213#ifdef DEBUG
208 if (!mapping->action) 214 if (!mapping->action)
209 logf("Action %d not found", action); 215 logf("Action %d not found", action);
210#endif 216#endif
217 break;
218 }
211 } 219 }
212 220
213 return action; 221 return action;
diff --git a/firmware/export/usb.h b/firmware/export/usb.h
index 911fa931d9..c380ac518d 100644
--- a/firmware/export/usb.h
+++ b/firmware/export/usb.h
@@ -148,4 +148,8 @@ bool firewire_detect(void);
148void usb_firewire_connect_event(void); 148void usb_firewire_connect_event(void);
149#endif 149#endif
150 150
151#ifdef USB_ENABLE_HID
152void usb_set_hid(bool enable);
153#endif
154
151#endif 155#endif
diff --git a/firmware/usb.c b/firmware/usb.c
index 62a335f712..dd0ef9dfe4 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -218,6 +218,10 @@ static inline bool usb_reboot_button(void)
218#endif 218#endif
219#endif /* HAVE_USB_POWER */ 219#endif /* HAVE_USB_POWER */
220 220
221#ifdef USB_ENABLE_HID
222static bool usb_hid = true;
223#endif
224
221static void usb_thread(void) 225static void usb_thread(void)
222{ 226{
223 int num_acks_to_expect = 0; 227 int num_acks_to_expect = 0;
@@ -284,7 +288,7 @@ static void usb_thread(void)
284#ifdef USB_ENABLE_CHARGING_ONLY 288#ifdef USB_ENABLE_CHARGING_ONLY
285 usb_core_enable_driver(USB_DRIVER_HID, false); 289 usb_core_enable_driver(USB_DRIVER_HID, false);
286#else 290#else
287 usb_core_enable_driver(USB_DRIVER_HID, true); 291 usb_core_enable_driver(USB_DRIVER_HID, usb_hid);
288#endif /* USB_ENABLE_CHARGING_ONLY */ 292#endif /* USB_ENABLE_CHARGING_ONLY */
289#endif /* USB_ENABLE_HID */ 293#endif /* USB_ENABLE_HID */
290 294
@@ -307,7 +311,7 @@ static void usb_thread(void)
307 usb_core_enable_driver(USB_DRIVER_MASS_STORAGE, true); 311 usb_core_enable_driver(USB_DRIVER_MASS_STORAGE, true);
308#endif 312#endif
309#ifdef USB_ENABLE_HID 313#ifdef USB_ENABLE_HID
310 usb_core_enable_driver(USB_DRIVER_HID, true); 314 usb_core_enable_driver(USB_DRIVER_HID, usb_hid);
311#endif 315#endif
312#ifdef USB_ENABLE_CHARGING_ONLY 316#ifdef USB_ENABLE_CHARGING_ONLY
313 usb_core_enable_driver(USB_DRIVER_CHARGING_ONLY, false); 317 usb_core_enable_driver(USB_DRIVER_CHARGING_ONLY, false);
@@ -691,6 +695,14 @@ bool usb_powered(void)
691} 695}
692#endif 696#endif
693 697
698#ifdef USB_ENABLE_HID
699void usb_set_hid(bool enable)
700{
701 usb_hid = enable;
702 usb_core_enable_driver(USB_DRIVER_HID, usb_hid);
703}
704#endif
705
694#else 706#else
695 707
696#ifdef USB_NONE 708#ifdef USB_NONE
diff --git a/manual/appendix/config_file_options.tex b/manual/appendix/config_file_options.tex
index f6c95652a9..43f6aea203 100644
--- a/manual/appendix/config_file_options.tex
+++ b/manual/appendix/config_file_options.tex
@@ -95,6 +95,11 @@
95 \opt{accessory_supply}{ 95 \opt{accessory_supply}{
96 accessory power supply & on, off & N/A\\ 96 accessory power supply & on, off & N/A\\
97 } 97 }
98 \opt{usb_hid}{
99 usb hid & on, off & N/A\\
100 usb keypad mode
101 & multimedia, presentation, browser\opt{usb_hid_mouse}{, mouse}& N/A\\
102 }
98 idle poweroff & off, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60 103 idle poweroff & off, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60
99 & minutes\\ 104 & minutes\\
100 max files in playlist & 1000 - 32000 & N/A\\ 105 max files in playlist & 1000 - 32000 & N/A\\
diff --git a/manual/configure_rockbox/system_options.tex b/manual/configure_rockbox/system_options.tex
index 6a98b32a20..0651d61f7d 100644
--- a/manual/configure_rockbox/system_options.tex
+++ b/manual/configure_rockbox/system_options.tex
@@ -183,6 +183,14 @@ this option \setting{On}. If it is not required, then turning this setting
183 } 183 }
184} 184}
185\opt{usb_hid}{ 185\opt{usb_hid}{
186 \subsection{USB HID}
187 \label{ref:USB_HID}
188 This option turns the USB HID feature \setting{On} and \setting{Off}.
189 When this feature is enabled, the \dap{} enumerates as a Human Interface
190 Device (HID), composed of several HID sub devices.
191 Since the \dap{} also enumerates as a Mass Storage Device, it becomes a USB
192 Composite Device, which contains both these devices.
193
186 \subsection{USB Keypad Mode} 194 \subsection{USB Keypad Mode}
187 This setting control the keypad mode when the \dap{} is attached to a 195 This setting control the keypad mode when the \dap{} is attached to a
188 computer through USB. Pressing a key on the \dap{} sends a keystroke the 196 computer through USB. Pressing a key on the \dap{} sends a keystroke the
diff --git a/manual/rockbox_interface/main.tex b/manual/rockbox_interface/main.tex
index d992fdea97..834a039053 100644
--- a/manual/rockbox_interface/main.tex
+++ b/manual/rockbox_interface/main.tex
@@ -580,6 +580,11 @@ To turn on and off your Rockbox enabled \dap{} use the following keys:
580 } 580 }
581\subsection{Putting music on your \dap{}} 581\subsection{Putting music on your \dap{}}
582 582
583\note{Due to a bug in some OS X versions, the \dap{} can not be mounted, unless
584 the USB HID feature is disabled. See \reference{ref:USB_HID} for more
585 information.\newline
586}
587
583With the \dap{} connected to the computer as an MSC/UMS device (like a 588With the \dap{} connected to the computer as an MSC/UMS device (like a
584USB Drive), music files can be put on the player via any standard file 589USB Drive), music files can be put on the player via any standard file
585transfer method that you would use to copy files between drives (e.g. Drag 'n' Drop). 590transfer method that you would use to copy files between drives (e.g. Drag 'n' Drop).