⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_standard_desc.c

📁 这是nrf24lu1的无线鼠标源代码,应用平台是keil c
💻 C
字号:
/* Copyright (c) 2007 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is confidential property of 
 * Nordic Semiconductor. The use, copying, transfer or disclosure 
 * of such information is prohibited except by express written
 * agreement with Nordic Semiconductor.
 */

/** @file
 * USB device descriptor and USB HID configuration descriptior.
 */

/** @{
 * @ingroup nordic_usb
 */


#include "usb_desc.h"
#include "nordic_common.h"

#define MAX_PACKET_SIZE_EP0  32

#define EP1_PACKET_SIZE 0x00a
#define EP2_PACKET_SIZE 0x00a
#define EP3_PACKET_SIZE 0x00a

code const hal_usb_dev_desc_t g_usb_dev_desc =
{
  sizeof(hal_usb_dev_desc_t),                // bLength
  0x01,                               // bDescriptorType
  SWAP(0x0200),                             // bcdUSB
  0x00,                               // bDeviceClass
  0x00,                               // bDeviceSubClass
  0x00,                               // bDeviceProtocol
  MAX_PACKET_SIZE_EP0,                // bMaxPacketSize0
  SWAP(VID),                          // idVendor (Nordic )
  SWAP(PID),                          // idProduct (dongle)
  SWAP(0x0100),                             // bcdDevice
  0x01,                               // iManufacturer
  0x02,                               // iProduct
  0x03,                               // iSerialNumber
  0x01                                // bNumConfigurations
};

// From "USB Device Class Definition for Human Interface Devices (HID)".
// Section 7.1:
// "When a Get_Descriptor(Configuration) request is issued,
// it returns the Configuration descriptor, all Interface descriptors,
// all Endpoint descriptors, and the HID descriptor for each interface."
code const usb_conf_desc_templ_t g_usb_conf_desc =
{
  { // configuration_descriptor hid_configuration_descriptor
    sizeof(hal_usb_conf_desc_t),         // Length
    0x02,                               // Type                             
    SWAP(sizeof(usb_conf_desc_templ_t)),        // Totallength
    0x02,                               // NumInterfaces
    0x01,                               // bConfigurationValue
    0x00,                               // iConfiguration
    0xA0,                               // bmAttributes (0x80 + Remote Wakeup)
    0x32                                // MaxPower (in 2mA units) = 100 * 2mA
  },
  { // interface_descriptor hid_interface_descriptor    (MOUSE)
    sizeof(hal_usb_if_desc_t),             // Length
    0x04,                               // bDescriptorType
    0x00,                               // bInterfaceNumber
    0x00,                               // bAlternateSetting
    0x01,                               // bNumEndpoints
    0x03,                               // bInterfaceClass (3 = HID)
    0x01,                               // bInterfaceSubClass
    0x02,                               // bInterfaceProcotol(0=None, 1=Keyb, 2=Mouse)
    0x00                                // iInterface
  },
  { // class_descriptor hid_descriptor
    sizeof(hal_usb_hid_desc_t),             // Length
    0x21,	                                // bDescriptorType
    SWAP(0x0111),	                                // bcdHID
    0x00,	                                // bCountryCode
    0x01,	                                // bNumDescriptors
    0x22,                                   // bDescriptorType
    SWAP(HID_REPORT_DESCRIPTOR_SIZE_MOUSE), // wItemLength (tot. len. of report
                                            // descriptor)
  },
  { // endpoint_descriptor hid_endpoint_in_descriptor
    sizeof(hal_usb_ep_desc_t),          // Length
    0x05,                               // bDescriptorType
    0x81,                               // bEndpointAddress
    0x03,                               // bmAttributes
    SWAP(EP1_PACKET_SIZE),              // MaxPacketSize (LITTLE ENDIAN)
    4                                   // bInterval
  },
  { // interface_descriptor hid_interface_descriptor    (KEYBOARD)
    sizeof(hal_usb_if_desc_t),        // Length
    0x04,                               // bDescriptorType
    0x01,                               // bInterfaceNumber
    0x00,                               // bAlternateSetting
    0x01,                               // bNumEndpoints
    0x03,                               // bInterfaceClass (3 = HID)
    0x01,                               // bInterfaceSubClass
    0x01,                               // bInterfaceProcotol(0=None, 1=Keyb, 2=Mouse)
    0x00                                // iInterface
  },
  { // class_descriptor hid_descriptor
    sizeof(hal_usb_hid_desc_t),          // Length
    0x21,	                            // bDescriptorType
    0x0111,	                            // bcdHID
    0x00,	                            // bCountryCode
    0x01,	                            // bNumDescriptors
    0x22,                               // bDescriptorType
    SWAP(HID_REPORT_DESCRIPTOR_SIZE_KEYB),   // wItemLength (tot. len. of report
                                        // descriptor)
  },
  { // endpoint_descriptor hid_endpoint_in_descriptor
    sizeof(hal_usb_ep_desc_t),              // Length
    0x05,                               // bDescriptorType
    0x82,                               // bEndpointAddress
    0x03,                               // bmAttributes
    SWAP(EP2_PACKET_SIZE),              // MaxPacketSize (LITTLE ENDIAN)
    10                                  // bInterval
  },
#if 0
  { // interface_descriptor hid_interface_descriptor    (REMOTE CONTROL)
    sizeof(hal_usb_if_desc_t),          // Length
    0x04,                               // bDescriptorType
    0x02,                               // bInterfaceNumber
    0x00,                               // bAlternateSetting
    0x01,                               // bNumEndpoints
    0x03,                               // bInterfaceClass (3 = HID)
    0x00,                               // bInterfaceSubClass
    0x00,                               // bInterfaceProcotol(0=None, 1=Keyb, 2=Mouse)
    0x00                                // iInterface
  },
  { // class_descriptor hid_descriptor
    sizeof(hal_usb_hid_desc_t),          // Length
    0x21,	                            // bDescriptorType
    SWAP(0x0111),	                    // bcdHID
    0x00,	                            // bCountryCode
    0x01,	                            // bNumDescriptors
    0x22,                               // bDescriptorType
    SWAP(HID_REPORT_DESCRIPTOR_SIZE_RC),// wItemLength (tot. len. of report
                                        // descriptor)
  },
  { // endpoint_descriptor hid_endpoint_in_descriptor
    sizeof(hal_usb_ep_desc_t),          // Length
    0x05,                               // bDescriptorType
    0x83,                               // bEndpointAddress
    0x03,                               // bmAttributes
    SWAP(EP3_PACKET_SIZE),              // MaxPacketSize (LITTLE ENDIAN)
    10                                   // bInterval
  }
#endif
};

#define USB_STRING_IDX_1_DESC "Nordic Semiconductor"
#define USB_STRING_IDX_2_DESC "Nordic Semiconductor Wireless Desktop nRF24LU1 CX-1885"
#define USB_STRING_IDX_3_DESC "CX-1870"

code uint8_t g_usb_string_desc_1[] = {
    sizeof(USB_STRING_IDX_1_DESC) * 2, 
    0x03, 
    'N',00,
    'o',00,
    'r',00,
    'd',00,
    'i',00,
    'c',00,
    ' ',00,
    'S',00,
    'e',00,
    'm',00,
    'i',00,
    'c',00,
    'o',00,
    'n',00,
    'd',00,
    'u',00,
    'c',00,
    't',00,
    'o',00,
    'r', 00 
};

code uint8_t g_usb_string_desc_2[] = {
    sizeof(USB_STRING_IDX_2_DESC) * 2,
    0x03, 
    'N',00,
    'o',00,
    'r',00,
    'd',00,
    'i',00,
    'c',00,
    ' ',00,
    'S',00,
    'e',00,
    'm',00,
    'i',00,
    'c',00,
    'o',00,
    'n',00,
    'd',00,
    'u',00,
    'c',00,
    't',00,
    'o',00,
    'r',00, 
    ' ',00, 
    'W',00,
    'i',00,
    'r',00,
    'e',00,
    'l',00,
    'e',00,
    's',00,
    's',00,
    ' ',00, 
    'D',00,
    'e',00,
    's',00,
    'k',00,
    't',00,
    'o',00,
    'p',00,
    ' ',00,
    'n',00,
    'R',00,
    'F',00,
    '2',00,
    '4',00,
    'L',00,
    '0',00,
    '1',00,
    ' ',00, 
    'C',00,
    'X',00,
    '-',00,
    '1',00,
    '8',00,
    '8',00,
    '5',00,
};

code uint8_t g_usb_string_desc_3[] = {
    sizeof(USB_STRING_IDX_3_DESC) * 2,
    0x03, 
    'C',00,
    'X',00,
    '-',00,
    '1',00,
    '8',00,
    '8',00,
    '5',00,
};

code usb_string_desc_templ_t g_usb_string_desc = {
    g_usb_string_desc_1,
    g_usb_string_desc_2,
    g_usb_string_desc_3,
};
/** @} */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -