├── HID_template ├── MDK-ARM │ ├── .vscode │ │ ├── uv4.log.lock │ │ ├── uv4.log │ │ ├── settings.json │ │ ├── c_cpp_properties.json │ │ └── keil-assistant.log │ ├── EventRecorderStub.scvd │ ├── RTE │ │ └── _HID_template │ │ │ └── RTE_Components.h │ ├── readme.md │ └── DebugConfig │ │ └── HID_template_STM32F103C6_1.0.0.dbgconf ├── hid_dev │ ├── mouse.h │ ├── psk_hid.c │ ├── keyboard.h │ ├── touch_screen.h │ ├── psk_hid.h │ ├── custom_control.h │ ├── custom_control.c │ ├── touch_screen.c │ └── mouse.c ├── back_up base on custom │ ├── hid_dev │ │ ├── mouse.h │ │ ├── psk_hid.c │ │ ├── keyboard.h │ │ ├── touch_screen.h │ │ ├── hid │ │ │ ├── usage_sensor.h │ │ │ ├── usage_button.h │ │ │ ├── usage_ordinal.h │ │ │ ├── usage_device.h │ │ │ ├── usage_desktop.h │ │ │ ├── usage_telephony.h │ │ │ ├── usage_aux_display.h │ │ │ ├── mouse.h │ │ │ ├── usage_led.h │ │ │ ├── usage_keyboard.h │ │ │ ├── keyboard.h │ │ │ ├── usage_lighting.h │ │ │ ├── usage_consumer.h │ │ │ └── usage_power.h │ │ ├── psk_hid.h │ │ ├── custom_control.h │ │ ├── custom_control.c │ │ ├── touch_screen.c │ │ └── mouse.c │ ├── Middlewares │ │ └── ST │ │ │ └── STM32_USB_Device_Library │ │ │ ├── Core │ │ │ ├── Inc │ │ │ │ ├── usbd_ctlreq.h │ │ │ │ ├── usbd_ioreq.h │ │ │ │ └── usbd_core.h │ │ │ └── Src │ │ │ │ └── usbd_ioreq.c │ │ │ └── Class │ │ │ └── CustomHID │ │ │ └── Inc │ │ │ └── usbd_customhid.h │ └── USB_DEVICE │ │ ├── App │ │ ├── usb_device.h │ │ ├── usb_device.c │ │ ├── usbd_custom_hid_if.h │ │ └── usbd_desc.h │ │ └── Target │ │ └── usbd_conf.h ├── Drivers │ ├── CMSIS │ │ ├── Device │ │ │ └── ST │ │ │ │ └── STM32F1xx │ │ │ │ └── Include │ │ │ │ ├── stm32f103x6.h │ │ │ │ ├── stm32f1xx.h │ │ │ │ └── system_stm32f1xx.h │ │ └── Include │ │ │ ├── cmsis_version.h │ │ │ └── tz_context.h │ └── STM32F1xx_HAL_Driver │ │ ├── License.md │ │ ├── Inc │ │ └── stm32f1xx_hal_pcd_ex.h │ │ └── Src │ │ └── stm32f1xx_hal_gpio_ex.c ├── Core │ ├── Inc │ │ ├── tim.h │ │ ├── gpio.h │ │ ├── stm32_assert.h │ │ ├── stm32f1xx_it.h │ │ └── main.h │ └── Src │ │ ├── gpio.c │ │ ├── tim.c │ │ └── stm32f1xx_hal_msp.c ├── hardware │ ├── pid.h │ ├── pid.c │ └── lwrb.h ├── Middlewares │ └── ST │ │ └── STM32_USB_Device_Library │ │ ├── Core │ │ ├── Inc │ │ │ ├── usbd_ctlreq.h │ │ │ ├── usbd_ioreq.h │ │ │ └── usbd_core.h │ │ └── Src │ │ │ └── usbd_ioreq.c │ │ └── Class │ │ └── CustomHID │ │ └── Inc │ │ └── usbd_customhid.h ├── USB_DEVICE │ ├── App │ │ ├── usb_device.h │ │ ├── usb_device.c │ │ ├── usbd_custom_hid_if.h │ │ └── usbd_desc.h │ └── Target │ │ └── usbd_conf.h └── HID_template.ioc ├── .gitattributes ├── readme_pic └── Snipaste_2023-03-11_12-35-59.jpg ├── .gitignore └── LICENSE /HID_template/MDK-ARM/.vscode/uv4.log.lock: -------------------------------------------------------------------------------- 1 | 22/04/20 13:25:20 -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /HID_template/hid_dev/mouse.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PtilopsisSak/STM32F103C6T6-customHID/HEAD/HID_template/hid_dev/mouse.h -------------------------------------------------------------------------------- /HID_template/hid_dev/psk_hid.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PtilopsisSak/STM32F103C6T6-customHID/HEAD/HID_template/hid_dev/psk_hid.c -------------------------------------------------------------------------------- /HID_template/hid_dev/keyboard.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PtilopsisSak/STM32F103C6T6-customHID/HEAD/HID_template/hid_dev/keyboard.h -------------------------------------------------------------------------------- /HID_template/hid_dev/touch_screen.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PtilopsisSak/STM32F103C6T6-customHID/HEAD/HID_template/hid_dev/touch_screen.h -------------------------------------------------------------------------------- /readme_pic/Snipaste_2023-03-11_12-35-59.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PtilopsisSak/STM32F103C6T6-customHID/HEAD/readme_pic/Snipaste_2023-03-11_12-35-59.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | HID_template/MDK-ARM/.vscode/c_cpp_properties.json 3 | HID_template/MDK-ARM/.vscode/c_cpp_properties.json 4 | HID_template/MDK-ARM/.vscode/keil-assistant.log 5 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/mouse.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PtilopsisSak/STM32F103C6T6-customHID/HEAD/HID_template/back_up base on custom/hid_dev/mouse.h -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/psk_hid.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PtilopsisSak/STM32F103C6T6-customHID/HEAD/HID_template/back_up base on custom/hid_dev/psk_hid.c -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/keyboard.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PtilopsisSak/STM32F103C6T6-customHID/HEAD/HID_template/back_up base on custom/hid_dev/keyboard.h -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/touch_screen.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PtilopsisSak/STM32F103C6T6-customHID/HEAD/HID_template/back_up base on custom/hid_dev/touch_screen.h -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/usage_sensor.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PtilopsisSak/STM32F103C6T6-customHID/HEAD/HID_template/back_up base on custom/hid_dev/hid/usage_sensor.h -------------------------------------------------------------------------------- /HID_template/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103x6.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PtilopsisSak/STM32F103C6T6-customHID/HEAD/HID_template/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103x6.h -------------------------------------------------------------------------------- /HID_template/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PtilopsisSak/STM32F103C6T6-customHID/HEAD/HID_template/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h -------------------------------------------------------------------------------- /HID_template/MDK-ARM/.vscode/uv4.log: -------------------------------------------------------------------------------- 1 | *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\MDK5\ARM\ARMCC\Bin' 2 | Build target 'HID_template' 3 | "HID_template\HID_template.axf" - 0 Error(s), 0 Warning(s). 4 | Build Time Elapsed: 00:00:01 5 | -------------------------------------------------------------------------------- /HID_template/MDK-ARM/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "main.h": "c", 4 | "tim.h": "c", 5 | "usbd_custom_hid_if.h": "c", 6 | "keyboard.h": "c", 7 | "psk_hid.h": "c", 8 | "usbd_customhid.h": "c", 9 | "mouse.h": "c", 10 | "touch_screen.h": "c", 11 | "usb_device.h": "c", 12 | "usbd_def.h": "c" 13 | } 14 | } -------------------------------------------------------------------------------- /HID_template/MDK-ARM/EventRecorderStub.scvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/psk_hid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Ptisak 3 | * @Date: 2022-03-19 09:59:20 4 | * @LastEditors: Ptisak 5 | * @LastEditTime: 2022-04-20 14:06:27 6 | * @Description: file content 7 | */ 8 | #ifndef _PSK_HID 9 | #define _PSK_HID 10 | 11 | #include "main.h" 12 | #include "mouse.h" 13 | #include "keyboard.h" 14 | #include "touch_screen.h" 15 | #include "custom_control.h" 16 | #define SEND_DELAY 5 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /HID_template/MDK-ARM/RTE/_HID_template/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'HID_template' 7 | * Target: 'HID_template' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f10x.h" 18 | 19 | 20 | #endif /* RTE_COMPONENTS_H */ 21 | -------------------------------------------------------------------------------- /HID_template/hid_dev/psk_hid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Ptisak 3 | * @Date: 2022-03-19 09:59:20 4 | * @LastEditors: Ptisak 5 | * @LastEditTime: 2023-03-11 19:43:22 6 | * @Description: file content 7 | */ 8 | #ifndef _PSK_HID 9 | #define _PSK_HID 10 | 11 | #define SEND_DELAY 5 12 | 13 | #define KEYBOARD_WITH_LWRB 14 | #define MOUSE_USING_PID 15 | 16 | #include "main.h" 17 | 18 | void MY_USB_HID_SEND_REPORT(uint8_t *report, uint16_t len); 19 | 20 | #include "usbd_custom_hid_if.h" 21 | 22 | #include "mouse.h" 23 | #include "keyboard.h" 24 | #include "touch_screen.h" 25 | #include "custom_control.h" 26 | #endif 27 | -------------------------------------------------------------------------------- /HID_template/hid_dev/custom_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Ptisak 3 | * @Date: 2022-03-18 20:57:47 4 | * @LastEditors: Ptisak 5 | * @LastEditTime: 2022-04-19 16:15:18 6 | * @Description: file content 7 | */ 8 | #ifndef _CUSTOM_CONTROL_H 9 | #define _CUSTOM_CONTROL_H 10 | #include "main.h" 11 | #include "usbd_custom_hid_if.h" 12 | 13 | enum custom_key 14 | { 15 | VOL_UP, 16 | VOL_DOWN, 17 | MUTE, 18 | PAUSE_PLAY 19 | }; 20 | 21 | typedef struct 22 | { 23 | uint8_t report_id; //报告ID 24 | uint8_t special_key; 25 | //报文只发送前2个字节 26 | uint8_t key_reserve; 27 | int8_t special_key_release_times[8]; 28 | } custom_buff_t; 29 | 30 | extern custom_buff_t custom_buff; 31 | 32 | void send_custom_control_data(void); 33 | 34 | /** 35 | * @brief : 用户控制设备初始化 36 | */ 37 | void custom_init(void); 38 | /** 39 | * @brief : 添加按键, 见 enum custom_key 40 | * @note : custom_press_key(VOL_DOWN, -1); 41 | * @param {enum custom_key} k 42 | * @param {int8_t} times *SEND_DELAY ms后松开(异步), -1 一直按下 43 | */ 44 | void custom_press_key(enum custom_key k, int8_t times); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/custom_control.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Ptisak 3 | * @Date: 2022-03-18 20:57:47 4 | * @LastEditors: Ptisak 5 | * @LastEditTime: 2022-04-19 16:15:18 6 | * @Description: file content 7 | */ 8 | #ifndef _CUSTOM_CONTROL_H 9 | #define _CUSTOM_CONTROL_H 10 | #include "main.h" 11 | #include "usbd_custom_hid_if.h" 12 | 13 | enum custom_key 14 | { 15 | VOL_UP, 16 | VOL_DOWN, 17 | MUTE, 18 | PAUSE_PLAY 19 | }; 20 | 21 | typedef struct 22 | { 23 | uint8_t report_id; //报告ID 24 | uint8_t special_key; 25 | //报文只发送前2个字节 26 | uint8_t key_reserve; 27 | int8_t special_key_release_times[8]; 28 | } custom_buff_t; 29 | 30 | extern custom_buff_t custom_buff; 31 | 32 | void send_custom_control_data(void); 33 | 34 | /** 35 | * @brief : 用户控制设备初始化 36 | */ 37 | void custom_init(void); 38 | /** 39 | * @brief : 添加按键, 见 enum custom_key 40 | * @note : custom_press_key(VOL_DOWN, -1); 41 | * @param {enum custom_key} k 42 | * @param {int8_t} times *SEND_DELAY ms后松开(异步), -1 一直按下 43 | */ 44 | void custom_press_key(enum custom_key k, int8_t times); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 PtiSak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/usage_button.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usage_button.h 4 | * @author Benedek Kupper 5 | * @version 0.1 6 | * @date 2018-01-31 7 | * @brief USB Human Interface Device Class 8 | * Button Usage Page definitions 9 | * 10 | * Copyright (c) 2018 Benedek Kupper 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | #ifndef __HID_USAGE_BUTTON_H_ 25 | #define __HID_USAGE_BUTTON_H_ 26 | #include 27 | 28 | #define HID_USAGE_PAGE_BUTTON HID_ITEM_1(0x0, GLOBAL, 0x09) 29 | 30 | #define HID_USAGE_BUTTON(VAL) HID_USAGE_1(VAL) 31 | 32 | #endif /* __HID_USAGE_BUTTON_H_ */ 33 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/usage_ordinal.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usage_ordinal.h 4 | * @author Benedek Kupper 5 | * @version 0.1 6 | * @date 2020-04-02 7 | * @brief USB Human Interface Device Class 8 | * Ordinal Usage Page definitions 9 | * 10 | * Copyright (c) 2020 Benedek Kupper 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | #ifndef __HID_USAGE_ORDINAL_H_ 25 | #define __HID_USAGE_ORDINAL_H_ 26 | #include 27 | 28 | #define HID_USAGE_PAGE_ORDINAL HID_ITEM_1(0x0, GLOBAL, 0x0A) 29 | 30 | #define HID_USAGE_ORD_INST(VAL) HID_USAGE_1(VAL) 31 | 32 | #endif /* __HID_USAGE_ORDINAL_H_ */ 33 | -------------------------------------------------------------------------------- /HID_template/Core/Inc/tim.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file tim.h 5 | * @brief This file contains all the function prototypes for 6 | * the tim.c file 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __TIM_H__ 22 | #define __TIM_H__ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "main.h" 30 | 31 | /* USER CODE BEGIN Includes */ 32 | 33 | /* USER CODE END Includes */ 34 | 35 | /* USER CODE BEGIN Private defines */ 36 | 37 | /* USER CODE END Private defines */ 38 | 39 | void MX_TIM1_Init(void); 40 | 41 | /* USER CODE BEGIN Prototypes */ 42 | 43 | /* USER CODE END Prototypes */ 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* __TIM_H__ */ 50 | 51 | -------------------------------------------------------------------------------- /HID_template/Core/Inc/gpio.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file gpio.h 5 | * @brief This file contains all the function prototypes for 6 | * the gpio.c file 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __GPIO_H__ 22 | #define __GPIO_H__ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "main.h" 30 | 31 | /* USER CODE BEGIN Includes */ 32 | 33 | /* USER CODE END Includes */ 34 | 35 | /* USER CODE BEGIN Private defines */ 36 | 37 | /* USER CODE END Private defines */ 38 | 39 | void MX_GPIO_Init(void); 40 | 41 | /* USER CODE BEGIN Prototypes */ 42 | 43 | /* USER CODE END Prototypes */ 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | #endif /*__ GPIO_H__ */ 49 | 50 | -------------------------------------------------------------------------------- /HID_template/Drivers/STM32F1xx_HAL_Driver/License.md: -------------------------------------------------------------------------------- 1 | Copyright 2016(-2021) STMicroelectronics. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /HID_template/Core/Src/gpio.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file gpio.c 5 | * @brief This file provides code for the configuration 6 | * of all used GPIO pins. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "gpio.h" 23 | 24 | /* USER CODE BEGIN 0 */ 25 | 26 | /* USER CODE END 0 */ 27 | 28 | /*----------------------------------------------------------------------------*/ 29 | /* Configure GPIO */ 30 | /*----------------------------------------------------------------------------*/ 31 | /* USER CODE BEGIN 1 */ 32 | 33 | /* USER CODE END 1 */ 34 | 35 | /** Configure pins as 36 | * Analog 37 | * Input 38 | * Output 39 | * EVENT_OUT 40 | * EXTI 41 | */ 42 | void MX_GPIO_Init(void) 43 | { 44 | 45 | /* GPIO Ports Clock Enable */ 46 | LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOD); 47 | LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); 48 | 49 | } 50 | 51 | /* USER CODE BEGIN 2 */ 52 | 53 | /* USER CODE END 2 */ 54 | -------------------------------------------------------------------------------- /HID_template/hid_dev/custom_control.c: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Ptisak 3 | * @Date: 2022-03-18 20:57:47 4 | * @LastEditors: Ptisak 5 | * @LastEditTime: 2022-03-22 13:48:50 6 | * @Description: file content 7 | */ 8 | #include "custom_control.h" 9 | // #include "usbd_hid.h" 10 | 11 | custom_buff_t custom_buff; 12 | custom_buff_t custom_buff_last; 13 | 14 | void send_custom_control_data(void) 15 | { 16 | static uint8_t i; 17 | static uint8_t lastsend; 18 | if (memcmp(&custom_buff, &custom_buff_last, 2) == 0) 19 | { 20 | // equal 21 | if (lastsend){ 22 | lastsend--; 23 | USBD_CUSTOM_HID_SendReport_FS((uint8_t *)&custom_buff, 2u); 24 | } 25 | } 26 | else 27 | { 28 | memcpy(&custom_buff_last, &custom_buff, 2); 29 | USBD_CUSTOM_HID_SendReport_FS((uint8_t *)&custom_buff, 2u); 30 | lastsend = 0; 31 | } 32 | 33 | for (i = 0; i < 4; i++) 34 | { 35 | if (custom_buff.special_key_release_times[i] > 0) 36 | { 37 | custom_buff.special_key_release_times[i]--; 38 | } 39 | 40 | if (custom_buff.special_key_release_times[i] == 0) 41 | { 42 | custom_buff.special_key &= ~(0x01 << i); 43 | } 44 | else 45 | { 46 | custom_buff.special_key |= (0x01 << i); 47 | } 48 | } 49 | } 50 | 51 | void custom_init(void) 52 | { 53 | memset(&custom_buff, 0X00, sizeof(custom_buff)); 54 | memset(&custom_buff_last, 0X00, sizeof(custom_buff_last)); 55 | custom_buff.report_id = 0x05; 56 | } 57 | 58 | void custom_press_key(enum custom_key k, int8_t times) 59 | { 60 | if (times) 61 | { 62 | custom_buff.special_key |= (0x01 << k); 63 | } 64 | custom_buff.special_key_release_times[k] = times; 65 | return; 66 | } 67 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/custom_control.c: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Ptisak 3 | * @Date: 2022-03-18 20:57:47 4 | * @LastEditors: Ptisak 5 | * @LastEditTime: 2022-03-22 13:48:50 6 | * @Description: file content 7 | */ 8 | #include "custom_control.h" 9 | // #include "usbd_hid.h" 10 | 11 | custom_buff_t custom_buff; 12 | custom_buff_t custom_buff_last; 13 | 14 | void send_custom_control_data(void) 15 | { 16 | static uint8_t i; 17 | static uint8_t lastsend; 18 | if (memcmp(&custom_buff, &custom_buff_last, 2) == 0) 19 | { 20 | // equal 21 | if (lastsend){ 22 | lastsend--; 23 | USBD_CUSTOM_HID_SendReport_FS((uint8_t *)&custom_buff, 2u); 24 | } 25 | } 26 | else 27 | { 28 | memcpy(&custom_buff_last, &custom_buff, 2); 29 | USBD_CUSTOM_HID_SendReport_FS((uint8_t *)&custom_buff, 2u); 30 | lastsend = 0; 31 | } 32 | 33 | for (i = 0; i < 4; i++) 34 | { 35 | if (custom_buff.special_key_release_times[i] > 0) 36 | { 37 | custom_buff.special_key_release_times[i]--; 38 | } 39 | 40 | if (custom_buff.special_key_release_times[i] == 0) 41 | { 42 | custom_buff.special_key &= ~(0x01 << i); 43 | } 44 | else 45 | { 46 | custom_buff.special_key |= (0x01 << i); 47 | } 48 | } 49 | } 50 | 51 | void custom_init(void) 52 | { 53 | memset(&custom_buff, 0X00, sizeof(custom_buff)); 54 | memset(&custom_buff_last, 0X00, sizeof(custom_buff_last)); 55 | custom_buff.report_id = 0x05; 56 | } 57 | 58 | void custom_press_key(enum custom_key k, int8_t times) 59 | { 60 | if (times) 61 | { 62 | custom_buff.special_key |= (0x01 << k); 63 | } 64 | custom_buff.special_key_release_times[k] = times; 65 | return; 66 | } 67 | -------------------------------------------------------------------------------- /HID_template/Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/usage_device.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usage_device.h 4 | * @author Benedek Kupper 5 | * @version 0.1 6 | * @date 2020-04-02 7 | * @brief USB Human Interface Device Class 8 | * Generic Device Usage Page definitions 9 | * 10 | * Copyright (c) 2020 Benedek Kupper 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | #ifndef __HID_USAGE_DEVICE_H_ 25 | #define __HID_USAGE_DEVICE_H_ 26 | #include 27 | 28 | #define HID_USAGE_PAGE_DEVICE HID_ITEM_1(0x0, GLOBAL, 0x06) 29 | 30 | #define HID_USAGE_DEV_BKGND_CTRLS HID_USAGE_1(0x01) 31 | 32 | #define HID_USAGE_DEV_BATTERY_STR HID_USAGE_1(0x20) 33 | 34 | #define HID_USAGE_DEV_SW_VER HID_USAGE_1(0x2A) 35 | #define HID_USAGE_DEV_PROT_VER HID_USAGE_1(0x2B) 36 | #define HID_USAGE_DEV_HW_VER HID_USAGE_1(0x2C) 37 | #define HID_USAGE_DEV_MAJOR HID_USAGE_1(0x2D) 38 | #define HID_USAGE_DEV_MINOR HID_USAGE_1(0x2E) 39 | #define HID_USAGE_DEV_REVISION HID_USAGE_1(0x2F) 40 | 41 | #define HID_USAGE_DEV_HANDEDNESS HID_USAGE_1(0x30) 42 | #define HID_USAGE_DEV_HAND_EITHER HID_USAGE_1(0x31) 43 | #define HID_USAGE_DEV_HAND_LEFT HID_USAGE_1(0x32) 44 | #define HID_USAGE_DEV_HAND_RIGHT HID_USAGE_1(0x33) 45 | #define HID_USAGE_DEV_HAND_BOTH HID_USAGE_1(0x34) 46 | 47 | #endif /* __HID_USAGE_DEVICE_H_ */ 48 | -------------------------------------------------------------------------------- /HID_template/Core/Inc/stm32_assert.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32_assert.h 5 | * @brief STM32 assert file. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2018 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32_ASSERT_H 22 | #define __STM32_ASSERT_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Includes ------------------------------------------------------------------*/ 31 | /* Exported macro ------------------------------------------------------------*/ 32 | #ifdef USE_FULL_ASSERT 33 | /** 34 | * @brief The assert_param macro is used for function's parameters check. 35 | * @param expr: If expr is false, it calls assert_failed function 36 | * which reports the name of the source file and the source 37 | * line number of the call that failed. 38 | * If expr is true, it returns no value. 39 | * @retval None 40 | */ 41 | #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) 42 | /* Exported functions ------------------------------------------------------- */ 43 | void assert_failed(uint8_t* file, uint32_t line); 44 | #else 45 | #define assert_param(expr) ((void)0U) 46 | #endif /* USE_FULL_ASSERT */ 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* __STM32_ASSERT_H */ 53 | 54 | -------------------------------------------------------------------------------- /HID_template/Core/Src/tim.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file tim.c 5 | * @brief This file provides code for the configuration 6 | * of the TIM instances. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "tim.h" 22 | 23 | /* USER CODE BEGIN 0 */ 24 | 25 | /* USER CODE END 0 */ 26 | 27 | /* TIM1 init function */ 28 | void MX_TIM1_Init(void) 29 | { 30 | 31 | /* USER CODE BEGIN TIM1_Init 0 */ 32 | 33 | /* USER CODE END TIM1_Init 0 */ 34 | 35 | LL_TIM_InitTypeDef TIM_InitStruct = {0}; 36 | 37 | /* Peripheral clock enable */ 38 | LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1); 39 | 40 | /* TIM1 interrupt Init */ 41 | NVIC_SetPriority(TIM1_UP_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0)); 42 | NVIC_EnableIRQ(TIM1_UP_IRQn); 43 | 44 | /* USER CODE BEGIN TIM1_Init 1 */ 45 | 46 | /* USER CODE END TIM1_Init 1 */ 47 | TIM_InitStruct.Prescaler = 719; 48 | TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; 49 | TIM_InitStruct.Autoreload = 124; 50 | TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; 51 | TIM_InitStruct.RepetitionCounter = 0; 52 | LL_TIM_Init(TIM1, &TIM_InitStruct); 53 | LL_TIM_DisableARRPreload(TIM1); 54 | LL_TIM_SetClockSource(TIM1, LL_TIM_CLOCKSOURCE_INTERNAL); 55 | LL_TIM_SetTriggerOutput(TIM1, LL_TIM_TRGO_RESET); 56 | LL_TIM_DisableMasterSlaveMode(TIM1); 57 | /* USER CODE BEGIN TIM1_Init 2 */ 58 | 59 | /* USER CODE END TIM1_Init 2 */ 60 | 61 | } 62 | 63 | /* USER CODE BEGIN 1 */ 64 | 65 | /* USER CODE END 1 */ 66 | -------------------------------------------------------------------------------- /HID_template/Core/Inc/stm32f1xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f1xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F1xx_IT_H 22 | #define __STM32F1xx_IT_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Private includes ----------------------------------------------------------*/ 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN ET */ 35 | 36 | /* USER CODE END ET */ 37 | 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* USER CODE BEGIN EC */ 40 | 41 | /* USER CODE END EC */ 42 | 43 | /* Exported macro ------------------------------------------------------------*/ 44 | /* USER CODE BEGIN EM */ 45 | 46 | /* USER CODE END EM */ 47 | 48 | /* Exported functions prototypes ---------------------------------------------*/ 49 | void NMI_Handler(void); 50 | void HardFault_Handler(void); 51 | void MemManage_Handler(void); 52 | void BusFault_Handler(void); 53 | void UsageFault_Handler(void); 54 | void SVC_Handler(void); 55 | void DebugMon_Handler(void); 56 | void PendSV_Handler(void); 57 | void SysTick_Handler(void); 58 | void USB_LP_CAN1_RX0_IRQHandler(void); 59 | void TIM1_UP_IRQHandler(void); 60 | /* USER CODE BEGIN EFP */ 61 | 62 | /* USER CODE END EFP */ 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif /* __STM32F1xx_IT_H */ 69 | -------------------------------------------------------------------------------- /HID_template/MDK-ARM/readme.md: -------------------------------------------------------------------------------- 1 | # 基于 STM32F103C6T6 的一个 usbhid 复合设备的工程模板 2 | 3 | 依靠 32 模拟成自定义 hid 设备, 目前实现了鼠标, 键盘, 触摸屏, 实现了数据接收 4 | 5 | #### 注意 6 | 7 | 用 cubemx 生成工程前请先备份 Middlewares 和 USB_DEVICE 这两个文件夹 8 | 生成完用备份的替换掉生成后的 9 | 10 | #### 如何使用 11 | 12 | 引用头文件 13 | 14 | ```c 15 | #include "psk_hid.h" 16 | ``` 17 | 18 | 准备一个 5ms 定时器发送四个数据, 最好来一个稍大于 1ms 的定时器分开发送, 因为电脑接收数据包最短 1ms 轮询 19 | 20 | (可以只发送想要用的几个) 21 | 22 | 我开了一个 1.25ms 的定时器, 分了四次执行发送数据包的代码, 可以把丢包率降到最低 23 | 24 | ```c 25 | void TIM1_IRQ(void) 26 | { 27 | if (LL_TIM_IsActiveFlag_UPDATE(TIM1) == SET) 28 | { 29 | LL_TIM_ClearFlag_UPDATE(TIM1); // 1.25 ms 30 | static uint8_t i; 31 | switch (i) 32 | { 33 | case 0: 34 | send_keyboard_data(); 35 | break; 36 | case 1: 37 | send_custom_control_data(); 38 | break; 39 | case 2: 40 | send_touch_data(); 41 | break; 42 | default: 43 | send_mouse_data(); 44 | } 45 | i = (i + 1) % 4; 46 | } 47 | } 48 | ``` 49 | 50 | 初始化(可以只初始化几个) 51 | 52 | ```c 53 | mouse_init(); 54 | keyboard_init(); 55 | custom_init(); 56 | touch_init(); 57 | ``` 58 | 59 | 开始愉快的玩耍吧 60 | 61 | ```c 62 | void shutdown(void) 63 | { 64 | keyboard_press_sp_key(LEFT_GUI, 2); 65 | keyboard_press_char('x', 2); 66 | keyboard_delay(100); 67 | keyboard_press_sp_key(LEFT_GUI, 2); 68 | keyboard_press_char('x', 2); 69 | keyboard_delay(50); 70 | keyboard_press_str("uuuuuuuuuuuuuuuuuuu\n", 1); 71 | } 72 | ``` 73 | 74 | #### 自定义 75 | 76 | 找到 usbd_desc.c, 修改部分代码 65 行左右 77 | 78 | ```c 79 | #define USBD_VID 6666 // 生产商ID 80 | #define USBD_LANGID_STRING 1033 // 不知道 81 | #define USBD_MANUFACTURER_STRING "NJUST 6003-Ptisak LAB INC" // 生产商名字 82 | #define USBD_PID_FS 23333 // 产品ID, 每个产品唯一, 最好自己修改 83 | #define USBD_PRODUCT_STRING_FS "Ptisak Pia !(o `~')/''" // 产品名字 84 | #define USBD_CONFIGURATION_STRING_FS "PSK INF" // 配置字段, 可以改 85 | #define USBD_INTERFACE_STRING_FS "PSK HID INTERFACE" // 可以改 86 | ``` 87 | 88 | 改设备描述符(不建议, 因为改了后可能每个设备的报告 ID 要改) 89 | usbd_custom_hid_if.c , 91 行 90 | CUSTOM_HID_ReportDesc_FS <- 这个是设备描述符数组 91 | USBD_CUSTOM_HID_REPORT_DESC_SIZE <- 这个是长度, 必须和设备描述符数组长度匹配 92 | -------------------------------------------------------------------------------- /HID_template/Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /** @addtogroup CMSIS 21 | * @{ 22 | */ 23 | 24 | /** @addtogroup stm32f10x_system 25 | * @{ 26 | */ 27 | 28 | /** 29 | * @brief Define to prevent recursive inclusion 30 | */ 31 | #ifndef __SYSTEM_STM32F10X_H 32 | #define __SYSTEM_STM32F10X_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /** @addtogroup STM32F10x_System_Includes 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @} 44 | */ 45 | 46 | 47 | /** @addtogroup STM32F10x_System_Exported_types 48 | * @{ 49 | */ 50 | 51 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 52 | extern const uint8_t AHBPrescTable[16U]; /*!< AHB prescalers table values */ 53 | extern const uint8_t APBPrescTable[8U]; /*!< APB prescalers table values */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @addtogroup STM32F10x_System_Exported_Constants 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @addtogroup STM32F10x_System_Exported_Macros 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @addtogroup STM32F10x_System_Exported_Functions 76 | * @{ 77 | */ 78 | 79 | extern void SystemInit(void); 80 | extern void SystemCoreClockUpdate(void); 81 | /** 82 | * @} 83 | */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /*__SYSTEM_STM32F10X_H */ 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 99 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/usage_desktop.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usage_desktop.h 4 | * @author Benedek Kupper 5 | * @version 0.1 6 | * @date 2018-01-31 7 | * @brief USB Human Interface Device Class 8 | * Desktop Usage Page definitions 9 | * 10 | * Copyright (c) 2018 Benedek Kupper 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | #ifndef __HID_USAGE_DESKTOP_H_ 25 | #define __HID_USAGE_DESKTOP_H_ 26 | #include 27 | 28 | #define HID_USAGE_PAGE_DESKTOP HID_ITEM_1(0x0, GLOBAL, 0x01) 29 | 30 | #define HID_USAGE_DT_POINTER HID_USAGE_1(0x01) 31 | #define HID_USAGE_DT_MOUSE HID_USAGE_1(0x02) 32 | #define HID_USAGE_DT_JOYSTICK HID_USAGE_1(0x04) 33 | #define HID_USAGE_DT_GAMEPAD HID_USAGE_1(0x05) 34 | #define HID_USAGE_DT_KEYBOARD HID_USAGE_1(0x06) 35 | #define HID_USAGE_DT_KEYPAD HID_USAGE_1(0x07) 36 | #define HID_USAGE_DT_MULTI_AXIS_CTRL HID_USAGE_1(0x08) 37 | 38 | #define HID_USAGE_DT_X HID_USAGE_1(0x30) 39 | #define HID_USAGE_DT_Y HID_USAGE_1(0x31) 40 | #define HID_USAGE_DT_Z HID_USAGE_1(0x32) 41 | #define HID_USAGE_DT_RX HID_USAGE_1(0x33) 42 | #define HID_USAGE_DT_RY HID_USAGE_1(0x34) 43 | #define HID_USAGE_DT_RZ HID_USAGE_1(0x35) 44 | #define HID_USAGE_DT_WHEEL HID_USAGE_1(0x38) 45 | #define HID_USAGE_DT_MOTION_WAKEUP HID_USAGE_1(0x3C) 46 | 47 | #define HID_USAGE_DT_RESOLUTION_MULT HID_USAGE_1(0x48) 48 | 49 | #define HID_USAGE_DT_SYS_CTRL HID_USAGE_1(0x80) 50 | #define HID_USAGE_DT_SYS_POWER_DOWN HID_USAGE_1(0x81) 51 | #define HID_USAGE_DT_SYS_SLEEP HID_USAGE_1(0x82) 52 | #define HID_USAGE_DT_SYS_WAKEUP HID_USAGE_1(0x83) 53 | 54 | 55 | #endif /* __HID_USAGE_DESKTOP_H_ */ 56 | -------------------------------------------------------------------------------- /HID_template/MDK-ARM/DebugConfig/HID_template_STM32F103C6_1.0.0.dbgconf: -------------------------------------------------------------------------------- 1 | // File: STM32F101_102_103_105_107.dbgconf 2 | // Version: 1.0.0 3 | // Note: refer to STM32F101xx STM32F102xx STM32F103xx STM32F105xx STM32F107xx Reference manual (RM0008) 4 | // STM32F101xx STM32F102xx STM32F103xx STM32F105xx STM32F107xx datasheets 5 | 6 | // <<< Use Configuration Wizard in Context Menu >>> 7 | 8 | // Debug MCU configuration register (DBGMCU_CR) 9 | // Reserved bits must be kept at reset value 10 | // DBG_TIM11_STOP TIM11 counter stopped when core is halted 11 | // DBG_TIM10_STOP TIM10 counter stopped when core is halted 12 | // DBG_TIM9_STOP TIM9 counter stopped when core is halted 13 | // DBG_TIM14_STOP TIM14 counter stopped when core is halted 14 | // DBG_TIM13_STOP TIM13 counter stopped when core is halted 15 | // DBG_TIM12_STOP TIM12 counter stopped when core is halted 16 | // DBG_CAN2_STOP Debug CAN2 stopped when core is halted 17 | // DBG_TIM7_STOP TIM7 counter stopped when core is halted 18 | // DBG_TIM6_STOP TIM6 counter stopped when core is halted 19 | // DBG_TIM5_STOP TIM5 counter stopped when core is halted 20 | // DBG_TIM8_STOP TIM8 counter stopped when core is halted 21 | // DBG_I2C2_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted 22 | // DBG_I2C1_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted 23 | // DBG_CAN1_STOP Debug CAN1 stopped when Core is halted 24 | // DBG_TIM4_STOP TIM4 counter stopped when core is halted 25 | // DBG_TIM3_STOP TIM3 counter stopped when core is halted 26 | // DBG_TIM2_STOP TIM2 counter stopped when core is halted 27 | // DBG_TIM1_STOP TIM1 counter stopped when core is halted 28 | // DBG_WWDG_STOP Debug window watchdog stopped when core is halted 29 | // DBG_IWDG_STOP Debug independent watchdog stopped when core is halted 30 | // DBG_STANDBY Debug standby mode 31 | // DBG_STOP Debug stop mode 32 | // DBG_SLEEP Debug sleep mode 33 | // 34 | DbgMCU_CR = 0x00000007; 35 | 36 | // <<< end of configuration section >>> 37 | -------------------------------------------------------------------------------- /HID_template/Core/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __MAIN_H 23 | #define __MAIN_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f1xx_hal.h" 31 | 32 | #include "stm32f1xx_ll_rcc.h" 33 | #include "stm32f1xx_ll_bus.h" 34 | #include "stm32f1xx_ll_system.h" 35 | #include "stm32f1xx_ll_exti.h" 36 | #include "stm32f1xx_ll_cortex.h" 37 | #include "stm32f1xx_ll_utils.h" 38 | #include "stm32f1xx_ll_pwr.h" 39 | #include "stm32f1xx_ll_dma.h" 40 | #include "stm32f1xx_ll_tim.h" 41 | #include "stm32f1xx_ll_gpio.h" 42 | 43 | /* Private includes ----------------------------------------------------------*/ 44 | /* USER CODE BEGIN Includes */ 45 | 46 | /* USER CODE END Includes */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN ET */ 50 | void TIM1_IRQ(void); 51 | 52 | /* USER CODE END ET */ 53 | 54 | /* Exported constants --------------------------------------------------------*/ 55 | /* USER CODE BEGIN EC */ 56 | 57 | /* USER CODE END EC */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* USER CODE BEGIN EM */ 61 | 62 | /* USER CODE END EM */ 63 | 64 | /* Exported functions prototypes ---------------------------------------------*/ 65 | void Error_Handler(void); 66 | 67 | /* USER CODE BEGIN EFP */ 68 | 69 | /* USER CODE END EFP */ 70 | 71 | /* Private defines -----------------------------------------------------------*/ 72 | /* USER CODE BEGIN Private defines */ 73 | 74 | /* USER CODE END Private defines */ 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /* __MAIN_H */ 81 | -------------------------------------------------------------------------------- /HID_template/Core/Src/stm32f1xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f1xx_hal_msp.c 5 | * @brief This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "main.h" 23 | /* USER CODE BEGIN Includes */ 24 | 25 | /* USER CODE END Includes */ 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* USER CODE BEGIN TD */ 29 | 30 | /* USER CODE END TD */ 31 | 32 | /* Private define ------------------------------------------------------------*/ 33 | /* USER CODE BEGIN Define */ 34 | 35 | /* USER CODE END Define */ 36 | 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* USER CODE BEGIN Macro */ 39 | 40 | /* USER CODE END Macro */ 41 | 42 | /* Private variables ---------------------------------------------------------*/ 43 | /* USER CODE BEGIN PV */ 44 | 45 | /* USER CODE END PV */ 46 | 47 | /* Private function prototypes -----------------------------------------------*/ 48 | /* USER CODE BEGIN PFP */ 49 | 50 | /* USER CODE END PFP */ 51 | 52 | /* External functions --------------------------------------------------------*/ 53 | /* USER CODE BEGIN ExternalFunctions */ 54 | 55 | /* USER CODE END ExternalFunctions */ 56 | 57 | /* USER CODE BEGIN 0 */ 58 | 59 | /* USER CODE END 0 */ 60 | /** 61 | * Initializes the Global MSP. 62 | */ 63 | void HAL_MspInit(void) 64 | { 65 | /* USER CODE BEGIN MspInit 0 */ 66 | 67 | /* USER CODE END MspInit 0 */ 68 | 69 | __HAL_RCC_AFIO_CLK_ENABLE(); 70 | __HAL_RCC_PWR_CLK_ENABLE(); 71 | 72 | /* System interrupt init*/ 73 | 74 | /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled 75 | */ 76 | __HAL_AFIO_REMAP_SWJ_NOJTAG(); 77 | 78 | /* USER CODE BEGIN MspInit 1 */ 79 | 80 | /* USER CODE END MspInit 1 */ 81 | } 82 | 83 | /* USER CODE BEGIN 1 */ 84 | 85 | /* USER CODE END 1 */ 86 | 87 | -------------------------------------------------------------------------------- /HID_template/hardware/pid.h: -------------------------------------------------------------------------------- 1 | #ifndef __pid_H__ 2 | #define __pid_H__ 3 | 4 | #include "stm32f1xx_hal.h" 5 | 6 | enum 7 | { 8 | LLAST = 0, 9 | LAST, 10 | NOW, 11 | POSITION_PID, 12 | DELTA_PID, 13 | }; 14 | typedef struct pid_t 15 | { 16 | float p; 17 | float i; 18 | float d; 19 | 20 | float set; 21 | float get; 22 | float err[3]; 23 | 24 | float pout; 25 | float iout; 26 | float dout; 27 | float out; 28 | 29 | float input_max_err; //input max err; 30 | float output_deadband; //output deadband; 31 | 32 | uint32_t pid_mode; 33 | uint32_t max_out; 34 | uint32_t integral_limit; 35 | 36 | void (*f_param_init)(struct pid_t *pid, 37 | uint32_t pid_mode, 38 | uint32_t max_output, 39 | uint32_t inte_limit, 40 | float p, 41 | float i, 42 | float d); 43 | void (*f_pid_reset)(struct pid_t *pid, float p, float i, float d); 44 | 45 | } pid_t; 46 | 47 | 48 | #if 0 49 | #define PID_PARAM_DEFAULT \ 50 | {\ 51 | 0,\ 52 | 0,\ 53 | 0,\ 54 | 0,\ 55 | 0,\ 56 | {0,0,0},\ 57 | 0,\ 58 | 0,\ 59 | 0,\ 60 | 0,\ 61 | 0,\ 62 | 0,\ 63 | }\ 64 | 65 | typedef struct 66 | { 67 | float p; 68 | float i; 69 | float d; 70 | 71 | float set; 72 | float get; 73 | float err[3]; //error 74 | 75 | float pout; 76 | float iout; 77 | float dout; 78 | float out; 79 | 80 | float input_max_err; //input max err; 81 | float output_deadband; //output deadband; 82 | 83 | float p_far; 84 | float p_near; 85 | float grade_range; 86 | 87 | uint32_t pid_mode; 88 | uint32_t max_out; 89 | uint32_t integral_limit; 90 | 91 | void (*f_param_init)(struct pid_t *pid, 92 | uint32_t pid_mode, 93 | uint32_t max_output, 94 | uint32_t inte_limit, 95 | float p, 96 | float i, 97 | float d); 98 | void (*f_pid_reset)(struct pid_t *pid, float p, float i, float d); 99 | 100 | } grade_pid_t; 101 | #endif 102 | 103 | void PID_struct_init( 104 | pid_t* pid, 105 | uint32_t mode, 106 | uint32_t maxout, 107 | uint32_t intergral_limit, 108 | 109 | float kp, 110 | float ki, 111 | float kd); 112 | 113 | float pid_calc(pid_t *pid, float get, float set); 114 | float position_pid_calc(pid_t *pid, float fdb, float ref); 115 | void ControlLoop(void); 116 | void ControtLoopTaskInit(void); 117 | 118 | extern pid_t pid_x; 119 | extern pid_t pid_y; 120 | #endif 121 | 122 | 123 | -------------------------------------------------------------------------------- /HID_template/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_req.h 4 | * @author MCD Application Team 5 | * @brief Header file for the usbd_req.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USB_REQUEST_H 22 | #define __USB_REQUEST_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_REQ 37 | * @brief header file for the usbd_req.c file 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_REQ_Exported_Defines 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_REQ_Exported_Types 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | 58 | /** @defgroup USBD_REQ_Exported_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @defgroup USBD_REQ_Exported_Variables 66 | * @{ 67 | */ 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype 73 | * @{ 74 | */ 75 | 76 | USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 77 | USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 78 | USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 79 | 80 | 81 | void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 82 | 83 | void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata); 84 | 85 | void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); 86 | /** 87 | * @} 88 | */ 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* __USB_REQUEST_H */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /HID_template/USB_DEVICE/App/usb_device.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usb_device.h 5 | * @version : v2.0_Cube 6 | * @brief : Header for usb_device.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __USB_DEVICE__H__ 23 | #define __USB_DEVICE__H__ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f1xx.h" 31 | #include "stm32f1xx_hal.h" 32 | #include "usbd_def.h" 33 | 34 | /* USER CODE BEGIN INCLUDE */ 35 | 36 | /* USER CODE END INCLUDE */ 37 | 38 | /** @addtogroup USBD_OTG_DRIVER 39 | * @{ 40 | */ 41 | 42 | /** @defgroup USBD_DEVICE USBD_DEVICE 43 | * @brief Device file for Usb otg low level driver. 44 | * @{ 45 | */ 46 | 47 | /** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables 48 | * @brief Public variables. 49 | * @{ 50 | */ 51 | 52 | /* Private variables ---------------------------------------------------------*/ 53 | /* USER CODE BEGIN PV */ 54 | 55 | /* USER CODE END PV */ 56 | 57 | /* Private function prototypes -----------------------------------------------*/ 58 | /* USER CODE BEGIN PFP */ 59 | 60 | /* USER CODE END PFP */ 61 | 62 | /* 63 | * -- Insert your variables declaration here -- 64 | */ 65 | /* USER CODE BEGIN VARIABLES */ 66 | 67 | /* USER CODE END VARIABLES */ 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype 73 | * @brief Declaration of public functions for Usb device. 74 | * @{ 75 | */ 76 | 77 | /** USB Device initialization function. */ 78 | void MX_USB_DEVICE_Init(void); 79 | 80 | /* 81 | * -- Insert functions declaration here -- 82 | */ 83 | /* USER CODE BEGIN FD */ 84 | 85 | /* USER CODE END FD */ 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /* __USB_DEVICE__H__ */ 103 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_req.h 4 | * @author MCD Application Team 5 | * @brief Header file for the usbd_req.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USB_REQUEST_H 22 | #define __USB_REQUEST_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_REQ 37 | * @brief header file for the usbd_req.c file 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_REQ_Exported_Defines 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_REQ_Exported_Types 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | 58 | /** @defgroup USBD_REQ_Exported_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @defgroup USBD_REQ_Exported_Variables 66 | * @{ 67 | */ 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype 73 | * @{ 74 | */ 75 | 76 | USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 77 | USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 78 | USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 79 | 80 | 81 | void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 82 | 83 | void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata); 84 | 85 | void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); 86 | /** 87 | * @} 88 | */ 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* __USB_REQUEST_H */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/USB_DEVICE/App/usb_device.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usb_device.h 5 | * @version : v2.0_Cube 6 | * @brief : Header for usb_device.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __USB_DEVICE__H__ 23 | #define __USB_DEVICE__H__ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f1xx.h" 31 | #include "stm32f1xx_hal.h" 32 | #include "usbd_def.h" 33 | 34 | /* USER CODE BEGIN INCLUDE */ 35 | 36 | /* USER CODE END INCLUDE */ 37 | 38 | /** @addtogroup USBD_OTG_DRIVER 39 | * @{ 40 | */ 41 | 42 | /** @defgroup USBD_DEVICE USBD_DEVICE 43 | * @brief Device file for Usb otg low level driver. 44 | * @{ 45 | */ 46 | 47 | /** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables 48 | * @brief Public variables. 49 | * @{ 50 | */ 51 | 52 | /* Private variables ---------------------------------------------------------*/ 53 | /* USER CODE BEGIN PV */ 54 | 55 | /* USER CODE END PV */ 56 | 57 | /* Private function prototypes -----------------------------------------------*/ 58 | /* USER CODE BEGIN PFP */ 59 | 60 | /* USER CODE END PFP */ 61 | 62 | /* 63 | * -- Insert your variables declaration here -- 64 | */ 65 | /* USER CODE BEGIN VARIABLES */ 66 | 67 | /* USER CODE END VARIABLES */ 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype 73 | * @brief Declaration of public functions for Usb device. 74 | * @{ 75 | */ 76 | 77 | /** USB Device initialization function. */ 78 | void MX_USB_DEVICE_Init(void); 79 | 80 | /* 81 | * -- Insert functions declaration here -- 82 | */ 83 | /* USER CODE BEGIN FD */ 84 | 85 | /* USER CODE END FD */ 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /* __USB_DEVICE__H__ */ 103 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/usage_telephony.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usage_desktop.h 4 | * @author Benedek Kupper 5 | * @version 0.1 6 | * @date 2020-09-21 7 | * @brief USB Human Interface Device Class 8 | * Telephony Usage Page definitions 9 | * 10 | * Copyright (c) 2020 Benedek Kupper 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | #ifndef __HID_USAGE_TELEPHONY_H_ 25 | #define __HID_USAGE_TELEPHONY_H_ 26 | #include 27 | 28 | #define HID_USAGE_PAGE_TELEPHONY HID_ITEM_1(0x0, GLOBAL, 0x0B) 29 | 30 | #define HID_USAGE_TP_PHONE HID_USAGE_1(0x01) 31 | #define HID_USAGE_TP_ANSWERING_MACHINE HID_USAGE_1(0x02) 32 | #define HID_USAGE_TP_DUAL_MODE_PHONE HID_USAGE_2(0x014B) 33 | 34 | #define HID_USAGE_TP_MESSAGE_CTRLS HID_USAGE_1(0x03) 35 | #define HID_USAGE_TP_HANDSET HID_USAGE_1(0x04) 36 | #define HID_USAGE_TP_HEADSET HID_USAGE_1(0x05) 37 | #define HID_USAGE_TP_KEY_PAD HID_USAGE_1(0x06) 38 | 39 | #define HID_USAGE_TP_HOOK_SWITCH HID_USAGE_1(0x20) 40 | #define HID_USAGE_TP_FLASH HID_USAGE_1(0x21) 41 | #define HID_USAGE_TP_FEATURE HID_USAGE_1(0x22) 42 | #define HID_USAGE_TP_HOLD HID_USAGE_1(0x23) 43 | #define HID_USAGE_TP_REDIAL HID_USAGE_1(0x24) 44 | #define HID_USAGE_TP_TRANSFER HID_USAGE_1(0x25) 45 | #define HID_USAGE_TP_DROP HID_USAGE_1(0x26) 46 | #define HID_USAGE_TP_PARK HID_USAGE_1(0x27) 47 | #define HID_USAGE_TP_ALT_FUNCTION HID_USAGE_1(0x29) 48 | 49 | #define HID_USAGE_TP_RING_ENABLE HID_USAGE_1(0x2D) 50 | 51 | #define HID_USAGE_TP_HOST_CTRL HID_USAGE_1(0xF0) 52 | #define HID_USAGE_TP_HOST_AVAIL HID_USAGE_1(0xF1) 53 | #define HID_USAGE_TP_HOST_CALL_ACTIVE HID_USAGE_1(0xF2) 54 | #define HID_USAGE_TP_ACT_HANDSET_AUDIO HID_USAGE_1(0xF3) 55 | #define HID_USAGE_TP_RING_TYPE HID_USAGE_1(0xF4) 56 | 57 | #define HID_USAGE_TP_STOP_RING_TONE HID_USAGE_1(0xF8) 58 | #define HID_USAGE_TP_PSTN_RING_TONE HID_USAGE_1(0xF9) 59 | #define HID_USAGE_TP_HOST_RING_TONE HID_USAGE_1(0xFA) 60 | 61 | #endif /* __HID_USAGE_TELEPHONY_H_ */ 62 | -------------------------------------------------------------------------------- /HID_template/USB_DEVICE/App/usb_device.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usb_device.c 5 | * @version : v2.0_Cube 6 | * @brief : This file implements the USB Device 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | 23 | #include "usb_device.h" 24 | #include "usbd_core.h" 25 | #include "usbd_desc.h" 26 | #include "usbd_customhid.h" 27 | #include "usbd_custom_hid_if.h" 28 | 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | /* USER CODE BEGIN PV */ 34 | /* Private variables ---------------------------------------------------------*/ 35 | 36 | /* USER CODE END PV */ 37 | 38 | /* USER CODE BEGIN PFP */ 39 | /* Private function prototypes -----------------------------------------------*/ 40 | 41 | /* USER CODE END PFP */ 42 | 43 | /* USB Device Core handle declaration. */ 44 | USBD_HandleTypeDef hUsbDeviceFS; 45 | 46 | /* 47 | * -- Insert your variables declaration here -- 48 | */ 49 | /* USER CODE BEGIN 0 */ 50 | 51 | /* USER CODE END 0 */ 52 | 53 | /* 54 | * -- Insert your external function declaration here -- 55 | */ 56 | /* USER CODE BEGIN 1 */ 57 | 58 | /* USER CODE END 1 */ 59 | 60 | /** 61 | * Init USB device Library, add supported class and start the library 62 | * @retval None 63 | */ 64 | void MX_USB_DEVICE_Init(void) 65 | { 66 | /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */ 67 | 68 | /* USER CODE END USB_DEVICE_Init_PreTreatment */ 69 | 70 | /* Init Device Library, add supported class and start the library. */ 71 | if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK) 72 | { 73 | Error_Handler(); 74 | } 75 | if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CUSTOM_HID) != USBD_OK) 76 | { 77 | Error_Handler(); 78 | } 79 | if (USBD_CUSTOM_HID_RegisterInterface(&hUsbDeviceFS, &USBD_CustomHID_fops_FS) != USBD_OK) 80 | { 81 | Error_Handler(); 82 | } 83 | if (USBD_Start(&hUsbDeviceFS) != USBD_OK) 84 | { 85 | Error_Handler(); 86 | } 87 | 88 | /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ 89 | 90 | /* USER CODE END USB_DEVICE_Init_PostTreatment */ 91 | } 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/USB_DEVICE/App/usb_device.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usb_device.c 5 | * @version : v2.0_Cube 6 | * @brief : This file implements the USB Device 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | 23 | #include "usb_device.h" 24 | #include "usbd_core.h" 25 | #include "usbd_desc.h" 26 | #include "usbd_customhid.h" 27 | #include "usbd_custom_hid_if.h" 28 | 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | /* USER CODE BEGIN PV */ 34 | /* Private variables ---------------------------------------------------------*/ 35 | 36 | /* USER CODE END PV */ 37 | 38 | /* USER CODE BEGIN PFP */ 39 | /* Private function prototypes -----------------------------------------------*/ 40 | 41 | /* USER CODE END PFP */ 42 | 43 | /* USB Device Core handle declaration. */ 44 | USBD_HandleTypeDef hUsbDeviceFS; 45 | 46 | /* 47 | * -- Insert your variables declaration here -- 48 | */ 49 | /* USER CODE BEGIN 0 */ 50 | 51 | /* USER CODE END 0 */ 52 | 53 | /* 54 | * -- Insert your external function declaration here -- 55 | */ 56 | /* USER CODE BEGIN 1 */ 57 | 58 | /* USER CODE END 1 */ 59 | 60 | /** 61 | * Init USB device Library, add supported class and start the library 62 | * @retval None 63 | */ 64 | void MX_USB_DEVICE_Init(void) 65 | { 66 | /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */ 67 | 68 | /* USER CODE END USB_DEVICE_Init_PreTreatment */ 69 | 70 | /* Init Device Library, add supported class and start the library. */ 71 | if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK) 72 | { 73 | Error_Handler(); 74 | } 75 | if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CUSTOM_HID) != USBD_OK) 76 | { 77 | Error_Handler(); 78 | } 79 | if (USBD_CUSTOM_HID_RegisterInterface(&hUsbDeviceFS, &USBD_CustomHID_fops_FS) != USBD_OK) 80 | { 81 | Error_Handler(); 82 | } 83 | if (USBD_Start(&hUsbDeviceFS) != USBD_OK) 84 | { 85 | Error_Handler(); 86 | } 87 | 88 | /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ 89 | 90 | /* USER CODE END USB_DEVICE_Init_PostTreatment */ 91 | } 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | -------------------------------------------------------------------------------- /HID_template/Drivers/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /HID_template/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pcd_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_pcd_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of PCD HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F1xx_HAL_PCD_EX_H 22 | #define STM32F1xx_HAL_PCD_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f1xx_hal_def.h" 30 | 31 | #if defined (USB) || defined (USB_OTG_FS) 32 | /** @addtogroup STM32F1xx_HAL_Driver 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup PCDEx 37 | * @{ 38 | */ 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macros -----------------------------------------------------------*/ 42 | /* Exported functions --------------------------------------------------------*/ 43 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions 44 | * @{ 45 | */ 46 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 47 | * @{ 48 | */ 49 | 50 | #if defined (USB_OTG_FS) 51 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size); 52 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size); 53 | #endif /* defined (USB_OTG_FS) */ 54 | 55 | #if defined (USB) 56 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, uint16_t ep_addr, 57 | uint16_t ep_kind, uint32_t pmaadress); 58 | 59 | void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state); 60 | #endif /* defined (USB) */ 61 | void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); 62 | void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** 77 | * @} 78 | */ 79 | #endif /* defined (USB) || defined (USB_OTG_FS) */ 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | 86 | #endif /* STM32F1xx_HAL_PCD_EX_H */ 87 | 88 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 89 | -------------------------------------------------------------------------------- /HID_template/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.h 4 | * @author MCD Application Team 5 | * @brief Header file for the usbd_ioreq.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_IOREQ_H 22 | #define __USBD_IOREQ_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | #include "usbd_core.h" 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_IOREQ 37 | * @brief header file for the usbd_ioreq.c file 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_IOREQ_Exported_Defines 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_IOREQ_Exported_Types 50 | * @{ 51 | */ 52 | 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | 59 | 60 | /** @defgroup USBD_IOREQ_Exported_Macros 61 | * @{ 62 | */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup USBD_IOREQ_Exported_Variables 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype 77 | * @{ 78 | */ 79 | 80 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, 81 | uint8_t *pbuf, 82 | uint16_t len); 83 | 84 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 85 | uint8_t *pbuf, 86 | uint16_t len); 87 | 88 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, 89 | uint8_t *pbuf, 90 | uint16_t len); 91 | 92 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, 93 | uint8_t *pbuf, 94 | uint16_t len); 95 | 96 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev); 97 | 98 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev); 99 | 100 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 101 | 102 | /** 103 | * @} 104 | */ 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif /* __USBD_IOREQ_H */ 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.h 4 | * @author MCD Application Team 5 | * @brief Header file for the usbd_ioreq.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_IOREQ_H 22 | #define __USBD_IOREQ_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | #include "usbd_core.h" 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_IOREQ 37 | * @brief header file for the usbd_ioreq.c file 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_IOREQ_Exported_Defines 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_IOREQ_Exported_Types 50 | * @{ 51 | */ 52 | 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | 59 | 60 | /** @defgroup USBD_IOREQ_Exported_Macros 61 | * @{ 62 | */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup USBD_IOREQ_Exported_Variables 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype 77 | * @{ 78 | */ 79 | 80 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, 81 | uint8_t *pbuf, 82 | uint16_t len); 83 | 84 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 85 | uint8_t *pbuf, 86 | uint16_t len); 87 | 88 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, 89 | uint8_t *pbuf, 90 | uint16_t len); 91 | 92 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, 93 | uint8_t *pbuf, 94 | uint16_t len); 95 | 96 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev); 97 | 98 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev); 99 | 100 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 101 | 102 | /** 103 | * @} 104 | */ 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif /* __USBD_IOREQ_H */ 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/usage_aux_display.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usage_aux_display.h 4 | * @author Benedek Kupper 5 | * @version 0.1 6 | * @date 2019-04-28 7 | * @brief USB Human Interface Device Class 8 | * Auxiliary Display Usage Page definitions 9 | * 10 | * Copyright (c) 2019 Benedek Kupper 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | #ifndef __HID_USAGE_AUX_DISPLAY_H_ 25 | #define __HID_USAGE_AUX_DISPLAY_H_ 26 | #include 27 | 28 | #define HID_USAGE_PAGE_AUX_DISPLAY HID_ITEM_1(0x0, GLOBAL, 0x14) 29 | 30 | #define HID_USAGE_AD_ALPHANUM_DISPLAY HID_USAGE_1(0x01) 31 | #define HID_USAGE_AD_AUX_DISPLAY HID_USAGE_1(0x02) 32 | #define HID_USAGE_AD_DISPLAY_ATTR_REPORT HID_USAGE_1(0x20) 33 | #define HID_USAGE_AD_ASCII_CHARSET HID_USAGE_1(0x21) 34 | #define HID_USAGE_AD_DATA_READ_BACK HID_USAGE_1(0x22) 35 | #define HID_USAGE_AD_FONT_READ_BACK HID_USAGE_1(0x23) 36 | #define HID_USAGE_AD_DISPLAY_CTRL_REPORT HID_USAGE_1(0x24) 37 | #define HID_USAGE_AD_CLEAR_DISPLAY HID_USAGE_1(0x25) 38 | #define HID_USAGE_AD_DISPLAY_ENABLE HID_USAGE_1(0x26) 39 | 40 | #define HID_USAGE_AD_SCREENSAVER_DELAY HID_USAGE_1(0x27) 41 | #define HID_USAGE_AD_SCREENSAVER_ENABLE HID_USAGE_1(0x28) 42 | #define HID_USAGE_AD_VERTICAL_SCROLL HID_USAGE_1(0x29) 43 | #define HID_USAGE_AD_HORIZONTAL_SCROLL HID_USAGE_1(0x2a) 44 | #define HID_USAGE_AD_CHAR_REPORT HID_USAGE_1(0x2b) 45 | #define HID_USAGE_AD_DISPLAY_DATA HID_USAGE_1(0x2c) 46 | #define HID_USAGE_AD_DISPLAY_STATUS HID_USAGE_1(0x2d) 47 | #define HID_USAGE_AD_STAT_NOT_READY HID_USAGE_1(0x2e) 48 | #define HID_USAGE_AD_STAT_READY HID_USAGE_1(0x2f) 49 | #define HID_USAGE_AD_ERR_INVALID_CHAR HID_USAGE_1(0x30) 50 | #define HID_USAGE_AD_ERR_FONT_DATA HID_USAGE_1(0x31) 51 | 52 | #define HID_USAGE_AD_ROWS HID_USAGE_1(0x35) 53 | #define HID_USAGE_AD_COLUMNS HID_USAGE_1(0x36) 54 | 55 | #define HID_USAGE_AD_UNICODE_CHARSET HID_USAGE_1(0x41) 56 | #define HID_USAGE_AD_FONT_7SEGMENT HID_USAGE_1(0x42) 57 | #define HID_USAGE_AD_7SEGMENT_DIRECT_MAP HID_USAGE_1(0x43) 58 | #define HID_USAGE_AD_FONT_14SEGMENT HID_USAGE_1(0x44) 59 | #define HID_USAGE_AD_14SEGMENT_DIRECT_MAP HID_USAGE_1(0x45) 60 | #define HID_USAGE_AD_DISPLAY_BRIGHTNESS HID_USAGE_1(0x46) 61 | #define HID_USAGE_AD_DISPLAY_CONTRAST HID_USAGE_1(0x47) 62 | #define HID_USAGE_AD_CHAR_ATTR HID_USAGE_1(0x48) 63 | #define HID_USAGE_AD_ATTR_READ_BACK HID_USAGE_1(0x49) 64 | #define HID_USAGE_AD_ATTR_DATA HID_USAGE_1(0x4a) 65 | 66 | #endif /* __HID_USAGE_AUX_DISPLAY_H_ */ 67 | -------------------------------------------------------------------------------- /HID_template/USB_DEVICE/App/usbd_custom_hid_if.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Ptisak 3 | * @Date: 2022-04-19 13:15:26 4 | * @LastEditors: Ptisak 5 | * @LastEditTime: 2022-04-19 14:30:58 6 | */ 7 | /* USER CODE BEGIN Header */ 8 | /** 9 | ****************************************************************************** 10 | * @file : usbd_custom_hid_if.h 11 | * @version : v2.0_Cube 12 | * @brief : Header for usbd_custom_hid_if.c file. 13 | ****************************************************************************** 14 | * @attention 15 | * 16 | * Copyright (c) 2022 STMicroelectronics. 17 | * All rights reserved. 18 | * 19 | * This software is licensed under terms that can be found in the LICENSE file 20 | * in the root directory of this software component. 21 | * If no LICENSE file comes with this software, it is provided AS-IS. 22 | * 23 | ****************************************************************************** 24 | */ 25 | /* USER CODE END Header */ 26 | 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __USBD_CUSTOM_HID_IF_H__ 29 | #define __USBD_CUSTOM_HID_IF_H__ 30 | 31 | #ifdef __cplusplus 32 | extern "C" 33 | { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_customhid.h" 38 | 39 | /* USER CODE BEGIN INCLUDE */ 40 | int8_t USBD_CUSTOM_HID_SendReport_FS(uint8_t *report, uint16_t len); 41 | /* USER CODE END INCLUDE */ 42 | 43 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 44 | * @brief For Usb device. 45 | * @{ 46 | */ 47 | 48 | /** @defgroup USBD_CUSTOM_HID USBD_CUSTOM_HID 49 | * @brief Usb custom human interface device module. 50 | * @{ 51 | */ 52 | 53 | /** @defgroup USBD_CUSTOM_HID_Exported_Defines USBD_CUSTOM_HID_Exported_Defines 54 | * @brief Defines. 55 | * @{ 56 | */ 57 | 58 | /* USER CODE BEGIN EXPORTED_DEFINES */ 59 | 60 | /* USER CODE END EXPORTED_DEFINES */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup USBD_CUSTOM_HID_Exported_Types USBD_CUSTOM_HID_Exported_Types 67 | * @brief Types. 68 | * @{ 69 | */ 70 | 71 | /* USER CODE BEGIN EXPORTED_TYPES */ 72 | 73 | /* USER CODE END EXPORTED_TYPES */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** @defgroup USBD_CUSTOM_HID_Exported_Macros USBD_CUSTOM_HID_Exported_Macros 80 | * @brief Aliases. 81 | * @{ 82 | */ 83 | 84 | /* USER CODE BEGIN EXPORTED_MACRO */ 85 | 86 | /* USER CODE END EXPORTED_MACRO */ 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @defgroup USBD_CUSTOM_HID_Exported_Variables USBD_CUSTOM_HID_Exported_Variables 93 | * @brief Public variables. 94 | * @{ 95 | */ 96 | 97 | /** CUSTOMHID Interface callback. */ 98 | extern USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_fops_FS; 99 | 100 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 101 | 102 | /* USER CODE END EXPORTED_VARIABLES */ 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | /** @defgroup USBD_CUSTOM_HID_Exported_FunctionsPrototype USBD_CUSTOM_HID_Exported_FunctionsPrototype 109 | * @brief Public functions declaration. 110 | * @{ 111 | */ 112 | 113 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 114 | 115 | /* USER CODE END EXPORTED_FUNCTIONS */ 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** 126 | * @} 127 | */ 128 | 129 | #ifdef __cplusplus 130 | } 131 | #endif 132 | 133 | #endif /* __USBD_CUSTOM_HID_IF_H__ */ 134 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/USB_DEVICE/App/usbd_custom_hid_if.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Ptisak 3 | * @Date: 2022-04-19 13:15:26 4 | * @LastEditors: Ptisak 5 | * @LastEditTime: 2022-04-19 14:30:58 6 | */ 7 | /* USER CODE BEGIN Header */ 8 | /** 9 | ****************************************************************************** 10 | * @file : usbd_custom_hid_if.h 11 | * @version : v2.0_Cube 12 | * @brief : Header for usbd_custom_hid_if.c file. 13 | ****************************************************************************** 14 | * @attention 15 | * 16 | * Copyright (c) 2022 STMicroelectronics. 17 | * All rights reserved. 18 | * 19 | * This software is licensed under terms that can be found in the LICENSE file 20 | * in the root directory of this software component. 21 | * If no LICENSE file comes with this software, it is provided AS-IS. 22 | * 23 | ****************************************************************************** 24 | */ 25 | /* USER CODE END Header */ 26 | 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __USBD_CUSTOM_HID_IF_H__ 29 | #define __USBD_CUSTOM_HID_IF_H__ 30 | 31 | #ifdef __cplusplus 32 | extern "C" 33 | { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_customhid.h" 38 | 39 | /* USER CODE BEGIN INCLUDE */ 40 | int8_t USBD_CUSTOM_HID_SendReport_FS(uint8_t *report, uint16_t len); 41 | /* USER CODE END INCLUDE */ 42 | 43 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 44 | * @brief For Usb device. 45 | * @{ 46 | */ 47 | 48 | /** @defgroup USBD_CUSTOM_HID USBD_CUSTOM_HID 49 | * @brief Usb custom human interface device module. 50 | * @{ 51 | */ 52 | 53 | /** @defgroup USBD_CUSTOM_HID_Exported_Defines USBD_CUSTOM_HID_Exported_Defines 54 | * @brief Defines. 55 | * @{ 56 | */ 57 | 58 | /* USER CODE BEGIN EXPORTED_DEFINES */ 59 | 60 | /* USER CODE END EXPORTED_DEFINES */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup USBD_CUSTOM_HID_Exported_Types USBD_CUSTOM_HID_Exported_Types 67 | * @brief Types. 68 | * @{ 69 | */ 70 | 71 | /* USER CODE BEGIN EXPORTED_TYPES */ 72 | 73 | /* USER CODE END EXPORTED_TYPES */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** @defgroup USBD_CUSTOM_HID_Exported_Macros USBD_CUSTOM_HID_Exported_Macros 80 | * @brief Aliases. 81 | * @{ 82 | */ 83 | 84 | /* USER CODE BEGIN EXPORTED_MACRO */ 85 | 86 | /* USER CODE END EXPORTED_MACRO */ 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @defgroup USBD_CUSTOM_HID_Exported_Variables USBD_CUSTOM_HID_Exported_Variables 93 | * @brief Public variables. 94 | * @{ 95 | */ 96 | 97 | /** CUSTOMHID Interface callback. */ 98 | extern USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_fops_FS; 99 | 100 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 101 | 102 | /* USER CODE END EXPORTED_VARIABLES */ 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | /** @defgroup USBD_CUSTOM_HID_Exported_FunctionsPrototype USBD_CUSTOM_HID_Exported_FunctionsPrototype 109 | * @brief Public functions declaration. 110 | * @{ 111 | */ 112 | 113 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 114 | 115 | /* USER CODE END EXPORTED_FUNCTIONS */ 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** 126 | * @} 127 | */ 128 | 129 | #ifdef __cplusplus 130 | } 131 | #endif 132 | 133 | #endif /* __USBD_CUSTOM_HID_IF_H__ */ 134 | -------------------------------------------------------------------------------- /HID_template/USB_DEVICE/App/usbd_desc.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_desc.c 5 | * @version : v2.0_Cube 6 | * @brief : Header for usbd_conf.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_DESC__C__ 22 | #define __USBD_DESC__C__ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | 31 | /* USER CODE BEGIN INCLUDE */ 32 | 33 | /* USER CODE END INCLUDE */ 34 | 35 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 36 | * @{ 37 | */ 38 | 39 | /** @defgroup USBD_DESC USBD_DESC 40 | * @brief Usb device descriptors module. 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants 45 | * @brief Constants. 46 | * @{ 47 | */ 48 | #define DEVICE_ID1 (UID_BASE) 49 | #define DEVICE_ID2 (UID_BASE + 0x4) 50 | #define DEVICE_ID3 (UID_BASE + 0x8) 51 | 52 | #define USB_SIZ_STRING_SERIAL 0x1A 53 | 54 | /* USER CODE BEGIN EXPORTED_CONSTANTS */ 55 | 56 | /* USER CODE END EXPORTED_CONSTANTS */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | /** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines 63 | * @brief Defines. 64 | * @{ 65 | */ 66 | 67 | /* USER CODE BEGIN EXPORTED_DEFINES */ 68 | 69 | /* USER CODE END EXPORTED_DEFINES */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions 76 | * @brief Types. 77 | * @{ 78 | */ 79 | 80 | /* USER CODE BEGIN EXPORTED_TYPES */ 81 | 82 | /* USER CODE END EXPORTED_TYPES */ 83 | 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros 89 | * @brief Aliases. 90 | * @{ 91 | */ 92 | 93 | /* USER CODE BEGIN EXPORTED_MACRO */ 94 | 95 | /* USER CODE END EXPORTED_MACRO */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables 102 | * @brief Public variables. 103 | * @{ 104 | */ 105 | 106 | /** Descriptor for the Usb device. */ 107 | extern USBD_DescriptorsTypeDef FS_Desc; 108 | 109 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 110 | 111 | /* USER CODE END EXPORTED_VARIABLES */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype 118 | * @brief Public functions declaration. 119 | * @{ 120 | */ 121 | 122 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 123 | 124 | /* USER CODE END EXPORTED_FUNCTIONS */ 125 | 126 | /** 127 | * @} 128 | */ 129 | 130 | /** 131 | * @} 132 | */ 133 | 134 | /** 135 | * @} 136 | */ 137 | 138 | #ifdef __cplusplus 139 | } 140 | #endif 141 | 142 | #endif /* __USBD_DESC__C__ */ 143 | 144 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/USB_DEVICE/App/usbd_desc.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_desc.c 5 | * @version : v2.0_Cube 6 | * @brief : Header for usbd_conf.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_DESC__C__ 22 | #define __USBD_DESC__C__ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | 31 | /* USER CODE BEGIN INCLUDE */ 32 | 33 | /* USER CODE END INCLUDE */ 34 | 35 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 36 | * @{ 37 | */ 38 | 39 | /** @defgroup USBD_DESC USBD_DESC 40 | * @brief Usb device descriptors module. 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants 45 | * @brief Constants. 46 | * @{ 47 | */ 48 | #define DEVICE_ID1 (UID_BASE) 49 | #define DEVICE_ID2 (UID_BASE + 0x4) 50 | #define DEVICE_ID3 (UID_BASE + 0x8) 51 | 52 | #define USB_SIZ_STRING_SERIAL 0x1A 53 | 54 | /* USER CODE BEGIN EXPORTED_CONSTANTS */ 55 | 56 | /* USER CODE END EXPORTED_CONSTANTS */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | /** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines 63 | * @brief Defines. 64 | * @{ 65 | */ 66 | 67 | /* USER CODE BEGIN EXPORTED_DEFINES */ 68 | 69 | /* USER CODE END EXPORTED_DEFINES */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions 76 | * @brief Types. 77 | * @{ 78 | */ 79 | 80 | /* USER CODE BEGIN EXPORTED_TYPES */ 81 | 82 | /* USER CODE END EXPORTED_TYPES */ 83 | 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros 89 | * @brief Aliases. 90 | * @{ 91 | */ 92 | 93 | /* USER CODE BEGIN EXPORTED_MACRO */ 94 | 95 | /* USER CODE END EXPORTED_MACRO */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables 102 | * @brief Public variables. 103 | * @{ 104 | */ 105 | 106 | /** Descriptor for the Usb device. */ 107 | extern USBD_DescriptorsTypeDef FS_Desc; 108 | 109 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 110 | 111 | /* USER CODE END EXPORTED_VARIABLES */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype 118 | * @brief Public functions declaration. 119 | * @{ 120 | */ 121 | 122 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 123 | 124 | /* USER CODE END EXPORTED_FUNCTIONS */ 125 | 126 | /** 127 | * @} 128 | */ 129 | 130 | /** 131 | * @} 132 | */ 133 | 134 | /** 135 | * @} 136 | */ 137 | 138 | #ifdef __cplusplus 139 | } 140 | #endif 141 | 142 | #endif /* __USBD_DESC__C__ */ 143 | 144 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/mouse.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file mouse.h 4 | * @author Benedek Kupper 5 | * @version 0.1 6 | * @date 2018-09-04 7 | * @brief USB Human Interface Device Class 8 | * Mouse report definitions 9 | * 10 | * Copyright (c) 2018 Benedek Kupper 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | #ifndef __HID_MOUSE_H_ 25 | #define __HID_MOUSE_H_ 26 | #include 27 | #include 28 | #include 29 | 30 | /** @ingroup USBD_HID 31 | * @addtogroup USBD_HID_Common_Reports Common HID Reports 32 | * @{ */ 33 | 34 | /** @brief HID mouse report descriptor with scroll wheel */ 35 | #define HID_MOUSE_REPORT_DESC(...) \ 36 | HID_USAGE_PAGE_DESKTOP, \ 37 | HID_USAGE_DT_MOUSE, \ 38 | HID_COLLECTION_APPLICATION( \ 39 | HID_USAGE_DT_POINTER, \ 40 | HID_COLLECTION_PHYSICAL( \ 41 | HID_USAGE_PAGE_BUTTON, \ 42 | /* 3 buttons */ \ 43 | HID_USAGE_MIN_8(1), \ 44 | HID_USAGE_MAX_8(3), \ 45 | HID_LOGICAL_MIN_8(0), \ 46 | HID_LOGICAL_MAX_8(1), \ 47 | HID_REPORT_SIZE(1), \ 48 | HID_REPORT_COUNT(3), \ 49 | HID_INPUT(Data_Var_Abs), \ 50 | HID_REPORT_SIZE(5), \ 51 | HID_REPORT_COUNT(1), \ 52 | HID_OUTPUT(Const_Arr_Abs), \ 53 | HID_USAGE_PAGE_DESKTOP, \ 54 | /* X-Y movement + wheel */ \ 55 | HID_USAGE_DT_X, \ 56 | HID_USAGE_DT_Y, \ 57 | HID_USAGE_DT_WHEEL, \ 58 | HID_LOGICAL_MIN_8(-127), \ 59 | HID_LOGICAL_MAX_8(127), \ 60 | HID_REPORT_SIZE(8), \ 61 | HID_REPORT_COUNT(3), \ 62 | HID_INPUT(Data_Var_Rel), \ 63 | ), \ 64 | __VA_ARGS__) 65 | 66 | 67 | /** @brief Remote motion wakeup extension for @ref HID_MOUSE_WAKEUP_DESC */ 68 | #define HID_MOUSE_WAKEUP_DESC \ 69 | HID_USAGE_DT_MOTION_WAKEUP, \ 70 | HID_USAGE_PAGE_VENDOR_SPEC, \ 71 | /* 2 flags configuration */ \ 72 | HID_USAGE(1), \ 73 | HID_LOGICAL_MIN_8(0), \ 74 | HID_LOGICAL_MAX_8(1), \ 75 | HID_REPORT_SIZE(1), \ 76 | HID_REPORT_COUNT(2), \ 77 | HID_FEATURE(Data_Var_Abs | \ 78 | NoPreferred_Flag), \ 79 | HID_REPORT_SIZE(6), \ 80 | HID_REPORT_COUNT(1), \ 81 | HID_FEATURE(Const_Arr_Abs), 82 | 83 | 84 | /** @brief HID mouse IN report layout */ 85 | typedef struct { 86 | union { 87 | struct { 88 | uint8_t left : 1; 89 | uint8_t right : 1; 90 | uint8_t mid : 1; 91 | uint8_t : 5; 92 | }; 93 | uint8_t buttons; 94 | }; 95 | uint8_t x; 96 | uint8_t y; 97 | uint8_t wheel; 98 | }HID_MouseReportType; 99 | 100 | /** @} */ 101 | 102 | #endif /* __HID_MOUSE_H_ */ 103 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/usage_led.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usage_led.h 4 | * @author Benedek Kupper 5 | * @version 0.1 6 | * @date 2018-01-31 7 | * @brief USB Human Interface Device Class 8 | * LED Usage Page definitions 9 | * 10 | * Copyright (c) 2018 Benedek Kupper 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | #ifndef __HID_USAGE_LED_H_ 25 | #define __HID_USAGE_LED_H_ 26 | #include 27 | 28 | #define HID_USAGE_PAGE_LED HID_ITEM_1(0x0, GLOBAL, 0x08) 29 | 30 | /* General device indicators */ 31 | #define HID_USAGE_LED_POWER HID_USAGE_1(0x06) 32 | #define HID_USAGE_LED_BATTERY_OP HID_USAGE_1(0x1B) 33 | #define HID_USAGE_LED_BATTERY_OK HID_USAGE_1(0x1C) 34 | #define HID_USAGE_LED_BATTERY_LOW HID_USAGE_1(0x1D) 35 | #define HID_USAGE_LED_STANDBY HID_USAGE_1(0x27) 36 | #define HID_USAGE_LED_ONLINE HID_USAGE_1(0x2A) 37 | #define HID_USAGE_LED_OFFLINE HID_USAGE_1(0x2B) 38 | #define HID_USAGE_LED_BUSY HID_USAGE_1(0x2C) 39 | #define HID_USAGE_LED_READY HID_USAGE_1(0x2D) 40 | #define HID_USAGE_LED_ERROR HID_USAGE_1(0x39) 41 | #define HID_USAGE_LED_SUSPEND HID_USAGE_1(0x4C) 42 | #define HID_USAGE_LED_EXT_POWERED HID_USAGE_1(0x4D) 43 | 44 | #define HID_USAGE_LED_SELECTED HID_USAGE_1(0x3A) 45 | #define HID_USAGE_LED_IN_USE HID_USAGE_1(0x3B) 46 | #define HID_USAGE_LED_MULTI_MODE HID_USAGE_1(0x3C) 47 | #define HID_USAGE_LED_MODE_ON HID_USAGE_1(0x3D) 48 | #define HID_USAGE_LED_MODE_FLASH HID_USAGE_1(0x3E) 49 | #define HID_USAGE_LED_MODE_SLOW_BLINK HID_USAGE_1(0x3F) 50 | #define HID_USAGE_LED_MODE_FAST_BLINK HID_USAGE_1(0x40) 51 | #define HID_USAGE_LED_MODE_OFF HID_USAGE_1(0x41) 52 | #define HID_USAGE_LED_TIME_FLASH_ON HID_USAGE_1(0x42) 53 | #define HID_USAGE_LED_TIME_SLOW_BLINK_ON HID_USAGE_1(0x43) 54 | #define HID_USAGE_LED_TIME_SLOW_BLINK_OFF HID_USAGE_1(0x44) 55 | #define HID_USAGE_LED_TIME_FAST_BLINK_ON HID_USAGE_1(0x45) 56 | #define HID_USAGE_LED_TIME_FAST_BLINK_OFF HID_USAGE_1(0x46) 57 | #define HID_USAGE_LED_COLOR HID_USAGE_1(0x47) 58 | #define HID_USAGE_LED_COLOR_RED HID_USAGE_1(0x48) 59 | #define HID_USAGE_LED_COLOR_GREEN HID_USAGE_1(0x49) 60 | #define HID_USAGE_LED_COLOR_AMBER HID_USAGE_1(0x4A) 61 | 62 | /* Keyboard indicators */ 63 | #define HID_USAGE_LED_NUMLOCK HID_USAGE_1(0x01) 64 | #define HID_USAGE_LED_CAPSLOCK HID_USAGE_1(0x02) 65 | #define HID_USAGE_LED_SCROLLLOCK HID_USAGE_1(0x03) 66 | 67 | /* Consumer indicators */ 68 | #define HID_USAGE_LED_MUTE HID_USAGE_1(0x09) 69 | #define HID_USAGE_LED_CAMERA_ON HID_USAGE_1(0x28) 70 | #define HID_USAGE_LED_CAMERA_OFF HID_USAGE_1(0x29) 71 | 72 | /* Telephony indicators */ 73 | #define HID_USAGE_LED_MICROPHONE HID_USAGE_1(0x21) 74 | 75 | /* Media transport indicators */ 76 | #define HID_USAGE_LED_FORWARD HID_USAGE_1(0x31) 77 | #define HID_USAGE_LED_REVERSE HID_USAGE_1(0x32) 78 | #define HID_USAGE_LED_STOP HID_USAGE_1(0x33) 79 | #define HID_USAGE_LED_REWIND HID_USAGE_1(0x34) 80 | #define HID_USAGE_LED_FFWD HID_USAGE_1(0x35) 81 | #define HID_USAGE_LED_PLAY HID_USAGE_1(0x36) 82 | #define HID_USAGE_LED_PAUSE HID_USAGE_1(0x37) 83 | 84 | 85 | #endif /* __HID_USAGE_LED_H_ */ 86 | -------------------------------------------------------------------------------- /HID_template/hardware/pid.c: -------------------------------------------------------------------------------- 1 | #include "pid.h" 2 | #include "math.h" 3 | 4 | 5 | void abs_limit(float *a, float ABS_MAX) 6 | { 7 | if (*a > ABS_MAX) 8 | *a = ABS_MAX; 9 | if (*a < -ABS_MAX) 10 | *a = -ABS_MAX; 11 | } 12 | 13 | static void pid_param_init( 14 | pid_t* pid, 15 | uint32_t mode, 16 | uint32_t maxout, 17 | uint32_t intergral_limit, 18 | float kp, 19 | float ki, 20 | float kd) 21 | { 22 | 23 | pid->integral_limit = intergral_limit; 24 | pid->max_out = maxout; 25 | pid->pid_mode = mode; 26 | 27 | pid->p = kp; 28 | pid->i = ki; 29 | pid->d = kd; 30 | 31 | } 32 | /** 33 | * @brief modify pid parameter when code running 34 | * @param[in] pid: control pid struct 35 | * @param[in] p/i/d: pid parameter 36 | * @retval none 37 | */ 38 | static void pid_reset(pid_t *pid, float kp, float ki, float kd) 39 | { 40 | pid->p = kp; 41 | pid->i = ki; 42 | pid->d = kd; 43 | 44 | pid->pout = 0; 45 | pid->iout = 0; 46 | pid->dout = 0; 47 | pid->out = 0; 48 | 49 | } 50 | 51 | /** 52 | * @brief calculate delta PID and position PID 53 | * @param[in] pid: control pid struct 54 | * @param[in] get: measure feedback value 55 | * @param[in] set: target value 56 | * @retval pid calculate output 57 | */ 58 | float pid_calc(pid_t *pid, float get, float set) 59 | { 60 | pid->get = get; 61 | pid->set = set; 62 | pid->err[NOW] = set - get; 63 | 64 | if ((pid->input_max_err != 0) && (fabs(pid->err[NOW]) > pid->input_max_err)) 65 | return 0; 66 | 67 | if (pid->pid_mode == POSITION_PID) //position PID 68 | { 69 | pid->pout = pid->p * pid->err[NOW]; 70 | pid->iout += pid->i * pid->err[NOW]; 71 | pid->dout = pid->d * (pid->err[NOW] - pid->err[LAST]); 72 | 73 | abs_limit(&(pid->iout), pid->integral_limit); 74 | pid->out = pid->pout + pid->iout + pid->dout; 75 | abs_limit(&(pid->out), pid->max_out); 76 | } 77 | else if (pid->pid_mode == DELTA_PID) //delta PID 78 | { 79 | pid->pout = pid->p * (pid->err[NOW] - pid->err[LAST]); 80 | pid->iout = pid->i * pid->err[NOW]; 81 | pid->dout = pid->d * (pid->err[NOW] - 2 * pid->err[LAST] + pid->err[LLAST]); 82 | 83 | pid->out += pid->pout + pid->iout + pid->dout; 84 | abs_limit(&(pid->out), pid->max_out); 85 | } 86 | 87 | pid->err[LLAST] = pid->err[LAST]; 88 | pid->err[LAST] = pid->err[NOW]; 89 | 90 | 91 | if ((pid->output_deadband != 0) && (fabs(pid->out) < pid->output_deadband)) 92 | return 0; 93 | else 94 | return pid->out; 95 | 96 | } 97 | /** 98 | * @brief initialize pid parameter 99 | * @retval none 100 | */ 101 | void PID_struct_init( 102 | pid_t* pid, 103 | uint32_t mode, 104 | uint32_t maxout, 105 | uint32_t intergral_limit, 106 | 107 | float kp, 108 | float ki, 109 | float kd) 110 | { 111 | pid->f_param_init = pid_param_init; 112 | pid->f_pid_reset = pid_reset; 113 | 114 | pid->f_param_init(pid, mode, maxout, intergral_limit, kp, ki, kd); 115 | pid->f_pid_reset(pid, kp, ki, kd); 116 | } 117 | 118 | /** 119 | * @brief calculate position PID 120 | * @param[in] pid: control pid struct 121 | * @param[in] get: measure feedback value 122 | * @param[in] set: target value 123 | * @retval pid calculate output 124 | */ 125 | float position_pid_calc(pid_t *pid, float get, float set) 126 | { 127 | pid->get = get; 128 | pid->set = set; 129 | pid->err[NOW] = set - get; 130 | pid->pout = pid->p * pid->err[NOW]; 131 | pid->iout += pid->i * pid->err[NOW]; 132 | pid->dout = pid->d * (pid->err[NOW] - pid->err[LAST]); 133 | abs_limit(&(pid->iout), pid->integral_limit); 134 | pid->out = pid->pout + pid->iout + pid->dout; 135 | abs_limit(&(pid->out), pid->max_out); 136 | 137 | pid->err[LLAST] = pid->err[LAST]; 138 | pid->err[LAST] = pid->err[NOW]; 139 | return pid->out; 140 | } 141 | 142 | pid_t pid_x; 143 | pid_t pid_y; 144 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/usage_keyboard.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usage_keyboard.h 4 | * @author Benedek Kupper 5 | * @version 0.1 6 | * @date 2018-01-31 7 | * @brief USB Human Interface Device Class 8 | * Keyboard Usage Page definitions 9 | * 10 | * Copyright (c) 2018 Benedek Kupper 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | #ifndef __HID_USAGE_KEYBOARD_H_ 25 | #define __HID_USAGE_KEYBOARD_H_ 26 | #include 27 | 28 | #define HID_USAGE_PAGE_KEYBOARD HID_ITEM_1(0x0, GLOBAL, 0x07) 29 | 30 | /* HID key enumeration (doesn't contain modifier keys) */ 31 | typedef enum { 32 | KNone = 0, 33 | KErrorRollOver, 34 | KErrorPOSTFail, 35 | KErrorUndefined, 36 | Ka, 37 | Kb, 38 | Kc, 39 | Kd, 40 | Ke, 41 | Kf, 42 | Kg, 43 | Kh, 44 | Ki, 45 | Kj, 46 | Kk, 47 | Kl, 48 | Km, 49 | Kn, 50 | Ko, 51 | Kp, 52 | Kq, 53 | Kr, 54 | Ks, 55 | Kt, 56 | Ku, 57 | Kv, 58 | Kw, 59 | Kx, 60 | Ky, 61 | Kz, 62 | K1, 63 | K2, 64 | K3, 65 | K4, 66 | K5, 67 | K6, 68 | K7, 69 | K8, 70 | K9, 71 | K0, 72 | KEnter, 73 | KEsc, 74 | KBackspace, 75 | KTab, 76 | KSpace, 77 | KMinusUnderscore, 78 | KEqualPlus, 79 | KLeftBrace, 80 | KRightBrace, 81 | KBackslashPipe, 82 | KHashTilde, 83 | KSemiColon, 84 | KApostrophe, 85 | KGrave, 86 | KCommaLessthan, 87 | KDotGreaterthan, 88 | KSlashQuestionmark, 89 | KCapsLock, 90 | KF1, 91 | KF2, 92 | KF3, 93 | KF4, 94 | KF5, 95 | KF6, 96 | KF7, 97 | KF8, 98 | KF9, 99 | KF10, 100 | KF11, 101 | KF12, 102 | KPrintscreenSysrq, 103 | KScrollLock, 104 | KPause, 105 | KInsert, 106 | KHome, 107 | KPageup, 108 | KDelete, 109 | KEnd, 110 | KPagedown, 111 | KRight, 112 | KLeft, 113 | KDown, 114 | KUp, 115 | KNumLock, 116 | KPSlash, 117 | KPAsterisk, 118 | KPMinus, 119 | KPPlus, 120 | KPEnter, 121 | KP1, 122 | KP2, 123 | KP3, 124 | KP4, 125 | KP5, 126 | KP6, 127 | KP7, 128 | KP8, 129 | KP9, 130 | KP0, 131 | KPDot, 132 | KLessGreaterthan, 133 | KApplication, 134 | KPower, /* = 0x66 */ 135 | 136 | KOpen = 0x74, 137 | KHelp, 138 | KProps, 139 | KFront, 140 | KStop, 141 | KAgain, 142 | KUndo, 143 | KCut, 144 | KCopy, 145 | KPaste, 146 | KFind, 147 | KMute, 148 | KVolumeUp, 149 | KVolumeDown, /* = 0x81 */ 150 | 151 | KLeftCtrl = 0xE0, 152 | KLeftShift, 153 | KLeftAlt, 154 | KLeftGUI, 155 | KRightCtrl, 156 | KRightShift, 157 | KRightAlt, 158 | KRightGUI, 159 | 160 | KMediaPlayPause = 0xE8, 161 | KMediaPrevious = 0xEA, 162 | KMediaNext, 163 | KMediaEject, 164 | KMediaVolumeUp, 165 | KMediaVolumeDown, 166 | KMediaMute, 167 | KMediaBack = 0xF1, 168 | KMediaForward, 169 | KMediaStop, 170 | }HID_KeyType; 171 | 172 | 173 | typedef enum { 174 | MLeftCtrl = 0x01, 175 | MLeftShift = 0x02, 176 | MLeftAlt = 0x04, 177 | MLeftGUI = 0x08, 178 | MRightCtrl = 0x10, 179 | MRightShift = 0x20, 180 | MRightAlt = 0x40, 181 | MRightGUI = 0x80, 182 | }HID_KeyModifierType; 183 | 184 | 185 | #endif /* __HID_USAGE_KEYBOARD_H_ */ 186 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/keyboard.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file keyboard.h 4 | * @author Benedek Kupper 5 | * @version 0.1 6 | * @date 2018-09-04 7 | * @brief USB Human Interface Device Class 8 | * Keyboard report definitions 9 | * 10 | * Copyright (c) 2018 Benedek Kupper 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | #ifndef __HID_KEYBOARD_H_ 25 | #define __HID_KEYBOARD_H_ 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | /** @ingroup USBD_HID 32 | * @addtogroup USBD_HID_Common_Reports Common HID Reports 33 | * @{ */ 34 | 35 | /** @brief HID keyboard report descriptor */ 36 | #define HID_KEYBOARD_REPORT_DESC(...) \ 37 | HID_USAGE_PAGE_DESKTOP, \ 38 | HID_USAGE_DT_KEYBOARD, \ 39 | HID_COLLECTION_APPLICATION( \ 40 | HID_USAGE_PAGE_KEYBOARD, \ 41 | /* Key modifier flags */ \ 42 | HID_USAGE_MIN_8(KLeftCtrl), \ 43 | HID_USAGE_MAX_8(KRightGUI), \ 44 | HID_LOGICAL_MIN_8(0), \ 45 | HID_LOGICAL_MAX_8(1), \ 46 | HID_REPORT_SIZE(1), \ 47 | HID_REPORT_COUNT(8), \ 48 | HID_INPUT(Data_Var_Abs), \ 49 | /* Reserved byte */ \ 50 | HID_REPORT_SIZE(8), \ 51 | HID_REPORT_COUNT(1), \ 52 | HID_INPUT(Const_Arr_Abs), \ 53 | /* 6 keys buffer */ \ 54 | HID_USAGE_MIN_8(KNone), \ 55 | HID_USAGE_MAX_8(KApplication), \ 56 | HID_LOGICAL_MIN_8(KNone), \ 57 | HID_LOGICAL_MAX_8(KApplication),\ 58 | HID_REPORT_SIZE(8), \ 59 | HID_REPORT_COUNT(6), \ 60 | HID_INPUT(Data_Arr_Abs), \ 61 | __VA_ARGS__) 62 | 63 | 64 | /** @brief LED indicator extension for @ref HID_KEYBOARD_REPORT_DESC */ 65 | #define HID_KEYBOARD_LED_DESC \ 66 | HID_USAGE_PAGE_LED, \ 67 | /* LED indicators */ \ 68 | HID_USAGE_MIN_8(1), \ 69 | HID_USAGE_MAX_8(5), \ 70 | HID_REPORT_SIZE(1), \ 71 | HID_REPORT_COUNT(5), \ 72 | HID_OUTPUT(Data_Var_Abs), \ 73 | HID_REPORT_SIZE(3), \ 74 | HID_REPORT_COUNT(1), \ 75 | HID_OUTPUT(Const_Arr_Abs), 76 | 77 | 78 | /** @brief HID keyboard IN report layout */ 79 | typedef struct { 80 | union { 81 | struct { 82 | uint8_t lctrl : 1; 83 | uint8_t lshift : 1; 84 | uint8_t lalt : 1; 85 | uint8_t lgui : 1; 86 | uint8_t rctrl : 1; 87 | uint8_t rshift : 1; 88 | uint8_t ralt : 1; 89 | uint8_t rgui : 1; 90 | }; 91 | uint8_t mod; 92 | }; 93 | uint8_t reserved; 94 | uint8_t key[6]; 95 | }HID_KeyReportType; 96 | 97 | 98 | /** @brief HID keyboard OUT report layout (LEDs for ~locks) */ 99 | typedef union { 100 | struct { 101 | uint8_t num : 1; 102 | uint8_t caps : 1; 103 | uint8_t scroll : 1; 104 | uint8_t compose : 1; 105 | uint8_t kana : 1; 106 | uint8_t : 3; 107 | }; 108 | uint8_t b; 109 | }HID_KeyLedReportType; 110 | 111 | /** @} */ 112 | 113 | #endif /* __HID_KEYBOARD_H_ */ 114 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/usage_lighting.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usage_lighting.h 4 | * @author Benedek Kupper 5 | * @version 0.1 6 | * @date 2018-01-31 7 | * @brief USB Human Interface Device Class 8 | * Lighting and Illumination Usage Page definitions 9 | * 10 | * Copyright (c) 2018 Benedek Kupper 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | #ifndef __HID_USAGE_LIGHITNG_H_ 25 | #define __HID_USAGE_LIGHITNG_H_ 26 | #include 27 | 28 | #define HID_USAGE_PAGE_LIGHTING HID_ITEM_1(0x0, GLOBAL, 0x59) 29 | 30 | #define HID_USAGE_LI_LAMPARRAY HID_USAGE_1(0x01) 31 | 32 | #define HID_USAGE_LI_LA_ATTR_REPORT HID_USAGE_1(0x02) 33 | #define HID_USAGE_LI_LAMPCOUNT HID_USAGE_1(0x03) 34 | #define HID_USAGE_LI_BOUNDINGBOX_X HID_USAGE_1(0x04) /* In micrometers */ 35 | #define HID_USAGE_LI_BOUNDINGBOX_Y HID_USAGE_1(0x05) /* In micrometers */ 36 | #define HID_USAGE_LI_BOUNDINGBOX_Z HID_USAGE_1(0x06) /* In micrometers */ 37 | #define HID_USAGE_LI_LA_KIND HID_USAGE_1(0x07) 38 | typedef enum { 39 | LampArrayKindKeyboard = 1, 40 | LampArrayKindMouse, 41 | LampArrayKindGameController, 42 | LampArrayKindPeripheral, 43 | LampArrayKindScene, 44 | LampArrayKindNotification, 45 | LampArrayKindChassis, 46 | LampArrayKindWearable, 47 | LampArrayKindFurniture, 48 | LampArrayKindArt, 49 | }LampArrayKind_t; 50 | #define HID_USAGE_LI_MIN_UPDATE_INTERVAL HID_USAGE_1(0x08) /* In microseconds */ 51 | 52 | #define HID_USAGE_LI_LAMP_ATTR_REQ_REPORT HID_USAGE_1(0x20) 53 | #define HID_USAGE_LI_LAMPID HID_USAGE_1(0x21) 54 | 55 | #define HID_USAGE_LI_LAMP_ATTR_RESP_REPORT HID_USAGE_1(0x22) 56 | #define HID_USAGE_LI_POSITION_X HID_USAGE_1(0x23) /* In micrometers */ 57 | #define HID_USAGE_LI_POSITION_Y HID_USAGE_1(0x24) /* In micrometers */ 58 | #define HID_USAGE_LI_POSITION_Z HID_USAGE_1(0x25) /* In micrometers */ 59 | #define HID_USAGE_LI_LAMP_PURPOSES HID_USAGE_1(0x26) 60 | typedef enum { 61 | LampPurposeControl = 0x01, 62 | LampPurposeAccent = 0x02, 63 | LampPurposeBranding = 0x04, 64 | LampPurposeStatus = 0x08, 65 | LampPurposeIllumination = 0x10, 66 | LampPurposePresentation = 0x20, 67 | }LampPurpose_t; 68 | #define HID_USAGE_LI_UPDATE_LATENCY HID_USAGE_1(0x27) /* In microseconds */ 69 | #define HID_USAGE_LI_RED_LEVEL_COUNT HID_USAGE_1(0x28) 70 | #define HID_USAGE_LI_GREEN_LEVEL_COUNT HID_USAGE_1(0x29) 71 | #define HID_USAGE_LI_BLUE_LEVEL_COUNT HID_USAGE_1(0x2A) 72 | #define HID_USAGE_LI_INTENSITY_LEVEL_COUNT HID_USAGE_1(0x2B) 73 | #define HID_USAGE_LI_PROGRAMMABLE HID_USAGE_1(0x2C) 74 | 75 | #define HID_USAGE_LI_LAMP_MULTI_UPDATE_REPORT HID_USAGE_1(0x50) 76 | #define HID_USAGE_LI_RED_UPDATE_CHANNEL HID_USAGE_1(0x51) 77 | #define HID_USAGE_LI_GREEN_UPDATE_CHANNEL HID_USAGE_1(0x52) 78 | #define HID_USAGE_LI_BLUE_UPDATE_CHANNEL HID_USAGE_1(0x53) 79 | #define HID_USAGE_LI_INTENSITY_UPDATE_CHANNEL HID_USAGE_1(0x54) 80 | #define HID_USAGE_LI_LAMP_UPDATE_FLAGS HID_USAGE_1(0x55) 81 | typedef enum { 82 | LampUpdateComplete = 0x01, 83 | }LampUpdateFlags_t; 84 | 85 | #define HID_USAGE_LI_LAMP_RANGE_UPDATE_REPORT HID_USAGE_1(0x60) 86 | #define HID_USAGE_LI_LAMPID_START HID_USAGE_1(0x61) 87 | #define HID_USAGE_LI_LAMPID_END HID_USAGE_1(0x62) 88 | 89 | #define HID_USAGE_LI_LA_CTRL_REPORT HID_USAGE_1(0x70) 90 | #define HID_USAGE_LI_AUTONOMOUS_MODE HID_USAGE_1(0x71) 91 | 92 | #endif /* __HID_USAGE_LIGHITNG_H_ */ 93 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/usage_consumer.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usage_consumer.h 4 | * @author Benedek Kupper 5 | * @version 0.1 6 | * @date 2018-11-18 7 | * @brief USB Human Interface Device Class 8 | * Consumer Usage Page definitions 9 | * 10 | * Copyright (c) 2018 Benedek Kupper 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | #ifndef __HID_USAGE_CONSUMER_H_ 25 | #define __HID_USAGE_CONSUMER_H_ 26 | #include 27 | 28 | #define HID_USAGE_PAGE_CONSUMER HID_ITEM_1(0x0, GLOBAL, 0x0C) 29 | 30 | #define HID_USAGE_CMR_CONSUMER_CTRL HID_USAGE_1(0x01) 31 | #define HID_USAGE_CMR_NUM_KEYPAD HID_USAGE_1(0x02) 32 | #define HID_USAGE_CMR_PROG_BUTTONS HID_USAGE_1(0x03) 33 | #define HID_USAGE_CMR_MICROPHONE HID_USAGE_1(0x04) 34 | #define HID_USAGE_CMR_HEADPHONE HID_USAGE_1(0x05) 35 | #define HID_USAGE_CMR_GRAPHIC_EQ HID_USAGE_1(0x06) 36 | 37 | /* General controls */ 38 | #define HID_USAGE_CMR_POWER HID_USAGE_1(0x30) 39 | #define HID_USAGE_CMR_RESET HID_USAGE_1(0x31) 40 | #define HID_USAGE_CMR_SLEEP HID_USAGE_1(0x32) 41 | #define HID_USAGE_CMR_SLEEP_AFTER HID_USAGE_1(0x33) 42 | #define HID_USAGE_CMR_SLEEP_MODE HID_USAGE_1(0x34) 43 | #define HID_USAGE_CMR_ILLUMINATION HID_USAGE_1(0x35) 44 | #define HID_USAGE_CMR_FUNCTION_BUTTONS HID_USAGE_1(0x36) 45 | 46 | /* Menu controls */ 47 | #define HID_USAGE_CMR_MENU HID_USAGE_1(0x40) 48 | #define HID_USAGE_CMR_MENU_PICK HID_USAGE_1(0x41) 49 | #define HID_USAGE_CMR_MENU_UP HID_USAGE_1(0x42) 50 | #define HID_USAGE_CMR_MENU_DOWN HID_USAGE_1(0x43) 51 | #define HID_USAGE_CMR_MENU_LEFT HID_USAGE_1(0x44) 52 | #define HID_USAGE_CMR_MENU_RIGHT HID_USAGE_1(0x45) 53 | #define HID_USAGE_CMR_MENU_ESC HID_USAGE_1(0x46) 54 | #define HID_USAGE_CMR_MENU_VALUE_INC HID_USAGE_1(0x47) 55 | #define HID_USAGE_CMR_MENU_VALUE_DEC HID_USAGE_1(0x48) 56 | 57 | /* Transport controls */ 58 | #define HID_USAGE_CMR_PLAY HID_USAGE_1(0xB0) 59 | #define HID_USAGE_CMR_PAUSE HID_USAGE_1(0xB1) 60 | #define HID_USAGE_CMR_PLAY_PAUSE HID_USAGE_1(0xCD) 61 | #define HID_USAGE_CMR_PLAY_SKIP HID_USAGE_1(0xCE) 62 | #define HID_USAGE_CMR_RECORD HID_USAGE_1(0xB2) 63 | #define HID_USAGE_CMR_FFWD HID_USAGE_1(0xB3) 64 | #define HID_USAGE_CMR_REWIND HID_USAGE_1(0xB4) 65 | #define HID_USAGE_CMR_SCAN_NEXT HID_USAGE_1(0xB5) 66 | #define HID_USAGE_CMR_SCAN_PREV HID_USAGE_1(0xB6) 67 | #define HID_USAGE_CMR_STOP HID_USAGE_1(0xB7) 68 | #define HID_USAGE_CMR_EJECT HID_USAGE_1(0xB8) 69 | #define HID_USAGE_CMR_STOP_EJECT HID_USAGE_1(0xCC) 70 | #define HID_USAGE_CMR_SHUFFLE HID_USAGE_1(0xB9) 71 | #define HID_USAGE_CMR_REPEAT HID_USAGE_1(0xBC) 72 | 73 | /* Audio controls */ 74 | #define HID_USAGE_CMR_VOLUME HID_USAGE_1(0xE0) 75 | #define HID_USAGE_CMR_VOLUME_INC HID_USAGE_1(0xE9) 76 | #define HID_USAGE_CMR_VOLUME_DEC HID_USAGE_1(0xEA) 77 | #define HID_USAGE_CMR_BALANCE HID_USAGE_1(0xE1) 78 | #define HID_USAGE_CMR_BALANCE_RIGHT HID_USAGE_2(0x0150) 79 | #define HID_USAGE_CMR_BALANCE_LEFT HID_USAGE_2(0x0151) 80 | #define HID_USAGE_CMR_MUTE HID_USAGE_1(0xE2) 81 | #define HID_USAGE_CMR_BASS HID_USAGE_1(0xE3) 82 | #define HID_USAGE_CMR_BASS_INC HID_USAGE_2(0x0152) 83 | #define HID_USAGE_CMR_BASS_DEC HID_USAGE_2(0x0153) 84 | #define HID_USAGE_CMR_TREBLE HID_USAGE_1(0xE4) 85 | #define HID_USAGE_CMR_TREBLE_INC HID_USAGE_2(0x0154) 86 | #define HID_USAGE_CMR_TREBLE_DEC HID_USAGE_2(0x0155) 87 | #define HID_USAGE_CMR_BASS_BOOST HID_USAGE_1(0xE5) 88 | 89 | 90 | #endif /* __HID_USAGE_CONSUMER_H_ */ 91 | -------------------------------------------------------------------------------- /HID_template/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_customhid.h 4 | * @author MCD Application Team 5 | * @brief header file for the usbd_customhid.c file. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USB_CUSTOMHID_H 22 | #define __USB_CUSTOMHID_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usbd_ioreq.h" 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_CUSTOM_HID 37 | * @brief This file is the Header file for USBD_customhid.c 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_CUSTOM_HID_Exported_Defines 42 | * @{ 43 | */ 44 | #define CUSTOM_HID_EPIN_ADDR 0x81U 45 | #define CUSTOM_HID_EPIN_SIZE 64U 46 | 47 | #define CUSTOM_HID_EPOUT_ADDR 0x01U 48 | #define CUSTOM_HID_EPOUT_SIZE 0x02U 49 | 50 | #define USB_CUSTOM_HID_CONFIG_DESC_SIZ 41U 51 | #define USB_CUSTOM_HID_DESC_SIZ 9U 52 | 53 | #ifndef CUSTOM_HID_HS_BINTERVAL 54 | #define CUSTOM_HID_HS_BINTERVAL 0x05U 55 | #endif /* CUSTOM_HID_HS_BINTERVAL */ 56 | 57 | #ifndef CUSTOM_HID_FS_BINTERVAL 58 | #define CUSTOM_HID_FS_BINTERVAL 0x05U 59 | #endif /* CUSTOM_HID_FS_BINTERVAL */ 60 | 61 | #ifndef USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 62 | #define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x02U 63 | #endif /* USBD_CUSTOMHID_OUTREPORT_BUF_SIZE */ 64 | #ifndef USBD_CUSTOM_HID_REPORT_DESC_SIZE 65 | #define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163U 66 | #endif /* USBD_CUSTOM_HID_REPORT_DESC_SIZE */ 67 | 68 | #define CUSTOM_HID_DESCRIPTOR_TYPE 0x21U 69 | #define CUSTOM_HID_REPORT_DESC 0x22U 70 | 71 | #define CUSTOM_HID_REQ_SET_PROTOCOL 0x0BU 72 | #define CUSTOM_HID_REQ_GET_PROTOCOL 0x03U 73 | 74 | #define CUSTOM_HID_REQ_SET_IDLE 0x0AU 75 | #define CUSTOM_HID_REQ_GET_IDLE 0x02U 76 | 77 | #define CUSTOM_HID_REQ_SET_REPORT 0x09U 78 | #define CUSTOM_HID_REQ_GET_REPORT 0x01U 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 84 | * @{ 85 | */ 86 | typedef enum 87 | { 88 | CUSTOM_HID_IDLE = 0U, 89 | CUSTOM_HID_BUSY, 90 | } CUSTOM_HID_StateTypeDef; 91 | 92 | typedef struct _USBD_CUSTOM_HID_Itf 93 | { 94 | uint8_t *pReport; 95 | int8_t (*Init)(void); 96 | int8_t (*DeInit)(void); 97 | int8_t (*OutEvent)(uint8_t event_idx, uint8_t state); 98 | 99 | } USBD_CUSTOM_HID_ItfTypeDef; 100 | 101 | typedef struct 102 | { 103 | uint8_t Report_buf[USBD_CUSTOMHID_OUTREPORT_BUF_SIZE]; 104 | uint32_t Protocol; 105 | uint32_t IdleState; 106 | uint32_t AltSetting; 107 | uint32_t IsReportAvailable; 108 | CUSTOM_HID_StateTypeDef state; 109 | } USBD_CUSTOM_HID_HandleTypeDef; 110 | /** 111 | * @} 112 | */ 113 | 114 | /** @defgroup USBD_CORE_Exported_Macros 115 | * @{ 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | /** @defgroup USBD_CORE_Exported_Variables 123 | * @{ 124 | */ 125 | 126 | extern USBD_ClassTypeDef USBD_CUSTOM_HID; 127 | #define USBD_CUSTOM_HID_CLASS &USBD_CUSTOM_HID 128 | /** 129 | * @} 130 | */ 131 | 132 | /** @defgroup USB_CORE_Exported_Functions 133 | * @{ 134 | */ 135 | uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev, 136 | uint8_t *report, 137 | uint16_t len); 138 | 139 | uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev, 140 | USBD_CUSTOM_HID_ItfTypeDef *fops); 141 | 142 | /** 143 | * @} 144 | */ 145 | 146 | #ifdef __cplusplus 147 | } 148 | #endif 149 | 150 | #endif /* __USB_CUSTOMHID_H */ 151 | /** 152 | * @} 153 | */ 154 | 155 | /** 156 | * @} 157 | */ 158 | 159 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 160 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_customhid.h 4 | * @author MCD Application Team 5 | * @brief header file for the usbd_customhid.c file. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USB_CUSTOMHID_H 22 | #define __USB_CUSTOMHID_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usbd_ioreq.h" 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_CUSTOM_HID 37 | * @brief This file is the Header file for USBD_customhid.c 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_CUSTOM_HID_Exported_Defines 42 | * @{ 43 | */ 44 | #define CUSTOM_HID_EPIN_ADDR 0x81U 45 | #define CUSTOM_HID_EPIN_SIZE 64U 46 | 47 | #define CUSTOM_HID_EPOUT_ADDR 0x01U 48 | #define CUSTOM_HID_EPOUT_SIZE 0x02U 49 | 50 | #define USB_CUSTOM_HID_CONFIG_DESC_SIZ 41U 51 | #define USB_CUSTOM_HID_DESC_SIZ 9U 52 | 53 | #ifndef CUSTOM_HID_HS_BINTERVAL 54 | #define CUSTOM_HID_HS_BINTERVAL 0x05U 55 | #endif /* CUSTOM_HID_HS_BINTERVAL */ 56 | 57 | #ifndef CUSTOM_HID_FS_BINTERVAL 58 | #define CUSTOM_HID_FS_BINTERVAL 0x05U 59 | #endif /* CUSTOM_HID_FS_BINTERVAL */ 60 | 61 | #ifndef USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 62 | #define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x02U 63 | #endif /* USBD_CUSTOMHID_OUTREPORT_BUF_SIZE */ 64 | #ifndef USBD_CUSTOM_HID_REPORT_DESC_SIZE 65 | #define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163U 66 | #endif /* USBD_CUSTOM_HID_REPORT_DESC_SIZE */ 67 | 68 | #define CUSTOM_HID_DESCRIPTOR_TYPE 0x21U 69 | #define CUSTOM_HID_REPORT_DESC 0x22U 70 | 71 | #define CUSTOM_HID_REQ_SET_PROTOCOL 0x0BU 72 | #define CUSTOM_HID_REQ_GET_PROTOCOL 0x03U 73 | 74 | #define CUSTOM_HID_REQ_SET_IDLE 0x0AU 75 | #define CUSTOM_HID_REQ_GET_IDLE 0x02U 76 | 77 | #define CUSTOM_HID_REQ_SET_REPORT 0x09U 78 | #define CUSTOM_HID_REQ_GET_REPORT 0x01U 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 84 | * @{ 85 | */ 86 | typedef enum 87 | { 88 | CUSTOM_HID_IDLE = 0U, 89 | CUSTOM_HID_BUSY, 90 | } CUSTOM_HID_StateTypeDef; 91 | 92 | typedef struct _USBD_CUSTOM_HID_Itf 93 | { 94 | uint8_t *pReport; 95 | int8_t (*Init)(void); 96 | int8_t (*DeInit)(void); 97 | int8_t (*OutEvent)(uint8_t event_idx, uint8_t state); 98 | 99 | } USBD_CUSTOM_HID_ItfTypeDef; 100 | 101 | typedef struct 102 | { 103 | uint8_t Report_buf[USBD_CUSTOMHID_OUTREPORT_BUF_SIZE]; 104 | uint32_t Protocol; 105 | uint32_t IdleState; 106 | uint32_t AltSetting; 107 | uint32_t IsReportAvailable; 108 | CUSTOM_HID_StateTypeDef state; 109 | } USBD_CUSTOM_HID_HandleTypeDef; 110 | /** 111 | * @} 112 | */ 113 | 114 | /** @defgroup USBD_CORE_Exported_Macros 115 | * @{ 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | /** @defgroup USBD_CORE_Exported_Variables 123 | * @{ 124 | */ 125 | 126 | extern USBD_ClassTypeDef USBD_CUSTOM_HID; 127 | #define USBD_CUSTOM_HID_CLASS &USBD_CUSTOM_HID 128 | /** 129 | * @} 130 | */ 131 | 132 | /** @defgroup USB_CORE_Exported_Functions 133 | * @{ 134 | */ 135 | uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev, 136 | uint8_t *report, 137 | uint16_t len); 138 | 139 | uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev, 140 | USBD_CUSTOM_HID_ItfTypeDef *fops); 141 | 142 | /** 143 | * @} 144 | */ 145 | 146 | #ifdef __cplusplus 147 | } 148 | #endif 149 | 150 | #endif /* __USB_CUSTOMHID_H */ 151 | /** 152 | * @} 153 | */ 154 | 155 | /** 156 | * @} 157 | */ 158 | 159 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 160 | -------------------------------------------------------------------------------- /HID_template/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_gpio_ex.c 4 | * @author MCD Application Team 5 | * @brief GPIO Extension HAL module driver. 6 | * This file provides firmware functions to manage the following 7 | * functionalities of the General Purpose Input/Output (GPIO) extension peripheral. 8 | * + Extended features functions 9 | * 10 | @verbatim 11 | ============================================================================== 12 | ##### GPIO Peripheral extension features ##### 13 | ============================================================================== 14 | [..] GPIO module on STM32F1 family, manage also the AFIO register: 15 | (+) Possibility to use the EVENTOUT Cortex feature 16 | 17 | ##### How to use this driver ##### 18 | ============================================================================== 19 | [..] This driver provides functions to use EVENTOUT Cortex feature 20 | (#) Configure EVENTOUT Cortex feature using the function HAL_GPIOEx_ConfigEventout() 21 | (#) Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEventout() 22 | (#) Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout() 23 | 24 | @endverbatim 25 | ****************************************************************************** 26 | * @attention 27 | * 28 | *

© Copyright (c) 2016 STMicroelectronics. 29 | * All rights reserved.

30 | * 31 | * This software component is licensed by ST under BSD 3-Clause license, 32 | * the "License"; You may not use this file except in compliance with the 33 | * License. You may obtain a copy of the License at: 34 | * opensource.org/licenses/BSD-3-Clause 35 | * 36 | ****************************************************************************** 37 | */ 38 | 39 | /* Includes ------------------------------------------------------------------*/ 40 | #include "stm32f1xx_hal.h" 41 | 42 | /** @addtogroup STM32F1xx_HAL_Driver 43 | * @{ 44 | */ 45 | 46 | /** @defgroup GPIOEx GPIOEx 47 | * @brief GPIO HAL module driver 48 | * @{ 49 | */ 50 | 51 | #ifdef HAL_GPIO_MODULE_ENABLED 52 | 53 | /** @defgroup GPIOEx_Exported_Functions GPIOEx Exported Functions 54 | * @{ 55 | */ 56 | 57 | /** @defgroup GPIOEx_Exported_Functions_Group1 Extended features functions 58 | * @brief Extended features functions 59 | * 60 | @verbatim 61 | ============================================================================== 62 | ##### Extended features functions ##### 63 | ============================================================================== 64 | [..] This section provides functions allowing to: 65 | (+) Configure EVENTOUT Cortex feature using the function HAL_GPIOEx_ConfigEventout() 66 | (+) Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEventout() 67 | (+) Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout() 68 | 69 | @endverbatim 70 | * @{ 71 | */ 72 | 73 | /** 74 | * @brief Configures the port and pin on which the EVENTOUT Cortex signal will be connected. 75 | * @param GPIO_PortSource Select the port used to output the Cortex EVENTOUT signal. 76 | * This parameter can be a value of @ref GPIOEx_EVENTOUT_PORT. 77 | * @param GPIO_PinSource Select the pin used to output the Cortex EVENTOUT signal. 78 | * This parameter can be a value of @ref GPIOEx_EVENTOUT_PIN. 79 | * @retval None 80 | */ 81 | void HAL_GPIOEx_ConfigEventout(uint32_t GPIO_PortSource, uint32_t GPIO_PinSource) 82 | { 83 | /* Verify the parameters */ 84 | assert_param(IS_AFIO_EVENTOUT_PORT(GPIO_PortSource)); 85 | assert_param(IS_AFIO_EVENTOUT_PIN(GPIO_PinSource)); 86 | 87 | /* Apply the new configuration */ 88 | MODIFY_REG(AFIO->EVCR, (AFIO_EVCR_PORT) | (AFIO_EVCR_PIN), (GPIO_PortSource) | (GPIO_PinSource)); 89 | } 90 | 91 | /** 92 | * @brief Enables the Event Output. 93 | * @retval None 94 | */ 95 | void HAL_GPIOEx_EnableEventout(void) 96 | { 97 | SET_BIT(AFIO->EVCR, AFIO_EVCR_EVOE); 98 | } 99 | 100 | /** 101 | * @brief Disables the Event Output. 102 | * @retval None 103 | */ 104 | void HAL_GPIOEx_DisableEventout(void) 105 | { 106 | CLEAR_BIT(AFIO->EVCR, AFIO_EVCR_EVOE); 107 | } 108 | 109 | /** 110 | * @} 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | #endif /* HAL_GPIO_MODULE_ENABLED */ 118 | 119 | /** 120 | * @} 121 | */ 122 | 123 | /** 124 | * @} 125 | */ 126 | 127 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 128 | -------------------------------------------------------------------------------- /HID_template/hid_dev/touch_screen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Ptisak 3 | * @Date: 2022-04-19 08:40:35 4 | * @LastEditors: Ptisak 5 | * @LastEditTime: 2023-03-11 18:21:33 6 | * @Version: 1.0 7 | */ 8 | #include "touch_screen.h" 9 | #include "stdlib.h" 10 | 11 | touch_inf ttouch_inf; 12 | touch_buff ttouch_buff; 13 | // touch_buff ttouch_buff_last; 14 | static int con_index; 15 | 16 | void touch_init(void) 17 | { 18 | memset(&ttouch_buff, 0X00, sizeof(ttouch_buff)); 19 | ttouch_buff.report_id = 0x04; 20 | // memset(&ttouch_buff_last, 0X00, sizeof(ttouch_buff)); 21 | touch_set_size(1920, 1080); 22 | } 23 | 24 | void send_touch_data(void) 25 | { 26 | static uint8_t k; 27 | k = 0; 28 | if (ttouch_inf.continue_function) 29 | { 30 | touch_continue_function(); 31 | } 32 | if (ttouch_inf.release < 0) 33 | { 34 | ttouch_buff.touch_flag = 1; 35 | } 36 | else if (ttouch_inf.release > 0) 37 | { 38 | ttouch_buff.touch_flag = 1; 39 | ttouch_inf.release--; 40 | } 41 | else if (ttouch_buff.touch_flag == 1) 42 | { 43 | k = 1; 44 | ttouch_buff.touch_flag = 0; 45 | } 46 | if (ttouch_buff.touch_flag || k != 0) 47 | { 48 | MY_USB_HID_SEND_REPORT((uint8_t *)&ttouch_buff, sizeof(ttouch_buff)); 49 | } 50 | } 51 | 52 | void touch_set_size(uint16_t x, uint16_t y) 53 | { 54 | ttouch_inf.x_max = x; 55 | ttouch_inf.y_max = y; 56 | ttouch_inf.x_scale = 4095.f / x; 57 | ttouch_inf.y_scale = 4095.f / y; 58 | } 59 | void touch_set_time(int16_t times_ms) 60 | { 61 | if (times_ms > 0) 62 | { 63 | times_ms /= SEND_DELAY; 64 | } 65 | ttouch_inf.release = times_ms; 66 | } 67 | void touch_set_pos(uint16_t x, uint16_t y) 68 | { 69 | // srand(HAL_GetTick()); 70 | ttouch_buff.x = (uint16_t)((x)*ttouch_inf.x_scale); 71 | ttouch_buff.y = (uint16_t)((y)*ttouch_inf.y_scale); 72 | } 73 | void touch_set_continue_function(int8_t s) 74 | { 75 | con_index = 0; 76 | ttouch_inf.continue_function = !!s; 77 | } 78 | 79 | __weak void touch_continue_function(void) 80 | { 81 | if (con_index == 0) 82 | { 83 | touch_set_time(-1); 84 | touch_set_pos(1009, 802); 85 | } 86 | else if (con_index == 2) 87 | { 88 | touch_set_time(-1); 89 | touch_set_pos(801, 781); 90 | } 91 | else 92 | { 93 | touch_set_time(0); 94 | } 95 | con_index = (con_index + 1) % 4; 96 | } 97 | 98 | // float get_rand(void) 99 | // { 100 | // return (rand() % 100) / 100.f; 101 | // } 102 | #if USING_SHELL 103 | void touch_cmd(int argc, char **argv) 104 | { 105 | static int32_t a, b, c; 106 | if (argc < 2) 107 | { 108 | rt_kprintf("Error\n"); 109 | return; 110 | } 111 | if (!strcmp(argv[1], "down")) 112 | { 113 | touch_set_time(-1); 114 | return; 115 | } 116 | else if (!strcmp(argv[1], "up")) 117 | { 118 | touch_set_time(0); 119 | return; 120 | } 121 | else if (!strcmp(argv[1], "pos")) 122 | { 123 | if (argc < 4) 124 | { 125 | rt_kprintf("Error\n"); 126 | return; 127 | } 128 | sscanf(argv[2], "%d", &a); 129 | sscanf(argv[3], "%d", &b); 130 | ; 131 | //_sscanf(argv[4], "%d", &c); 132 | 133 | touch_set_pos((uint16_t)(a), (uint16_t)(b)); 134 | return; 135 | } 136 | else if (!strcmp(argv[1], "tap")) 137 | { 138 | c = 13; 139 | if (argc == 4) 140 | { 141 | sscanf(argv[2], "%d", &a); 142 | sscanf(argv[3], "%d", &b); 143 | } 144 | else if (argc == 5) 145 | { 146 | sscanf(argv[2], "%d", &a); 147 | sscanf(argv[3], "%d", &b); 148 | sscanf(argv[4], "%d", &c); 149 | } 150 | else 151 | { 152 | rt_kprintf("Error\n"); 153 | return; 154 | } 155 | touch_set_pos((uint16_t)(a), (uint16_t)(b)); 156 | touch_set_time(c); 157 | return; 158 | } 159 | else if (!strcmp(argv[1], "size")) 160 | { 161 | if (argc < 4) 162 | { 163 | rt_kprintf("Error\n"); 164 | return; 165 | } 166 | sscanf(argv[2], "%d", &a); 167 | sscanf(argv[3], "%d", &b); 168 | // rt_kprintf("touch size\n"); 169 | touch_set_size((uint16_t)(a), (uint16_t)(b)); 170 | return; 171 | } 172 | return; 173 | } 174 | // SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_DISABLE_RETURN, touch, touch_cmd, test);// FINSH_FUNCTION_EXPORT_ALIAS(mouse_cmd, __cmd_mouse, mouse); 175 | 176 | // FINSH_FUNCTION_EXPORT_ALIAS(touch_cmd, __cmd_touch, touch screen); 177 | #endif 178 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/touch_screen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Ptisak 3 | * @Date: 2022-04-19 08:40:35 4 | * @LastEditors: Ptisak 5 | * @LastEditTime: 2022-04-20 14:24:13 6 | * @Version: 1.0 7 | */ 8 | #include "touch_screen.h" 9 | #include "stdlib.h" 10 | 11 | touch_inf ttouch_inf; 12 | touch_buff ttouch_buff; 13 | // touch_buff ttouch_buff_last; 14 | static int con_index; 15 | 16 | void touch_init(void) 17 | { 18 | memset(&ttouch_buff, 0X00, sizeof(ttouch_buff)); 19 | ttouch_buff.report_id = 0x04; 20 | // memset(&ttouch_buff_last, 0X00, sizeof(ttouch_buff)); 21 | touch_set_size(1920, 1080); 22 | } 23 | 24 | void send_touch_data(void) 25 | { 26 | static uint8_t k; 27 | k = 0; 28 | if (ttouch_inf.continue_function) 29 | { 30 | touch_continue_function(); 31 | } 32 | if (ttouch_inf.release < 0) 33 | { 34 | ttouch_buff.touch_flag = 1; 35 | } 36 | else if (ttouch_inf.release > 0) 37 | { 38 | ttouch_buff.touch_flag = 1; 39 | ttouch_inf.release--; 40 | } 41 | else if (ttouch_buff.touch_flag == 1) 42 | { 43 | k = 1; 44 | ttouch_buff.touch_flag = 0; 45 | } 46 | if (ttouch_buff.touch_flag || k != 0) 47 | { 48 | USBD_CUSTOM_HID_SendReport_FS((uint8_t *)&ttouch_buff, sizeof(ttouch_buff)); 49 | } 50 | } 51 | 52 | void touch_set_size(uint16_t x, uint16_t y) 53 | { 54 | ttouch_inf.x_max = x; 55 | ttouch_inf.y_max = y; 56 | ttouch_inf.x_scale = 4095.f / x; 57 | ttouch_inf.y_scale = 4095.f / y; 58 | } 59 | void touch_set_time(int16_t times_ms) 60 | { 61 | if (times_ms > 0) 62 | { 63 | times_ms /= SEND_DELAY; 64 | } 65 | ttouch_inf.release = times_ms; 66 | } 67 | void touch_set_pos(uint16_t x, uint16_t y) 68 | { 69 | // srand(HAL_GetTick()); 70 | ttouch_buff.x = (uint16_t)((x)*ttouch_inf.x_scale); 71 | ttouch_buff.y = (uint16_t)((y)*ttouch_inf.y_scale); 72 | } 73 | void touch_set_continue_function(int8_t s) 74 | { 75 | con_index = 0; 76 | ttouch_inf.continue_function = !!s; 77 | } 78 | 79 | __weak void touch_continue_function(void) 80 | { 81 | if (con_index == 0) 82 | { 83 | touch_set_time(-1); 84 | touch_set_pos(1009, 802); 85 | } 86 | else if (con_index == 2) 87 | { 88 | touch_set_time(-1); 89 | touch_set_pos(801, 781); 90 | } 91 | else 92 | { 93 | touch_set_time(0); 94 | } 95 | con_index = (con_index + 1) % 4; 96 | } 97 | 98 | // float get_rand(void) 99 | // { 100 | // return (rand() % 100) / 100.f; 101 | // } 102 | #if USING_SHELL 103 | void touch_cmd(int argc, char **argv) 104 | { 105 | static int32_t a, b, c; 106 | if (argc < 2) 107 | { 108 | rt_kprintf("Error\n"); 109 | return; 110 | } 111 | if (!strcmp(argv[1], "down")) 112 | { 113 | touch_set_time(-1); 114 | return; 115 | } 116 | else if (!strcmp(argv[1], "up")) 117 | { 118 | touch_set_time(0); 119 | return; 120 | } 121 | else if (!strcmp(argv[1], "pos")) 122 | { 123 | if (argc < 4) 124 | { 125 | rt_kprintf("Error\n"); 126 | return; 127 | } 128 | sscanf(argv[2], "%d", &a); 129 | sscanf(argv[3], "%d", &b); 130 | ; 131 | //_sscanf(argv[4], "%d", &c); 132 | 133 | touch_set_pos((uint16_t)(a), (uint16_t)(b)); 134 | return; 135 | } 136 | else if (!strcmp(argv[1], "tap")) 137 | { 138 | c = 13; 139 | if (argc == 4) 140 | { 141 | sscanf(argv[2], "%d", &a); 142 | sscanf(argv[3], "%d", &b); 143 | } 144 | else if (argc == 5) 145 | { 146 | sscanf(argv[2], "%d", &a); 147 | sscanf(argv[3], "%d", &b); 148 | sscanf(argv[4], "%d", &c); 149 | } 150 | else 151 | { 152 | rt_kprintf("Error\n"); 153 | return; 154 | } 155 | touch_set_pos((uint16_t)(a), (uint16_t)(b)); 156 | touch_set_time(c); 157 | return; 158 | } 159 | else if (!strcmp(argv[1], "size")) 160 | { 161 | if (argc < 4) 162 | { 163 | rt_kprintf("Error\n"); 164 | return; 165 | } 166 | sscanf(argv[2], "%d", &a); 167 | sscanf(argv[3], "%d", &b); 168 | // rt_kprintf("touch size\n"); 169 | touch_set_size((uint16_t)(a), (uint16_t)(b)); 170 | return; 171 | } 172 | return; 173 | } 174 | // SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_DISABLE_RETURN, touch, touch_cmd, test);// FINSH_FUNCTION_EXPORT_ALIAS(mouse_cmd, __cmd_mouse, mouse); 175 | 176 | // FINSH_FUNCTION_EXPORT_ALIAS(touch_cmd, __cmd_touch, touch screen); 177 | #endif 178 | -------------------------------------------------------------------------------- /HID_template/USB_DEVICE/Target/usbd_conf.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_conf.h 5 | * @version : v2.0_Cube 6 | * @brief : Header for usbd_conf.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __USBD_CONF__H__ 23 | #define __USBD_CONF__H__ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include 31 | #include 32 | #include 33 | #include "main.h" 34 | #include "stm32f1xx.h" 35 | #include "stm32f1xx_hal.h" 36 | 37 | /* USER CODE BEGIN INCLUDE */ 38 | 39 | /* USER CODE END INCLUDE */ 40 | 41 | /** @addtogroup USBD_OTG_DRIVER 42 | * @{ 43 | */ 44 | 45 | /** @defgroup USBD_CONF USBD_CONF 46 | * @brief Configuration file for Usb otg low level driver. 47 | * @{ 48 | */ 49 | 50 | /** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables 51 | * @brief Public variables. 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines 60 | * @brief Defines for configuration of the Usb device. 61 | * @{ 62 | */ 63 | 64 | /*---------- -----------*/ 65 | #define USBD_MAX_NUM_INTERFACES 1 66 | /*---------- -----------*/ 67 | #define USBD_MAX_NUM_CONFIGURATION 1 68 | /*---------- -----------*/ 69 | #define USBD_MAX_STR_DESC_SIZ 512 70 | /*---------- -----------*/ 71 | #define USBD_DEBUG_LEVEL 0 72 | /*---------- -----------*/ 73 | #define USBD_SELF_POWERED 1 74 | /*---------- -----------*/ 75 | #define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 64 76 | /*---------- -----------*/ 77 | #define USBD_CUSTOM_HID_REPORT_DESC_SIZE 251 78 | /*---------- -----------*/ 79 | #define CUSTOM_HID_FS_BINTERVAL 0x1 80 | 81 | /****************************************/ 82 | /* #define for FS and HS identification */ 83 | #define DEVICE_FS 0 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | /** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros 90 | * @brief Aliases. 91 | * @{ 92 | */ 93 | 94 | /* Memory management macros */ 95 | 96 | /** Alias for memory allocation. */ 97 | #define USBD_malloc (uint32_t *)USBD_static_malloc 98 | 99 | /** Alias for memory release. */ 100 | #define USBD_free USBD_static_free 101 | 102 | /** Alias for memory set. */ 103 | #define USBD_memset /* Not used */ 104 | 105 | /** Alias for memory copy. */ 106 | #define USBD_memcpy /* Not used */ 107 | 108 | /** Alias for delay. */ 109 | #define USBD_Delay HAL_Delay 110 | 111 | /* For footprint reasons and since only one allocation is handled in the HID class 112 | driver, the malloc/free is changed into a static allocation method */ 113 | void *USBD_static_malloc(uint32_t size); 114 | void USBD_static_free(void *p); 115 | 116 | /* DEBUG macros */ 117 | 118 | #if (USBD_DEBUG_LEVEL > 0) 119 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\ 120 | printf("\n"); 121 | #else 122 | #define USBD_UsrLog(...) 123 | #endif 124 | 125 | #if (USBD_DEBUG_LEVEL > 1) 126 | 127 | #define USBD_ErrLog(...) printf("ERROR: ") ;\ 128 | printf(__VA_ARGS__);\ 129 | printf("\n"); 130 | #else 131 | #define USBD_ErrLog(...) 132 | #endif 133 | 134 | #if (USBD_DEBUG_LEVEL > 2) 135 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\ 136 | printf(__VA_ARGS__);\ 137 | printf("\n"); 138 | #else 139 | #define USBD_DbgLog(...) 140 | #endif 141 | 142 | /** 143 | * @} 144 | */ 145 | 146 | /** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types 147 | * @brief Types. 148 | * @{ 149 | */ 150 | 151 | /** 152 | * @} 153 | */ 154 | 155 | /** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype 156 | * @brief Declaration of public functions for Usb device. 157 | * @{ 158 | */ 159 | 160 | /* Exported functions -------------------------------------------------------*/ 161 | 162 | /** 163 | * @} 164 | */ 165 | 166 | /** 167 | * @} 168 | */ 169 | 170 | /** 171 | * @} 172 | */ 173 | 174 | #ifdef __cplusplus 175 | } 176 | #endif 177 | 178 | #endif /* __USBD_CONF__H__ */ 179 | 180 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/USB_DEVICE/Target/usbd_conf.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_conf.h 5 | * @version : v2.0_Cube 6 | * @brief : Header for usbd_conf.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __USBD_CONF__H__ 23 | #define __USBD_CONF__H__ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include 31 | #include 32 | #include 33 | #include "main.h" 34 | #include "stm32f1xx.h" 35 | #include "stm32f1xx_hal.h" 36 | 37 | /* USER CODE BEGIN INCLUDE */ 38 | 39 | /* USER CODE END INCLUDE */ 40 | 41 | /** @addtogroup USBD_OTG_DRIVER 42 | * @{ 43 | */ 44 | 45 | /** @defgroup USBD_CONF USBD_CONF 46 | * @brief Configuration file for Usb otg low level driver. 47 | * @{ 48 | */ 49 | 50 | /** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables 51 | * @brief Public variables. 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines 60 | * @brief Defines for configuration of the Usb device. 61 | * @{ 62 | */ 63 | 64 | /*---------- -----------*/ 65 | #define USBD_MAX_NUM_INTERFACES 1 66 | /*---------- -----------*/ 67 | #define USBD_MAX_NUM_CONFIGURATION 1 68 | /*---------- -----------*/ 69 | #define USBD_MAX_STR_DESC_SIZ 512 70 | /*---------- -----------*/ 71 | #define USBD_DEBUG_LEVEL 0 72 | /*---------- -----------*/ 73 | #define USBD_SELF_POWERED 1 74 | /*---------- -----------*/ 75 | #define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 64 76 | /*---------- -----------*/ 77 | #define USBD_CUSTOM_HID_REPORT_DESC_SIZE 251 78 | /*---------- -----------*/ 79 | #define CUSTOM_HID_FS_BINTERVAL 0x1 80 | 81 | /****************************************/ 82 | /* #define for FS and HS identification */ 83 | #define DEVICE_FS 0 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | /** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros 90 | * @brief Aliases. 91 | * @{ 92 | */ 93 | 94 | /* Memory management macros */ 95 | 96 | /** Alias for memory allocation. */ 97 | #define USBD_malloc (uint32_t *)USBD_static_malloc 98 | 99 | /** Alias for memory release. */ 100 | #define USBD_free USBD_static_free 101 | 102 | /** Alias for memory set. */ 103 | #define USBD_memset /* Not used */ 104 | 105 | /** Alias for memory copy. */ 106 | #define USBD_memcpy /* Not used */ 107 | 108 | /** Alias for delay. */ 109 | #define USBD_Delay HAL_Delay 110 | 111 | /* For footprint reasons and since only one allocation is handled in the HID class 112 | driver, the malloc/free is changed into a static allocation method */ 113 | void *USBD_static_malloc(uint32_t size); 114 | void USBD_static_free(void *p); 115 | 116 | /* DEBUG macros */ 117 | 118 | #if (USBD_DEBUG_LEVEL > 0) 119 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\ 120 | printf("\n"); 121 | #else 122 | #define USBD_UsrLog(...) 123 | #endif 124 | 125 | #if (USBD_DEBUG_LEVEL > 1) 126 | 127 | #define USBD_ErrLog(...) printf("ERROR: ") ;\ 128 | printf(__VA_ARGS__);\ 129 | printf("\n"); 130 | #else 131 | #define USBD_ErrLog(...) 132 | #endif 133 | 134 | #if (USBD_DEBUG_LEVEL > 2) 135 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\ 136 | printf(__VA_ARGS__);\ 137 | printf("\n"); 138 | #else 139 | #define USBD_DbgLog(...) 140 | #endif 141 | 142 | /** 143 | * @} 144 | */ 145 | 146 | /** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types 147 | * @brief Types. 148 | * @{ 149 | */ 150 | 151 | /** 152 | * @} 153 | */ 154 | 155 | /** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype 156 | * @brief Declaration of public functions for Usb device. 157 | * @{ 158 | */ 159 | 160 | /* Exported functions -------------------------------------------------------*/ 161 | 162 | /** 163 | * @} 164 | */ 165 | 166 | /** 167 | * @} 168 | */ 169 | 170 | /** 171 | * @} 172 | */ 173 | 174 | #ifdef __cplusplus 175 | } 176 | #endif 177 | 178 | #endif /* __USBD_CONF__H__ */ 179 | 180 | -------------------------------------------------------------------------------- /HID_template/hid_dev/mouse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Ptisak 3 | * @Date: 2022-04-19 08:40:35 4 | * @LastEditors: Ptisak 5 | * @LastEditTime: 2023-03-11 15:40:53 6 | * @Version: Do not edit 7 | */ 8 | #include "mouse.h" 9 | 10 | #ifdef MOUSE_USING_PID 11 | #include "pid.h" 12 | #endif 13 | 14 | #include "stdlib.h" 15 | #include "math.h" 16 | 17 | Mouse_buff tMouse_buff; 18 | Mouse_buff tMouse_buff_last; 19 | 20 | mouse_state_t mouse_state; 21 | 22 | void mouse_init(void) 23 | { 24 | #ifdef MOUSE_USING_PID 25 | PID_struct_init(&pid_x, POSITION_PID, 100.f, 100.f, 0.6f, 0.0f, 0.2f); 26 | PID_struct_init(&pid_y, POSITION_PID, 100.f, 100.f, 0.6f, 0.0f, 0.2f); 27 | #endif 28 | memset(&tMouse_buff, 0X00, sizeof(tMouse_buff)); 29 | tMouse_buff.report_id = 0x02; 30 | memset(&mouse_state, 0X00, sizeof(mouse_state)); 31 | } 32 | 33 | void send_mouse_data(void) 34 | { 35 | static uint8_t i; 36 | 37 | if (mouse_state.continue_function) 38 | { 39 | mouse_continue_function(); 40 | } 41 | if (mouse_state.x == mouse_state.cur_x && mouse_state.y == mouse_state.cur_y) 42 | { 43 | tMouse_buff.mouse_rel_x = 0; 44 | tMouse_buff.mouse_rel_y = 0; 45 | } 46 | else 47 | { 48 | 49 | #ifdef MOUSE_USING_PID 50 | tMouse_buff.mouse_rel_x = (int8_t)pid_calc(&pid_x, mouse_state.cur_x, mouse_state.x); 51 | tMouse_buff.mouse_rel_y = (int8_t)pid_calc(&pid_y, mouse_state.cur_y, mouse_state.y); 52 | 53 | if (tMouse_buff.mouse_rel_x == 0 && tMouse_buff.mouse_rel_y == 0) 54 | { 55 | mouse_state.x = mouse_state.cur_x; 56 | mouse_state.y = mouse_state.cur_y; 57 | } 58 | #else 59 | tMouse_buff.mouse_rel_x = mouse_state.x - mouse_state.cur_x; 60 | tMouse_buff.mouse_rel_y = mouse_state.y - mouse_state.cur_y; 61 | #endif 62 | mouse_state.cur_x += tMouse_buff.mouse_rel_x; 63 | mouse_state.cur_y += tMouse_buff.mouse_rel_y; 64 | } 65 | for (i = 0; i < 3; i++) 66 | { 67 | if (mouse_state.key[i] > 0) 68 | { 69 | mouse_state.key[i]--; 70 | tMouse_buff.key |= 0x01u << i; 71 | } 72 | else if (mouse_state.key[i] < 0) 73 | { 74 | tMouse_buff.key |= 0x01u << i; 75 | } 76 | else 77 | { 78 | tMouse_buff.key &= ~(0x01u << i); 79 | mouse_state.key[i] = mouse_state.continue_key[i]; 80 | } 81 | } 82 | if (memcmp(&tMouse_buff_last, &tMouse_buff, sizeof(tMouse_buff)) == 0) 83 | { 84 | } 85 | else 86 | { 87 | memcpy(&tMouse_buff_last, &tMouse_buff, sizeof(tMouse_buff)); 88 | MY_USB_HID_SEND_REPORT((uint8_t *)&tMouse_buff, sizeof(tMouse_buff)); 89 | } 90 | } 91 | 92 | void mouse_set_continue_click(enum mouse_key key, int8_t time) 93 | { 94 | mouse_state.continue_key[key] = (uint8_t)time; 95 | } 96 | void mouse_set_click(enum mouse_key key, int8_t time) 97 | { 98 | mouse_state.key[key] = time; 99 | } 100 | void mouse_set_continue_function(int8_t s) 101 | { 102 | mouse_state.continue_function = !!s; 103 | } 104 | void mouse_move(int16_t x, int16_t y) 105 | { 106 | mouse_state.x = x; 107 | mouse_state.y = y; 108 | } 109 | int randint(int a, int b) 110 | { 111 | static int r; 112 | r = b - a; 113 | return ((rand() % r) + a); 114 | } 115 | void rand_reset(void) 116 | { 117 | srand(SysTick->VAL); 118 | } 119 | __weak void mouse_continue_function(void) 120 | { 121 | static float deg; 122 | static int r; 123 | deg += 0.22f; 124 | deg += (randint(0, 10)) * 0.01f; 125 | if (deg > 6.283f) 126 | { 127 | deg -= 6.283f; 128 | } 129 | r = randint(40, 50); 130 | mouse_state.x = cos(deg) * r; 131 | mouse_state.y = sin(deg) * r; 132 | } 133 | #if USING_SHELL 134 | void mouse_cmd(int argc, char **argv) 135 | { 136 | static int32_t a, b; 137 | if (argc < 2) 138 | { 139 | rt_kprintf("Error\n"); 140 | return; 141 | } 142 | if (!strcmp(argv[1], "down")) 143 | { 144 | return; 145 | } 146 | else if (!strcmp(argv[1], "up")) 147 | { 148 | return; 149 | } 150 | else if (!strcmp(argv[1], "move")) 151 | { 152 | if (argc < 4) 153 | { 154 | rt_kprintf("Error\n"); 155 | return; 156 | } 157 | sscanf(argv[2], "%d", &a); 158 | sscanf(argv[3], "%d", &b); 159 | mouse_state.x += a; 160 | mouse_state.y += b; 161 | return; 162 | } 163 | else if (!strcmp(argv[1], "tap")) 164 | { 165 | if (argc == 4) 166 | { 167 | sscanf(argv[2], "%d", &a); 168 | sscanf(argv[3], "%d", &b); 169 | } 170 | else 171 | { 172 | rt_kprintf("Error\n"); 173 | return; 174 | } 175 | return; 176 | } 177 | else if (!strcmp(argv[1], "size")) 178 | { 179 | if (argc < 4) 180 | { 181 | rt_kprintf("Error\n"); 182 | return; 183 | } 184 | sscanf(argv[2], "%d", &a); 185 | sscanf(argv[3], "%d", &b); 186 | return; 187 | } 188 | return; 189 | } 190 | 191 | // SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_DISABLE_RETURN, mouse, mouse_cmd, test);// FINSH_FUNCTION_EXPORT_ALIAS(mouse_cmd, __cmd_mouse, mouse); 192 | #endif 193 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/mouse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Ptisak 3 | * @Date: 2022-04-19 08:40:35 4 | * @LastEditors: Ptisak 5 | * @LastEditTime: 2022-04-19 16:38:53 6 | * @Version: Do not edit 7 | */ 8 | #include "mouse.h" 9 | 10 | #ifdef USING_PID 11 | #include "pid.h" 12 | #endif 13 | 14 | #include "stdlib.h" 15 | #include "math.h" 16 | 17 | Mouse_buff tMouse_buff; 18 | Mouse_buff tMouse_buff_last; 19 | 20 | mouse_state_t mouse_state; 21 | 22 | void mouse_init(void) 23 | { 24 | #ifdef USING_PID 25 | PID_struct_init(&pid_x, POSITION_PID, 100.f, 100.f, 0.6f, 0.0f, 0.2f); 26 | PID_struct_init(&pid_y, POSITION_PID, 100.f, 100.f, 0.6f, 0.0f, 0.2f); 27 | #endif 28 | memset(&tMouse_buff, 0X00, sizeof(tMouse_buff)); 29 | tMouse_buff.report_id = 0x02; 30 | memset(&mouse_state, 0X00, sizeof(mouse_state)); 31 | } 32 | 33 | void send_mouse_data(void) 34 | { 35 | static uint8_t i; 36 | 37 | if (mouse_state.continue_function) 38 | { 39 | mouse_continue_function(); 40 | } 41 | if (mouse_state.x == mouse_state.cur_x && mouse_state.y == mouse_state.cur_y) 42 | { 43 | tMouse_buff.mouse_rel_x = 0; 44 | tMouse_buff.mouse_rel_y = 0; 45 | } 46 | else 47 | { 48 | 49 | #ifdef USING_PID 50 | tMouse_buff.mouse_rel_x = (int8_t)pid_calc(&pid_x, mouse_state.cur_x, mouse_state.x); 51 | tMouse_buff.mouse_rel_y = (int8_t)pid_calc(&pid_y, mouse_state.cur_y, mouse_state.y); 52 | 53 | if (tMouse_buff.mouse_rel_x == 0 && tMouse_buff.mouse_rel_y == 0) 54 | { 55 | mouse_state.x = mouse_state.cur_x; 56 | mouse_state.y = mouse_state.cur_y; 57 | } 58 | #else 59 | tMouse_buff.mouse_rel_x = mouse_state.x - mouse_state.cur_x; 60 | tMouse_buff.mouse_rel_y = mouse_state.y - mouse_state.cur_y; 61 | #endif 62 | mouse_state.cur_x += tMouse_buff.mouse_rel_x; 63 | mouse_state.cur_y += tMouse_buff.mouse_rel_y; 64 | } 65 | for (i = 0; i < 3; i++) 66 | { 67 | if (mouse_state.key[i] > 0) 68 | { 69 | mouse_state.key[i]--; 70 | tMouse_buff.key |= 0x01u << i; 71 | } 72 | else if (mouse_state.key[i] < 0) 73 | { 74 | tMouse_buff.key |= 0x01u << i; 75 | } 76 | else 77 | { 78 | tMouse_buff.key &= ~(0x01u << i); 79 | mouse_state.key[i] = mouse_state.continue_key[i]; 80 | } 81 | } 82 | if (memcmp(&tMouse_buff_last, &tMouse_buff, sizeof(tMouse_buff)) == 0) 83 | { 84 | } 85 | else 86 | { 87 | memcpy(&tMouse_buff_last, &tMouse_buff, sizeof(tMouse_buff)); 88 | USBD_CUSTOM_HID_SendReport_FS((uint8_t *)&tMouse_buff, sizeof(tMouse_buff)); 89 | } 90 | } 91 | 92 | void mouse_set_continue_click(enum mouse_key key, int8_t time) 93 | { 94 | mouse_state.continue_key[key] = (uint8_t)time; 95 | } 96 | void mouse_set_click(enum mouse_key key, int8_t time) 97 | { 98 | mouse_state.key[key] = time; 99 | } 100 | void mouse_set_continue_function(int8_t s) 101 | { 102 | mouse_state.continue_function = !!s; 103 | } 104 | void mouse_move(int16_t x, int16_t y) 105 | { 106 | mouse_state.x = x; 107 | mouse_state.y = y; 108 | } 109 | int randint(int a, int b) 110 | { 111 | static int r; 112 | r = b - a; 113 | return ((rand() % r) + a); 114 | } 115 | void rand_reset(void) 116 | { 117 | srand(SysTick->VAL); 118 | } 119 | __weak void mouse_continue_function(void) 120 | { 121 | static float deg; 122 | static int r; 123 | deg += 0.22f; 124 | deg += (randint(0, 10)) * 0.01f; 125 | if (deg > 6.283f) 126 | { 127 | deg -= 6.283f; 128 | } 129 | r = randint(40, 50); 130 | mouse_state.x = cos(deg) * r; 131 | mouse_state.y = sin(deg) * r; 132 | } 133 | #if USING_SHELL 134 | void mouse_cmd(int argc, char **argv) 135 | { 136 | static int32_t a, b; 137 | if (argc < 2) 138 | { 139 | rt_kprintf("Error\n"); 140 | return; 141 | } 142 | if (!strcmp(argv[1], "down")) 143 | { 144 | return; 145 | } 146 | else if (!strcmp(argv[1], "up")) 147 | { 148 | return; 149 | } 150 | else if (!strcmp(argv[1], "move")) 151 | { 152 | if (argc < 4) 153 | { 154 | rt_kprintf("Error\n"); 155 | return; 156 | } 157 | sscanf(argv[2], "%d", &a); 158 | sscanf(argv[3], "%d", &b); 159 | mouse_state.x += a; 160 | mouse_state.y += b; 161 | return; 162 | } 163 | else if (!strcmp(argv[1], "tap")) 164 | { 165 | if (argc == 4) 166 | { 167 | sscanf(argv[2], "%d", &a); 168 | sscanf(argv[3], "%d", &b); 169 | } 170 | else 171 | { 172 | rt_kprintf("Error\n"); 173 | return; 174 | } 175 | return; 176 | } 177 | else if (!strcmp(argv[1], "size")) 178 | { 179 | if (argc < 4) 180 | { 181 | rt_kprintf("Error\n"); 182 | return; 183 | } 184 | sscanf(argv[2], "%d", &a); 185 | sscanf(argv[3], "%d", &b); 186 | return; 187 | } 188 | return; 189 | } 190 | 191 | // SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_DISABLE_RETURN, mouse, mouse_cmd, test);// FINSH_FUNCTION_EXPORT_ALIAS(mouse_cmd, __cmd_mouse, mouse); 192 | #endif 193 | -------------------------------------------------------------------------------- /HID_template/hardware/lwrb.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file lwrb.h 3 | * \brief LwRB - Lightweight ring buffer 4 | */ 5 | 6 | /* 7 | * Copyright (c) 2020 Tilen MAJERLE 8 | * 9 | * Permission is hereby granted, free of charge, to any person 10 | * obtaining a copy of this software and associated documentation 11 | * files (the "Software"), to deal in the Software without restriction, 12 | * including without limitation the rights to use, copy, modify, merge, 13 | * publish, distribute, sublicense, and/or sell copies of the Software, 14 | * and to permit persons to whom the Software is furnished to do so, 15 | * subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be 18 | * included in all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 23 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | * OTHER DEALINGS IN THE SOFTWARE. 28 | * 29 | * This file is part of LwRB - Lightweight ring buffer library. 30 | * 31 | * Author: Tilen MAJERLE 32 | * Version: v2.0.3 33 | */ 34 | #ifndef LWRB_HDR_H 35 | #define LWRB_HDR_H 36 | 37 | #include 38 | #include 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif /* __cplusplus */ 43 | 44 | /** 45 | * \defgroup LWRB Lightweight ring buffer manager 46 | * \brief Lightweight ring buffer manager 47 | * \{ 48 | */ 49 | 50 | /** 51 | * \brief Enable buffer structure pointer parameters as volatile 52 | * To use this feature, uncomment keyword below, or define in global compiler settings 53 | */ 54 | #ifndef LWRB_VOLATILE 55 | #define LWRB_VOLATILE /* volatile */ 56 | #endif 57 | 58 | /** 59 | * \brief Adds 2 magic words to make sure if memory is corrupted 60 | * application can detect wrong data pointer and maximum size 61 | */ 62 | #ifndef LWRB_USE_MAGIC 63 | #define LWRB_USE_MAGIC 1 64 | #endif 65 | 66 | /** 67 | * \brief Event type for buffer operations 68 | */ 69 | typedef enum { 70 | LWRB_EVT_READ, /*!< Read event */ 71 | LWRB_EVT_WRITE, /*!< Write event */ 72 | LWRB_EVT_RESET, /*!< Reset event */ 73 | } lwrb_evt_type_t; 74 | 75 | /** 76 | * \brief Buffer structure forward declaration 77 | */ 78 | struct lwrb; 79 | 80 | /** 81 | * \brief Event callback function type 82 | * \param[in] buff: Buffer handle for event 83 | * \param[in] evt: Event type 84 | * \param[in] bp: Number of bytes written or read (when used), depends on event type 85 | */ 86 | typedef void (*lwrb_evt_fn)(struct lwrb* buff, lwrb_evt_type_t evt, size_t bp); 87 | 88 | /** 89 | * \brief Buffer structure 90 | */ 91 | typedef struct lwrb { 92 | #if LWRB_USE_MAGIC 93 | uint32_t magic1; /*!< Magic 1 word */ 94 | #endif /* LWRB_USE_MAGIC */ 95 | uint8_t* buff; /*!< Pointer to buffer data. 96 | Buffer is considered initialized when `buff != NULL` and `size > 0` */ 97 | LWRB_VOLATILE size_t size; /*!< Size of buffer data. Size of actual buffer is `1` byte less than value holds */ 98 | LWRB_VOLATILE size_t r; /*!< Next read pointer. Buffer is considered empty when `r == w` and full when `w == r - 1` */ 99 | LWRB_VOLATILE size_t w; /*!< Next write pointer. Buffer is considered empty when `r == w` and full when `w == r - 1` */ 100 | lwrb_evt_fn evt_fn; /*!< Pointer to event callback function */ 101 | #if LWRB_USE_MAGIC 102 | uint32_t magic2; /*!< Magic 2 word */ 103 | #endif /* LWRB_USE_MAGIC */ 104 | } lwrb_t; 105 | 106 | uint8_t lwrb_init(lwrb_t* buff, void* buffdata, size_t size); 107 | uint8_t lwrb_is_ready(lwrb_t* buff); 108 | void lwrb_free(lwrb_t* buff); 109 | void lwrb_reset(lwrb_t* buff); 110 | void lwrb_set_evt_fn(lwrb_t* buff, lwrb_evt_fn fn); 111 | 112 | /* Read/Write functions */ 113 | size_t lwrb_write(lwrb_t* buff, const void* data, size_t btw); 114 | size_t lwrb_read(lwrb_t* buff, void* data, size_t btr); 115 | size_t lwrb_peek(lwrb_t* buff, size_t skip_count, void* data, size_t btp); 116 | 117 | /* Buffer size information */ 118 | size_t lwrb_get_free(lwrb_t* buff); 119 | size_t lwrb_get_full(lwrb_t* buff); 120 | 121 | /* Read data block management */ 122 | void* lwrb_get_linear_block_read_address(lwrb_t* buff); 123 | size_t lwrb_get_linear_block_read_length(lwrb_t* buff); 124 | size_t lwrb_skip(lwrb_t* buff, size_t len); 125 | 126 | /* Write data block management */ 127 | void* lwrb_get_linear_block_write_address(lwrb_t* buff); 128 | size_t lwrb_get_linear_block_write_length(lwrb_t* buff); 129 | size_t lwrb_advance(lwrb_t* buff, size_t len); 130 | 131 | /** 132 | * \} 133 | */ 134 | 135 | #ifdef __cplusplus 136 | } 137 | #endif /* __cplusplus */ 138 | 139 | #endif /* LWRB_HDR_H */ 140 | -------------------------------------------------------------------------------- /HID_template/HID_template.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | File.Version=6 3 | GPIO.groupedBy=Group By Peripherals 4 | KeepUserPlacement=false 5 | Mcu.Family=STM32F1 6 | Mcu.IP0=NVIC 7 | Mcu.IP1=RCC 8 | Mcu.IP2=SYS 9 | Mcu.IP3=TIM1 10 | Mcu.IP4=USB 11 | Mcu.IP5=USB_DEVICE 12 | Mcu.IPNb=6 13 | Mcu.Name=STM32F103C(4-6)Tx 14 | Mcu.Package=LQFP48 15 | Mcu.Pin0=PD0-OSC_IN 16 | Mcu.Pin1=PD1-OSC_OUT 17 | Mcu.Pin2=PA11 18 | Mcu.Pin3=PA12 19 | Mcu.Pin4=PA13 20 | Mcu.Pin5=PA14 21 | Mcu.Pin6=VP_SYS_VS_Systick 22 | Mcu.Pin7=VP_TIM1_VS_ClockSourceINT 23 | Mcu.Pin8=VP_USB_DEVICE_VS_USB_DEVICE_CUSTOM_HID_FS 24 | Mcu.PinsNb=9 25 | Mcu.ThirdPartyNb=0 26 | Mcu.UserConstants= 27 | Mcu.UserName=STM32F103C6Tx 28 | MxCube.Version=6.4.0 29 | MxDb.Version=DB.6.0.40 30 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 31 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false 32 | NVIC.ForceEnableDMAVector=true 33 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 34 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false 35 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false 36 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false 37 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 38 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false 39 | NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true 40 | NVIC.TIM1_UP_IRQn=true\:0\:0\:false\:false\:true\:true\:true 41 | NVIC.USB_LP_CAN1_RX0_IRQn=true\:0\:0\:false\:false\:true\:false\:true 42 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 43 | PA11.Mode=Device 44 | PA11.Signal=USB_DM 45 | PA12.Mode=Device 46 | PA12.Signal=USB_DP 47 | PA13.Mode=Serial_Wire 48 | PA13.Signal=SYS_JTMS-SWDIO 49 | PA14.Mode=Serial_Wire 50 | PA14.Signal=SYS_JTCK-SWCLK 51 | PD0-OSC_IN.Mode=HSE-External-Oscillator 52 | PD0-OSC_IN.Signal=RCC_OSC_IN 53 | PD1-OSC_OUT.Mode=HSE-External-Oscillator 54 | PD1-OSC_OUT.Signal=RCC_OSC_OUT 55 | PinOutPanel.RotationAngle=0 56 | ProjectManager.AskForMigrate=true 57 | ProjectManager.BackupPrevious=false 58 | ProjectManager.CompilerOptimize=6 59 | ProjectManager.ComputerToolchain=false 60 | ProjectManager.CoupleFile=true 61 | ProjectManager.CustomerFirmwarePackage= 62 | ProjectManager.DefaultFWLocation=true 63 | ProjectManager.DeletePrevious=true 64 | ProjectManager.DeviceId=STM32F103C6Tx 65 | ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.4 66 | ProjectManager.FreePins=false 67 | ProjectManager.HalAssertFull=false 68 | ProjectManager.HeapSize=0x200 69 | ProjectManager.KeepUserCode=true 70 | ProjectManager.LastFirmware=true 71 | ProjectManager.LibraryCopy=1 72 | ProjectManager.MainLocation=Core/Src 73 | ProjectManager.NoMain=false 74 | ProjectManager.PreviousToolchain= 75 | ProjectManager.ProjectBuild=false 76 | ProjectManager.ProjectFileName=HID_template.ioc 77 | ProjectManager.ProjectName=HID_template 78 | ProjectManager.RegisterCallBack= 79 | ProjectManager.StackSize=0x400 80 | ProjectManager.TargetToolchain=MDK-ARM V5.32 81 | ProjectManager.ToolChainLocation= 82 | ProjectManager.UnderRoot=false 83 | ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-LL-true,2-SystemClock_Config-RCC-false-LL-false,3-MX_TIM1_Init-TIM1-false-LL-true,4-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false 84 | RCC.ADCFreqValue=36000000 85 | RCC.AHBFreq_Value=72000000 86 | RCC.APB1CLKDivider=RCC_HCLK_DIV2 87 | RCC.APB1Freq_Value=36000000 88 | RCC.APB1TimFreq_Value=72000000 89 | RCC.APB2Freq_Value=72000000 90 | RCC.APB2TimFreq_Value=72000000 91 | RCC.FCLKCortexFreq_Value=72000000 92 | RCC.FamilyName=M 93 | RCC.HCLKFreq_Value=72000000 94 | RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,USBPrescaler,VCOOutput2Freq_Value 95 | RCC.MCOFreq_Value=72000000 96 | RCC.PLLCLKFreq_Value=72000000 97 | RCC.PLLMCOFreq_Value=36000000 98 | RCC.PLLMUL=RCC_PLL_MUL9 99 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE 100 | RCC.SYSCLKFreq_VALUE=72000000 101 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 102 | RCC.TimSysFreq_Value=72000000 103 | RCC.USBFreq_Value=48000000 104 | RCC.USBPrescaler=RCC_USBCLKSOURCE_PLL_DIV1_5 105 | RCC.VCOOutput2Freq_Value=8000000 106 | TIM1.IPParameters=Prescaler,Period 107 | TIM1.Period=124 108 | TIM1.Prescaler=719 109 | USB_DEVICE.CLASS_NAME_FS=CUSTOM_HID 110 | USB_DEVICE.CONFIGURATION_STRING_CUSTOMHID_FS=PSK INF 111 | USB_DEVICE.CUSTOM_HID_FS_BINTERVAL=0x1 112 | USB_DEVICE.INTERFACE_STRING_CUSTOMHID_FS=PSK HID INTERFACE 113 | USB_DEVICE.IPParameters=VirtualMode,VirtualModeFS,CLASS_NAME_FS,VID,MANUFACTURER_STRING,LANGID_STRING,PRODUCT_STRING_CUSTOMHID_FS,CONFIGURATION_STRING_CUSTOMHID_FS,INTERFACE_STRING_CUSTOMHID_FS,PID_CUSTOMHID_FS,CUSTOM_HID_FS_BINTERVAL,USBD_CUSTOMHID_OUTREPORT_BUF_SIZE,USBD_CUSTOM_HID_REPORT_DESC_SIZE 114 | USB_DEVICE.LANGID_STRING=1033 115 | USB_DEVICE.MANUFACTURER_STRING=NJUST 6003-Ptisak LAB INC 116 | USB_DEVICE.PID_CUSTOMHID_FS=23333 117 | USB_DEVICE.PRODUCT_STRING_CUSTOMHID_FS=Ptisak Pia \!(o `~')/'' 118 | USB_DEVICE.USBD_CUSTOMHID_OUTREPORT_BUF_SIZE=64 119 | USB_DEVICE.USBD_CUSTOM_HID_REPORT_DESC_SIZE=251 120 | USB_DEVICE.VID=6666 121 | USB_DEVICE.VirtualMode=CustomHid 122 | USB_DEVICE.VirtualModeFS=Custom_Hid_FS 123 | VP_SYS_VS_Systick.Mode=SysTick 124 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 125 | VP_TIM1_VS_ClockSourceINT.Mode=Internal 126 | VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT 127 | VP_USB_DEVICE_VS_USB_DEVICE_CUSTOM_HID_FS.Mode=CUSTOM_HID_FS 128 | VP_USB_DEVICE_VS_USB_DEVICE_CUSTOM_HID_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CUSTOM_HID_FS 129 | board=custom 130 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/hid_dev/hid/usage_power.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usage_power.h 4 | * @author Benedek Kupper 5 | * @version 0.1 6 | * @date 2018-01-31 7 | * @brief USB Human Interface Device Class 8 | * Power Device Usage Page definitions 9 | * 10 | * Copyright (c) 2018 Benedek Kupper 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | #ifndef __HID_USAGE_POWER_H_ 25 | #define __HID_USAGE_POWER_H_ 26 | #include 27 | 28 | #define HID_USAGE_PAGE_POWER_DEVICE HID_ITEM_1(0x0, GLOBAL, 0x84) 29 | 30 | #define HID_USAGE_PS_INAME HID_USAGE_1(0x01) 31 | #define HID_USAGE_PS_PRESENT_STATUS HID_USAGE_1(0x02) 32 | #define HID_USAGE_PS_CHANGED_STATUS HID_USAGE_1(0x03) 33 | #define HID_USAGE_PS_UPS HID_USAGE_1(0x04) 34 | #define HID_USAGE_PS_POWER_SUPPLY HID_USAGE_1(0x05) 35 | #define HID_USAGE_PS_PERIPHERAL HID_USAGE_1(0x06) 36 | #define HID_USAGE_PS_BATTERY_SYSTEM HID_USAGE_1(0x10) 37 | #define HID_USAGE_PS_BATTERY_SYSTEM_ID HID_USAGE_1(0x11) 38 | #define HID_USAGE_PS_BATTERY HID_USAGE_1(0x12) 39 | #define HID_USAGE_PS_BATTERY_ID HID_USAGE_1(0x13) 40 | #define HID_USAGE_PS_CHARGER HID_USAGE_1(0x14) 41 | #define HID_USAGE_PS_CHARGER_ID HID_USAGE_1(0x15) 42 | #define HID_USAGE_PS_POWER_CONVERTER HID_USAGE_1(0x16) 43 | #define HID_USAGE_PS_POWER_CONVERTER_ID HID_USAGE_1(0x16) 44 | #define HID_USAGE_PS_OUTLET_SYSTEM HID_USAGE_1(0x18) 45 | #define HID_USAGE_PS_OUTLET_SYSTEM_ID HID_USAGE_1(0x19) 46 | #define HID_USAGE_PS_INPUT HID_USAGE_1(0x1A) 47 | #define HID_USAGE_PS_INPUT_ID HID_USAGE_1(0x1B) 48 | #define HID_USAGE_PS_OUTPUT HID_USAGE_1(0x1C) 49 | #define HID_USAGE_PS_OUTPUT_ID HID_USAGE_1(0x1D) 50 | #define HID_USAGE_PS_FLOW HID_USAGE_1(0x1E) 51 | #define HID_USAGE_PS_FLOW_ID HID_USAGE_1(0x1F) 52 | #define HID_USAGE_PS_OUTLET HID_USAGE_1(0x20) 53 | #define HID_USAGE_PS_OUTLET_ID HID_USAGE_1(0x21) 54 | #define HID_USAGE_PS_GANG HID_USAGE_1(0x22) 55 | #define HID_USAGE_PS_GANG_ID HID_USAGE_1(0x23) 56 | #define HID_USAGE_PS_POWER_SUMMARY HID_USAGE_1(0x24) 57 | #define HID_USAGE_PS_POWER_SUMMARY_ID HID_USAGE_1(0x25) 58 | #define HID_USAGE_PS_VOLTAGE HID_USAGE_1(0x30) 59 | #define HID_USAGE_PS_CURRENT HID_USAGE_1(0x31) 60 | #define HID_USAGE_PS_FREQUENCY HID_USAGE_1(0x32) 61 | #define HID_USAGE_PS_APPARENT_POWER HID_USAGE_1(0x33) 62 | #define HID_USAGE_PS_ACTIVE_POWER HID_USAGE_1(0x34) 63 | #define HID_USAGE_PS_TEMPERATURE HID_USAGE_1(0x36) 64 | #define HID_USAGE_PS_CONFIGVOLTAGE HID_USAGE_1(0x40) 65 | #define HID_USAGE_PS_CONFIGCURRENT HID_USAGE_1(0x41) 66 | #define HID_USAGE_PS_CONFIGFREQ HID_USAGE_1(0x42) 67 | #define HID_USAGE_PS_CONFIGAPP_POWER HID_USAGE_1(0x43) 68 | #define HID_USAGE_PS_CONFIGACT_POWER HID_USAGE_1(0x44) 69 | #define HID_USAGE_PS_CONFIGTEMPERATURE HID_USAGE_1(0x46) 70 | #define HID_USAGE_PS_SWITCHONCTRL HID_USAGE_1(0x50) 71 | #define HID_USAGE_PS_SWITCHOFFCTRL HID_USAGE_1(0x51) 72 | #define HID_USAGE_PS_TOGGLECTRL HID_USAGE_1(0x52) 73 | #define HID_USAGE_PS_PRESENT HID_USAGE_1(0x60) 74 | #define HID_USAGE_PS_GOOD HID_USAGE_1(0x61) 75 | #define HID_USAGE_PS_OVERLOAD HID_USAGE_1(0x65) 76 | #define HID_USAGE_PS_OVERCHARGED HID_USAGE_1(0x66) 77 | #define HID_USAGE_PS_OVERTEMP HID_USAGE_1(0x67) 78 | #define HID_USAGE_PS_RESERVED HID_USAGE_1(0x6A) 79 | #define HID_USAGE_PS_SWITCH_ON_OFF HID_USAGE_1(0x6B) 80 | #define HID_USAGE_PS_SWITCHABLE HID_USAGE_1(0x6C) 81 | #define HID_USAGE_PS_USED HID_USAGE_1(0x6D) 82 | #define HID_USAGE_PS_BOOST HID_USAGE_1(0x6E) 83 | #define HID_USAGE_PS_BUCK HID_USAGE_1(0x6F) 84 | 85 | #define HID_USAGE_PAGE_BATTERY_SYSTEM HID_ITEM_1(0x0, GLOBAL, 0x85) 86 | 87 | #define HID_USAGE_BS_OUTPUT_CONNECTION HID_USAGE_1(0x16) 88 | #define HID_USAGE_BS_CHARGER_CONNECTION HID_USAGE_1(0x17) 89 | #define HID_USAGE_BS_BATTERY_INSERTION HID_USAGE_1(0x18) 90 | #define HID_USAGE_BS_CHARGING_INDICATOR HID_USAGE_1(0x1D) 91 | #define HID_USAGE_BS_CAPACITY_MODE HID_USAGE_1(0x2C) 92 | #define HID_USAGE_BS_DESIGN_CAP HID_USAGE_1(0x83) 93 | #define HID_USAGE_BS_REMAINING_CAP HID_USAGE_1(0x66) 94 | #define HID_USAGE_BS_FULLCHARGE_CAP HID_USAGE_1(0x67) 95 | #define HID_USAGE_BS_BATTERY_PRESENT HID_USAGE_1(0xD1) 96 | #define HID_USAGE_BS_TERM_CHARGE HID_USAGE_1(0x40) 97 | #define HID_USAGE_BS_TERM_DISCHARGE HID_USAGE_1(0x41) 98 | #define HID_USAGE_BS_BELOW_REMCAPLIMIT HID_USAGE_1(0x42) 99 | #define HID_USAGE_BS_CHARGING HID_USAGE_1(0x44) 100 | #define HID_USAGE_BS_DISCHARGING HID_USAGE_1(0x45) 101 | #define HID_USAGE_BS_FULLY_CHARGED HID_USAGE_1(0x46) 102 | #define HID_USAGE_BS_FULLY_DISCHARGED HID_USAGE_1(0x47) 103 | #define HID_USAGE_BS_INHIBIT_CHARGE HID_USAGE_1(0xC0) 104 | 105 | #endif /* __HID_USAGE_POWER_H_ */ 106 | -------------------------------------------------------------------------------- /HID_template/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.c 4 | * @author MCD Application Team 5 | * @brief This file provides the IO requests APIs for control endpoints. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "usbd_ioreq.h" 22 | 23 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 24 | * @{ 25 | */ 26 | 27 | 28 | /** @defgroup USBD_IOREQ 29 | * @brief control I/O requests module 30 | * @{ 31 | */ 32 | 33 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions 34 | * @{ 35 | */ 36 | /** 37 | * @} 38 | */ 39 | 40 | 41 | /** @defgroup USBD_IOREQ_Private_Defines 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @} 47 | */ 48 | 49 | 50 | /** @defgroup USBD_IOREQ_Private_Macros 51 | * @{ 52 | */ 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBD_IOREQ_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes 68 | * @{ 69 | */ 70 | /** 71 | * @} 72 | */ 73 | 74 | 75 | /** @defgroup USBD_IOREQ_Private_Functions 76 | * @{ 77 | */ 78 | 79 | /** 80 | * @brief USBD_CtlSendData 81 | * send data on the ctl pipe 82 | * @param pdev: device instance 83 | * @param buff: pointer to data buffer 84 | * @param len: length of data to be sent 85 | * @retval status 86 | */ 87 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, 88 | uint8_t *pbuf, uint16_t len) 89 | { 90 | /* Set EP0 State */ 91 | pdev->ep0_state = USBD_EP0_DATA_IN; 92 | pdev->ep_in[0].total_length = len; 93 | pdev->ep_in[0].rem_length = len; 94 | 95 | /* Start the transfer */ 96 | USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 97 | 98 | return USBD_OK; 99 | } 100 | 101 | /** 102 | * @brief USBD_CtlContinueSendData 103 | * continue sending data on the ctl pipe 104 | * @param pdev: device instance 105 | * @param buff: pointer to data buffer 106 | * @param len: length of data to be sent 107 | * @retval status 108 | */ 109 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 110 | uint8_t *pbuf, uint16_t len) 111 | { 112 | /* Start the next transfer */ 113 | USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 114 | 115 | return USBD_OK; 116 | } 117 | 118 | /** 119 | * @brief USBD_CtlPrepareRx 120 | * receive data on the ctl pipe 121 | * @param pdev: device instance 122 | * @param buff: pointer to data buffer 123 | * @param len: length of data to be received 124 | * @retval status 125 | */ 126 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, 127 | uint8_t *pbuf, uint16_t len) 128 | { 129 | /* Set EP0 State */ 130 | pdev->ep0_state = USBD_EP0_DATA_OUT; 131 | pdev->ep_out[0].total_length = len; 132 | pdev->ep_out[0].rem_length = len; 133 | 134 | /* Start the transfer */ 135 | USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 136 | 137 | return USBD_OK; 138 | } 139 | 140 | /** 141 | * @brief USBD_CtlContinueRx 142 | * continue receive data on the ctl pipe 143 | * @param pdev: device instance 144 | * @param buff: pointer to data buffer 145 | * @param len: length of data to be received 146 | * @retval status 147 | */ 148 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, 149 | uint8_t *pbuf, uint16_t len) 150 | { 151 | USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 152 | 153 | return USBD_OK; 154 | } 155 | 156 | /** 157 | * @brief USBD_CtlSendStatus 158 | * send zero lzngth packet on the ctl pipe 159 | * @param pdev: device instance 160 | * @retval status 161 | */ 162 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev) 163 | { 164 | /* Set EP0 State */ 165 | pdev->ep0_state = USBD_EP0_STATUS_IN; 166 | 167 | /* Start the transfer */ 168 | USBD_LL_Transmit(pdev, 0x00U, NULL, 0U); 169 | 170 | return USBD_OK; 171 | } 172 | 173 | /** 174 | * @brief USBD_CtlReceiveStatus 175 | * receive zero lzngth packet on the ctl pipe 176 | * @param pdev: device instance 177 | * @retval status 178 | */ 179 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev) 180 | { 181 | /* Set EP0 State */ 182 | pdev->ep0_state = USBD_EP0_STATUS_OUT; 183 | 184 | /* Start the transfer */ 185 | USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); 186 | 187 | return USBD_OK; 188 | } 189 | 190 | /** 191 | * @brief USBD_GetRxCount 192 | * returns the received data length 193 | * @param pdev: device instance 194 | * @param ep_addr: endpoint address 195 | * @retval Rx Data blength 196 | */ 197 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 198 | { 199 | return USBD_LL_GetRxDataSize(pdev, ep_addr); 200 | } 201 | 202 | /** 203 | * @} 204 | */ 205 | 206 | 207 | /** 208 | * @} 209 | */ 210 | 211 | 212 | /** 213 | * @} 214 | */ 215 | 216 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 217 | -------------------------------------------------------------------------------- /HID_template/MDK-ARM/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "D:\\stm32_file\\cubemx\\HID_template\\**" 8 | ], 9 | "defines": [ 10 | "_DEBUG", 11 | "UNICODE", 12 | "_UNICODE" 13 | ], 14 | "cStandard": "c17", 15 | "cppStandard": "c++17", 16 | "intelliSenseMode": "windows-msvc-x64" 17 | }, 18 | { 19 | "name": "HID_template", 20 | "includePath": [ 21 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\Core\\Inc", 22 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\Drivers\\STM32F1xx_HAL_Driver\\Inc", 23 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\Drivers\\CMSIS\\Device\\ST\\STM32F1xx\\Include", 24 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\Drivers\\CMSIS\\Include", 25 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\USB_DEVICE\\App", 26 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\USB_DEVICE\\Target", 27 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\Drivers\\STM32F1xx_HAL_Driver\\Inc\\Legacy", 28 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\Middlewares\\ST\\STM32_USB_Device_Library\\Core\\Inc", 29 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\Middlewares\\ST\\STM32_USB_Device_Library\\Class\\CustomHID\\Inc", 30 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\hid_dev", 31 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\hardware", 32 | "D:\\MDK5\\ARM\\ARMCC\\include", 33 | "D:\\MDK5\\ARM\\ARMCC\\include\\rw", 34 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\MDK-ARM", 35 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\Core\\Src", 36 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\Drivers\\STM32F1xx_HAL_Driver\\Src", 37 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\Middlewares\\ST\\STM32_USB_Device_Library\\Core\\Src", 38 | "d:\\000-Ptisak\\Document\\GitHub\\STM32F103C6T6-customHID\\HID_template\\Middlewares\\ST\\STM32_USB_Device_Library\\Class\\CustomHID\\Src" 39 | ], 40 | "defines": [ 41 | "STM32F103x6", 42 | "USE_FULL_LL_DRIVER", 43 | "USE_HAL_DRIVER", 44 | "__CC_ARM", 45 | "__arm__", 46 | "__align(x)=", 47 | "__ALIGNOF__(x)=", 48 | "__alignof__(x)=", 49 | "__asm(x)=", 50 | "__forceinline=", 51 | "__restrict=", 52 | "__global_reg(n)=", 53 | "__inline=", 54 | "__int64=long long", 55 | "__INTADDR__(expr)=0", 56 | "__irq=", 57 | "__packed=", 58 | "__pure=", 59 | "__smc(n)=", 60 | "__svc(n)=", 61 | "__svc_indirect(n)=", 62 | "__svc_indirect_r7(n)=", 63 | "__value_in_regs=", 64 | "__weak=", 65 | "__writeonly=", 66 | "__declspec(x)=", 67 | "__attribute__(x)=", 68 | "__nonnull__(x)=", 69 | "__register=", 70 | "__breakpoint(x)=", 71 | "__cdp(x,y,z)=", 72 | "__clrex()=", 73 | "__clz(x)=0U", 74 | "__current_pc()=0U", 75 | "__current_sp()=0U", 76 | "__disable_fiq()=", 77 | "__disable_irq()=", 78 | "__dmb(x)=", 79 | "__dsb(x)=", 80 | "__enable_fiq()=", 81 | "__enable_irq()=", 82 | "__fabs(x)=0.0", 83 | "__fabsf(x)=0.0f", 84 | "__force_loads()=", 85 | "__force_stores()=", 86 | "__isb(x)=", 87 | "__ldrex(x)=0U", 88 | "__ldrexd(x)=0U", 89 | "__ldrt(x)=0U", 90 | "__memory_changed()=", 91 | "__nop()=", 92 | "__pld(...)=", 93 | "__pli(...)=", 94 | "__qadd(x,y)=0", 95 | "__qdbl(x)=0", 96 | "__qsub(x,y)=0", 97 | "__rbit(x)=0U", 98 | "__rev(x)=0U", 99 | "__return_address()=0U", 100 | "__ror(x,y)=0U", 101 | "__schedule_barrier()=", 102 | "__semihost(x,y)=0", 103 | "__sev()=", 104 | "__sqrt(x)=0.0", 105 | "__sqrtf(x)=0.0f", 106 | "__ssat(x,y)=0", 107 | "__strex(x,y)=0U", 108 | "__strexd(x,y)=0", 109 | "__strt(x,y)=", 110 | "__swp(x,y)=0U", 111 | "__usat(x,y)=0U", 112 | "__wfe()=", 113 | "__wfi()=", 114 | "__yield()=", 115 | "__vfp_status(x,y)=0" 116 | ], 117 | "intelliSenseMode": "${default}" 118 | } 119 | ], 120 | "version": 4 121 | } -------------------------------------------------------------------------------- /HID_template/back_up base on custom/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.c 4 | * @author MCD Application Team 5 | * @brief This file provides the IO requests APIs for control endpoints. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "usbd_ioreq.h" 22 | 23 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 24 | * @{ 25 | */ 26 | 27 | 28 | /** @defgroup USBD_IOREQ 29 | * @brief control I/O requests module 30 | * @{ 31 | */ 32 | 33 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions 34 | * @{ 35 | */ 36 | /** 37 | * @} 38 | */ 39 | 40 | 41 | /** @defgroup USBD_IOREQ_Private_Defines 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @} 47 | */ 48 | 49 | 50 | /** @defgroup USBD_IOREQ_Private_Macros 51 | * @{ 52 | */ 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBD_IOREQ_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes 68 | * @{ 69 | */ 70 | /** 71 | * @} 72 | */ 73 | 74 | 75 | /** @defgroup USBD_IOREQ_Private_Functions 76 | * @{ 77 | */ 78 | 79 | /** 80 | * @brief USBD_CtlSendData 81 | * send data on the ctl pipe 82 | * @param pdev: device instance 83 | * @param buff: pointer to data buffer 84 | * @param len: length of data to be sent 85 | * @retval status 86 | */ 87 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, 88 | uint8_t *pbuf, uint16_t len) 89 | { 90 | /* Set EP0 State */ 91 | pdev->ep0_state = USBD_EP0_DATA_IN; 92 | pdev->ep_in[0].total_length = len; 93 | pdev->ep_in[0].rem_length = len; 94 | 95 | /* Start the transfer */ 96 | USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 97 | 98 | return USBD_OK; 99 | } 100 | 101 | /** 102 | * @brief USBD_CtlContinueSendData 103 | * continue sending data on the ctl pipe 104 | * @param pdev: device instance 105 | * @param buff: pointer to data buffer 106 | * @param len: length of data to be sent 107 | * @retval status 108 | */ 109 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 110 | uint8_t *pbuf, uint16_t len) 111 | { 112 | /* Start the next transfer */ 113 | USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 114 | 115 | return USBD_OK; 116 | } 117 | 118 | /** 119 | * @brief USBD_CtlPrepareRx 120 | * receive data on the ctl pipe 121 | * @param pdev: device instance 122 | * @param buff: pointer to data buffer 123 | * @param len: length of data to be received 124 | * @retval status 125 | */ 126 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, 127 | uint8_t *pbuf, uint16_t len) 128 | { 129 | /* Set EP0 State */ 130 | pdev->ep0_state = USBD_EP0_DATA_OUT; 131 | pdev->ep_out[0].total_length = len; 132 | pdev->ep_out[0].rem_length = len; 133 | 134 | /* Start the transfer */ 135 | USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 136 | 137 | return USBD_OK; 138 | } 139 | 140 | /** 141 | * @brief USBD_CtlContinueRx 142 | * continue receive data on the ctl pipe 143 | * @param pdev: device instance 144 | * @param buff: pointer to data buffer 145 | * @param len: length of data to be received 146 | * @retval status 147 | */ 148 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, 149 | uint8_t *pbuf, uint16_t len) 150 | { 151 | USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 152 | 153 | return USBD_OK; 154 | } 155 | 156 | /** 157 | * @brief USBD_CtlSendStatus 158 | * send zero lzngth packet on the ctl pipe 159 | * @param pdev: device instance 160 | * @retval status 161 | */ 162 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev) 163 | { 164 | /* Set EP0 State */ 165 | pdev->ep0_state = USBD_EP0_STATUS_IN; 166 | 167 | /* Start the transfer */ 168 | USBD_LL_Transmit(pdev, 0x00U, NULL, 0U); 169 | 170 | return USBD_OK; 171 | } 172 | 173 | /** 174 | * @brief USBD_CtlReceiveStatus 175 | * receive zero lzngth packet on the ctl pipe 176 | * @param pdev: device instance 177 | * @retval status 178 | */ 179 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev) 180 | { 181 | /* Set EP0 State */ 182 | pdev->ep0_state = USBD_EP0_STATUS_OUT; 183 | 184 | /* Start the transfer */ 185 | USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); 186 | 187 | return USBD_OK; 188 | } 189 | 190 | /** 191 | * @brief USBD_GetRxCount 192 | * returns the received data length 193 | * @param pdev: device instance 194 | * @param ep_addr: endpoint address 195 | * @retval Rx Data blength 196 | */ 197 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 198 | { 199 | return USBD_LL_GetRxDataSize(pdev, ep_addr); 200 | } 201 | 202 | /** 203 | * @} 204 | */ 205 | 206 | 207 | /** 208 | * @} 209 | */ 210 | 211 | 212 | /** 213 | * @} 214 | */ 215 | 216 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 217 | -------------------------------------------------------------------------------- /HID_template/MDK-ARM/.vscode/keil-assistant.log: -------------------------------------------------------------------------------- 1 | Log at : 2022/4/19|09:26:22|GMT+0800 2 | 3 | [TypeError: Cannot read properties of undefined (reading 'replace') 4 | at x.toAbsolutePath (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:8420) 5 | at I. (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:11269) 6 | at Generator.next () 7 | at c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4542 8 | at new Promise () 9 | at r (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4287) 10 | at I.load (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:10382) 11 | at x. (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:8182) 12 | at Generator.next () 13 | at a (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4344) 14 | at runMicrotasks () 15 | at processTicksAndRejections (node:internal/process/task_queues:96:5)] 16 | Log at : 2022/4/19|09:26:28|GMT+0800 17 | 18 | [TypeError: Cannot read properties of undefined (reading 'replace') 19 | at x.toAbsolutePath (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:8420) 20 | at I. (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:11269) 21 | at Generator.next () 22 | at c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4542 23 | at new Promise () 24 | at r (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4287) 25 | at I.load (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:10382) 26 | at x. (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:8182) 27 | at Generator.next () 28 | at a (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4344) 29 | at processTicksAndRejections (node:internal/process/task_queues:96:5)] 30 | Log at : 2022/4/19|09:27:18|GMT+0800 31 | 32 | [TypeError: Cannot read properties of undefined (reading 'replace') 33 | at x.toAbsolutePath (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:8420) 34 | at I. (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:11269) 35 | at Generator.next () 36 | at c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4542 37 | at new Promise () 38 | at r (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4287) 39 | at I.load (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:10382) 40 | at x. (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:8182) 41 | at Generator.next () 42 | at a (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4344) 43 | at processTicksAndRejections (node:internal/process/task_queues:96:5)] 44 | Log at : 2022/4/19|09:28:40|GMT+0800 45 | 46 | Log at : 2022/4/19|12:28:17|GMT+0800 47 | 48 | Log at : 2022/4/19|13:11:56|GMT+0800 49 | 50 | Log at : 2022/4/19|13:15:41|GMT+0800 51 | 52 | [TypeError: Cannot read properties of undefined (reading 'replace') 53 | at x.toAbsolutePath (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:8420) 54 | at I. (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:11269) 55 | at Generator.next () 56 | at c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4542 57 | at new Promise () 58 | at r (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4287) 59 | at I.load (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:10382) 60 | at x. (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:8182) 61 | at Generator.next () 62 | at a (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4344) 63 | at processTicksAndRejections (node:internal/process/task_queues:96:5)] 64 | Log at : 2022/4/19|13:18:51|GMT+0800 65 | 66 | [TypeError: Cannot read properties of undefined (reading 'replace') 67 | at x.toAbsolutePath (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:8420) 68 | at I. (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:11269) 69 | at Generator.next () 70 | at c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4542 71 | at new Promise () 72 | at r (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4287) 73 | at I.load (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:10382) 74 | at x. (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:8182) 75 | at Generator.next () 76 | at a (c:\Users\Ptisak\.vscode\extensions\cl.keil-assistant-1.6.2\dist\extension.js:1:4344) 77 | at processTicksAndRejections (node:internal/process/task_queues:96:5)] 78 | Log at : 2022/4/19|13:19:52|GMT+0800 79 | 80 | Log at : 2022/4/19|13:20:42|GMT+0800 81 | 82 | Log at : 2022/4/19|13:32:41|GMT+0800 83 | 84 | Log at : 2022/4/19|13:41:50|GMT+0800 85 | 86 | Log at : 2022/4/19|14:25:46|GMT+0800 87 | 88 | Log at : 2022/4/19|15:32:56|GMT+0800 89 | 90 | Log at : 2022/4/19|16:55:25|GMT+0800 91 | 92 | Log at : 2022/4/20|13:08:12|GMT+0800 93 | 94 | Log at : 2022/4/20|13:25:12|GMT+0800 95 | 96 | Log at : 2023/3/11|12:43:24|GMT+0800 97 | 98 | Log at : 2023/3/11|12:44:28|GMT+0800 99 | 100 | Log at : 2023/3/11|15:33:32|GMT+0800 101 | 102 | -------------------------------------------------------------------------------- /HID_template/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_core.h 4 | * @author MCD Application Team 5 | * @brief Header file for usbd_core.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_CORE_H 22 | #define __USBD_CORE_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_conf.h" 30 | #include "usbd_def.h" 31 | #include "usbd_ioreq.h" 32 | #include "usbd_ctlreq.h" 33 | 34 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 35 | * @{ 36 | */ 37 | 38 | /** @defgroup USBD_CORE 39 | * @brief This file is the Header file for usbd_core.c file 40 | * @{ 41 | */ 42 | 43 | 44 | /** @defgroup USBD_CORE_Exported_Defines 45 | * @{ 46 | */ 47 | #ifndef USBD_DEBUG_LEVEL 48 | #define USBD_DEBUG_LEVEL 0U 49 | #endif /* USBD_DEBUG_LEVEL */ 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 56 | * @{ 57 | */ 58 | 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | 66 | /** @defgroup USBD_CORE_Exported_Macros 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup USBD_CORE_Exported_Variables 75 | * @{ 76 | */ 77 | #define USBD_SOF USBD_LL_SOF 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @defgroup USBD_CORE_Exported_FunctionsPrototype 83 | * @{ 84 | */ 85 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id); 86 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); 87 | USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev); 88 | USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev); 89 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass); 90 | 91 | USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev); 92 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 93 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 94 | 95 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup); 96 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); 97 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); 98 | 99 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev); 100 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed); 101 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev); 102 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev); 103 | 104 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev); 105 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 106 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 107 | 108 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev); 109 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev); 110 | 111 | /* USBD Low Level Driver */ 112 | USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev); 113 | USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev); 114 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev); 115 | USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev); 116 | USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, 117 | uint8_t ep_addr, 118 | uint8_t ep_type, 119 | uint16_t ep_mps); 120 | 121 | USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 122 | USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 123 | USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 124 | USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 125 | uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 126 | USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr); 127 | USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, 128 | uint8_t ep_addr, 129 | uint8_t *pbuf, 130 | uint16_t size); 131 | 132 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, 133 | uint8_t ep_addr, 134 | uint8_t *pbuf, 135 | uint16_t size); 136 | 137 | uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 138 | void USBD_LL_Delay(uint32_t Delay); 139 | 140 | /** 141 | * @} 142 | */ 143 | 144 | #ifdef __cplusplus 145 | } 146 | #endif 147 | 148 | #endif /* __USBD_CORE_H */ 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /HID_template/back_up base on custom/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_core.h 4 | * @author MCD Application Team 5 | * @brief Header file for usbd_core.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_CORE_H 22 | #define __USBD_CORE_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_conf.h" 30 | #include "usbd_def.h" 31 | #include "usbd_ioreq.h" 32 | #include "usbd_ctlreq.h" 33 | 34 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 35 | * @{ 36 | */ 37 | 38 | /** @defgroup USBD_CORE 39 | * @brief This file is the Header file for usbd_core.c file 40 | * @{ 41 | */ 42 | 43 | 44 | /** @defgroup USBD_CORE_Exported_Defines 45 | * @{ 46 | */ 47 | #ifndef USBD_DEBUG_LEVEL 48 | #define USBD_DEBUG_LEVEL 0U 49 | #endif /* USBD_DEBUG_LEVEL */ 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 56 | * @{ 57 | */ 58 | 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | 66 | /** @defgroup USBD_CORE_Exported_Macros 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup USBD_CORE_Exported_Variables 75 | * @{ 76 | */ 77 | #define USBD_SOF USBD_LL_SOF 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @defgroup USBD_CORE_Exported_FunctionsPrototype 83 | * @{ 84 | */ 85 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id); 86 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); 87 | USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev); 88 | USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev); 89 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass); 90 | 91 | USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev); 92 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 93 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 94 | 95 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup); 96 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); 97 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); 98 | 99 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev); 100 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed); 101 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev); 102 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev); 103 | 104 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev); 105 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 106 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 107 | 108 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev); 109 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev); 110 | 111 | /* USBD Low Level Driver */ 112 | USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev); 113 | USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev); 114 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev); 115 | USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev); 116 | USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, 117 | uint8_t ep_addr, 118 | uint8_t ep_type, 119 | uint16_t ep_mps); 120 | 121 | USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 122 | USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 123 | USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 124 | USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 125 | uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 126 | USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr); 127 | USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, 128 | uint8_t ep_addr, 129 | uint8_t *pbuf, 130 | uint16_t size); 131 | 132 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, 133 | uint8_t ep_addr, 134 | uint8_t *pbuf, 135 | uint16_t size); 136 | 137 | uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 138 | void USBD_LL_Delay(uint32_t Delay); 139 | 140 | /** 141 | * @} 142 | */ 143 | 144 | #ifdef __cplusplus 145 | } 146 | #endif 147 | 148 | #endif /* __USBD_CORE_H */ 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 159 | 160 | 161 | 162 | --------------------------------------------------------------------------------