Skip to content

Commit 085bd3c

Browse files
authored
Merge pull request #2283 from shuffle2/hid-device-set-report
hid_device: use separate buffer for SET_REPORT instead of epout
2 parents 69313ef + 1661acf commit 085bd3c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/class/hid/hid_device.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ typedef struct
4646
uint8_t ep_out; // optional Out endpoint
4747
uint8_t itf_protocol; // Boot mouse or keyboard
4848

49-
uint8_t protocol_mode; // Boot (0) or Report protocol (1)
50-
uint8_t idle_rate; // up to application to handle idle rate
5149
uint16_t report_desc_len;
50+
CFG_TUSB_MEM_ALIGN uint8_t protocol_mode; // Boot (0) or Report protocol (1)
51+
CFG_TUSB_MEM_ALIGN uint8_t idle_rate; // up to application to handle idle rate
5252

5353
CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_HID_EP_BUFSIZE];
5454
CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_HID_EP_BUFSIZE];
55+
CFG_TUSB_MEM_ALIGN uint8_t ctrl_buf[CFG_TUD_HID_EP_BUFSIZE];
5556

5657
// TODO save hid descriptor since host can specifically request this after enumeration
5758
// Note: HID descriptor may be not available from application after enumeration
@@ -295,7 +296,7 @@ bool hidd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
295296
uint8_t const report_type = tu_u16_high(request->wValue);
296297
uint8_t const report_id = tu_u16_low(request->wValue);
297298

298-
uint8_t* report_buf = p_hid->epin_buf;
299+
uint8_t* report_buf = p_hid->ctrl_buf;
299300
uint16_t req_len = tu_min16(request->wLength, CFG_TUD_HID_EP_BUFSIZE);
300301

301302
uint16_t xferlen = 0;
@@ -312,22 +313,22 @@ bool hidd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
312313
xferlen += tud_hid_get_report_cb(hid_itf, report_id, (hid_report_type_t) report_type, report_buf, req_len);
313314
TU_ASSERT( xferlen > 0 );
314315

315-
tud_control_xfer(rhport, request, p_hid->epin_buf, xferlen);
316+
tud_control_xfer(rhport, request, p_hid->ctrl_buf, xferlen);
316317
}
317318
break;
318319

319320
case HID_REQ_CONTROL_SET_REPORT:
320321
if ( stage == CONTROL_STAGE_SETUP )
321322
{
322-
TU_VERIFY(request->wLength <= sizeof(p_hid->epout_buf));
323-
tud_control_xfer(rhport, request, p_hid->epout_buf, request->wLength);
323+
TU_VERIFY(request->wLength <= sizeof(p_hid->ctrl_buf));
324+
tud_control_xfer(rhport, request, p_hid->ctrl_buf, request->wLength);
324325
}
325326
else if ( stage == CONTROL_STAGE_ACK )
326327
{
327328
uint8_t const report_type = tu_u16_high(request->wValue);
328329
uint8_t const report_id = tu_u16_low(request->wValue);
329330

330-
uint8_t const* report_buf = p_hid->epout_buf;
331+
uint8_t const* report_buf = p_hid->ctrl_buf;
331332
uint16_t report_len = tu_min16(request->wLength, CFG_TUD_HID_EP_BUFSIZE);
332333

333334
// If host request a specific Report ID, extract report ID in buffer before invoking callback

0 commit comments

Comments
 (0)