Index: apps/misc.h =================================================================== --- apps/misc.h (revision 23313) +++ apps/misc.h (working copy) @@ -100,6 +100,7 @@ */ char *strip_extension(char* buffer, int buffer_size, const char *filename); +#ifdef HAVE_LCD_BITMAP /* A simplified scanf */ /* * Checks whether the value at position 'position' was really read @@ -111,4 +112,10 @@ const char* parse_list(const char *fmt, uint32_t *set_vals, const char sep, const char* str, ...); +/* only used in USB HID and set_time screen */ +#if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0) +int clamp_value_wrap(int value, int max, int min); +#endif +#endif + #endif /* MISC_H */ Index: apps/screens.c =================================================================== --- apps/screens.c (revision 23313) +++ apps/screens.c (working copy) @@ -60,18 +60,6 @@ #include "dsp.h" #endif -/* only used in set_time screen */ -#if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) -static int clamp_value_wrap(int value, int max, int min) -{ - if (value > max) - return min; - if (value < min) - return max; - return value; -} -#endif - #if (CONFIG_STORAGE & STORAGE_MMC) int mmc_remove_request(void) { Index: apps/gui/usb_screen.c =================================================================== --- apps/gui/usb_screen.c (revision 23313) +++ apps/gui/usb_screen.c (working copy) @@ -64,7 +64,7 @@ { int button; #ifdef USB_ENABLE_HID - if (usb_core_driver_enabled(USB_DRIVER_HID)) + if (usb_keypad_mode) { button = get_hid_usb_action(); @@ -157,20 +157,24 @@ logo->height = logo_height; #ifdef USB_ENABLE_HID - struct viewport *title = &usb_screen_vps->title; - int char_height, nb_lines; + if (usb_keypad_mode) + { + struct viewport *title = &usb_screen_vps->title; + int char_height, nb_lines; - /* nb_lines only returns the number of fully visible lines, small screens - or really large fonts could cause problems with the calculation below. - */ - nb_lines = viewport_get_nb_lines(parent); - if (nb_lines == 0) - nb_lines++; + /* nb_lines only returns the number of fully visible lines, small + * screens or really large fonts could cause problems with the + * calculation below. + */ + nb_lines = viewport_get_nb_lines(parent); + if (nb_lines == 0) + nb_lines++; - char_height = parent->height/nb_lines; + char_height = parent->height/nb_lines; - *title = *parent; - title->y = logo->y + logo->height + char_height; + *title = *parent; + title->y = logo->y + logo->height + char_height; + } #endif } #endif @@ -209,9 +213,12 @@ screen->transparent_bitmap(usblogo, 0, 0, logo->width, logo->height); #ifdef USB_ENABLE_HID - screen->set_viewport(&usb_screen_vps->title); - usb_screen_vps->title.flags |= VP_FLAG_ALIGN_CENTER; - screen->puts_scroll(0, 0, str(keypad_mode_name_get())); + if (usb_keypad_mode) + { + screen->set_viewport(&usb_screen_vps->title); + usb_screen_vps->title.flags |= VP_FLAG_ALIGN_CENTER; + screen->puts_scroll(0, 0, str(keypad_mode_name_get())); + } #endif /* USB_ENABLE_HID */ } screen->set_viewport(parent); @@ -252,7 +259,8 @@ #endif #ifdef USB_ENABLE_HID - usb_keypad_mode = global_settings.usb_keypad_mode; + usb_keypad_mode = usb_core_driver_enabled(USB_DRIVER_HID) ? + global_settings.usb_keypad_mode : 0; #endif FOR_NB_SCREENS(i) @@ -283,7 +291,7 @@ const struct viewport* vp = NULL; #if defined(HAVE_LCD_BITMAP) && defined(USB_ENABLE_HID) - vp = &usb_screen_vps_ar[i].title; + vp = usb_keypad_mode ? &usb_screen_vps_ar[i].title : NULL; #elif !defined(HAVE_LCD_BITMAP) vp = &usb_screen_vps_ar[i].parent; #endif Index: apps/settings_list.c =================================================================== --- apps/settings_list.c (revision 23313) +++ apps/settings_list.c (working copy) @@ -1624,18 +1624,18 @@ #ifdef USB_ENABLE_HID CHOICE_SETTING(0, usb_keypad_mode, LANG_USB_KEYPAD_MODE, 0, - "usb keypad mode", "multimedia,presentation,browser" + "usb keypad mode", "off,multimedia,presentation,browser" #ifdef HAVE_USB_HID_MOUSE ",mouse" #endif , NULL, #ifdef HAVE_USB_HID_MOUSE + 5, +#else 4, -#else - 3, #endif - ID2P(LANG_MULTIMEDIA_MODE), ID2P(LANG_PRESENTATION_MODE), - ID2P(LANG_BROWSER_MODE) + ID2P(LANG_OFF), ID2P(LANG_MULTIMEDIA_MODE), + ID2P(LANG_PRESENTATION_MODE), ID2P(LANG_BROWSER_MODE) #ifdef HAVE_USB_HID_MOUSE , ID2P(LANG_MOUSE_MODE) #endif Index: apps/usb_keymaps.c =================================================================== --- apps/usb_keymaps.c (revision 23313) +++ apps/usb_keymaps.c (working copy) @@ -23,6 +23,7 @@ #ifdef USB_ENABLE_HID #include "action.h" #include "lang.h" +#include "misc.h" #include "usbstack/usb_hid.h" //#define LOGF_ENABLE #include "logf.h" @@ -162,6 +163,7 @@ static const hid_key_mapping_t *hid_key_mappings[] = { + NULL, &hid_key_mapping_multimedia, &hid_key_mapping_presentation, &hid_key_mapping_browser, @@ -174,40 +176,47 @@ int get_hid_usb_action(void) { - int action; + int action, step; const hid_key_mapping_t *key_mapping = hid_key_mappings[usb_keypad_mode]; + step = -1; action = get_action(key_mapping->context, HZ/4); - /* Skip key mappings in a cyclic way */ - if (action == ACTION_USB_HID_MODE_SWITCH_NEXT) + switch (action) { - /* TODO: Use clamp_value_wrap() */ - usb_keypad_mode = (usb_keypad_mode + 1) % NUM_KEY_MAPPINGS; - } - else if (action == ACTION_USB_HID_MODE_SWITCH_PREV) - { - /* TODO: Use clamp_value_wrap() */ - usb_keypad_mode = (usb_keypad_mode - 1) % NUM_KEY_MAPPINGS; - } - else if (action > ACTION_USB_HID_FIRST && action < ACTION_USB_HID_LAST) - { - const mapping_t *mapping; - const hid_key_mapping_t *key_mapping = - hid_key_mappings[usb_keypad_mode]; + case ACTION_USB_HID_MODE_SWITCH_NEXT: + step = 1; + case ACTION_USB_HID_MODE_SWITCH_PREV: + /* Switch key mappings in a cyclic way */ + usb_keypad_mode = clamp_value_wrap(usb_keypad_mode + step, + NUM_KEY_MAPPINGS - 1, 1); + break; + default: + { + const mapping_t *mapping; + const hid_key_mapping_t *key_mapping = + hid_key_mappings[usb_keypad_mode]; - for (mapping = key_mapping->mapping; mapping->action; mapping++) - { - if (action == mapping->action) - { - logf("Action %d", action); - usb_hid_send(key_mapping->usage_page, mapping->id); + if (action <= ACTION_USB_HID_FIRST || + action >= ACTION_USB_HID_LAST) + { + break; + } + + for (mapping = key_mapping->mapping; mapping->action; mapping++) + { + if (action == mapping->action) + { + logf("Action %d", action); + usb_hid_send(key_mapping->usage_page, mapping->id); + break; + } + } +#ifdef DEBUG + if (!mapping->action) + logf("Action %d not found", action); +#endif break; } - } -#ifdef DEBUG - if (!mapping->action) - logf("Action %d not found", action); -#endif } return action; Index: apps/misc.c =================================================================== --- apps/misc.c (revision 23313) +++ apps/misc.c (working copy) @@ -1063,4 +1063,16 @@ va_end(ap); return 0; } + +/* only used in USB HID and set_time screen */ +#if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0) +int clamp_value_wrap(int value, int max, int min) +{ + if (value > max) + return min; + if (value < min) + return max; + return value; +} #endif +#endif Index: firmware/usb.c =================================================================== --- firmware/usb.c (revision 23313) +++ firmware/usb.c (working copy) @@ -307,6 +307,7 @@ usb_core_enable_driver(USB_DRIVER_MASS_STORAGE, true); #endif #ifdef USB_ENABLE_HID + /* XXX: Should be enabled according to usb_keypad_mode != 0 */ usb_core_enable_driver(USB_DRIVER_HID, true); #endif #ifdef USB_ENABLE_CHARGING_ONLY