USB Component  Version 5.1
MDK-Professional Middleware for USB Device and Host
 All Data Structures Functions Variables Enumerations Enumerator Groups Pages
rl_usb.h
1 /*------------------------------------------------------------------------------
2  * MDK Middleware - Component ::USB
3  * Copyright (c) 2004-2013 ARM Germany GmbH. All rights reserved.
4  *------------------------------------------------------------------------------
5  * Name: rl_usb.h
6  * Purpose: USB User API
7  * Rev.: V5.10
8  *----------------------------------------------------------------------------*/
9 
10 #ifndef __RL_USB_H__
11 #define __RL_USB_H__
12 
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 #include <stdint.h>
19 #include <stdbool.h>
20 
21 
22 // ==== USB Constants and Defines ====
23 
25 typedef enum {
26  usbOK = 0,
27 
30 
31  usbThreadError = 0x10,
34 
46 
48 } usbStatus;
49 
50 
51 // ==== USB Device Functions ====
52 
56 extern usbStatus USBD_Initialize (int8_t device);
57 
61 extern usbStatus USBD_Uninitialize (int8_t device);
62 
66 extern usbStatus USBD_Connect (int8_t device);
67 
71 extern usbStatus USBD_Disconnect (int8_t device);
72 
77 extern bool USBD_Configured (int8_t device);
78 
79 
80 // ==== USB Device Custom Class Functions ====
81 
82 #ifdef __DOXYGEN__
83 
84 // following functions are available for each instance of a Custom class.
85 // generic prefix USBD_CustomClassn is USBD_CustomClassn for Custom class instance 0.
86 
90 
94 
98 
102 void USBD_CustomClassn_EventEndpointStart (uint8_t ep_addr);
103 
107 void USBD_CustomClassn_EventEndpointStop (uint8_t ep_addr);
108 
117 usbdRequestStatus USBD_CustomClassn_Endpoint0_SetupPacketReceived (const USB_SETUP_PACKET *setup_packet, uint8_t **buf, int32_t *len);
118 
122 void USBD_CustomClassn_Endpoint0_SetupPacketProcessed (const USB_SETUP_PACKET *setup_packet);
123 
131 usbdRequestStatus USBD_CustomClassn_Endpoint0_OutDataReceived (int32_t len);
132 
140 usbdRequestStatus USBD_CustomClassn_Endpoint0_InDataSent (int32_t len);
141 
146 void USBD_CustomClassn_Endpoint1_Event (ARM_USBD_EP_EVENT event);
147 void USBD_CustomClassn_Endpoint2_Event (ARM_USBD_EP_EVENT event);
148 void USBD_CustomClassn_Endpoint3_Event (ARM_USBD_EP_EVENT event);
149 void USBD_CustomClassn_Endpoint4_Event (ARM_USBD_EP_EVENT event);
150 void USBD_CustomClassn_Endpoint5_Event (ARM_USBD_EP_EVENT event);
151 void USBD_CustomClassn_Endpoint6_Event (ARM_USBD_EP_EVENT event);
152 void USBD_CustomClassn_Endpoint7_Event (ARM_USBD_EP_EVENT event);
153 void USBD_CustomClassn_Endpoint8_Event (ARM_USBD_EP_EVENT event);
154 void USBD_CustomClassn_Endpoint9_Event (ARM_USBD_EP_EVENT event);
155 void USBD_CustomClassn_Endpoint10_Event (ARM_USBD_EP_EVENT event);
156 void USBD_CustomClassn_Endpoint11_Event (ARM_USBD_EP_EVENT event);
157 void USBD_CustomClassn_Endpoint12_Event (ARM_USBD_EP_EVENT event);
158 void USBD_CustomClassn_Endpoint13_Event (ARM_USBD_EP_EVENT event);
159 void USBD_CustomClassn_Endpoint14_Event (ARM_USBD_EP_EVENT event);
160 void USBD_CustomClassn_Endpoint15_Event (ARM_USBD_EP_EVENT event);
161 
162 #endif // __DOXYGEN
163 
170 extern usbStatus USBD_EndpointReadStart (int8_t device, uint8_t ep_addr, uint8_t *buf, uint32_t len);
171 
180 extern int32_t USBD_EndpointRead (int8_t device, uint8_t ep_addr, uint8_t *buf, uint32_t len);
181 
190 extern int32_t USBD_EndpointWrite (int8_t device, uint8_t ep_addr, const uint8_t *buf, uint32_t len);
191 
192 
193 // ==== USB Device Audio Device Functions ====
194 
195 #ifdef __DOXYGEN__
196 
197 // following functions are available for each instance of a ADC class.
198 // generic prefix USBD_ADCn is USBD_ADC0 for ADC class instance 0.
199 
202 void USBD_ADCn_Initialize (void);
203 
206 void USBD_ADCn_Uninitialize (void);
207 
208 #endif // __DOXYGEN
209 
217 extern int32_t USBD_ADC_ReadSample (int8_t instance, void *buf, int32_t num);
218 
226 extern int32_t USBD_ADC_WriteSample (int8_t instance, const uint8_t *buf, int32_t num);
227 
228 
229 // ==== USB Device Communication Device (Abstract Control Model) Functions ====
230 
231 #ifdef __DOXYGEN__
232 
233 // following functions are available for each instance of a CDC class.
234 // generic prefix USBD_CDCn is USBD_CDC0 for CDC class instance 0.
235 
238 void USBD_CDCn_ACM_Initialize (void);
239 
242 void USBD_CDCn_ACM_Uninitialize (void);
243 
246 void USBD_CDCn_ACM_Reset (void);
247 
252 bool USBD_CDCn_ACM_SetLineCoding (CDC_LINE_CODING *line_coding);
253 
258 bool USBD_CDCn_ACM_GetLineCoding (CDC_LINE_CODING *line_coding);
259 
266 bool USBD_CDCn_ACM_SetControlLineState (uint16_t state);
267 
268 #endif // __DOXYGEN
269 
275 extern int USBD_CDC_ACM_GetChar (int8_t instance);
276 
283 extern int USBD_CDC_ACM_PutChar (int8_t instance, int ch);
284 
292 extern int32_t USBD_CDC_ACM_ReadData (int8_t instance, uint8_t *buf, int32_t len);
293 
301 extern int32_t USBD_CDC_ACM_WriteData (int8_t instance, const uint8_t *buf, int32_t len);
302 
307 extern int32_t USBD_CDC_ACM_DataAvailable (int8_t instance);
308 
320 extern usbStatus USBD_CDC_ACM_Notify (int8_t instance, uint16_t state);
321 
327 extern void USBD_CDC_ACM_DataReceived (int8_t instance, int32_t len);
328 
329 
330 // ==== USB Device Human Interface Device Functions ====
331 
332 #ifdef __DOXYGEN__
333 
334 // following functions are available for each instance of a HID class.
335 // generic prefix USBD_HIDn is USBD_HID0 for HID class instance 0.
336 
339 void USBD_HIDn_Initialize (void);
340 
343 void USBD_HIDn_Uninitialize (void);
344 
358 int32_t USBD_HIDn_GetReport (uint8_t rtype, uint8_t req, uint8_t rid, uint8_t *buf);
359 
372 bool USBD_HIDn_SetReport (uint8_t rtype, uint8_t req, uint8_t rid, const uint8_t *buf, int32_t len);
373 
374 #endif // __DOXYGEN
375 
382 extern usbStatus USBD_HID_GetReportTrigger (int8_t instance, uint8_t rid, const uint8_t *buf, int32_t len);
383 
384 
385 #ifdef __DOXYGEN__
386 
387 // ==== USB Device Mass Storage Device Functions ====
388 
389 // following functions are available for each instance of a MSC class.
390 // generic prefix USBD_MSCn is USBD_MSC0 for MSC class instance 0.
391 
394 void USBD_MSCn_Initialize (void);
395 
398 void USBD_MSCn_Uninitialize (void);
399 
406 bool USBD_MSCn_Read (uint32_t lba, uint16_t cnt, uint8_t *buf);
407 
414 bool USBD_MSCn_Write (uint32_t lba, uint16_t cnt, const uint8_t *buf);
415 
416 #endif // __DOXYGEN
417 
418 
419 // ==== USB Host Functions ====
420 
424 extern usbStatus USBH_Initialize (uint8_t ctrl);
425 
429 extern usbStatus USBH_Uninitialize (uint8_t ctrl);
430 
434 extern usbStatus USBH_GetDeviceStatus (int8_t device);
435 
436 
437 // ==== USB Host Mass Storage Functions ====
438 
442 extern usbStatus USBH_MSC_GetDeviceStatus (int8_t instance);
443 
450 extern usbStatus USBH_MSC_Read (int8_t instance, uint32_t lba, uint16_t cnt, uint8_t *buf);
451 
458 extern usbStatus USBH_MSC_Write (int8_t instance, uint32_t lba, uint16_t cnt, const uint8_t *buf);
459 
465 extern usbStatus USBH_MSC_ReadCapacity (int8_t instance, uint32_t *block_count, uint32_t *block_size);
466 
467 
468 // ==== USB Host Human Interface Device Functions ====
469 
473 extern usbStatus USBH_HID_GetDeviceStatus (int8_t instance);
474 
482 extern int32_t USBH_HID_Read (int8_t instance, uint8_t *buf, int32_t len);
483 
491 extern int32_t USBH_HID_Write (int8_t instance, const uint8_t *buf, int32_t len);
492 
498 extern int USBH_HID_GetKeyboardKey (int8_t instance);
499 
501 typedef struct _usbHID_MouseState {
502  uint8_t button;
503  int16_t x;
504  int16_t y;
506 
511 extern usbStatus USBH_HID_GetMouseState (int8_t instance, usbHID_MouseState *state);
512 
513 
514 #ifdef __cplusplus
515 }
516 #endif
517 
518 #endif