From 86081b1e89b5ef1803b9f6ca2fda29cf66ebeb8f Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Fri, 14 Oct 2022 20:00:20 +0800 Subject: [PATCH] fix hid state and video state --- demo/cdc_acm_hid_msc_template.c | 8 ++------ demo/hid_custom_inout_template.c | 3 ++- demo/hid_keyboard_template.c | 3 ++- demo/hid_mouse_template.c | 3 ++- demo/video_static_mjpeg_template.c | 16 +++++++++++++--- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/demo/cdc_acm_hid_msc_template.c b/demo/cdc_acm_hid_msc_template.c index dbb40776..13b97cdc 100644 --- a/demo/cdc_acm_hid_msc_template.c +++ b/demo/cdc_acm_hid_msc_template.c @@ -235,12 +235,7 @@ static volatile uint8_t hid_state = HID_STATE_IDLE; /* 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 */ @@ -341,6 +336,7 @@ void hid_mouse_test(void) if (ret < 0) { return; } + hid_state = HID_STATE_BUSY; while (hid_state == HID_STATE_BUSY) { } } diff --git a/demo/hid_custom_inout_template.c b/demo/hid_custom_inout_template.c index c62f81d8..c1e80212 100644 --- a/demo/hid_custom_inout_template.c +++ b/demo/hid_custom_inout_template.c @@ -214,11 +214,12 @@ void hid_custom_keyboard_init(void) 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; + int ret = usbd_ep_start_write(HIDRAW_IN_EP, sendbuffer, 8); if (ret < 0) { return; } + custom_state = HID_STATE_BUSY; 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 4dddf148..4b41bbfb 100644 --- a/demo/hid_keyboard_template.c +++ b/demo/hid_keyboard_template.c @@ -205,11 +205,12 @@ void hid_keyboard_init(void) 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; + int ret = usbd_ep_start_write(HID_INT_EP, sendbuffer, 8); if (ret < 0) { return; } + hid_state = HID_STATE_BUSY; while (hid_state == HID_STATE_BUSY) { } } diff --git a/demo/hid_mouse_template.c b/demo/hid_mouse_template.c index aa4f24d6..971ab1f0 100644 --- a/demo/hid_mouse_template.c +++ b/demo/hid_mouse_template.c @@ -244,11 +244,12 @@ void hid_mouse_test(void) /*!< move mouse pointer */ mouse_cfg.x += 10; mouse_cfg.y = 0; - hid_state = HID_STATE_BUSY; + int ret = usbd_ep_start_write(HID_INT_EP, (uint8_t *)&mouse_cfg, 4); if (ret < 0) { return; } + hid_state = HID_STATE_BUSY; while (hid_state == HID_STATE_BUSY) { } } diff --git a/demo/video_static_mjpeg_template.c b/demo/video_static_mjpeg_template.c index 685b01da..43ce25bf 100644 --- a/demo/video_static_mjpeg_template.c +++ b/demo/video_static_mjpeg_template.c @@ -147,20 +147,21 @@ void usbd_configure_done_callback(void) } volatile bool tx_flag = 0; +volatile bool iso_tx_busy = false; void usbd_video_open(uint8_t intf) { tx_flag = 1; USB_LOG_RAW("OPEN\r\n"); + iso_tx_busy = false; } void usbd_video_close(uint8_t intf) { USB_LOG_RAW("CLOSE\r\n"); tx_flag = 0; + iso_tx_busy = false; } -volatile bool iso_tx_busy = false; - void usbd_video_iso_callback(uint8_t ep, uint32_t nbytes) { USB_LOG_RAW("actual in len:%d\r\n", nbytes); @@ -182,7 +183,7 @@ void video_init() usbd_initialize(); } -USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t packet_buffer[10 * 1024]; +USB_MEM_ALIGNX uint8_t packet_buffer[10 * 1024]; void video_test() { @@ -196,6 +197,9 @@ void video_test() iso_tx_busy = true; usbd_ep_start_write(VIDEO_IN_EP, packet_buffer, out_len); while (iso_tx_busy) { + if (tx_flag == 0) { + break; + } } #else /* dwc2 must use this method */ @@ -204,11 +208,17 @@ void video_test() iso_tx_busy = true; usbd_ep_start_write(VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], out_len - (packets - 1) * MAX_PAYLOAD_SIZE); while (iso_tx_busy) { + if (tx_flag == 0) { + break; + } } } else { iso_tx_busy = true; usbd_ep_start_write(VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], MAX_PAYLOAD_SIZE); while (iso_tx_busy) { + if (tx_flag == 0) { + break; + } } } }