check hid write return val because test hid in task not in isr

This commit is contained in:
sakumisu
2022-08-20 20:29:00 +08:00
parent b72e794ea7
commit 1e80e240e2
4 changed files with 35 additions and 36 deletions

View File

@@ -1,9 +1,6 @@
#include "usbd_core.h"
#include "usbd_hid.h"
#define HID_STATE_IDLE 0
#define HID_STATE_BUSY 1
/*!< hidraw in endpoint */
#define HIDRAW_IN_EP 0x81
#define HIDRAW_IN_SIZE 64
@@ -19,9 +16,6 @@
#define USBD_MAX_POWER 100
#define USBD_LANGID_STRING 1033
/*!< hid state ! Data can be sent only when state is idle */
static uint8_t custom_state = HID_STATE_IDLE;
/*!< config descriptor size */
#define USB_HID_CONFIG_DESC_SIZ (9 + 9 + 9 + 7 + 7)
@@ -166,6 +160,12 @@ static const uint8_t hid_custom_report_desc[HID_CUSTOM_REPORT_DESC_SIZE] = {
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[2048];
#define HID_STATE_IDLE 0
#define HID_STATE_BUSY 1
/*!< hid state ! Data can be sent only when state is idle */
static volatile uint8_t custom_state = HID_STATE_IDLE;
void usbd_configure_done_callback(void)
{
/* setup first out ep read transfer */
@@ -175,10 +175,7 @@ void usbd_configure_done_callback(void)
static void usbd_hid_custom_in_callback(uint8_t ep, uint32_t nbytes)
{
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
if (custom_state == HID_STATE_BUSY) {
/*!< update the state */
custom_state = HID_STATE_IDLE;
}
custom_state = HID_STATE_IDLE;
}
static void usbd_hid_custom_out_callback(uint8_t ep, uint32_t nbytes)
@@ -218,7 +215,10 @@ void hid_custom_test(void)
{
uint8_t sendbuffer[64] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 };
custom_state = HID_STATE_BUSY;
usbd_ep_start_write(HIDRAW_IN_EP, sendbuffer, 8);
int ret = usbd_ep_start_write(HIDRAW_IN_EP, sendbuffer, 8);
if (ret < 0) {
return;
}
while (custom_state == HID_STATE_BUSY) {
}
}