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 
47 
49 } usbStatus;
50 
51 
52 // ==== USB Device Functions ====
53 
57 extern usbStatus USBD_Initialize (int8_t device);
58 
62 extern usbStatus USBD_Uninitialize (int8_t device);
63 
67 extern usbStatus USBD_Connect (int8_t device);
68 
72 extern usbStatus USBD_Disconnect (int8_t device);
73 
78 extern bool USBD_Configured (int8_t device);
79 
80 
81 // ==== USB Device Custom Class Functions ====
82 
83 #ifdef __DOXYGEN__
84 
85 // following functions are available for each instance of a Custom class.
86 // generic prefix USBD_CustomClassn is USBD_CustomClassn for Custom class instance 0.
87 
91 
95 
99 
105 void USBD_CustomClassn_EventEndpointStart (uint8_t ep_addr);
106 
112 void USBD_CustomClassn_EventEndpointStop (uint8_t ep_addr);
113 
122 usbdRequestStatus USBD_CustomClassn_Endpoint0_SetupPacketReceived (const USB_SETUP_PACKET *setup_packet, uint8_t **buf, int32_t *len);
123 
127 void USBD_CustomClassn_Endpoint0_SetupPacketProcessed (const USB_SETUP_PACKET *setup_packet);
128 
136 usbdRequestStatus USBD_CustomClassn_Endpoint0_OutDataReceived (int32_t len);
137 
145 usbdRequestStatus USBD_CustomClassn_Endpoint0_InDataSent (int32_t len);
146 
151 void USBD_CustomClassn_Endpoint1_Event (ARM_USBD_EP_EVENT event);
152 void USBD_CustomClassn_Endpoint2_Event (ARM_USBD_EP_EVENT event);
153 void USBD_CustomClassn_Endpoint3_Event (ARM_USBD_EP_EVENT event);
154 void USBD_CustomClassn_Endpoint4_Event (ARM_USBD_EP_EVENT event);
155 void USBD_CustomClassn_Endpoint5_Event (ARM_USBD_EP_EVENT event);
156 void USBD_CustomClassn_Endpoint6_Event (ARM_USBD_EP_EVENT event);
157 void USBD_CustomClassn_Endpoint7_Event (ARM_USBD_EP_EVENT event);
158 void USBD_CustomClassn_Endpoint8_Event (ARM_USBD_EP_EVENT event);
159 void USBD_CustomClassn_Endpoint9_Event (ARM_USBD_EP_EVENT event);
160 void USBD_CustomClassn_Endpoint10_Event (ARM_USBD_EP_EVENT event);
161 void USBD_CustomClassn_Endpoint11_Event (ARM_USBD_EP_EVENT event);
162 void USBD_CustomClassn_Endpoint12_Event (ARM_USBD_EP_EVENT event);
163 void USBD_CustomClassn_Endpoint13_Event (ARM_USBD_EP_EVENT event);
164 void USBD_CustomClassn_Endpoint14_Event (ARM_USBD_EP_EVENT event);
165 void USBD_CustomClassn_Endpoint15_Event (ARM_USBD_EP_EVENT event);
166 
167 #endif // __DOXYGEN
168 
177 extern usbStatus USBD_EndpointRead (int8_t device, uint8_t ep_addr, uint8_t *buf, uint32_t len);
178 
185 extern uint32_t USBD_EndpointReadGetResult (int8_t device, const uint8_t ep_addr);
186 
195 extern usbStatus USBD_EndpointWrite (int8_t device, uint8_t ep_addr, const uint8_t *buf, uint32_t len);
196 
203 extern uint32_t USBD_EndpointWriteGetResult (int8_t device, const uint8_t ep_addr);
204 
212 extern usbStatus USBD_EndpointStall (int8_t device, uint8_t ep_addr, bool stall);
213 
220 extern usbStatus USBD_EndpointAbort (int8_t device, uint8_t ep_addr);
221 
222 
223 // ==== USB Device Audio Device Functions ====
224 
225 #ifdef __DOXYGEN__
226 
227 // following functions are available for each instance of a ADC class.
228 // generic prefix USBD_ADCn is USBD_ADC0 for ADC class instance 0.
229 
232 void USBD_ADCn_Initialize (void);
233 
236 void USBD_ADCn_Uninitialize (void);
237 
238 #endif // __DOXYGEN
239 
247 extern int32_t USBD_ADC_ReadSample (int8_t instance, void *buf, int32_t num);
248 
256 extern int32_t USBD_ADC_WriteSample (int8_t instance, const uint8_t *buf, int32_t num);
257 
258 
259 // ==== USB Device Communication Device (Abstract Control Model) Functions ====
260 
261 #ifdef __DOXYGEN__
262 
263 // following functions are available for each instance of a CDC class.
264 // generic prefix USBD_CDCn is USBD_CDC0 for CDC class instance 0.
265 
268 void USBD_CDCn_ACM_Initialize (void);
269 
272 void USBD_CDCn_ACM_Uninitialize (void);
273 
276 void USBD_CDCn_ACM_Reset (void);
277 
282 bool USBD_CDCn_ACM_SetLineCoding (CDC_LINE_CODING *line_coding);
283 
288 bool USBD_CDCn_ACM_GetLineCoding (CDC_LINE_CODING *line_coding);
289 
296 bool USBD_CDCn_ACM_SetControlLineState (uint16_t state);
297 
298 #endif // __DOXYGEN
299 
305 extern int USBD_CDC_ACM_GetChar (int8_t instance);
306 
313 extern int USBD_CDC_ACM_PutChar (int8_t instance, int ch);
314 
322 extern int32_t USBD_CDC_ACM_ReadData (int8_t instance, uint8_t *buf, int32_t len);
323 
331 extern int32_t USBD_CDC_ACM_WriteData (int8_t instance, const uint8_t *buf, int32_t len);
332 
337 extern int32_t USBD_CDC_ACM_DataAvailable (int8_t instance);
338 
350 extern usbStatus USBD_CDC_ACM_Notify (int8_t instance, uint16_t state);
351 
357 extern void USBD_CDC_ACM_DataReceived (int8_t instance, int32_t len);
358 
359 
360 // ==== USB Device Human Interface Device Functions ====
361 
362 #ifdef __DOXYGEN__
363 
364 // following functions are available for each instance of a HID class.
365 // generic prefix USBD_HIDn is USBD_HID0 for HID class instance 0.
366 
369 void USBD_HIDn_Initialize (void);
370 
373 void USBD_HIDn_Uninitialize (void);
374 
388 int32_t USBD_HIDn_GetReport (uint8_t rtype, uint8_t req, uint8_t rid, uint8_t *buf);
389 
402 bool USBD_HIDn_SetReport (uint8_t rtype, uint8_t req, uint8_t rid, const uint8_t *buf, int32_t len);
403 
404 #endif // __DOXYGEN
405 
412 extern usbStatus USBD_HID_GetReportTrigger (int8_t instance, uint8_t rid, const uint8_t *buf, int32_t len);
413 
414 
415 #ifdef __DOXYGEN__
416 
417 // ==== USB Device Mass Storage Device Functions ====
418 
419 // following functions are available for each instance of a MSC class.
420 // generic prefix USBD_MSCn is USBD_MSC0 for MSC class instance 0.
421 
424 void USBD_MSCn_Initialize (void);
425 
428 void USBD_MSCn_Uninitialize (void);
429 
436 bool USBD_MSCn_Read (uint32_t lba, uint16_t cnt, uint8_t *buf);
437 
444 bool USBD_MSCn_Write (uint32_t lba, uint16_t cnt, const uint8_t *buf);
445 
446 #endif // __DOXYGEN
447 
448 
449 // ==== USB Host Functions ====
450 
454 extern usbStatus USBH_Initialize (uint8_t ctrl);
455 
459 extern usbStatus USBH_Uninitialize (uint8_t ctrl);
460 
464 extern usbStatus USBH_GetDeviceStatus (int8_t device);
465 
466 
467 // ==== USB Host Mass Storage Functions ====
468 
472 extern usbStatus USBH_MSC_GetDeviceStatus (int8_t instance);
473 
480 extern usbStatus USBH_MSC_Read (int8_t instance, uint32_t lba, uint16_t cnt, uint8_t *buf);
481 
488 extern usbStatus USBH_MSC_Write (int8_t instance, uint32_t lba, uint16_t cnt, const uint8_t *buf);
489 
495 extern usbStatus USBH_MSC_ReadCapacity (int8_t instance, uint32_t *block_count, uint32_t *block_size);
496 
497 
498 // ==== USB Host Human Interface Device Functions ====
499 
503 extern usbStatus USBH_HID_GetDeviceStatus (int8_t instance);
504 
512 extern int32_t USBH_HID_Read (int8_t instance, uint8_t *buf, int32_t len);
513 
521 extern int32_t USBH_HID_Write (int8_t instance, const uint8_t *buf, int32_t len);
522 
528 extern int USBH_HID_GetKeyboardKey (int8_t instance);
529 
531 typedef struct _usbHID_MouseState {
532  uint8_t button;
533  int16_t x;
534  int16_t y;
536 
541 extern usbStatus USBH_HID_GetMouseState (int8_t instance, usbHID_MouseState *state);
542 
543 
544 #ifdef __cplusplus
545 }
546 #endif
547 
548 #endif