mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-22 19:20:52 +00:00
correct hid host mount/unmount callback
rename HOST_CLASS_HID to CFG_TUH_HID
This commit is contained in:
parent
be165a6713
commit
a5cd81a226
@ -154,7 +154,7 @@ static inline void process_kbd_report(hid_keyboard_report_t const *p_new_report)
|
|||||||
prev_report = *p_new_report;
|
prev_report = *p_new_report;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tuh_hid_mounted_cb(uint8_t dev_addr)
|
void tuh_hid_mounted_cb(uint8_t dev_addr, uint8_t instance)
|
||||||
{
|
{
|
||||||
// application set-up
|
// application set-up
|
||||||
printf("A Keyboard device (address %d) is mounted\r\n", dev_addr);
|
printf("A Keyboard device (address %d) is mounted\r\n", dev_addr);
|
||||||
@ -162,7 +162,7 @@ void tuh_hid_mounted_cb(uint8_t dev_addr)
|
|||||||
tuh_hid_keyboard_get_report(dev_addr, &usb_keyboard_report);
|
tuh_hid_keyboard_get_report(dev_addr, &usb_keyboard_report);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tuh_hid_unmounted_cb(uint8_t dev_addr)
|
void tuh_hid_unmounted_cb(uint8_t dev_addr, uint8_t instance)
|
||||||
{
|
{
|
||||||
// application tear-down
|
// application tear-down
|
||||||
printf("A Keyboard device (address %d) is unmounted\r\n", dev_addr);
|
printf("A Keyboard device (address %d) is unmounted\r\n", dev_addr);
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include "tusb_option.h"
|
#include "tusb_option.h"
|
||||||
|
|
||||||
#if (TUSB_OPT_HOST_ENABLED && HOST_CLASS_HID)
|
#if (TUSB_OPT_HOST_ENABLED && CFG_TUH_HID)
|
||||||
|
|
||||||
#include "common/tusb_common.h"
|
#include "common/tusb_common.h"
|
||||||
#include "hid_host.h"
|
#include "hid_host.h"
|
||||||
@ -76,8 +76,8 @@ typedef struct
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t itf_count;
|
uint8_t inst_count;
|
||||||
hidh_interface_t interface[CFG_TUH_HID];
|
hidh_interface_t instances[CFG_TUH_HID];
|
||||||
} hidh_device_t;
|
} hidh_device_t;
|
||||||
|
|
||||||
static hidh_device_t _hidh_dev[CFG_TUSB_HOST_DEVICE_MAX-1];
|
static hidh_device_t _hidh_dev[CFG_TUSB_HOST_DEVICE_MAX-1];
|
||||||
@ -93,15 +93,28 @@ TU_ATTR_ALWAYS_INLINE static inline hidh_device_t* get_dev(uint8_t dev_addr)
|
|||||||
// Get Interface by instance number
|
// Get Interface by instance number
|
||||||
TU_ATTR_ALWAYS_INLINE static inline hidh_interface_t* get_instance(uint8_t dev_addr, uint8_t instance)
|
TU_ATTR_ALWAYS_INLINE static inline hidh_interface_t* get_instance(uint8_t dev_addr, uint8_t instance)
|
||||||
{
|
{
|
||||||
return &_hidh_dev[dev_addr-1].interface[instance];
|
return &_hidh_dev[dev_addr-1].instances[instance];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get instance ID by interface number
|
||||||
|
static uint8_t get_instance_id(uint8_t dev_addr, uint8_t itf)
|
||||||
|
{
|
||||||
|
for ( uint8_t inst = 0; inst < CFG_TUH_HID; inst++ )
|
||||||
|
{
|
||||||
|
hidh_interface_t *hid = get_instance(dev_addr, inst);
|
||||||
|
|
||||||
|
if ( (hid->itf_num == itf) && (hid->ep_in != 0) ) return inst;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Interface by interface number
|
// Get Interface by interface number
|
||||||
static hidh_interface_t* get_interface(uint8_t dev_addr, uint8_t itf)
|
static hidh_interface_t* get_interface(uint8_t dev_addr, uint8_t itf)
|
||||||
{
|
{
|
||||||
for(uint8_t inst=0; inst<CFG_TUH_HID; inst++)
|
for ( uint8_t inst = 0; inst < CFG_TUH_HID; inst++ )
|
||||||
{
|
{
|
||||||
hidh_interface_t* hid = get_instance(dev_addr, inst);
|
hidh_interface_t *hid = get_instance(dev_addr, inst);
|
||||||
|
|
||||||
if ( (hid->itf_num == itf) && (hid->ep_in != 0) ) return hid;
|
if ( (hid->itf_num == itf) && (hid->ep_in != 0) ) return hid;
|
||||||
}
|
}
|
||||||
@ -114,18 +127,13 @@ static hidh_interface_t* get_interface(uint8_t dev_addr, uint8_t itf)
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
uint8_t tuh_n_hid_instance_count(uint8_t daddr)
|
uint8_t tuh_n_hid_instance_count(uint8_t daddr)
|
||||||
{
|
{
|
||||||
return get_dev(daddr)->itf_count;
|
return get_dev(daddr)->inst_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// HID Interface common functions
|
// HID Interface common functions
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
static inline void hidh_interface_close(hidh_interface_t *p_hid)
|
|
||||||
{
|
|
||||||
tu_memclr(p_hid, sizeof(hidh_interface_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
// called from public API need to validate parameters
|
// called from public API need to validate parameters
|
||||||
tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_interface_t *p_hid)
|
tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_interface_t *p_hid)
|
||||||
{
|
{
|
||||||
@ -234,19 +242,13 @@ bool hidh_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32
|
|||||||
|
|
||||||
void hidh_close(uint8_t dev_addr)
|
void hidh_close(uint8_t dev_addr)
|
||||||
{
|
{
|
||||||
uint8_t itf = 0;
|
hidh_device_t* hid_dev = get_dev(dev_addr);
|
||||||
hidh_interface_t* hid_itf = get_instance(dev_addr, itf);
|
if (tuh_hid_unmounted_cb)
|
||||||
|
|
||||||
if (tuh_hid_unmounted_cb) tuh_hid_unmounted_cb(dev_addr);
|
|
||||||
hidh_interface_close(hid_itf);
|
|
||||||
|
|
||||||
#if CFG_TUH_HID_MOUSE
|
|
||||||
if( mouseh_data[dev_addr-1].ep_in != 0 )
|
|
||||||
{
|
{
|
||||||
hidh_interface_close(&mouseh_data[dev_addr-1]);
|
for ( uint8_t inst = 0; inst < hid_dev->inst_count; inst++) tuh_hid_unmounted_cb(dev_addr, inst);
|
||||||
tuh_hid_mouse_unmounted_cb( dev_addr );
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
tu_memclr(hid_dev, sizeof(hidh_device_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@ -270,7 +272,7 @@ bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *de
|
|||||||
// not enough interface, try to increase CFG_TUH_HID
|
// not enough interface, try to increase CFG_TUH_HID
|
||||||
// TODO multiple devices
|
// TODO multiple devices
|
||||||
hidh_device_t* hid_dev = get_dev(dev_addr);
|
hidh_device_t* hid_dev = get_dev(dev_addr);
|
||||||
TU_ASSERT(hid_dev->itf_count < CFG_TUH_HID);
|
TU_ASSERT(hid_dev->inst_count < CFG_TUH_HID);
|
||||||
|
|
||||||
//------------- Endpoint Descriptor -------------//
|
//------------- Endpoint Descriptor -------------//
|
||||||
p_desc = tu_desc_next(p_desc);
|
p_desc = tu_desc_next(p_desc);
|
||||||
@ -280,8 +282,8 @@ bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *de
|
|||||||
// TODO also open endpoint OUT
|
// TODO also open endpoint OUT
|
||||||
TU_ASSERT( usbh_edpt_open(rhport, dev_addr, desc_ep) );
|
TU_ASSERT( usbh_edpt_open(rhport, dev_addr, desc_ep) );
|
||||||
|
|
||||||
hidh_interface_t* hid_itf = get_instance(dev_addr, hid_dev->itf_count);
|
hidh_interface_t* hid_itf = get_instance(dev_addr, hid_dev->inst_count);
|
||||||
hid_dev->itf_count++;
|
hid_dev->inst_count++;
|
||||||
|
|
||||||
hid_itf->itf_num = desc_itf->bInterfaceNumber;
|
hid_itf->itf_num = desc_itf->bInterfaceNumber;
|
||||||
hid_itf->ep_in = desc_ep->bEndpointAddress;
|
hid_itf->ep_in = desc_ep->bEndpointAddress;
|
||||||
@ -393,14 +395,18 @@ bool config_get_report_desc_complete(uint8_t dev_addr, tusb_control_request_t co
|
|||||||
{
|
{
|
||||||
TU_ASSERT(XFER_RESULT_SUCCESS == result);
|
TU_ASSERT(XFER_RESULT_SUCCESS == result);
|
||||||
uint8_t const itf_num = (uint8_t) request->wIndex;
|
uint8_t const itf_num = (uint8_t) request->wIndex;
|
||||||
hidh_interface_t* hid_itf = get_interface(dev_addr, itf_num);
|
uint8_t const inst = get_instance_id(dev_addr, itf_num);
|
||||||
|
//hidh_interface_t* hid_itf = get_instance(dev_addr, inst);
|
||||||
|
|
||||||
if (tuh_hid_descriptor_report_cb) tuh_hid_descriptor_report_cb(dev_addr, hid_itf->itf_num, usbh_get_enum_buf(), request->wLength);
|
if (tuh_hid_descriptor_report_cb)
|
||||||
|
{
|
||||||
|
tuh_hid_descriptor_report_cb(dev_addr, inst, usbh_get_enum_buf(), request->wLength);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO Report descriptor parser
|
// TODO Report descriptor parser
|
||||||
|
|
||||||
// enumeration is complete
|
// enumeration is complete
|
||||||
if (tuh_hid_mounted_cb) tuh_hid_mounted_cb(dev_addr);
|
if (tuh_hid_mounted_cb) tuh_hid_mounted_cb(dev_addr, inst);
|
||||||
|
|
||||||
// notify usbh that driver enumeration is complete
|
// notify usbh that driver enumeration is complete
|
||||||
usbh_driver_set_config_complete(dev_addr, itf_num);
|
usbh_driver_set_config_complete(dev_addr, itf_num);
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
// Get the number of HID instances
|
// Get the number of HID instances
|
||||||
uint8_t tuh_n_hid_instance_count(uint8_t daddr);
|
uint8_t tuh_n_hid_instance_count(uint8_t daddr);
|
||||||
|
|
||||||
// Check if HID instance support keyboard
|
// Check if HID instance has keyboard
|
||||||
bool tuh_n_hid_n_keyboard_mounted(uint8_t daddr, uint8_t instance);
|
bool tuh_n_hid_n_keyboard_mounted(uint8_t daddr, uint8_t instance);
|
||||||
|
|
||||||
|
|
||||||
@ -86,8 +86,8 @@ uint8_t tuh_hid_instance_count(void)
|
|||||||
// Note: enumeration is still not complete yet
|
// Note: enumeration is still not complete yet
|
||||||
TU_ATTR_WEAK void tuh_hid_descriptor_report_cb(uint8_t daddr, uint8_t instance, uint8_t const* report_desc, uint16_t desc_len);
|
TU_ATTR_WEAK void tuh_hid_descriptor_report_cb(uint8_t daddr, uint8_t instance, uint8_t const* report_desc, uint16_t desc_len);
|
||||||
|
|
||||||
TU_ATTR_WEAK void tuh_hid_mounted_cb(uint8_t dev_addr);
|
TU_ATTR_WEAK void tuh_hid_mounted_cb (uint8_t dev_addr, uint8_t instance);
|
||||||
TU_ATTR_WEAK void tuh_hid_unmounted_cb(uint8_t dev_addr);
|
TU_ATTR_WEAK void tuh_hid_unmounted_cb(uint8_t dev_addr, uint8_t instance);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ static usbh_class_driver_t const usbh_class_drivers[] =
|
|||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HOST_CLASS_HID
|
#if CFG_TUH_HID
|
||||||
{
|
{
|
||||||
DRIVER_NAME("HID")
|
DRIVER_NAME("HID")
|
||||||
.class_code = TUSB_CLASS_HID,
|
.class_code = TUSB_CLASS_HID,
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
#if TUSB_OPT_HOST_ENABLED
|
#if TUSB_OPT_HOST_ENABLED
|
||||||
#include "host/usbh.h"
|
#include "host/usbh.h"
|
||||||
|
|
||||||
#if HOST_CLASS_HID
|
#if CFG_TUH_HID
|
||||||
#include "class/hid/hid_host.h"
|
#include "class/hid/hid_host.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -266,9 +266,6 @@
|
|||||||
#error there is no benefit enable hub with max device is 1. Please disable hub or increase CFG_TUSB_HOST_DEVICE_MAX
|
#error there is no benefit enable hub with max device is 1. Please disable hub or increase CFG_TUSB_HOST_DEVICE_MAX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//------------- HID CLASS -------------//
|
|
||||||
#define HOST_CLASS_HID ( CFG_TUH_HID_KEYBOARD + CFG_TUH_HID_MOUSE + CFG_TUSB_HOST_HID_GENERIC )
|
|
||||||
|
|
||||||
#ifndef CFG_TUH_ENUMERATION_BUFSZIE
|
#ifndef CFG_TUH_ENUMERATION_BUFSZIE
|
||||||
#define CFG_TUH_ENUMERATION_BUFSZIE 256
|
#define CFG_TUH_ENUMERATION_BUFSZIE 256
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user