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 
197 
198 extern usbStatus USBD_EndpointStall (int8_t device, uint8_t ep_addr, bool stall);
199 
204 
205 extern usbStatus USBD_EndpointAbort (int8_t device, uint8_t ep_addr);
206 
207 
208 // ==== USB Device Audio Device Functions ====
209 
210 #ifdef __DOXYGEN__
211 
212 // following functions are available for each instance of a ADC class.
213 // generic prefix USBD_ADCn is USBD_ADC0 for ADC class instance 0.
214 
217 void USBD_ADCn_Initialize (void);
218 
221 void USBD_ADCn_Uninitialize (void);
222 
223 #endif // __DOXYGEN
224 
232 extern int32_t USBD_ADC_ReadSample (int8_t instance, void *buf, int32_t num);
233 
241 extern int32_t USBD_ADC_WriteSample (int8_t instance, const uint8_t *buf, int32_t num);
242 
243 
244 // ==== USB Device Communication Device (Abstract Control Model) Functions ====
245 
246 #ifdef __DOXYGEN__
247 
248 // following functions are available for each instance of a CDC class.
249 // generic prefix USBD_CDCn is USBD_CDC0 for CDC class instance 0.
250 
253 void USBD_CDCn_ACM_Initialize (void);
254 
257 void USBD_CDCn_ACM_Uninitialize (void);
258 
261 void USBD_CDCn_ACM_Reset (void);
262 
267 bool USBD_CDCn_ACM_SetLineCoding (CDC_LINE_CODING *line_coding);
268 
273 bool USBD_CDCn_ACM_GetLineCoding (CDC_LINE_CODING *line_coding);
274 
281 bool USBD_CDCn_ACM_SetControlLineState (uint16_t state);
282 
283 #endif // __DOXYGEN
284 
290 extern int USBD_CDC_ACM_GetChar (int8_t instance);
291 
298 extern int USBD_CDC_ACM_PutChar (int8_t instance, int ch);
299 
307 extern int32_t USBD_CDC_ACM_ReadData (int8_t instance, uint8_t *buf, int32_t len);
308 
316 extern int32_t USBD_CDC_ACM_WriteData (int8_t instance, const uint8_t *buf, int32_t len);
317 
322 extern int32_t USBD_CDC_ACM_DataAvailable (int8_t instance);
323 
335 extern usbStatus USBD_CDC_ACM_Notify (int8_t instance, uint16_t state);
336 
342 extern void USBD_CDC_ACM_DataReceived (int8_t instance, int32_t len);
343 
344 
345 // ==== USB Device Human Interface Device Functions ====
346 
347 #ifdef __DOXYGEN__
348 
349 // following functions are available for each instance of a HID class.
350 // generic prefix USBD_HIDn is USBD_HID0 for HID class instance 0.
351 
354 void USBD_HIDn_Initialize (void);
355 
358 void USBD_HIDn_Uninitialize (void);
359 
373 int32_t USBD_HIDn_GetReport (uint8_t rtype, uint8_t req, uint8_t rid, uint8_t *buf);
374 
387 bool USBD_HIDn_SetReport (uint8_t rtype, uint8_t req, uint8_t rid, const uint8_t *buf, int32_t len);
388 
389 #endif // __DOXYGEN
390 
397 extern usbStatus USBD_HID_GetReportTrigger (int8_t instance, uint8_t rid, const uint8_t *buf, int32_t len);
398 
399 
400 #ifdef __DOXYGEN__
401 
402 // ==== USB Device Mass Storage Device Functions ====
403 
404 // following functions are available for each instance of a MSC class.
405 // generic prefix USBD_MSCn is USBD_MSC0 for MSC class instance 0.
406 
409 void USBD_MSCn_Initialize (void);
410 
413 void USBD_MSCn_Uninitialize (void);
414 
421 bool USBD_MSCn_Read (uint32_t lba, uint16_t cnt, uint8_t *buf);
422 
429 bool USBD_MSCn_Write (uint32_t lba, uint16_t cnt, const uint8_t *buf);
430 
431 #endif // __DOXYGEN
432 
433 
434 // ==== USB Host Functions ====
435 
439 extern usbStatus USBH_Initialize (uint8_t ctrl);
440 
444 extern usbStatus USBH_Uninitialize (uint8_t ctrl);
445 
449 extern usbStatus USBH_GetDeviceStatus (int8_t device);
450 
451 
452 // ==== USB Host Mass Storage Functions ====
453 
457 extern usbStatus USBH_MSC_GetDeviceStatus (int8_t instance);
458 
465 extern usbStatus USBH_MSC_Read (int8_t instance, uint32_t lba, uint16_t cnt, uint8_t *buf);
466 
473 extern usbStatus USBH_MSC_Write (int8_t instance, uint32_t lba, uint16_t cnt, const uint8_t *buf);
474 
480 extern usbStatus USBH_MSC_ReadCapacity (int8_t instance, uint32_t *block_count, uint32_t *block_size);
481 
482 
483 // ==== USB Host Human Interface Device Functions ====
484 
488 extern usbStatus USBH_HID_GetDeviceStatus (int8_t instance);
489 
497 extern int32_t USBH_HID_Read (int8_t instance, uint8_t *buf, int32_t len);
498 
506 extern int32_t USBH_HID_Write (int8_t instance, const uint8_t *buf, int32_t len);
507 
513 extern int USBH_HID_GetKeyboardKey (int8_t instance);
514 
516 typedef struct _usbHID_MouseState {
517  uint8_t button;
518  int16_t x;
519  int16_t y;
521 
526 extern usbStatus USBH_HID_GetMouseState (int8_t instance, usbHID_MouseState *state);
527 
528 
529 #ifdef __cplusplus
530 }
531 #endif
532 
533 #endif