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 USBHAL.h Source File

USBHAL.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 USBBUSINTERFACE_H
00020 #define USBBUSINTERFACE_H
00021 
00022 #include <stdint.h>
00023 
00024 // #include "mbed.h"
00025 #include "USBEndpoints.h"
00026 
00027 class USBHAL : public USB_State_Receiver, public USB_Frame_Receiver, public USB_Endpoint_Receiver {
00028 public:
00029     /* Configuration */
00030     USBHAL();
00031     ~USBHAL();
00032 
00033     void init(void);
00034 
00035     void connect(void);
00036     void disconnect(void);
00037     void configureDevice(void);
00038     void unconfigureDevice(void);
00039     void setAddress(uint8_t address);
00040     void remoteWakeup(void);
00041 
00042     /* Endpoint 0 */
00043     void EP0setup(uint8_t *buffer);
00044     void EP0read(void);
00045     uint32_t EP0getReadResult(uint8_t *buffer);
00046     void EP0write(uint8_t *buffer, uint32_t size);
00047     void EP0getWriteResult(void);
00048     void EP0stall(void);
00049 
00050     /* Other endpoints */
00051     EP_STATUS endpointRead(uint8_t bEP, uint32_t maximumSize);
00052     EP_STATUS endpointReadResult(uint8_t bEP, uint8_t *data, uint32_t *bytesRead);
00053     EP_STATUS endpointWrite(uint8_t bEP, uint8_t *data, uint32_t size);
00054     EP_STATUS endpointWriteResult(uint8_t bEP);
00055     uint8_t endpointStatus(uint8_t bEP);
00056     void stallEndpoint(uint8_t bEP);
00057     void unstallEndpoint(uint8_t bEP);
00058     bool realiseEndpoint(uint8_t bEP, uint32_t maxPacket, uint32_t options);
00059     bool getEndpointStallState(uint8_t bEP);
00060     uint32_t endpointReadcore(uint8_t bEP, uint8_t *buffer);
00061 
00062     uint16_t lastFrame(void);
00063 
00064     bool endpointSetInterrupt(uint8_t bEP, bool enabled);
00065     bool endpointGetInterrupt(uint8_t bEP);
00066     void endpointTriggerInterrupt(uint8_t bEP);
00067 
00068     /* misc hardware stuff */
00069     uint32_t getSerialNumber(int length, uint32_t *buf);
00070 
00071     static void _usbisr(void);
00072 
00073     void usbisr(void);
00074     static USBHAL * instance;
00075     uint8_t can_transfer[32];
00076 
00077 protected:
00078     virtual bool USBEvent_busReset(void){return false;};
00079     virtual bool USBEvent_connectStateChanged(bool connected){return false;};
00080     virtual bool USBEvent_suspendStateChanged(bool suspended){return false;};
00081 
00082     virtual bool USBEvent_Frame(uint16_t){return false;};
00083 
00084     virtual bool USBEvent_Request(CONTROL_TRANSFER&){return false;};
00085     virtual bool USBEvent_RequestComplete(CONTROL_TRANSFER&, uint8_t *, uint32_t){return false;};
00086 
00087     virtual bool USBEvent_EPIn(uint8_t, uint8_t){return false;};
00088     virtual bool USBEvent_EPOut(uint8_t, uint8_t){return false;};
00089 
00090     virtual void busReset(void){};
00091     virtual void EP0setupCallback(void){};
00092     virtual void EP0out(void){};
00093     virtual void EP0in(void){};
00094     virtual void connectStateChanged(unsigned int connected){};
00095     virtual void suspendStateChanged(unsigned int suspended){};
00096     virtual void SOF(int frameNumber){};
00097 };
00098 
00099 #endif