diff --git a/Firmware/Pigeon/Inc/usbd_conf.h b/Firmware/Pigeon/Inc/usbd_conf.h index ee7848d..e591347 100644 --- a/Firmware/Pigeon/Inc/usbd_conf.h +++ b/Firmware/Pigeon/Inc/usbd_conf.h @@ -63,7 +63,7 @@ */ /*---------- -----------*/ -#define USBD_MAX_NUM_INTERFACES 1 +#define USBD_MAX_NUM_INTERFACES 2 /*---------- -----------*/ #define USBD_MAX_NUM_CONFIGURATION 1 /*---------- -----------*/ @@ -75,9 +75,9 @@ /*---------- -----------*/ #define USBD_SELF_POWERED 1 /*---------- -----------*/ -#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 2 +#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 64 /*---------- -----------*/ -#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 63 +#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 45 /****************************************/ /* #define for FS and HS identification */ diff --git a/Firmware/Pigeon/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h b/Firmware/Pigeon/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h index 8feeb69..7586bf8 100644 --- a/Firmware/Pigeon/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h +++ b/Firmware/Pigeon/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h @@ -52,11 +52,11 @@ #define WINUSB_EPOUT_ADDR 0x02 #define WINUSB_EPOUT_SIZE 0x40 -#define CUSTOM_HID_EPIN_ADDR 0x81 -#define CUSTOM_HID_EPIN_SIZE 0x02 +#define WINUSB_EPIN_ADDR 0x82 +#define WINUSB_EPIN_SIZE 0x08 -#define CUSTOM_HID_EPOUT_ADDR 0x01 -#define CUSTOM_HID_EPOUT_SIZE 0x02 +#define CUSTOM_HID_EPIN_ADDR 0x81 +#define CUSTOM_HID_EPIN_SIZE 0x08 #define USB_CUSTOM_HID_CONFIG_DESC_SIZ 57 #define USB_CUSTOM_HID_DESC_SIZ 9 diff --git a/Firmware/Pigeon/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c b/Firmware/Pigeon/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c index ae156b0..50b5933 100644 --- a/Firmware/Pigeon/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c +++ b/Firmware/Pigeon/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c @@ -147,7 +147,7 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_ USB_CUSTOM_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */ 0x00, - 0x02, /*bNumInterfaces: 1 interface*/ + 0x02, /*bNumInterfaces: 2 interfaces*/ 0x01, /*bConfigurationValue: Configuration value*/ 0x04, /*iConfiguration: Index of string descriptor describing the configuration*/ @@ -160,11 +160,11 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_ USB_DESC_TYPE_INTERFACE,/*bDescriptorType: Interface descriptor type*/ 0x00, /*bInterfaceNumber: Number of Interface*/ 0x00, /*bAlternateSetting: Alternate setting*/ - 0x02, /*bNumEndpoints*/ + 0x01, /*bNumEndpoints*/ 0x03, /*bInterfaceClass: CUSTOM_HID*/ - 0x00, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/ + 0x01, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/ 0x01, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/ - 0x05, /*iInterface: Index of string descriptor*/ + 0x05, /*iInterface: Index of string descriptor*/ /******************** Descriptor of CUSTOM_HID *************************/ /* 18 */ 0x09, /*bLength: CUSTOM_HID Descriptor size*/ @@ -180,41 +180,40 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_ /* 27 */ 0x07, /*bLength: Endpoint Descriptor size*/ USB_DESC_TYPE_ENDPOINT, /*bDescriptorType:*/ - CUSTOM_HID_EPIN_ADDR, /*bEndpointAddress: Endpoint Address (IN)*/ 0x03, /*bmAttributes: Interrupt endpoint*/ - CUSTOM_HID_EPIN_SIZE, /*wMaxPacketSize: 2 Byte max */ + CUSTOM_HID_EPIN_SIZE, /*wMaxPacketSize: 8 Byte max */ 0x00, - 0x20, /*bInterval: Polling Interval (20 ms)*/ - /* 34 */ - - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */ - CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/ - 0x03, /* bmAttributes: Interrupt endpoint */ - CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */ - 0x00, - 0x20, /* bInterval: Polling Interval (20 ms) */ + 0x02, /*bInterval: Polling Interval (2 ms)*/ /************** Descriptor of WINUSB interface ****************/ - /* 41 */ + /* 34‬ */ 0x09, /*bLength: Interface Descriptor size*/ USB_DESC_TYPE_INTERFACE,/*bDescriptorType: Interface descriptor type*/ 0x01, /*bInterfaceNumber: Number of Interface*/ 0x00, /*bAlternateSetting: Alternate setting*/ - 0x01, /*bNumEndpoints*/ + 0x02, /*bNumEndpoints*/ 0xFF, /*bInterfaceClass: Vendor define*/ 0x00, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/ 0x00, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/ - 0x06, /*iInterface: Index of string descriptor*/ + 0x06, /*iInterface: Index of string descriptor*/ /******************** Descriptor of WINUSB endpoints ********************/ + /* 43 */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */ + WINUSB_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/ + 0x02, /* bmAttributes: Bulk endpoint */ + WINUSB_EPOUT_SIZE, /* wMaxPacketSize: 64 Bytes max */ + 0x00, + 0x0, /* bInterval: Polling Interval (0 ms) */ /* 50 */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */ - WINUSB_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/ - 0x02, /* bmAttributes: Bulk endpoint */ - WINUSB_EPOUT_SIZE, /* wMaxPacketSize: 64 Bytes max */ + + 0x07, /*bLength: Endpoint Descriptor size*/ + USB_DESC_TYPE_ENDPOINT, /*bDescriptorType:*/ + WINUSB_EPIN_ADDR, /*bEndpointAddress: Endpoint Address (IN)*/ + 0x03, /*bmAttributes: Interrupt endpoint*/ + WINUSB_EPIN_SIZE, /*wMaxPacketSize: 8 Byte max */ 0x00, - 0x0, /* bInterval: Polling Interval (20 ms) */ + 0x02, /*bInterval: Polling Interval (2 ms)*/ /* 57 */ } ; @@ -274,16 +273,18 @@ static uint8_t USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev, USBD_EP_TYPE_INTR, CUSTOM_HID_EPIN_SIZE); - /* Open EP OUT */ + /* Open EP IN */ USBD_LL_OpenEP(pdev, - CUSTOM_HID_EPOUT_ADDR, + WINUSB_EPIN_ADDR, USBD_EP_TYPE_INTR, - CUSTOM_HID_EPOUT_SIZE); + WINUSB_EPIN_SIZE); + /* Open EP OUT */ USBD_LL_OpenEP(pdev, WINUSB_EPOUT_ADDR, - USBD_EP_TYPE_INTR, + USBD_EP_TYPE_BULK, WINUSB_EPOUT_SIZE); + pdev->pClassData = USBD_malloc(sizeof (USBD_CUSTOM_HID_HandleTypeDef)); if(pdev->pClassData == NULL) @@ -297,7 +298,7 @@ static uint8_t USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev, hhid->state = CUSTOM_HID_IDLE; ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->Init(); /* Prepare Out endpoint to receive 1st packet */ - USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf, + USBD_LL_PrepareReceive(pdev, WINUSB_EPOUT_ADDR, hhid->Report_buf, USBD_CUSTOMHID_OUTREPORT_BUF_SIZE); } @@ -317,10 +318,12 @@ static uint8_t USBD_CUSTOM_HID_DeInit (USBD_HandleTypeDef *pdev, /* Close CUSTOM_HID EP IN */ USBD_LL_CloseEP(pdev, CUSTOM_HID_EPIN_ADDR); + USBD_LL_CloseEP(pdev, + WINUSB_EPIN_ADDR); /* Close CUSTOM_HID EP OUT */ USBD_LL_CloseEP(pdev, - CUSTOM_HID_EPOUT_ADDR); + WINUSB_EPOUT_ADDR); /* FRee allocated memory */ if(pdev->pClassData != NULL) @@ -493,7 +496,7 @@ static uint8_t USBD_CUSTOM_HID_DataOut (USBD_HandleTypeDef *pdev, ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0], hhid->Report_buf[1]); - USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR , hhid->Report_buf, + USBD_LL_PrepareReceive(pdev, WINUSB_EPOUT_ADDR , hhid->Report_buf, USBD_CUSTOMHID_OUTREPORT_BUF_SIZE); return USBD_OK; diff --git a/Firmware/Pigeon/Src/main.c b/Firmware/Pigeon/Src/main.c index 3161cb5..84eaf9a 100644 --- a/Firmware/Pigeon/Src/main.c +++ b/Firmware/Pigeon/Src/main.c @@ -28,6 +28,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "st7735_hal.h" +#include "usbd_customhid.h" // #include "usb_cmd.h" /* USER CODE END Includes */ @@ -51,7 +52,26 @@ /* USER CODE BEGIN PV */ extern TIM_HandleTypeDef htim2; extern SPI_HandleTypeDef hspi1; +extern USBD_HandleTypeDef hUsbDeviceFS; uint8_t b=0; +/* keybuf[0] -bit0: Left CTRL + * -bit1: Left SHIFT + * -bit2: Left ALT + * -bit3: Left GUI + * -bit4: Right CTRL + * -bit5: Right SHIFT + * -bit6: Right ALT + * -bit7: Right GUI + * keybuf[1] - Padding = Always 0x00 + * keybuf[2] - Key 1 + * keybuf[3] - Key 2 + * keybuf[4] - Key 3 + * keybuf[5] - Key 4 + * keybuf[6] - Key 5 + * keybuf[7] - Key 6 + */ + uint8_t keybuf[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +uint8_t sth[13]={0x1e,0x1e,0x21,0x22,0x1e,0x21,0x1e,0x26,0x1e,0x26,0x25,0x1e,0x27}; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -62,7 +82,17 @@ void SystemClock_Config(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ - +void keyPress(){ + for (int i = 0; i < 13; ++i) + { + keybuf[2]=sth[i]; + while(USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, keybuf, 8)); //发送键值 + HAL_Delay(11); + keybuf[2]=0x00; + while(USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, keybuf, 8)); //发送键值 + HAL_Delay(11); + } +} /* USER CODE END 0 */ /** @@ -101,25 +131,23 @@ int main(void) HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2); ST7735_Init(&hspi1); ST7735_FillScreen(ST7735_WHITE); - //ST7735_print("Boot Done!", Font_7x10, ST7735_WHITE, ST7735_BLACK); + ST7735_print("KOKODAYO!", Font_7x10, ST7735_RED, ST7735_WHITE); + __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, 50); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { - if(HAL_GPIO_ReadPin(FUN_KEY_GPIO_Port, FUN_KEY_Pin) == GPIO_PIN_SET) //按下按键 + if(HAL_GPIO_ReadPin(FUN_KEY_GPIO_Port, FUN_KEY_Pin) == GPIO_PIN_SET) { - HAL_Delay(20); //按键延时消抖 - if(HAL_GPIO_ReadPin(FUN_KEY_GPIO_Port, FUN_KEY_Pin) == GPIO_PIN_SET) //按键仍在按下状?? + HAL_Delay(20); + if(HAL_GPIO_ReadPin(FUN_KEY_GPIO_Port, FUN_KEY_Pin) == GPIO_PIN_SET) { - - while(HAL_GPIO_ReadPin(FUN_KEY_GPIO_Port, FUN_KEY_Pin) == GPIO_PIN_SET) //等待松开按键 + while(HAL_GPIO_ReadPin(FUN_KEY_GPIO_Port, FUN_KEY_Pin) == GPIO_PIN_SET) { - __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, b++); - HAL_Delay(10); } - + keyPress(); } } /* USER CODE END WHILE */ diff --git a/Firmware/Pigeon/Src/usbd_conf.c b/Firmware/Pigeon/Src/usbd_conf.c index bee52cf..825adc1 100644 --- a/Firmware/Pigeon/Src/usbd_conf.c +++ b/Firmware/Pigeon/Src/usbd_conf.c @@ -337,8 +337,11 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) /* USER CODE END EndPoint_Configuration */ /* USER CODE BEGIN EndPoint_Configuration_CUSTOM_HID */ HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CUSTOM_HID_EPIN_ADDR , PCD_SNG_BUF, 0x98); - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CUSTOM_HID_EPOUT_ADDR , PCD_SNG_BUF, 0xD8); /* USER CODE END EndPoint_Configuration_CUSTOM_HID */ + /* USER CODE BEGIN EndPoint_Configuration_WINUSB */ + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , WINUSB_EPIN_ADDR , PCD_SNG_BUF, 0xD8); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , WINUSB_EPOUT_ADDR , PCD_SNG_BUF, 0x118); + /* USER CODE END EndPoint_Configuration_WINUSB */ return USBD_OK; } diff --git a/Firmware/Pigeon/Src/usbd_custom_hid_if.c b/Firmware/Pigeon/Src/usbd_custom_hid_if.c index 7448265..e9bb0a1 100644 --- a/Firmware/Pigeon/Src/usbd_custom_hid_if.c +++ b/Firmware/Pigeon/Src/usbd_custom_hid_if.c @@ -103,18 +103,11 @@ __ALIGN_BEGIN static uint8_t CUSTOM_HID_ReportDesc_FS[USBD_CUSTOM_HID_REPORT_DES 0x75, 0x01, // REPORT_SIZE (1) 0x95, 0x08, // REPORT_COUNT (8) 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x95, 0x01, // REPORT_COUNT (1) 0x75, 0x08, // REPORT_SIZE (8) 0x81, 0x03, // INPUT (Cnst,Var,Abs) - 0x95, 0x05, // REPORT_COUNT (5) - 0x75, 0x01, // REPORT_SIZE (1) - 0x05, 0x08, // USAGE_PAGE (LEDs) - 0x19, 0x01, // USAGE_MINIMUM (Num Lock) - 0x29, 0x05, // USAGE_MAXIMUM (Kana) - 0x91, 0x02, // OUTPUT (Data,Var,Abs) - 0x95, 0x01, // REPORT_COUNT (1) - 0x75, 0x03, // REPORT_SIZE (3) - 0x91, 0x03, // OUTPUT (Cnst,Var,Abs) + 0x95, 0x06, // REPORT_COUNT (6) 0x75, 0x08, // REPORT_SIZE (8) 0x15, 0x00, // LOGICAL_MINIMUM (0)