| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
usbd_api.h
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------
2 * U S B - K e r n e l
3 *----------------------------------------------------------------------------
4 * Name: mw_usbd_api.h
5 * Purpose: USB Custom Configuration
6 * Version: V1.20
7 *----------------------------------------------------------------------------
8 * This software is supplied "AS IS" without any warranties, express,
9 * implied or statutory, including but not limited to the implied
10 * warranties of fitness for purpose, satisfactory quality and
11 * noninfringement. Keil extends you a royalty-free right to reproduce
12 * and distribute executable files created using this software for use
13 * on NXP ARM microcontroller devices only. Nothing else gives
14 * you the right to use this software.
15 *
16 * Copyright (c) 2005-2009 Keil Software.
17 * Adaption to LPCxxxx, Copyright (c) 2009 NXP.
18 *----------------------------------------------------------------------------*/
19
20 #include "error.h"
21 #include "mw_usbd.h"
22
23 #ifndef __MW_USBD_API_H__
24 #define __MW_USBD_API_H__
25
26 typedef void* USBD_HANDLE_T;
27 typedef void* USBD_HID_HANDLE_T;
28
29 /* function pointer types */
30 typedef ErrorCode_t (*USB_CB_T) (USBD_HANDLE_T hUsb);
31 typedef ErrorCode_t (*USB_PARAM_CB_T) (USBD_HANDLE_T hUsb, uint32_t event);
32 /* USBD setup request and endpoint event handler type */
33 typedef ErrorCode_t (*USB_EP_HANDLER_T)(USBD_HANDLE_T hUsb, void* data, uint32_t event);
34
35 /* USB descriptors data structure */
36 typedef struct _USB_CORE_DESCS_T
37 {
38 /* all pointers in this structure should be 4 byte aligned */
39 //ALIGNED(4)
40 uint8_t *device_desc;
41 uint8_t *string_desc;
42 uint8_t *full_speed_desc;
43 uint8_t *high_speed_desc;
44 uint8_t *device_qualifier;
45 } USB_CORE_DESCS_T;
46
47
48 /* Override functions */
49 typedef struct __USBD_OVERRIDES_T
50 {
51 USB_CB_T USB_EvtSetupHandler;
52 USB_CB_T USB_EvtOutHandler;
53 USB_CB_T USB_ReqGetStatus;
54 USB_CB_T USB_ReqGetDescriptor;
55 USB_CB_T USB_ReqGetConfiguration;
56 USB_CB_T USB_ReqSetConfiguration;
57 USB_CB_T USB_ReqGetInterface;
58 USB_CB_T USB_ReqSetInterface;
59 USB_PARAM_CB_T USB_ReqSetClrFeature;
60 USB_PARAM_CB_T USB_ReqVendor;
61 } USBD_OVERRIDES_T;
62
63
64 typedef struct __USBD_API_INIT_PARAM_T
65 {
66 uint32_t usb_reg_base;
67 uint32_t mem_base;
68 uint32_t mem_size;
69 uint8_t max_num_ep; /* max number of endpoints supported by the HW */
70
71 /* USB Device Events Callback Functions */
72 USB_CB_T USB_Reset_Event;
73 USB_CB_T USB_Suspend_Event;
74 USB_CB_T USB_Resume_Event;
75 USB_CB_T USB_WakeUp_Event;
76 USB_CB_T USB_SOF_Event;
77 /*0 - Clear, 1 - Set*/
78 USB_PARAM_CB_T USB_WakeUpCfg;
79 USB_PARAM_CB_T USB_Power_Event;
80 USB_PARAM_CB_T USB_Error_Event;
81
82 /* USB Core Events Callback Functions */
83 USB_CB_T USB_Configure_Event;
84 USB_CB_T USB_Interface_Event;
85 USB_CB_T USB_Feature_Event;
86
87 /* cache and mmu translation functions */
88 uint32_t (* virt_to_phys)(void* vaddr);
89 void (* cache_flush)(uint32_t* start_adr, uint32_t* end_adr);
90
91 } USBD_API_INIT_PARAM_T;
92
93 //#include "mw_usbd/mw_usbd_hw.h" Batjo
94 #include "mw_usbd_hw.h"
95
96 /* midleware API */
97 extern ErrorCode_t mwUSB_RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);
98 extern ErrorCode_t mwUSB_RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);
99 extern void mwUSB_SetupStage (USBD_HANDLE_T hUsb);
100 extern void mwUSB_DataInStage(USBD_HANDLE_T hUsb);
101 extern void mwUSB_DataOutStage(USBD_HANDLE_T hUsb);
102 extern void mwUSB_StatusInStage(USBD_HANDLE_T hUsb);
103 extern void mwUSB_StatusOutStage(USBD_HANDLE_T hUsb);
104 extern void mwUSB_StallEp0(USBD_HANDLE_T hUsb);
105
106
107 /************************************************************
108 * Mass Storage API structures and function prototypes
109 ************************************************************/
110 typedef struct __USBD_MSC_INIT_PARAM_T
111 {
112 /* memory allocation params */
113 uint32_t mem_base;
114 uint32_t mem_size;
115 /* mass storage paramas */
116 uint8_t* InquiryStr; /* Data pointed by the pointer should be of global scope. */
117 uint32_t BlockCount;
118 uint32_t BlockSize;
119 uint32_t MemorySize;
120 /* Pointer to the interface descriptor within the descriptor
121 * array passed to USBD_Init(). Assumes both HS and FS use same
122 * BULK endpoints. Also the mwMSC_init() assumes that both BULK_IN
123 * and BULK_OUT endpoints have same number. If different the EP_ISR
124 * handlers should be installed manual by user code.
125 */
126 uint8_t* intf_desc;
127 /* user defined functions */
128 void (*MSC_Write)( uint32_t offset, uint8_t** src, uint32_t length);
129 void (*MSC_Read)( uint32_t offset, uint8_t** dst, uint32_t length);
130 ErrorCode_t (*MSC_Verify)( uint32_t offset, uint8_t dst[], uint32_t length);
131 /* optional call back for MSC_Write optimization */
132 void (*MSC_GetWriteBuf)( uint32_t offset, uint8_t** buff_adr, uint32_t length);
133 /* user overridable function */
134 ErrorCode_t (*MSC_Ep0_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
135
136 } USBD_MSC_INIT_PARAM_T;
137
138 extern uint32_t mwMSC_GetMemSize(USBD_MSC_INIT_PARAM_T* param);
139 extern ErrorCode_t mwMSC_init(USBD_HANDLE_T hUsb, USBD_MSC_INIT_PARAM_T* param);
140
141 /************************************************************
142 * Device Firmware Upgrade (DFU) API structures and function prototypes
143 ************************************************************/
144 typedef struct __USBD_DFU_INIT_PARAM_T
145 {
146 /* memory allocation params */
147 uint32_t mem_base;
148 uint32_t mem_size;
149 /* DFU paramas */
150 uint16_t wTransferSize;
151
152 /* Pointer to the interface descriptor within the descriptor
153 * array passed to USBD_Init().
154 */
155 uint8_t* intf_desc;
156 /* user defined functions */
157 /* return DFU_STATUS_ values defined in mw_usbd_dfu.h */
158 uint8_t (*DFU_Write)( uint32_t block_num, uint8_t** src, uint32_t length);
159 /* return
160 * DFU_STATUS_ : values defined in mw_usbd_dfu.h in case of errors
161 * 0 : If end of memory reached
162 * length : Amount of data copied to destination buffer
163 */
164 uint32_t (*DFU_Read)( uint32_t block_num, uint8_t** dst, uint32_t length);
165 /* callback called after download is finished */
166 void (*DFU_Done)(void);
167 /* callback called after USB_REQ_DFU_DETACH is recived */
168 void (*DFU_Detach)(USBD_HANDLE_T hUsb);
169
170 /* user overridable function */
171 ErrorCode_t (*DFU_Ep0_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
172
173 } USBD_DFU_INIT_PARAM_T;
174
175 uint32_t mwDFU_GetMemSize(USBD_DFU_INIT_PARAM_T* param);
176 extern ErrorCode_t mwDFU_init(USBD_HANDLE_T hUsb, USBD_DFU_INIT_PARAM_T* param);
177
178 /************************************************************
179 * Human Interface Device (HID) API structures and function prototypes
180 ************************************************************/
181 typedef struct _HID_REPORT_T {
182 uint16_t len;
183 uint8_t idle_time;
184 uint8_t __pad;
185 uint8_t* desc;
186 } USB_HID_REPORT_T;
187
188 typedef struct __USBD_HID_INIT_PARAM_T
189 {
190 /* memory allocation params */
191 uint32_t mem_base;
192 uint32_t mem_size;
193 /* HID paramas */
194 uint8_t max_reports;
195
196 /* Pointer to the interface descriptor within the descriptor
197 * array passed to USBD_Init().
198 */
199 uint8_t* intf_desc;
200 USB_HID_REPORT_T* report_data;
201
202 /* user defined functions */
203 /* required functions */
204 ErrorCode_t (*HID_GetReport)( USBD_HID_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t* length);
205 ErrorCode_t (*HID_SetReport)( USBD_HID_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t length);
206 /* optional functions */
207 ErrorCode_t (*HID_GetPhysDesc)( USBD_HID_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuf, uint16_t* length);
208 ErrorCode_t (*HID_SetIdle)( USBD_HID_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t idleTime);
209 ErrorCode_t (*HID_SetProtocol)( USBD_HID_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t protocol);
210 ErrorCode_t (*HID_EpIn_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
211 ErrorCode_t (*HID_EpOut_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
212
213 /* user overridable function */
214 ErrorCode_t (*HID_GetReportDesc)(USBD_HID_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuf, uint16_t* length);
215 ErrorCode_t (*HID_Ep0_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
216
217 } USBD_HID_INIT_PARAM_T;
218
219 extern uint32_t mwHID_GetMemSize(USBD_HID_INIT_PARAM_T* param);
220 extern ErrorCode_t mwHID_init(USBD_HANDLE_T hUsb, USBD_HID_INIT_PARAM_T* param);
221
222 #endif /* __MW_USBD_API_H__ */