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

@@ -13,7 +13,7 @@
/*!< endpoint address */ /*!< endpoint address */
#define HID_INT_EP 0x86 #define HID_INT_EP 0x86
#define HID_INT_EP_SIZE 8 #define HID_INT_EP_SIZE 4
#define HID_INT_EP_INTERVAL 10 #define HID_INT_EP_INTERVAL 10
#define USBD_VID 0xFFFF #define USBD_VID 0xFFFF
@@ -230,7 +230,7 @@ static struct hid_mouse mouse_cfg;
#define HID_STATE_BUSY 1 #define HID_STATE_BUSY 1
/*!< hid state ! Data can be sent only when state is idle */ /*!< 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 ------------------------------------------------------------------*/ /* function ------------------------------------------------------------------*/
static void usbd_hid_int_callback(uint8_t ep, uint32_t nbytes) static void usbd_hid_int_callback(uint8_t ep, uint32_t nbytes)
@@ -337,7 +337,10 @@ void hid_mouse_test(void)
/*!< move mouse pointer */ /*!< move mouse pointer */
mouse_cfg.x += 10; mouse_cfg.x += 10;
mouse_cfg.y = 0; 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) { while (hid_state == HID_STATE_BUSY) {
} }
} }

View File

@@ -1,9 +1,6 @@
#include "usbd_core.h" #include "usbd_core.h"
#include "usbd_hid.h" #include "usbd_hid.h"
#define HID_STATE_IDLE 0
#define HID_STATE_BUSY 1
/*!< hidraw in endpoint */ /*!< hidraw in endpoint */
#define HIDRAW_IN_EP 0x81 #define HIDRAW_IN_EP 0x81
#define HIDRAW_IN_SIZE 64 #define HIDRAW_IN_SIZE 64
@@ -19,9 +16,6 @@
#define USBD_MAX_POWER 100 #define USBD_MAX_POWER 100
#define USBD_LANGID_STRING 1033 #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 */ /*!< config descriptor size */
#define USB_HID_CONFIG_DESC_SIZ (9 + 9 + 9 + 7 + 7) #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]; 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) void usbd_configure_done_callback(void)
{ {
/* setup first out ep read transfer */ /* 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) static void usbd_hid_custom_in_callback(uint8_t ep, uint32_t nbytes)
{ {
USB_LOG_RAW("actual in len:%d\r\n", nbytes); USB_LOG_RAW("actual in len:%d\r\n", nbytes);
if (custom_state == HID_STATE_BUSY) { custom_state = HID_STATE_IDLE;
/*!< update the state */
custom_state = HID_STATE_IDLE;
}
} }
static void usbd_hid_custom_out_callback(uint8_t ep, uint32_t nbytes) 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 }; uint8_t sendbuffer[64] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 };
custom_state = HID_STATE_BUSY; 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) { while (custom_state == HID_STATE_BUSY) {
} }
} }

View File

@@ -181,21 +181,16 @@ void usbd_configure_done_callback(void)
#define HID_STATE_BUSY 1 #define HID_STATE_BUSY 1
/*!< hid state ! Data can be sent only when state is idle */ /*!< 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) void usbd_hid_int_callback(uint8_t ep, uint32_t nbytes)
{ {
/*!< endpoint call back */ hid_state = HID_STATE_IDLE;
/*!< transfer successfully */
if (hid_state == HID_STATE_BUSY) {
/*!< update the state */
hid_state = HID_STATE_IDLE;
}
} }
static struct usbd_endpoint hid_in_ep = { static struct usbd_endpoint hid_in_ep = {
.ep_cb = usbd_hid_int_callback, .ep_cb = usbd_hid_int_callback,
.ep_addr = 0x81 .ep_addr = HID_INT_EP
}; };
void hid_keyboard_init(void) 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 uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 }; //A
hid_state = HID_STATE_BUSY; 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) { while (hid_state == HID_STATE_BUSY) {
} }
} }

View File

@@ -1,12 +1,9 @@
#include "usbd_core.h" #include "usbd_core.h"
#include "usbd_hid.h" #include "usbd_hid.h"
#define HID_STATE_IDLE 0
#define HID_STATE_BUSY 1
/*!< endpoint address */ /*!< endpoint address */
#define HID_INT_EP 0x81 #define HID_INT_EP 0x81
#define HID_INT_EP_SIZE 8 #define HID_INT_EP_SIZE 4
#define HID_INT_EP_INTERVAL 10 #define HID_INT_EP_INTERVAL 10
#define USBD_VID 0xffff #define USBD_VID 0xffff
@@ -191,8 +188,11 @@ struct hid_mouse {
/*!< mouse report */ /*!< mouse report */
static struct hid_mouse mouse_cfg; 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 */ /*!< 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) void usbd_configure_done_callback(void)
{ {
@@ -202,18 +202,13 @@ void usbd_configure_done_callback(void)
/* function ------------------------------------------------------------------*/ /* function ------------------------------------------------------------------*/
static void usbd_hid_int_callback(uint8_t ep, uint32_t nbytes) static void usbd_hid_int_callback(uint8_t ep, uint32_t nbytes)
{ {
/*!< endpoint call back */ hid_state = HID_STATE_IDLE;
/*!< transfer successfully */
if (hid_state == HID_STATE_BUSY) {
/*!< update the state */
hid_state = HID_STATE_IDLE;
}
} }
/*!< endpoint call back */ /*!< endpoint call back */
static struct usbd_endpoint hid_in_ep = { static struct usbd_endpoint hid_in_ep = {
.ep_cb = usbd_hid_int_callback, .ep_cb = usbd_hid_int_callback,
.ep_addr = 0x81 .ep_addr = HID_INT_EP
}; };
/* function ------------------------------------------------------------------*/ /* function ------------------------------------------------------------------*/
@@ -250,7 +245,10 @@ void hid_mouse_test(void)
mouse_cfg.x += 10; mouse_cfg.x += 10;
mouse_cfg.y = 0; mouse_cfg.y = 0;
hid_state = HID_STATE_BUSY; 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) { while (hid_state == HID_STATE_BUSY) {
} }
} }