/*!
\file composite_hid_wrapper.c
\brief this file calls to the separate HID and printer class layer handlers
\version 2020-08-13, V3.0.0, firmware for GD32F3x0
\version 2022-06-30, V3.1.0, firmware for GD32F3x0
*/
/*
Copyright (c) 2022, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "composite_hid_core.h"
#include <string.h>
#include "appGPIO.h"
extern usbDataOutCallback gHidDoutCb;
/* Note:it should use the C99 standard when compiling the below codes */
/*
* USB standard device descriptor
* usb标准设备描述符
* https://hellocode.blog.csdn.net/article/details/112251509
*/
__ALIGN_BEGIN const usb_desc_dev composite_hid_dev_desc __ALIGN_END = {
.header =
{
.bLength = USB_DEV_DESC_LEN, //设备描述符的字节数大小
.bDescriptorType = USB_DESCTYPE_DEV //设备描述符类型编号
},
.bcdUSB = USBD_BCD, //USB协议的版本号 USB1.1-0x0110,USB2.0-0x0200
.bDeviceClass = 0x00, //设备类型的代码->值从0x01~0xFE为USB定义的标准设备类,USB_CLASS_CDC
.bDeviceSubClass = 0x00, //0
.bDeviceProtocol = 0x00, //0
.bMaxPacketSize0 = USB_FS_EP0_MAX_LEN, //端点0最长包长8,16,32,64为合法.USB_FS_EP0_MAX_LEN
.idVendor = USBD_VID,
.idProduct = USBD_PID,
.bcdDevice = DEVICE_BCD, //设备版本号
.iManufacturer = STR_IDX_MFC, //厂商描述字符串索引
.iProduct = STR_IDX_PRODUCT, //产品描述字符串索引
.iSerialNumber = STR_IDX_SERIAL, //产品序列号字符串索引
.bNumberConfigurations = USBD_CFG_MAX_NUM //可配置参数
};
/*
* USB standard device descriptor
* usb标准配置描述符
*/
__ALIGN_BEGIN const usb_composite_hid_desc_config_set composite_hid_config_desc __ALIGN_END =
{
/* usb标准配置描述符 */
.config =
{
.header =
{
.bLength = sizeof(usb_desc_config),
.bDescriptorType = USB_DESCTYPE_CONFIG,
},
.wTotalLength = sizeof(usb_composite_hid_desc_config_set),
#if EN_CUSTOM_HID
.bNumInterfaces = 0x02, //组合设备有多个接口
#else
.bNumInterfaces = 0x01, //组合设备有多个接口
#endif
.bConfigurationValue = 0x01, //配置的值
.iConfiguration = STR_IDX_CONFIG, //配置字符串索引
.bmAttributes = 0xC0, //该设备属性
//D7是保留位,默认为1;
//D6表示供电方式,0是自供电,1是总线供电;
//D5表示是否支持远程唤醒,为1表示设备支持远程唤醒;
//D4~D0保留,默认为0。
.bMaxPower = 0x96 //设备所需要电流单位2mA //300ma
},
/* standard HID */
/* usb接口描述符 */
.hid_itf =
{
.header =
{
.bLength = sizeof(usb_desc_itf),
.bDescriptorType = USB_DESCTYPE_ITF
},
.bInterfaceNumber = STANDARD_HID_INTERFACE, //该接口的编号,从0开始
.bAlternateSetting = 0x00U, //该接口的备用编号
.bNumEndpoints = STANDARD_HID_EP_NUM, //该接口使用的端点数
.bInterfaceClass = USB_HID_CLASS, //该接口使用的类
.bInterfaceSubClass = 0x00U, //USB_HID_SUBCLASS_BOOT_ITF, //该接口使用的子类
.bInterfaceProtocol = 0x00U, //USB_HID_PROTOCOL_KEYBOARD, //该接口使用的协议
.iInterface = STR_IDX_ITF //描述符字符串索引
},
/* standard HID描述符 */
.hid_vendor =
{
.header =
{
.bLength = sizeof(usb_desc_hid),
.bDescriptorType = USB_DESCTYPE_HID
},
.bcdHID = 0x0111U, //HID设备所遵循的HID版本号,为4位16进制的BCD码。1.0即0x0100,1.1即0x0101,2.0即0x0200。
.bCountryCode = 0x00U,
.bNumDescriptors = 0x01U,
.bDescriptorType = USB_DESCTYPE_REPORT,
.wDescriptorLength = USB_HID_REPORT_DESC_LEN,
},
/* 端点描述符 */
.hid_epin =
{
.header =
{
.bLength = sizeof(usb_desc_ep),
.bDescriptorType = USB_DESCTYPE_EP
},
.bEndpointAddress = STANDARD_HID_IN_EP, //EP1_IN
.bmAttributes = USB_EP_ATTR_INT,
.wMaxPacketSize = STANDARD_HID_IN_PACKET,
.bInterval = 0x20U
},
#if STANDARD_HID_EP_NUM == 2
/* 端点描述符 */
.hid_epout =
{
.header =
{
.bLength = sizeof(usb_desc_ep),
.bDescriptorType = USB_DESCTYPE_EP
},
.bEndpointAddress = STANDARD_HID_OUT_EP, //EP1_OUT
.bmAttributes = USB_EP_ATTR_INT,
.wMaxPacketSize = STANDARD_HID_OUT_PACKET,
.bInterval = 0x20U
},
#endif
#if EN_CUSTOM_HID
/* custom HID */
/* usb接口描述符 */
.custom_hid_itf =
{
.header =
{
.bLength = sizeof(usb_desc_itf),
.bDescriptorType = USB_DESCTYPE_ITF
},
.bInterfaceNumber = CUSTOM_HID_INTERFACE, //该接口的编号,从0开始
.bAlternateSetting = 0x00U, //该接口的备用编号
.bNumEndpoints = 0x02U, //该接口使用的端点数
.bInterfaceClass = USB_HID_CLASS, //该接口使用的类
.bInterfaceSubClass = 0x00U, //该接口使用的子类
.bInterfaceProtocol = 0x00U, //该接口使用的协议
.iInterface = 0x00U //描述符字符串索引
},
/* HID描述符 */
.custom_hid_vendor =
{
.header =
{
.bLength = sizeof(usb_desc_hid),
.bDescriptorType = USB_DESCTYPE_HID
},
.bcdHID = 0x0111U, //HID设备所遵循的HID版本号,为4位16进制的BCD码。1.0即0x0100,1.1即0x0101,2.0即0x0200。
.bCountryCode = 0x00U,
.bNumDescriptors = 0x01U,
.bDescriptorType = USB_DESCTYPE_REPORT,
.wDescriptorLength = CUSTOM_HID_REPORT_DESC_LEN,
},
/*