]> begriffs open source - cmsis-freertos/blob - Demo/CORTEX_LPC1768_IAR/LPCUSB/usbapi.h
osEventFlagsWait: Fix flag comparison
[cmsis-freertos] / Demo / CORTEX_LPC1768_IAR / LPCUSB / usbapi.h
1 /*
2         LPCUSB, an USB device driver for LPC microcontrollers   
3         Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl)
4
5         Redistribution and use in source and binary forms, with or without
6         modification, are permitted provided that the following conditions are met:
7
8         1. Redistributions of source code must retain the above copyright
9            notice, this list of conditions and the following disclaimer.
10         2. Redistributions in binary form must reproduce the above copyright
11            notice, this list of conditions and the following disclaimer in the
12            documentation and/or other materials provided with the distribution.
13         3. The name of the author may not be used to endorse or promote products
14            derived from this software without specific prior written permission.
15
16         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 
20         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 /**
29         @file
30 */
31
32 #include "usbstruct.h"          // for TSetupPacket
33
34 /*************************************************************************
35         USB configuration
36 **************************************************************************/
37
38 #define MAX_PACKET_SIZE0        64              /**< maximum packet size for EP 0 */
39
40 /*************************************************************************
41         USB hardware interface
42 **************************************************************************/
43
44 // endpoint status sent through callback
45 #define EP_STATUS_DATA          (1<<0)          /**< EP has data */
46 #define EP_STATUS_STALLED       (1<<1)          /**< EP is stalled */
47 #define EP_STATUS_SETUP         (1<<2)          /**< EP received setup packet */
48 #define EP_STATUS_ERROR         (1<<3)          /**< EP data was overwritten by setup packet */
49 #define EP_STATUS_NACKED        (1<<4)          /**< EP sent NAK */
50
51 // device status sent through callback
52 #define DEV_STATUS_CONNECT              (1<<0)  /**< device just got connected */
53 #define DEV_STATUS_SUSPEND              (1<<2)  /**< device entered suspend state */
54 #define DEV_STATUS_RESET                (1<<4)  /**< device just got reset */
55
56 // interrupt bits for NACK events in USBHwNakIntEnable
57 // (these bits conveniently coincide with the LPC176x USB controller bit)
58 #define INACK_CI                (1<<1)                  /**< interrupt on NACK for control in */
59 #define INACK_CO                (1<<2)                  /**< interrupt on NACK for control out */
60 #define INACK_II                (1<<3)                  /**< interrupt on NACK for interrupt in */
61 #define INACK_IO                (1<<4)                  /**< interrupt on NACK for interrupt out */
62 #define INACK_BI                (1<<5)                  /**< interrupt on NACK for bulk in */
63 #define INACK_BO                (1<<6)                  /**< interrupt on NACK for bulk out */
64
65 BOOL USBHwInit                  (void);
66 void USBHwISR                   (void);
67
68 void USBHwNakIntEnable  (unsigned char bIntBits);
69
70 void USBHwConnect               (BOOL fConnect);
71
72 void USBHwSetAddress    (unsigned char bAddr);
73 void USBHwConfigDevice  (BOOL fConfigured);
74
75 // endpoint operations
76 void USBHwEPConfig              (unsigned char bEP, unsigned short wMaxPacketSize);
77 int  USBHwEPRead                (unsigned char bEP, unsigned char *pbBuf, int iMaxLen);
78 int      USBHwEPWrite           (unsigned char bEP, unsigned char *pbBuf, int iLen);
79 void USBHwEPStall               (unsigned char bEP, BOOL fStall);
80 unsigned char   USBHwEPGetStatus        (unsigned char bEP);
81
82 /** Endpoint interrupt handler callback */
83 typedef void (TFnEPIntHandler)  (unsigned char bEP, unsigned char bEPStatus);
84 void USBHwRegisterEPIntHandler  (unsigned char bEP, TFnEPIntHandler *pfnHandler);
85
86 /** Device status handler callback */
87 typedef void (TFnDevIntHandler) (unsigned char bDevStatus);
88 void USBHwRegisterDevIntHandler (TFnDevIntHandler *pfnHandler);
89
90 /** Frame event handler callback */
91 typedef void (TFnFrameHandler)(unsigned short wFrame);
92 void USBHwRegisterFrameHandler(TFnFrameHandler *pfnHandler);
93
94
95 /*************************************************************************
96         USB application interface
97 **************************************************************************/
98
99 // initialise the complete stack, including HW
100 BOOL USBInit(void);
101
102 /** Request handler callback (standard, vendor, class) */
103 typedef BOOL (TFnHandleRequest)(TSetupPacket *pSetup, int *piLen, unsigned char **ppbData);
104 void USBRegisterRequestHandler(int iType, TFnHandleRequest *pfnHandler, unsigned char *pbDataStore);
105 void USBRegisterCustomReqHandler(TFnHandleRequest *pfnHandler);
106
107 /** Descriptor handler callback */
108 typedef BOOL (TFnGetDescriptor)(unsigned short wTypeIndex, unsigned short wLangID, int *piLen, unsigned char **ppbData);
109
110 /** Default standard request handler */
111 BOOL USBHandleStandardRequest(TSetupPacket *pSetup, int *piLen, unsigned char **ppbData);
112
113 /** Default EP0 handler */
114 void USBHandleControlTransfer(unsigned char bEP, unsigned char bEPStat);
115
116 /** Descriptor handling */
117 void USBRegisterDescriptors(const unsigned char *pabDescriptors);
118 BOOL USBGetDescriptor(unsigned short wTypeIndex, unsigned short wLangID, int *piLen, unsigned char **ppbData);