- Timestamp:
- Apr 30, 2016, 11:29:25 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rtos_arduino/trunk/arduino_lib/hardware/arduino/samd/cores/arduino/USB/USBAPI.h
r136 r224 1 1 /* 2 Copyright (c) 201 2 Arduino. All right reserved.2 Copyright (c) 2015 Arduino LLC. All right reserved. 3 3 4 4 This library is free software; you can redistribute it and/or … … 16 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 17 */ 18 19 #ifndef __USBAPI__ 20 #define __USBAPI__ 21 22 23 /* Define attribute */ 24 #if defined ( __CC_ARM ) /* Keil uVision 4 */ 25 #define WEAK (__attribute__ ((weak))) 26 #elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */ 27 #define WEAK __weak 28 #elif defined ( __GNUC__ ) /* GCC CS */ 29 #define WEAK __attribute__ ((weak)) 30 #endif 31 18 /* 19 **Modified 04/04/2016 by Arduino.org development team 20 */ 21 22 #pragma once 23 24 #define WEAK __attribute__ ((weak)) 25 26 #define HSTPIPCFG_PTYPE_BLK 1 27 #define HSTPIPCFG_PTOKEN_IN 2 28 #define HSTPIPCFG_PTOKEN_OUT 3 29 #define HSTPIPCFG_PBK_1_BANK 4 30 #define HSTPIPCFG_PTYPE_INTRPT 5 31 32 #define EP0 0 33 #define EPX_SIZE 64 // 64 for Full Speed, EPT size max is 1024 32 34 33 35 #if defined __cplusplus … … 37 39 38 40 //================================================================================ 39 //================================================================================ 40 // USB 41 42 class USBDevice_ 43 { 44 public: 45 USBDevice_(); 41 // USB 42 //================================================================================ 43 //================================================================================ 44 // Low level API 45 typedef struct { 46 union { 47 uint8_t bmRequestType; 48 struct { 49 uint8_t direction : 5; 50 uint8_t type : 2; 51 uint8_t transferDirection : 1; 52 }; 53 }; 54 uint8_t bRequest; 55 uint8_t wValueL; 56 uint8_t wValueH; 57 uint16_t wIndex; 58 uint16_t wLength; 59 } Setup; 60 61 62 class USBDevice_ { 63 public: 64 USBDevice_() {}; 65 66 // USB Device API 67 void init(); 68 bool attach(); // Serial port goes down too... 69 bool detach(); 70 46 71 bool configured(); 47 72 48 bool attach(); 49 bool detach(); // Serial port goes down too... 50 void poll(); 51 void init(); 52 }; 73 private: 74 bool initialized; 75 }; 76 53 77 extern USBDevice_ USBDevice; 54 78 55 79 //================================================================================ 56 //================================================================================57 80 // Serial over CDC (Serial1 is the physical port) 58 81 59 82 class Serial_ : public Stream 60 83 { 61 private: 62 RingBuffer *_cdc_rx_buffer; 63 public: 84 public: 85 Serial_(USBDevice_ &_usb) : usb(_usb) { } 64 86 void begin(uint32_t baud_count); 65 87 void begin(unsigned long, uint8_t); … … 75 97 using Print::write; // pull in write(str) from Print 76 98 operator bool(); 99 100 // This method allows processing "SEND_BREAK" requests sent by 101 // the USB host. Those requests indicate that the host wants to 102 // send a BREAK signal and are accompanied by a single uint16_t 103 // value, specifying the duration of the break. The value 0 104 // means to end any current break, while the value 0xffff means 105 // to start an indefinite break. 106 // readBreak() will return the value of the most recent break 107 // request, but will return it at most once, returning -1 when 108 // readBreak() is called again (until another break request is 109 // received, which is again returned once). 110 // This also mean that if two break requests are received 111 // without readBreak() being called in between, the value of the 112 // first request is lost. 113 // Note that the value returned is a long, so it can return 114 // 0-0xffff as well as -1. 115 int32_t readBreak(); 116 117 // These return the settings specified by the USB host for the 118 // serial port. These aren't really used, but are offered here 119 // in case a sketch wants to act on these settings. 120 uint32_t baud(); 121 uint8_t stopbits(); 122 uint8_t paritytype(); 123 uint8_t numbits(); 124 bool dtr(); 125 bool rts(); 126 enum { 127 ONE_STOP_BIT = 0, 128 ONE_AND_HALF_STOP_BIT = 1, 129 TWO_STOP_BITS = 2, 130 }; 131 enum { 132 NO_PARITY = 0, 133 ODD_PARITY = 1, 134 EVEN_PARITY = 2, 135 MARK_PARITY = 3, 136 SPACE_PARITY = 4, 137 }; 138 139 private: 140 USBDevice_ &usb; 141 RingBuffer *_cdc_rx_buffer; 77 142 }; 78 143 extern Serial_ SerialUSB; … … 171 236 //================================================================================ 172 237 //================================================================================ 173 // Low level API174 175 typedef struct176 {177 uint8_t bmRequestType;178 uint8_t bRequest;179 uint8_t wValueL;180 uint8_t wValueH;181 uint16_t wIndex;182 uint16_t wLength;183 uint8_t data[8];184 } Setup;185 186 //================================================================================187 //================================================================================188 238 // HID 'Driver' 189 239 … … 202 252 uint32_t MSC_GetInterface(uint8_t* interfaceNum); 203 253 uint32_t MSC_GetDescriptor(uint32_t i); 204 bool MSC_Setup(Setup& setup);254 bool MSC_Setup(Setup& pSetup); 205 255 bool MSC_Data(uint8_t rx,uint8_t tx); 206 256 … … 209 259 // CDC 'Driver' 210 260 211 const void* CDC_GetInterface(/*uint8_t* interfaceNum*/); 212 uint32_t WEAK CDC_GetInterfaceLength(void); 261 int CDC_GetInterface(uint8_t* interfaceNum); 262 const void* _CDC_GetInterface(void); 263 uint32_t _CDC_GetInterfaceLength(void); 213 264 uint32_t CDC_GetOtherInterface(uint8_t* interfaceNum); 214 265 uint32_t CDC_GetDescriptor(uint32_t i); 215 bool CDC_Setup(Setup& setup); 216 217 //================================================================================ 218 //================================================================================ 219 220 uint32_t USBD_SendControl(uint8_t flags, const void* d, uint32_t len); 266 bool CDC_Setup(Setup& pSetup); 267 268 269 //================================================================================ 270 //================================================================================ 271 272 uint32_t USBD_SendControl(const void* _data, uint32_t len); 221 273 uint32_t USBD_RecvControl(void* d, uint32_t len); 274 void USBD_Calibrate(); 222 275 uint32_t USBD_SendInterfaces(void); 223 276 bool USBD_ClassInterfaceRequest(Setup& setup); … … 228 281 uint32_t USBD_Recv(uint32_t ep, void* data, uint32_t len); // non-blocking 229 282 uint32_t USBD_Recv(uint32_t ep); // non-blocking 283 uint8_t USBD_armRecv(uint32_t ep); 230 284 void USBD_Flush(uint32_t ep); 231 285 uint32_t USBD_Connected(void); 232 286 233 287 #endif // __cplusplus 234 #endif // __USBAPI__
Note:
See TracChangeset
for help on using the changeset viewer.