Skip to content

Commit

Permalink
update(demo): set hid busy before write
Browse files Browse the repository at this point in the history
  • Loading branch information
sakumisu committed Nov 13, 2024
1 parent 24fc172 commit e3ff8ff
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
9 changes: 5 additions & 4 deletions demo/cdc_acm_hid_msc_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
if(usb_device_is_configured(busid) == false) {
return;
}
/*!< move mouse pointer */
mouse_cfg.x += 10;
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;
usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
while (hid_state == HID_STATE_BUSY) {
}
}
Expand Down
7 changes: 4 additions & 3 deletions demo/hid_keyboard_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

memcpy(write_buffer, sendbuffer, 8);
int ret = usbd_ep_start_write(busid, HID_INT_EP, write_buffer, 8);
if (ret < 0) {
if(usb_device_is_configured(busid) == false) {
return;
}

memcpy(write_buffer, sendbuffer, 8);
hid_state = HID_STATE_BUSY;
usbd_ep_start_write(busid, HID_INT_EP, write_buffer, 8);
while (hid_state == HID_STATE_BUSY) {
}
}
9 changes: 5 additions & 4 deletions demo/hid_mouse_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,15 @@ void draw_circle(uint8_t *buf)
/* https://cps-check.com/cn/polling-rate-check */
void hid_mouse_test(uint8_t busid)
{
if(usb_device_is_configured(busid) == false) {
return;
}

int counter = 0;
while (counter < 1000) {
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;
usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
while (hid_state == HID_STATE_BUSY) {
}

Expand Down
9 changes: 5 additions & 4 deletions demo/hid_remote_wakeup_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ void hid_mouse_test(uint8_t busid)
static uint32_t count = 1000;
int ret;

if(usb_device_is_configured(busid) == false) {
return;
}

// if (gpio_read_pin(GPIO_PIN) == 1) {
// ret = usbd_send_remote_wakeup(busid);
// if (ret < 0) {
Expand All @@ -317,11 +321,8 @@ void hid_mouse_test(uint8_t busid)

while (count) {
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;
usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
while (hid_state == HID_STATE_BUSY) {
}

Expand Down
7 changes: 4 additions & 3 deletions demo/video_audiov1_hid_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

memcpy(hid_write_buffer, sendbuffer, 8);
int ret = usbd_ep_start_write(busid, HID_INT_EP, hid_write_buffer, 8);
if (ret < 0) {
if(usb_device_is_configured(busid) == false) {
return;
}

memcpy(hid_write_buffer, sendbuffer, 8);
hid_state = HID_STATE_BUSY;
usbd_ep_start_write(busid, HID_INT_EP, hid_write_buffer, 8);
while (hid_state == HID_STATE_BUSY) {
}
}
Expand Down
7 changes: 4 additions & 3 deletions demo/webusb_hid_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

memcpy(write_buffer, sendbuffer, 8);
int ret = usbd_ep_start_write(busid, HID_INT_EP, write_buffer, 8);
if (ret < 0) {
if(usb_device_is_configured(busid) == false) {
return;
}

memcpy(write_buffer, sendbuffer, 8);
hid_state = HID_STATE_BUSY;
usbd_ep_start_write(busid, HID_INT_EP, write_buffer, 8);
while (hid_state == HID_STATE_BUSY) {
}
}

0 comments on commit e3ff8ff

Please sign in to comment.