- Main Page
- Classes
- Files
- Related Pages

- File List
- File Members

# usbapi.h

Go to the documentation of this file.

    00001 /*
    00002         LPCUSB, an USB device driver for LPC microcontrollers
    00003         Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl)
    00004
    00005         Redistribution and use in source and binary forms, with or without
    00006         modification, are permitted provided that the following conditions are met:
    00007
    00008         1. Redistributions of source code must retain the above copyright
    00009            notice, this list of conditions and the following disclaimer.
    00010         2. Redistributions in binary form must reproduce the above copyright
    00011            notice, this list of conditions and the following disclaimer in the
    00012            documentation and/or other materials provided with the distribution.
    00013         3. The name of the author may not be used to endorse or promote products
    00014            derived from this software without specific prior written permission.
    00015
    00016         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    00017         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    00018         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    00019         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    00020         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    00021         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    00022         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    00023         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00024         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    00025         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00026 */
    00027
    00033 #include "type.h"
    00034 #include "usbstruct.h"          // for TSetupPacket
    00035
    00036 /*************************************************************************
    00037         USB configuration
    00038 **************************************************************************/
    00039
    00040 #define MAX_PACKET_SIZE0        64
    00042 /*************************************************************************
    00043         USB hardware interface
    00044 **************************************************************************/
    00045
    00046 // endpoint status sent through callback
    00047 #define EP_STATUS_DATA          (1<<0)
    00048 #define EP_STATUS_STALLED       (1<<1)
    00049 #define EP_STATUS_SETUP         (1<<2)
    00050 #define EP_STATUS_ERROR         (1<<3)
    00051 #define EP_STATUS_NACKED        (1<<4)
    00053 // device status sent through callback
    00054 #define DEV_STATUS_CONNECT              (1<<0)
    00055 #define DEV_STATUS_SUSPEND              (1<<2)
    00056 #define DEV_STATUS_RESET                (1<<4)
    00058 // interrupt bits for NACK events in USBHwNakIntEnable
    00059 // (these bits conveniently coincide with the LPC214x USB controller bit)
    00060 #define INACK_CI                (1<<1)
    00061 #define INACK_CO                (1<<2)
    00062 #define INACK_II                (1<<3)
    00063 #define INACK_IO                (1<<4)
    00064 #define INACK_BI                (1<<5)
    00065 #define INACK_BO                (1<<6)
    00067 BOOL USBHwInit                  (void);
    00068 void USBHwISR                   (void);
    00069
    00070 void USBHwNakIntEnable  (U8 bIntBits);
    00071
    00072 void USBHwConnect               (BOOL fConnect);
    00073
    00074 void USBHwSetAddress    (U8 bAddr);
    00075 void USBHwConfigDevice  (BOOL fConfigured);
    00076
    00077 // endpoint operations
    00078 void USBHwEPConfig              (U8 bEP, U16 wMaxPacketSize);
    00079 int  USBHwEPRead                (U8 bEP, U8 *pbBuf, int iMaxLen);
    00080 int      USBHwEPWrite           (U8 bEP, U8 *pbBuf, int iLen);
    00081 void USBHwEPStall               (U8 bEP, BOOL fStall);
    00082 U8   USBHwEPGetStatus   (U8 bEP);
    00083
    00085 typedef void (TFnEPIntHandler)  (U8 bEP, U8 bEPStatus);
    00086 void USBHwRegisterEPIntHandler  (U8 bEP, TFnEPIntHandler *pfnHandler);
    00087
    00089 typedef void (TFnDevIntHandler) (U8 bDevStatus);
    00090 void USBHwRegisterDevIntHandler (TFnDevIntHandler *pfnHandler);
    00091
    00093 typedef void (TFnFrameHandler)(U16 wFrame);
    00094 void USBHwRegisterFrameHandler(TFnFrameHandler *pfnHandler);
    00095
    00096
    00097 /*************************************************************************
    00098         USB application interface
    00099 **************************************************************************/
    00100
    00101 // initialise the complete stack, including HW
    00102 BOOL USBInit(void);
    00103
    00105 typedef BOOL (TFnHandleRequest)(TSetupPacket *pSetup, int *piLen, U8 **ppbData);
    00106 void USBRegisterRequestHandler(int iType, TFnHandleRequest *pfnHandler, U8 *pbDataStore);
    00107 void USBRegisterCustomReqHandler(TFnHandleRequest *pfnHandler);
    00108
    00110 typedef BOOL (TFnGetDescriptor)(U16 wTypeIndex, U16 wLangID, int *piLen, U8 **ppbData);
    00111
    00113 BOOL USBHandleStandardRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData);
    00114
    00116 void USBHandleControlTransfer(U8 bEP, U8 bEPStat);
    00117
    00119 void USBRegisterDescriptors(const U8 *pabDescriptors);
    00120 BOOL USBGetDescriptor(U16 wTypeIndex, U16 wLangID, int *piLen, U8 **ppbData);