update(demo): set hid busy before write

This commit is contained in:
sakumisu
2024-11-13 21:44:46 +08:00
parent 24fc172ad8
commit e3ff8ffe6a
6 changed files with 27 additions and 21 deletions

View File

@@ -332,14 +332,15 @@ void cdc_acm_hid_msc_descriptor_init(uint8_t busid, uintptr_t reg_base)
*/ */
void hid_mouse_test(uint8_t busid) void hid_mouse_test(uint8_t busid)
{ {
if(usb_device_is_configured(busid) == false) {
return;
}
/*!< move mouse pointer */ /*!< move mouse pointer */
mouse_cfg.x += 10; mouse_cfg.x += 10;
mouse_cfg.y = 0; mouse_cfg.y = 0;
int ret = usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
if (ret < 0) {
return;
}
hid_state = HID_STATE_BUSY; hid_state = HID_STATE_BUSY;
usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
while (hid_state == HID_STATE_BUSY) { while (hid_state == HID_STATE_BUSY) {
} }
} }

View File

@@ -236,12 +236,13 @@ void hid_keyboard_test(uint8_t busid)
{ {
const uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 }; const uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 };
memcpy(write_buffer, sendbuffer, 8); if(usb_device_is_configured(busid) == false) {
int ret = usbd_ep_start_write(busid, HID_INT_EP, write_buffer, 8);
if (ret < 0) {
return; return;
} }
memcpy(write_buffer, sendbuffer, 8);
hid_state = HID_STATE_BUSY; hid_state = HID_STATE_BUSY;
usbd_ep_start_write(busid, HID_INT_EP, write_buffer, 8);
while (hid_state == HID_STATE_BUSY) { while (hid_state == HID_STATE_BUSY) {
} }
} }

View File

@@ -304,14 +304,15 @@ void draw_circle(uint8_t *buf)
/* https://cps-check.com/cn/polling-rate-check */ /* https://cps-check.com/cn/polling-rate-check */
void hid_mouse_test(uint8_t busid) void hid_mouse_test(uint8_t busid)
{ {
if(usb_device_is_configured(busid) == false) {
return;
}
int counter = 0; int counter = 0;
while (counter < 1000) { while (counter < 1000) {
draw_circle((uint8_t *)&mouse_cfg); draw_circle((uint8_t *)&mouse_cfg);
int ret = usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
if (ret < 0) {
return;
}
hid_state = HID_STATE_BUSY; hid_state = HID_STATE_BUSY;
usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
while (hid_state == HID_STATE_BUSY) { while (hid_state == HID_STATE_BUSY) {
} }

View File

@@ -307,6 +307,10 @@ void hid_mouse_test(uint8_t busid)
static uint32_t count = 1000; static uint32_t count = 1000;
int ret; int ret;
if(usb_device_is_configured(busid) == false) {
return;
}
// if (gpio_read_pin(GPIO_PIN) == 1) { // if (gpio_read_pin(GPIO_PIN) == 1) {
// ret = usbd_send_remote_wakeup(busid); // ret = usbd_send_remote_wakeup(busid);
// if (ret < 0) { // if (ret < 0) {
@@ -317,11 +321,8 @@ void hid_mouse_test(uint8_t busid)
while (count) { while (count) {
draw_circle((uint8_t *)&mouse_cfg); draw_circle((uint8_t *)&mouse_cfg);
int ret = usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
if (ret < 0) {
return;
}
hid_state = HID_STATE_BUSY; hid_state = HID_STATE_BUSY;
usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
while (hid_state == HID_STATE_BUSY) { while (hid_state == HID_STATE_BUSY) {
} }

View File

@@ -458,12 +458,13 @@ void hid_keyboard_test(uint8_t busid)
{ {
const uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 }; const uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 };
memcpy(hid_write_buffer, sendbuffer, 8); if(usb_device_is_configured(busid) == false) {
int ret = usbd_ep_start_write(busid, HID_INT_EP, hid_write_buffer, 8);
if (ret < 0) {
return; return;
} }
memcpy(hid_write_buffer, sendbuffer, 8);
hid_state = HID_STATE_BUSY; hid_state = HID_STATE_BUSY;
usbd_ep_start_write(busid, HID_INT_EP, hid_write_buffer, 8);
while (hid_state == HID_STATE_BUSY) { while (hid_state == HID_STATE_BUSY) {
} }
} }

View File

@@ -371,12 +371,13 @@ void hid_keyboard_test(uint8_t busid)
{ {
const uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 }; const uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 };
memcpy(write_buffer, sendbuffer, 8); if(usb_device_is_configured(busid) == false) {
int ret = usbd_ep_start_write(busid, HID_INT_EP, write_buffer, 8);
if (ret < 0) {
return; return;
} }
memcpy(write_buffer, sendbuffer, 8);
hid_state = HID_STATE_BUSY; hid_state = HID_STATE_BUSY;
usbd_ep_start_write(busid, HID_INT_EP, write_buffer, 8);
while (hid_state == HID_STATE_BUSY) { while (hid_state == HID_STATE_BUSY) {
} }
} }