diff options
| author | sakumisu <[email protected]> | 2022-08-20 20:29:00 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2022-08-20 20:29:00 +0800 |
| commit | 1e80e240e2ebe1eae047340f10bf4225e9dfd7e2 (patch) | |
| tree | 84d09774b6d0e5112becb420cf9f6fa3ee631b65 | |
| parent | b72e794ea7bafafa07de1d0c501ec94402c773fa (diff) | |
check hid write return val because test hid in task not in isr
| -rw-r--r-- | demo/cdc_acm_hid_msc_template.c | 9 | ||||
| -rw-r--r-- | demo/hid_custom_inout_template.c | 22 | ||||
| -rw-r--r-- | demo/hid_keyboard_template.c | 16 | ||||
| -rw-r--r-- | demo/hid_mouse_template.c | 24 |
4 files changed, 35 insertions, 36 deletions
diff --git a/demo/cdc_acm_hid_msc_template.c b/demo/cdc_acm_hid_msc_template.c index 0f0ce420..dbb40776 100644 --- a/demo/cdc_acm_hid_msc_template.c +++ b/demo/cdc_acm_hid_msc_template.c @@ -13,7 +13,7 @@ /*!< endpoint address */ #define HID_INT_EP 0x86 -#define HID_INT_EP_SIZE 8 +#define HID_INT_EP_SIZE 4 #define HID_INT_EP_INTERVAL 10 #define USBD_VID 0xFFFF @@ -230,7 +230,7 @@ static struct hid_mouse mouse_cfg; #define HID_STATE_BUSY 1 /*!< hid state ! Data can be sent only when state is idle */ -static uint8_t hid_state = HID_STATE_IDLE; +static volatile uint8_t hid_state = HID_STATE_IDLE; /* function ------------------------------------------------------------------*/ static void usbd_hid_int_callback(uint8_t ep, uint32_t nbytes) @@ -337,7 +337,10 @@ void hid_mouse_test(void) /*!< move mouse pointer */ mouse_cfg.x += 10; mouse_cfg.y = 0; - usbd_ep_start_write(HID_INT_EP, (uint8_t *)&mouse_cfg, 4); + int ret = usbd_ep_start_write(HID_INT_EP, (uint8_t *)&mouse_cfg, 4); + if (ret < 0) { + return; + } while (hid_state == HID_STATE_BUSY) { } } diff --git a/demo/hid_custom_inout_template.c b/demo/hid_custom_inout_template.c index 4570b57f..c62f81d8 100644 --- a/demo/hid_custom_inout_template.c +++ b/demo/hid_custom_inout_template.c @@ -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) { } }
\ No newline at end of file diff --git a/demo/hid_keyboard_template.c b/demo/hid_keyboard_template.c index e4fc04f9..4dddf148 100644 --- a/demo/hid_keyboard_template.c +++ b/demo/hid_keyboard_template.c @@ -181,21 +181,16 @@ void usbd_configure_done_callback(void) #define HID_STATE_BUSY 1 /*!< hid state ! Data can be sent only when state is idle */ -static uint8_t hid_state = HID_STATE_IDLE; +static volatile uint8_t hid_state = HID_STATE_IDLE; void usbd_hid_int_callback(uint8_t ep, uint32_t nbytes) { - /*!< endpoint call back */ - /*!< transfer successfully */ - if (hid_state == HID_STATE_BUSY) { - /*!< update the state */ - hid_state = HID_STATE_IDLE; - } + hid_state = HID_STATE_IDLE; } static struct usbd_endpoint hid_in_ep = { .ep_cb = usbd_hid_int_callback, - .ep_addr = 0x81 + .ep_addr = HID_INT_EP }; void hid_keyboard_init(void) @@ -211,7 +206,10 @@ void hid_keyboard_test(void) { uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 }; //A hid_state = HID_STATE_BUSY; - usbd_ep_start_write(HID_INT_EP, sendbuffer, 8); + int ret = usbd_ep_start_write(HID_INT_EP, sendbuffer, 8); + if (ret < 0) { + return; + } while (hid_state == HID_STATE_BUSY) { } } diff --git a/demo/hid_mouse_template.c b/demo/hid_mouse_template.c index e44c2da5..aa4f24d6 100644 --- a/demo/hid_mouse_template.c +++ b/demo/hid_mouse_template.c @@ -1,12 +1,9 @@ #include "usbd_core.h" #include "usbd_hid.h" -#define HID_STATE_IDLE 0 -#define HID_STATE_BUSY 1 - /*!< endpoint address */ #define HID_INT_EP 0x81 -#define HID_INT_EP_SIZE 8 +#define HID_INT_EP_SIZE 4 #define HID_INT_EP_INTERVAL 10 #define USBD_VID 0xffff @@ -191,8 +188,11 @@ struct hid_mouse { /*!< mouse report */ static struct hid_mouse mouse_cfg; +#define HID_STATE_IDLE 0 +#define HID_STATE_BUSY 1 + /*!< hid state ! Data can be sent only when state is idle */ -static uint8_t hid_state = HID_STATE_IDLE; +static volatile uint8_t hid_state = HID_STATE_IDLE; void usbd_configure_done_callback(void) { @@ -202,18 +202,13 @@ void usbd_configure_done_callback(void) /* function ------------------------------------------------------------------*/ static void usbd_hid_int_callback(uint8_t ep, uint32_t nbytes) { - /*!< endpoint call back */ - /*!< transfer successfully */ - if (hid_state == HID_STATE_BUSY) { - /*!< update the state */ - hid_state = HID_STATE_IDLE; - } + hid_state = HID_STATE_IDLE; } /*!< endpoint call back */ static struct usbd_endpoint hid_in_ep = { .ep_cb = usbd_hid_int_callback, - .ep_addr = 0x81 + .ep_addr = HID_INT_EP }; /* function ------------------------------------------------------------------*/ @@ -250,7 +245,10 @@ void hid_mouse_test(void) mouse_cfg.x += 10; mouse_cfg.y = 0; hid_state = HID_STATE_BUSY; - usbd_ep_start_write(HID_INT_EP, (uint8_t *)&mouse_cfg, 4); + int ret = usbd_ep_start_write(HID_INT_EP, (uint8_t *)&mouse_cfg, 4); + if (ret < 0) { + return; + } while (hid_state == HID_STATE_BUSY) { } } |
