-
Notifications
You must be signed in to change notification settings - Fork 3
/
usb_device_generic.h
182 lines (139 loc) · 6.44 KB
/
usb_device_generic.h
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
//DOM-IGNORE-BEGIN
/*******************************************************************************
Software License Agreement
The software supplied herewith by Microchip Technology Incorporated
(the "Company") for its PICmicro(R) Microcontroller is intended and
supplied to you, the Company's customer, for use solely and
exclusively on Microchip PICmicro Microcontroller products. The
software is owned by the Company and/or its supplier, and is
protected under applicable copyright laws. All rights are reserved.
Any use in violation of the foregoing restrictions may subject the
user to criminal sanctions under applicable laws, as well as to
civil liability for the breach of the terms and conditions of this
license.
THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*******************************************************************************/
//DOM-IGNORE-END
#ifndef USBGEN_H
#define USBGEN_H
#include <stdint.h>
#include "usb_config.h"
/** I N C L U D E S **********************************************************/
/** D E F I N I T I O N S ****************************************************/
/** S T R U C T U R E S ******************************************************/
/** E X T E R N S ************************************************************/
/** P U B L I C P R O T O T Y P E S *****************************************/
/********************************************************************
Function:
USB_HANDLE USBGenWrite(BYTE ep, BYTE* data, WORD len)
Summary:
Sends the specified data out the specified endpoint
Description:
This function sends the specified data out the specified
endpoint and returns a handle to the transfer information.
Typical Usage:
<code>
//make sure that the last transfer isn't busy by checking the handle
if(!USBHandleBusy(USBGenericInHandle))
{
//Send the data contained in the INPacket[] array out on
// endpoint USBGEN_EP_NUM
USBGenericInHandle = USBGenWrite(USBGEN_EP_NUM,(BYTE*)&INPacket[0],sizeof(INPacket));
}
</code>
PreCondition:
None
Parameters:
BYTE ep - the endpoint you want to send the data out of
BYTE* data - pointer to the data that you wish to send
WORD len - the length of the data that you wish to send
Return Values:
USB_HANDLE - a handle for the transfer. This information
should be kept to track the status of the transfer
Remarks:
None
*******************************************************************/
#define USBGenWrite(ep,data,len) USBTxOnePacket(ep,data,len)
/********************************************************************
Function:
USB_HANDLE USBGenRead(BYTE ep, BYTE* data, WORD len)
Summary:
Receives the specified data out the specified endpoint
Description:
Receives the specified data out the specified endpoint.
Typical Usage:
<code>
//Read 64-bytes from endpoint USBGEN_EP_NUM, into the OUTPacket array.
// Make sure to save the return handle so that we can check it later
// to determine when the transfer is complete.
if(!USBHandleBusy(USBOutHandle))
{
USBOutHandle = USBGenRead(USBGEN_EP_NUM,(BYTE*)&OUTPacket,64);
}
</code>
PreCondition:
None
Parameters:
BYTE ep - the endpoint you want to receive the data into
BYTE* data - pointer to where the data will go when it arrives
WORD len - the length of the data that you wish to receive
Return Values:
USB_HANDLE - a handle for the transfer. This information
should be kept to track the status of the transfer
Remarks:
None
*******************************************************************/
#define USBGenRead(ep,data,len) USBRxOnePacket(ep,data,len)
/********************************************************************
Function:
void USBCheckVendorRequest(void)
Summary:
This routine handles vendor class specific requests that happen on EP0.
This function should be called from the USBCBCheckOtherReq() call back
function whenever implementing a custom/vendor class device.
Description:
This routine handles vendor specific requests that may arrive on EP0 as
a control transfer. These can include, but are not necessarily
limited to, requests for Microsft specific OS feature descriptor(s).
This function should be called from the USBCBCheckOtherReq() call back
function whenever using a vendor class device.
Typical Usage:
<code>
void USBCBCheckOtherReq(void)
{
//Since the stack didn't handle the request I need to check
// my class drivers to see if it is for them
USBCheckVendorRequest();
}
</code>
PreCondition:
None
Parameters:
Although this function has a void input, this handler function will
typically need to look at the 8-byte SETUP packet contents that the
host just sent, which may contain the vendor class specific request.
Therefore, the statically allocated SetupPkt structure may be looked
at while in the context of this function, and it will contain the most
recently received 8-byte SETUP packet data.
Return Values:
None
Remarks:
This function normally gets called within the same context as the
USBDeviceTasks() function, just after a new control transfer request
from the host has arrived. If the USB stack is operated in
USB_INTERRUPT mode (a usb_config.h option), then this function
will be executed in the interrupt context. If however the USB stack
is operated in the USB_POLLING mode, then this function executes in the
main loop context.
In order to respond to class specific control transfer request(s) in
this handler function, it is suggested to use one or more of the
USBEP0SendRAMPtr(), USBEP0SendROMPtr(), or USBEP0Receive() API
functions.
*******************************************************************/
void USBCheckVendorRequest(void);
#endif //USBGEN_H