2019-03-20 16:11:42 +07:00
|
|
|
/*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018, hathach (tinyusb.org)
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* This file is part of the TinyUSB stack.
|
|
|
|
*/
|
2018-03-11 00:16:10 +07:00
|
|
|
|
2018-07-01 15:45:04 +07:00
|
|
|
#include "tusb.h"
|
2018-03-11 00:16:10 +07:00
|
|
|
|
2019-04-11 00:51:28 +07:00
|
|
|
// If HID Generic interface is generated
|
|
|
|
#define AUTO_DESC_HID_GENERIC (CFG_TUD_HID && ((CFG_TUD_HID_KEYBOARD && !CFG_TUD_HID_KEYBOARD_BOOT) || \
|
|
|
|
(CFG_TUD_HID_MOUSE && !CFG_TUD_HID_MOUSE_BOOT)) )
|
2018-03-11 00:16:10 +07:00
|
|
|
|
2019-04-11 00:51:28 +07:00
|
|
|
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
|
|
|
|
* Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
|
|
|
|
*
|
|
|
|
* Auto ProductID layout's Bitmap:
|
|
|
|
* [MSB] HID Generic | Boot Mouse | Boot Keyboard | MSC | CDC [LSB]
|
|
|
|
*/
|
|
|
|
#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
|
2019-04-17 13:55:55 +07:00
|
|
|
#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | \
|
2019-04-11 00:51:28 +07:00
|
|
|
_PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) | (AUTO_DESC_HID_GENERIC << 4) )
|
|
|
|
|
|
|
|
//------------- Device Descriptors -------------//
|
|
|
|
tusb_desc_device_t const desc_device =
|
|
|
|
{
|
|
|
|
.bLength = sizeof(tusb_desc_device_t),
|
|
|
|
.bDescriptorType = TUSB_DESC_DEVICE,
|
|
|
|
.bcdUSB = 0x0200,
|
|
|
|
|
|
|
|
#if CFG_TUD_CDC
|
|
|
|
// Use Interface Association Descriptor (IAD) for CDC
|
|
|
|
// As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
|
|
|
|
.bDeviceClass = TUSB_CLASS_MISC,
|
|
|
|
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
|
|
|
.bDeviceProtocol = MISC_PROTOCOL_IAD,
|
|
|
|
#else
|
|
|
|
.bDeviceClass = 0x00,
|
|
|
|
.bDeviceSubClass = 0x00,
|
|
|
|
.bDeviceProtocol = 0x00,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
.bMaxPacketSize0 = CFG_TUD_ENDOINT0_SIZE,
|
|
|
|
|
|
|
|
.idVendor = 0xCafe,
|
2019-04-17 13:55:55 +07:00
|
|
|
.idProduct = USB_PID,
|
2019-04-11 00:51:28 +07:00
|
|
|
.bcdDevice = 0x0100,
|
|
|
|
|
|
|
|
.iManufacturer = 0x01,
|
|
|
|
.iProduct = 0x02,
|
|
|
|
.iSerialNumber = 0x03,
|
|
|
|
|
|
|
|
.bNumConfigurations = 0x01
|
|
|
|
};
|
|
|
|
|
|
|
|
//------------- String Descriptors -------------//
|
2018-03-11 00:16:10 +07:00
|
|
|
// array of pointer to string descriptors
|
2018-07-01 15:11:58 +07:00
|
|
|
uint16_t const * const string_desc_arr [] =
|
2018-03-11 00:16:10 +07:00
|
|
|
{
|
2018-07-12 22:11:37 +07:00
|
|
|
// 0: is supported language = English
|
|
|
|
TUD_DESC_STRCONV(0x0409),
|
2018-03-11 00:16:10 +07:00
|
|
|
|
2018-07-12 22:11:37 +07:00
|
|
|
// 1: Manufacturer
|
|
|
|
TUD_DESC_STRCONV('t', 'i', 'n', 'y', 'u', 's', 'b', '.', 'o', 'r', 'g'),
|
2018-03-11 00:16:10 +07:00
|
|
|
|
2018-07-12 22:11:37 +07:00
|
|
|
// 2: Product
|
|
|
|
TUD_DESC_STRCONV('t', 'i', 'n', 'y', 'u', 's', 'b', ' ', 'd', 'e', 'v', 'i', 'c', 'e'),
|
2018-03-11 00:16:10 +07:00
|
|
|
|
2019-04-11 00:51:28 +07:00
|
|
|
// 3: Serials, should use chip ID
|
2018-07-12 22:11:37 +07:00
|
|
|
TUD_DESC_STRCONV('1', '2', '3', '4', '5', '6'),
|
2018-03-11 00:16:10 +07:00
|
|
|
|
2018-07-23 15:25:45 +07:00
|
|
|
#if CFG_TUD_CDC
|
2018-07-12 22:11:37 +07:00
|
|
|
// 4: CDC Interface
|
|
|
|
TUD_DESC_STRCONV('t','u','s','b',' ','c','d','c'),
|
2018-07-23 15:25:45 +07:00
|
|
|
#endif
|
2018-03-11 00:16:10 +07:00
|
|
|
|
2018-07-23 15:25:45 +07:00
|
|
|
#if CFG_TUD_MSC
|
2018-07-12 22:11:37 +07:00
|
|
|
// 5: MSC Interface
|
|
|
|
TUD_DESC_STRCONV('t','u','s','b',' ','m','s','c'),
|
2018-07-23 15:25:45 +07:00
|
|
|
#endif
|
2018-07-23 16:00:07 +07:00
|
|
|
|
|
|
|
#if CFG_TUD_HID_KEYBOARD
|
|
|
|
// 6: Keyboard
|
|
|
|
TUD_DESC_STRCONV('t','u','s','b',' ','k','e','y','b','o','a','r','d'),
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CFG_TUD_HID_MOUSE
|
|
|
|
// 7: Mouse
|
|
|
|
TUD_DESC_STRCONV('t','u','s','b',' ','m', 'o','u','s','e'),
|
|
|
|
#endif
|
|
|
|
|
2018-03-11 00:16:10 +07:00
|
|
|
};
|
|
|
|
|
2018-07-01 15:11:58 +07:00
|
|
|
// tud_desc_set is required by tinyusb stack
|
|
|
|
// since CFG_TUD_DESC_AUTO is enabled, we only need to set string_arr
|
|
|
|
tud_desc_set_t tud_desc_set =
|
2018-03-11 00:16:10 +07:00
|
|
|
{
|
2019-04-11 00:51:28 +07:00
|
|
|
.device = &desc_device,
|
2018-07-01 15:11:58 +07:00
|
|
|
.config = NULL,
|
2018-07-23 16:12:14 +07:00
|
|
|
|
|
|
|
.string_arr = (uint8_t const **) string_desc_arr,
|
|
|
|
.string_count = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]),
|
2018-07-23 15:25:45 +07:00
|
|
|
|
|
|
|
.hid_report =
|
|
|
|
{
|
2018-07-28 12:38:45 +07:00
|
|
|
.generic = NULL,
|
2018-07-23 15:25:45 +07:00
|
|
|
.boot_keyboard = NULL,
|
|
|
|
.boot_mouse = NULL
|
|
|
|
}
|
2018-03-11 00:16:10 +07:00
|
|
|
};
|