From 2ae9850438a7994c37a4b2bf9a1f390d911165cb Mon Sep 17 00:00:00 2001 From: Robert Fisk Date: Sun, 17 Apr 2016 01:55:55 +1200 Subject: [PATCH] Add HID files that went missing in merge --- .../Class/HID/Inc/usbh_hid_keybd.h | 326 ++++++++++++++ .../Class/HID/Inc/usbh_hid_mouse.h | 125 ++++++ .../Class/HID/Inc/usbh_hid_parser.h | 106 +++++ .../Class/HID/Inc/usbh_hid_usage.h | 200 +++++++++ .../Class/HID/Src/usbh_hid_keybd.c | 418 ++++++++++++++++++ .../Class/HID/Src/usbh_hid_mouse.c | 267 +++++++++++ .../Class/HID/Src/usbh_hid_parser.c | 235 ++++++++++ 7 files changed, 1677 insertions(+) create mode 100644 Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_keybd.h create mode 100644 Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_mouse.h create mode 100644 Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_parser.h create mode 100644 Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_usage.h create mode 100644 Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_keybd.c create mode 100644 Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_mouse.c create mode 100644 Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_parser.c diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_keybd.h b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_keybd.h new file mode 100644 index 0000000..29678e0 --- /dev/null +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_keybd.h @@ -0,0 +1,326 @@ +/** + ****************************************************************************** + * @file usbh_hid_keybd.h + * @author MCD Application Team + * @version V3.2.2 + * @date 07-July-2015 + * @brief This file contains all the prototypes for the usbh_hid_keybd.c + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2015 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive -----------------------------------------------*/ +#ifndef __USBH_HID_KEYBD_H +#define __USBH_HID_KEYBD_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "usbh_hid.h" +#include "usbh_hid_keybd.h" + +/** @addtogroup USBH_LIB + * @{ + */ + +/** @addtogroup USBH_CLASS + * @{ + */ + +/** @addtogroup USBH_HID_CLASS + * @{ + */ + +/** @defgroup USBH_HID_KEYBD + * @brief This file is the Header file for usbh_hid_keybd.c + * @{ + */ + + +/** @defgroup USBH_HID_KEYBD_Exported_Types + * @{ + */ +#define KEY_NONE 0x00 +#define KEY_ERRORROLLOVER 0x01 +#define KEY_POSTFAIL 0x02 +#define KEY_ERRORUNDEFINED 0x03 +#define KEY_A 0x04 +#define KEY_B 0x05 +#define KEY_C 0x06 +#define KEY_D 0x07 +#define KEY_E 0x08 +#define KEY_F 0x09 +#define KEY_G 0x0A +#define KEY_H 0x0B +#define KEY_I 0x0C +#define KEY_J 0x0D +#define KEY_K 0x0E +#define KEY_L 0x0F +#define KEY_M 0x10 +#define KEY_N 0x11 +#define KEY_O 0x12 +#define KEY_P 0x13 +#define KEY_Q 0x14 +#define KEY_R 0x15 +#define KEY_S 0x16 +#define KEY_T 0x17 +#define KEY_U 0x18 +#define KEY_V 0x19 +#define KEY_W 0x1A +#define KEY_X 0x1B +#define KEY_Y 0x1C +#define KEY_Z 0x1D +#define KEY_1_EXCLAMATION_MARK 0x1E +#define KEY_2_AT 0x1F +#define KEY_3_NUMBER_SIGN 0x20 +#define KEY_4_DOLLAR 0x21 +#define KEY_5_PERCENT 0x22 +#define KEY_6_CARET 0x23 +#define KEY_7_AMPERSAND 0x24 +#define KEY_8_ASTERISK 0x25 +#define KEY_9_OPARENTHESIS 0x26 +#define KEY_0_CPARENTHESIS 0x27 +#define KEY_ENTER 0x28 +#define KEY_ESCAPE 0x29 +#define KEY_BACKSPACE 0x2A +#define KEY_TAB 0x2B +#define KEY_SPACEBAR 0x2C +#define KEY_MINUS_UNDERSCORE 0x2D +#define KEY_EQUAL_PLUS 0x2E +#define KEY_OBRACKET_AND_OBRACE 0x2F +#define KEY_CBRACKET_AND_CBRACE 0x30 +#define KEY_BACKSLASH_VERTICAL_BAR 0x31 +#define KEY_NONUS_NUMBER_SIGN_TILDE 0x32 +#define KEY_SEMICOLON_COLON 0x33 +#define KEY_SINGLE_AND_DOUBLE_QUOTE 0x34 +#define KEY_GRAVE ACCENT AND TILDE 0x35 +#define KEY_COMMA_AND_LESS 0x36 +#define KEY_DOT_GREATER 0x37 +#define KEY_SLASH_QUESTION 0x38 +#define KEY_CAPS LOCK 0x39 +#define KEY_F1 0x3A +#define KEY_F2 0x3B +#define KEY_F3 0x3C +#define KEY_F4 0x3D +#define KEY_F5 0x3E +#define KEY_F6 0x3F +#define KEY_F7 0x40 +#define KEY_F8 0x41 +#define KEY_F9 0x42 +#define KEY_F10 0x43 +#define KEY_F11 0x44 +#define KEY_F12 0x45 +#define KEY_PRINTSCREEN 0x46 +#define KEY_SCROLL LOCK 0x47 +#define KEY_PAUSE 0x48 +#define KEY_INSERT 0x49 +#define KEY_HOME 0x4A +#define KEY_PAGEUP 0x4B +#define KEY_DELETE 0x4C +#define KEY_END1 0x4D +#define KEY_PAGEDOWN 0x4E +#define KEY_RIGHTARROW 0x4F +#define KEY_LEFTARROW 0x50 +#define KEY_DOWNARROW 0x51 +#define KEY_UPARROW 0x52 +#define KEY_KEYPAD_NUM_LOCK_AND_CLEAR 0x53 +#define KEY_KEYPAD_SLASH 0x54 +#define KEY_KEYPAD_ASTERIKS 0x55 +#define KEY_KEYPAD_MINUS 0x56 +#define KEY_KEYPAD_PLUS 0x57 +#define KEY_KEYPAD_ENTER 0x58 +#define KEY_KEYPAD_1_END 0x59 +#define KEY_KEYPAD_2_DOWN_ARROW 0x5A +#define KEY_KEYPAD_3_PAGEDN 0x5B +#define KEY_KEYPAD_4_LEFT_ARROW 0x5C +#define KEY_KEYPAD_5 0x5D +#define KEY_KEYPAD_6_RIGHT_ARROW 0x5E +#define KEY_KEYPAD_7_HOME 0x5F +#define KEY_KEYPAD_8_UP_ARROW 0x60 +#define KEY_KEYPAD_9_PAGEUP 0x61 +#define KEY_KEYPAD_0_INSERT 0x62 +#define KEY_KEYPAD_DECIMAL_SEPARATOR_DELETE 0x63 +#define KEY_NONUS_BACK_SLASH_VERTICAL_BAR 0x64 +#define KEY_APPLICATION 0x65 +#define KEY_POWER 0x66 +#define KEY_KEYPAD_EQUAL 0x67 +#define KEY_F13 0x68 +#define KEY_F14 0x69 +#define KEY_F15 0x6A +#define KEY_F16 0x6B +#define KEY_F17 0x6C +#define KEY_F18 0x6D +#define KEY_F19 0x6E +#define KEY_F20 0x6F +#define KEY_F21 0x70 +#define KEY_F22 0x71 +#define KEY_F23 0x72 +#define KEY_F24 0x73 +#define KEY_EXECUTE 0x74 +#define KEY_HELP 0x75 +#define KEY_MENU 0x76 +#define KEY_SELECT 0x77 +#define KEY_STOP 0x78 +#define KEY_AGAIN 0x79 +#define KEY_UNDO 0x7A +#define KEY_CUT 0x7B +#define KEY_COPY 0x7C +#define KEY_PASTE 0x7D +#define KEY_FIND 0x7E +#define KEY_MUTE 0x7F +#define KEY_VOLUME_UP 0x80 +#define KEY_VOLUME_DOWN 0x81 +#define KEY_LOCKING_CAPS_LOCK 0x82 +#define KEY_LOCKING_NUM_LOCK 0x83 +#define KEY_LOCKING_SCROLL_LOCK 0x84 +#define KEY_KEYPAD_COMMA 0x85 +#define KEY_KEYPAD_EQUAL_SIGN 0x86 +#define KEY_INTERNATIONAL1 0x87 +#define KEY_INTERNATIONAL2 0x88 +#define KEY_INTERNATIONAL3 0x89 +#define KEY_INTERNATIONAL4 0x8A +#define KEY_INTERNATIONAL5 0x8B +#define KEY_INTERNATIONAL6 0x8C +#define KEY_INTERNATIONAL7 0x8D +#define KEY_INTERNATIONAL8 0x8E +#define KEY_INTERNATIONAL9 0x8F +#define KEY_LANG1 0x90 +#define KEY_LANG2 0x91 +#define KEY_LANG3 0x92 +#define KEY_LANG4 0x93 +#define KEY_LANG5 0x94 +#define KEY_LANG6 0x95 +#define KEY_LANG7 0x96 +#define KEY_LANG8 0x97 +#define KEY_LANG9 0x98 +#define KEY_ALTERNATE_ERASE 0x99 +#define KEY_SYSREQ 0x9A +#define KEY_CANCEL 0x9B +#define KEY_CLEAR 0x9C +#define KEY_PRIOR 0x9D +#define KEY_RETURN 0x9E +#define KEY_SEPARATOR 0x9F +#define KEY_OUT 0xA0 +#define KEY_OPER 0xA1 +#define KEY_CLEAR_AGAIN 0xA2 +#define KEY_CRSEL 0xA3 +#define KEY_EXSEL 0xA4 +#define KEY_KEYPAD_00 0xB0 +#define KEY_KEYPAD_000 0xB1 +#define KEY_THOUSANDS_SEPARATOR 0xB2 +#define KEY_DECIMAL_SEPARATOR 0xB3 +#define KEY_CURRENCY_UNIT 0xB4 +#define KEY_CURRENCY_SUB_UNIT 0xB5 +#define KEY_KEYPAD_OPARENTHESIS 0xB6 +#define KEY_KEYPAD_CPARENTHESIS 0xB7 +#define KEY_KEYPAD_OBRACE 0xB8 +#define KEY_KEYPAD_CBRACE 0xB9 +#define KEY_KEYPAD_TAB 0xBA +#define KEY_KEYPAD_BACKSPACE 0xBB +#define KEY_KEYPAD_A 0xBC +#define KEY_KEYPAD_B 0xBD +#define KEY_KEYPAD_C 0xBE +#define KEY_KEYPAD_D 0xBF +#define KEY_KEYPAD_E 0xC0 +#define KEY_KEYPAD_F 0xC1 +#define KEY_KEYPAD_XOR 0xC2 +#define KEY_KEYPAD_CARET 0xC3 +#define KEY_KEYPAD_PERCENT 0xC4 +#define KEY_KEYPAD_LESS 0xC5 +#define KEY_KEYPAD_GREATER 0xC6 +#define KEY_KEYPAD_AMPERSAND 0xC7 +#define KEY_KEYPAD_LOGICAL_AND 0xC8 +#define KEY_KEYPAD_VERTICAL_BAR 0xC9 +#define KEY_KEYPAD_LOGIACL_OR 0xCA +#define KEY_KEYPAD_COLON 0xCB +#define KEY_KEYPAD_NUMBER_SIGN 0xCC +#define KEY_KEYPAD_SPACE 0xCD +#define KEY_KEYPAD_AT 0xCE +#define KEY_KEYPAD_EXCLAMATION_MARK 0xCF +#define KEY_KEYPAD_MEMORY_STORE 0xD0 +#define KEY_KEYPAD_MEMORY_RECALL 0xD1 +#define KEY_KEYPAD_MEMORY_CLEAR 0xD2 +#define KEY_KEYPAD_MEMORY_ADD 0xD3 +#define KEY_KEYPAD_MEMORY_SUBTRACT 0xD4 +#define KEY_KEYPAD_MEMORY_MULTIPLY 0xD5 +#define KEY_KEYPAD_MEMORY_DIVIDE 0xD6 +#define KEY_KEYPAD_PLUSMINUS 0xD7 +#define KEY_KEYPAD_CLEAR 0xD8 +#define KEY_KEYPAD_CLEAR_ENTRY 0xD9 +#define KEY_KEYPAD_BINARY 0xDA +#define KEY_KEYPAD_OCTAL 0xDB +#define KEY_KEYPAD_DECIMAL 0xDC +#define KEY_KEYPAD_HEXADECIMAL 0xDD +#define KEY_LEFTCONTROL 0xE0 +#define KEY_LEFTSHIFT 0xE1 +#define KEY_LEFTALT 0xE2 +#define KEY_LEFT_GUI 0xE3 +#define KEY_RIGHTCONTROL 0xE4 +#define KEY_RIGHTSHIFT 0xE5 +#define KEY_RIGHTALT 0xE6 +#define KEY_RIGHT_GUI 0xE7 + +typedef struct +{ + uint8_t state; + uint8_t lctrl; + uint8_t lshift; + uint8_t lalt; + uint8_t lgui; + uint8_t rctrl; + uint8_t rshift; + uint8_t ralt; + uint8_t rgui; + uint8_t keys[6]; +} +HID_KEYBD_Info_TypeDef; + +USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost); +HID_KEYBD_Info_TypeDef *USBH_HID_GetKeybdInfo(USBH_HandleTypeDef *phost); +uint8_t USBH_HID_GetASCIICode(HID_KEYBD_Info_TypeDef *info); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USBH_HID_KEYBD_H */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_mouse.h b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_mouse.h new file mode 100644 index 0000000..cf46a40 --- /dev/null +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_mouse.h @@ -0,0 +1,125 @@ +/** + ****************************************************************************** + * @file usbh_hid_mouse.h + * @author MCD Application Team + * @version V3.2.2 + * @date 07-July-2015 + * @brief This file contains all the prototypes for the usbh_hid_mouse.c + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2015 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive ----------------------------------------------*/ +#ifndef __USBH_HID_MOUSE_H +#define __USBH_HID_MOUSE_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "usbh_hid.h" + +/** @addtogroup USBH_LIB + * @{ + */ + +/** @addtogroup USBH_CLASS + * @{ + */ + +/** @addtogroup USBH_HID_CLASS + * @{ + */ + +/** @defgroup USBH_HID_MOUSE + * @brief This file is the Header file for usbh_hid_mouse.c + * @{ + */ + + +/** @defgroup USBH_HID_MOUSE_Exported_Types + * @{ + */ + +typedef struct _HID_MOUSE_Info +{ + uint8_t x; + uint8_t y; + uint8_t buttons[3]; +} +HID_MOUSE_Info_TypeDef; + +/** + * @} + */ + +/** @defgroup USBH_HID_MOUSE_Exported_Defines + * @{ + */ +/** + * @} + */ + +/** @defgroup USBH_HID_MOUSE_Exported_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup USBH_HID_MOUSE_Exported_Variables + * @{ + */ +/** + * @} + */ + +/** @defgroup USBH_HID_MOUSE_Exported_FunctionsPrototype + * @{ + */ +USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost); +HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USBH_HID_MOUSE_H */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_parser.h b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_parser.h new file mode 100644 index 0000000..5df2137 --- /dev/null +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_parser.h @@ -0,0 +1,106 @@ +/** + ****************************************************************************** + * @file usbh_hid_parser.c + * @author MCD Application Team + * @version V3.2.2 + * @date 07-July-2015 + * @brief This file is the header file of the usbh_hid_parser.c + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2015 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive -----------------------------------------------*/ +#ifndef __USBH_HID_PARSER_H +#define __USBH_HID_PARSER_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "usbh_hid.h" +#include "usbh_hid_usage.h" + +/** @addtogroup USBH_LIB + * @{ + */ + +/** @addtogroup USBH_CLASS + * @{ + */ + +/** @addtogroup USBH_HID_CLASS + * @{ + */ + +/** @defgroup USBH_HID_PARSER + * @brief This file is the Header file for usbh_hid_parser.c + * @{ + */ + + +/** @defgroup USBH_HID_PARSER_Exported_Types + * @{ + */ +typedef struct +{ + uint8_t *data; + uint32_t size; + uint8_t shift; + uint8_t count; + uint8_t sign; + uint32_t logical_min; /*min value device can return*/ + uint32_t logical_max; /*max value device can return*/ + uint32_t physical_min; /*min vale read can report*/ + uint32_t physical_max; /*max value read can report*/ + uint32_t resolution; +} +HID_Report_ItemTypedef; + + +uint32_t HID_ReadItem (HID_Report_ItemTypedef *ri, uint8_t ndx); +uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USBH_HID_PARSER_H */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_usage.h b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_usage.h new file mode 100644 index 0000000..27fc0e9 --- /dev/null +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_usage.h @@ -0,0 +1,200 @@ +/** + ****************************************************************************** + * @file usbh_hid_usage.c + * @author MCD Application Team + * @version V3.2.2 + * @date 07-July-2015 + * @brief This file contain the USAGE page codes + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2015 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ +/* Define to prevent recursive ----------------------------------------------*/ +#ifndef __USDH_HID_USAGE_H +#define __USDH_HID_USAGE_H + +#ifdef __cplusplus + extern "C" { +#endif + +/** @addtogroup USBH_LIB + * @{ + */ + +/** @addtogroup USBH_CLASS + * @{ + */ + +/** @addtogroup USBH_HID_CLASS + * @{ + */ + +/** @defgroup USBH_HID_USAGE + * @brief This file is the Header file for usbh_hid_usage.c + * @{ + */ + + +/** @defgroup USBH_HID_USAGE_Exported_Types + * @{ + */ + +/****************************************************/ +/* HID 1.11 usage pages */ +/****************************************************/ + +#define HID_USAGE_PAGE_UNDEFINED uint16_t (0x00) /* Undefined */ +/**** Top level pages */ +#define HID_USAGE_PAGE_GEN_DES uint16_t (0x01) /* Generic Desktop Controls*/ +#define HID_USAGE_PAGE_SIM_CTR uint16_t (0x02) /* Simulation Controls */ +#define HID_USAGE_PAGE_VR_CTR uint16_t (0x03) /* VR Controls */ +#define HID_USAGE_PAGE_SPORT_CTR uint16_t (0x04) /* Sport Controls */ +#define HID_USAGE_PAGE_GAME_CTR uint16_t (0x05) /* Game Controls */ +#define HID_USAGE_PAGE_GEN_DEV uint16_t (0x06) /* Generic Device Controls */ +#define HID_USAGE_PAGE_KEYB uint16_t (0x07) /* Keyboard/Keypad */ +#define HID_USAGE_PAGE_LED uint16_t (0x08) /* LEDs */ +#define HID_USAGE_PAGE_BUTTON uint16_t (0x09) /* Button */ +#define HID_USAGE_PAGE_ORDINAL uint16_t (0x0A) /* Ordinal */ +#define HID_USAGE_PAGE_PHONE uint16_t (0x0B) /* Telephony */ +#define HID_USAGE_PAGE_CONSUMER uint16_t (0x0C) /* Consumer */ +#define HID_USAGE_PAGE_DIGITIZER uint16_t (0x0D) /* Digitizer*/ +/* 0E Reserved */ +#define HID_USAGE_PAGE_PID uint16_t (0x0F) /* PID Page (force feedback and related devices) */ +#define HID_USAGE_PAGE_UNICODE uint16_t (0x10) /* Unicode */ +/* 11-13 Reserved */ +#define HID_USAGE_PAGE_ALNUM_DISP uint16_t (0x14) /* Alphanumeric Display */ +/* 15-1f Reserved */ +/**** END of top level pages */ +/* 25-3f Reserved */ +#define HID_USAGE_PAGE_MEDICAL uint16_t (0x40) /* Medical Instruments */ +/* 41-7F Reserved */ +/*80-83 Monitor pages USB Device Class Definition for Monitor Devices + 84-87 Power pages USB Device Class Definition for Power Devices */ +/* 88-8B Reserved */ +#define HID_USAGE_PAGE_BARCODE uint16_t (0x8C) /* Bar Code Scanner page */ +#define HID_USAGE_PAGE_SCALE uint16_t (0x8D) /* Scale page */ +#define HID_USAGE_PAGE_MSR uint16_t (0x8E) /* Magnetic Stripe Reading (MSR) Devices */ +#define HID_USAGE_PAGE_POS uint16_t (0x8F) /* Reserved Point of Sale pages */ +#define HID_USAGE_PAGE_CAMERA_CTR uint16_t (0x90) /* Camera Control Page */ +#define HID_USAGE_PAGE_ARCADE uint16_t (0x91) /* Arcade Page */ + +/****************************************************/ +/* Usage definitions for the "Generic Desktop" page */ +/****************************************************/ +#define HID_USAGE_UNDEFINED uint16_t (0x00) /* Undefined */ +#define HID_USAGE_POINTER uint16_t (0x01) /* Pointer (Physical Collection) */ +#define HID_USAGE_MOUSE uint16_t (0x02) /* Mouse (Application Collection) */ +/* 03 Reserved */ +#define HID_USAGE_JOYSTICK uint16_t (0x04) /* Joystick (Application Collection) */ +#define HID_USAGE_GAMEPAD uint16_t (0x05) /* Game Pad (Application Collection) */ +#define HID_USAGE_KBD uint16_t (0x06) /* Keyboard (Application Collection) */ +#define HID_USAGE_KEYPAD uint16_t (0x07) /* Keypad (Application Collection) */ +#define HID_USAGE_MAX_CTR uint16_t (0x08) /* Multi-axis Controller (Application Collection) */ +/* 09-2F Reserved */ +#define HID_USAGE_X uint16_t (0x30) /* X (Dynamic Value) */ +#define HID_USAGE_Y uint16_t (0x31) /* Y (Dynamic Value) */ +#define HID_USAGE_Z uint16_t (0x32) /* Z (Dynamic Value) */ +#define HID_USAGE_RX uint16_t (0x33) /* Rx (Dynamic Value) */ +#define HID_USAGE_RY uint16_t (0x34) /* Ry (Dynamic Value) */ +#define HID_USAGE_RZ uint16_t (0x35) /* Rz (Dynamic Value) */ +#define HID_USAGE_SLIDER uint16_t (0x36) /* Slider (Dynamic Value) */ +#define HID_USAGE_DIAL uint16_t (0x37) /* Dial (Dynamic Value) */ +#define HID_USAGE_WHEEL uint16_t (0x38) /* Wheel (Dynamic Value) */ +#define HID_USAGE_HATSW uint16_t (0x39) /* Hat switch (Dynamic Value) */ +#define HID_USAGE_COUNTEDBUF uint16_t (0x3A) /* Counted Buffer (Logical Collection) */ +#define HID_USAGE_BYTECOUNT uint16_t (0x3B) /* Byte Count (Dynamic Value) */ +#define HID_USAGE_MOTIONWAKE uint16_t (0x3C) /* Motion Wakeup (One Shot Control) */ +#define HID_USAGE_START uint16_t (0x3D) /* Start (On/Off Control) */ +#define HID_USAGE_SELECT uint16_t (0x3E) /* Select (On/Off Control) */ +/* 3F Reserved */ +#define HID_USAGE_VX uint16_t (0x40) /* Vx (Dynamic Value) */ +#define HID_USAGE_VY uint16_t (0x41) /* Vy (Dynamic Value) */ +#define HID_USAGE_VZ uint16_t (0x42) /* Vz (Dynamic Value) */ +#define HID_USAGE_VBRX uint16_t (0x43) /* Vbrx (Dynamic Value) */ +#define HID_USAGE_VBRY uint16_t (0x44) /* Vbry (Dynamic Value) */ +#define HID_USAGE_VBRZ uint16_t (0x45) /* Vbrz (Dynamic Value) */ +#define HID_USAGE_VNO uint16_t (0x46) /* Vno (Dynamic Value) */ +#define HID_USAGE_FEATNOTIF uint16_t (0x47) /* Feature Notification (Dynamic Value),(Dynamic Flag) */ +/* 48-7F Reserved */ +#define HID_USAGE_SYSCTL uint16_t (0x80) /* System Control (Application Collection) */ +#define HID_USAGE_PWDOWN uint16_t (0x81) /* System Power Down (One Shot Control) */ +#define HID_USAGE_SLEEP uint16_t (0x82) /* System Sleep (One Shot Control) */ +#define HID_USAGE_WAKEUP uint16_t (0x83) /* System Wake Up (One Shot Control) */ +#define HID_USAGE_CONTEXTM uint16_t (0x84) /* System Context Menu (One Shot Control) */ +#define HID_USAGE_MAINM uint16_t (0x85) /* System Main Menu (One Shot Control) */ +#define HID_USAGE_APPM uint16_t (0x86) /* System App Menu (One Shot Control) */ +#define HID_USAGE_MENUHELP uint16_t (0x87) /* System Menu Help (One Shot Control) */ +#define HID_USAGE_MENUEXIT uint16_t (0x88) /* System Menu Exit (One Shot Control) */ +#define HID_USAGE_MENUSELECT uint16_t (0x89) /* System Menu Select (One Shot Control) */ +#define HID_USAGE_SYSM_RIGHT uint16_t (0x8A) /* System Menu Right (Re-Trigger Control) */ +#define HID_USAGE_SYSM_LEFT uint16_t (0x8B) /* System Menu Left (Re-Trigger Control) */ +#define HID_USAGE_SYSM_UP uint16_t (0x8C) /* System Menu Up (Re-Trigger Control) */ +#define HID_USAGE_SYSM_DOWN uint16_t (0x8D) /* System Menu Down (Re-Trigger Control) */ +#define HID_USAGE_COLDRESET uint16_t (0x8E) /* System Cold Restart (One Shot Control) */ +#define HID_USAGE_WARMRESET uint16_t (0x8F) /* System Warm Restart (One Shot Control) */ +#define HID_USAGE_DUP uint16_t (0x90) /* D-pad Up (On/Off Control) */ +#define HID_USAGE_DDOWN uint16_t (0x91) /* D-pad Down (On/Off Control) */ +#define HID_USAGE_DRIGHT uint16_t (0x92) /* D-pad Right (On/Off Control) */ +#define HID_USAGE_DLEFT uint16_t (0x93) /* D-pad Left (On/Off Control) */ +/* 94-9F Reserved */ +#define HID_USAGE_SYS_DOCK uint16_t (0xA0) /* System Dock (One Shot Control) */ +#define HID_USAGE_SYS_UNDOCK uint16_t (0xA1) /* System Undock (One Shot Control) */ +#define HID_USAGE_SYS_SETUP uint16_t (0xA2) /* System Setup (One Shot Control) */ +#define HID_USAGE_SYS_BREAK uint16_t (0xA3) /* System Break (One Shot Control) */ +#define HID_USAGE_SYS_DBGBRK uint16_t (0xA4) /* System Debugger Break (One Shot Control) */ +#define HID_USAGE_APP_BRK uint16_t (0xA5) /* Application Break (One Shot Control) */ +#define HID_USAGE_APP_DBGBRK uint16_t (0xA6) /* Application Debugger Break (One Shot Control) */ +#define HID_USAGE_SYS_SPKMUTE uint16_t (0xA7) /* System Speaker Mute (One Shot Control) */ +#define HID_USAGE_SYS_HIBERN uint16_t (0xA8) /* System Hibernate (One Shot Control) */ +/* A9-AF Reserved */ +#define HID_USAGE_SYS_SIDPINV uint16_t (0xB0) /* System Display Invert (One Shot Control) */ +#define HID_USAGE_SYS_DISPINT uint16_t (0xB1) /* System Display Internal (One Shot Control) */ +#define HID_USAGE_SYS_DISPEXT uint16_t (0xB2) /* System Display External (One Shot Control) */ +#define HID_USAGE_SYS_DISPBOTH uint16_t (0xB3) /* System Display Both (One Shot Control) */ +#define HID_USAGE_SYS_DISPDUAL uint16_t (0xB4) /* System Display Dual (One Shot Control) */ +#define HID_USAGE_SYS_DISPTGLIE uint16_t (0xB5) /* System Display Toggle Int/Ext (One Shot Control) */ +#define HID_USAGE_SYS_DISP_SWAP uint16_t (0xB6) /* System Display Swap Primary/Secondary (One Shot Control) */ +#define HID_USAGE_SYS_DIPS_LCDA uint16_t (0xB7) /* System Display LCD Autoscale (One Shot Control) */ +/* B8-FFFF Reserved */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USDH_HID_USAGE_H */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_keybd.c b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_keybd.c new file mode 100644 index 0000000..624f24a --- /dev/null +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_keybd.c @@ -0,0 +1,418 @@ +/** + ****************************************************************************** + * @file usbh_hid_keybd.c + * @author MCD Application Team + * @version V3.2.2 + * @date 07-July-2015 + * @brief This file is the application layer for USB Host HID Keyboard handling + * QWERTY and AZERTY Keyboard are supported as per the selection in + * usbh_hid_keybd.h + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2015 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + + +/* Includes ------------------------------------------------------------------*/ +#include "usbh_hid_keybd.h" +#include "usbh_hid_parser.h" + +/** @addtogroup USBH_LIB +* @{ +*/ + +/** @addtogroup USBH_CLASS +* @{ +*/ + +/** @addtogroup USBH_HID_CLASS +* @{ +*/ + +/** @defgroup USBH_HID_KEYBD +* @brief This file includes HID Layer Handlers for USB Host HID class. +* @{ +*/ + +/** @defgroup USBH_HID_KEYBD_Private_TypesDefinitions +* @{ +*/ +/** +* @} +*/ + + +/** @defgroup USBH_HID_KEYBD_Private_Defines +* @{ +*/ +/** +* @} +*/ +#ifndef AZERTY_KEYBOARD + #define QWERTY_KEYBOARD +#endif +#define KBD_LEFT_CTRL 0x01 +#define KBD_LEFT_SHIFT 0x02 +#define KBD_LEFT_ALT 0x04 +#define KBD_LEFT_GUI 0x08 +#define KBD_RIGHT_CTRL 0x10 +#define KBD_RIGHT_SHIFT 0x20 +#define KBD_RIGHT_ALT 0x40 +#define KBD_RIGHT_GUI 0x80 +#define KBR_MAX_NBR_PRESSED 6 + +/** @defgroup USBH_HID_KEYBD_Private_Macros +* @{ +*/ +/** +* @} +*/ + +/** @defgroup USBH_HID_KEYBD_Private_FunctionPrototypes +* @{ +*/ +static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost); +/** +* @} +*/ + +/** @defgroup USBH_HID_KEYBD_Private_Variables +* @{ +*/ + +HID_KEYBD_Info_TypeDef keybd_info; +uint32_t keybd_report_data[2]; + +static const HID_Report_ItemTypedef imp_0_lctrl={ + (uint8_t*)keybd_report_data+0, /*data*/ + 1, /*size*/ + 0, /*shift*/ + 0, /*count (only for array items)*/ + 0, /*signed?*/ + 0, /*min value read can return*/ + 1, /*max value read can return*/ + 0, /*min vale device can report*/ + 1, /*max value device can report*/ + 1 /*resolution*/ +}; +static const HID_Report_ItemTypedef imp_0_lshift={ + (uint8_t*)keybd_report_data+0, /*data*/ + 1, /*size*/ + 1, /*shift*/ + 0, /*count (only for array items)*/ + 0, /*signed?*/ + 0, /*min value read can return*/ + 1, /*max value read can return*/ + 0, /*min vale device can report*/ + 1, /*max value device can report*/ + 1 /*resolution*/ +}; +static const HID_Report_ItemTypedef imp_0_lalt={ + (uint8_t*)keybd_report_data+0, /*data*/ + 1, /*size*/ + 2, /*shift*/ + 0, /*count (only for array items)*/ + 0, /*signed?*/ + 0, /*min value read can return*/ + 1, /*max value read can return*/ + 0, /*min vale device can report*/ + 1, /*max value device can report*/ + 1 /*resolution*/ +}; +static const HID_Report_ItemTypedef imp_0_lgui={ + (uint8_t*)keybd_report_data+0, /*data*/ + 1, /*size*/ + 3, /*shift*/ + 0, /*count (only for array items)*/ + 0, /*signed?*/ + 0, /*min value read can return*/ + 1, /*max value read can return*/ + 0, /*min vale device can report*/ + 1, /*max value device can report*/ + 1 /*resolution*/ +}; +static const HID_Report_ItemTypedef imp_0_rctrl={ + (uint8_t*)keybd_report_data+0, /*data*/ + 1, /*size*/ + 4, /*shift*/ + 0, /*count (only for array items)*/ + 0, /*signed?*/ + 0, /*min value read can return*/ + 1, /*max value read can return*/ + 0, /*min vale device can report*/ + 1, /*max value device can report*/ + 1 /*resolution*/ +}; +static const HID_Report_ItemTypedef imp_0_rshift={ + (uint8_t*)keybd_report_data+0, /*data*/ + 1, /*size*/ + 5, /*shift*/ + 0, /*count (only for array items)*/ + 0, /*signed?*/ + 0, /*min value read can return*/ + 1, /*max value read can return*/ + 0, /*min vale device can report*/ + 1, /*max value device can report*/ + 1 /*resolution*/ +}; +static const HID_Report_ItemTypedef imp_0_ralt={ + (uint8_t*)keybd_report_data+0, /*data*/ + 1, /*size*/ + 6, /*shift*/ + 0, /*count (only for array items)*/ + 0, /*signed?*/ + 0, /*min value read can return*/ + 1, /*max value read can return*/ + 0, /*min vale device can report*/ + 1, /*max value device can report*/ + 1 /*resolution*/ +}; +static const HID_Report_ItemTypedef imp_0_rgui={ + (uint8_t*)keybd_report_data+0, /*data*/ + 1, /*size*/ + 7, /*shift*/ + 0, /*count (only for array items)*/ + 0, /*signed?*/ + 0, /*min value read can return*/ + 1, /*max value read can return*/ + 0, /*min vale device can report*/ + 1, /*max value device can report*/ + 1 /*resolution*/ +}; + +static const HID_Report_ItemTypedef imp_0_key_array={ + (uint8_t*)keybd_report_data+2, /*data*/ + 8, /*size*/ + 0, /*shift*/ + 6, /*count (only for array items)*/ + 0, /*signed?*/ + 0, /*min value read can return*/ + 101, /*max value read can return*/ + 0, /*min vale device can report*/ + 101, /*max value device can report*/ + 1 /*resolution*/ +}; + +#ifdef QWERTY_KEYBOARD +static const int8_t HID_KEYBRD_Key[] = { + '\0', '`', '1', '2', '3', '4', '5', '6', + '7', '8', '9', '0', '-', '=', '\0', '\r', + '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', + 'i', 'o', 'p', '[', ']', '\\', + '\0', 'a', 's', 'd', 'f', 'g', 'h', 'j', + 'k', 'l', ';', '\'', '\0', '\n', + '\0', '\0', 'z', 'x', 'c', 'v', 'b', 'n', + 'm', ',', '.', '/', '\0', '\0', + '\0', '\0', '\0', ' ', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\r', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '7', '4', '1', + '\0', '/', '8', '5', '2', + '0', '*', '9', '6', '3', + '.', '-', '+', '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0' +}; + +static const int8_t HID_KEYBRD_ShiftKey[] = { + '\0', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', + '_', '+', '\0', '\0', '\0', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', + 'I', 'O', 'P', '{', '}', '|', '\0', 'A', 'S', 'D', 'F', 'G', + 'H', 'J', 'K', 'L', ':', '"', '\0', '\n', '\0', '\0', 'Z', 'X', + 'C', 'V', 'B', 'N', 'M', '<', '>', '?', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' +}; + +#else + +static const int8_t HID_KEYBRD_Key[] = { + '\0', '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', + '-', '=', '\0', '\r', '\t', 'a', 'z', 'e', 'r', 't', 'y', 'u', + 'i', 'o', 'p', '[', ']', '\\', '\0', 'q', 's', 'd', 'f', 'g', + 'h', 'j', 'k', 'l', 'm', '\0', '\0', '\n', '\0', '\0', 'w', 'x', + 'c', 'v', 'b', 'n', ',', ';', ':', '!', '\0', '\0', '\0', '\0', + '\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\r', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '7', '4', '1','\0', '/', + '8', '5', '2', '0', '*', '9', '6', '3', '.', '-', '+', '\0', + '\n', '\0', '\0', '\0', '\0', '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' +}; + +static const int8_t HID_KEYBRD_ShiftKey[] = { + '\0', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', + '+', '\0', '\0', '\0', 'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', + 'P', '{', '}', '*', '\0', 'Q', 'S', 'D', 'F', 'G', 'H', 'J', 'K', + 'L', 'M', '%', '\0', '\n', '\0', '\0', 'W', 'X', 'C', 'V', 'B', 'N', + '?', '.', '/', '\0', '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' +}; +#endif + +static const uint8_t HID_KEYBRD_Codes[] = { + 0, 0, 0, 0, 31, 50, 48, 33, + 19, 34, 35, 36, 24, 37, 38, 39, /* 0x00 - 0x0F */ + 52, 51, 25, 26, 17, 20, 32, 21, + 23, 49, 18, 47, 22, 46, 2, 3, /* 0x10 - 0x1F */ + 4, 5, 6, 7, 8, 9, 10, 11, + 43, 110, 15, 16, 61, 12, 13, 27, /* 0x20 - 0x2F */ + 28, 29, 42, 40, 41, 1, 53, 54, + 55, 30, 112, 113, 114, 115, 116, 117, /* 0x30 - 0x3F */ + 118, 119, 120, 121, 122, 123, 124, 125, + 126, 75, 80, 85, 76, 81, 86, 89, /* 0x40 - 0x4F */ + 79, 84, 83, 90, 95, 100, 105, 106, + 108, 93, 98, 103, 92, 97, 102, 91, /* 0x50 - 0x5F */ + 96, 101, 99, 104, 45, 129, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x6F */ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x7F */ + 0, 0, 0, 0, 0, 107, 0, 56, + 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 - 0x8F */ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 - 0x9F */ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* 0xA0 - 0xAF */ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* 0xB0 - 0xBF */ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* 0xC0 - 0xCF */ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* 0xD0 - 0xDF */ + 58, 44, 60, 127, 64, 57, 62, 128 /* 0xE0 - 0xE7 */ +}; + +/** + * @brief USBH_HID_KeybdInit + * The function init the HID keyboard. + * @param phost: Host handle + * @retval USBH Status + */ +USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost) +{ + uint32_t x; + HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; + + keybd_info.lctrl=keybd_info.lshift= 0; + keybd_info.lalt=keybd_info.lgui= 0; + keybd_info.rctrl=keybd_info.rshift= 0; + keybd_info.ralt=keybd_info.rgui=0; + + + for(x=0; x< (sizeof(keybd_report_data)/sizeof(uint32_t)); x++) + { + keybd_report_data[x]=0; + } + + if(HID_Handle->length > (sizeof(keybd_report_data)/sizeof(uint32_t))) + { + HID_Handle->length = (sizeof(keybd_report_data)/sizeof(uint32_t)); + } + HID_Handle->pData = (uint8_t*)keybd_report_data; + fifo_init(&HID_Handle->fifo, phost->device.Data, HID_QUEUE_SIZE * sizeof(keybd_report_data)); + + return USBH_OK; +} + +/** + * @brief USBH_HID_GetKeybdInfo + * The function return keyboard information. + * @param phost: Host handle + * @retval keyboard information + */ +HID_KEYBD_Info_TypeDef *USBH_HID_GetKeybdInfo(USBH_HandleTypeDef *phost) +{ + if(USBH_HID_KeybdDecode(phost) == USBH_OK) + { + return &keybd_info; + } + else + { + return NULL; + } +} + +/** + * @brief USBH_HID_KeybdDecode + * The function decode keyboard data. + * @param phost: Host handle + * @retval USBH Status + */ +static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost) +{ + uint8_t x; + + HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; + if(HID_Handle->length == 0) + { + return USBH_FAIL; + } + /*Fill report */ + if(fifo_read(&HID_Handle->fifo, &keybd_report_data, HID_Handle->length) == HID_Handle->length) + { + + keybd_info.lctrl=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lctrl, 0); + keybd_info.lshift=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lshift, 0); + keybd_info.lalt=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lalt, 0); + keybd_info.lgui=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lgui, 0); + keybd_info.rctrl=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rctrl, 0); + keybd_info.rshift=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rshift, 0); + keybd_info.ralt=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_ralt, 0); + keybd_info.rgui=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rgui, 0); + + for(x=0; x < sizeof(keybd_info.keys); x++) + { + keybd_info.keys[x]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_key_array, x); + } + + return USBH_OK; + } + return USBH_FAIL; +} + +/** + * @brief USBH_HID_GetASCIICode + * The function decode keyboard data into ASCII characters. + * @param phost: Host handle + * @param info: Keyboard information + * @retval ASCII code + */ +uint8_t USBH_HID_GetASCIICode(HID_KEYBD_Info_TypeDef *info) +{ + uint8_t output; + if((info->lshift == 1) || (info->rshift)) + { + output = HID_KEYBRD_ShiftKey[HID_KEYBRD_Codes[info->keys[0]]]; + } + else + { + output = HID_KEYBRD_Key[HID_KEYBRD_Codes[info->keys[0]]]; + } + return output; +} +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_mouse.c b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_mouse.c new file mode 100644 index 0000000..862fcda --- /dev/null +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_mouse.c @@ -0,0 +1,267 @@ +/** + ****************************************************************************** + * @file usbh_hid_mouse.c + * @author MCD Application Team + * @version V3.2.2 + * @date 07-July-2015 + * @brief This file is the application layer for USB Host HID Mouse Handling. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2015 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "usbh_hid_mouse.h" +#include "usbh_hid_parser.h" + + +/** @addtogroup USBH_LIB + * @{ + */ + +/** @addtogroup USBH_CLASS + * @{ + */ + +/** @addtogroup USBH_HID_CLASS + * @{ + */ + +/** @defgroup USBH_HID_MOUSE + * @brief This file includes HID Layer Handlers for USB Host HID class. + * @{ + */ + +/** @defgroup USBH_HID_MOUSE_Private_TypesDefinitions + * @{ + */ +/** + * @} + */ + + +/** @defgroup USBH_HID_MOUSE_Private_Defines + * @{ + */ +/** + * @} + */ + + +/** @defgroup USBH_HID_MOUSE_Private_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup USBH_HID_MOUSE_Private_FunctionPrototypes + * @{ + */ +static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost); + +/** + * @} + */ + + +/** @defgroup USBH_HID_MOUSE_Private_Variables + * @{ + */ +HID_MOUSE_Info_TypeDef mouse_info; +uint32_t mouse_report_data[1]; + +/* Structures defining how to access items in a HID mouse report */ +/* Access button 1 state. */ +static const HID_Report_ItemTypedef prop_b1={ + (uint8_t *)mouse_report_data+0, /*data*/ + 1, /*size*/ + 0, /*shift*/ + 0, /*count (only for array items)*/ + 0, /*signed?*/ + 0, /*min value read can return*/ + 1, /*max value read can return*/ + 0, /*min value device can report*/ + 1, /*max value device can report*/ + 1 /*resolution*/ +}; + +/* Access button 2 state. */ +static const HID_Report_ItemTypedef prop_b2={ + (uint8_t *)mouse_report_data+0, /*data*/ + 1, /*size*/ + 1, /*shift*/ + 0, /*count (only for array items)*/ + 0, /*signed?*/ + 0, /*min value read can return*/ + 1, /*max value read can return*/ + 0, /*min value device can report*/ + 1, /*max value device can report*/ + 1 /*resolution*/ +}; + +/* Access button 3 state. */ +static const HID_Report_ItemTypedef prop_b3={ + (uint8_t *)mouse_report_data+0, /*data*/ + 1, /*size*/ + 2, /*shift*/ + 0, /*count (only for array items)*/ + 0, /*signed?*/ + 0, /*min value read can return*/ + 1, /*max value read can return*/ + 0, /*min vale device can report*/ + 1, /*max value device can report*/ + 1 /*resolution*/ +}; + +/* Access x coordinate change. */ +static const HID_Report_ItemTypedef prop_x={ + (uint8_t *)mouse_report_data+1, /*data*/ + 8, /*size*/ + 0, /*shift*/ + 0, /*count (only for array items)*/ + 1, /*signed?*/ + 0, /*min value read can return*/ + 0xFFFF,/*max value read can return*/ + 0, /*min vale device can report*/ + 0xFFFF,/*max value device can report*/ + 1 /*resolution*/ +}; + +/* Access y coordinate change. */ +static const HID_Report_ItemTypedef prop_y={ + (uint8_t *)mouse_report_data+2, /*data*/ + 8, /*size*/ + 0, /*shift*/ + 0, /*count (only for array items)*/ + 1, /*signed?*/ + 0, /*min value read can return*/ + 0xFFFF,/*max value read can return*/ + 0, /*min vale device can report*/ + 0xFFFF,/*max value device can report*/ + 1 /*resolution*/ +}; + + +/** + * @} + */ + + +/** @defgroup USBH_HID_MOUSE_Private_Functions + * @{ + */ + +/** + * @brief USBH_HID_MouseInit + * The function init the HID mouse. + * @param phost: Host handle + * @retval USBH Status + */ +USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost) +{ + HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; + + mouse_info.x=0; + mouse_info.y=0; + mouse_info.buttons[0]=0; + mouse_info.buttons[1]=0; + mouse_info.buttons[2]=0; + + mouse_report_data[0]=0; + + if(HID_Handle->length > sizeof(mouse_report_data)) + { + HID_Handle->length = sizeof(mouse_report_data); + } + HID_Handle->pData = (uint8_t *)mouse_report_data; + fifo_init(&HID_Handle->fifo, phost->device.Data, HID_QUEUE_SIZE * sizeof(mouse_report_data)); + + return USBH_OK; +} + +/** + * @brief USBH_HID_GetMouseInfo + * The function return mouse information. + * @param phost: Host handle + * @retval mouse information + */ +HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost) +{ + if(USBH_HID_MouseDecode(phost)== USBH_OK) + { + return &mouse_info; + } + else + { + return NULL; + } +} + +/** + * @brief USBH_HID_MouseDecode + * The function decode mouse data. + * @param phost: Host handle + * @retval USBH Status + */ +static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost) +{ + HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; + + if(HID_Handle->length == 0) + { + return USBH_FAIL; + } + /*Fill report */ + if(fifo_read(&HID_Handle->fifo, &mouse_report_data, HID_Handle->length) == HID_Handle->length) + { + + /*Decode report */ + mouse_info.x = (int16_t )HID_ReadItem((HID_Report_ItemTypedef *) &prop_x, 0); + mouse_info.y = (int16_t )HID_ReadItem((HID_Report_ItemTypedef *) &prop_y, 0); + + mouse_info.buttons[0]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b1, 0); + mouse_info.buttons[1]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b2, 0); + mouse_info.buttons[2]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b3, 0); + + return USBH_OK; + } + return USBH_FAIL; +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + + +/** + * @} + */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_parser.c b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_parser.c new file mode 100644 index 0000000..5b0762d --- /dev/null +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_parser.c @@ -0,0 +1,235 @@ +/** + ****************************************************************************** + * @file usbh_hid_parser.c + * @author MCD Application Team + * @version V3.2.2 + * @date 07-July-2015 + * @brief This file is the HID Layer Handlers for USB Host HID class. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2015 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ +/* Includes ------------------------------------------------------------------*/ +#include "usbh_hid_parser.h" + + +/** @addtogroup USBH_LIB + * @{ + */ + +/** @addtogroup USBH_CLASS + * @{ + */ + +/** @addtogroup USBH_HID_CLASS + * @{ + */ + +/** @defgroup USBH_HID_PARSER + * @brief This file includes HID parsers for USB Host HID class. + * @{ + */ + +/** @defgroup USBH_HID_PARSER_Private_TypesDefinitions + * @{ + */ +/** + * @} + */ + + +/** @defgroup USBH_HID_PARSER_Private_Defines + * @{ + */ +/** + * @} + */ + + +/** @defgroup USBH_HID_PARSER_Private_Macros + * @{ + */ +/** + * @} + */ + +/** @defgroup USBH_HID_PARSER_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + + +/** @defgroup USBH_HID_PARSER_Private_Variables + * @{ + */ + +/** + * @} + */ + + +/** @defgroup USBH_HID_PARSER_Private_Functions + * @{ + */ + +/** + * @brief HID_ReadItem + * The function read a report item. + * @param ri: report item + * @param ndx: report index +* @retval status (0 : fail / otherwise: item value) + */ +uint32_t HID_ReadItem(HID_Report_ItemTypedef *ri, uint8_t ndx) +{ + uint32_t val=0; + uint32_t x=0; + uint32_t bofs; + uint8_t *data=ri->data; + uint8_t shift=ri->shift; + + /* get the logical value of the item */ + + /* if this is an array, wee may need to offset ri->data.*/ + if (ri->count > 0) + { + /* If app tries to read outside of the array. */ + if (ri->count <= ndx) + { + return(0); + } + + /* calculate bit offset */ + bofs = ndx*ri->size; + bofs += shift; + /* calculate byte offset + shift pair from bit offset. */ + data+=bofs/8; + shift=(uint8_t)(bofs%8); + } + /* read data bytes in little endian order */ + for(x=0; x < ((ri->size & 0x7) ? (ri->size/8)+1 : (ri->size/8)); x++) + { + val=(uint32_t)(*data << (x*8)); + } + val=(val >> shift) & ((1<size)-1); + + if (val < ri->logical_min || val > ri->logical_max) + { + return(0); + } + + /* convert logical value to physical value */ + /* See if the number is negative or not. */ + if ((ri->sign) && (val & (1<<(ri->size-1)))) + { + /* yes, so sign extend value to 32 bits. */ + int vs=(int)((-1 & ~((1<<(ri->size))-1)) | val); + + if(ri->resolution == 1) + { + return((uint32_t)vs); + } + return((uint32_t)(vs*ri->resolution)); + } + else + { + if(ri->resolution == 1) + { + return(val); + } + return(val*ri->resolution); + } +} + +/** + * @brief HID_WriteItem + * The function write a report item. + * @param ri: report item + * @param ndx: report index + * @retval status (1: fail/ 0 : Ok) + */ +uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx) +{ + uint32_t x; + uint32_t mask; + uint32_t bofs; + uint8_t *data=ri->data; + uint8_t shift=ri->shift; + + if (value < ri->physical_min || value > ri->physical_max) + { + return(1); + } + + /* if this is an array, wee may need to offset ri->data.*/ + if (ri->count > 0) + { + /* If app tries to read outside of the array. */ + if (ri->count >= ndx) + { + return(0); + } + /* calculate bit offset */ + bofs = ndx*ri->size; + bofs += shift; + /* calculate byte offset + shift pair from bit offset. */ + data+=bofs/8; + shift=(uint8_t)(bofs%8); + + } + + /* Convert physical value to logical value. */ + if (ri->resolution != 1) + { + value=value/ri->resolution; + } + + /* Write logical value to report in little endian order. */ + mask=(uint32_t)((1<size)-1); + value = (value & mask) << shift; + + for(x=0; x < ((ri->size & 0x7) ? (ri->size/8)+1 : (ri->size/8)); x++) + { + *(ri->data+x)=(uint8_t)((*(ri->data+x) & ~(mask>>(x*8))) | ((value>>(x*8)) & (mask>>(x*8)))); + } + return(0); +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + + +/** + * @} + */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/