@@ -86,6 +86,11 @@ tu_static char logMsg[150];
86
86
// imposes a minimum buffer size of 32 bytes.
87
87
#define USBTMCD_BUFFER_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
88
88
89
+ // Interrupt endpoint buffer size, default to 2 bytes as USB488 specification.
90
+ #ifndef CFG_TUD_USBTMC_INT_EP_SIZE
91
+ #define CFG_TUD_USBTMC_INT_EP_SIZE 2
92
+ #endif
93
+
89
94
/*
90
95
* The state machine does not allow simultaneous reading and writing. This is
91
96
* consistent with USBTMC.
@@ -124,13 +129,15 @@ typedef struct
124
129
uint8_t ep_bulk_in ;
125
130
uint8_t ep_bulk_out ;
126
131
uint8_t ep_int_in ;
132
+ uint32_t ep_bulk_in_wMaxPacketSize ;
133
+ uint32_t ep_bulk_out_wMaxPacketSize ;
127
134
// IN buffer is only used for first packet, not the remainder
128
135
// in order to deal with prepending header
129
136
CFG_TUSB_MEM_ALIGN uint8_t ep_bulk_in_buf [USBTMCD_BUFFER_SIZE ];
130
- uint32_t ep_bulk_in_wMaxPacketSize ;
131
137
// OUT buffer receives one packet at a time
132
138
CFG_TUSB_MEM_ALIGN uint8_t ep_bulk_out_buf [USBTMCD_BUFFER_SIZE ];
133
- uint32_t ep_bulk_out_wMaxPacketSize ;
139
+ // Buffer int msg to ensure alignment and placement correctness
140
+ CFG_TUSB_MEM_ALIGN uint8_t ep_int_in_buf [CFG_TUD_USBTMC_INT_EP_SIZE ];
134
141
135
142
uint32_t transfer_size_remaining ; // also used for requested length for bulk IN.
136
143
uint32_t transfer_size_sent ; // To keep track of data bytes that have been queued in FIFO (not header bytes)
@@ -240,6 +247,19 @@ bool tud_usbtmc_transmit_dev_msg_data(
240
247
return true;
241
248
}
242
249
250
+ bool tud_usbtmc_transmit_notification_data (const void * data , size_t len )
251
+ {
252
+ #ifndef NDEBUG
253
+ TU_ASSERT (len > 0 );
254
+ TU_ASSERT (usbtmc_state .ep_int_in != 0 );
255
+ #endif
256
+ TU_VERIFY (usbd_edpt_busy (usbtmc_state .rhport , usbtmc_state .ep_int_in ));
257
+
258
+ TU_VERIFY (tu_memcpy_s (usbtmc_state .ep_int_in_buf , sizeof (usbtmc_state .ep_int_in_buf ), data , len ) == 0 );
259
+ TU_VERIFY (usbd_edpt_xfer (usbtmc_state .rhport , usbtmc_state .ep_int_in , usbtmc_state .ep_int_in_buf , (uint16_t )len ));
260
+ return true;
261
+ }
262
+
243
263
void usbtmcd_init_cb (void )
244
264
{
245
265
usbtmc_state .capabilities = tud_usbtmc_get_capabilities_cb ();
@@ -547,9 +567,10 @@ bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
547
567
case STATE_TX_INITIATED :
548
568
if (usbtmc_state .transfer_size_remaining >= sizeof (usbtmc_state .ep_bulk_in_buf ))
549
569
{
550
- // FIXME! This removes const below!
570
+ // Copy buffer to ensure alignment correctness
571
+ memcpy (usbtmc_state .ep_bulk_in_buf , usbtmc_state .devInBuffer , sizeof (usbtmc_state .ep_bulk_in_buf ));
551
572
TU_VERIFY ( usbd_edpt_xfer (rhport , usbtmc_state .ep_bulk_in ,
552
- ( void * )( uintptr_t ) usbtmc_state .devInBuffer , sizeof (usbtmc_state .ep_bulk_in_buf )));
573
+ usbtmc_state .ep_bulk_in_buf , sizeof (usbtmc_state .ep_bulk_in_buf )));
553
574
usbtmc_state .devInBuffer += sizeof (usbtmc_state .ep_bulk_in_buf );
554
575
usbtmc_state .transfer_size_remaining -= sizeof (usbtmc_state .ep_bulk_in_buf );
555
576
usbtmc_state .transfer_size_sent += sizeof (usbtmc_state .ep_bulk_in_buf );
@@ -585,7 +606,9 @@ bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
585
606
}
586
607
}
587
608
else if (ep_addr == usbtmc_state .ep_int_in ) {
588
- // Good?
609
+ if (tud_usbtmc_notification_complete_cb ) {
610
+ TU_VERIFY (tud_usbtmc_notification_complete_cb ());
611
+ }
589
612
return true;
590
613
}
591
614
return false;
0 commit comments