Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBDevice.h Source File

USBDevice.h

00001 /* Copyright (c) 2010-2011 mbed.org, MIT License
00002 *
00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004 * and associated documentation files (the "Software"), to deal in the Software without
00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
00007 * Software is furnished to do so, subject to the following conditions:
00008 *
00009 * The above copyright notice and this permission notice shall be included in all copies or
00010 * substantial portions of the Software.
00011 *
00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017 */
00018 
00019 #ifndef USBDEVICE_H
00020 #define USBDEVICE_H
00021 
00022 // #include "mbed.h"
00023 #include "USBDevice_Types.h"
00024 #include "USBHAL.h"
00025 
00026 #include "../descriptor.h"
00027 
00028 class USBDevice: public USBHAL
00029 {
00030 public:
00031     USBDevice();
00032 
00033     bool configured(void);
00034 
00035     bool setDescriptors(usbdesc_base ** descriptors);
00036 
00037     void connect(void);
00038 
00039     void disconnect(void);
00040 
00041     bool addEndpoint(uint8_t endpoint, uint32_t maxPacket);
00042 
00043     bool readStart(uint8_t endpoint, uint32_t maxSize);
00044     bool readEP(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
00045     bool readEP_NB(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
00046 
00047     bool write(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
00048     bool writeNB(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
00049 
00050     virtual bool USBCallback_setConfiguration(uint8_t configuration) { return false; };
00051 
00052     virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate) { return false; };
00053 
00054 protected:
00055     virtual bool USBEvent_busReset(void);
00056 
00057     virtual void EP0setupCallback(void);
00058     virtual void EP0out(void);
00059     virtual void EP0in(void);
00060 
00061     virtual bool USBEvent_Frame(uint16_t);
00062 
00063     int  findDescriptorIndex(uint8_t start, uint8_t descriptorType, uint8_t descriptorIndex, uint8_t alternate);
00064     int  findDescriptorIndex(uint8_t descriptorType, uint8_t descriptorIndex);
00065     uint8_t * findDescriptor(uint8_t descriptorType, uint8_t descriptorIndex);
00066     uint8_t * findDescriptor(uint8_t descriptorType);
00067 
00068     CONTROL_TRANSFER * getTransferPtr(void);
00069 
00070     uint16_t VENDOR_ID;
00071     uint16_t PRODUCT_ID;
00072     uint16_t PRODUCT_RELEASE;
00073 
00074 private:
00075     bool addRateFeedbackEndpoint(uint8_t endpoint, uint32_t maxPacket);
00076     bool requestGetDescriptor(void);
00077     bool controlOut(void);
00078     bool controlIn(void);
00079     bool requestSetAddress(void);
00080     bool requestSetConfiguration(void);
00081     bool requestSetFeature(void);
00082     bool requestClearFeature(void);
00083     bool requestGetStatus(void);
00084     bool requestSetup(void);
00085     bool controlSetup(void);
00086     void decodeSetupPacket(uint8_t *data, SETUP_PACKET *packet);
00087     bool requestGetConfiguration(void);
00088     bool requestGetInterface(void);
00089     bool requestSetInterface(void);
00090     bool assembleConfigDescriptor(void);
00091 
00092     usbdesc_base **descriptors;
00093 
00094     volatile uint16_t lastFrameIndex;
00095 
00096     CONTROL_TRANSFER transfer;
00097     USB_DEVICE device;
00098 
00099     uint8_t control_buffer[64];
00100 
00101     uint16_t currentInterface;
00102     uint8_t currentAlternate;
00103 };
00104 
00105 
00106 #endif