Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
USBDevice.h
00001 /* USBDevice.h */ 00002 /* Generic USB device */ 00003 /* Copyright (c) 2011 ARM Limited. All rights reserved. */ 00004 00005 #ifndef USBDEVICE_H 00006 #define USBDEVICE_H 00007 00008 #include "mbed.h" 00009 #include "USBDevice_Types.h" 00010 #include "USBBusInterface.h" 00011 00012 00013 00014 class USBDevice: public USBHAL 00015 { 00016 public: 00017 USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release); 00018 00019 /* 00020 * Check if the device is configured 00021 * 00022 * @returns true if configured, false otherwise 00023 */ 00024 bool configured(void); 00025 00026 /* 00027 * Connect a device 00028 */ 00029 void connect(void); 00030 00031 /* 00032 * Disconnect a device 00033 */ 00034 void disconnect(void); 00035 00036 /* 00037 * Add an endpoint 00038 * 00039 * @param endpoint endpoint which will be added 00040 * @param maxPacket Maximum size of a packet which can be sent for this endpoint 00041 * @returns true if successful, false otherwise 00042 */ 00043 bool addEndpoint(uint8_t endpoint, uint32_t maxPacket); 00044 00045 /* 00046 * Start a reading on a certain endpoint. 00047 * You can access the result of the reading by USBDevice_read 00048 * 00049 * @param endpoint endpoint which will be read 00050 * @param maxSize the maximum length that can be read 00051 * @return true if successful 00052 */ 00053 bool readStart(uint8_t endpoint, uint16_t maxSize); 00054 00055 /* 00056 * Read a certain endpoint. Before calling this function, USBUSBDevice_readStart 00057 * must be called. 00058 * 00059 * Warning: blocking 00060 * 00061 * @param endpoint endpoint which will be read 00062 * @param buffer buffer will be filled with the data received 00063 * @param size the number of bytes read will be stored in *size 00064 * @param maxSize the maximum length that can be read 00065 * @returns true if successful 00066 */ 00067 bool readEP(uint8_t endpoint, uint8_t * buffer, uint16_t * size, uint16_t maxSize); 00068 00069 /* 00070 * Read a certain endpoint. 00071 * 00072 * Warning: non blocking 00073 * 00074 * @param endpoint endpoint which will be read 00075 * @param buffer buffer will be filled with the data received (if data are available) 00076 * @param size the number of bytes read will be stored in *size 00077 * @param maxSize the maximum length that can be read 00078 * @returns true if successful 00079 */ 00080 bool readEP_NB(uint8_t endpoint, uint8_t * buffer, uint16_t * size, uint16_t maxSize); 00081 00082 /* 00083 * Write a certain endpoint. 00084 * 00085 * Warning: blocking 00086 * 00087 * @param endpoint endpoint to write 00088 * @param buffer data contained in buffer will be write 00089 * @param size the number of bytes to write 00090 * @param maxSize the maximum length that can be written on this endpoint 00091 */ 00092 bool write(uint8_t endpoint, uint8_t * buffer, uint16_t size, uint16_t maxSize); 00093 00094 00095 /* 00096 * Write a certain endpoint. 00097 * 00098 * Warning: non blocking 00099 * 00100 * @param endpoint endpoint to write 00101 * @param buffer data contained in buffer will be write 00102 * @param size the number of bytes to write 00103 * @param maxSize the maximum length that can be written on this endpoint 00104 */ 00105 bool writeNB(uint8_t endpoint, uint8_t * buffer, uint16_t size, uint16_t maxSize); 00106 00107 00108 /* 00109 * Called by USBDevice layer on bus reset. Warning: Called in ISR context 00110 * 00111 * May be used to reset state 00112 */ 00113 virtual void USBCallback_busReset(void) {}; 00114 00115 /* 00116 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context 00117 * This is used to handle extensions to standard requests 00118 * and class specific requests 00119 * 00120 * @returns true if class handles this request 00121 */ 00122 virtual bool USBCallback_request() { return false; }; 00123 00124 /* 00125 * Called by USBDevice on Endpoint0 request completion 00126 * if the 'notify' flag has been set to true. Warning: Called in ISR context 00127 * 00128 * In this case it is used to indicate that a HID report has 00129 * been received from the host on endpoint 0 00130 * 00131 * @param buf buffer received on endpoint 0 00132 * @param length length of this buffer 00133 */ 00134 virtual void USBCallback_requestCompleted(uint8_t * buf, uint16_t length) {}; 00135 00136 /* 00137 * Called by USBDevice layer. Set configuration of the device. 00138 * For instance, you can add all endpoints that you need on this function. 00139 * 00140 * @param configuration Number of the configuration 00141 */ 00142 virtual bool USBCallback_setConfiguration(uint8_t configuration) { return false; }; 00143 00144 /* 00145 * Called by USBDevice layer. Set interface/alternate of the device. 00146 * 00147 * @param interface Number of the interface to be configured 00148 * @param alternate Number of the alternate to be configured 00149 * @returns true if class handles this request 00150 */ 00151 virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate) { return false; }; 00152 00153 /* 00154 * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength. 00155 * 00156 * @returns pointer to the device descriptor 00157 */ 00158 virtual uint8_t * deviceDesc(); 00159 00160 /* 00161 * Get configuration descriptor 00162 * 00163 * @returns pointer to the configuration descriptor 00164 */ 00165 virtual uint8_t * configurationDesc(){return NULL;}; 00166 00167 /* 00168 * Get string lang id descriptor 00169 * 00170 * @return pointer to the string lang id descriptor 00171 */ 00172 virtual uint8_t * stringLangidDesc(); 00173 00174 /* 00175 * Get string manufacturer descriptor 00176 * 00177 * @returns pointer to the string manufacturer descriptor 00178 */ 00179 virtual uint8_t * stringImanufacturerDesc(); 00180 00181 /* 00182 * Get string product descriptor 00183 * 00184 * @returns pointer to the string product descriptor 00185 */ 00186 virtual uint8_t * stringIproductDesc(); 00187 00188 /* 00189 * Get string serial descriptor 00190 * 00191 * @returns pointer to the string serial descriptor 00192 */ 00193 virtual uint8_t * stringIserialDesc(); 00194 00195 /* 00196 * Get string configuration descriptor 00197 * 00198 * @returns pointer to the string configuration descriptor 00199 */ 00200 virtual uint8_t * stringIConfigurationDesc(); 00201 00202 /* 00203 * Get string interface descriptor 00204 * 00205 * @returns pointer to the string interface descriptor 00206 */ 00207 virtual uint8_t * stringIinterfaceDesc(); 00208 00209 /* 00210 * Get the length of the report descriptor 00211 * 00212 * @returns length of the report descriptor 00213 */ 00214 virtual uint16_t reportDescLength() { return 0; }; 00215 00216 00217 00218 protected: 00219 virtual void busReset(void); 00220 virtual void EP0setupCallback(void); 00221 virtual void EP0out(void); 00222 virtual void EP0in(void); 00223 virtual void connectStateChanged(unsigned int connected); 00224 virtual void suspendStateChanged(unsigned int suspended); 00225 uint8_t * findDescriptor(uint8_t descriptorType); 00226 CONTROL_TRANSFER * getTransferPtr(void); 00227 00228 uint16_t VENDOR_ID; 00229 uint16_t PRODUCT_ID; 00230 uint16_t PRODUCT_RELEASE; 00231 00232 private: 00233 bool addRateFeedbackEndpoint(uint8_t endpoint, uint32_t maxPacket); 00234 bool requestGetDescriptor(void); 00235 bool controlOut(void); 00236 bool controlIn(void); 00237 bool requestSetAddress(void); 00238 bool requestSetConfiguration(void); 00239 bool requestSetFeature(void); 00240 bool requestClearFeature(void); 00241 bool requestGetStatus(void); 00242 bool requestSetup(void); 00243 bool controlSetup(void); 00244 void decodeSetupPacket(uint8_t *data, SETUP_PACKET *packet); 00245 bool requestGetConfiguration(void); 00246 bool requestGetInterface(void); 00247 bool requestSetInterface(void); 00248 00249 CONTROL_TRANSFER transfer; 00250 USB_DEVICE device; 00251 00252 uint16_t currentInterface; 00253 uint8_t currentAlternate; 00254 }; 00255 00256 00257 #endif
Generated on Wed Jul 13 2022 13:59:01 by
1.7.2