mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-29 01:20:19 +00:00
fix variable names. add itf n callbacks to multihid
This commit is contained in:
parent
081af79009
commit
db3fe97f62
@ -167,9 +167,10 @@ void hid_task(void)
|
|||||||
// Invoked when received GET_REPORT control request
|
// Invoked when received GET_REPORT control request
|
||||||
// Application must fill buffer report's content and return its length.
|
// Application must fill buffer report's content and return its length.
|
||||||
// Return zero will cause the stack to STALL request
|
// Return zero will cause the stack to STALL request
|
||||||
uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
|
uint16_t tud_hid_n_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
|
||||||
{
|
{
|
||||||
// TODO not Implemented
|
// TODO not Implemented
|
||||||
|
(void) itf;
|
||||||
(void) report_id;
|
(void) report_id;
|
||||||
(void) report_type;
|
(void) report_type;
|
||||||
(void) buffer;
|
(void) buffer;
|
||||||
@ -180,9 +181,10 @@ uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type,
|
|||||||
|
|
||||||
// Invoked when received SET_REPORT control request or
|
// Invoked when received SET_REPORT control request or
|
||||||
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
|
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
|
||||||
void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
|
void tud_hid_n_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
|
||||||
{
|
{
|
||||||
// TODO set LED based on CAPLOCK, NUMLOCK etc...
|
// TODO set LED based on CAPLOCK, NUMLOCK etc...
|
||||||
|
(void) itf;
|
||||||
(void) report_id;
|
(void) report_id;
|
||||||
(void) report_type;
|
(void) report_type;
|
||||||
(void) buffer;
|
(void) buffer;
|
||||||
|
@ -83,13 +83,13 @@ uint8_t desc_hid_report2[] =
|
|||||||
// Invoked when received GET HID REPORT DESCRIPTOR
|
// Invoked when received GET HID REPORT DESCRIPTOR
|
||||||
// Application return pointer to descriptor
|
// Application return pointer to descriptor
|
||||||
// Descriptor contents must exist long enough for transfer to complete
|
// Descriptor contents must exist long enough for transfer to complete
|
||||||
uint8_t const * tud_hid_descriptor_report_cb(uint8_t desc_index)
|
uint8_t const * tud_hid_n_descriptor_report_cb(uint8_t itf)
|
||||||
{
|
{
|
||||||
if (desc_index == 0)
|
if (itf == 0)
|
||||||
{
|
{
|
||||||
return desc_hid_report1;
|
return desc_hid_report1;
|
||||||
}
|
}
|
||||||
else if (desc_index == 1)
|
else if (itf == 1)
|
||||||
{
|
{
|
||||||
return desc_hid_report2;
|
return desc_hid_report2;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ static inline hidd_interface_t* get_interface_by_itfnum(uint8_t itf_num)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t get_descindex_by_itfnum(uint8_t itf_num)
|
static inline uint8_t get_hid_index_by_itfnum(uint8_t itf_num)
|
||||||
{
|
{
|
||||||
for (uint8_t i=0; i < CFG_TUD_HID; i++ )
|
for (uint8_t i=0; i < CFG_TUD_HID; i++ )
|
||||||
{
|
{
|
||||||
@ -230,6 +230,10 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
|||||||
hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) request->wIndex );
|
hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) request->wIndex );
|
||||||
TU_ASSERT(p_hid);
|
TU_ASSERT(p_hid);
|
||||||
|
|
||||||
|
#if CFG_TUD_HID>1
|
||||||
|
uint8_t const hid_itf = get_hid_index_by_itfnum((uint8_t) request->wIndex);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD)
|
if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD)
|
||||||
{
|
{
|
||||||
//------------- STD Request -------------//
|
//------------- STD Request -------------//
|
||||||
@ -245,8 +249,7 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
|||||||
else if (request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
|
else if (request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
|
||||||
{
|
{
|
||||||
#if CFG_TUD_HID>1
|
#if CFG_TUD_HID>1
|
||||||
uint8_t const calculated_desc_index = get_descindex_by_itfnum((uint8_t) request->wIndex);
|
uint8_t const * desc_report = tud_hid_n_descriptor_report_cb(hid_itf);
|
||||||
uint8_t const * desc_report = tud_hid_descriptor_report_cb(calculated_desc_index);
|
|
||||||
#else
|
#else
|
||||||
uint8_t const * desc_report = tud_hid_descriptor_report_cb();
|
uint8_t const * desc_report = tud_hid_descriptor_report_cb();
|
||||||
#endif
|
#endif
|
||||||
@ -268,7 +271,11 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
|||||||
uint8_t const report_type = tu_u16_high(request->wValue);
|
uint8_t const report_type = tu_u16_high(request->wValue);
|
||||||
uint8_t const report_id = tu_u16_low(request->wValue);
|
uint8_t const report_id = tu_u16_low(request->wValue);
|
||||||
|
|
||||||
|
#if CFG_TUD_HID>1
|
||||||
|
uint16_t xferlen = tud_hid_n_get_report_cb(hid_itf, report_id, (hid_report_type_t) report_type, p_hid->epin_buf, request->wLength);
|
||||||
|
#else
|
||||||
uint16_t xferlen = tud_hid_get_report_cb(report_id, (hid_report_type_t) report_type, p_hid->epin_buf, request->wLength);
|
uint16_t xferlen = tud_hid_get_report_cb(report_id, (hid_report_type_t) report_type, p_hid->epin_buf, request->wLength);
|
||||||
|
#endif
|
||||||
TU_ASSERT( xferlen > 0 );
|
TU_ASSERT( xferlen > 0 );
|
||||||
|
|
||||||
tud_control_xfer(rhport, request, p_hid->epin_buf, xferlen);
|
tud_control_xfer(rhport, request, p_hid->epin_buf, xferlen);
|
||||||
@ -336,7 +343,12 @@ bool hidd_control_complete(uint8_t rhport, tusb_control_request_t const * p_requ
|
|||||||
uint8_t const report_type = tu_u16_high(p_request->wValue);
|
uint8_t const report_type = tu_u16_high(p_request->wValue);
|
||||||
uint8_t const report_id = tu_u16_low(p_request->wValue);
|
uint8_t const report_id = tu_u16_low(p_request->wValue);
|
||||||
|
|
||||||
|
#if CFG_TUD_HID>1
|
||||||
|
uint8_t const hid_itf = get_hid_index_by_itfnum((uint8_t)p_request->wIndex);
|
||||||
|
tud_hid_n_set_report_cb(hid_itf, report_id, (hid_report_type_t) report_type, p_hid->epout_buf, p_request->wLength);
|
||||||
|
#else
|
||||||
tud_hid_set_report_cb(report_id, (hid_report_type_t) report_type, p_hid->epout_buf, p_request->wLength);
|
tud_hid_set_report_cb(report_id, (hid_report_type_t) report_type, p_hid->epout_buf, p_request->wLength);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -358,7 +370,11 @@ bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
|||||||
|
|
||||||
if (ep_addr == p_hid->ep_out)
|
if (ep_addr == p_hid->ep_out)
|
||||||
{
|
{
|
||||||
|
#if CFG_TUD_HID>1
|
||||||
|
tud_hid_n_set_report_cb(itf, 0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes);
|
||||||
|
#else
|
||||||
tud_hid_set_report_cb(0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes);
|
tud_hid_set_report_cb(0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes);
|
||||||
|
#endif
|
||||||
TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
|
TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8
|
|||||||
// Invoked when received GET HID REPORT DESCRIPTOR request
|
// Invoked when received GET HID REPORT DESCRIPTOR request
|
||||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
||||||
#if CFG_TUD_HID>1
|
#if CFG_TUD_HID>1
|
||||||
uint8_t const * tud_hid_descriptor_report_cb(uint8_t desc_index);
|
uint8_t const * tud_hid_n_descriptor_report_cb(uint8_t itf);
|
||||||
#else
|
#else
|
||||||
uint8_t const * tud_hid_descriptor_report_cb(void);
|
uint8_t const * tud_hid_descriptor_report_cb(void);
|
||||||
#endif
|
#endif
|
||||||
@ -95,11 +95,19 @@ uint8_t const * tud_hid_descriptor_report_cb(void);
|
|||||||
// Invoked when received GET_REPORT control request
|
// Invoked when received GET_REPORT control request
|
||||||
// Application must fill buffer report's content and return its length.
|
// Application must fill buffer report's content and return its length.
|
||||||
// Return zero will cause the stack to STALL request
|
// Return zero will cause the stack to STALL request
|
||||||
|
#if CFG_TUD_HID>1
|
||||||
|
uint16_t tud_hid_n_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
|
||||||
|
#else
|
||||||
uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
|
uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Invoked when received SET_REPORT control request or
|
// Invoked when received SET_REPORT control request or
|
||||||
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
|
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
|
||||||
|
#if CFG_TUD_HID>1
|
||||||
|
void tud_hid_n_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
|
||||||
|
#else
|
||||||
void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
|
void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Invoked when received SET_PROTOCOL request ( mode switch Boot <-> Report )
|
// Invoked when received SET_PROTOCOL request ( mode switch Boot <-> Report )
|
||||||
TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
|
TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user