Skip to content

Commit 95be35b

Browse files
committed
add support for usbtmc vendor-spicific command messages
1 parent 1a783b3 commit 95be35b

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/class/usbtmc/usbtmc_device.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*/
4646

4747
//Limitations:
48-
// "vendor-specific" commands are not handled.
48+
// "vendor-specific" commands are handled similar to normal massages, except that the MsgID is changed to "vendor-specific".
4949
// Dealing with "termchar" must be handled by the application layer,
5050
// though additional error checking is does in this module.
5151
// talkOnly and listenOnly are NOT supported. They're not permitted
@@ -171,6 +171,8 @@ tu_static uint8_t termChar;
171171

172172
tu_static uint8_t termCharRequested = false;
173173

174+
tu_static uint8_t usbtmcVendorSpecificRequested = false;
175+
174176
#if OSAL_MUTEX_REQUIRED
175177
static OSAL_MUTEX_DEF(usbtmcLockBuffer);
176178
#endif
@@ -226,7 +228,14 @@ bool tud_usbtmc_transmit_dev_msg_data(
226228
TU_VERIFY(usbtmc_state.state == STATE_TX_REQUESTED);
227229
usbtmc_msg_dev_dep_msg_in_header_t *hdr = (usbtmc_msg_dev_dep_msg_in_header_t*)usbtmc_epbuf.epin;
228230
tu_varclr(hdr);
229-
hdr->header.MsgID = USBTMC_MSGID_DEV_DEP_MSG_IN;
231+
if(usbtmcVendorSpecificRequested)
232+
{
233+
hdr->header.MsgID = USBTMC_MSGID_VENDOR_SPECIFIC_IN;
234+
}
235+
else
236+
{
237+
hdr->header.MsgID = USBTMC_MSGID_DEV_DEP_MSG_IN;
238+
}
230239
hdr->header.bTag = usbtmc_state.lastBulkInTag;
231240
hdr->header.bTagInverse = (uint8_t)~(usbtmc_state.lastBulkInTag);
232241
hdr->TransferSize = len;
@@ -512,6 +521,7 @@ bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
512521

513522
switch(msg->header.MsgID) {
514523
case USBTMC_MSGID_DEV_DEP_MSG_OUT:
524+
usbtmcVendorSpecificRequested = false;
515525
if(!handle_devMsgOutStart(rhport, msg, xferred_bytes))
516526
{
517527
usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
@@ -520,6 +530,7 @@ bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
520530
break;
521531

522532
case USBTMC_MSGID_DEV_DEP_MSG_IN:
533+
usbtmcVendorSpecificRequested = false;
523534
TU_VERIFY(handle_devMsgIn(msg, xferred_bytes));
524535
break;
525536

@@ -532,7 +543,19 @@ bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
532543
break;
533544
#endif
534545
case USBTMC_MSGID_VENDOR_SPECIFIC_MSG_OUT:
546+
usbtmcVendorSpecificRequested = true;
547+
if(!handle_devMsgOutStart(rhport, msg, xferred_bytes))
548+
{
549+
usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
550+
return false;
551+
}
552+
break;
553+
535554
case USBTMC_MSGID_VENDOR_SPECIFIC_IN:
555+
usbtmcVendorSpecificRequested = true;
556+
TU_VERIFY(handle_devMsgIn(msg, xferred_bytes));
557+
break;
558+
536559
default:
537560
usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
538561
return false;

0 commit comments

Comments
 (0)