From 08fb988e87b2d41830b390bae94810c4937675b5 Mon Sep 17 00:00:00 2001 From: Frank Gevaerts Date: Sat, 23 May 2009 14:42:54 +0000 Subject: [PATCH] Add HID keymap handling in usb screen. This allows to use the DAP as a keypad to control the PC. The current keymaps are audio-oriented (play/pause/volume/...) (FS#10218 by Tomer Shalev) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21054 a1c6a512-1295-4272-9138-f99709370657 --- apps/action.h | 10 +++++ apps/keymaps/keymap-c100.c | 18 +++++++- apps/keymaps/keymap-c200.c | 22 +++++++++- apps/keymaps/keymap-clip.c | 22 +++++++++- apps/keymaps/keymap-e200.c | 22 +++++++++- apps/keymaps/keymap-gigabeat-s.c | 44 +++++++++++++++++++ apps/keymaps/keymap-h10.c | 63 ++++++++++++++++++++++++++++ apps/keymaps/keymap-hdd1630.c | 25 +++++++++++ apps/keymaps/keymap-ipod.c | 40 +++++++++++++++++- apps/keymaps/keymap-mr100.c | 39 +++++++++++++++++ apps/keymaps/keymap-ondavx747.c | 17 ++++++++ apps/keymaps/keymap-sa9200.c | 25 +++++++++++ apps/keymaps/keymap-touchscreen.c | 16 +++++++ apps/screens.c | 70 ++++++++++++++++++++++++++++--- 14 files changed, 422 insertions(+), 11 deletions(-) diff --git a/apps/action.h b/apps/action.h index bd215debb8..9869fb30b1 100644 --- a/apps/action.h +++ b/apps/action.h @@ -74,6 +74,7 @@ enum { CONTEXT_RECSCREEN, CONTEXT_KEYBOARD, CONTEXT_FM, + CONTEXT_USB_HID, }; @@ -237,6 +238,15 @@ enum { ACTION_TOUCH_REPMODE, #endif + /* USB HID codes */ + ACTION_USB_HID_PLAY, + ACTION_USB_HID_STOP, + ACTION_USB_HID_SKIPPREV, + ACTION_USB_HID_SKIPNEXT, + ACTION_USB_HID_VOLDOWN, + ACTION_USB_HID_VOLUP, + ACTION_USB_HID_MUTE, + ACTION_USB_HID_MENU, LAST_ACTION_PLACEHOLDER, /* custom actions should be this + something */ }; diff --git a/apps/keymaps/keymap-c100.c b/apps/keymaps/keymap-c100.c index 70cb17ae1a..087be8665f 100644 --- a/apps/keymaps/keymap-c100.c +++ b/apps/keymaps/keymap-c100.c @@ -269,6 +269,19 @@ static const struct button_mapping button_context_bmark[] = { LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST), }; /* button_context_bmark */ +#ifdef HAVE_USBSTACK +static const struct button_mapping button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_VOLUP, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_VOLUP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_USB_HID_MUTE, BUTTON_VOLDOWN, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_MENU, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_usb_hid */ +#endif + /* get_context_mapping returns a pointer to one of the above defined arrays depending on the context */ const struct button_mapping* get_context_mapping(int context) { @@ -317,7 +330,10 @@ const struct button_mapping* get_context_mapping(int context) #endif case CONTEXT_KEYBOARD: return button_context_keyboard; - +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return button_context_usb_hid; +#endif default: return button_context_standard; } diff --git a/apps/keymaps/keymap-c200.c b/apps/keymaps/keymap-c200.c index 430ca50e59..56504584f8 100644 --- a/apps/keymaps/keymap-c200.c +++ b/apps/keymaps/keymap-c200.c @@ -281,6 +281,23 @@ static const struct button_mapping button_context_bmark[] = { LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST), }; /* button_context_bmark */ +#ifdef HAVE_USBSTACK +static const struct button_mapping button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_UP, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_VOL_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_VOL_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_MUTE, BUTTON_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_POWER, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_usb_hid */ +#endif + /* get_context_mapping returns a pointer to one of the above defined arrays depending on the context */ const struct button_mapping* get_context_mapping(int context) { @@ -330,7 +347,10 @@ const struct button_mapping* get_context_mapping(int context) #endif case CONTEXT_KEYBOARD: return button_context_keyboard; - +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return button_context_usb_hid; +#endif default: return button_context_standard; } diff --git a/apps/keymaps/keymap-clip.c b/apps/keymaps/keymap-clip.c index e1d31cb398..4b778beeb7 100644 --- a/apps/keymaps/keymap-clip.c +++ b/apps/keymaps/keymap-clip.c @@ -265,6 +265,23 @@ static const struct button_mapping button_context_bmark[] = { LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST), }; /* button_context_bmark */ +#ifdef HAVE_USBSTACK +static const struct button_mapping button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_UP, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_POWER, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_VOL_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_VOL_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_MUTE, BUTTON_SELECT, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_DOWN, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_usb_hid */ +#endif + /* get_context_mapping returns a pointer to one of the above defined arrays depending on the context */ const struct button_mapping* get_context_mapping(int context) { @@ -310,7 +327,10 @@ const struct button_mapping* get_context_mapping(int context) return button_context_recscreen; case CONTEXT_KEYBOARD: return button_context_keyboard; - +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return button_context_usb_hid; +#endif default: return button_context_standard; } diff --git a/apps/keymaps/keymap-e200.c b/apps/keymaps/keymap-e200.c index c94ae03802..a2017de6f3 100644 --- a/apps/keymaps/keymap-e200.c +++ b/apps/keymaps/keymap-e200.c @@ -271,6 +271,23 @@ static const struct button_mapping button_context_bmark[] = { LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST), }; /* button_context_bmark */ +#ifdef HAVE_USBSTACK +static const struct button_mapping button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_UP, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_POWER, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_SCROLL_FWD, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_SCROLL_BACK, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_MUTE, BUTTON_SELECT, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_DOWN, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_usb_hid */ +#endif + /* get_context_mapping returns a pointer to one of the above defined arrays depending on the context */ const struct button_mapping* get_context_mapping(int context) { @@ -318,7 +335,10 @@ const struct button_mapping* get_context_mapping(int context) return button_context_recscreen; case CONTEXT_KEYBOARD: return button_context_keyboard; - +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return button_context_usb_hid; +#endif default: return button_context_standard; } diff --git a/apps/keymaps/keymap-gigabeat-s.c b/apps/keymaps/keymap-gigabeat-s.c index f431f5fc02..4fc7e8d469 100644 --- a/apps/keymaps/keymap-gigabeat-s.c +++ b/apps/keymaps/keymap-gigabeat-s.c @@ -464,6 +464,42 @@ static const struct button_mapping remote_button_context_right_is_inc[] = { LAST_ITEM_IN_LIST }; /* remote_button_context_right_is_inc */ +#ifdef HAVE_USBSTACK +static const struct button_mapping button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_PLAY, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_POWER, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_VOL_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_VOL_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_MUTE, BUTTON_SELECT, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_MENU, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_usb_hid */ + +static const struct button_mapping remote_button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_RC_PLAY, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_RC_POWER, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_RC_REW, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_RC_FF, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_RC_VOL_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_RC_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_RC_VOL_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_RC_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_MUTE, BUTTON_RC_DSP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_RC_DSP, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* remote_button_context_usb_hid */ +#endif + static const struct button_mapping* get_context_mapping_remote( int context ) { context &= ~CONTEXT_REMOTE; @@ -506,6 +542,10 @@ static const struct button_mapping* get_context_mapping_remote( int context ) case CONTEXT_FM: return remote_button_context_radio; +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return remote_button_context_usb_hid; +#endif default: return remote_button_context_standard; } @@ -573,6 +613,10 @@ const struct button_mapping* get_context_mapping(int context) case CONTEXT_FM: return button_context_radio; +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return button_context_usb_hid; +#endif default: return button_context_standard; } diff --git a/apps/keymaps/keymap-h10.c b/apps/keymaps/keymap-h10.c index 9afca4e61c..77247d35d8 100644 --- a/apps/keymaps/keymap-h10.c +++ b/apps/keymaps/keymap-h10.c @@ -332,6 +332,61 @@ static const struct button_mapping button_context_radio[] = { }; + + + + + +static const struct button_mapping remote_button_context_wps[] = { + { ACTION_WPS_PLAY, BUTTON_RC_PLAY|BUTTON_REL, BUTTON_RC_PLAY }, + { ACTION_WPS_STOP, BUTTON_RC_PLAY|BUTTON_REPEAT,BUTTON_RC_PLAY }, + { ACTION_WPS_SKIPPREV, BUTTON_RC_REW|BUTTON_REL, BUTTON_RC_REW}, + { ACTION_WPS_SEEKBACK, BUTTON_RC_REW|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_WPS_STOPSEEK, BUTTON_RC_REW|BUTTON_REL, BUTTON_RC_REW|BUTTON_REPEAT }, + { ACTION_WPS_SKIPNEXT, BUTTON_RC_FF|BUTTON_REL, BUTTON_RC_FF }, + { ACTION_WPS_SEEKFWD, BUTTON_RC_FF|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_WPS_STOPSEEK, BUTTON_RC_FF|BUTTON_REL, BUTTON_RC_FF|BUTTON_REPEAT }, + + { ACTION_WPS_VOLDOWN, BUTTON_RC_VOL_DOWN, BUTTON_NONE }, + { ACTION_WPS_VOLDOWN, BUTTON_RC_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_WPS_VOLUP, BUTTON_RC_VOL_UP, BUTTON_NONE }, + { ACTION_WPS_VOLUP, BUTTON_RC_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, + + { ACTION_WPS_PITCHSCREEN, BUTTON_RC_PLAY|BUTTON_LEFT, BUTTON_RC_PLAY }, + { ACTION_WPS_ID3SCREEN, BUTTON_RC_PLAY|BUTTON_RIGHT, BUTTON_RC_PLAY }, + + LAST_ITEM_IN_LIST +}; /* remote_button_context_wps */ + +#ifdef HAVE_USBSTACK +static const struct button_mapping button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_PLAY, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_PLAY|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_REW, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_FF, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_SCROLL_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_SCROLL_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_SCROLL_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_SCROLL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_POWER, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_usb_hid */ + +static const struct button_mapping remote_button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_RC_PLAY, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_RC_PLAY|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_RC_REW, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_RC_FF, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_RC_SCROLL_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_RC_SCROLL_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_RC_SCROLL_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_RC_SCROLL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* remote_button_context_usb_hid */ +#endif + static const struct button_mapping* get_context_mapping_remote( int context ) { context ^= CONTEXT_REMOTE; @@ -361,6 +416,10 @@ static const struct button_mapping* get_context_mapping_remote( int context ) return remote_button_context_pitchscreen; case CONTEXT_RECSCREEN: return button_context_recscreen; +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return remote_button_context_usb_hid; +#endif default: return remote_button_context_standard; @@ -415,6 +474,10 @@ const struct button_mapping* get_context_mapping(int context) return button_context_recscreen; case CONTEXT_FM: return button_context_radio; +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return button_context_usb_hid; +#endif default: return button_context_standard; } diff --git a/apps/keymaps/keymap-hdd1630.c b/apps/keymaps/keymap-hdd1630.c index 6b38983d08..deb77307b8 100644 --- a/apps/keymaps/keymap-hdd1630.c +++ b/apps/keymaps/keymap-hdd1630.c @@ -282,6 +282,27 @@ static const struct button_mapping button_context_radio[] = { }; #endif +#ifdef HAVE_USBSTACK +static const struct button_mapping button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_VIEW, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_POWER, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_VOL_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_VOL_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_MUTE, BUTTON_SELECT, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_MENU, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_usb_hid */ +#endif + const struct button_mapping* get_context_mapping(int context) { switch (context) @@ -328,6 +349,10 @@ const struct button_mapping* get_context_mapping(int context) #if CONFIG_TUNER case CONTEXT_FM: return button_context_radio; +#endif +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return button_context_usb_hid; #endif } return button_context_standard; diff --git a/apps/keymaps/keymap-ipod.c b/apps/keymaps/keymap-ipod.c index a7aeb27568..163a810036 100644 --- a/apps/keymaps/keymap-ipod.c +++ b/apps/keymaps/keymap-ipod.c @@ -188,6 +188,23 @@ const struct button_mapping button_context_recscreen[] = { }; /* button_context_recscreen */ #endif +#ifdef HAVE_USBSTACK +static const struct button_mapping button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_PLAY, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_PLAY|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_SCROLL_FWD, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_SCROLL_BACK, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_MUTE, BUTTON_SELECT, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_MENU, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_usb_hid */ +#endif + #if BUTTON_REMOTE != 0 /***************************************************************************** * Remote control mappings @@ -220,6 +237,20 @@ static const struct button_mapping remote_button_context_wps[] = { LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) }; +#ifdef HAVE_USBSTACK +static const struct button_mapping remote_button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_RC_PLAY, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_RC_PLAY|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_RC_LEFT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_RC_RIGHT, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_RC_VOL_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_RC_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_RC_VOL_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_RC_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* remote_button_context_usb_hid */ +#endif static const struct button_mapping* get_context_mapping_remote( int context ) { @@ -229,7 +260,10 @@ static const struct button_mapping* get_context_mapping_remote( int context ) { case CONTEXT_WPS: return remote_button_context_wps; - +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return remote_button_context_usb_hid; +#endif default: return remote_button_context_standard; } @@ -281,6 +315,10 @@ const struct button_mapping* get_context_mapping(int context) #ifdef HAVE_RECORDING case CONTEXT_RECSCREEN: return button_context_recscreen; +#endif +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return button_context_usb_hid; #endif default: return button_context_standard; diff --git a/apps/keymaps/keymap-mr100.c b/apps/keymaps/keymap-mr100.c index 8b7b74d19b..aff235a480 100644 --- a/apps/keymaps/keymap-mr100.c +++ b/apps/keymaps/keymap-mr100.c @@ -313,6 +313,37 @@ static const struct button_mapping remote_button_context_tree[] = { LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) }; +#ifdef HAVE_USBSTACK +static const struct button_mapping button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_PLAY, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_POWER, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_LEFT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_MUTE, BUTTON_SELECT, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_MENU, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_usb_hid */ + +static const struct button_mapping remote_button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_RC_PLAY, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_RC_PLAY|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_RC_REW, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_RC_FF, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_RC_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_RC_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_RC_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_RC_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_RC_FAV, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* remote_button_context_usb_hid */ +#endif + static const struct button_mapping* get_context_mapping_remote( int context ) { context ^= CONTEXT_REMOTE; @@ -324,6 +355,10 @@ static const struct button_mapping* get_context_mapping_remote( int context ) case CONTEXT_MAINMENU: case CONTEXT_TREE: return remote_button_context_tree; +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return remote_button_context_usb_hid; +#endif } return remote_button_context_standard; } @@ -374,6 +409,10 @@ const struct button_mapping* get_context_mapping(int context) return button_context_pitchscreen; case CONTEXT_KEYBOARD: return button_context_keyboard; +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return button_context_usb_hid; +#endif } return button_context_standard; } diff --git a/apps/keymaps/keymap-ondavx747.c b/apps/keymaps/keymap-ondavx747.c index 82fde820fb..0b7f1b3870 100644 --- a/apps/keymaps/keymap-ondavx747.c +++ b/apps/keymaps/keymap-ondavx747.c @@ -152,6 +152,19 @@ static const struct button_mapping button_context_keyboard[] = { LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD) }; /* button_context_keyboard */ +#ifdef HAVE_USBSTACK +static const struct button_mapping button_context_usb_hid[] = { + { ACTION_USB_HID_VOLUP, BUTTON_VOL_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_VOL_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_MUTE, BUTTON_POWER, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_MENU, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_usb_hid */ +#endif + const struct button_mapping* target_get_context_mapping(int context) { switch (context) @@ -196,6 +209,10 @@ const struct button_mapping* target_get_context_mapping(int context) return button_context_pitchscreen; case CONTEXT_KEYBOARD: return button_context_keyboard; +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return button_context_usb_hid; +#endif } return button_context_standard; } diff --git a/apps/keymaps/keymap-sa9200.c b/apps/keymaps/keymap-sa9200.c index 478eea3bfe..3091ec6156 100644 --- a/apps/keymaps/keymap-sa9200.c +++ b/apps/keymaps/keymap-sa9200.c @@ -269,6 +269,27 @@ static const struct button_mapping button_context_keyboard[] = { LAST_ITEM_IN_LIST }; /* button_context_keyboard */ +#ifdef HAVE_USBSTACK +static const struct button_mapping button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_RIGHT, BUTTON_NONE }, + { ACTION_USB_HID_STOP, BUTTON_POWER, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_REW, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_FFWD, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_VOL_UP, BUTTON_NONE }, + { ACTION_USB_HID_VOLUP, BUTTON_VOL_UP|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_VOL_DOWN, BUTTON_NONE }, + { ACTION_USB_HID_VOLDOWN, BUTTON_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE }, + { ACTION_USB_HID_MUTE, BUTTON_SELECT, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_MENU, BUTTON_NONE }, + + LAST_ITEM_IN_LIST +}; /* button_context_usb_hid */ +#endif + const struct button_mapping* get_context_mapping(int context) { switch (context) @@ -312,6 +333,10 @@ const struct button_mapping* get_context_mapping(int context) return button_context_pitchscreen; case CONTEXT_KEYBOARD: return button_context_keyboard; +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return button_context_usb_hid; +#endif } return button_context_standard; } diff --git a/apps/keymaps/keymap-touchscreen.c b/apps/keymaps/keymap-touchscreen.c index ce5d01c9dc..70009794a5 100644 --- a/apps/keymaps/keymap-touchscreen.c +++ b/apps/keymaps/keymap-touchscreen.c @@ -245,6 +245,18 @@ static const struct button_mapping button_context_radio[] = { LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM2|CONTEXT_FM) }; /* button_context_radio */ +#ifdef HAVE_USBSTACK +static const struct button_mapping button_context_usb_hid[] = { + { ACTION_USB_HID_PLAY, BUTTON_TOPRIGHT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPPREV, BUTTON_MIDLEFT, BUTTON_NONE }, + { ACTION_USB_HID_SKIPNEXT, BUTTON_MIDRIGHT, BUTTON_NONE }, + { ACTION_USB_HID_MUTE, BUTTON_CENTER, BUTTON_NONE }, + { ACTION_USB_HID_MENU, BUTTON_TOPLEFT, BUTTON_NONE }, + + LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM2|CONTEXT_USB_HID) +}; /* button_context_usb_hid */ +#endif + const struct button_mapping* get_context_mapping(int context) { if (context & CONTEXT_CUSTOM2 @@ -297,6 +309,10 @@ const struct button_mapping* get_context_mapping(int context) return button_context_pitchscreen; case CONTEXT_KEYBOARD: return button_context_keyboard; +#ifdef HAVE_USBSTACK + case CONTEXT_USB_HID: + return button_context_usb_hid; +#endif } return button_context_standard; } diff --git a/apps/screens.c b/apps/screens.c index 8c2b145550..be7e29a0c9 100644 --- a/apps/screens.c +++ b/apps/screens.c @@ -34,6 +34,12 @@ #include "audio.h" #include "mp3_playback.h" #include "usb.h" +#if defined(HAVE_USBSTACK) +#include "usb_core.h" +#ifdef USB_CLASS_HID +#include "usbstack/usb_hid.h" +#endif +#endif #include "settings.h" #include "status.h" #include "playlist.h" @@ -90,23 +96,70 @@ static int clamp_value_wrap(int value, int max, int min) #endif #ifndef SIMULATOR -static int handle_usb_events(struct event_queue *q) +static int handle_usb_events(void) { - struct queue_event ev; int next_update=0; +#ifdef HAVE_TOUCHSCREEN + enum touchscreen_mode old_mode = touchscreen_get_mode(); + + /* TODO: Paint buttons on screens OR switch to point mode and use + * touchscreen as a touchpad to move the host's mouse cursor */ + touchscreen_set_mode(TOUCHSCREEN_BUTTON); +#endif /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */ while(1) { - queue_wait_w_tmo(q, &ev, HZ/4); - switch(ev.id) + int button; +#if defined(HAVE_USBSTACK) && defined(USB_CLASS_HID) + bool hid_enabled = usb_core_driver_enabled(USB_DRIVER_HID); + + if (hid_enabled) + { + consumer_usage_page_t cmd = UNASSIGNED; + button = get_action(CONTEXT_USB_HID, HZ/4); + + switch (button) + { + case ACTION_USB_HID_PLAY: + cmd = PLAY_PAUSE; + break; + case ACTION_USB_HID_STOP: + cmd = STOP; + break; + case ACTION_USB_HID_SKIPPREV: + cmd = SCAN_PREVIOUS_TRACK; + break; + case ACTION_USB_HID_SKIPNEXT: + cmd = SCAN_NEXT_TRACK; + break; + case ACTION_USB_HID_VOLDOWN: + cmd = VOLUME_DECREMENT; + break; + case ACTION_USB_HID_VOLUP: + cmd = VOLUME_INCREMENT; + break; + case ACTION_USB_HID_MUTE: + cmd = MUTE; + break; + } + + if (cmd != UNASSIGNED) + usb_hid_send_consumer_usage(cmd); + } + else +#endif + button = button_get_w_tmo(HZ/4); + + switch(button) { case SYS_USB_DISCONNECTED: usb_acknowledge(SYS_USB_DISCONNECTED_ACK); - return 0; + goto Exit; case SYS_TIMEOUT: break; } + if(TIME_AFTER(current_tick,next_update)) { if(usb_inserted()) { @@ -118,6 +171,11 @@ static int handle_usb_events(struct event_queue *q) next_update=current_tick+HZ/2; } } +Exit: +#ifdef HAVE_TOUCHSCREEN + touchscreen_set_mode(old_mode); +#endif + return 0; } #endif @@ -172,7 +230,7 @@ void usb_screen(void) while (button_get(true) & BUTTON_REL); #else usb_acknowledge(SYS_USB_CONNECTED_ACK); - while(handle_usb_events(&button_queue)); + while (handle_usb_events()); #endif /* SIMULATOR */ #ifdef HAVE_LCD_CHARCELLS status_set_usb(false);