forked from Grapsus/cc254x_sdcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usb.c
660 lines (574 loc) · 25 KB
/
usb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
#include "usb.h"
#include "cc254x_map.h"
#include "cc254x_types.h"
#include "util.h"
//#include <board.h>
//#include <stdio.h>
//#include "uart0.h"
// TODO: make the usb library work will with Sleep Mode 0 (an interrupt should be enabled for all the endpoints we care about so we can handle them quickly)
// TODO: SUSPEND MODE!
extern uint8 CODE usbConfigurationDescriptor[];
static void usbStandardDeviceRequestHandler();
#define CONTROL_TRANSFER_STATE_NONE 0
#define CONTROL_TRANSFER_STATE_WRITE 1
#define CONTROL_TRANSFER_STATE_READ 2
USB_SETUP_PACKET XDATA usbSetupPacket;
uint8 XDATA usbDeviceState = USB_STATE_DETACHED;
uint8 XDATA controlTransferState = CONTROL_TRANSFER_STATE_NONE;
uint16 XDATA controlTransferBytesLeft;
XDATA uint8 * controlTransferPointer;
volatile BIT usbSuspendMode = 0;
// TODO: eventually: Enable the USB interrupt and only set usbActivityFlag in the ISR
volatile BIT usbActivityFlag = 0;
void usbInit()
{
}
// TODO: try using DMA in usbReadFifo and usbWriteFifo and see how that affects the speed of usbComTxSend(x, 128).
void usbReadFifo(uint8 endpointNumber, uint8 count, uint8 XDATA * buffer)
{
XDATA uint8 * fifo = (XDATA uint8 *)(0x6220 + (uint8)(endpointNumber<<1));
//printf("UR %hhd\r\n", count);
while(count > 0)
{
count--;
*(buffer++) = *fifo;
}
usbActivityFlag = 1;
}
void usbWriteFifo(uint8 endpointNumber, uint8 count, const uint8 XDATA * buffer)
{
XDATA uint8 * fifo = (XDATA uint8 *)(0x6220 + (uint8)(endpointNumber<<1));
//printf("UW %hhd\r\n", count);
while(count > 0)
{
count--;
//printf(" %02hhx\r\n", *buffer);
*fifo = *(buffer++);
}
// We don't set the usbActivityFlag here; we wait until the packet is
// actually sent.
}
// Performs some basic tasks that should be done after USB is connected and after every
// Reset interrupt.
static void basicUsbInit()
{
// enable USB and USB PLL
USBCTRL |= (1 << 1) | (1 << 0);
// wait for PLL to lock
while( ! USBCTRL & (1 << 7)){}
usbSuspendMode = 0;
// Enable suspend detection and disable any other weird features.
//USBPOW = 1;
// Enable the USB common interrupts we care about: Reset, Resume, Suspend.
// Without this, we USBCIF.SUSPENDIF will not get set (the datasheet is incomplete).
USBCIE = 0b0111;
}
void usbPoll()
{
uint8 usbcif;
uint8 usbiif;
//uint8 usboif = USBOIF;
// TODO fixme
/*if (!usbPowerPresent())
{
// The VBUS line is low. This usually means that the USB cable has been
// disconnected or the computer has been turned off.
SLEEP &= ~(1<<7); // Disable the USB module (SLEEP.USB_EN = 0).
disableUsbPullup();
usbDeviceState = USB_STATE_DETACHED;
usbSuspendMode = 0;
return;
}*/
if (usbDeviceState == USB_STATE_DETACHED)
{
enableUsbPullup();
SLEEP |= (1<<7); // Enable the USB module (SLEEP.USB_EN = 1).
__asm nop __endasm; // Datasheet doesn't say so, but David suspects we need some NOPs here before writing to USB registers.
__asm nop __endasm;
__asm nop __endasm;
__asm nop __endasm;
usbDeviceState = USB_STATE_POWERED;
basicUsbInit();
}
usbcif = USBCIF;
usbiif = USBIIF;
if (usbcif & (1<<0)) // Check SUSPENDIF
{
// The bus has been idle for 3 ms, so we are now in Suspend mode.
// It is the user's responsibility to check usbSuspended() and go to sleep (PM1)
// if necessary.
usbSuspendMode = 1;
}
if (usbcif & (1<<2)) // check RSTIF, the reset flag
{
// A USB reset signal has been received.
usbDeviceState = USB_STATE_DEFAULT;
controlTransferState = CONTROL_TRANSFER_STATE_NONE;
basicUsbInit();
}
if (usbcif & (1<<1)) // Check RESUMEIF
{
usbSuspendMode = 0;
}
if (usbiif & (1<<0)) // Check EP0IF
{
// Something happened on Endpoint 0, the endpoint for control transfers.
uint8 usbcs0;
USBINDEX = 0;
usbcs0 = USBCS0;
usbActivityFlag = 1;
if (usbcs0 & (1<<4)) // Check SETUP_END
{
// A new setup packet has arrived, prematurely ending the previous control transfer.
USBCS0 = 0x80; // Clear the SETUP_END bit
controlTransferState = CONTROL_TRANSFER_STATE_NONE;
}
if (usbcs0 & (1<<2)) // Check SENT_STALL
{
// A STALL packet was sent
USBCS0 = 0x00; // Reset endpoint 0.
controlTransferState = CONTROL_TRANSFER_STATE_NONE;
}
if (usbcs0 & (1<<0)) // Check OUTPKT_RDY
{
// Requirement: Every codepath from here must result in writing a 1 to
// bit 6 of USBCS0 to clear the OUTPKT_RDY flag: USBCS0 = (1<<6).
if (controlTransferState == CONTROL_TRANSFER_STATE_WRITE)
{
// A data packet has been received as part of a control write transfer.
uint8 bytesReceived = USBCNT0;
if (bytesReceived > controlTransferBytesLeft)
{
bytesReceived = controlTransferBytesLeft;
}
usbReadFifo(0, bytesReceived, controlTransferPointer);
controlTransferPointer += bytesReceived;
controlTransferBytesLeft -= bytesReceived;
if (controlTransferBytesLeft)
{
// Arm the endpoint to receive more bytes
USBCS0 = (1<<6); // De-asserts the OUTPKT_RDY bit (bit 0).
}
else
{
// The host has sent all the data we were expecting.
if (usbSetupPacket.requestType != USB_REQUEST_TYPE_STANDARD) // OPT: remove this check
{
usbCallbackControlWriteHandler();
}
USBINDEX = 0; // Just in case USBINDEX was changed above.
if (controlTransferState == CONTROL_TRANSFER_STATE_NONE)
{
// The data received was invalid.
USBCS0 = (1<<6) | (1<<3) | (1<<5); // clear OUTPKT_RDY, set DATA_END, SEND_STALL
}
else
{
// The data received was valid.
USBCS0 = (1<<6) | (1<<3); // clear OUTPKT_RDY, set DATA_END
controlTransferState = CONTROL_TRANSFER_STATE_NONE;
}
}
}
else if (USBCNT0 == 8)
{
// A SETUP packet has been received from the computer, starting a new
// control transfer.
usbReadFifo(0, 8, (uint8 XDATA *)&usbSetupPacket); // Store the data in usbSetupPacket.
// Wipe out the information about the last control transfer.
controlTransferState = CONTROL_TRANSFER_STATE_NONE;
if (usbSetupPacket.requestType == USB_REQUEST_TYPE_STANDARD)
{
// The request_type field indicates that this is a Standard Device Request
// as described in USB2.0 Chapter 9.4 Standard Device Requests.
// These requests are handled by the library in the function below.
usbStandardDeviceRequestHandler();
}
else
{
// Otherwise, we use this callback so the user can decide how to handle the
// setup packet. In this callback, the user can call various helper
// functions that set controlTransferState.
usbCallbackSetupHandler();
}
USBINDEX = 0; // Select EP0 again because the functions above might have changed USBINDEX.
// Modify the count so that we don't send more data than the host requested.
if(controlTransferBytesLeft > usbSetupPacket.wLength)
{
controlTransferBytesLeft = usbSetupPacket.wLength;
}
// Prepare for the first transaction after the SETUP packet.
if (controlTransferState == CONTROL_TRANSFER_STATE_NONE)
{
// This is invalid/unrecognized control transfer, so send a STALL packet.
USBCS0 = (1<<6) | (1<<5); // Clears the OUTPKT_RDY flag because we've handled it, and sends a STALL.
}
else if (controlTransferState == CONTROL_TRANSFER_STATE_WRITE)
{
if (controlTransferBytesLeft)
{
// Arm the endpoint to receive the first data packet of a control write transfer.
USBCS0 = (1<<6); // De-asserts the OUTPKT_RDY bit.
}
else
{
// Acknowledge a control write transfer with no data phase.
USBCS0 = (1<<6) | (1<<3) | (1<<1); // De-asserts OUTPKY_RDY, asserts DATA_END, asserts INPKT_RDY.
controlTransferState = CONTROL_TRANSFER_STATE_NONE;
}
}
}
else
{
// An OUT packet was received on Endpoint 0, but we are not in the middle of a
// control write transfer and it was not the right length to be a setup packet.
// This situation is not expected.
USBCS0 = (1<<6); // De-asserts the OUTPKT_RDY.
}
}
if (!(usbcs0 & (1<<1)) && (controlTransferState == CONTROL_TRANSFER_STATE_READ))
{
// We are doing a control read transfer, and Endpoint 0 is ready to accept another
// IN packet to send to the computer.
uint8 bytesToSend;
if (controlTransferBytesLeft < USB_EP0_PACKET_SIZE)
{
// Send the last packet (might be an empty packet).
usbcs0 = (1<<1)|(1<<3); // INPKT_RDY and DATA_END
bytesToSend = controlTransferBytesLeft;
controlTransferState = CONTROL_TRANSFER_STATE_NONE;
}
else
{
// Send a packet.
usbcs0 = (1<<1); // INPKT_RDY
bytesToSend = USB_EP0_PACKET_SIZE;
}
// Arm endpoint 0 to send the next packet.
usbWriteFifo(0, bytesToSend, controlTransferPointer);
USBCS0 = usbcs0;
// Update the control transfer state.
controlTransferPointer += bytesToSend;
controlTransferBytesLeft -= bytesToSend;
}
}
}
// usbStandardDeviceRequestHandler(): Implementation of USB2.0 Section 9.4, Standard Device Requests.
// This function gets called whenever we receive a SETUP packet on endpoint zero with the requestType
// field set to STANDARD. This function reads the SETUP packet and uses that to set the control
// transfer state variables with all the information needed to respond to the request.
// Assumption: controlTransferState is CONTROL_TRANSFER_STATE_NONE when this function is called.
static void usbStandardDeviceRequestHandler()
{
// Prepare a convenient two-byte buffer for sending 1 or 2 byte responses.
static XDATA uint8 response[2];
response[0] = 0;
response[1] = 0;
// Now we decide how to handle the new setup packet. There are several possibilities:
// * Invalid: The SETUP packet had a problem with it, or we don't support the feature,
// so we need to STALL the next transaction to indicate an request error to the host.
// * Control Read: We must send some data to the computer, so we need to decide
// where the data is coming from (address, plus RAM/ROM selection)
// * Control Write with no data phase: We need to prepare for the status phase, where
// our device must send a zero-length EP0 IN packet to indicate success.
// * Control Write with data phase: The computer will send data to us, and we need to
// decide where in RAM to put it. (No standard device requests use this type,
// so ignore this case.)
switch(usbSetupPacket.bRequest)
{
case USB_REQUEST_GET_DESCRIPTOR: // USB Spec 9.4.3 Get Descriptor
{
switch(usbSetupPacket.wValue >> 8)
{
case USB_DESCRIPTOR_TYPE_DEVICE:
{
controlTransferPointer = CODE_TO_XDATA(&usbDeviceDescriptor);
controlTransferBytesLeft = sizeof(USB_DESCRIPTOR_DEVICE);
break;
}
case USB_DESCRIPTOR_TYPE_CONFIGURATION:
{
if ((usbSetupPacket.wValue & 0xFF) != 0)
{
// Invalid configuration index.
return;
}
// The configuration descriptor has an application-dependent size, which
// we determine by reading the 3rd and 4th byte.
controlTransferPointer = CODE_TO_XDATA(usbConfigurationDescriptor);
controlTransferBytesLeft = *(uint16 *)&usbConfigurationDescriptor[2];
break;
}
case USB_DESCRIPTOR_TYPE_STRING:
{
if ((usbSetupPacket.wValue & 0xFF) >= usbStringDescriptorCount)
{
// This is either an invalid string index or it is 0xEE,
// which is defined by Microsoft OS Descriptors 1.0.
// This library provides no features for handling such requests,
// but we call the user's callback in case they want to.
usbCallbackClassDescriptorHandler();
return;
}
controlTransferPointer = CODE_TO_XDATA(usbStringDescriptors[usbSetupPacket.wValue & 0xFF]);
controlTransferBytesLeft = controlTransferPointer[0];
break;
}
default:
{
// see if the class recognizes the descriptor type; it should call usbControlRead if it does
usbCallbackClassDescriptorHandler();
if (controlTransferState == CONTROL_TRANSFER_STATE_NONE)
{
// unknown type of descriptor
return;
}
break;
}
}
controlTransferState = CONTROL_TRANSFER_STATE_READ;
return;
}
case USB_REQUEST_SET_ADDRESS: // USB Spec, 9.4.6 Set Address
{
// Get ready to set the address when the status phase is complete.
// We always set the most siginificant bit, because .device_address might be 0
// and that is a valid request, meaning we should revert to address 0.
//pendingDeviceAddress = (usbSetupPacket.wValue & 0xFF) | 0x80;
USBADDR = (uint8)usbSetupPacket.wValue;
usbDeviceState = ((uint8)usbSetupPacket.wValue) ? USB_STATE_ADDRESS : USB_STATE_DEFAULT;
// Get ready to provide a handshake.
usbControlAcknowledge();
return;
}
case USB_REQUEST_SET_CONFIGURATION: // USB Spec, 9.4.7 Set Configuration
{
// Assumption: there is only one configuration and its value is 1.
switch(usbSetupPacket.wValue)
{
case 0:
{
// We have been deconfigured.
// TODO: Add resetNonzeroEndpoints() and call it here.
if (usbDeviceState > USB_STATE_ADDRESS)
{
usbDeviceState = USB_STATE_ADDRESS;
}
break;
}
case 1:
{
// The device has been configured. This is normal operating
// state of a USB device. We can now start using non-zero
// endpoints.
usbDeviceState = USB_STATE_CONFIGURED;
usbCallbackInitEndpoints();
break;
}
default:
{
// Invalid configuration value, so STALL.
return;
}
}
// Get ready to provide a handshake.
usbControlAcknowledge();
return;
}
case USB_REQUEST_GET_CONFIGURATION: // USB Spec 9.4.2 Get Configuration
{
// Assumption: there is only one configuration and its value is 1.
response[0] = (usbDeviceState == USB_STATE_CONFIGURED) ? 1 : 0;
usbControlRead(1, response);
return;
}
case USB_REQUEST_GET_INTERFACE: // USB Spec 9.4.4 Get Interface
{
// Assumption: the "alternate setting number" of each interface
// is zero and there are no alternate settings.
// Assumption: interface numbers go from 0 to
// config->interface_count-1, with no gaps.
if (usbDeviceState < USB_STATE_CONFIGURED)
{
// Invalid request because we have not reached the configured state.
return;
}
if (usbSetupPacket.wIndex >= ((USB_DESCRIPTOR_CONFIGURATION *)&usbConfigurationDescriptor)->bNumInterfaces)
{
// Invalid index: there is no such interface.
return;
}
// Send a single-byte response of "0".
// Assumption: response[0] == 0
usbControlRead(1, response);
return;
}
case USB_REQUEST_GET_STATUS: // USB Spec 9.4.5 Get Status
{
switch(usbSetupPacket.recipient)
{
case USB_RECIPIENT_DEVICE:
{
// See USB Spec Table 9-4.
response[0] = vinPowerPresent() ? 1 : 0;
// Assumption: response[1] == 0
usbControlRead(2, response);
return;
}
case USB_RECIPIENT_INTERFACE:
{
if (usbDeviceState < USB_STATE_CONFIGURED && usbSetupPacket.wIndex != 0)
{
// It is invalid to ask about interfaces other than 0 before the
// configured state.
return;
}
if (usbSetupPacket.wIndex >= ((USB_DESCRIPTOR_CONFIGURATION *)&usbConfigurationDescriptor)->bNumInterfaces)
{
// Invalid index: there is no such interface.
return;
}
// Send a 2-byte response of 0,0 (all of the bits are reserved)
// Assumption: response[0] == 0 and response[1] == 0
usbControlRead(2, response);
return;
}
case USB_RECIPIENT_ENDPOINT:
{
if ((usbSetupPacket.wValue & 15) == 0)
{
// We don't support the halt feature on Endpoint 0
// (the USB Spec does not require or recommend it).
return;
}
if (usbDeviceState < USB_STATE_CONFIGURED)
{
// It is invalid to ask about non-zero endpoints before
// the configured state.
return;
}
// Assumption: We don't have a USB halt feature, i.e. we
// don't stall on non-zero endpoints.
// Send a 2-byte response of 0,0.
// Assumption: response[0] == 0 and response[1] == 0
usbControlRead(2, response);
return;
}
}
return;
}
// Here are some more standard device requests we would need
// to be USB compliant. We didn't use them yet on any of our
// PIC devices and it has not caused a problem as far as I
// know. We pay lip service to them here just in case they are
// needed by some future driver.
case USB_REQUEST_SET_FEATURE:
case USB_REQUEST_CLEAR_FEATURE:
{
// Acknowledge the request but don't do anything.
usbControlAcknowledge();
return;
}
case USB_REQUEST_SYNCH_FRAME:
{
// Send a two-byte response of 0,0.
usbControlRead(2, response);
return;
}
}
}
BIT usbSuspended()
{
return usbSuspendMode;
}
// Sleeps until we receive USB resume signaling.
// This uses PM1. ( PM2 and PM3 are not usable because they will reset the USB module. )
// NOTE: For some reason, USB suspend does not work if you plug your device into a computer
// that is already sleeping. If you do that, the device will remain awake with
// usbDeviceState == USB_STATE_POWERED and it will draw more power than it should from USB.
// TODO: figure out how to wake up when self power is connected. Probably we should use the
// sleep timer to wake up regularly and check (that's going to be easier than using a P2
// interrupt I think).
// TODO: make sure suspend mode doesn't interfere with the radio libraries. We should
// probably make a simple power-event registration thing using function pointers,
// (either an array, or a linked list where the memory is contributed by the modules using it).
// When going to sleep, we would call these functions in the order they were added;
// when waking up, we would call them in the opposite order. Look at how we handle power
// on the jrk, maestros, and simple motor controller to see if this pattern works.
void usbSleep()
{
uint8 savedPICTL = PICTL;
BIT savedP0IE = P0IE;
// The USB resume interrupt is mapped to the non-existent pin, P0_7.
P0IE = 0; // Disable the P0 interrupt while we are reconfiguring it (maybe not necessary).
PICTL |= (1<<4); // PICTL.P0IENH = 1 Enable the Port 0 interrupts for inputs 4-7 (USB_RESUME is #7).
PICTL &= ~(1<<0); // PICTL.P0ICON = 0 Detect rising edges (this is required for waking up).
do
{
// Clear the P0 interrupt flag that might prevent us from sleeping.
P0IFG = 0; // Clear Port 0 module interrupt flags.
P0IF = 0; // Clear Port 0 CPU interrupt flag (IRCON.P0IF = 0).
P0IE = 1; // Enable the Port 0 interrupt (IEN1.P0IE = 1) so we can wake up.
// Put the device to sleep by following the recommended pseudo code in the datasheet section 12.1.3:
SLEEP = (SLEEP & ~3) | 1; // SLEEP.MODE = 1 : Selects Power Mode 1 (PM1).
__asm nop __endasm; __asm nop __endasm; __asm nop __endasm;
if (SLEEP & 3)
{
P1_0 = 1;
PCON |= 1; // PCON.IDLE = 1 : Actually go to sleep.
P1_0 = 0;
}
// Disable the Port 0 interrupt. If we don't do this, and there is no ISR
// (just a reti), then the non-existent ISR could run many times while we
// are awake, slowing down this loop.
P0IE = 0; // (IEN1.P0IE = 1)
// Check to see if the USB_RESUME bit is set. If it is set, then there was
// activity detected on the USB and it is time to wake up.
// NOTE: The P0INT ISR might also set usbSuspendMode to 0 if the user defines
// that ISR. See the comment about P0INT in usb.h for more info.
if (P0IFG & 0x80)
{
usbSuspendMode = 0;
}
}
while(usbSuspendMode && !vinPowerPresent());
// Wait for the high speed crystal oscillator to become stable again
// because we can't write to USB registers until that happens.
while(!(SLEEP & (1<<6))){};
// Restore the interrupt registers to their original states.
PICTL = savedPICTL;
P0IE = savedP0IE;
}
void usbControlRead(uint16 bytesCount, uint8 XDATA * source)
{
controlTransferState = CONTROL_TRANSFER_STATE_READ;
controlTransferBytesLeft = bytesCount;
controlTransferPointer = source;
}
void usbControlWrite(uint16 bytesCount, uint8 XDATA * source)
{
controlTransferState = CONTROL_TRANSFER_STATE_WRITE;
controlTransferBytesLeft = bytesCount;
controlTransferPointer = source;
}
void usbControlAcknowledge()
{
controlTransferState = CONTROL_TRANSFER_STATE_WRITE;
controlTransferBytesLeft = 0;
}
void usbControlStall()
{
controlTransferState = CONTROL_TRANSFER_STATE_NONE;
}
void usbInitEndpointIn(uint8 endpointNumber, uint8 maxPacketSize)
{
USBINDEX = endpointNumber;
USBMAXI = (maxPacketSize + 7) >> 3;
USBCSIH = 1; // Enable Double buffering
}
void usbInitEndpointOut(uint8 endpointNumber, uint8 maxPacketSize)
{
USBINDEX = endpointNumber;
USBMAXO = (maxPacketSize + 7) >> 3;
USBCSOH = 1; // Enable Double buffering
}