USB-JoyStickMouse移植到HID

1.       修改usb_conf.h 文件

#define EP_NUM     (3)   改为3个端点

#define ENDP2_RXADDR        (0x128)   分配端点2输出ram偏移

    /* #define EP1_IN_Callback   NOP_Process*/

#define  EP2_IN_Callback   NOP_Process

#define  EP3_IN_Callback   NOP_Process

#define  EP4_IN_Callback   NOP_Process

#define  EP5_IN_Callback   NOP_Process

#define  EP6_IN_Callback   NOP_Process

#define  EP7_IN_Callback   NOP_Process

 

#define  EP1_OUT_Callback   NOP_Process

//#define EP2_OUT_Callback   NOP_Process

#define  EP3_OUT_Callback   NOP_Process

#define  EP4_OUT_Callback   NOP_Process

#define  EP5_OUT_Callback   NOP_Process

#define  EP6_OUT_Callback   NOP_Process

#define  EP7_OUT_Callback   NOP_Process

允许端点1输入回调,允许端点2输出回调处理

2.       main.c文件或usb_endp.c中定义回调函数

voidEP2_OUT_Callback(void)

{

 USB_ReceiveFlg = TRUE;

 PMAToUserBufferCopy(Receive_Buffer,ENDP2_RXADDR,16);

 MsgCmd =Receive_Buffer[0];

 switch(MsgCmd)

 {

      case 1:

                   LED1_ON;

                             break;

             case 2:

                   LED2_ON;

                             break;

             default:

                   LED1_OFF; LED2_OFF;

 }

     SetEPRxStatus(ENDP2,EP_RX_VALID);

}

3.      修改VIDPID 方便区别

 constuint8_t Joystick_DeviceDescriptor[JOYSTICK_SIZ_DEVICE_DESC] =

  {

   0x12,                      /*bLength */

   USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/

   0x00,                       /*bcdUSB*/

   0x02,

   0x00,                      /*bDeviceClass*/

   0x00,                      /*bDeviceSubClass*/

   0x00,                      /*bDeviceProtocol*/

   0x40,                      /*bMaxPacketSize 64*/

    0x16,                       /*idVendor (0x0483)*/

    0x20,

    0x09,                       /*idProduct = 0x5710*/

    0x05,

   0x00,                      /*bcdDevice rel. 2.00*/

   0x02,

   1,                         /*Index of string descriptor describing

                                                 manufacturer */

   2,                         /*Index of string descriptor describing

                                                product*/

   3,                         /*Index of string descriptor describing the

                                                device serial number */

   0x01                       /*bNumConfigurations*/

}

4.       修改配置描述符

constuint8_t Joystick_ConfigDescriptor[JOYSTICK_SIZ_CONFIG_DESC] =

  {

    0x09, /* bLength: Configuration Descriptorsize */

    USB_CONFIGURATION_DESCRIPTOR_TYPE, /*bDescriptorType: Configuration */

    JOYSTICK_SIZ_CONFIG_DESC,

    /* wTotalLength: Bytes returned */

    0x00,

    0x01,         /*bNumInterfaces: 1 interface*/

    0x01,         /*bConfigurationValue: Configurationvalue*/

    0x00,         /*iConfiguration: Index of stringdescriptor describing

                                     theconfiguration*/

    0xE0,         /*bmAttributes: Self powered */

    0x32,         /*MaxPower 100 mA: this current isused for detecting Vbus*/

 

    /************** Descriptor of JoystickMouse interface ****************/

    /* 09 */

    0x09,         /*bLength: Interface Descriptor size*/

   USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptortype*/

    0x00,         /*bInterfaceNumber: Number ofInterface*/

    0x00,         /*bAlternateSetting: Alternatesetting*/

    0x02,         /*bNumEndpoints*/                //变为两个端口  ep1 IN ep2 OUT

    0x03,         /*bInterfaceClass: HID*/

    0x00,        /*bInterfaceSubClass : 1=BOOT, 0=no boot*/       //自定义hid

    0x00,    /*nInterfaceProtocol : 0=none, 1=keyboard,2=mouse*/  //自定义hid

    0,            /*iInterface: Index of stringdescriptor*/

    /*********** Descriptor of Joystick MouseHID ********************/

    /* 18 */

    0x09,         /*bLength: HID Descriptor size*/

    HID_DESCRIPTOR_TYPE, /*bDescriptorType:HID*/

    0x00,         /*bcdHID: HID Class Spec releasenumber*/

    0x01,

    0x00,         /*bCountryCode: Hardware target country*/

    0x01,         /*bNumDescriptors: Number of HID classdescriptors to follow*/

    0x22,         /*bDescriptorType*/

    JOYSTICK_SIZ_REPORT_DESC,/*wItemLength:Total length of Report descriptor*/

    0x00,

    /************* Descriptor of Joystick Mouseendpoint ********************/

    /* 27 */

    0x07,          /*bLength: Endpoint Descriptor size*/

    USB_ENDPOINT_DESCRIPTOR_TYPE,/*bDescriptorType:*/

 

    0x81,          /*bEndpointAddress: Endpoint Address(IN)*/

              // bit 3...0 : the endpoint number

                   // bit 6...4 : reserved

                    // bit 7     : 0(OUT), 1(IN)

    0x03,          /*bmAttributes: Interrupt endpoint*/

    0x04,          /*wMaxPacketSize: 4 Byte max */  //包长为4byte

    0x00,

    0x20,          /*bInterval: Polling Interval (32ms)*/

    /* 34 */

 

0x07,        /* bLength: Endpoint Descriptor size */

   USB_ENDPOINT_DESCRIPTOR_TYPE,      /*bDescriptorType: */

                    /*     Endpoint descriptor type */

    0x02,          /* bEndpointAddress: */                    //追加一个端点2作为输出

                    /*     Endpoint Address (OUT) */

    0x03,          /* bmAttributes: Interrupt endpoint */

    0x08,//0x02,     /* wMaxPacketSize: 20 Bytes max  */ //包长为8byte

    0x00,

    0x10,          /* bInterval: Polling Interval (32 ms)*/

 

/* 41 */

  }

; /* MOUSE_ConfigDescriptor */

别忘了修改JOYSTICK_SIZ_CONFIG_DESC数组的大小41

 

5.      最后修改报告描述符,同样JOYSTICK_SIZ_REPORT_DESC修改为27

constuint8_t Joystick_ReportDescriptor[JOYSTICK_SIZ_REPORT_DESC] =

{

 

 0x05,0x01, // USAGE_PAGE (Generic Desktop)

 

 0x09,0x00, // USAGE (0)

 

 

 0xa1,0x01, // COLLECTION (Application)

  

 0x15,0x00, //     LOGICAL_MINIMUM (0)

  

 0x25,0xff, //     LOGICAL_MAXIMUM (255)

 

 0x19,0x01, //     USAGE_MINIMUM (1)

 

 0x29,0x08, //     USAGE_MAXIMUM (8) 

 0x95,0x08, //     REPORT_COUNT (8)

 

 0x75,0x08, //     REPORT_SIZE (8)

  

 0x81,0x02, //     INPUT (Data,Var,Abs)

 //--------------------------------输出---------------------

 0x19,0x01,

 0x29,0x08,

 0x91,0x02,

 0xc0       // END_COLLECTION

 

}; /* CustomHID_ReportDescriptor */

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
RT-Thread 是一个开源的实时操作系统,它具有轻量级、可裁剪、可移植等特点。而 hc32f460 是汇顶科技推出的一款高性能的32位ARM Cortex-M4F内核的微控制器。 要将 RT-Thread 移植到 hc32f460 上,我们需要进行以下几个步骤: 1. 确认硬件支持:首先需要确保 hc32f460 上的硬件资源能够满足 RT-Thread 的要求,比如存储器空间、CPU性能等。 2. 创建移植目录:在 RT-Thread 的源代码目录中,我们可以通过复制一个与 hc32f460 对应的目录来进行移植。例如,将 `port` 目录下的 `hc32` 目录复制,并重命名为 `hc32f460`。 3. 配置:打开 `rtconfig.h` 文件,根据 hc32f460 的硬件特点和资源情况,对 RT-Thread 进行相应的配置。这包括设置堆栈大小、线程数量、中断优先级、时钟相关配置等。 4. 驱动移植:检查 hc32f460 上的外设驱动是否与 RT-Thread 的驱动兼容。如果不兼容,需要进行一些适配工作,确保驱动能够正确地与 RT-Thread 进行交互。 5. 编译:使用 hc32f460 相应的编译工具链,编译 RT-Thread 移植代码。 6. 烧录和运行:将编译生成的可执行文件烧录到 hc32f460 的存储器中,并启动芯片,即可运行 RT-Thread。 总之,将 RT-Thread 移植到 hc32f460 上主要涉及硬件支持、目录创建、配置、驱动移植以及编译和烧录等步骤。只要按照这些步骤进行操作,我们就可以成功将 RT-Thread 移植到 hc32f460 上,并利用 RT-Thread 强大的功能和优势来开发我们的应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值