lpc1768usb使用-配置

#ifndef __USBCFG_H__

#define __USBCFG_H__

 

 

//#define USB_IF_NUM          1

#define USB_MAX_PACKET0     64

#define USB_DMA_EP          0x00000000

 

 

//尽量不要是能太多时间

//这里每一个事件都代表着一个回调函数,使能了该事件就需要实现相应的回调函数

 

#define USB_EP_EVENT        0x0003  //哪些端点需要实现中断处理函数,一位代表一个端点

 

#define USB_CONFIGURE_EVENT 1   //usb配置事件

 

#define USB_HID_IF_NUM      0   //usb hid使用端点 第几个接口

 

#define USB_DEBUG   0

 

#if USB_DEBUG

#define usb_debug_printf(format,args...)    printf(format,##args)       //变参宏定义

#else

#define  usb_debug_printf(x,...)  while(0);

#endif

 

#endif 

 

#ifndef __USBUSER_H__

#define __USBUSER_H__

#include "usbhw.h"

 

//hid报告长度

#define HID_REPORT_NUM      1

 

//hid中断端点地址

#define HID_EP_IN           0x81

#define HID_EP_OUT          0X01

 

 

/* USB回调方法 */

extern void USB_Power_Event(BOOL power);

extern void USB_Reset_Event(void);

extern void USB_Suspend_Event(void);

extern void USB_Resume_Event(void);

extern void USB_WakeUp_Event(void);

extern void USB_SOF_Event(void);

extern void USB_Error_Event(U32 error);

 

 

 

/* usb端点终端回调函数类型定义 */

#define USB_EVT_SETUP       1   /*  setup包 */

#define USB_EVT_OUT         2   /*  OUT 包 */

#define USB_EVT_IN          3   /*  IN 包 */

#define USB_EVT_OUT_NAK     4   /*  NACK OUT 包 */

#define USB_EVT_IN_NAK      5   /*  NACK IN 包 */

#define USB_EVT_OUT_STALL   6   /*  忽略 out包 */

#define USB_EVT_IN_STALL    7   /*  忽略 in包 */

 

 

 

 

/* USB端点事件回调期(方法数组) */

extern void (* const USB_P_EP[16])(U32 event);

 

 

 

/* USB端点回调方法 */

extern void USB_EndPoint0(U32 event);//最重要的函数,处理USB枚举相关事件

extern void USB_EndPoint1(U32 event);

extern void USB_EndPoint2(U32 event);

extern void USB_EndPoint3(U32 event);

extern void USB_EndPoint4(U32 event);

extern void USB_EndPoint5(U32 event);

extern void USB_EndPoint6(U32 event);

extern void USB_EndPoint7(U32 event);

extern void USB_EndPoint8(U32 event);

extern void USB_EndPoint9(U32 event);

extern void USB_EndPoint10(U32 event);

extern void USB_EndPoint11(U32 event);

extern void USB_EndPoint12(U32 event);

extern void USB_EndPoint13(U32 event);

extern void USB_EndPoint14(U32 event);

extern void USB_EndPoint15(U32 event);

 

/* USB枚举过程内核调用事件 */

extern void USB_Configure_Event(void);

extern void USB_Interface_Event(void);

extern void USB_Feature_Event(void);

 

 

 

 

 

#endif 

 

 

 

 

#include "usbuser.h"

 

 

#include "usbep1.h"

/*

 *  USB Set Configuration Event Callback

 *   Called automatically on USB Set Configuration Request

 */

 

#if USB_CONFIGURE_EVENT

void USB_Configure_Event (void)

{

    u8 Buf[4]={0,0,0,0};

    if (USB_Configuration)

    { /* Check if USB is configured */

        USB_WriteEP(HID_EP_IN, Buf, sizeof(Buf));

    }

}

#endif

 

//宏展开为USB_EndPointx()类型的函数

#define P_EP(n) ((USB_EP_EVENT & (1 << (n))) ? USB_EndPoint##n : NULL)

 

/* USB端点中断处理的回调函数 */

void (* const USB_P_EP[16])(U32 event) =

{   P_EP(0), //使用宏

    P_EP(1),

    P_EP(2),

    P_EP(3),

    P_EP(4),

    P_EP(5),

    P_EP(6),

    P_EP(7),

    P_EP(8),

    P_EP(9),

    P_EP(10),

    P_EP(11),

    P_EP(12),

    P_EP(13),

    P_EP(14),

    P_EP(15),

};

 

//端点1中断的回调函数

void USB_EndPoint1(U32 event)

{

 

    switch (event)

    {

    case USB_EVT_IN:

        usb_ep1_in_process();

        //GetInReport();

        //USB_WriteEP(HID_EP_IN, &InReport, sizeof(InReport));

        break;

    case USB_EVT_OUT:

        usb_ep1_out_process();

        break;

    }

}

 

void USB_EndPoint2(U32 event)

{

   

}

 

void USB_EndPoint3(U32 event)

{

}

 

void USB_EndPoint4(U32 event)

{

}

 

void USB_EndPoint5(U32 event)

{

}

 

void USB_EndPoint6(U32 event)

{

}

 

void USB_EndPoint7(U32 event)

{

}

 

void USB_EndPoint8(U32 event)

{

}

 

void USB_EndPoint9(U32 event)

{

}

 

void USB_EndPoint10(U32 event)

{

}

 

void USB_EndPoint11(U32 event)

{

}

 

void USB_EndPoint12(U32 event)

{

}

 

void USB_EndPoint13(U32 event)

{

}

 

void USB_EndPoint14(U32 event)

{

}

 

void USB_EndPoint15(U32 event)

{

}

 

 

 

 

 

 

 

 

 

 

 

#ifndef __USBCFG_H__

#define __USBCFG_H__

 

 

//#define USB_IF_NUM          1

#define USB_MAX_PACKET0     64

#define USB_DMA_EP          0x00000000

 

 

//尽量不要是能太多时间

//这里每一个事件都代表着一个回调函数,使能了该事件就需要实现相应的回调函数

 

#define USB_EP_EVENT        0x0003  //哪些端点需要实现中断处理函数,一位代表一个端点

 

#define USB_CONFIGURE_EVENT 1   //usb配置事件

 

#define USB_HID_IF_NUM      0   //usb hid使用端点 第几个接口

 

#define USB_DEBUG   0

 

#if USB_DEBUG

#define usb_debug_printf(format,args...)    printf(format,##args)       //变参宏定义

#else

#define  usb_debug_printf(x,...)  while(0);

#endif

 

#endif 

 

#ifndef __USBUSER_H__

#define __USBUSER_H__

#include "usbhw.h"

 

//hid报告长度

#define HID_REPORT_NUM      1

 

//hid中断端点地址

#define HID_EP_IN           0x81

#define HID_EP_OUT          0X01

 

 

/* USB回调方法 */

extern void USB_Power_Event(BOOL power);

extern void USB_Reset_Event(void);

extern void USB_Suspend_Event(void);

extern void USB_Resume_Event(void);

extern void USB_WakeUp_Event(void);

extern void USB_SOF_Event(void);

extern void USB_Error_Event(U32 error);

 

 

 

/* usb端点终端回调函数类型定义 */

#define USB_EVT_SETUP       1   /*  setup包 */

#define USB_EVT_OUT         2   /*  OUT 包 */

#define USB_EVT_IN          3   /*  IN 包 */

#define USB_EVT_OUT_NAK     4   /*  NACK OUT 包 */

#define USB_EVT_IN_NAK      5   /*  NACK IN 包 */

#define USB_EVT_OUT_STALL   6   /*  忽略 out包 */

#define USB_EVT_IN_STALL    7   /*  忽略 in包 */

 

 

 

 

/* USB端点事件回调期(方法数组) */

extern void (* const USB_P_EP[16])(U32 event);

 

 

 

/* USB端点回调方法 */

extern void USB_EndPoint0(U32 event);//最重要的函数,处理USB枚举相关事件

extern void USB_EndPoint1(U32 event);

extern void USB_EndPoint2(U32 event);

extern void USB_EndPoint3(U32 event);

extern void USB_EndPoint4(U32 event);

extern void USB_EndPoint5(U32 event);

extern void USB_EndPoint6(U32 event);

extern void USB_EndPoint7(U32 event);

extern void USB_EndPoint8(U32 event);

extern void USB_EndPoint9(U32 event);

extern void USB_EndPoint10(U32 event);

extern void USB_EndPoint11(U32 event);

extern void USB_EndPoint12(U32 event);

extern void USB_EndPoint13(U32 event);

extern void USB_EndPoint14(U32 event);

extern void USB_EndPoint15(U32 event);

 

/* USB枚举过程内核调用事件 */

extern void USB_Configure_Event(void);

extern void USB_Interface_Event(void);

extern void USB_Feature_Event(void);

 

 

 

 

 

#endif 

 

 

 

 

#include "usbuser.h"

 

 

#include "usbep1.h"

/*

 *  USB Set Configuration Event Callback

 *   Called automatically on USB Set Configuration Request

 */

 

#if USB_CONFIGURE_EVENT

void USB_Configure_Event (void)

{

    u8 Buf[4]={0,0,0,0};

    if (USB_Configuration)

    { /* Check if USB is configured */

        USB_WriteEP(HID_EP_IN, Buf, sizeof(Buf));

    }

}

#endif

 

//宏展开为USB_EndPointx()类型的函数

#define P_EP(n) ((USB_EP_EVENT & (1 << (n))) ? USB_EndPoint##n : NULL)

 

/* USB端点中断处理的回调函数 */

void (* const USB_P_EP[16])(U32 event) =

{   P_EP(0), //使用宏

    P_EP(1),

    P_EP(2),

    P_EP(3),

    P_EP(4),

    P_EP(5),

    P_EP(6),

    P_EP(7),

    P_EP(8),

    P_EP(9),

    P_EP(10),

    P_EP(11),

    P_EP(12),

    P_EP(13),

    P_EP(14),

    P_EP(15),

};

 

//端点1中断的回调函数

void USB_EndPoint1(U32 event)

{

 

    switch (event)

    {

    case USB_EVT_IN:

        usb_ep1_in_process();

        //GetInReport();

        //USB_WriteEP(HID_EP_IN, &InReport, sizeof(InReport));

        break;

    case USB_EVT_OUT:

        usb_ep1_out_process();

        break;

    }

}

 

void USB_EndPoint2(U32 event)

{

   

}

 

void USB_EndPoint3(U32 event)

{

}

 

void USB_EndPoint4(U32 event)

{

}

 

void USB_EndPoint5(U32 event)

{

}

 

void USB_EndPoint6(U32 event)

{

}

 

void USB_EndPoint7(U32 event)

{

}

 

void USB_EndPoint8(U32 event)

{

}

 

void USB_EndPoint9(U32 event)

{

}

 

void USB_EndPoint10(U32 event)

{

}

 

void USB_EndPoint11(U32 event)

{

}

 

void USB_EndPoint12(U32 event)

{

}

 

void USB_EndPoint13(U32 event)

{

}

 

void USB_EndPoint14(U32 event)

{

}

 

void USB_EndPoint15(U32 event)

{

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

原文地址:https://www.cnblogs.com/dengxiaojun/p/4338697.html