mirror of
https://github.com/ArteryTek/AT32F403A_407_Firmware_Library.git
synced 2026-05-21 09:22:19 +00:00
update version to v2.0.7
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file keyboard_class.c
|
||||
* @version v2.0.6
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.7
|
||||
* @date 2022-02-11
|
||||
* @brief usb hid keyboard class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -40,27 +40,19 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
usb_sts_type class_init_handler(void *udev);
|
||||
usb_sts_type class_clear_handler(void *udev);
|
||||
usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup);
|
||||
usb_sts_type class_ept0_tx_handler(void *udev);
|
||||
usb_sts_type class_ept0_rx_handler(void *udev);
|
||||
usb_sts_type class_in_handler(void *udev, uint8_t ept_num);
|
||||
usb_sts_type class_out_handler(void *udev, uint8_t ept_num);
|
||||
usb_sts_type class_sof_handler(void *udev);
|
||||
usb_sts_type class_event_handler(void *udev, usbd_event_type event);
|
||||
|
||||
/* hid static variable */
|
||||
static uint32_t hid_protocol = 0;
|
||||
static uint32_t hid_set_idle = 0;
|
||||
static uint32_t alt_setting = 0;
|
||||
static uint8_t hid_state;
|
||||
__IO uint8_t hid_suspend_flag = 0;
|
||||
uint8_t hid_set_report[64];
|
||||
__IO uint8_t g_u8tx_completed = 0;
|
||||
static usb_sts_type class_init_handler(void *udev);
|
||||
static usb_sts_type class_clear_handler(void *udev);
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup);
|
||||
static usb_sts_type class_ept0_tx_handler(void *udev);
|
||||
static usb_sts_type class_ept0_rx_handler(void *udev);
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num);
|
||||
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num);
|
||||
static usb_sts_type class_sof_handler(void *udev);
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event);
|
||||
|
||||
keyboard_type keyboard_struct;
|
||||
#define SHIFT 0x80
|
||||
const unsigned char _asciimap[128] =
|
||||
const static unsigned char _asciimap[128] =
|
||||
{
|
||||
0x00,// NUL
|
||||
0x00,// SOH
|
||||
@@ -205,6 +197,7 @@ usbd_class_handler keyboard_class_handler =
|
||||
class_out_handler,
|
||||
class_sof_handler,
|
||||
class_event_handler,
|
||||
&keyboard_struct
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -212,20 +205,20 @@ usbd_class_handler keyboard_class_handler =
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_init_handler(void *udev)
|
||||
static usb_sts_type class_init_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
keyboard_type *pkeyboard = (keyboard_type *)pudev->class_handler->pdata;
|
||||
#ifndef USB_EPT_AUTO_MALLOC_BUFFER
|
||||
/* use user define buffer address */
|
||||
usbd_ept_buf_custom_define(pudev, USBD_HID_IN_EPT, EPT1_TX_ADDR);
|
||||
usbd_ept_buf_custom_define(pudev, USBD_KEYBOARD_IN_EPT, EPT1_TX_ADDR);
|
||||
#endif
|
||||
|
||||
/* open hid in endpoint */
|
||||
usbd_ept_open(pudev, USBD_HID_IN_EPT, EPT_INT_TYPE, USBD_IN_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_KEYBOARD_IN_EPT, EPT_INT_TYPE, USBD_KEYBOARD_IN_MAXPACKET_SIZE);
|
||||
|
||||
g_u8tx_completed = 1;
|
||||
pkeyboard->g_u8tx_completed = 1;
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -235,13 +228,13 @@ usb_sts_type class_init_handler(void *udev)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_clear_handler(void *udev)
|
||||
static usb_sts_type class_clear_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
/* close hid in endpoint */
|
||||
usbd_ept_close(pudev, USBD_HID_IN_EPT);
|
||||
usbd_ept_close(pudev, USBD_KEYBOARD_IN_EPT);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -252,10 +245,11 @@ usb_sts_type class_clear_handler(void *udev)
|
||||
* @param setup: setup packet
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
keyboard_type *pkeyboard = (keyboard_type *)pudev->class_handler->pdata;
|
||||
uint16_t len;
|
||||
uint8_t *buf;
|
||||
|
||||
@@ -266,20 +260,20 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
switch(setup->bRequest)
|
||||
{
|
||||
case HID_REQ_SET_PROTOCOL:
|
||||
hid_protocol = (uint8_t)setup->wValue;
|
||||
pkeyboard->hid_protocol = (uint8_t)setup->wValue;
|
||||
break;
|
||||
case HID_REQ_GET_PROTOCOL:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&hid_protocol, 1);
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&pkeyboard->hid_protocol, 1);
|
||||
break;
|
||||
case HID_REQ_SET_IDLE:
|
||||
hid_set_idle = (uint8_t)(setup->wValue >> 8);
|
||||
pkeyboard->hid_set_idle = (uint8_t)(setup->wValue >> 8);
|
||||
break;
|
||||
case HID_REQ_GET_IDLE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&hid_set_idle, 1);
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&pkeyboard->hid_set_idle, 1);
|
||||
break;
|
||||
case HID_REQ_SET_REPORT:
|
||||
hid_state = HID_REQ_SET_REPORT;
|
||||
usbd_ctrl_recv(pudev, hid_set_report, setup->wLength);
|
||||
pkeyboard->hid_state = HID_REQ_SET_REPORT;
|
||||
usbd_ctrl_recv(pudev, pkeyboard->hid_set_report, setup->wLength);
|
||||
break;
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
@@ -293,21 +287,21 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
case USB_STD_REQ_GET_DESCRIPTOR:
|
||||
if(setup->wValue >> 8 == HID_REPORT_DESC)
|
||||
{
|
||||
len = MIN(USBD_HID_SIZ_REPORT_DESC, setup->wLength);
|
||||
buf = (uint8_t *)g_usbd_hid_report;
|
||||
len = MIN(USBD_KEYBOARD_SIZ_REPORT_DESC, setup->wLength);
|
||||
buf = (uint8_t *)g_usbd_keyboard_report;
|
||||
}
|
||||
else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
len = MIN(9, setup->wLength);
|
||||
buf = (uint8_t *)g_hid_usb_desc;
|
||||
buf = (uint8_t *)g_keyboard_usb_desc;
|
||||
}
|
||||
usbd_ctrl_send(pudev, (uint8_t *)buf, len);
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&alt_setting, 1);
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&pkeyboard->alt_setting, 1);
|
||||
break;
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
alt_setting = setup->wValue;
|
||||
pkeyboard->alt_setting = setup->wValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -325,7 +319,7 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
static usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
@@ -339,16 +333,17 @@ usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
static usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
keyboard_type *pkeyboard = (keyboard_type *)pudev->class_handler->pdata;
|
||||
uint32_t recv_len = usbd_get_recv_len(pudev, 0);
|
||||
/* ...user code... */
|
||||
if( hid_state == HID_REQ_SET_REPORT)
|
||||
if( pkeyboard->hid_state == HID_REQ_SET_REPORT)
|
||||
{
|
||||
/* hid buffer process */
|
||||
hid_state = 0;
|
||||
pkeyboard->hid_state = 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -360,14 +355,16 @@ usb_sts_type class_ept0_rx_handler(void *udev)
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
static usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
keyboard_type *pkeyboard = (keyboard_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
g_u8tx_completed = 1;
|
||||
pkeyboard->g_u8tx_completed = 1;
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -378,7 +375,7 @@ usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
@@ -390,7 +387,7 @@ usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_sof_handler(void *udev)
|
||||
static usb_sts_type class_sof_handler(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
@@ -405,9 +402,11 @@ usb_sts_type class_sof_handler(void *udev)
|
||||
* @param event: usb device event
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
static usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
keyboard_type *pkeyboard = (keyboard_type *)pudev->class_handler->pdata;
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
@@ -416,7 +415,7 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
hid_suspend_flag = 1;
|
||||
pkeyboard->hid_suspend_flag = 1;
|
||||
/* ...user code... */
|
||||
|
||||
break;
|
||||
@@ -437,13 +436,13 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
* @param len: report length
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len)
|
||||
usb_sts_type usb_keyboard_class_send_report(void *udev, uint8_t *report, uint16_t len)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
if(usbd_connect_state_get(pudev) == USB_CONN_STATE_CONFIGURED)
|
||||
usbd_ept_send(pudev, USBD_HID_IN_EPT, report, len);
|
||||
usbd_ept_send(pudev, USBD_KEYBOARD_IN_EPT, report, len);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -458,8 +457,8 @@ usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len)
|
||||
void usb_hid_keyboard_send_char(void *udev, uint8_t ascii_code)
|
||||
{
|
||||
uint8_t key_data = 0;
|
||||
static uint8_t temp = 0;
|
||||
static uint8_t keyboard_buf[8] = {0, 0, 6, 0, 0, 0, 0, 0};
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
keyboard_type *pkeyboard = (keyboard_type *)pudev->class_handler->pdata;
|
||||
|
||||
if(ascii_code > 128)
|
||||
{
|
||||
@@ -480,17 +479,17 @@ void usb_hid_keyboard_send_char(void *udev, uint8_t ascii_code)
|
||||
}
|
||||
}
|
||||
|
||||
if((temp == ascii_code) && (ascii_code != 0))
|
||||
if((pkeyboard->temp == ascii_code) && (ascii_code != 0))
|
||||
{
|
||||
keyboard_buf[0] = 0;
|
||||
keyboard_buf[2] = 0;
|
||||
class_send_report(udev, keyboard_buf, 8);
|
||||
pkeyboard->keyboard_buf[0] = 0;
|
||||
pkeyboard->keyboard_buf[2] = 0;
|
||||
usb_keyboard_class_send_report(udev, pkeyboard->keyboard_buf, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
keyboard_buf[0] = key_data;
|
||||
keyboard_buf[2] = ascii_code;
|
||||
class_send_report(udev, keyboard_buf, 8);
|
||||
pkeyboard->keyboard_buf[0] = key_data;
|
||||
pkeyboard->keyboard_buf[2] = ascii_code;
|
||||
usb_keyboard_class_send_report(udev, pkeyboard->keyboard_buf, 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file keyboard_class.h
|
||||
* @version v2.0.6
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.7
|
||||
* @date 2022-02-11
|
||||
* @brief usb hid keyboard header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -50,45 +50,40 @@ extern "C" {
|
||||
/**
|
||||
* @brief usb hid use endpoint define
|
||||
*/
|
||||
#define USBD_HID_IN_EPT 0x81
|
||||
#define USBD_KEYBOARD_IN_EPT 0x81
|
||||
|
||||
/**
|
||||
* @brief usb hid in and out max packet size define
|
||||
*/
|
||||
#define USBD_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_OUT_MAXPACKET_SIZE 0x40
|
||||
#define USBD_KEYBOARD_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_KEYBOARD_OUT_MAXPACKET_SIZE 0x40
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_hid_class_request_code_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t hid_protocol;
|
||||
uint32_t hid_set_idle;
|
||||
uint32_t alt_setting;
|
||||
uint8_t hid_set_report[64];
|
||||
uint8_t keyboard_buf[8];
|
||||
|
||||
/**
|
||||
* @brief usb hid class request code define
|
||||
*/
|
||||
#define HID_REQ_SET_PROTOCOL 0x0B
|
||||
#define HID_REQ_GET_PROTOCOL 0x03
|
||||
#define HID_REQ_SET_IDLE 0x0A
|
||||
#define HID_REQ_GET_IDLE 0x02
|
||||
#define HID_REQ_SET_REPORT 0x09
|
||||
#define HID_REQ_GET_REPORT 0x01
|
||||
#define HID_DESCRIPTOR_TYPE 0x21
|
||||
#define HID_REPORT_DESC 0x22
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
__IO uint8_t hid_suspend_flag;
|
||||
__IO uint8_t g_u8tx_completed;
|
||||
uint8_t hid_state;
|
||||
uint8_t temp;
|
||||
|
||||
}keyboard_type;
|
||||
|
||||
/** @defgroup USB_hid_class_exported_functions
|
||||
* @{
|
||||
*/
|
||||
extern usbd_class_handler keyboard_class_handler;
|
||||
extern __IO uint8_t g_u8tx_completed;
|
||||
|
||||
usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len);
|
||||
usb_sts_type usb_keyboard_class_send_report(void *udev, uint8_t *report, uint16_t len);
|
||||
void usb_hid_keyboard_send_char(void *udev, uint8_t ascii_code);
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file keyboard_desc.c
|
||||
* @version v2.0.6
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.7
|
||||
* @date 2022-02-11
|
||||
* @brief usb hid keyboard device descriptor
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -41,18 +41,18 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
usbd_desc_t *get_device_descriptor(void);
|
||||
usbd_desc_t *get_device_qualifier(void);
|
||||
usbd_desc_t *get_device_configuration(void);
|
||||
usbd_desc_t *get_device_other_speed(void);
|
||||
usbd_desc_t *get_device_lang_id(void);
|
||||
usbd_desc_t *get_device_manufacturer_string(void);
|
||||
usbd_desc_t *get_device_product_string(void);
|
||||
usbd_desc_t *get_device_serial_string(void);
|
||||
usbd_desc_t *get_device_interface_string(void);
|
||||
usbd_desc_t *get_device_config_string(void);
|
||||
static usbd_desc_t *get_device_descriptor(void);
|
||||
static usbd_desc_t *get_device_qualifier(void);
|
||||
static usbd_desc_t *get_device_configuration(void);
|
||||
static usbd_desc_t *get_device_other_speed(void);
|
||||
static usbd_desc_t *get_device_lang_id(void);
|
||||
static usbd_desc_t *get_device_manufacturer_string(void);
|
||||
static usbd_desc_t *get_device_product_string(void);
|
||||
static usbd_desc_t *get_device_serial_string(void);
|
||||
static usbd_desc_t *get_device_interface_string(void);
|
||||
static usbd_desc_t *get_device_config_string(void);
|
||||
|
||||
uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf);
|
||||
static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf);
|
||||
static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len);
|
||||
static void get_serial_num(void);
|
||||
static uint8_t g_usbd_desc_buffer[256];
|
||||
@@ -80,7 +80,7 @@ usbd_desc_handler keyboard_desc_handler =
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD static uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL =
|
||||
{
|
||||
USB_DEVICE_DESC_LEN, /* bLength */
|
||||
USB_DESCIPTOR_TYPE_DEVICE, /* bDescriptorType */
|
||||
@@ -90,10 +90,10 @@ ALIGNED_HEAD uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL =
|
||||
0x00, /* bDeviceSubClass */
|
||||
0x00, /* bDeviceProtocol */
|
||||
USB_MAX_EP0_SIZE, /* bMaxPacketSize */
|
||||
LBYTE(USBD_VENDOR_ID), /* idVendor */
|
||||
HBYTE(USBD_VENDOR_ID), /* idVendor */
|
||||
LBYTE(USBD_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_PRODUCT_ID), /* idProduct */
|
||||
LBYTE(USBD_KEYBOARD_VENDOR_ID), /* idVendor */
|
||||
HBYTE(USBD_KEYBOARD_VENDOR_ID), /* idVendor */
|
||||
LBYTE(USBD_KEYBOARD_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_KEYBOARD_PRODUCT_ID), /* idProduct */
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
USB_MFC_STRING, /* Index of manufacturer string */
|
||||
@@ -108,17 +108,17 @@ ALIGNED_HEAD uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL =
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD static uint8_t g_usbd_configuration[USBD_KEYBOARD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
{
|
||||
USB_DEVICE_CFG_DESC_LEN, /* bLength: configuration descriptor size */
|
||||
USB_DESCIPTOR_TYPE_CONFIGURATION, /* bDescriptorType: configuration */
|
||||
LBYTE(USBD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
HBYTE(USBD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
LBYTE(USBD_KEYBOARD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
HBYTE(USBD_KEYBOARD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
0x01, /* bNumInterfaces: 1 interface */
|
||||
0x01, /* bConfigurationValue: configuration value */
|
||||
0x00, /* iConfiguration: index of string descriptor describing
|
||||
the configuration */
|
||||
0xE0, /* bmAttributes: self powered ans support remote wakeup*/
|
||||
0xE0, /* bmAttributes: self powered and support remote wakeup*/
|
||||
0x32, /* MaxPower 100 mA: this current is used for detecting vbus */
|
||||
|
||||
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
|
||||
@@ -133,21 +133,21 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
LBYTE(HID_BCD_NUM),
|
||||
HBYTE(HID_BCD_NUM), /* bcdHID: HID class specification release number */
|
||||
LBYTE(KEYBOARD_BCD_NUM),
|
||||
HBYTE(KEYBOARD_BCD_NUM), /* bcdHID: HID class specification release number */
|
||||
0x00, /* bCountryCode: hardware target conutry */
|
||||
0x01, /* bNumDescriptors: number of HID class descriptor to follow */
|
||||
HID_CLASS_DESC_REPORT, /* bDescriptorType: report descriptor type */
|
||||
LBYTE(sizeof(g_usbd_hid_report)),
|
||||
HBYTE(sizeof(g_usbd_hid_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
LBYTE(sizeof(g_usbd_keyboard_report)),
|
||||
HBYTE(sizeof(g_usbd_keyboard_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_HID_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USBD_KEYBOARD_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_INTERRUPT, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
LBYTE(USBD_KEYBOARD_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_KEYBOARD_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
KEYBOARD_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -156,7 +156,7 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_usbd_hid_report[USBD_HID_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_usbd_keyboard_report[USBD_KEYBOARD_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x06, // USAGE (Keyboard)
|
||||
@@ -198,17 +198,17 @@ ALIGNED_HEAD uint8_t g_usbd_hid_report[USBD_HID_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_hid_usb_desc[9] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_keyboard_usb_desc[9] ALIGNED_TAIL =
|
||||
{
|
||||
0x09, /* bLength: size of HID descriptor in bytes */
|
||||
HID_CLASS_DESC_HID, /* bDescriptorType: HID descriptor type */
|
||||
LBYTE(HID_BCD_NUM),
|
||||
HBYTE(HID_BCD_NUM), /* bcdHID: HID class specification release number */
|
||||
LBYTE(KEYBOARD_BCD_NUM),
|
||||
HBYTE(KEYBOARD_BCD_NUM), /* bcdHID: HID class specification release number */
|
||||
0x00, /* bCountryCode: hardware target conutry */
|
||||
0x01, /* bNumDescriptors: number of HID class descriptor to follow */
|
||||
HID_CLASS_DESC_REPORT, /* bDescriptorType: report descriptor type */
|
||||
LBYTE(sizeof(g_usbd_hid_report)),
|
||||
HBYTE(sizeof(g_usbd_hid_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
LBYTE(sizeof(g_usbd_keyboard_report)),
|
||||
HBYTE(sizeof(g_usbd_keyboard_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
};
|
||||
|
||||
|
||||
@@ -218,9 +218,9 @@ ALIGNED_HEAD uint8_t g_hid_usb_desc[9] ALIGNED_TAIL =
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_string_lang_id[USBD_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD static uint8_t g_string_lang_id[USBD_KEYBOARD_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_KEYBOARD_SIZ_STRING_LANGID,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
0x09,
|
||||
0x04,
|
||||
@@ -232,42 +232,42 @@ ALIGNED_HEAD uint8_t g_string_lang_id[USBD_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
ALIGNED_HEAD uint8_t g_string_serial[USBD_SIZ_STRING_SERIAL] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD static uint8_t g_string_serial[USBD_KEYBOARD_SIZ_STRING_SERIAL] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_SERIAL,
|
||||
USBD_KEYBOARD_SIZ_STRING_SERIAL,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
};
|
||||
|
||||
|
||||
/* device descriptor */
|
||||
usbd_desc_t device_descriptor =
|
||||
static usbd_desc_t device_descriptor =
|
||||
{
|
||||
USB_DEVICE_DESC_LEN,
|
||||
g_usbd_descriptor
|
||||
};
|
||||
|
||||
/* config descriptor */
|
||||
usbd_desc_t config_descriptor =
|
||||
static usbd_desc_t config_descriptor =
|
||||
{
|
||||
USBD_CONFIG_DESC_SIZE,
|
||||
USBD_KEYBOARD_CONFIG_DESC_SIZE,
|
||||
g_usbd_configuration
|
||||
};
|
||||
|
||||
/* langid descriptor */
|
||||
usbd_desc_t langid_descriptor =
|
||||
static usbd_desc_t langid_descriptor =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_KEYBOARD_SIZ_STRING_LANGID,
|
||||
g_string_lang_id
|
||||
};
|
||||
|
||||
/* serial descriptor */
|
||||
usbd_desc_t serial_descriptor =
|
||||
static usbd_desc_t serial_descriptor =
|
||||
{
|
||||
USBD_SIZ_STRING_SERIAL,
|
||||
USBD_KEYBOARD_SIZ_STRING_SERIAL,
|
||||
g_string_serial
|
||||
};
|
||||
|
||||
usbd_desc_t vp_desc;
|
||||
static usbd_desc_t vp_desc;
|
||||
|
||||
/**
|
||||
* @brief standard usb unicode convert
|
||||
@@ -275,7 +275,7 @@ usbd_desc_t vp_desc;
|
||||
* @param unicode_buf: unicode buffer
|
||||
* @retval length
|
||||
*/
|
||||
uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
static uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf)
|
||||
{
|
||||
uint16_t str_len = 0, id_pos = 2;
|
||||
uint8_t *tmp_str = string;
|
||||
@@ -349,7 +349,7 @@ static void get_serial_num(void)
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_descriptor(void)
|
||||
static usbd_desc_t *get_device_descriptor(void)
|
||||
{
|
||||
return &device_descriptor;
|
||||
}
|
||||
@@ -359,7 +359,7 @@ usbd_desc_t *get_device_descriptor(void)
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t * get_device_qualifier(void)
|
||||
static usbd_desc_t * get_device_qualifier(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -369,7 +369,7 @@ usbd_desc_t * get_device_qualifier(void)
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_configuration(void)
|
||||
static usbd_desc_t *get_device_configuration(void)
|
||||
{
|
||||
return &config_descriptor;
|
||||
}
|
||||
@@ -379,7 +379,7 @@ usbd_desc_t *get_device_configuration(void)
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_other_speed(void)
|
||||
static usbd_desc_t *get_device_other_speed(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -389,7 +389,7 @@ usbd_desc_t *get_device_other_speed(void)
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_lang_id(void)
|
||||
static usbd_desc_t *get_device_lang_id(void)
|
||||
{
|
||||
return &langid_descriptor;
|
||||
}
|
||||
@@ -400,9 +400,9 @@ usbd_desc_t *get_device_lang_id(void)
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_manufacturer_string(void)
|
||||
static usbd_desc_t *get_device_manufacturer_string(void)
|
||||
{
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_KEYBOARD_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -412,9 +412,9 @@ usbd_desc_t *get_device_manufacturer_string(void)
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_product_string(void)
|
||||
static usbd_desc_t *get_device_product_string(void)
|
||||
{
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_KEYBOARD_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -424,7 +424,7 @@ usbd_desc_t *get_device_product_string(void)
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_serial_string(void)
|
||||
static usbd_desc_t *get_device_serial_string(void)
|
||||
{
|
||||
get_serial_num();
|
||||
return &serial_descriptor;
|
||||
@@ -435,9 +435,9 @@ usbd_desc_t *get_device_serial_string(void)
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_interface_string(void)
|
||||
static usbd_desc_t *get_device_interface_string(void)
|
||||
{
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_KEYBOARD_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -447,9 +447,9 @@ usbd_desc_t *get_device_interface_string(void)
|
||||
* @param none
|
||||
* @retval usbd_desc
|
||||
*/
|
||||
usbd_desc_t *get_device_config_string(void)
|
||||
static usbd_desc_t *get_device_config_string(void)
|
||||
{
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_KEYBOARD_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file keyboard_desc.h
|
||||
* @version v2.0.6
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.7
|
||||
* @date 2022-02-11
|
||||
* @brief usb keyboard descriptor header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -50,41 +50,34 @@ extern "C" {
|
||||
/**
|
||||
* @brief usb bcd number define
|
||||
*/
|
||||
#define HID_BCD_NUM 0x0110
|
||||
|
||||
/**
|
||||
* @brief usb hid class descriptor define
|
||||
*/
|
||||
#define HID_CLASS_DESC_HID 0x21
|
||||
#define HID_CLASS_DESC_REPORT 0x22
|
||||
#define HID_CLASS_DESC_PHYSICAL 0x23
|
||||
#define KEYBOARD_BCD_NUM 0x0110
|
||||
|
||||
/**
|
||||
* @brief usb vendor id and product id define
|
||||
*/
|
||||
#define USBD_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRODUCT_ID 0x6040
|
||||
#define USBD_KEYBOARD_VENDOR_ID 0x2E3C
|
||||
#define USBD_KEYBOARD_PRODUCT_ID 0x6040
|
||||
|
||||
/**
|
||||
* @brief usb descriptor size define
|
||||
*/
|
||||
#define USBD_CONFIG_DESC_SIZE 34
|
||||
#define USBD_HID_SIZ_REPORT_DESC 63
|
||||
#define USBD_SIZ_STRING_LANGID 4
|
||||
#define USBD_SIZ_STRING_SERIAL 0x1A
|
||||
#define USBD_KEYBOARD_CONFIG_DESC_SIZE 34
|
||||
#define USBD_KEYBOARD_SIZ_REPORT_DESC 63
|
||||
#define USBD_KEYBOARD_SIZ_STRING_LANGID 4
|
||||
#define USBD_KEYBOARD_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
/**
|
||||
* @brief usb string define(vendor, product configuration, interface)
|
||||
*/
|
||||
#define USBD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_DESC_PRODUCT_STRING "Keyboard"
|
||||
#define USBD_DESC_CONFIGURATION_STRING "Keyboard Config"
|
||||
#define USBD_DESC_INTERFACE_STRING "Keyboard Interface"
|
||||
#define USBD_KEYBOARD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_KEYBOARD_DESC_PRODUCT_STRING "Keyboard"
|
||||
#define USBD_KEYBOARD_DESC_CONFIGURATION_STRING "Keyboard Config"
|
||||
#define USBD_KEYBOARD_DESC_INTERFACE_STRING "Keyboard Interface"
|
||||
|
||||
/**
|
||||
* @brief usb hid endpoint interval define
|
||||
*/
|
||||
#define HID_BINTERVAL_TIME 0x0A
|
||||
#define KEYBOARD_BINTERVAL_TIME 0x0A
|
||||
|
||||
/**
|
||||
* @brief usb mcu id address deine
|
||||
@@ -96,11 +89,8 @@ extern "C" {
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
extern uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN];
|
||||
extern uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE];
|
||||
extern uint8_t g_usbd_hid_report[USBD_HID_SIZ_REPORT_DESC];
|
||||
extern uint8_t g_hid_usb_desc[9];
|
||||
extern uint8_t g_usbd_keyboard_report[USBD_KEYBOARD_SIZ_REPORT_DESC];
|
||||
extern uint8_t g_keyboard_usb_desc[9];
|
||||
extern usbd_desc_handler keyboard_desc_handler;
|
||||
|
||||
/**
|
||||
@@ -110,10 +100,10 @@ extern usbd_desc_handler keyboard_desc_handler;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user