mirror of
https://gitee.com/Vancouver2017/luban-lite-t3e-pro.git
synced 2025-12-14 02:18:54 +00:00
60 lines
1.8 KiB
C
60 lines
1.8 KiB
C
/*
|
|
* Copyright (c) 2023-2024, ArtInChip Technology Co., Ltd
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
*/
|
|
|
|
#include <rtconfig.h>
|
|
#include "usbh_core.h"
|
|
#include "usbh_hid.h"
|
|
|
|
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t hid_buffer[128];
|
|
|
|
void usbh_hid_callback(void *arg, int nbytes)
|
|
{
|
|
struct usbh_hid *hid_class = (struct usbh_hid *)arg;
|
|
|
|
if (nbytes > 0) {
|
|
for (int i = 0; i < nbytes; i++) {
|
|
USB_LOG_RAW("0x%02x ", hid_buffer[i]);
|
|
}
|
|
USB_LOG_RAW("nbytes:%d\r\n", nbytes);
|
|
usbh_int_urb_fill(&hid_class->intin_urb, hid_class->hport, hid_class->intin, hid_buffer, hid_class->intin->wMaxPacketSize, 0, usbh_hid_callback, hid_class);
|
|
usbh_submit_urb(&hid_class->intin_urb);
|
|
} else if (nbytes == -USB_ERR_NAK) { /* only dwc2 should do this */
|
|
usbh_int_urb_fill(&hid_class->intin_urb, hid_class->hport, hid_class->intin, hid_buffer, hid_class->intin->wMaxPacketSize, 0, usbh_hid_callback, hid_class);
|
|
usbh_submit_urb(&hid_class->intin_urb);
|
|
} else {
|
|
}
|
|
}
|
|
|
|
static void usbh_hid_thread(void *argument)
|
|
{
|
|
int ret;
|
|
struct usbh_hid *hid_class = (struct usbh_hid *)argument;
|
|
|
|
/* test with only one buffer, if you have more hid class, modify by yourself */
|
|
|
|
/* Suggest you to use timer for int transfer and use ep interval */
|
|
usbh_int_urb_fill(&hid_class->intin_urb, hid_class->hport, hid_class->intin, hid_buffer, hid_class->intin->wMaxPacketSize, 0, usbh_hid_callback, hid_class);
|
|
ret = usbh_submit_urb(&hid_class->intin_urb);
|
|
if (ret < 0) {
|
|
goto delete;
|
|
}
|
|
// clang-format off
|
|
delete:
|
|
usb_osal_thread_delete(NULL);
|
|
// clang-format on
|
|
}
|
|
|
|
void usbh_hid_run(struct usbh_hid *hid_class)
|
|
{
|
|
usb_osal_thread_create("usbh_hid", 2048, CONFIG_USBHOST_PSC_PRIO + 1, usbh_hid_thread, hid_class);
|
|
}
|
|
|
|
void usbh_hid_stop(struct usbh_hid *hid_class)
|
|
{
|
|
}
|
|
|