format codes
This commit is contained in:
@@ -1,286 +1,286 @@
|
||||
/**
|
||||
* @file usbd_hid.c
|
||||
* @brief
|
||||
*
|
||||
* Copyright (c) 2022 sakumisu
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_hid.h"
|
||||
|
||||
#define HID_STATE_IDLE 0
|
||||
#define HID_STATE_BUSY 1
|
||||
|
||||
struct usbd_hid_cfg_private {
|
||||
const uint8_t *hid_descriptor;
|
||||
const uint8_t *hid_report_descriptor;
|
||||
uint32_t hid_report_descriptor_len;
|
||||
uint8_t current_intf_num;
|
||||
uint8_t hid_state;
|
||||
uint8_t report;
|
||||
uint8_t idle_state;
|
||||
uint8_t protocol;
|
||||
|
||||
uint8_t (*get_report_callback)(uint8_t report_id, uint8_t report_type);
|
||||
void (*set_report_callback)(uint8_t report_id, uint8_t report_type, uint8_t *report, uint8_t report_len);
|
||||
uint8_t (*get_idle_callback)(uint8_t report_id);
|
||||
void (*set_idle_callback)(uint8_t report_id, uint8_t duration);
|
||||
void (*set_protocol_callback)(uint8_t protocol);
|
||||
uint8_t (*get_protocol_callback)(void);
|
||||
|
||||
usb_slist_t list;
|
||||
} usbd_hid_cfg[4];
|
||||
|
||||
static usb_slist_t usbd_hid_class_head = USB_SLIST_OBJECT_INIT(usbd_hid_class_head);
|
||||
|
||||
static void usbd_hid_reset(void)
|
||||
{
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
hid_intf->hid_state = HID_STATE_IDLE;
|
||||
hid_intf->report = 0;
|
||||
hid_intf->idle_state = 0;
|
||||
hid_intf->protocol = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int hid_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("HID Custom request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
setup->bRequest);
|
||||
|
||||
if (((setup->bmRequestType & USB_REQUEST_DIR_MASK) == USB_REQUEST_DIR_IN) &&
|
||||
setup->bRequest == USB_REQUEST_GET_DESCRIPTOR) {
|
||||
uint8_t value = (uint8_t)(setup->wValue >> 8);
|
||||
uint8_t intf_num = (uint8_t)setup->wIndex;
|
||||
|
||||
struct usbd_hid_cfg_private *current_hid_intf = NULL;
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
current_hid_intf = hid_intf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (current_hid_intf == NULL) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
switch (value) {
|
||||
case HID_DESCRIPTOR_TYPE_HID:
|
||||
USB_LOG_INFO("get HID Descriptor\r\n");
|
||||
*data = (uint8_t *)current_hid_intf->hid_descriptor;
|
||||
*len = current_hid_intf->hid_descriptor[0];
|
||||
break;
|
||||
|
||||
case HID_DESCRIPTOR_TYPE_HID_REPORT:
|
||||
USB_LOG_INFO("get Report Descriptor\r\n");
|
||||
*data = (uint8_t *)current_hid_intf->hid_report_descriptor;
|
||||
*len = current_hid_intf->hid_report_descriptor_len;
|
||||
break;
|
||||
|
||||
case HID_DESCRIPTOR_TYPE_HID_PHYSICAL:
|
||||
USB_LOG_INFO("get PHYSICAL Descriptor\r\n");
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int hid_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("HID Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
setup->bRequest);
|
||||
|
||||
struct usbd_hid_cfg_private *current_hid_intf = NULL;
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
uint8_t intf_num = (uint8_t)setup->wIndex;
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
current_hid_intf = hid_intf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (current_hid_intf == NULL) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
switch (setup->bRequest) {
|
||||
case HID_REQUEST_GET_REPORT:
|
||||
if (current_hid_intf->get_report_callback)
|
||||
current_hid_intf->report = current_hid_intf->get_report_callback(LO_BYTE(setup->wValue), HI_BYTE(setup->wValue)); /*report id ,report type*/
|
||||
|
||||
*data = (uint8_t *)¤t_hid_intf->report;
|
||||
*len = 1;
|
||||
break;
|
||||
case HID_REQUEST_GET_IDLE:
|
||||
if (current_hid_intf->get_idle_callback)
|
||||
current_hid_intf->idle_state = current_hid_intf->get_idle_callback(LO_BYTE(setup->wValue));
|
||||
|
||||
*data = (uint8_t *)¤t_hid_intf->idle_state;
|
||||
*len = 1;
|
||||
break;
|
||||
case HID_REQUEST_GET_PROTOCOL:
|
||||
if (current_hid_intf->get_protocol_callback)
|
||||
current_hid_intf->protocol = current_hid_intf->get_protocol_callback();
|
||||
|
||||
*data = (uint8_t *)¤t_hid_intf->protocol;
|
||||
*len = 1;
|
||||
break;
|
||||
case HID_REQUEST_SET_REPORT:
|
||||
if (current_hid_intf->set_report_callback)
|
||||
current_hid_intf->set_report_callback(LO_BYTE(setup->wValue), HI_BYTE(setup->wValue), *data, *len); /*report id ,report type,report,report len*/
|
||||
|
||||
current_hid_intf->report = **data;
|
||||
break;
|
||||
case HID_REQUEST_SET_IDLE:
|
||||
if (current_hid_intf->set_idle_callback)
|
||||
current_hid_intf->set_idle_callback(LO_BYTE(setup->wValue), HI_BYTE(setup->wIndex)); /*report id ,duration*/
|
||||
|
||||
current_hid_intf->idle_state = HI_BYTE(setup->wIndex);
|
||||
break;
|
||||
case HID_REQUEST_SET_PROTOCOL:
|
||||
if (current_hid_intf->set_protocol_callback)
|
||||
current_hid_intf->set_protocol_callback(LO_BYTE(setup->wValue)); /*protocol*/
|
||||
|
||||
current_hid_intf->protocol = LO_BYTE(setup->wValue);
|
||||
break;
|
||||
|
||||
default:
|
||||
USB_LOG_WRN("Unhandled HID Class bRequest 0x%02x\r\n", setup->bRequest);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void hid_notify_handler(uint8_t event, void *arg)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
usbd_hid_reset();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_hid_reset_state(void)
|
||||
{
|
||||
// usbd_hid_cfg.hid_state = HID_STATE_IDLE;
|
||||
}
|
||||
|
||||
void usbd_hid_send_report(uint8_t ep, uint8_t *data, uint8_t len)
|
||||
{
|
||||
// if(usbd_hid_cfg.hid_state == HID_STATE_IDLE)
|
||||
// {
|
||||
// usbd_hid_cfg.hid_state = HID_STATE_BUSY;
|
||||
// usbd_ep_write(ep, data, len, NULL);
|
||||
// }
|
||||
}
|
||||
|
||||
void usbd_hid_descriptor_register(uint8_t intf_num, const uint8_t *desc)
|
||||
{
|
||||
// usbd_hid_cfg.hid_descriptor = desc;
|
||||
}
|
||||
|
||||
void usbd_hid_report_descriptor_register(uint8_t intf_num, const uint8_t *desc, uint32_t desc_len)
|
||||
{
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
hid_intf->hid_report_descriptor = desc;
|
||||
hid_intf->hid_report_descriptor_len = desc_len;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// clang-format off
|
||||
void usbd_hid_set_request_callback( uint8_t intf_num,
|
||||
uint8_t (*get_report_callback)(uint8_t report_id, uint8_t report_type),
|
||||
void (*set_report_callback)(uint8_t report_id, uint8_t report_type, uint8_t *report, uint8_t report_len),
|
||||
uint8_t (*get_idle_callback)(uint8_t report_id),
|
||||
void (*set_idle_callback)(uint8_t report_id, uint8_t duration),
|
||||
void (*set_protocol_callback)(uint8_t protocol),
|
||||
uint8_t (*get_protocol_callback)(void))
|
||||
// clang-format on
|
||||
{
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
if (get_report_callback)
|
||||
hid_intf->get_report_callback = get_report_callback;
|
||||
if (set_report_callback)
|
||||
hid_intf->set_report_callback = set_report_callback;
|
||||
if (get_idle_callback)
|
||||
hid_intf->get_idle_callback = get_idle_callback;
|
||||
if (set_idle_callback)
|
||||
hid_intf->set_idle_callback = set_idle_callback;
|
||||
if (set_protocol_callback)
|
||||
hid_intf->set_protocol_callback = set_protocol_callback;
|
||||
if (get_protocol_callback)
|
||||
hid_intf->get_protocol_callback = get_protocol_callback;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_hid_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
{
|
||||
static usbd_class_t *last_class = NULL;
|
||||
static uint8_t hid_num = 0;
|
||||
if (last_class != devclass) {
|
||||
last_class = devclass;
|
||||
usbd_class_register(devclass);
|
||||
}
|
||||
|
||||
intf->class_handler = hid_class_request_handler;
|
||||
intf->custom_handler = hid_custom_request_handler;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = hid_notify_handler;
|
||||
usbd_class_add_interface(devclass, intf);
|
||||
|
||||
usbd_hid_cfg[hid_num].current_intf_num = intf->intf_num;
|
||||
usb_slist_add_tail(&usbd_hid_class_head, &usbd_hid_cfg[hid_num].list);
|
||||
hid_num++;
|
||||
}
|
||||
/**
|
||||
* @file usbd_hid.c
|
||||
* @brief
|
||||
*
|
||||
* Copyright (c) 2022 sakumisu
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_hid.h"
|
||||
|
||||
#define HID_STATE_IDLE 0
|
||||
#define HID_STATE_BUSY 1
|
||||
|
||||
struct usbd_hid_cfg_private {
|
||||
const uint8_t *hid_descriptor;
|
||||
const uint8_t *hid_report_descriptor;
|
||||
uint32_t hid_report_descriptor_len;
|
||||
uint8_t current_intf_num;
|
||||
uint8_t hid_state;
|
||||
uint8_t report;
|
||||
uint8_t idle_state;
|
||||
uint8_t protocol;
|
||||
|
||||
uint8_t (*get_report_callback)(uint8_t report_id, uint8_t report_type);
|
||||
void (*set_report_callback)(uint8_t report_id, uint8_t report_type, uint8_t *report, uint8_t report_len);
|
||||
uint8_t (*get_idle_callback)(uint8_t report_id);
|
||||
void (*set_idle_callback)(uint8_t report_id, uint8_t duration);
|
||||
void (*set_protocol_callback)(uint8_t protocol);
|
||||
uint8_t (*get_protocol_callback)(void);
|
||||
|
||||
usb_slist_t list;
|
||||
} usbd_hid_cfg[4];
|
||||
|
||||
static usb_slist_t usbd_hid_class_head = USB_SLIST_OBJECT_INIT(usbd_hid_class_head);
|
||||
|
||||
static void usbd_hid_reset(void)
|
||||
{
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
hid_intf->hid_state = HID_STATE_IDLE;
|
||||
hid_intf->report = 0;
|
||||
hid_intf->idle_state = 0;
|
||||
hid_intf->protocol = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int hid_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("HID Custom request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
setup->bRequest);
|
||||
|
||||
if (((setup->bmRequestType & USB_REQUEST_DIR_MASK) == USB_REQUEST_DIR_IN) &&
|
||||
setup->bRequest == USB_REQUEST_GET_DESCRIPTOR) {
|
||||
uint8_t value = (uint8_t)(setup->wValue >> 8);
|
||||
uint8_t intf_num = (uint8_t)setup->wIndex;
|
||||
|
||||
struct usbd_hid_cfg_private *current_hid_intf = NULL;
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
current_hid_intf = hid_intf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (current_hid_intf == NULL) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
switch (value) {
|
||||
case HID_DESCRIPTOR_TYPE_HID:
|
||||
USB_LOG_INFO("get HID Descriptor\r\n");
|
||||
*data = (uint8_t *)current_hid_intf->hid_descriptor;
|
||||
*len = current_hid_intf->hid_descriptor[0];
|
||||
break;
|
||||
|
||||
case HID_DESCRIPTOR_TYPE_HID_REPORT:
|
||||
USB_LOG_INFO("get Report Descriptor\r\n");
|
||||
*data = (uint8_t *)current_hid_intf->hid_report_descriptor;
|
||||
*len = current_hid_intf->hid_report_descriptor_len;
|
||||
break;
|
||||
|
||||
case HID_DESCRIPTOR_TYPE_HID_PHYSICAL:
|
||||
USB_LOG_INFO("get PHYSICAL Descriptor\r\n");
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int hid_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("HID Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
setup->bRequest);
|
||||
|
||||
struct usbd_hid_cfg_private *current_hid_intf = NULL;
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
uint8_t intf_num = (uint8_t)setup->wIndex;
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
current_hid_intf = hid_intf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (current_hid_intf == NULL) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
switch (setup->bRequest) {
|
||||
case HID_REQUEST_GET_REPORT:
|
||||
if (current_hid_intf->get_report_callback)
|
||||
current_hid_intf->report = current_hid_intf->get_report_callback(LO_BYTE(setup->wValue), HI_BYTE(setup->wValue)); /*report id ,report type*/
|
||||
|
||||
*data = (uint8_t *)¤t_hid_intf->report;
|
||||
*len = 1;
|
||||
break;
|
||||
case HID_REQUEST_GET_IDLE:
|
||||
if (current_hid_intf->get_idle_callback)
|
||||
current_hid_intf->idle_state = current_hid_intf->get_idle_callback(LO_BYTE(setup->wValue));
|
||||
|
||||
*data = (uint8_t *)¤t_hid_intf->idle_state;
|
||||
*len = 1;
|
||||
break;
|
||||
case HID_REQUEST_GET_PROTOCOL:
|
||||
if (current_hid_intf->get_protocol_callback)
|
||||
current_hid_intf->protocol = current_hid_intf->get_protocol_callback();
|
||||
|
||||
*data = (uint8_t *)¤t_hid_intf->protocol;
|
||||
*len = 1;
|
||||
break;
|
||||
case HID_REQUEST_SET_REPORT:
|
||||
if (current_hid_intf->set_report_callback)
|
||||
current_hid_intf->set_report_callback(LO_BYTE(setup->wValue), HI_BYTE(setup->wValue), *data, *len); /*report id ,report type,report,report len*/
|
||||
|
||||
current_hid_intf->report = **data;
|
||||
break;
|
||||
case HID_REQUEST_SET_IDLE:
|
||||
if (current_hid_intf->set_idle_callback)
|
||||
current_hid_intf->set_idle_callback(LO_BYTE(setup->wValue), HI_BYTE(setup->wIndex)); /*report id ,duration*/
|
||||
|
||||
current_hid_intf->idle_state = HI_BYTE(setup->wIndex);
|
||||
break;
|
||||
case HID_REQUEST_SET_PROTOCOL:
|
||||
if (current_hid_intf->set_protocol_callback)
|
||||
current_hid_intf->set_protocol_callback(LO_BYTE(setup->wValue)); /*protocol*/
|
||||
|
||||
current_hid_intf->protocol = LO_BYTE(setup->wValue);
|
||||
break;
|
||||
|
||||
default:
|
||||
USB_LOG_WRN("Unhandled HID Class bRequest 0x%02x\r\n", setup->bRequest);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void hid_notify_handler(uint8_t event, void *arg)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
usbd_hid_reset();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_hid_reset_state(void)
|
||||
{
|
||||
// usbd_hid_cfg.hid_state = HID_STATE_IDLE;
|
||||
}
|
||||
|
||||
void usbd_hid_send_report(uint8_t ep, uint8_t *data, uint8_t len)
|
||||
{
|
||||
// if(usbd_hid_cfg.hid_state == HID_STATE_IDLE)
|
||||
// {
|
||||
// usbd_hid_cfg.hid_state = HID_STATE_BUSY;
|
||||
// usbd_ep_write(ep, data, len, NULL);
|
||||
// }
|
||||
}
|
||||
|
||||
void usbd_hid_descriptor_register(uint8_t intf_num, const uint8_t *desc)
|
||||
{
|
||||
// usbd_hid_cfg.hid_descriptor = desc;
|
||||
}
|
||||
|
||||
void usbd_hid_report_descriptor_register(uint8_t intf_num, const uint8_t *desc, uint32_t desc_len)
|
||||
{
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
hid_intf->hid_report_descriptor = desc;
|
||||
hid_intf->hid_report_descriptor_len = desc_len;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// clang-format off
|
||||
void usbd_hid_set_request_callback( uint8_t intf_num,
|
||||
uint8_t (*get_report_callback)(uint8_t report_id, uint8_t report_type),
|
||||
void (*set_report_callback)(uint8_t report_id, uint8_t report_type, uint8_t *report, uint8_t report_len),
|
||||
uint8_t (*get_idle_callback)(uint8_t report_id),
|
||||
void (*set_idle_callback)(uint8_t report_id, uint8_t duration),
|
||||
void (*set_protocol_callback)(uint8_t protocol),
|
||||
uint8_t (*get_protocol_callback)(void))
|
||||
// clang-format on
|
||||
{
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
if (get_report_callback)
|
||||
hid_intf->get_report_callback = get_report_callback;
|
||||
if (set_report_callback)
|
||||
hid_intf->set_report_callback = set_report_callback;
|
||||
if (get_idle_callback)
|
||||
hid_intf->get_idle_callback = get_idle_callback;
|
||||
if (set_idle_callback)
|
||||
hid_intf->set_idle_callback = set_idle_callback;
|
||||
if (set_protocol_callback)
|
||||
hid_intf->set_protocol_callback = set_protocol_callback;
|
||||
if (get_protocol_callback)
|
||||
hid_intf->get_protocol_callback = get_protocol_callback;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_hid_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
{
|
||||
static usbd_class_t *last_class = NULL;
|
||||
static uint8_t hid_num = 0;
|
||||
if (last_class != devclass) {
|
||||
last_class = devclass;
|
||||
usbd_class_register(devclass);
|
||||
}
|
||||
|
||||
intf->class_handler = hid_class_request_handler;
|
||||
intf->custom_handler = hid_custom_request_handler;
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = hid_notify_handler;
|
||||
usbd_class_add_interface(devclass, intf);
|
||||
|
||||
usbd_hid_cfg[hid_num].current_intf_num = intf->intf_num;
|
||||
usb_slist_add_tail(&usbd_hid_class_head, &usbd_hid_cfg[hid_num].list);
|
||||
hid_num++;
|
||||
}
|
||||
|
||||
@@ -1,275 +1,275 @@
|
||||
/**
|
||||
* @file usbh_hid.c
|
||||
*
|
||||
* Copyright (c) 2022 sakumisu
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_hid.h"
|
||||
|
||||
#define DEV_FORMAT "/dev/input%d"
|
||||
#define DEV_NAMELEN 16
|
||||
|
||||
static uint32_t g_devinuse = 0;
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbh_hid_devno_alloc
|
||||
*
|
||||
* Description:
|
||||
* Allocate a unique /dev/hid[n] minor number in the range 0-31.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int usbh_hid_devno_alloc(struct usbh_hid *priv)
|
||||
{
|
||||
uint32_t flags;
|
||||
int devno;
|
||||
|
||||
flags = usb_osal_enter_critical_section();
|
||||
for (devno = 0; devno < 32; devno++) {
|
||||
uint32_t bitno = 1 << devno;
|
||||
if ((g_devinuse & bitno) == 0) {
|
||||
g_devinuse |= bitno;
|
||||
priv->minor = devno;
|
||||
usb_osal_leave_critical_section(flags);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
usb_osal_leave_critical_section(flags);
|
||||
return -EMFILE;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbh_hid_devno_free
|
||||
*
|
||||
* Description:
|
||||
* Free a /dev/hid[n] minor number so that it can be used.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void usbh_hid_devno_free(struct usbh_hid *priv)
|
||||
{
|
||||
int devno = priv->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
uint32_t flags = usb_osal_enter_critical_section();
|
||||
g_devinuse &= ~(1 << devno);
|
||||
usb_osal_leave_critical_section(flags);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbh_hid_mkdevname
|
||||
*
|
||||
* Description:
|
||||
* Format a /dev/hid[n] device name given a minor number.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline void usbh_hid_mkdevname(struct usbh_hid *priv, char *devname)
|
||||
{
|
||||
snprintf(devname, DEV_NAMELEN, DEV_FORMAT, priv->minor);
|
||||
}
|
||||
|
||||
int usbh_hid_get_report_descriptor(struct usbh_hubport *hport, uint8_t intf, uint8_t *buffer)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hid_class->setup;
|
||||
|
||||
if (hid_class->intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_STANDARD | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = USB_REQUEST_GET_DESCRIPTOR;
|
||||
setup->wValue = HID_DESCRIPTOR_TYPE_HID_REPORT << 8;
|
||||
setup->wIndex = intf;
|
||||
setup->wLength = 128;
|
||||
|
||||
return usbh_control_transfer(hport->ep0, setup, buffer);
|
||||
}
|
||||
|
||||
int usbh_hid_set_idle(struct usbh_hubport *hport, uint8_t intf, uint8_t report_id, uint8_t duration)
|
||||
{
|
||||
int ret;
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hid_class->setup;
|
||||
|
||||
if (hid_class->intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = HID_REQUEST_SET_IDLE;
|
||||
setup->wValue = report_id;
|
||||
setup->wIndex = (duration << 8) | intf;
|
||||
setup->wLength = 0;
|
||||
|
||||
ret = usbh_control_transfer(hport->ep0, setup, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_hid_get_idle(struct usbh_hubport *hport, uint8_t intf, uint8_t *buffer)
|
||||
{
|
||||
int ret;
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hid_class->setup;
|
||||
|
||||
if (hid_class->intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = HID_REQUEST_GET_IDLE;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = intf;
|
||||
setup->wLength = 1;
|
||||
|
||||
ret = usbh_control_transfer(hport->ep0, setup, buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
USB_NOCACHE_RAM_SECTION uint8_t report_buffer[128];
|
||||
|
||||
void usbh_hid_callback(void *arg, int nbytes)
|
||||
{
|
||||
printf("nbytes:%d\r\n", nbytes);
|
||||
}
|
||||
|
||||
int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usbh_endpoint_cfg ep_cfg = { 0 };
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
char devname[DEV_NAMELEN];
|
||||
int ret;
|
||||
|
||||
struct usbh_hid *hid_class = usb_malloc(sizeof(struct usbh_hid));
|
||||
if (hid_class == NULL) {
|
||||
USB_LOG_ERR("Fail to alloc hid_class\r\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset(hid_class, 0, sizeof(struct usbh_hid));
|
||||
|
||||
usbh_hid_devno_alloc(hid_class);
|
||||
usbh_hid_mkdevname(hid_class, devname);
|
||||
|
||||
hport->config.intf[intf].priv = hid_class;
|
||||
|
||||
hid_class->setup = usb_iomalloc(sizeof(struct usb_setup_packet));
|
||||
if (hid_class->setup == NULL) {
|
||||
USB_LOG_ERR("Fail to alloc setup\r\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
hid_class->intf = intf;
|
||||
|
||||
ret = usbh_hid_set_idle(hport, intf, 0, 0);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = usbh_hid_get_report_descriptor(hport, intf, report_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < hport->config.intf[intf].intf_desc.bNumEndpoints; i++) {
|
||||
ep_desc = &hport->config.intf[intf].ep[i].ep_desc;
|
||||
ep_cfg.ep_addr = ep_desc->bEndpointAddress;
|
||||
ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK;
|
||||
ep_cfg.ep_mps = ep_desc->wMaxPacketSize;
|
||||
ep_cfg.ep_interval = ep_desc->bInterval;
|
||||
ep_cfg.hport = hport;
|
||||
if (ep_desc->bEndpointAddress & 0x80) {
|
||||
usbh_ep_alloc(&hid_class->intin, &ep_cfg);
|
||||
} else {
|
||||
usbh_ep_alloc(&hid_class->intout, &ep_cfg);
|
||||
}
|
||||
}
|
||||
|
||||
USB_LOG_INFO("Register HID Class:%s\r\n", devname);
|
||||
|
||||
ret = usbh_ep_intr_async_transfer(hid_class->intin, report_buffer, 128, usbh_hid_callback, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
#if 0
|
||||
ret = usbh_ep_intr_transfer(hid_class->intin, report_buffer, 128);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
USB_LOG_INFO("recv len:%d\r\n", ret);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_hid_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
char devname[DEV_NAMELEN];
|
||||
int ret = 0;
|
||||
|
||||
struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
|
||||
|
||||
if (hid_class) {
|
||||
usbh_hid_devno_free(hid_class);
|
||||
usbh_hid_mkdevname(hid_class, devname);
|
||||
|
||||
if (hid_class->intin) {
|
||||
ret = usb_ep_cancel(hid_class->intin);
|
||||
if (ret < 0) {
|
||||
}
|
||||
usbh_ep_free(hid_class->intin);
|
||||
}
|
||||
|
||||
if (hid_class->intout) {
|
||||
ret = usb_ep_cancel(hid_class->intout);
|
||||
if (ret < 0) {
|
||||
}
|
||||
usbh_ep_free(hid_class->intout);
|
||||
}
|
||||
if (hid_class->setup)
|
||||
usb_iofree(hid_class->setup);
|
||||
|
||||
usb_free(hid_class);
|
||||
hport->config.intf[intf].priv = NULL;
|
||||
|
||||
USB_LOG_INFO("Unregister HID Class:%s\r\n", devname);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const struct usbh_class_driver hid_class_driver = {
|
||||
.driver_name = "hid",
|
||||
.connect = usbh_hid_connect,
|
||||
.disconnect = usbh_hid_disconnect
|
||||
/**
|
||||
* @file usbh_hid.c
|
||||
*
|
||||
* Copyright (c) 2022 sakumisu
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_hid.h"
|
||||
|
||||
#define DEV_FORMAT "/dev/input%d"
|
||||
#define DEV_NAMELEN 16
|
||||
|
||||
static uint32_t g_devinuse = 0;
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbh_hid_devno_alloc
|
||||
*
|
||||
* Description:
|
||||
* Allocate a unique /dev/hid[n] minor number in the range 0-31.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int usbh_hid_devno_alloc(struct usbh_hid *priv)
|
||||
{
|
||||
uint32_t flags;
|
||||
int devno;
|
||||
|
||||
flags = usb_osal_enter_critical_section();
|
||||
for (devno = 0; devno < 32; devno++) {
|
||||
uint32_t bitno = 1 << devno;
|
||||
if ((g_devinuse & bitno) == 0) {
|
||||
g_devinuse |= bitno;
|
||||
priv->minor = devno;
|
||||
usb_osal_leave_critical_section(flags);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
usb_osal_leave_critical_section(flags);
|
||||
return -EMFILE;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbh_hid_devno_free
|
||||
*
|
||||
* Description:
|
||||
* Free a /dev/hid[n] minor number so that it can be used.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void usbh_hid_devno_free(struct usbh_hid *priv)
|
||||
{
|
||||
int devno = priv->minor;
|
||||
|
||||
if (devno >= 0 && devno < 32) {
|
||||
uint32_t flags = usb_osal_enter_critical_section();
|
||||
g_devinuse &= ~(1 << devno);
|
||||
usb_osal_leave_critical_section(flags);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbh_hid_mkdevname
|
||||
*
|
||||
* Description:
|
||||
* Format a /dev/hid[n] device name given a minor number.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline void usbh_hid_mkdevname(struct usbh_hid *priv, char *devname)
|
||||
{
|
||||
snprintf(devname, DEV_NAMELEN, DEV_FORMAT, priv->minor);
|
||||
}
|
||||
|
||||
int usbh_hid_get_report_descriptor(struct usbh_hubport *hport, uint8_t intf, uint8_t *buffer)
|
||||
{
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hid_class->setup;
|
||||
|
||||
if (hid_class->intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_STANDARD | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = USB_REQUEST_GET_DESCRIPTOR;
|
||||
setup->wValue = HID_DESCRIPTOR_TYPE_HID_REPORT << 8;
|
||||
setup->wIndex = intf;
|
||||
setup->wLength = 128;
|
||||
|
||||
return usbh_control_transfer(hport->ep0, setup, buffer);
|
||||
}
|
||||
|
||||
int usbh_hid_set_idle(struct usbh_hubport *hport, uint8_t intf, uint8_t report_id, uint8_t duration)
|
||||
{
|
||||
int ret;
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hid_class->setup;
|
||||
|
||||
if (hid_class->intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = HID_REQUEST_SET_IDLE;
|
||||
setup->wValue = report_id;
|
||||
setup->wIndex = (duration << 8) | intf;
|
||||
setup->wLength = 0;
|
||||
|
||||
ret = usbh_control_transfer(hport->ep0, setup, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_hid_get_idle(struct usbh_hubport *hport, uint8_t intf, uint8_t *buffer)
|
||||
{
|
||||
int ret;
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
|
||||
|
||||
setup = hid_class->setup;
|
||||
|
||||
if (hid_class->intf != intf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE;
|
||||
setup->bRequest = HID_REQUEST_GET_IDLE;
|
||||
setup->wValue = 0;
|
||||
setup->wIndex = intf;
|
||||
setup->wLength = 1;
|
||||
|
||||
ret = usbh_control_transfer(hport->ep0, setup, buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
USB_NOCACHE_RAM_SECTION uint8_t report_buffer[128];
|
||||
|
||||
void usbh_hid_callback(void *arg, int nbytes)
|
||||
{
|
||||
printf("nbytes:%d\r\n", nbytes);
|
||||
}
|
||||
|
||||
int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
struct usbh_endpoint_cfg ep_cfg = { 0 };
|
||||
struct usb_endpoint_descriptor *ep_desc;
|
||||
char devname[DEV_NAMELEN];
|
||||
int ret;
|
||||
|
||||
struct usbh_hid *hid_class = usb_malloc(sizeof(struct usbh_hid));
|
||||
if (hid_class == NULL) {
|
||||
USB_LOG_ERR("Fail to alloc hid_class\r\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset(hid_class, 0, sizeof(struct usbh_hid));
|
||||
|
||||
usbh_hid_devno_alloc(hid_class);
|
||||
usbh_hid_mkdevname(hid_class, devname);
|
||||
|
||||
hport->config.intf[intf].priv = hid_class;
|
||||
|
||||
hid_class->setup = usb_iomalloc(sizeof(struct usb_setup_packet));
|
||||
if (hid_class->setup == NULL) {
|
||||
USB_LOG_ERR("Fail to alloc setup\r\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
hid_class->intf = intf;
|
||||
|
||||
ret = usbh_hid_set_idle(hport, intf, 0, 0);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = usbh_hid_get_report_descriptor(hport, intf, report_buffer);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < hport->config.intf[intf].intf_desc.bNumEndpoints; i++) {
|
||||
ep_desc = &hport->config.intf[intf].ep[i].ep_desc;
|
||||
ep_cfg.ep_addr = ep_desc->bEndpointAddress;
|
||||
ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK;
|
||||
ep_cfg.ep_mps = ep_desc->wMaxPacketSize;
|
||||
ep_cfg.ep_interval = ep_desc->bInterval;
|
||||
ep_cfg.hport = hport;
|
||||
if (ep_desc->bEndpointAddress & 0x80) {
|
||||
usbh_ep_alloc(&hid_class->intin, &ep_cfg);
|
||||
} else {
|
||||
usbh_ep_alloc(&hid_class->intout, &ep_cfg);
|
||||
}
|
||||
}
|
||||
|
||||
USB_LOG_INFO("Register HID Class:%s\r\n", devname);
|
||||
|
||||
ret = usbh_ep_intr_async_transfer(hid_class->intin, report_buffer, 128, usbh_hid_callback, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
#if 0
|
||||
ret = usbh_ep_intr_transfer(hid_class->intin, report_buffer, 128);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
USB_LOG_INFO("recv len:%d\r\n", ret);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_hid_disconnect(struct usbh_hubport *hport, uint8_t intf)
|
||||
{
|
||||
char devname[DEV_NAMELEN];
|
||||
int ret = 0;
|
||||
|
||||
struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
|
||||
|
||||
if (hid_class) {
|
||||
usbh_hid_devno_free(hid_class);
|
||||
usbh_hid_mkdevname(hid_class, devname);
|
||||
|
||||
if (hid_class->intin) {
|
||||
ret = usb_ep_cancel(hid_class->intin);
|
||||
if (ret < 0) {
|
||||
}
|
||||
usbh_ep_free(hid_class->intin);
|
||||
}
|
||||
|
||||
if (hid_class->intout) {
|
||||
ret = usb_ep_cancel(hid_class->intout);
|
||||
if (ret < 0) {
|
||||
}
|
||||
usbh_ep_free(hid_class->intout);
|
||||
}
|
||||
if (hid_class->setup)
|
||||
usb_iofree(hid_class->setup);
|
||||
|
||||
usb_free(hid_class);
|
||||
hport->config.intf[intf].priv = NULL;
|
||||
|
||||
USB_LOG_INFO("Unregister HID Class:%s\r\n", devname);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const struct usbh_class_driver hid_class_driver = {
|
||||
.driver_name = "hid",
|
||||
.connect = usbh_hid_connect,
|
||||
.disconnect = usbh_hid_disconnect
|
||||
};
|
||||
@@ -1,45 +1,45 @@
|
||||
/**
|
||||
* @file usbh_hid.h
|
||||
*
|
||||
* Copyright (c) 2022 sakumisu
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
#ifndef _USBH_HID_H
|
||||
#define _USBH_HID_H
|
||||
|
||||
#include "usb_hid.h"
|
||||
|
||||
struct usbh_hid {
|
||||
struct usb_setup_packet *setup;
|
||||
uint8_t intf; /* interface number */
|
||||
uint8_t minor;
|
||||
usbh_epinfo_t intin; /* INTR IN endpoint */
|
||||
usbh_epinfo_t intout; /* INTR OUT endpoint */
|
||||
};
|
||||
|
||||
extern const struct usbh_class_driver hid_class_driver;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file usbh_hid.h
|
||||
*
|
||||
* Copyright (c) 2022 sakumisu
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
#ifndef _USBH_HID_H
|
||||
#define _USBH_HID_H
|
||||
|
||||
#include "usb_hid.h"
|
||||
|
||||
struct usbh_hid {
|
||||
struct usb_setup_packet *setup;
|
||||
uint8_t intf; /* interface number */
|
||||
uint8_t minor;
|
||||
usbh_epinfo_t intin; /* INTR IN endpoint */
|
||||
usbh_epinfo_t intout; /* INTR OUT endpoint */
|
||||
};
|
||||
|
||||
extern const struct usbh_class_driver hid_class_driver;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user