30
30
#define EP_TYPE_ISOCHRONOUS_IN 0x41
31
31
#define EP_TYPE_ISOCHRONOUS_OUT 0x40
32
32
33
+ /* * Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */
34
+ #define TX_RX_LED_PULSE_MS 100
35
+ volatile u8 TxLEDPulse; /* *< Milliseconds remaining for data Tx LED pulse */
36
+ volatile u8 RxLEDPulse; /* *< Milliseconds remaining for data Rx LED pulse */
37
+
33
38
// ==================================================================
34
39
// ==================================================================
35
40
@@ -108,11 +113,17 @@ void Recv(volatile u8* data, u8 count)
108
113
{
109
114
while (count--)
110
115
*data++ = UEDATX;
116
+
117
+ RXLED1; // light the RX LED
118
+ RxLEDPulse = TX_RX_LED_PULSE_MS;
111
119
}
112
120
113
121
static inline u8 Recv8 ()
114
122
{
115
- return UEDATX;
123
+ RXLED1; // light the RX LED
124
+ RxLEDPulse = TX_RX_LED_PULSE_MS;
125
+
126
+ return UEDATX;
116
127
}
117
128
118
129
static inline void Send8 (u8 d)
@@ -206,13 +217,13 @@ u8 USB_Available(u8 ep)
206
217
return FifoByteCount ();
207
218
}
208
219
209
- // Non Blocking recieve
220
+ // Non Blocking receive
210
221
// Return number of bytes read
211
222
int USB_Recv (u8 ep, void * d, int len)
212
223
{
213
224
if (!_usbConfiguration || len < 0 )
214
225
return -1 ;
215
-
226
+
216
227
LockEP lock (ep);
217
228
u8 n = FifoByteCount ();
218
229
len = min (n,len);
@@ -222,7 +233,7 @@ int USB_Recv(u8 ep, void* d, int len)
222
233
*dst++ = Recv8 ();
223
234
if (len && !FifoByteCount ()) // release empty buffer
224
235
ReleaseRX ();
225
-
236
+
226
237
return len;
227
238
}
228
239
@@ -289,6 +300,8 @@ int USB_Send(u8 ep, const void* d, int len)
289
300
ReleaseTX ();
290
301
}
291
302
}
303
+ TXLED1; // light the TX LED
304
+ TxLEDPulse = TX_RX_LED_PULSE_MS;
292
305
return r;
293
306
}
294
307
@@ -306,11 +319,6 @@ const u8 _initEndpoints[] =
306
319
#ifdef HID_ENABLED
307
320
EP_TYPE_INTERRUPT_IN // HID_ENDPOINT_INT
308
321
#endif
309
-
310
- #ifdef MSC_ENABLED
311
- EP_TYPE_BULK_OUT, // MSC_ENDPOINT_OUT
312
- EP_TYPE_BULK_IN, // MSC_ENDPOINT_IN
313
- #endif
314
322
};
315
323
316
324
#define EP_SINGLE_64 0x32 // EP0
@@ -350,11 +358,6 @@ bool ClassInterfaceRequest(Setup& setup)
350
358
return CDC_Setup (setup);
351
359
#endif
352
360
353
- #ifdef MSC_ENABLED
354
- if (MSC_INTERFACE == i)
355
- return MSC_Setup (setup);
356
- #endif
357
-
358
361
#ifdef HID_ENABLED
359
362
if (HID_INTERFACE == i)
360
363
return HID_Setup (setup);
@@ -425,9 +428,6 @@ int SendInterfaces()
425
428
total += HID_GetInterface (&interfaces);
426
429
#endif
427
430
428
- #ifdef MSC_ENABLED
429
- total += MSC_GetInterface (&interfaces);
430
- #endif
431
431
return interfaces;
432
432
}
433
433
@@ -504,8 +504,6 @@ ISR(USB_COM_vect)
504
504
Recv ((u8*)&setup,8 );
505
505
ClearSetupInt ();
506
506
507
- // printHex((u8*)&setup,8);
508
-
509
507
u8 requestType = setup.bmRequestType ;
510
508
if (requestType & REQUEST_DEVICETOHOST)
511
509
WaitIN ();
@@ -596,12 +594,18 @@ ISR(USB_GEN_vect)
596
594
UEIENX = 1 << RXSTPE; // Enable interrupts for ep0
597
595
}
598
596
599
- // Start of Frame
597
+ // Start of Frame - happens every millisecond so we use it for TX and RX LED one-shot timing, too
600
598
if (udint & (1 <<SOFI))
601
599
{
602
600
#ifdef CDC_ENABLED
603
601
USB_Flush (CDC_TX); // Send a tx frame if found
604
602
#endif
603
+
604
+ // check whether the one-shot period has elapsed. if so, turn off the LED
605
+ if (TxLEDPulse && !(--TxLEDPulse))
606
+ TXLED0;
607
+ if (RxLEDPulse && !(--RxLEDPulse))
608
+ RXLED0;
605
609
}
606
610
}
607
611
@@ -634,6 +638,8 @@ void USB_::attach()
634
638
USBCON = ((1 <<USBE)|(1 <<OTGPADE)); // start USB clock
635
639
UDIEN = (1 <<EORSTE)|(1 <<SOFE); // Enable interrupts for EOR (End of Reset) and SOF (start of frame)
636
640
UDCON = 0 ; // enable attach resistor
641
+
642
+ TX_RX_LED_INIT;
637
643
}
638
644
639
645
void USB_::detach ()
@@ -649,14 +655,6 @@ bool USB_::configured()
649
655
650
656
void USB_::poll ()
651
657
{
652
- #ifdef MSC_ENABLED
653
- if (!_usbConfiguration)
654
- return ;
655
-
656
- // Service disk
657
- if (USB_Available (MSC_RX))
658
- MSC_Data (MSC_RX,MSC_TX);
659
- #endif
660
658
}
661
659
662
660
#endif /* if defined(USBCON) */
0 commit comments