summaryrefslogtreecommitdiff
path: root/src/class/bth/bth_device.c
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2021-01-21 16:35:13 +0700
committerGitHub <[email protected]>2021-01-21 16:35:13 +0700
commit1e134cbb31cb0fcd593d47e9865dd2c4dba68686 (patch)
tree4638eb5eb885e89be071a83a9297ad9da126cdf8 /src/class/bth/bth_device.c
parente0aa405d19e35dbf58cf502b8106455c1a3c2a5c (diff)
parent7aaccd94d2e11ee2329353b4119526c75279b3ba (diff)
Merge branch 'master' into pico
Diffstat (limited to 'src/class/bth/bth_device.c')
-rwxr-xr-xsrc/class/bth/bth_device.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/src/class/bth/bth_device.c b/src/class/bth/bth_device.c
index 252e20e37..481dc134e 100755
--- a/src/class/bth/bth_device.c
+++ b/src/class/bth/bth_device.c
@@ -186,43 +186,46 @@ uint16_t btd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_
return drv_len;
}
-bool btd_control_complete(uint8_t rhport, tusb_control_request_t const *request)
+// Invoked when a control transfer occurred on an interface of this class
+// Driver response accordingly to the request and the transfer stage (setup/data/ack)
+// return false to stall control endpoint (e.g unsupported request)
+bool btd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
{
(void)rhport;
- // Handle class request only
- TU_VERIFY(request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
-
- if (tud_bt_hci_cmd_cb) tud_bt_hci_cmd_cb(&_btd_itf.hci_cmd, request->wLength);
-
- return true;
-}
-
-bool btd_control_request(uint8_t rhport, tusb_control_request_t const *request)
-{
- (void)rhport;
-
- if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS &&
- request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_DEVICE)
- {
- // HCI command packet addressing for single function Primary Controllers
- TU_VERIFY(request->bRequest == 0 && request->wValue == 0 && request->wIndex == 0);
- }
- else if (request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE)
+ if ( stage == CONTROL_STAGE_SETUP )
{
- if (request->bRequest == TUSB_REQ_SET_INTERFACE && _btd_itf.itf_num + 1 == request->wIndex)
+ if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS &&
+ request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_DEVICE)
{
- // TODO: Set interface it would involve changing size of endpoint size
+ // HCI command packet addressing for single function Primary Controllers
+ TU_VERIFY(request->bRequest == 0 && request->wValue == 0 && request->wIndex == 0);
}
- else
+ else if (request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE)
{
- // HCI command packet for Primary Controller function in a composite device
- TU_VERIFY(request->bRequest == 0 && request->wValue == 0 && request->wIndex == _btd_itf.itf_num);
+ if (request->bRequest == TUSB_REQ_SET_INTERFACE && _btd_itf.itf_num + 1 == request->wIndex)
+ {
+ // TODO: Set interface it would involve changing size of endpoint size
+ }
+ else
+ {
+ // HCI command packet for Primary Controller function in a composite device
+ TU_VERIFY(request->bRequest == 0 && request->wValue == 0 && request->wIndex == _btd_itf.itf_num);
+ }
}
+ else return false;
+
+ return tud_control_xfer(rhport, request, &_btd_itf.hci_cmd, request->wLength);
+ }
+ else if ( stage == CONTROL_STAGE_DATA )
+ {
+ // Handle class request only
+ TU_VERIFY(request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
+
+ if (tud_bt_hci_cmd_cb) tud_bt_hci_cmd_cb(&_btd_itf.hci_cmd, request->wLength);
}
- else return false;
- return tud_control_xfer(rhport, request, &_btd_itf.hci_cmd, request->wLength);
+ return true;
}
bool btd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
@@ -246,7 +249,7 @@ bool btd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t
if (tud_bt_acl_data_sent_cb) tud_bt_acl_data_sent_cb((uint16_t)xferred_bytes);
}
- return TUSB_ERROR_NONE;
+ return true;
}
#endif