在SlaveFifoSync例程中添加HID设备枚举需要进行以下步骤:
1. 添加HID描述符:
- 打开USBBulkSourceSink.h文件,添加HID描述符的定义。
2. 添加HID设备的端口和DMA配置:
- 在USBBulkSourceSink.c文件中的CyFxSlFifoApplnInit函数中,添加HID设备的端口和DMA配置。
3. 添加HID线程:
- 在USBBulkSourceSink.c文件中的CyFxSlFifoApplnThread函数中,添加HID线程的处理逻辑。
4. 修改资源文件:
- 打开cyfxtx.cydwr文件,添加HID描述符的资源文件。
上述步骤中的详细实现细节可以参考以下步骤:
1. 添加HID描述符:
- 打开USBBulkSourceSink.h文件,在CyFxUSBSerial.h的上方添加以下代码:
```c
#define CY_FX_HID_EP_INTR 0x82 // HID interrupt endpoint address
#define CY_FX_HID_EP_INT_SIZE 0x04 // HID interrupt endpoint packet size
```
在CyFxUSBSerial.h的上方添加以下代码:
```c
#define HID_REPORT_DESCR_SIZE (30) // Size of HID report descriptor in bytes
```
在CyFxUSBSerial.h的上方添加以下代码:
```c
/* USB Standard Device Descriptor */
const uint8_t CyFxUSBSlFifoSyncDscr[] __attribute__ ((aligned (32))) =
{
0x12, /* Descriptor size */
0x01, /* Device descriptor type */
0x10,0x02, /* USB 2.0 */
0x00, /* Device class */
0x00, /* Device Sub-class */
0x00, /* Device protocol */
0x40, /* Maxpacket size for EP0 : 64 bytes */
0xB4,0x04, /* Vendor ID */
0xF0,0x00, /* Product ID */
0x34,0x00, /* Device release number */
0x01, /* Manufacturer string index */
0x02, /* Product string index */
0x00, /* Serial number string index */
0x01 /* Number of configurations */
};
/* USB Device Qualifier Descriptor */
const uint8_t CyFxUSBSerialQualDscr[] __attribute__ ((aligned (32))) =
{
0x0A, /* Descriptor size */
0x06, /* Device qualifier descriptor type */
0x00,0x02, /* USB 2.0 */
0x00, /* Device class */
0x00, /* Device Sub-class */
0x00, /* Device protocol */
0x40, /* Maxpacket size for EP0 : 64 bytes */
0x01, /* Number of configurations */
0x00 /* Reserved */
};
/* USB Configuration Descriptor */
const uint8_t CyFxUSBSerialHSConfigDscr[] __attribute__ ((aligned (32))) =
{
0x09, /* Descriptor size */
0x02, /* Configuration descriptor type */
0x29,0x00, /* Length of this descriptor and all sub descriptors */
0x02, /* Number of interfaces */
0x01, /* Configuration number */
0x00, /* Configuration string index */
0xC0, /* Config characteristics - self powered */
0x00, /* Max power consumption of device (in 2mA unit) : usb3.0 */
/* Interface Descriptor */
0x09, /* Descriptor size */
0x04, /* Interface descriptor type */
0x00, /* Interface number */
0x00, /* Alternate setting number */
0x00, /* Number of end points */
0x03, /* Interface class */
0x01, /* Interface sub class */
0x02, /* Interface protocol code */
0x00, /* Interface descriptor string index */
/* HID Interface Descriptor */
0x09, /* Descriptor size */
0x21, /* HID descriptor type */
0x00,0x01, /* HID class specification release number */
0x00, /* Country code */
0x01, /* Number of HID class descriptors */
0x22, /* HID class descriptor type */
0x34,0x00, /* Length of HID class descriptor */
/* Endpoint Descriptor */
0x07, /* Descriptor size */
0x05, /* End point descriptor type */
CY_FX_HID_EP_INTR, /* End point address 0x81 for IN */
0x03, /* Interrupt end point type */
0x04,0x00, /* Max packet size = 4 bytes */
0x0A /* Servicing interval for data transfers */
};
/* HID Report Descriptor */
const uint8_t CyFxUSBSerialHIDReportDscr[] __attribute__ ((aligned (32))) =
{
0x05, 0x01, /* Usage Page (Generic Desktop) */
0x09, 0x06, /* Usage (Keyboard) */
0xA1, 0x01, /* Collection (Application) */
0x05, 0x07, /* Usage Page (Key Codes) */
0x19, 0xE0, /* Usage Minimum (224) */
0x29, 0xE7, /* Usage Maximum (231) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */
0x75, 0x01, /* Report Size (1) */
0x95, 0x08, /* Report Count (8) */
0x81, 0x02, /* Input(Modifier) */
0x95, 0x01, /* Report Count (1) */
0x75, 0x08, /* Report Size (8) */
0x81, 0x01, /* Input(Reserved byte) */
0x95, 0x05, /* Report Count (5) */
0x75, 0x01, /* Report Size (1) */
0x05, 0x08, /* Usage Page (Page# for LEDs) */
0x19, 0x01, /* Usage Minimum (1) */
0x29, 0x05, /* Usage Maximum (5) */
0x91, 0x02, /* Output (Data, Variable, Absolute) */
0x95, 0x01, /* Report Count (1) */
0x75, 0x03, /* Report Size (3) */
0x91, 0x01, /* Output (Constant) */
0x95, 0x06, /* Report Count (6) */
0x75, 0x08, /* Report Size (8) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x65, /* Logical Maximum (101) */
0x05, 0x07, /* Usage Page (Key codes) */
0x19, 0x00, /* Usage Minimum (0) */
0x29, 0x65, /* Usage Maximum (101) */
0x81, 0x00, /* Input (Data, Array) */
0xC0 /* End Collection (Application) */
};
```
2. 添加HID设备的端点和DMA配置:
- 在USBBulkSourceSink.c文件中的CyFxSlFifoApplnInit函数中添加以下代码:
```c
/* Configure HID endpoint settings */
CyU3PUsbSetEpConfig(CY_FX_HID_EP_INTR, CY_U3P_USB_EP_INTR, CY_FX_HID_EP_INT_SIZE);
CyU3PUsbSetEpConfig(CY_FX_EP_PRODUCER_1, CY_U3P_USB_EP_ISO, 0x200);
```
在CyFxSlFifoApplnInit函数的末尾添加以下代码:
```c
/* Enable HID endpoint */
CyU3PUsbStall(CY_FX_HID_EP_INTR, CyFalse, CyTrue);
```
在CyFxSlFifoApplnInit函数的末尾添加以下代码:
```c
/* Setup DMA for HID endpoint */
status = CyU3PDmaChannelCreate(&glChHandleSlFifoUtoP, CY_U3P_DMA_TYPE_AUTO, &dmaCfg);
if (status != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (2, "CyU3PDmaChannelCreate failed, Error code = %dn", status);
CyFxAppErrorHandler(status);
}
```
在CyFxSlFifoApplnInit函数的末尾添加以下代码:
```c
/* Flush the Endpoint memory */
CyU3PUsbFlushEp(CY_FX_HID_EP_INTR);
```
3. 添加HID线程:
- 在USBBulkSourceSink.c文件中的CyFxSlFifoApplnThread中添加以下代码:
```c
{
// HID Thread Variables
uint32_t hidParam;
CyU3PReturnStatus_t hidApiRetStatus;
uint16_t hidSendCount = 0;
if (glIsApplnActive)
{
/* HID Device Interface */
if (glUsbDeviceInfo.hidHandle)
{
memset(glHidAppData, 0, sizeof(glHidAppData));
/* Call the HID Application Function */
hidApiRetStatus = CyFxHidApp(hidParam);
if (hidApiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (2, "HID Application failed with Error code = 0x%xn", hidApiRetStatus);
CyFxAppErrorHandler(hidApiRetStatus);
}
}
}
/* To Allow the Thread to Sleep */
CyU3PThreadSleep (100);
}
```
4. 修改资源文件:
- 打开cyfxtx.cydwr文件,右键点击USBDevice节点,选择Add HID Class Interface。
- 在Devices节点下添加以下资源文件:
- HID Report Descriptor:选择CyFxUSBSerialHIDReportDscr数组;
- HID Descriptor:选择CyFxUSBSerialHSDscr数组;
- Endpoint Configuration:选择CyFxUSBSerialISOCConfig和CyFxUSBSerialISOCConfig数组。
这些步骤可以在SlaveFifoSync例程中添加HID设备的枚举。但请注意,如果添加的HID设备与原来的Cypress FX3 USB StreamerExample Device共享USB连接,则需要进行一些额外的配置以确保两个设备可以正确枚举和工作。
在SlaveFifoSync例程中添加HID设备枚举需要进行以下步骤:
1. 添加HID描述符:
- 打开USBBulkSourceSink.h文件,添加HID描述符的定义。
2. 添加HID设备的端口和DMA配置:
- 在USBBulkSourceSink.c文件中的CyFxSlFifoApplnInit函数中,添加HID设备的端口和DMA配置。
3. 添加HID线程:
- 在USBBulkSourceSink.c文件中的CyFxSlFifoApplnThread函数中,添加HID线程的处理逻辑。
4. 修改资源文件:
- 打开cyfxtx.cydwr文件,添加HID描述符的资源文件。
上述步骤中的详细实现细节可以参考以下步骤:
1. 添加HID描述符:
- 打开USBBulkSourceSink.h文件,在CyFxUSBSerial.h的上方添加以下代码:
```c
#define CY_FX_HID_EP_INTR 0x82 // HID interrupt endpoint address
#define CY_FX_HID_EP_INT_SIZE 0x04 // HID interrupt endpoint packet size
```
在CyFxUSBSerial.h的上方添加以下代码:
```c
#define HID_REPORT_DESCR_SIZE (30) // Size of HID report descriptor in bytes
```
在CyFxUSBSerial.h的上方添加以下代码:
```c
/* USB Standard Device Descriptor */
const uint8_t CyFxUSBSlFifoSyncDscr[] __attribute__ ((aligned (32))) =
{
0x12, /* Descriptor size */
0x01, /* Device descriptor type */
0x10,0x02, /* USB 2.0 */
0x00, /* Device class */
0x00, /* Device Sub-class */
0x00, /* Device protocol */
0x40, /* Maxpacket size for EP0 : 64 bytes */
0xB4,0x04, /* Vendor ID */
0xF0,0x00, /* Product ID */
0x34,0x00, /* Device release number */
0x01, /* Manufacturer string index */
0x02, /* Product string index */
0x00, /* Serial number string index */
0x01 /* Number of configurations */
};
/* USB Device Qualifier Descriptor */
const uint8_t CyFxUSBSerialQualDscr[] __attribute__ ((aligned (32))) =
{
0x0A, /* Descriptor size */
0x06, /* Device qualifier descriptor type */
0x00,0x02, /* USB 2.0 */
0x00, /* Device class */
0x00, /* Device Sub-class */
0x00, /* Device protocol */
0x40, /* Maxpacket size for EP0 : 64 bytes */
0x01, /* Number of configurations */
0x00 /* Reserved */
};
/* USB Configuration Descriptor */
const uint8_t CyFxUSBSerialHSConfigDscr[] __attribute__ ((aligned (32))) =
{
0x09, /* Descriptor size */
0x02, /* Configuration descriptor type */
0x29,0x00, /* Length of this descriptor and all sub descriptors */
0x02, /* Number of interfaces */
0x01, /* Configuration number */
0x00, /* Configuration string index */
0xC0, /* Config characteristics - self powered */
0x00, /* Max power consumption of device (in 2mA unit) : usb3.0 */
/* Interface Descriptor */
0x09, /* Descriptor size */
0x04, /* Interface descriptor type */
0x00, /* Interface number */
0x00, /* Alternate setting number */
0x00, /* Number of end points */
0x03, /* Interface class */
0x01, /* Interface sub class */
0x02, /* Interface protocol code */
0x00, /* Interface descriptor string index */
/* HID Interface Descriptor */
0x09, /* Descriptor size */
0x21, /* HID descriptor type */
0x00,0x01, /* HID class specification release number */
0x00, /* Country code */
0x01, /* Number of HID class descriptors */
0x22, /* HID class descriptor type */
0x34,0x00, /* Length of HID class descriptor */
/* Endpoint Descriptor */
0x07, /* Descriptor size */
0x05, /* End point descriptor type */
CY_FX_HID_EP_INTR, /* End point address 0x81 for IN */
0x03, /* Interrupt end point type */
0x04,0x00, /* Max packet size = 4 bytes */
0x0A /* Servicing interval for data transfers */
};
/* HID Report Descriptor */
const uint8_t CyFxUSBSerialHIDReportDscr[] __attribute__ ((aligned (32))) =
{
0x05, 0x01, /* Usage Page (Generic Desktop) */
0x09, 0x06, /* Usage (Keyboard) */
0xA1, 0x01, /* Collection (Application) */
0x05, 0x07, /* Usage Page (Key Codes) */
0x19, 0xE0, /* Usage Minimum (224) */
0x29, 0xE7, /* Usage Maximum (231) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */
0x75, 0x01, /* Report Size (1) */
0x95, 0x08, /* Report Count (8) */
0x81, 0x02, /* Input(Modifier) */
0x95, 0x01, /* Report Count (1) */
0x75, 0x08, /* Report Size (8) */
0x81, 0x01, /* Input(Reserved byte) */
0x95, 0x05, /* Report Count (5) */
0x75, 0x01, /* Report Size (1) */
0x05, 0x08, /* Usage Page (Page# for LEDs) */
0x19, 0x01, /* Usage Minimum (1) */
0x29, 0x05, /* Usage Maximum (5) */
0x91, 0x02, /* Output (Data, Variable, Absolute) */
0x95, 0x01, /* Report Count (1) */
0x75, 0x03, /* Report Size (3) */
0x91, 0x01, /* Output (Constant) */
0x95, 0x06, /* Report Count (6) */
0x75, 0x08, /* Report Size (8) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x65, /* Logical Maximum (101) */
0x05, 0x07, /* Usage Page (Key codes) */
0x19, 0x00, /* Usage Minimum (0) */
0x29, 0x65, /* Usage Maximum (101) */
0x81, 0x00, /* Input (Data, Array) */
0xC0 /* End Collection (Application) */
};
```
2. 添加HID设备的端点和DMA配置:
- 在USBBulkSourceSink.c文件中的CyFxSlFifoApplnInit函数中添加以下代码:
```c
/* Configure HID endpoint settings */
CyU3PUsbSetEpConfig(CY_FX_HID_EP_INTR, CY_U3P_USB_EP_INTR, CY_FX_HID_EP_INT_SIZE);
CyU3PUsbSetEpConfig(CY_FX_EP_PRODUCER_1, CY_U3P_USB_EP_ISO, 0x200);
```
在CyFxSlFifoApplnInit函数的末尾添加以下代码:
```c
/* Enable HID endpoint */
CyU3PUsbStall(CY_FX_HID_EP_INTR, CyFalse, CyTrue);
```
在CyFxSlFifoApplnInit函数的末尾添加以下代码:
```c
/* Setup DMA for HID endpoint */
status = CyU3PDmaChannelCreate(&glChHandleSlFifoUtoP, CY_U3P_DMA_TYPE_AUTO, &dmaCfg);
if (status != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (2, "CyU3PDmaChannelCreate failed, Error code = %dn", status);
CyFxAppErrorHandler(status);
}
```
在CyFxSlFifoApplnInit函数的末尾添加以下代码:
```c
/* Flush the Endpoint memory */
CyU3PUsbFlushEp(CY_FX_HID_EP_INTR);
```
3. 添加HID线程:
- 在USBBulkSourceSink.c文件中的CyFxSlFifoApplnThread中添加以下代码:
```c
{
// HID Thread Variables
uint32_t hidParam;
CyU3PReturnStatus_t hidApiRetStatus;
uint16_t hidSendCount = 0;
if (glIsApplnActive)
{
/* HID Device Interface */
if (glUsbDeviceInfo.hidHandle)
{
memset(glHidAppData, 0, sizeof(glHidAppData));
/* Call the HID Application Function */
hidApiRetStatus = CyFxHidApp(hidParam);
if (hidApiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (2, "HID Application failed with Error code = 0x%xn", hidApiRetStatus);
CyFxAppErrorHandler(hidApiRetStatus);
}
}
}
/* To Allow the Thread to Sleep */
CyU3PThreadSleep (100);
}
```
4. 修改资源文件:
- 打开cyfxtx.cydwr文件,右键点击USBDevice节点,选择Add HID Class Interface。
- 在Devices节点下添加以下资源文件:
- HID Report Descriptor:选择CyFxUSBSerialHIDReportDscr数组;
- HID Descriptor:选择CyFxUSBSerialHSDscr数组;
- Endpoint Configuration:选择CyFxUSBSerialISOCConfig和CyFxUSBSerialISOCConfig数组。
这些步骤可以在SlaveFifoSync例程中添加HID设备的枚举。但请注意,如果添加的HID设备与原来的Cypress FX3 USB StreamerExample Device共享USB连接,则需要进行一些额外的配置以确保两个设备可以正确枚举和工作。
举报