Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix usb hid #20

Merged
merged 1 commit into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
#define HID_DEBUG(fmt, ...)
#endif

#define HID_DESCRIPTOR_LEN 25
#define HID_DESCRIPTOR_LEN 32
#define HID_KEYBOARD_REPORT_DESC_SIZE 63

#define HID_INT_EP 0x81
#define HID_INT_EP_SIZE 8
#define HID_INT_EP_INTERVAL 10

#define HID_OUT_EP 0x01
#define HID_OUT_EP_SIZE 1
#define HID_OUT_EP_INTERVAL 10

void smk_hid_usb_init();

void smk_usb_hid_daemon_task(void *pvParameters);
Expand Down
12 changes: 10 additions & 2 deletions firmware/bl_mcu_sdk/examples/keyboard/sipeed_keyboard_68/smk_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,27 @@ void usbd_hid_int_callback(uint8_t ep)
{
usbd_ep_write(HID_INT_EP, hid_usb.buf[hid_usb.flag], 8, NULL);
}

void usbd_hid_out_callback(uint8_t ep)
{
// usbd_ep_write(HID_INT_EP, hid_usb.buf[hid_usb.flag], 8, NULL);
}
static usbd_endpoint_t hid_in_ep = {
.ep_cb = usbd_hid_int_callback,
.ep_addr = 0x81
};
static usbd_endpoint_t hid_out_ep = {
.ep_cb = usbd_hid_out_callback,
.ep_addr = 0x01
};

extern struct device *usb_dc_init(void);

void smk_hid_usb_init()
{
usbd_hid_add_interface(&hid_class, &hid_intf);
usbd_interface_add_endpoint(&hid_intf, &hid_in_ep);
usbd_hid_report_descriptor_register(0, hid_keyboard_report_desc, HID_KEYBOARD_REPORT_DESC_SIZE);
usbd_interface_add_endpoint(&hid_intf, &hid_out_ep);
usbd_hid_report_descriptor_register(hid_intf.intf_num, hid_keyboard_report_desc, HID_KEYBOARD_REPORT_DESC_SIZE);
}

void smk_usb_hid_daemon_task(void *pvParameters)
Expand Down
30 changes: 13 additions & 17 deletions firmware/bl_mcu_sdk/examples/keyboard/sipeed_keyboard_68/smk_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,22 @@
#define USBD_LANGID_STRING 1033

// #define USB_CONFIG_HID_KEYBOARD_SIZE (9 + HID_DESCRIPTOR_LEN)
#define USB_CONFIG_SIZE (9 + CDC_ACM_DESCRIPTOR_LEN + 8 + HID_DESCRIPTOR_LEN)
#define USB_CONFIG_SIZE (9 + CDC_ACM_DESCRIPTOR_LEN + HID_DESCRIPTOR_LEN)

USB_DESC_SECTION const uint8_t sipeed_keyboard_descriptor[] = { // single hid keyboard device desc
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x02, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0xef, 0x02, 0x01, USBD_VID, USBD_PID, 0x0100, 0x01),
// USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0200, 0x01),
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x03, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
// USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_HID_KEYBOARD_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
CDC_ACM_DESCRIPTOR_INIT(0x00, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP, 0x02),
///////////////////////////////////////
/// interface association descriptor
///////////////////////////////////////
0x08, /* bLength */
USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */
0x02, /* bFirstInterface */
0x01, /* bInterfaceCount */
0x03, /* bFunctionClass */
0x01, /* bFunctionSubClass */
0x01, /* bFunctionProtocol */
0x00, /* iFunction */

// MSC_DESCRIPTOR_INIT(0x00, MSC_OUT_EP, MSC_IN_EP, 0x02),
/************** Descriptor of Joystick Mouse interface ****************/
/* 09 */
0x09, /* bLength: Interface Descriptor size */
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
0x02, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x01, /* bNumEndpoints */
0x02, /* bNumEndpoints */
0x03, /* bInterfaceClass: HID */
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
0x01, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
Expand All @@ -55,6 +43,14 @@ USB_DESC_SECTION const uint8_t sipeed_keyboard_descriptor[] = { // single hid ke
0x00,
/******************** Descriptor of Mouse endpoint ********************/
/* 27 */
0x07, /* bLength: Endpoint Descriptor size */
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
HID_OUT_EP, /* bEndpointAddress: Endpoint Address (IN) */
0x03, /* bmAttributes: Interrupt endpoint */
HID_OUT_EP_SIZE, /* wMaxPacketSize: 4 Byte max */
0x00,
HID_OUT_EP_INTERVAL, /* bInterval: Polling Interval */

0x07, /* bLength: Endpoint Descriptor size */
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */
HID_INT_EP, /* bEndpointAddress: Endpoint Address (IN) */
Expand Down Expand Up @@ -138,13 +134,13 @@ extern struct device *usb_dc_init(void);

void usb_init(){ //task init
usbd_desc_register(sipeed_keyboard_descriptor);
smk_hid_usb_init();
smk_cdc_init();
smk_hid_usb_init();

usb_fs = usb_dc_init();

if (usb_fs) {
device_control(usb_fs, DEVICE_CTRL_SET_INT, (void *)(USB_EP1_DATA_IN_IT | USB_EP3_DATA_OUT_IT | USB_EP5_DATA_IN_IT));
device_control(usb_fs, DEVICE_CTRL_SET_INT, (void *)(USB_EP1_DATA_IN_IT |USB_EP1_DATA_OUT_IT | USB_EP3_DATA_OUT_IT | USB_EP5_DATA_IN_IT));
}

while (!usb_device_is_configured()) {
Expand Down