mirror of
https://github.com/ArteryTek/AT32F415_Firmware_Library.git
synced 2026-05-21 01:12:20 +00:00
update version to v2.0.3
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file i2c_application.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief the driver library of the i2c peripheral
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -94,6 +94,16 @@
|
||||
#define I2C_START 0
|
||||
#define I2C_END 1
|
||||
|
||||
/**
|
||||
* @brief initializes peripherals used by the i2c.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
__WEAK void i2c_lowlevel_init(i2c_handle_type* hi2c)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief i2c peripheral initialization.
|
||||
* @param hi2c: the handle points to the operation information.
|
||||
@@ -1290,13 +1300,13 @@ i2c_status_type i2c_slave_transmit_dma(i2c_handle_type* hi2c, uint8_t* pdata, ui
|
||||
* @brief write data to the memory device through polling mode.
|
||||
* @param hi2c: the handle points to the operation information.
|
||||
* @param address: memory device address.
|
||||
* @param memaddress: memory address.
|
||||
* @param mem_address: memory address.
|
||||
* @param pdata: data buffer.
|
||||
* @param size: data size.
|
||||
* @param timeout: maximum waiting time.
|
||||
* @retval i2c status.
|
||||
*/
|
||||
i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, uint16_t address, uint16_t memaddress, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
{
|
||||
/* initialization parameters */
|
||||
hi2c->pbuff = pdata;
|
||||
@@ -1335,7 +1345,7 @@ i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, uint16_t address, uint16
|
||||
}
|
||||
|
||||
/* send memory address */
|
||||
i2c_data_send(hi2c->i2cx, memaddress);
|
||||
i2c_data_send(hi2c->i2cx, mem_address);
|
||||
|
||||
while(size > 0)
|
||||
{
|
||||
@@ -1372,13 +1382,13 @@ i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, uint16_t address, uint16
|
||||
* @brief read data from memory device through polling mode.
|
||||
* @param hi2c: the handle points to the operation information.
|
||||
* @param address: memory device address.
|
||||
* @param memaddress: memory address.
|
||||
* @param mem_address: memory address.
|
||||
* @param pdata: data buffer.
|
||||
* @param size: data size.
|
||||
* @param timeout: maximum waiting time.
|
||||
* @retval i2c status.
|
||||
*/
|
||||
i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_t memaddress, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
{
|
||||
/* initialization parameters */
|
||||
hi2c->pbuff = pdata;
|
||||
@@ -1420,7 +1430,7 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
|
||||
}
|
||||
|
||||
/* send memory address */
|
||||
i2c_data_send(hi2c->i2cx, memaddress);
|
||||
i2c_data_send(hi2c->i2cx, mem_address);
|
||||
|
||||
/* wait for the tdbe falg to be set */
|
||||
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
|
||||
@@ -1578,13 +1588,13 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, uint16_t address, uint16_
|
||||
* @brief write data to the memory device through interrupt mode.
|
||||
* @param hi2c: the handle points to the operation information.
|
||||
* @param address: memory device address.
|
||||
* @param memaddress: memory address.
|
||||
* @param mem_address: memory address.
|
||||
* @param pdata: data buffer.
|
||||
* @param size: data size.
|
||||
* @param timeout: maximum waiting time.
|
||||
* @retval i2c status.
|
||||
*/
|
||||
i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, uint16_t address, uint16_t memaddress, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
{
|
||||
/* initialization parameters */
|
||||
hi2c->mode = I2C_INT_MA_TX;
|
||||
@@ -1627,7 +1637,7 @@ i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, uint16_t address, ui
|
||||
}
|
||||
|
||||
/* send memory address */
|
||||
i2c_data_send(hi2c->i2cx, memaddress);
|
||||
i2c_data_send(hi2c->i2cx, mem_address);
|
||||
|
||||
/* wait for the tdbe falg to be set */
|
||||
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
|
||||
@@ -1648,13 +1658,13 @@ i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, uint16_t address, ui
|
||||
* @brief read data from memory device through interrupt mode.
|
||||
* @param hi2c: the handle points to the operation information.
|
||||
* @param address: memory device address.
|
||||
* @param memaddress: memory address.
|
||||
* @param mem_address: memory address.
|
||||
* @param pdata: data buffer.
|
||||
* @param size: data size.
|
||||
* @param timeout: maximum waiting time.
|
||||
* @retval i2c status.
|
||||
*/
|
||||
i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uint16_t memaddress, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
{
|
||||
/* initialization parameters */
|
||||
hi2c->mode = I2C_INT_MA_RX;
|
||||
@@ -1697,7 +1707,7 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uin
|
||||
}
|
||||
|
||||
/* send memory address */
|
||||
i2c_data_send(hi2c->i2cx, memaddress);
|
||||
i2c_data_send(hi2c->i2cx, mem_address);
|
||||
|
||||
/* wait for the tdbe falg to be set */
|
||||
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
|
||||
@@ -1758,13 +1768,13 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, uint16_t address, uin
|
||||
* @brief write data to the memory device through dma mode.
|
||||
* @param hi2c: the handle points to the operation information.
|
||||
* @param address: memory device address.
|
||||
* @param memaddress: memory address.
|
||||
* @param mem_address: memory address.
|
||||
* @param pdata: data buffer.
|
||||
* @param size: data size.
|
||||
* @param timeout: maximum waiting time.
|
||||
* @retval i2c status.
|
||||
*/
|
||||
i2c_status_type i2c_memory_write_dma(i2c_handle_type* hi2c, uint16_t address, uint16_t memaddress, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
i2c_status_type i2c_memory_write_dma(i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
{
|
||||
/* initialization parameters */
|
||||
hi2c->mode = I2C_DMA_MA_TX;
|
||||
@@ -1813,7 +1823,7 @@ i2c_status_type i2c_memory_write_dma(i2c_handle_type* hi2c, uint16_t address, ui
|
||||
}
|
||||
|
||||
/* send memory address */
|
||||
i2c_data_send(hi2c->i2cx, memaddress);
|
||||
i2c_data_send(hi2c->i2cx, mem_address);
|
||||
|
||||
/* wait for the tdbe falg to be set */
|
||||
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
|
||||
@@ -1834,13 +1844,13 @@ i2c_status_type i2c_memory_write_dma(i2c_handle_type* hi2c, uint16_t address, ui
|
||||
* @brief read data from memory device through polling mode.
|
||||
* @param hi2c: the handle points to the operation information.
|
||||
* @param address: memory device address.
|
||||
* @param memaddress: memory address.
|
||||
* @param mem_address: memory address.
|
||||
* @param pdata: data buffer.
|
||||
* @param size: data size.
|
||||
* @param timeout: maximum waiting time.
|
||||
* @retval i2c status.
|
||||
*/
|
||||
i2c_status_type i2c_memory_read_dma(i2c_handle_type* hi2c, uint16_t address, uint16_t memaddress, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
i2c_status_type i2c_memory_read_dma(i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout)
|
||||
{
|
||||
/* initialization parameters */
|
||||
hi2c->mode = I2C_DMA_MA_RX;
|
||||
@@ -1892,7 +1902,7 @@ i2c_status_type i2c_memory_read_dma(i2c_handle_type* hi2c, uint16_t address, uin
|
||||
}
|
||||
|
||||
/* send memory address */
|
||||
i2c_data_send(hi2c->i2cx, memaddress);
|
||||
i2c_data_send(hi2c->i2cx, mem_address);
|
||||
|
||||
/* wait for the tdbe falg to be set */
|
||||
if(i2c_wait_flag(hi2c, I2C_TDBE_FLAG, RESET, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file i2c_application.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief i2c application libray header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -135,7 +135,9 @@ typedef struct
|
||||
|
||||
void i2c_config (i2c_handle_type* hi2c);
|
||||
void i2c_lowlevel_init (i2c_handle_type* hi2c);
|
||||
void i2c_reset_ctrl2_register (i2c_handle_type* hi2c);
|
||||
i2c_status_type i2c_wait_end (i2c_handle_type* hi2c, uint32_t timeout);
|
||||
i2c_status_type i2c_wait_flag (i2c_handle_type* hi2c, uint32_t flag, flag_status status, uint32_t event_check, uint32_t timeout);
|
||||
|
||||
i2c_status_type i2c_master_transmit (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_master_receive (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
@@ -152,12 +154,12 @@ i2c_status_type i2c_master_receive_dma (i2c_handle_type* hi2c, uint16_t addre
|
||||
i2c_status_type i2c_slave_transmit_dma (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_slave_receive_dma (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
|
||||
i2c_status_type i2c_memory_write (i2c_handle_type* hi2c, uint16_t address, uint16_t memaddress, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_write_int (i2c_handle_type* hi2c, uint16_t address, uint16_t memaddress, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_write_dma (i2c_handle_type* hi2c, uint16_t address, uint16_t memaddress, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_read (i2c_handle_type* hi2c, uint16_t address, uint16_t memaddress, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_read_int (i2c_handle_type* hi2c, uint16_t address, uint16_t memaddress, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_read_dma (i2c_handle_type* hi2c, uint16_t address, uint16_t memaddress, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_write (i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_write_int (i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_write_dma (i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_read (i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_read_int (i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
i2c_status_type i2c_memory_read_dma (i2c_handle_type* hi2c, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout);
|
||||
|
||||
void i2c_evt_irq_handler (i2c_handle_type* hi2c);
|
||||
void i2c_err_irq_handler (i2c_handle_type* hi2c);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usb_core.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb core header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usb_std.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb standard header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -186,6 +186,56 @@ typedef enum
|
||||
#define USB_EPT_DESC_FD_EPT 0x10 /*!< usb endpoint description fd */
|
||||
#define USB_EPT_DESC_FDDATA_EPT 0x20 /*!< usb endpoint description fddata */
|
||||
|
||||
/**
|
||||
* @brief usb cdc class descriptor define
|
||||
*/
|
||||
#define USBD_CDC_CS_INTERFACE 0x24
|
||||
#define USBD_CDC_CS_ENDPOINT 0x25
|
||||
|
||||
/**
|
||||
* @brief usb cdc class sub-type define
|
||||
*/
|
||||
#define USBD_CDC_SUBTYPE_HEADER 0x00
|
||||
#define USBD_CDC_SUBTYPE_CMF 0x01
|
||||
#define USBD_CDC_SUBTYPE_ACM 0x02
|
||||
#define USBD_CDC_SUBTYPE_UFD 0x06
|
||||
|
||||
/**
|
||||
* @brief usb cdc class request code define
|
||||
*/
|
||||
#define SET_LINE_CODING 0x20
|
||||
#define GET_LINE_CODING 0x21
|
||||
|
||||
/**
|
||||
* @brief usb cdc class set line coding struct
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t bitrate; /* line coding baud rate */
|
||||
uint8_t format; /* line coding foramt */
|
||||
uint8_t parity; /* line coding parity */
|
||||
uint8_t data; /* line coding data bit */
|
||||
}linecoding_type;
|
||||
|
||||
/**
|
||||
* @brief usb hid class descriptor define
|
||||
*/
|
||||
#define HID_CLASS_DESC_HID 0x21
|
||||
#define HID_CLASS_DESC_REPORT 0x22
|
||||
#define HID_CLASS_DESC_PHYSICAL 0x23
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
||||
/**
|
||||
* @brief endpoint 0 max size
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbd_core.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb device core header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -105,6 +105,7 @@ typedef struct
|
||||
usb_sts_type (*out_handler)(void *udev, uint8_t ept_num); /*!< usb class out transfer complete handler */
|
||||
usb_sts_type (*sof_handler)(void *udev); /*!< usb class sof handler */
|
||||
usb_sts_type (*event_handler)(void *udev, usbd_event_type event); /*!< usb class event handler */
|
||||
void *pdata; /*!< usb class data pointer */
|
||||
}usbd_class_handler;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbd_int.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb interrupt header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usb_sdr.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_core.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host core header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -240,11 +240,11 @@ typedef struct
|
||||
uint8_t hch_out; /*!< out channel number */
|
||||
uint8_t ept0_size; /*!< endpoint 0 size */
|
||||
uint8_t *buffer; /*!< endpoint 0 transfer buffer */
|
||||
usb_setup_type setup; /*!< control setup type */
|
||||
uint16_t len; /*!< transfer length */
|
||||
uint8_t err_cnt; /*!< error counter */
|
||||
uint16_t timer; /*!< transfer timer */
|
||||
uint32_t timer; /*!< transfer timer */
|
||||
ctrl_sts_type sts; /*!< control transfer status */
|
||||
usb_setup_type setup; /*!< control setup type */
|
||||
ctrl_ept0_sts_type state; /*!< endpoint 0 state */
|
||||
} usbh_ctrl_type;
|
||||
|
||||
@@ -345,7 +345,7 @@ void usbh_hc_open(usbh_core_type *uhost,
|
||||
uint8_t ept_num,
|
||||
uint8_t dev_address,
|
||||
uint8_t type,
|
||||
uint8_t maxpacket,
|
||||
uint16_t maxpacket,
|
||||
uint8_t speed);
|
||||
void usbh_active_vbus(usbh_core_type *uhost, confirm_state state);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_ctrl.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_int.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usb_core.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb driver
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbd_core.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb device driver
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbd_int.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb interrupt request
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbd_sdr.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb standard device request
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_core.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host driver
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -424,6 +424,10 @@ usb_sts_type usbh_cfg_default_init(usbh_core_type *uhost)
|
||||
/* default speed is full speed */
|
||||
uhost->dev.speed = USB_FULL_SPEED_CORE_ID;
|
||||
|
||||
uhost->timer = 0;
|
||||
|
||||
uhost->ctrl.err_cnt = 0;
|
||||
|
||||
/* free all channel */
|
||||
usbh_free_channel(uhost, uhost->ctrl.hch_in);
|
||||
usbh_free_channel(uhost, uhost->ctrl.hch_out);
|
||||
@@ -632,7 +636,7 @@ void usbh_hc_open(usbh_core_type *uhost,
|
||||
uint8_t ept_num,
|
||||
uint8_t dev_address,
|
||||
uint8_t type,
|
||||
uint8_t maxpacket,
|
||||
uint16_t maxpacket,
|
||||
uint8_t speed)
|
||||
{
|
||||
/* device address */
|
||||
@@ -741,16 +745,16 @@ usb_sts_type usbh_ctrl_result_check(usbh_core_type *uhost, ctrl_ept0_sts_type ne
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief auto alloc address (1...127)
|
||||
* @brief auto alloc address (1...20)
|
||||
* @param none
|
||||
* @retval address (1...127)
|
||||
* @retval address (1...20)
|
||||
*/
|
||||
uint8_t usbh_alloc_address(void)
|
||||
{
|
||||
static uint8_t address = 0;
|
||||
if(address == 127)
|
||||
address = 0;
|
||||
return address + 1;
|
||||
static uint8_t address = 1;
|
||||
if(address == 20)
|
||||
address = 1;
|
||||
return address ++;
|
||||
}
|
||||
|
||||
|
||||
@@ -1163,6 +1167,7 @@ usb_sts_type usbh_loop_handler(usbh_core_type *uhost)
|
||||
if(uhost->port_enable)
|
||||
{
|
||||
uhost->global_state = USBH_ATTACHED;
|
||||
usb_delay_ms(50);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_ctrl.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host control request
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -39,6 +39,9 @@
|
||||
/** @defgroup USBH_ctrl_private_functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* control timeout 5s */
|
||||
#define CTRL_TIMEOUT 5000
|
||||
|
||||
/**
|
||||
* @brief usb host control send setup packet
|
||||
@@ -158,15 +161,24 @@ usb_sts_type usbh_ctrl_setup_wait_handler(usbh_core_type *uhost, uint32_t *timeo
|
||||
uhost->ctrl.state = CONTROL_STATUS_IN;
|
||||
}
|
||||
}
|
||||
uhost->ctrl.timer = OTG_HOST(uhost->usb_reg)->hfnum_bit.frnum;
|
||||
status = USB_OK;
|
||||
}
|
||||
else if(urb_state == URB_ERROR)
|
||||
else if(urb_state == URB_ERROR || urb_state == URB_NOTREADY)
|
||||
{
|
||||
uhost->ctrl.state = CONTROL_ERROR;
|
||||
uhost->ctrl.sts = CTRL_XACTERR;
|
||||
status = USB_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* wait nak timeout 5s*/
|
||||
if(uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT)
|
||||
{
|
||||
uhost->ctrl.state = CONTROL_ERROR;
|
||||
uhost->ctrl.sts = CTRL_XACTERR;
|
||||
status = USB_ERROR;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -210,6 +222,17 @@ usb_sts_type usbh_ctrl_data_in_wait_handler(usbh_core_type *uhost, uint32_t time
|
||||
{
|
||||
uhost->ctrl.state = CONTROL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* wait nak timeout 5s*/
|
||||
if(uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT)
|
||||
{
|
||||
uhost->ctrl.state = CONTROL_ERROR;
|
||||
uhost->ctrl.sts = CTRL_XACTERR;
|
||||
status = USB_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -258,6 +281,16 @@ usb_sts_type usbh_ctrl_data_out_wait_handler(usbh_core_type *uhost, uint32_t tim
|
||||
{
|
||||
uhost->ctrl.state = CONTROL_DATA_OUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* wait nak timeout 5s*/
|
||||
if(uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT)
|
||||
{
|
||||
uhost->ctrl.state = CONTROL_ERROR;
|
||||
uhost->ctrl.sts = CTRL_XACTERR;
|
||||
status = USB_ERROR;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -301,6 +334,16 @@ usb_sts_type usbh_ctrl_status_in_wait_handler(usbh_core_type *uhost, uint32_t ti
|
||||
{
|
||||
uhost->ctrl.state = CONTROL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* wait nak timeout 5s*/
|
||||
if(uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT)
|
||||
{
|
||||
uhost->ctrl.state = CONTROL_ERROR;
|
||||
uhost->ctrl.sts = CTRL_XACTERR;
|
||||
status = USB_ERROR;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -347,6 +390,16 @@ usb_sts_type usbh_ctrl_status_out_wait_handler(usbh_core_type *uhost, uint32_t t
|
||||
{
|
||||
uhost->ctrl.state = CONTROL_STATUS_OUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* wait nak timeout 5s*/
|
||||
if(uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT)
|
||||
{
|
||||
uhost->ctrl.state = CONTROL_ERROR;
|
||||
uhost->ctrl.sts = CTRL_XACTERR;
|
||||
status = USB_ERROR;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -365,9 +418,9 @@ usb_sts_type usbh_ctrl_error_handler(usbh_core_type *uhost)
|
||||
else
|
||||
{
|
||||
uhost->ctrl.sts = CTRL_FAIL;
|
||||
uhost->global_state = USBH_DISCONNECT;
|
||||
uhost->global_state = USBH_ERROR_STATE;
|
||||
uhost->ctrl.err_cnt = 0;
|
||||
USBH_DEBUG("control error: device not response");
|
||||
USBH_DEBUG("control error: **** Device No Response ****");
|
||||
status = USB_ERROR;
|
||||
}
|
||||
return status;
|
||||
@@ -408,6 +461,7 @@ usb_sts_type usbh_ctrl_transfer_loop(usbh_core_type *uhost)
|
||||
{
|
||||
case CONTROL_SETUP:
|
||||
usbh_ctrl_setup_handler(uhost);
|
||||
uhost->ctrl.timer = uhost->timer;
|
||||
break;
|
||||
|
||||
case CONTROL_SETUP_WAIT:
|
||||
@@ -416,6 +470,7 @@ usb_sts_type usbh_ctrl_transfer_loop(usbh_core_type *uhost)
|
||||
|
||||
case CONTROL_DATA_IN:
|
||||
usbh_ctrl_data_in_handler(uhost);
|
||||
uhost->ctrl.timer = uhost->timer;
|
||||
break;
|
||||
|
||||
case CONTROL_DATA_IN_WAIT:
|
||||
@@ -424,6 +479,7 @@ usb_sts_type usbh_ctrl_transfer_loop(usbh_core_type *uhost)
|
||||
|
||||
case CONTROL_DATA_OUT:
|
||||
usbh_ctrl_data_out_handler(uhost);
|
||||
uhost->ctrl.timer = uhost->timer;
|
||||
break;
|
||||
|
||||
case CONTROL_DATA_OUT_WAIT:
|
||||
@@ -432,6 +488,7 @@ usb_sts_type usbh_ctrl_transfer_loop(usbh_core_type *uhost)
|
||||
|
||||
case CONTROL_STATUS_IN:
|
||||
usbh_ctrl_status_in_handler(uhost);
|
||||
uhost->ctrl.timer = uhost->timer;
|
||||
break;
|
||||
|
||||
case CONTROL_STATUS_IN_WAIT:
|
||||
@@ -440,6 +497,7 @@ usb_sts_type usbh_ctrl_transfer_loop(usbh_core_type *uhost)
|
||||
|
||||
case CONTROL_STATUS_OUT:
|
||||
usbh_ctrl_status_out_handler(uhost);
|
||||
uhost->ctrl.timer = uhost->timer;
|
||||
break;
|
||||
|
||||
case CONTROL_STATUS_OUT_WAIT:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_int.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host interrupt request
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -133,12 +133,9 @@ void usbh_sof_handler(usbh_core_type *uhost)
|
||||
void usbh_disconnect_handler(usbh_core_type *uhost)
|
||||
{
|
||||
otg_global_type *usbx = uhost->usb_reg;
|
||||
otg_host_type *usb_host = OTG_HOST(usbx);
|
||||
|
||||
uint8_t i_index;
|
||||
|
||||
usb_host->hprt &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG |
|
||||
USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET);
|
||||
|
||||
usb_host_disable(usbx);
|
||||
|
||||
uhost->conn_sts = 0;
|
||||
@@ -225,11 +222,25 @@ void usbh_hch_in_handler(usbh_core_type *uhost, uint8_t chn)
|
||||
else if(uhost->hch[chn].state == HCH_XACTERR ||
|
||||
uhost->hch[chn].state == HCH_DATATGLERR)
|
||||
{
|
||||
uhost->urb_state[chn] = URB_ERROR;
|
||||
|
||||
uhost->err_cnt[chn] ++;
|
||||
if(uhost->err_cnt[chn] > 3)
|
||||
{
|
||||
uhost->urb_state[chn] = URB_ERROR;
|
||||
uhost->err_cnt[chn] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
uhost->urb_state[chn] = URB_NOTREADY;
|
||||
}
|
||||
usb_chh->hcchar_bit.chdis = FALSE;
|
||||
usb_chh->hcchar_bit.chena = TRUE;
|
||||
}
|
||||
else if(uhost->hch[chn].state == HCH_NAK)
|
||||
{
|
||||
usb_chh->hcchar_bit.chdis = FALSE;
|
||||
usb_chh->hcchar_bit.chena = TRUE;
|
||||
uhost->urb_state[chn] = URB_NOTREADY;
|
||||
}
|
||||
usb_chh->hcint = USB_OTG_HC_CHHLTD_FLAG;
|
||||
}
|
||||
else if(hcint_value & USB_OTG_HC_XACTERR_FLAG)
|
||||
@@ -237,18 +248,22 @@ void usbh_hch_in_handler(usbh_core_type *uhost, uint8_t chn)
|
||||
usb_chh->hcintmsk_bit.chhltdmsk = TRUE;
|
||||
uhost->hch[chn].state = HCH_XACTERR;
|
||||
usb_hch_halt(usbx, chn);
|
||||
uhost->err_cnt[chn] ++;
|
||||
usb_chh->hcint = USB_OTG_HC_XACTERR_FLAG;
|
||||
}
|
||||
else if(hcint_value & USB_OTG_HC_NAK_FLAG)
|
||||
{
|
||||
if(usb_chh->hcchar_bit.eptype == EPT_INT_TYPE)
|
||||
{
|
||||
uhost->err_cnt[chn] = 0;
|
||||
usb_chh->hcintmsk_bit.chhltdmsk = TRUE;
|
||||
usb_hch_halt(usbx, chn);
|
||||
}
|
||||
else if(usb_chh->hcchar_bit.eptype == EPT_BULK_TYPE ||
|
||||
usb_chh->hcchar_bit.eptype == EPT_CONTROL_TYPE)
|
||||
{
|
||||
uhost->err_cnt[chn] = 0;
|
||||
usb_chh->hcintmsk_bit.chhltdmsk = TRUE;
|
||||
usb_chh->hcchar_bit.chdis = FALSE;
|
||||
usb_chh->hcchar_bit.chena = TRUE;
|
||||
}
|
||||
@@ -310,7 +325,8 @@ void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn)
|
||||
if(uhost->hch[chn].state == HCH_XFRC)
|
||||
{
|
||||
uhost->urb_state[chn] = URB_DONE;
|
||||
if(uhost->hch[chn].ept_type == EPT_BULK_TYPE)
|
||||
if(uhost->hch[chn].ept_type == EPT_BULK_TYPE ||
|
||||
uhost->hch[chn].ept_type == EPT_INT_TYPE)
|
||||
{
|
||||
uhost->hch[chn].toggle_out ^= 1;
|
||||
}
|
||||
@@ -326,7 +342,16 @@ void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn)
|
||||
else if(uhost->hch[chn].state == HCH_XACTERR ||
|
||||
uhost->hch[chn].state == HCH_DATATGLERR)
|
||||
{
|
||||
uhost->urb_state[chn] = URB_ERROR;
|
||||
uhost->err_cnt[chn] ++;
|
||||
if(uhost->err_cnt[chn] > 3)
|
||||
{
|
||||
uhost->urb_state[chn] = URB_ERROR;
|
||||
uhost->err_cnt[chn] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
uhost->urb_state[chn] = URB_NOTREADY;
|
||||
}
|
||||
|
||||
usb_chh->hcchar_bit.chdis = FALSE;
|
||||
usb_chh->hcchar_bit.chena = TRUE;
|
||||
@@ -336,6 +361,7 @@ void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn)
|
||||
else if( hcint_value & USB_OTG_HC_XACTERR_FLAG)
|
||||
{
|
||||
usb_chh->hcintmsk_bit.chhltdmsk = TRUE;
|
||||
uhost->err_cnt[chn] ++;
|
||||
uhost->hch[chn].state = HCH_XACTERR;
|
||||
usb_hch_halt(usbx, chn);
|
||||
usb_chh->hcint = USB_OTG_HC_XACTERR_FLAG | USB_OTG_HC_NAK_FLAG;
|
||||
@@ -343,6 +369,7 @@ void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn)
|
||||
else if( hcint_value & USB_OTG_HC_NAK_FLAG)
|
||||
{
|
||||
usb_chh->hcintmsk_bit.chhltdmsk = TRUE;
|
||||
uhost->err_cnt[chn] = 0;
|
||||
usb_hch_halt(usbx, chn);
|
||||
uhost->hch[chn].state = HCH_NAK;
|
||||
usb_chh->hcint = USB_OTG_HC_NAK_FLAG;
|
||||
@@ -477,8 +504,7 @@ void usbh_port_handler(usbh_core_type *uhost)
|
||||
else
|
||||
{
|
||||
/* clean up hprt */
|
||||
usb_host->hprt &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG |
|
||||
USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET);
|
||||
uhost->port_enable = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_class.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb audio class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -41,29 +41,27 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
void audio_inisoincom_event(void *udev);
|
||||
void audio_req_get_cur(void *udev, usb_setup_type *setup);
|
||||
void audio_req_set_cur(void *udev, usb_setup_type *setup);
|
||||
void audio_req_get_min(void *udev, usb_setup_type *setup);
|
||||
void audio_req_get_max(void *udev, usb_setup_type *setup);
|
||||
void audio_req_get_res(void *udev, usb_setup_type *setup);
|
||||
void audio_get_interface(void *udev, usb_setup_type *setup);
|
||||
void audio_set_interface(void *udev, usb_setup_type *setup);
|
||||
static void audio_inisoincom_event(void *udev);
|
||||
static void audio_req_get_cur(void *udev, usb_setup_type *setup);
|
||||
static void audio_req_set_cur(void *udev, usb_setup_type *setup);
|
||||
static void audio_req_get_min(void *udev, usb_setup_type *setup);
|
||||
static void audio_req_get_max(void *udev, usb_setup_type *setup);
|
||||
static void audio_req_get_res(void *udev, usb_setup_type *setup);
|
||||
static void audio_get_interface(void *udev, usb_setup_type *setup);
|
||||
static void audio_set_interface(void *udev, usb_setup_type *setup);
|
||||
|
||||
usb_audio_type audio_struct = {0, 0, 0, 0, 0, 0x1400, 0, 0, 0, {0x0000, 0x1400, 0x33}, {0x0000, 0x1400, 0x33}};
|
||||
usb_audio_type audio_struct = {0, 0, 0, 0, 0, 0x1400, 0, 0, 0, {0x0000, 0x1400, 0x33}, {0x0000, 0x1400, 0x33}, 0, 0};
|
||||
|
||||
static __IO uint16_t audio_feedback_state = 0;
|
||||
static __IO uint8_t audio_spk_out_stage = 0;
|
||||
/* usb device class handler */
|
||||
usbd_class_handler audio_class_handler =
|
||||
{
|
||||
@@ -76,6 +74,7 @@ usbd_class_handler audio_class_handler =
|
||||
class_out_handler,
|
||||
class_sof_handler,
|
||||
class_event_handler,
|
||||
&audio_struct
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -83,10 +82,11 @@ usbd_class_handler audio_class_handler =
|
||||
* @param udev: usb device core handler 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;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* open microphone in endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUDIO_MIC_IN_EPT, EPT_ISO_TYPE, AUDIO_MIC_IN_MAXPACKET_SIZE);
|
||||
@@ -98,7 +98,7 @@ usb_sts_type class_init_handler(void *udev)
|
||||
usbd_ept_open(pudev, USBD_AUDIO_FEEDBACK_EPT, EPT_ISO_TYPE, AUDIO_FEEDBACK_MAXPACKET_SIZE);
|
||||
#endif
|
||||
/* start receive speaker out data */
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, audio_struct.audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, paudio->audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ usb_sts_type class_init_handler(void *udev)
|
||||
* @param udev: usb device core handler 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;
|
||||
@@ -133,7 +133,7 @@ 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;
|
||||
@@ -177,8 +177,9 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
case USB_STD_REQ_GET_DESCRIPTOR:
|
||||
if((setup->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE)
|
||||
{
|
||||
usbd_desc_t *config = pudev->desc_handler->get_device_configuration();
|
||||
len = MIN(AUDIO_DESCRIPTOR_SIZE, setup->wLength);
|
||||
usbd_ctrl_send(pudev, g_usbd_configuration+18, len);
|
||||
usbd_ctrl_send(pudev, config->descriptor + 18, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -211,7 +212,7 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
* @param udev: usb device core handler 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;
|
||||
|
||||
@@ -225,60 +226,61 @@ usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
* @param udev: usb device core handler 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;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
uint32_t recv_len = usbd_get_recv_len(pudev, 0);
|
||||
/* ...user code... */
|
||||
if( audio_struct.audio_cmd == AUDIO_REQ_SET_CUR)
|
||||
if( paudio->audio_cmd == AUDIO_REQ_SET_CUR)
|
||||
{
|
||||
/* class process */
|
||||
switch(audio_struct.request_no)
|
||||
switch( paudio->request_no)
|
||||
{
|
||||
case AUDIO_VOLUME_CONTROL:
|
||||
if(audio_struct.interface == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
if( paudio->interface == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
audio_struct.spk_volume = (uint16_t)(audio_struct.g_audio_cur[0] |
|
||||
(audio_struct.g_audio_cur[1] << 8));
|
||||
paudio->spk_volume = (uint16_t)( paudio->g_audio_cur[0] |
|
||||
( paudio->g_audio_cur[1] << 8));
|
||||
/* set volume */
|
||||
audio_codec_set_spk_volume(audio_struct.spk_volume*100/audio_struct.spk_volume_limits[1]);
|
||||
audio_codec_set_spk_volume(paudio->spk_volume*100/paudio->spk_volume_limits[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_struct.mic_volume = (uint16_t)(audio_struct.g_audio_cur[0] |
|
||||
(audio_struct.g_audio_cur[1] << 8));
|
||||
paudio->mic_volume = (uint16_t)(paudio->g_audio_cur[0] |
|
||||
(paudio->g_audio_cur[1] << 8));
|
||||
|
||||
audio_codec_set_mic_volume(audio_struct.mic_volume*256/audio_struct.mic_volume_limits[1]);
|
||||
audio_codec_set_mic_volume(paudio->mic_volume*256/paudio->mic_volume_limits[1]);
|
||||
}
|
||||
break;
|
||||
case AUDIO_MUTE_CONTROL:
|
||||
if(audio_struct.interface == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
if(paudio->interface == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
audio_struct.spk_mute = audio_struct.g_audio_cur[0];
|
||||
audio_codec_set_spk_mute(audio_struct.spk_mute);
|
||||
paudio->spk_mute = paudio->g_audio_cur[0];
|
||||
audio_codec_set_spk_mute(paudio->spk_mute);
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_struct.mic_mute = audio_struct.g_audio_cur[0];
|
||||
audio_codec_set_mic_mute(audio_struct.mic_mute);
|
||||
paudio->mic_mute = paudio->g_audio_cur[0];
|
||||
audio_codec_set_mic_mute(paudio->mic_mute);
|
||||
}
|
||||
|
||||
break;
|
||||
case AUDIO_FREQ_SET_CONTROL:
|
||||
if(audio_struct.enpd == USBD_AUDIO_MIC_IN_EPT)
|
||||
if(paudio->enpd == USBD_AUDIO_MIC_IN_EPT)
|
||||
{
|
||||
audio_struct.mic_freq = (audio_struct.g_audio_cur[0] |
|
||||
(audio_struct.g_audio_cur[1] << 8) |
|
||||
(audio_struct.g_audio_cur[2] << 16));
|
||||
audio_codec_set_mic_freq(audio_struct.mic_freq);
|
||||
paudio->mic_freq = (paudio->g_audio_cur[0] |
|
||||
(paudio->g_audio_cur[1] << 8) |
|
||||
(paudio->g_audio_cur[2] << 16));
|
||||
audio_codec_set_mic_freq(paudio->mic_freq);
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_struct.spk_freq = (audio_struct.g_audio_cur[0] |
|
||||
(audio_struct.g_audio_cur[1] << 8) |
|
||||
(audio_struct.g_audio_cur[2] << 16));
|
||||
audio_codec_set_spk_freq(audio_struct.spk_freq);
|
||||
paudio->spk_freq = (paudio->g_audio_cur[0] |
|
||||
(paudio->g_audio_cur[1] << 8) |
|
||||
(paudio->g_audio_cur[2] << 16));
|
||||
audio_codec_set_spk_freq(paudio->spk_freq);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -295,9 +297,11 @@ 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;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
uint32_t len = 0;
|
||||
|
||||
/* ...user code...
|
||||
@@ -305,14 +309,14 @@ usb_sts_type class_in_handler(void *udev, uint8_t ept_num)
|
||||
*/
|
||||
if((ept_num & 0x7F) == (USBD_AUDIO_MIC_IN_EPT & 0x7F))
|
||||
{
|
||||
len = audio_codec_mic_get_data(audio_struct.audio_mic_data);
|
||||
len = audio_codec_mic_get_data(paudio->audio_mic_data);
|
||||
usbd_flush_tx_fifo(udev, USBD_AUDIO_MIC_IN_EPT);
|
||||
usbd_ept_send(udev, USBD_AUDIO_MIC_IN_EPT, audio_struct.audio_mic_data, len);
|
||||
usbd_ept_send(udev, USBD_AUDIO_MIC_IN_EPT, paudio->audio_mic_data, len);
|
||||
}
|
||||
|
||||
else if((ept_num & 0x7F) == (USBD_AUDIO_FEEDBACK_EPT & 0x7F))
|
||||
{
|
||||
audio_feedback_state = 0;
|
||||
paudio->audio_feedback_state = 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -324,10 +328,11 @@ 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;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
uint16_t g_rxlen;
|
||||
|
||||
/* get endpoint receive data length */
|
||||
@@ -336,10 +341,10 @@ usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
if((ept_num & 0x7F) == (USBD_AUDIO_SPK_OUT_EPT & 0x7F))
|
||||
{
|
||||
/* speaker data*/
|
||||
audio_codec_spk_fifo_write(audio_struct.audio_spk_data, g_rxlen);
|
||||
audio_spk_out_stage = 1;
|
||||
audio_codec_spk_fifo_write(paudio->audio_spk_data, g_rxlen);
|
||||
paudio->audio_spk_out_stage = 1;
|
||||
/* get next data */
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, audio_struct.audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, paudio->audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -350,33 +355,35 @@ usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
* @param udev: usb device core handler 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;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
|
||||
#if AUDIO_SUPPORT_FEEDBACK
|
||||
if(audio_spk_out_stage & 2)
|
||||
if(paudio->audio_spk_out_stage & 2)
|
||||
{
|
||||
audio_spk_out_stage = 0;
|
||||
paudio->audio_spk_out_stage = 0;
|
||||
}
|
||||
else if( audio_spk_out_stage )
|
||||
else if( paudio->audio_spk_out_stage )
|
||||
{
|
||||
audio_spk_out_stage |= 2;
|
||||
paudio->audio_spk_out_stage |= 2;
|
||||
|
||||
if( 0 == audio_feedback_state )
|
||||
if( 0 == paudio->audio_feedback_state )
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
int len = audio_codec_spk_feedback(audio_struct.audio_feed_back);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, audio_struct.audio_feed_back, len);
|
||||
audio_feedback_state = 1;
|
||||
int len = audio_codec_spk_feedback(paudio->audio_feed_back);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, paudio->audio_feed_back, len);
|
||||
paudio->audio_feedback_state = 1;
|
||||
}
|
||||
if( audio_feedback_state++ > (1<<FEEDBACK_REFRESH_TIME) ) //timeout
|
||||
if( paudio->audio_feedback_state++ > (1<<FEEDBACK_REFRESH_TIME) ) //timeout
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
int len = audio_codec_spk_feedback(audio_struct.audio_feed_back);
|
||||
int len = audio_codec_spk_feedback(paudio->audio_feed_back);
|
||||
usbd_flush_tx_fifo(pudev, USBD_AUDIO_FEEDBACK_EPT);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, audio_struct.audio_feed_back, len);
|
||||
audio_feedback_state = 1;
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, paudio->audio_feed_back, len);
|
||||
paudio->audio_feedback_state = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -391,9 +398,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;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
@@ -402,10 +411,10 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
audio_struct.spk_alt_setting = 0;
|
||||
audio_codec_spk_alt_setting(audio_struct.spk_alt_setting);
|
||||
audio_struct.mic_alt_setting = 0;
|
||||
audio_codec_mic_alt_setting(audio_struct.spk_alt_setting);
|
||||
paudio->spk_alt_setting = 0;
|
||||
audio_codec_spk_alt_setting(paudio->spk_alt_setting);
|
||||
paudio->mic_alt_setting = 0;
|
||||
audio_codec_mic_alt_setting(paudio->spk_alt_setting);
|
||||
/* ...user code... */
|
||||
|
||||
break;
|
||||
@@ -428,10 +437,11 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
* @param udev: usb device core handler type
|
||||
* @retval none
|
||||
*/
|
||||
void audio_inisoincom_event(void *udev)
|
||||
static void audio_inisoincom_event(void *udev)
|
||||
{
|
||||
#if 0
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
uint32_t fnsof = OTG_DEVICE(pudev->usb_reg)->dsts_bit.soffn;
|
||||
uint32_t epctl_fb = USB_INEPT(pudev->usb_reg, (USBD_AUDIO_FEEDBACK_EPT&0x7F))->diepctl_bit.dpid;
|
||||
uint32_t epctl_in = USB_INEPT(pudev->usb_reg, (USBD_AUDIO_MIC_IN_EPT&0x7F))->diepctl_bit.dpid;
|
||||
@@ -443,7 +453,7 @@ void audio_inisoincom_event(void *udev)
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUDIO_FEEDBACK_EPT&0x7F))->diepctl_bit.snak = 1;
|
||||
usb_flush_tx_fifo(pudev->usb_reg, USBD_AUDIO_FEEDBACK_EPT&0x7F);
|
||||
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, audio_struct.audio_feed_back, 3);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, paudio->audio_feed_back, 3);
|
||||
}
|
||||
|
||||
if((fnsof & 0x1) == epctl_in)
|
||||
@@ -452,8 +462,8 @@ void audio_inisoincom_event(void *udev)
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUDIO_MIC_IN_EPT&0x7F))->diepctl_bit.snak = 1;
|
||||
usb_flush_tx_fifo(pudev->usb_reg, USBD_AUDIO_MIC_IN_EPT&0x7F);
|
||||
|
||||
len = audio_codec_mic_get_data(audio_struct.audio_mic_data);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_MIC_IN_EPT, audio_struct.audio_mic_data, len);
|
||||
len = audio_codec_mic_get_data(paudio->audio_mic_data);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_MIC_IN_EPT, paudio->audio_mic_data, len);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -464,33 +474,34 @@ void audio_inisoincom_event(void *udev)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_get_cur(void *udev, usb_setup_type *setup)
|
||||
static void audio_req_get_cur(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
if(HBYTE(setup->wIndex) == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
if(HBYTE(setup->wValue) == AUDIO_MUTE_CONTROL)
|
||||
{
|
||||
audio_struct.g_audio_cur[0] = audio_struct.spk_mute;
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
paudio->g_audio_cur[0] = paudio->spk_mute;
|
||||
usbd_ctrl_send(pudev, paudio->g_audio_cur, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.spk_volume;
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio->g_audio_cur) = paudio->spk_volume;
|
||||
usbd_ctrl_send(pudev, paudio->g_audio_cur, setup->wLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(HBYTE(setup->wValue) == AUDIO_MUTE_CONTROL)
|
||||
{
|
||||
audio_struct.g_audio_cur[0] = audio_struct.mic_mute;
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
paudio->g_audio_cur[0] = paudio->mic_mute;
|
||||
usbd_ctrl_send(pudev, paudio->g_audio_cur, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.mic_volume;
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio->g_audio_cur) = paudio->mic_volume;
|
||||
usbd_ctrl_send(pudev, paudio->g_audio_cur, setup->wLength);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -502,32 +513,33 @@ void audio_req_get_cur(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_set_cur(void *udev, usb_setup_type *setup)
|
||||
static void audio_req_set_cur(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
if(setup->wLength > 0)
|
||||
{
|
||||
usbd_ctrl_recv(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
usbd_ctrl_recv(pudev, paudio->g_audio_cur, setup->wLength);
|
||||
|
||||
audio_struct.audio_cmd = AUDIO_REQ_SET_CUR;
|
||||
audio_struct.audio_cmd_len = setup->wLength;
|
||||
paudio->audio_cmd = AUDIO_REQ_SET_CUR;
|
||||
paudio->audio_cmd_len = setup->wLength;
|
||||
|
||||
switch(setup->bmRequestType & AUDIO_REQ_CONTROL_MASK)
|
||||
{
|
||||
case AUDIO_REQ_CONTROL_INTERFACE:
|
||||
audio_struct.interface = HBYTE(setup->wIndex);
|
||||
paudio->interface = HBYTE(setup->wIndex);
|
||||
if(HBYTE(setup->wValue) == AUDIO_MUTE_CONTROL)
|
||||
{
|
||||
audio_struct.request_no = AUDIO_MUTE_CONTROL;
|
||||
paudio->request_no = AUDIO_MUTE_CONTROL;
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_struct.request_no = AUDIO_VOLUME_CONTROL;
|
||||
paudio->request_no = AUDIO_VOLUME_CONTROL;
|
||||
}
|
||||
break;
|
||||
case AUDIO_REQ_CONTROL_ENDPOINT:
|
||||
audio_struct.enpd = setup->wIndex;
|
||||
audio_struct.request_no = AUDIO_FREQ_SET_CONTROL;
|
||||
paudio->enpd = setup->wIndex;
|
||||
paudio->request_no = AUDIO_FREQ_SET_CONTROL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -541,18 +553,19 @@ void audio_req_set_cur(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_get_min(void *udev, usb_setup_type *setup)
|
||||
static void audio_req_get_min(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
if(HBYTE(setup->wIndex) == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.spk_volume_limits[0];
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio->g_audio_cur) = paudio->spk_volume_limits[0];
|
||||
usbd_ctrl_send(pudev, paudio->g_audio_cur, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.mic_volume_limits[0];
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio->g_audio_cur) = paudio->mic_volume_limits[0];
|
||||
usbd_ctrl_send(pudev, paudio->g_audio_cur, setup->wLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,18 +575,19 @@ void audio_req_get_min(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_get_max(void *udev, usb_setup_type *setup)
|
||||
static void audio_req_get_max(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
if(HBYTE(setup->wIndex) == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.spk_volume_limits[1];
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio->g_audio_cur) = paudio->spk_volume_limits[1];
|
||||
usbd_ctrl_send(pudev, paudio->g_audio_cur, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.mic_volume_limits[1];
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio->g_audio_cur) = paudio->mic_volume_limits[1];
|
||||
usbd_ctrl_send(pudev, paudio->g_audio_cur, setup->wLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -583,18 +597,19 @@ void audio_req_get_max(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_get_res(void *udev, usb_setup_type *setup)
|
||||
static void audio_req_get_res(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
if(HBYTE(setup->wIndex) == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.spk_volume_limits[2];
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio->g_audio_cur) = paudio->spk_volume_limits[2];
|
||||
usbd_ctrl_send(pudev, paudio->g_audio_cur, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.mic_volume_limits[2];
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio->g_audio_cur) = paudio->mic_volume_limits[2];
|
||||
usbd_ctrl_send(pudev, paudio->g_audio_cur, setup->wLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -604,28 +619,29 @@ void audio_req_get_res(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
static void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
uint32_t len;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
if(LBYTE(setup->wIndex) == AUDIO_SPK_INTERFACE_NUMBER)
|
||||
{
|
||||
audio_struct.spk_alt_setting = setup->wValue;
|
||||
audio_codec_spk_alt_setting(audio_struct.spk_alt_setting);
|
||||
if(audio_struct.spk_alt_setting )
|
||||
paudio->spk_alt_setting = setup->wValue;
|
||||
audio_codec_spk_alt_setting(paudio->spk_alt_setting);
|
||||
if(paudio->spk_alt_setting )
|
||||
{
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, audio_struct.audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, paudio->audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
}
|
||||
|
||||
}
|
||||
else if(LBYTE(setup->wIndex) == AUDIO_MIC_INTERFACE_NUMBER)
|
||||
{
|
||||
audio_struct.mic_alt_setting = setup->wValue;
|
||||
audio_codec_mic_alt_setting(audio_struct.mic_alt_setting);
|
||||
if(audio_struct.mic_alt_setting)
|
||||
paudio->mic_alt_setting = setup->wValue;
|
||||
audio_codec_mic_alt_setting(paudio->mic_alt_setting);
|
||||
if(paudio->mic_alt_setting)
|
||||
{
|
||||
len = audio_codec_mic_get_data(audio_struct.audio_mic_data);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_MIC_IN_EPT, audio_struct.audio_mic_data, len);
|
||||
len = audio_codec_mic_get_data(paudio->audio_mic_data);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_MIC_IN_EPT, paudio->audio_mic_data, len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -638,16 +654,17 @@ void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_get_interface(void *udev, usb_setup_type *setup)
|
||||
static void audio_get_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_type *paudio = (usb_audio_type *)pudev->class_handler->pdata;
|
||||
if(LBYTE(setup->wIndex) == AUDIO_SPK_INTERFACE_NUMBER)
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.spk_alt_setting, 1);
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&paudio->spk_alt_setting, 1);
|
||||
}
|
||||
else if(LBYTE(setup->wIndex) == AUDIO_MIC_INTERFACE_NUMBER)
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.mic_alt_setting, 1);
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&paudio->mic_alt_setting, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_class.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb audio class file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -108,6 +108,9 @@ typedef struct
|
||||
uint8_t audio_spk_data[AUDIO_SPK_OUT_MAXPACKET_SIZE];
|
||||
uint8_t audio_mic_data[AUDIO_MIC_IN_MAXPACKET_SIZE];
|
||||
uint8_t audio_feed_back[AUDIO_FEEDBACK_MAXPACKET_SIZE+1];
|
||||
|
||||
__IO uint16_t audio_feedback_state;
|
||||
__IO uint8_t audio_spk_out_stage;
|
||||
}usb_audio_type;
|
||||
|
||||
extern usbd_class_handler audio_class_handler;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_conf.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb audio config
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_desc.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb audio device descriptor
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -40,20 +40,18 @@
|
||||
/** @defgroup USB_audio_desc_private_functions
|
||||
* @{
|
||||
*/
|
||||
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);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
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];
|
||||
@@ -81,7 +79,7 @@ usbd_desc_handler audio_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 */
|
||||
@@ -91,10 +89,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_AUDIO_VENDOR_ID), /* idVendor */
|
||||
HBYTE(USBD_AUDIO_VENDOR_ID), /* idVendor */
|
||||
LBYTE(USBD_AUDIO_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_AUDIO_PRODUCT_ID), /* idProduct */
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
USB_MFC_STRING, /* Index of manufacturer string */
|
||||
@@ -109,12 +107,12 @@ 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_AUDIO_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_AUDIO_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
HBYTE(USBD_AUDIO_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
0x1 + AUDIO_INTERFACE_NUM, /* bNumInterfaces: n interface */
|
||||
0x01, /* bConfigurationValue: configuration value */
|
||||
0x00, /* iConfiguration: index of string descriptor describing
|
||||
@@ -135,8 +133,8 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
0x08+AUDIO_INTERFACE_NUM, /* bLength: size of this descriptor, in bytes 8+n */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: cs interface descriptor type */
|
||||
AUDIO_AC_HEADER, /* bDescriptorSubtype: Header function Descriptor*/
|
||||
LBYTE(BCD_NUM),
|
||||
HBYTE(BCD_NUM), /* bcdCDC: audio device class specification release number */
|
||||
LBYTE(AUDIO_BCD_NUM),
|
||||
HBYTE(AUDIO_BCD_NUM), /* bcdCDC: audio device class specification release number */
|
||||
LBYTE(AUDIO_INTERFACE_LEN),
|
||||
HBYTE(AUDIO_INTERFACE_LEN), /* wTotalLength: total number of bytes returned for the class-specific audio control interface */
|
||||
AUDIO_INTERFACE_NUM, /* bInClollection: the number of audio streaming */
|
||||
@@ -280,7 +278,7 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
USB_EPT_DESC_ISO | USB_ETP_DESC_ASYNC, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(AUDIO_MIC_IN_MAXPACKET_SIZE),
|
||||
HBYTE(AUDIO_MIC_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
AUDIO_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
0x00, /* bRefresh: unused */
|
||||
0x00, /* bSynchAddress: unused */
|
||||
|
||||
@@ -344,7 +342,7 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
USB_EPT_DESC_ISO | USB_ETP_DESC_ASYNC, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(AUDIO_SPK_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(AUDIO_SPK_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
AUDIO_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
0x00, /* bRefresh: unused */
|
||||
#if (AUDIO_SUPPORT_FEEDBACK == 1)
|
||||
USBD_AUDIO_FEEDBACK_EPT, /* bSynchAddress: feedback endpoint */
|
||||
@@ -384,9 +382,9 @@ 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_string_lang_id[USBD_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD static uint8_t g_string_lang_id[USBD_AUDIO_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_AUDIO_SIZ_STRING_LANGID,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
0x09,
|
||||
0x04,
|
||||
@@ -398,42 +396,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_AUDIO_SIZ_STRING_SERIAL] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_SERIAL,
|
||||
USBD_AUDIO_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_AUDIO_CONFIG_DESC_SIZE,
|
||||
g_usbd_configuration
|
||||
};
|
||||
|
||||
/* langid descriptor */
|
||||
usbd_desc_t langid_descriptor =
|
||||
static usbd_desc_t langid_descriptor =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_AUDIO_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_AUDIO_SIZ_STRING_SERIAL,
|
||||
g_string_serial
|
||||
};
|
||||
|
||||
usbd_desc_t vp_desc;
|
||||
static usbd_desc_t vp_desc;
|
||||
|
||||
/**
|
||||
* @brief standard usb unicode convert
|
||||
@@ -441,7 +439,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;
|
||||
@@ -515,7 +513,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;
|
||||
}
|
||||
@@ -525,7 +523,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;
|
||||
}
|
||||
@@ -535,7 +533,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;
|
||||
}
|
||||
@@ -545,7 +543,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;
|
||||
}
|
||||
@@ -555,7 +553,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;
|
||||
}
|
||||
@@ -566,9 +564,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_AUDIO_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -578,9 +576,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_AUDIO_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -590,7 +588,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;
|
||||
@@ -601,9 +599,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_AUDIO_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -613,9 +611,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_AUDIO_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_desc.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb audio descriptor header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -48,18 +48,18 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define BCD_NUM 0x0100
|
||||
#define AUDIO_BCD_NUM 0x0100
|
||||
|
||||
#define USBD_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRODUCT_ID 0x5730
|
||||
#define USBD_AUDIO_VENDOR_ID 0x2E3C
|
||||
#define USBD_AUDIO_PRODUCT_ID 0x5730
|
||||
|
||||
#define USBD_SIZ_STRING_LANGID 4
|
||||
#define USBD_SIZ_STRING_SERIAL 0x1A
|
||||
#define USBD_AUDIO_SIZ_STRING_LANGID 4
|
||||
#define USBD_AUDIO_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
#define USBD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_DESC_PRODUCT_STRING "AT32 Audio"
|
||||
#define USBD_DESC_CONFIGURATION_STRING "Audio Config"
|
||||
#define USBD_DESC_INTERFACE_STRING "Audio Interface"
|
||||
#define USBD_AUDIO_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_AUDIO_DESC_PRODUCT_STRING "AT32 Audio"
|
||||
#define USBD_AUDIO_DESC_CONFIGURATION_STRING "Audio Config"
|
||||
#define USBD_AUDIO_DESC_INTERFACE_STRING "Audio Interface"
|
||||
|
||||
/**
|
||||
* @brief audio interface subclass codes
|
||||
@@ -202,10 +202,10 @@ extern "C" {
|
||||
#define AUDIO_SPK_CHR AUDIO_SPK_CHANEL_NUM
|
||||
#define AUDIO_SPK_BITW (AUDIO_SPK_DEFAULT_BITW)
|
||||
|
||||
#define HID_BINTERVAL_TIME 0x01
|
||||
#define AUDIO_BINTERVAL_TIME 0x01
|
||||
|
||||
|
||||
#define USBD_CONFIG_DESC_SIZE ( 0x12 + AUDIO_INTERFACE_LEN + \
|
||||
#define USBD_AUDIO_CONFIG_DESC_SIZE ( 0x12 + AUDIO_INTERFACE_LEN + \
|
||||
+ (0x31 + AUDIO_SPK_FREQ_SIZE * 3) \
|
||||
+ (0x31 + AUDIO_MIC_FREQ_SIZE * 3) \
|
||||
+ (9 * AUDIO_SUPPORT_FEEDBACK) \
|
||||
@@ -216,8 +216,6 @@ extern "C" {
|
||||
#define MCU_ID2 (0x1FFFF7EC)
|
||||
#define MCU_ID3 (0x1FFFF7F0)
|
||||
|
||||
extern uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN];
|
||||
extern uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE];
|
||||
extern usbd_desc_handler audio_desc_handler;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_conf.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb audio config
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_class.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb audio class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -41,39 +41,28 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
void audio_inisoincom_event(void *udev);
|
||||
void audio_req_get_cur(void *udev, usb_setup_type *setup);
|
||||
void audio_req_set_cur(void *udev, usb_setup_type *setup);
|
||||
void audio_req_get_min(void *udev, usb_setup_type *setup);
|
||||
void audio_req_get_max(void *udev, usb_setup_type *setup);
|
||||
void audio_req_get_res(void *udev, usb_setup_type *setup);
|
||||
void audio_get_interface(void *udev, usb_setup_type *setup);
|
||||
void audio_set_interface(void *udev, usb_setup_type *setup);
|
||||
void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len);
|
||||
/* usb hid rx and tx buffer */
|
||||
static uint8_t g_rxhid_buff[USBD_OUT_MAXPACKET_SIZE];
|
||||
static uint8_t g_txhid_buff[USBD_IN_MAXPACKET_SIZE];
|
||||
static void audio_inisoincom_event(void *udev);
|
||||
static void audio_req_get_cur(void *udev, usb_setup_type *setup);
|
||||
static void audio_req_set_cur(void *udev, usb_setup_type *setup);
|
||||
static void audio_req_get_min(void *udev, usb_setup_type *setup);
|
||||
static void audio_req_get_max(void *udev, usb_setup_type *setup);
|
||||
static void audio_req_get_res(void *udev, usb_setup_type *setup);
|
||||
static void audio_get_interface(void *udev, usb_setup_type *setup);
|
||||
static void audio_set_interface(void *udev, usb_setup_type *setup);
|
||||
|
||||
static void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len);
|
||||
usb_audio_hid_type audio_hid_struct = {0, 0, 0, 0, 0, 0x1400, 0, 0, 0, {0x0000, 0x1400, 0x33}, {0x0000, 0x1400, 0x33}, 0, 0};
|
||||
|
||||
usb_audio_type audio_struct = {0, 0, 0, 0, 0, 0x1400, 0, 0, 0, {0x0000, 0x1400, 0x33}, {0x0000, 0x1400, 0x33}};
|
||||
/* custom 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;
|
||||
uint8_t hid_set_report[64];
|
||||
static __IO uint16_t audio_feedback_state = 0;
|
||||
static __IO uint8_t audio_spk_out_stage = 0;
|
||||
/* usb device class handler */
|
||||
usbd_class_handler audio_hid_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
@@ -85,6 +74,7 @@ usbd_class_handler audio_hid_class_handler =
|
||||
class_out_handler,
|
||||
class_sof_handler,
|
||||
class_event_handler,
|
||||
&audio_hid_struct
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -92,32 +82,33 @@ usbd_class_handler audio_hid_class_handler =
|
||||
* @param udev: usb device core handler 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;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* open microphone in endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUDIO_MIC_IN_EPT, EPT_ISO_TYPE, AUDIO_MIC_IN_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_AUHID_AUDIO_MIC_IN_EPT, EPT_ISO_TYPE, AUDIO_MIC_IN_MAXPACKET_SIZE);
|
||||
|
||||
/* open speaker out endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUDIO_SPK_OUT_EPT, EPT_ISO_TYPE, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_AUHID_AUDIO_SPK_OUT_EPT, EPT_ISO_TYPE, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
#if AUDIO_SUPPORT_FEEDBACK
|
||||
/* open speaker feedback endpoint */
|
||||
usbd_ept_open(pudev, USBD_AUDIO_FEEDBACK_EPT, EPT_ISO_TYPE, AUDIO_FEEDBACK_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_AUHID_AUDIO_FEEDBACK_EPT, EPT_ISO_TYPE, AUDIO_FEEDBACK_MAXPACKET_SIZE);
|
||||
#endif
|
||||
/* start receive speaker out data */
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, audio_struct.audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_AUHID_AUDIO_SPK_OUT_EPT, paudio_hid->audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
|
||||
/*open hid endpoint */
|
||||
/* open custom hid in endpoint */
|
||||
usbd_ept_open(pudev, USBD_HID_IN_EPT, EPT_INT_TYPE, USBD_IN_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_AUHID_HID_IN_EPT, EPT_INT_TYPE, USBD_AUHID_IN_MAXPACKET_SIZE);
|
||||
|
||||
/* open custom hid out endpoint */
|
||||
usbd_ept_open(pudev, USBD_HID_OUT_EPT, EPT_INT_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_AUHID_HID_OUT_EPT, EPT_INT_TYPE, USBD_AUHID_OUT_MAXPACKET_SIZE);
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_HID_OUT_EPT, g_rxhid_buff, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_AUHID_HID_OUT_EPT, paudio_hid->g_rxhid_buff, USBD_AUHID_OUT_MAXPACKET_SIZE);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -127,27 +118,27 @@ usb_sts_type class_init_handler(void *udev)
|
||||
* @param udev: usb device core handler 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 in endpoint */
|
||||
usbd_ept_close(pudev, USBD_AUDIO_MIC_IN_EPT);
|
||||
usbd_ept_close(pudev, USBD_AUHID_AUDIO_MIC_IN_EPT);
|
||||
|
||||
#if AUDIO_SUPPORT_FEEDBACK
|
||||
/* close in endpoint */
|
||||
usbd_ept_close(pudev, USBD_AUDIO_FEEDBACK_EPT);
|
||||
usbd_ept_close(pudev, USBD_AUHID_AUDIO_FEEDBACK_EPT);
|
||||
#endif
|
||||
|
||||
/* close out endpoint */
|
||||
usbd_ept_close(pudev, USBD_AUDIO_SPK_OUT_EPT);
|
||||
usbd_ept_close(pudev, USBD_AUHID_AUDIO_SPK_OUT_EPT);
|
||||
|
||||
/* close custom hid in endpoint */
|
||||
usbd_ept_close(pudev, USBD_HID_IN_EPT);
|
||||
usbd_ept_close(pudev, USBD_AUHID_HID_IN_EPT);
|
||||
|
||||
/* close custom hid out endpoint */
|
||||
usbd_ept_close(pudev, USBD_HID_OUT_EPT);
|
||||
usbd_ept_close(pudev, USBD_AUHID_HID_OUT_EPT);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -159,7 +150,7 @@ usb_sts_type class_clear_handler(void *udev)
|
||||
* @param setup: setup packet
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_audio_setup_handler(void *udev, usb_setup_type *setup)
|
||||
static usb_sts_type class_audio_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
@@ -202,8 +193,9 @@ usb_sts_type class_audio_setup_handler(void *udev, usb_setup_type *setup)
|
||||
case USB_STD_REQ_GET_DESCRIPTOR:
|
||||
if((setup->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE)
|
||||
{
|
||||
usbd_desc_t *config = pudev->desc_handler->get_device_configuration();
|
||||
len = MIN(AUDIO_DESCRIPTOR_SIZE, setup->wLength);
|
||||
usbd_ctrl_send(pudev, g_usbd_configuration+18, len);
|
||||
usbd_ctrl_send(pudev, config->descriptor + 18, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -238,10 +230,11 @@ usb_sts_type class_audio_setup_handler(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup packet
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type class_hid_setup_handler(void *udev, usb_setup_type *setup)
|
||||
static usb_sts_type class_hid_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
uint16_t len;
|
||||
uint8_t *buf;
|
||||
|
||||
@@ -252,20 +245,20 @@ usb_sts_type class_hid_setup_handler(void *udev, usb_setup_type *setup)
|
||||
switch(setup->bRequest)
|
||||
{
|
||||
case HID_REQ_SET_PROTOCOL:
|
||||
hid_protocol = (uint8_t)setup->wValue;
|
||||
paudio_hid->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 *)&paudio_hid->hid_protocol, 1);
|
||||
break;
|
||||
case HID_REQ_SET_IDLE:
|
||||
hid_set_idle = (uint8_t)(setup->wValue >> 8);
|
||||
paudio_hid->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 *)&paudio_hid->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);
|
||||
paudio_hid->hid_state = HID_REQ_SET_REPORT;
|
||||
usbd_ctrl_recv(pudev, paudio_hid->hid_set_report, setup->wLength);
|
||||
break;
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
@@ -279,21 +272,21 @@ usb_sts_type class_hid_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_AUHID_HID_SIZ_REPORT_DESC, setup->wLength);
|
||||
buf = (uint8_t *)g_usbd_audio_hid_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_audio_hid_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 *)&paudio_hid->alt_setting, 1);
|
||||
break;
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
alt_setting = setup->wValue;
|
||||
paudio_hid->alt_setting = setup->wValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -311,7 +304,7 @@ usb_sts_type class_hid_setup_handler(void *udev, usb_setup_type *setup)
|
||||
* @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;
|
||||
@@ -342,7 +335,7 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
* @param udev: usb device core handler 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;
|
||||
|
||||
@@ -356,74 +349,75 @@ usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
* @param udev: usb device core handler 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;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
usb_setup_type *setup = &pudev->setup;
|
||||
uint32_t recv_len = usbd_get_recv_len(pudev, 0);
|
||||
|
||||
/* ...user code... */
|
||||
if(setup->wIndex == HID_INTERFACE_NUMBER)
|
||||
{
|
||||
if( hid_state == HID_REQ_SET_REPORT)
|
||||
if( paudio_hid->hid_state == HID_REQ_SET_REPORT)
|
||||
{
|
||||
/* hid buffer process */
|
||||
usb_hid_buf_process(udev, hid_set_report, recv_len);
|
||||
hid_state = 0;
|
||||
usb_hid_buf_process(udev, paudio_hid->hid_set_report, recv_len);
|
||||
paudio_hid->hid_state = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ...user code... */
|
||||
if( audio_struct.audio_cmd == AUDIO_REQ_SET_CUR)
|
||||
if( paudio_hid->audio_cmd == AUDIO_REQ_SET_CUR)
|
||||
{
|
||||
/* class process */
|
||||
switch(audio_struct.request_no)
|
||||
switch(paudio_hid->request_no)
|
||||
{
|
||||
case AUDIO_VOLUME_CONTROL:
|
||||
if(audio_struct.interface == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
if(paudio_hid->interface == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
audio_struct.spk_volume = (uint16_t)(audio_struct.g_audio_cur[0] |
|
||||
(audio_struct.g_audio_cur[1] << 8));
|
||||
paudio_hid->spk_volume = (uint16_t)(paudio_hid->g_audio_cur[0] |
|
||||
(paudio_hid->g_audio_cur[1] << 8));
|
||||
/* set volume */
|
||||
audio_codec_set_spk_volume(audio_struct.spk_volume*100/audio_struct.spk_volume_limits[1]);
|
||||
audio_codec_set_spk_volume(paudio_hid->spk_volume*100/paudio_hid->spk_volume_limits[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_struct.mic_volume = (uint16_t)(audio_struct.g_audio_cur[0] |
|
||||
(audio_struct.g_audio_cur[1] << 8));
|
||||
paudio_hid->mic_volume = (uint16_t)(paudio_hid->g_audio_cur[0] |
|
||||
(paudio_hid->g_audio_cur[1] << 8));
|
||||
|
||||
audio_codec_set_mic_volume(audio_struct.mic_volume*256/audio_struct.mic_volume_limits[1]);
|
||||
audio_codec_set_mic_volume(paudio_hid->mic_volume*256/paudio_hid->mic_volume_limits[1]);
|
||||
}
|
||||
break;
|
||||
case AUDIO_MUTE_CONTROL:
|
||||
if(audio_struct.interface == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
if(paudio_hid->interface == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
audio_struct.spk_mute = audio_struct.g_audio_cur[0];
|
||||
audio_codec_set_spk_mute(audio_struct.spk_mute);
|
||||
paudio_hid->spk_mute = paudio_hid->g_audio_cur[0];
|
||||
audio_codec_set_spk_mute(paudio_hid->spk_mute);
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_struct.mic_mute = audio_struct.g_audio_cur[0];
|
||||
audio_codec_set_mic_mute(audio_struct.mic_mute);
|
||||
paudio_hid->mic_mute = paudio_hid->g_audio_cur[0];
|
||||
audio_codec_set_mic_mute(paudio_hid->mic_mute);
|
||||
}
|
||||
|
||||
break;
|
||||
case AUDIO_FREQ_SET_CONTROL:
|
||||
if(audio_struct.enpd == USBD_AUDIO_MIC_IN_EPT)
|
||||
if(paudio_hid->enpd == USBD_AUHID_AUDIO_MIC_IN_EPT)
|
||||
{
|
||||
audio_struct.mic_freq = (audio_struct.g_audio_cur[0] |
|
||||
(audio_struct.g_audio_cur[1] << 8) |
|
||||
(audio_struct.g_audio_cur[2] << 16));
|
||||
audio_codec_set_mic_freq(audio_struct.mic_freq);
|
||||
paudio_hid->mic_freq = (paudio_hid->g_audio_cur[0] |
|
||||
(paudio_hid->g_audio_cur[1] << 8) |
|
||||
(paudio_hid->g_audio_cur[2] << 16));
|
||||
audio_codec_set_mic_freq(paudio_hid->mic_freq);
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_struct.spk_freq = (audio_struct.g_audio_cur[0] |
|
||||
(audio_struct.g_audio_cur[1] << 8) |
|
||||
(audio_struct.g_audio_cur[2] << 16));
|
||||
audio_codec_set_spk_freq(audio_struct.spk_freq);
|
||||
paudio_hid->spk_freq = (paudio_hid->g_audio_cur[0] |
|
||||
(paudio_hid->g_audio_cur[1] << 8) |
|
||||
(paudio_hid->g_audio_cur[2] << 16));
|
||||
audio_codec_set_spk_freq(paudio_hid->spk_freq);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -441,28 +435,30 @@ 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;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
uint32_t len = 0;
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
if((ept_num & 0x7F) == (USBD_AUDIO_MIC_IN_EPT & 0x7F))
|
||||
if((ept_num & 0x7F) == (USBD_AUHID_AUDIO_MIC_IN_EPT & 0x7F))
|
||||
{
|
||||
len = audio_codec_mic_get_data(audio_struct.audio_mic_data);
|
||||
usbd_flush_tx_fifo(udev, USBD_AUDIO_MIC_IN_EPT);
|
||||
usbd_ept_send(udev, USBD_AUDIO_MIC_IN_EPT, audio_struct.audio_mic_data, len);
|
||||
len = audio_codec_mic_get_data(paudio_hid->audio_mic_data);
|
||||
usbd_flush_tx_fifo(udev, USBD_AUHID_AUDIO_MIC_IN_EPT);
|
||||
usbd_ept_send(udev, USBD_AUHID_AUDIO_MIC_IN_EPT, paudio_hid->audio_mic_data, len);
|
||||
}
|
||||
|
||||
else if((ept_num & 0x7F) == (USBD_AUDIO_FEEDBACK_EPT & 0x7F))
|
||||
else if((ept_num & 0x7F) == (USBD_AUHID_AUDIO_FEEDBACK_EPT & 0x7F))
|
||||
{
|
||||
audio_feedback_state = 0;
|
||||
paudio_hid->audio_feedback_state = 0;
|
||||
}
|
||||
else if((ept_num & 0x7F) == (USBD_HID_IN_EPT & 0x7F))
|
||||
else if((ept_num & 0x7F) == (USBD_AUHID_HID_IN_EPT & 0x7F))
|
||||
{
|
||||
usbd_flush_tx_fifo(udev, USBD_HID_IN_EPT);
|
||||
usbd_flush_tx_fifo(udev, USBD_AUHID_HID_IN_EPT);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -474,30 +470,31 @@ 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;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
uint16_t g_rxlen;
|
||||
|
||||
/* get endpoint receive data length */
|
||||
g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
if((ept_num & 0x7F) == (USBD_AUDIO_SPK_OUT_EPT & 0x7F))
|
||||
if((ept_num & 0x7F) == (USBD_AUHID_AUDIO_SPK_OUT_EPT & 0x7F))
|
||||
{
|
||||
/* speaker data*/
|
||||
audio_codec_spk_fifo_write(audio_struct.audio_spk_data, g_rxlen);
|
||||
audio_spk_out_stage = 1;
|
||||
audio_codec_spk_fifo_write(paudio_hid->audio_spk_data, g_rxlen);
|
||||
paudio_hid->audio_spk_out_stage = 1;
|
||||
/* get next data */
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, audio_struct.audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_AUHID_AUDIO_SPK_OUT_EPT, paudio_hid->audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
}
|
||||
else if((ept_num & 0x7F) == (USBD_HID_OUT_EPT & 0x7F))
|
||||
else if((ept_num & 0x7F) == (USBD_AUHID_HID_OUT_EPT & 0x7F))
|
||||
{
|
||||
/* hid buffer process */
|
||||
usb_hid_buf_process(udev, g_rxhid_buff, g_rxlen);
|
||||
usb_hid_buf_process(udev, paudio_hid->g_rxhid_buff, g_rxlen);
|
||||
|
||||
/* start receive next packet */
|
||||
usbd_ept_recv(pudev, USBD_HID_OUT_EPT, g_rxhid_buff, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_AUHID_HID_OUT_EPT, paudio_hid->g_rxhid_buff, USBD_AUHID_OUT_MAXPACKET_SIZE);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
@@ -507,33 +504,35 @@ usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
|
||||
* @param udev: usb device core handler 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;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
|
||||
#if AUDIO_SUPPORT_FEEDBACK
|
||||
if(audio_spk_out_stage & 2)
|
||||
if(paudio_hid->audio_spk_out_stage & 2)
|
||||
{
|
||||
audio_spk_out_stage = 0;
|
||||
paudio_hid->audio_spk_out_stage = 0;
|
||||
}
|
||||
else if( audio_spk_out_stage )
|
||||
else if( paudio_hid->audio_spk_out_stage )
|
||||
{
|
||||
audio_spk_out_stage |= 2;
|
||||
paudio_hid->audio_spk_out_stage |= 2;
|
||||
|
||||
if( 0 == audio_feedback_state )
|
||||
if( 0 == paudio_hid->audio_feedback_state )
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
int len = audio_codec_spk_feedback(audio_struct.audio_feed_back);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, audio_struct.audio_feed_back, len);
|
||||
audio_feedback_state = 1;
|
||||
int len = audio_codec_spk_feedback(paudio_hid->audio_feed_back);
|
||||
usbd_ept_send(pudev, USBD_AUHID_AUDIO_FEEDBACK_EPT, paudio_hid->audio_feed_back, len);
|
||||
paudio_hid->audio_feedback_state = 1;
|
||||
}
|
||||
if( audio_feedback_state++ > (1<<FEEDBACK_REFRESH_TIME) ) //timeout
|
||||
if( paudio_hid->audio_feedback_state++ > (1<<FEEDBACK_REFRESH_TIME) ) //timeout
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
int len = audio_codec_spk_feedback(audio_struct.audio_feed_back);
|
||||
usbd_flush_tx_fifo(pudev, USBD_AUDIO_FEEDBACK_EPT);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, audio_struct.audio_feed_back, len);
|
||||
audio_feedback_state = 1;
|
||||
int len = audio_codec_spk_feedback(paudio_hid->audio_feed_back);
|
||||
usbd_flush_tx_fifo(pudev, USBD_AUHID_AUDIO_FEEDBACK_EPT);
|
||||
usbd_ept_send(pudev, USBD_AUHID_AUDIO_FEEDBACK_EPT, paudio_hid->audio_feed_back, len);
|
||||
paudio_hid->audio_feedback_state = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -548,9 +547,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;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
@@ -559,10 +560,10 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
audio_struct.spk_alt_setting = 0;
|
||||
audio_codec_spk_alt_setting(audio_struct.spk_alt_setting);
|
||||
audio_struct.mic_alt_setting = 0;
|
||||
audio_codec_mic_alt_setting(audio_struct.spk_alt_setting);
|
||||
paudio_hid->spk_alt_setting = 0;
|
||||
audio_codec_spk_alt_setting(paudio_hid->spk_alt_setting);
|
||||
paudio_hid->mic_alt_setting = 0;
|
||||
audio_codec_mic_alt_setting(paudio_hid->spk_alt_setting);
|
||||
/* ...user code... */
|
||||
|
||||
break;
|
||||
@@ -585,32 +586,33 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
* @param udev: usb device core handler type
|
||||
* @retval none
|
||||
*/
|
||||
void audio_inisoincom_event(void *udev)
|
||||
static void audio_inisoincom_event(void *udev)
|
||||
{
|
||||
#if 0
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
uint32_t fnsof = OTG_DEVICE(pudev->usb_reg)->dsts_bit.soffn;
|
||||
uint32_t epctl_fb = USB_INEPT(pudev->usb_reg, (USBD_AUDIO_FEEDBACK_EPT&0x7F))->diepctl_bit.dpid;
|
||||
uint32_t epctl_in = USB_INEPT(pudev->usb_reg, (USBD_AUDIO_MIC_IN_EPT&0x7F))->diepctl_bit.dpid;
|
||||
uint32_t epctl_fb = USB_INEPT(pudev->usb_reg, (USBD_AUHID_AUDIO_FEEDBACK_EPT&0x7F))->diepctl_bit.dpid;
|
||||
uint32_t epctl_in = USB_INEPT(pudev->usb_reg, (USBD_AUHID_AUDIO_MIC_IN_EPT&0x7F))->diepctl_bit.dpid;
|
||||
uint32_t len = 0;
|
||||
|
||||
if((fnsof & 0x1) == epctl_fb)
|
||||
{
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUDIO_FEEDBACK_EPT&0x7F))->diepctl_bit.eptdis = 1;
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUDIO_FEEDBACK_EPT&0x7F))->diepctl_bit.snak = 1;
|
||||
usb_flush_tx_fifo(pudev->usb_reg, USBD_AUDIO_FEEDBACK_EPT&0x7F);
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUHID_AUDIO_FEEDBACK_EPT&0x7F))->diepctl_bit.eptdis = 1;
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUHID_AUDIO_FEEDBACK_EPT&0x7F))->diepctl_bit.snak = 1;
|
||||
usb_flush_tx_fifo(pudev->usb_reg, USBD_AUHID_AUDIO_FEEDBACK_EPT&0x7F);
|
||||
|
||||
usbd_ept_send(pudev, USBD_AUDIO_FEEDBACK_EPT, audio_struct.audio_feed_back, 3);
|
||||
usbd_ept_send(pudev, USBD_AUHID_AUDIO_FEEDBACK_EPT, paudio_hid->audio_feed_back, 3);
|
||||
}
|
||||
|
||||
if((fnsof & 0x1) == epctl_in)
|
||||
{
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUDIO_MIC_IN_EPT&0x7F))->diepctl_bit.eptdis = 1;
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUDIO_MIC_IN_EPT&0x7F))->diepctl_bit.snak = 1;
|
||||
usb_flush_tx_fifo(pudev->usb_reg, USBD_AUDIO_MIC_IN_EPT&0x7F);
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUHID_AUDIO_MIC_IN_EPT&0x7F))->diepctl_bit.eptdis = 1;
|
||||
USB_INEPT(pudev->usb_reg, (USBD_AUHID_AUDIO_MIC_IN_EPT&0x7F))->diepctl_bit.snak = 1;
|
||||
usb_flush_tx_fifo(pudev->usb_reg, USBD_AUHID_AUDIO_MIC_IN_EPT&0x7F);
|
||||
|
||||
len = audio_codec_mic_get_data(audio_struct.audio_mic_data);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_MIC_IN_EPT, audio_struct.audio_mic_data, len);
|
||||
len = audio_codec_mic_get_data(paudio_hid->audio_mic_data);
|
||||
usbd_ept_send(pudev, USBD_AUHID_AUDIO_MIC_IN_EPT, paudio_hid->audio_mic_data, len);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -621,33 +623,34 @@ void audio_inisoincom_event(void *udev)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_get_cur(void *udev, usb_setup_type *setup)
|
||||
static void audio_req_get_cur(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
if(HBYTE(setup->wIndex) == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
if(HBYTE(setup->wValue) == AUDIO_MUTE_CONTROL)
|
||||
{
|
||||
audio_struct.g_audio_cur[0] = audio_struct.spk_mute;
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
paudio_hid->g_audio_cur[0] = paudio_hid->spk_mute;
|
||||
usbd_ctrl_send(pudev, paudio_hid->g_audio_cur, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.spk_volume;
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio_hid->g_audio_cur) = paudio_hid->spk_volume;
|
||||
usbd_ctrl_send(pudev, paudio_hid->g_audio_cur, setup->wLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(HBYTE(setup->wValue) == AUDIO_MUTE_CONTROL)
|
||||
{
|
||||
audio_struct.g_audio_cur[0] = audio_struct.mic_mute;
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
paudio_hid->g_audio_cur[0] = paudio_hid->mic_mute;
|
||||
usbd_ctrl_send(pudev, paudio_hid->g_audio_cur, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.mic_volume;
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio_hid->g_audio_cur) = paudio_hid->mic_volume;
|
||||
usbd_ctrl_send(pudev, paudio_hid->g_audio_cur, setup->wLength);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -659,32 +662,33 @@ void audio_req_get_cur(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_set_cur(void *udev, usb_setup_type *setup)
|
||||
static void audio_req_set_cur(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
if(setup->wLength > 0)
|
||||
{
|
||||
usbd_ctrl_recv(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
usbd_ctrl_recv(pudev, paudio_hid->g_audio_cur, setup->wLength);
|
||||
|
||||
audio_struct.audio_cmd = AUDIO_REQ_SET_CUR;
|
||||
audio_struct.audio_cmd_len = setup->wLength;
|
||||
paudio_hid->audio_cmd = AUDIO_REQ_SET_CUR;
|
||||
paudio_hid->audio_cmd_len = setup->wLength;
|
||||
|
||||
switch(setup->bmRequestType & AUDIO_REQ_CONTROL_MASK)
|
||||
{
|
||||
case AUDIO_REQ_CONTROL_INTERFACE:
|
||||
audio_struct.interface = HBYTE(setup->wIndex);
|
||||
paudio_hid->interface = HBYTE(setup->wIndex);
|
||||
if(HBYTE(setup->wValue) == AUDIO_MUTE_CONTROL)
|
||||
{
|
||||
audio_struct.request_no = AUDIO_MUTE_CONTROL;
|
||||
paudio_hid->request_no = AUDIO_MUTE_CONTROL;
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_struct.request_no = AUDIO_VOLUME_CONTROL;
|
||||
paudio_hid->request_no = AUDIO_VOLUME_CONTROL;
|
||||
}
|
||||
break;
|
||||
case AUDIO_REQ_CONTROL_ENDPOINT:
|
||||
audio_struct.enpd = setup->wIndex;
|
||||
audio_struct.request_no = AUDIO_FREQ_SET_CONTROL;
|
||||
paudio_hid->enpd = setup->wIndex;
|
||||
paudio_hid->request_no = AUDIO_FREQ_SET_CONTROL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -698,18 +702,19 @@ void audio_req_set_cur(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_get_min(void *udev, usb_setup_type *setup)
|
||||
static void audio_req_get_min(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
if(HBYTE(setup->wIndex) == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.spk_volume_limits[0];
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio_hid->g_audio_cur) = paudio_hid->spk_volume_limits[0];
|
||||
usbd_ctrl_send(pudev, paudio_hid->g_audio_cur, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.mic_volume_limits[0];
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio_hid->g_audio_cur) = paudio_hid->mic_volume_limits[0];
|
||||
usbd_ctrl_send(pudev, paudio_hid->g_audio_cur, setup->wLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -719,18 +724,19 @@ void audio_req_get_min(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_get_max(void *udev, usb_setup_type *setup)
|
||||
static void audio_req_get_max(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
if(HBYTE(setup->wIndex) == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.spk_volume_limits[1];
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio_hid->g_audio_cur) = paudio_hid->spk_volume_limits[1];
|
||||
usbd_ctrl_send(pudev, paudio_hid->g_audio_cur, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.mic_volume_limits[1];
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio_hid->g_audio_cur) = paudio_hid->mic_volume_limits[1];
|
||||
usbd_ctrl_send(pudev, paudio_hid->g_audio_cur, setup->wLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -740,18 +746,19 @@ void audio_req_get_max(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_req_get_res(void *udev, usb_setup_type *setup)
|
||||
static void audio_req_get_res(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
if(HBYTE(setup->wIndex) == AUDIO_SPK_FEATURE_UNIT_ID)
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.spk_volume_limits[2];
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio_hid->g_audio_cur) = paudio_hid->spk_volume_limits[2];
|
||||
usbd_ctrl_send(pudev, paudio_hid->g_audio_cur, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
*((uint16_t *)audio_struct.g_audio_cur) = audio_struct.mic_volume_limits[2];
|
||||
usbd_ctrl_send(pudev, audio_struct.g_audio_cur, setup->wLength);
|
||||
*((uint16_t *)paudio_hid->g_audio_cur) = paudio_hid->mic_volume_limits[2];
|
||||
usbd_ctrl_send(pudev, paudio_hid->g_audio_cur, setup->wLength);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -761,28 +768,29 @@ void audio_req_get_res(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
static void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
uint32_t len;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
if(LBYTE(setup->wIndex) == AUDIO_SPK_INTERFACE_NUMBER)
|
||||
{
|
||||
audio_struct.spk_alt_setting = setup->wValue;
|
||||
audio_codec_spk_alt_setting(audio_struct.spk_alt_setting);
|
||||
if(audio_struct.spk_alt_setting )
|
||||
paudio_hid->spk_alt_setting = setup->wValue;
|
||||
audio_codec_spk_alt_setting(paudio_hid->spk_alt_setting);
|
||||
if(paudio_hid->spk_alt_setting )
|
||||
{
|
||||
usbd_ept_recv(pudev, USBD_AUDIO_SPK_OUT_EPT, audio_struct.audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_AUHID_AUDIO_SPK_OUT_EPT, paudio_hid->audio_spk_data, AUDIO_SPK_OUT_MAXPACKET_SIZE);
|
||||
}
|
||||
|
||||
}
|
||||
else if(LBYTE(setup->wIndex) == AUDIO_MIC_INTERFACE_NUMBER)
|
||||
{
|
||||
audio_struct.mic_alt_setting = setup->wValue;
|
||||
audio_codec_mic_alt_setting(audio_struct.mic_alt_setting);
|
||||
if(audio_struct.mic_alt_setting)
|
||||
paudio_hid->mic_alt_setting = setup->wValue;
|
||||
audio_codec_mic_alt_setting(paudio_hid->mic_alt_setting);
|
||||
if(paudio_hid->mic_alt_setting)
|
||||
{
|
||||
len = audio_codec_mic_get_data(audio_struct.audio_mic_data);
|
||||
usbd_ept_send(pudev, USBD_AUDIO_MIC_IN_EPT, audio_struct.audio_mic_data, len);
|
||||
len = audio_codec_mic_get_data(paudio_hid->audio_mic_data);
|
||||
usbd_ept_send(pudev, USBD_AUHID_AUDIO_MIC_IN_EPT, paudio_hid->audio_mic_data, len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -794,16 +802,17 @@ void audio_set_interface(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup class
|
||||
* @retval none
|
||||
*/
|
||||
void audio_get_interface(void *udev, usb_setup_type *setup)
|
||||
static void audio_get_interface(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
if(LBYTE(setup->wIndex) == AUDIO_SPK_INTERFACE_NUMBER)
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.spk_alt_setting, 1);
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&paudio_hid->spk_alt_setting, 1);
|
||||
}
|
||||
else if(LBYTE(setup->wIndex) == AUDIO_MIC_INTERFACE_NUMBER)
|
||||
{
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&audio_struct.mic_alt_setting, 1);
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&paudio_hid->mic_alt_setting, 1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -815,13 +824,13 @@ void audio_get_interface(void *udev, usb_setup_type *setup)
|
||||
* @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 audio_hid_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_AUHID_HID_IN_EPT, report, len);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -834,15 +843,16 @@ usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len)
|
||||
* @param len: report length
|
||||
* @retval none
|
||||
*/
|
||||
void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
static void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
{
|
||||
uint32_t i_index;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
usb_audio_hid_type *paudio_hid = (usb_audio_hid_type *)pudev->class_handler->pdata;
|
||||
|
||||
switch(report[0])
|
||||
{
|
||||
case HID_REPORT_ID_2:
|
||||
if(g_rxhid_buff[1] == 0)
|
||||
if(paudio_hid->g_rxhid_buff[1] == 0)
|
||||
{
|
||||
at32_led_off(LED2);
|
||||
}
|
||||
@@ -852,7 +862,7 @@ void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
}
|
||||
break;
|
||||
case HID_REPORT_ID_3:
|
||||
if(g_rxhid_buff[1] == 0)
|
||||
if(paudio_hid->g_rxhid_buff[1] == 0)
|
||||
{
|
||||
at32_led_off(LED3);
|
||||
}
|
||||
@@ -862,7 +872,7 @@ void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
}
|
||||
break;
|
||||
case HID_REPORT_ID_4:
|
||||
if(g_rxhid_buff[1] == 0)
|
||||
if(paudio_hid->g_rxhid_buff[1] == 0)
|
||||
{
|
||||
at32_led_off(LED4);
|
||||
}
|
||||
@@ -874,9 +884,9 @@ void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
case HID_REPORT_ID_6:
|
||||
for(i_index = 0; i_index < len; i_index ++)
|
||||
{
|
||||
g_txhid_buff[i_index] = report[i_index];
|
||||
paudio_hid->g_txhid_buff[i_index] = report[i_index];
|
||||
}
|
||||
usbd_ept_send(pudev, USBD_HID_IN_EPT, g_txhid_buff, len);
|
||||
usbd_ept_send(pudev, USBD_AUHID_HID_IN_EPT, paudio_hid->g_txhid_buff, len);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_class.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb audio class file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -25,8 +25,8 @@
|
||||
*/
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AUDIO_CLASS_H
|
||||
#define __AUDIO_CLASS_H
|
||||
#ifndef __AUDIO_HID_CLASS_H
|
||||
#define __AUDIO_HID_CLASS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -51,21 +51,21 @@ extern "C" {
|
||||
/**
|
||||
* @brief endpoint define
|
||||
*/
|
||||
#define USBD_AUDIO_MIC_IN_EPT 0x81
|
||||
#define USBD_AUDIO_SPK_OUT_EPT 0x02
|
||||
#define USBD_AUDIO_FEEDBACK_EPT 0x83
|
||||
#define USBD_AUHID_AUDIO_MIC_IN_EPT 0x81
|
||||
#define USBD_AUHID_AUDIO_SPK_OUT_EPT 0x02
|
||||
#define USBD_AUHID_AUDIO_FEEDBACK_EPT 0x83
|
||||
|
||||
/**
|
||||
* @brief usb custom hid use endpoint define
|
||||
*/
|
||||
#define USBD_HID_IN_EPT 0x82
|
||||
#define USBD_HID_OUT_EPT 0x01
|
||||
#define USBD_AUHID_HID_IN_EPT 0x82
|
||||
#define USBD_AUHID_HID_OUT_EPT 0x01
|
||||
|
||||
/**
|
||||
* @brief usb custom hid in and out max packet size define
|
||||
*/
|
||||
#define USBD_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_OUT_MAXPACKET_SIZE 0x40
|
||||
#define USBD_AUHID_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_AUHID_OUT_MAXPACKET_SIZE 0x40
|
||||
|
||||
/**
|
||||
* @brief endpoint support max size
|
||||
@@ -106,24 +106,12 @@ extern "C" {
|
||||
#define AUDIO_DESCRIPTOR_TYPE 0x21
|
||||
#define AUDIO_DESCRIPTOR_SIZE 0x09
|
||||
|
||||
/**
|
||||
* @brief usb custom 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
|
||||
|
||||
|
||||
/**
|
||||
* @brief usb audio control struct
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/* audio */
|
||||
uint8_t enpd;
|
||||
uint8_t interface;
|
||||
uint8_t request_no;
|
||||
@@ -144,11 +132,23 @@ typedef struct
|
||||
uint8_t audio_spk_data[AUDIO_SPK_OUT_MAXPACKET_SIZE];
|
||||
uint8_t audio_mic_data[AUDIO_MIC_IN_MAXPACKET_SIZE];
|
||||
uint8_t audio_feed_back[AUDIO_FEEDBACK_MAXPACKET_SIZE+1];
|
||||
}usb_audio_type;
|
||||
__IO uint16_t audio_feedback_state;
|
||||
__IO uint8_t audio_spk_out_stage;
|
||||
|
||||
|
||||
/* hid */
|
||||
uint32_t hid_protocol;
|
||||
uint32_t hid_set_idle;
|
||||
uint32_t alt_setting;
|
||||
uint8_t hid_state;
|
||||
uint8_t hid_set_report[64];
|
||||
uint8_t g_rxhid_buff[USBD_AUHID_OUT_MAXPACKET_SIZE];
|
||||
uint8_t g_txhid_buff[USBD_AUHID_IN_MAXPACKET_SIZE];
|
||||
}usb_audio_hid_type;
|
||||
|
||||
|
||||
extern usbd_class_handler audio_hid_class_handler;
|
||||
|
||||
usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len);
|
||||
usb_sts_type audio_hid_class_send_report(void *udev, uint8_t *report, uint16_t len);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_desc.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb audio device descriptor
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -40,20 +40,18 @@
|
||||
/** @defgroup USB_audio_hid_desc_private_functions
|
||||
* @{
|
||||
*/
|
||||
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);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
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];
|
||||
@@ -81,7 +79,7 @@ usbd_desc_handler audio_hid_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 */
|
||||
@@ -91,14 +89,14 @@ 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_AUHID_VENDOR_ID), /* idVendor */
|
||||
HBYTE(USBD_AUHID_VENDOR_ID), /* idVendor */
|
||||
#if AUDIO_SUPPORT_FEEDBACK
|
||||
LBYTE(USBD_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_PRODUCT_ID), /* idProduct */
|
||||
LBYTE(USBD_AUHID_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_AUHID_PRODUCT_ID), /* idProduct */
|
||||
#else
|
||||
LBYTE(USBD_PRODUCT_ID+1), /* idProduct */
|
||||
HBYTE(USBD_PRODUCT_ID+1), /* idProduct */
|
||||
LBYTE(USBD_AUHID_PRODUCT_ID+1), /* idProduct */
|
||||
HBYTE(USBD_AUHID_PRODUCT_ID+1), /* idProduct */
|
||||
#endif
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
@@ -114,12 +112,12 @@ 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_AUHID_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_AUHID_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
HBYTE(USBD_AUHID_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
0x1 + AUDIO_INTERFACE_NUM + 0x1, /* bNumInterfaces: n interface */
|
||||
0x01, /* bConfigurationValue: configuration value */
|
||||
0x00, /* iConfiguration: index of string descriptor describing
|
||||
@@ -140,8 +138,8 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
0x08+AUDIO_INTERFACE_NUM, /* bLength: size of this descriptor, in bytes 8+n */
|
||||
AUDIO_CS_INTERFACE, /* bDescriptorType: cs interface descriptor type */
|
||||
AUDIO_AC_HEADER, /* bDescriptorSubtype: Header function Descriptor*/
|
||||
LBYTE(BCD_NUM),
|
||||
HBYTE(BCD_NUM), /* bcdCDC: audio device class specification release number */
|
||||
LBYTE(AUHID_BCD_NUM),
|
||||
HBYTE(AUHID_BCD_NUM), /* bcdCDC: audio device class specification release number */
|
||||
LBYTE(AUDIO_INTERFACE_LEN),
|
||||
HBYTE(AUDIO_INTERFACE_LEN), /* wTotalLength: total number of bytes returned for the class-specific audio control interface */
|
||||
AUDIO_INTERFACE_NUM, /* bInClollection: the number of audio streaming */
|
||||
@@ -281,11 +279,11 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
|
||||
0x09, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_AUDIO_MIC_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USBD_AUHID_AUDIO_MIC_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_ISO | USB_ETP_DESC_ASYNC, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(AUDIO_MIC_IN_MAXPACKET_SIZE),
|
||||
HBYTE(AUDIO_MIC_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
AUHID_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
0x00, /* bRefresh: unused */
|
||||
0x00, /* bSynchAddress: unused */
|
||||
|
||||
@@ -345,14 +343,14 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
|
||||
0x09, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_AUDIO_SPK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USBD_AUHID_AUDIO_SPK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_ISO | USB_ETP_DESC_ASYNC, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(AUDIO_SPK_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(AUDIO_SPK_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
AUHID_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
0x00, /* bRefresh: unused */
|
||||
#if (AUDIO_SUPPORT_FEEDBACK == 1)
|
||||
USBD_AUDIO_FEEDBACK_EPT, /* bSynchAddress: feedback endpoint */
|
||||
USBD_AUHID_AUDIO_FEEDBACK_EPT, /* bSynchAddress: feedback endpoint */
|
||||
#else
|
||||
0x00, /* bSynchAddress: unused */
|
||||
#endif
|
||||
@@ -368,7 +366,7 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
#if (AUDIO_SUPPORT_FEEDBACK == 1)
|
||||
0x09, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_AUDIO_FEEDBACK_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USBD_AUHID_AUDIO_FEEDBACK_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
0x11, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(AUDIO_FEEDBACK_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HBYTE(AUDIO_FEEDBACK_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
@@ -394,29 +392,29 @@ 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(AUHID_HID_BCD_NUM),
|
||||
HBYTE(AUHID_HID_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_audio_hid_report)),
|
||||
HBYTE(sizeof(g_usbd_audio_hid_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_AUHID_HID_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_AUHID_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_AUHID_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
AUHID_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_HID_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USBD_AUHID_HID_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_INTERRUPT, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
LBYTE(USBD_AUHID_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_AUHID_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
AUHID_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
|
||||
|
||||
@@ -426,7 +424,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_audio_hid_report[USBD_AUHID_HID_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
0x06, 0xFF, 0x00, /* USAGE_PAGE(Vendor Page:0xFF00) */
|
||||
0x09, 0x01, /* USAGE (Demo Kit) */
|
||||
@@ -524,17 +522,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_audio_hid_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(AUHID_HID_BCD_NUM),
|
||||
HBYTE(AUHID_HID_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_audio_hid_report)),
|
||||
HBYTE(sizeof(g_usbd_audio_hid_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
};
|
||||
|
||||
|
||||
@@ -544,9 +542,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_AUHID_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_AUHID_SIZ_STRING_LANGID,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
0x09,
|
||||
0x04,
|
||||
@@ -558,42 +556,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_AUHID_SIZ_STRING_SERIAL] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_SERIAL,
|
||||
USBD_AUHID_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_AUHID_CONFIG_DESC_SIZE,
|
||||
g_usbd_configuration
|
||||
};
|
||||
|
||||
/* langid descriptor */
|
||||
usbd_desc_t langid_descriptor =
|
||||
static usbd_desc_t langid_descriptor =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_AUHID_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_AUHID_SIZ_STRING_SERIAL,
|
||||
g_string_serial
|
||||
};
|
||||
|
||||
usbd_desc_t vp_desc;
|
||||
static usbd_desc_t vp_desc;
|
||||
|
||||
/**
|
||||
* @brief standard usb unicode convert
|
||||
@@ -601,7 +599,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;
|
||||
@@ -675,7 +673,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;
|
||||
}
|
||||
@@ -685,7 +683,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;
|
||||
}
|
||||
@@ -695,7 +693,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;
|
||||
}
|
||||
@@ -705,7 +703,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;
|
||||
}
|
||||
@@ -715,7 +713,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;
|
||||
}
|
||||
@@ -726,9 +724,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_AUHID_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -738,9 +736,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_AUHID_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -750,7 +748,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;
|
||||
@@ -761,9 +759,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_AUHID_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -773,9 +771,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_AUHID_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file audio_desc.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb audio descriptor header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -25,8 +25,8 @@
|
||||
*/
|
||||
|
||||
/* define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AUDIO_DESC_H
|
||||
#define __AUDIO_DESC_H
|
||||
#ifndef __AUDIO_HID_DESC_H
|
||||
#define __AUDIO_HID_DESC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -47,20 +47,19 @@ extern "C" {
|
||||
/** @defgroup USB_audio_hid_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define AUHID_BCD_NUM 0x0100
|
||||
|
||||
#define BCD_NUM 0x0100
|
||||
#define USBD_AUHID_VENDOR_ID 0x2E3C
|
||||
#define USBD_AUHID_PRODUCT_ID 0x5555
|
||||
|
||||
#define USBD_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRODUCT_ID 0x5555
|
||||
|
||||
#define USBD_SIZ_STRING_LANGID 4
|
||||
#define USBD_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
#define USBD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_DESC_PRODUCT_STRING "AT32 Audio"
|
||||
#define USBD_DESC_CONFIGURATION_STRING "Audio Config"
|
||||
#define USBD_DESC_INTERFACE_STRING "Audio Interface"
|
||||
#define USBD_AUHID_SIZ_STRING_LANGID 4
|
||||
#define USBD_AUHID_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
#define USBD_AUHID_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_AUHID_DESC_PRODUCT_STRING "AT32 Audio"
|
||||
#define USBD_AUHID_DESC_CONFIGURATION_STRING "Audio Config"
|
||||
#define USBD_AUHID_DESC_INTERFACE_STRING "Audio Interface"
|
||||
/**
|
||||
* @brief audio interface subclass codes
|
||||
*/
|
||||
@@ -203,12 +202,12 @@ extern "C" {
|
||||
#define AUDIO_SPK_CHR AUDIO_SPK_CHANEL_NUM
|
||||
#define AUDIO_SPK_BITW (AUDIO_SPK_DEFAULT_BITW)
|
||||
|
||||
#define HID_BINTERVAL_TIME 0x01
|
||||
#define AUHID_HID_BINTERVAL_TIME 0x01
|
||||
|
||||
/**
|
||||
* @brief usb bcd number define
|
||||
*/
|
||||
#define HID_BCD_NUM 0x0110
|
||||
#define AUHID_HID_BCD_NUM 0x0110
|
||||
|
||||
/**
|
||||
* @brief usb hid class descriptor define
|
||||
@@ -227,24 +226,24 @@ extern "C" {
|
||||
#define HID_REPORT_ID_5 0x05
|
||||
#define HID_REPORT_ID_6 0xF0
|
||||
|
||||
#define USBD_HID_DESC_SIZE 32
|
||||
#define USBD_CONFIG_DESC_SIZE ( 0x12 + AUDIO_INTERFACE_LEN + \
|
||||
+ (0x31 + AUDIO_SPK_FREQ_SIZE * 3) \
|
||||
+ (0x31 + AUDIO_MIC_FREQ_SIZE * 3) \
|
||||
+ (9 * AUDIO_SUPPORT_FEEDBACK) \
|
||||
+ USBD_HID_DESC_SIZE)
|
||||
#define USBD_HID_SIZ_REPORT_DESC 126
|
||||
#define MCU_ID1 (0x1FFFF7E8)
|
||||
#define MCU_ID2 (0x1FFFF7EC)
|
||||
#define MCU_ID3 (0x1FFFF7F0)
|
||||
|
||||
|
||||
#define SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16))
|
||||
|
||||
#define MCU_ID1 (0x1FFFF7E8)
|
||||
#define MCU_ID2 (0x1FFFF7EC)
|
||||
#define MCU_ID3 (0x1FFFF7F0)
|
||||
#define USBD_AUHID_HID_SIZ_REPORT_DESC 126
|
||||
#define USBD_AUHID_HID_DESC_SIZE 32
|
||||
#define USBD_AUHID_CONFIG_DESC_SIZE ( 0x12 + AUDIO_INTERFACE_LEN + \
|
||||
+ (0x31 + AUDIO_SPK_FREQ_SIZE * 3) \
|
||||
+ (0x31 + AUDIO_MIC_FREQ_SIZE * 3) \
|
||||
+ (9 * AUDIO_SUPPORT_FEEDBACK) \
|
||||
+ USBD_AUHID_HID_DESC_SIZE)
|
||||
|
||||
extern uint8_t g_usbd_audio_hid_report[USBD_AUHID_HID_SIZ_REPORT_DESC];
|
||||
extern uint8_t g_audio_hid_usb_desc[9];
|
||||
|
||||
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_descriptor[USB_DEVICE_DESC_LEN];
|
||||
extern uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE];
|
||||
extern usbd_desc_handler audio_hid_desc_handler;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_class.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb cdc class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -40,39 +40,33 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len);
|
||||
/* usb rx and tx buffer */
|
||||
static uint32_t alt_setting = 0;
|
||||
static uint8_t g_rx_buff[USBD_OUT_MAXPACKET_SIZE];
|
||||
//static uint8_t g_tx_buff[USBD_IN_MAXPACKET_SIZE];
|
||||
static uint8_t g_cmd[USBD_CMD_MAXPACKET_SIZE];
|
||||
static uint8_t g_req;
|
||||
static uint16_t g_len, g_rxlen;
|
||||
__IO uint8_t g_tx_completed = 1, g_rx_completed = 0;
|
||||
static usb_sts_type cdc_struct_init(cdc_struct_type *pcdc);
|
||||
extern void usb_usart_config( linecoding_type linecoding);
|
||||
static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len);
|
||||
|
||||
linecoding_type linecoding =
|
||||
linecoding_type linecoding =
|
||||
{
|
||||
115200,
|
||||
0x00,
|
||||
0x00,
|
||||
0x08
|
||||
0,
|
||||
0,
|
||||
8
|
||||
};
|
||||
|
||||
/* static variable */
|
||||
|
||||
/* cdc data struct */
|
||||
cdc_struct_type cdc_struct;
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler class_handler =
|
||||
usbd_class_handler cdc_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -83,31 +77,33 @@ usbd_class_handler class_handler =
|
||||
class_out_handler,
|
||||
class_sof_handler,
|
||||
class_event_handler,
|
||||
&cdc_struct
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief initialize usb custom hid endpoint
|
||||
* @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;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* init cdc struct */
|
||||
cdc_struct_init(pcdc);
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_CDC_INT_EPT, EPT_INT_TYPE, USBD_CMD_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_CDC_INT_EPT, EPT_INT_TYPE, USBD_CDC_CMD_MAXPACKET_SIZE);
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_CDC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_IN_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_CDC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_CDC_IN_MAXPACKET_SIZE);
|
||||
|
||||
/* open out endpoint */
|
||||
usbd_ept_open(pudev, USBD_CDC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_CDC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_CDC_OUT_MAXPACKET_SIZE);
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, g_rx_buff, USBD_OUT_MAXPACKET_SIZE);
|
||||
|
||||
g_tx_completed = 1;
|
||||
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, pcdc->g_rx_buff, USBD_CDC_OUT_MAXPACKET_SIZE);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -117,7 +113,7 @@ 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;
|
||||
@@ -140,10 +136,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;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
switch(setup->bmRequestType & USB_REQ_TYPE_RESERVED)
|
||||
{
|
||||
@@ -153,14 +150,14 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
if(setup->bmRequestType & USB_REQ_DIR_DTH)
|
||||
{
|
||||
usb_vcp_cmd_process(udev, setup->bRequest, g_cmd, setup->wLength);
|
||||
usbd_ctrl_send(pudev, g_cmd, setup->wLength);
|
||||
usb_vcp_cmd_process(udev, setup->bRequest, pcdc->g_cmd, setup->wLength);
|
||||
usbd_ctrl_send(pudev, pcdc->g_cmd, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_req = setup->bRequest;
|
||||
g_len = setup->wLength;
|
||||
usbd_ctrl_recv(pudev, g_cmd, g_len);
|
||||
pcdc->g_req = setup->bRequest;
|
||||
pcdc->g_len = setup->wLength;
|
||||
usbd_ctrl_recv(pudev, pcdc->g_cmd, pcdc->g_len);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -173,10 +170,10 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&alt_setting, 1);
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&pcdc->alt_setting, 1);
|
||||
break;
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
alt_setting = setup->wValue;
|
||||
pcdc->alt_setting = setup->wValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -194,7 +191,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;
|
||||
|
||||
@@ -208,16 +205,17 @@ usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
* @param udev: usb device core handler 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;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
uint32_t recv_len = usbd_get_recv_len(pudev, 0);
|
||||
/* ...user code... */
|
||||
if( g_req == SET_LINE_CODING)
|
||||
if( pcdc->g_req == SET_LINE_CODING)
|
||||
{
|
||||
/* class process */
|
||||
usb_vcp_cmd_process(udev, g_req, g_cmd, recv_len);
|
||||
usb_vcp_cmd_process(udev, pcdc->g_req, pcdc->g_cmd, recv_len);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -229,16 +227,17 @@ 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)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
usbd_flush_tx_fifo(pudev, ept_num);
|
||||
g_tx_completed = 1;
|
||||
pcdc->g_tx_completed = 1;
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -249,16 +248,17 @@ 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;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* get endpoint receive data length */
|
||||
g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
pcdc->g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
/*set recv flag*/
|
||||
g_rx_completed = 1;
|
||||
pcdc->g_rx_completed = 1;
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -268,7 +268,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;
|
||||
|
||||
@@ -283,7 +283,7 @@ 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;
|
||||
switch(event)
|
||||
@@ -313,6 +313,23 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device cdc init
|
||||
* @param pcdc: to the structure of cdc_struct
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
static usb_sts_type cdc_struct_init(cdc_struct_type *pcdc)
|
||||
{
|
||||
pcdc->g_tx_completed = 1;
|
||||
pcdc->g_rx_completed = 0;
|
||||
pcdc->alt_setting = 0;
|
||||
pcdc->linecoding.bitrate = linecoding.bitrate;
|
||||
pcdc->linecoding.data = linecoding.data;
|
||||
pcdc->linecoding.format = linecoding.format;
|
||||
pcdc->linecoding.parity = linecoding.parity;
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb device class rx data process
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
@@ -322,21 +339,22 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
{
|
||||
uint16_t i_index = 0;
|
||||
uint16_t tmp_len = g_rxlen;
|
||||
uint16_t tmp_len = 0;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
|
||||
if(g_rx_completed == 0)
|
||||
if(pcdc->g_rx_completed == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
g_rx_completed = 0;
|
||||
tmp_len = g_rxlen;
|
||||
for(i_index = 0; i_index < g_rxlen; i_index ++)
|
||||
pcdc->g_rx_completed = 0;
|
||||
tmp_len = pcdc->g_rxlen;
|
||||
for(i_index = 0; i_index < pcdc->g_rxlen; i_index ++)
|
||||
{
|
||||
recv_data[i_index] = g_rx_buff[i_index];
|
||||
recv_data[i_index] = pcdc->g_rx_buff[i_index];
|
||||
}
|
||||
|
||||
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, g_rx_buff, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, pcdc->g_rx_buff, USBD_CDC_OUT_MAXPACKET_SIZE);
|
||||
|
||||
return tmp_len;
|
||||
}
|
||||
@@ -352,9 +370,10 @@ error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
{
|
||||
error_status status = SUCCESS;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
if(g_tx_completed)
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
if(pcdc->g_tx_completed)
|
||||
{
|
||||
g_tx_completed = 0;
|
||||
pcdc->g_tx_completed = 0;
|
||||
usbd_ept_send(pudev, USBD_CDC_BULK_IN_EPT, send_data, len);
|
||||
}
|
||||
else
|
||||
@@ -364,7 +383,6 @@ error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief usb device function
|
||||
* @param udev: to the structure of usbd_core_type
|
||||
@@ -373,25 +391,31 @@ error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
* @param len: buffer length
|
||||
* @retval none
|
||||
*/
|
||||
void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len)
|
||||
static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
cdc_struct_type *pcdc = (cdc_struct_type *)pudev->class_handler->pdata;
|
||||
switch(cmd)
|
||||
{
|
||||
case SET_LINE_CODING:
|
||||
linecoding.bitrate = (uint32_t)(buff[0] | (buff[1] << 8) | (buff[2] << 16) | (buff[3] <<24));
|
||||
linecoding.format = buff[4];
|
||||
linecoding.parity = buff[5];
|
||||
linecoding.data = buff[6];
|
||||
pcdc->linecoding.bitrate = (uint32_t)(buff[0] | (buff[1] << 8) | (buff[2] << 16) | (buff[3] <<24));
|
||||
pcdc->linecoding.format = buff[4];
|
||||
pcdc->linecoding.parity = buff[5];
|
||||
pcdc->linecoding.data = buff[6];
|
||||
#ifdef USB_VIRTUAL_COMPORT
|
||||
/* set hardware usart */
|
||||
usb_usart_config(pcdc->linecoding);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case GET_LINE_CODING:
|
||||
buff[0] = (uint8_t)linecoding.bitrate;
|
||||
buff[1] = (uint8_t)(linecoding.bitrate >> 8);
|
||||
buff[2] = (uint8_t)(linecoding.bitrate >> 16);
|
||||
buff[3] = (uint8_t)(linecoding.bitrate >> 24);
|
||||
buff[4] = (uint8_t)(linecoding.format);
|
||||
buff[5] = (uint8_t)(linecoding.parity);
|
||||
buff[6] = (uint8_t)(linecoding.data);
|
||||
buff[0] = (uint8_t)pcdc->linecoding.bitrate;
|
||||
buff[1] = (uint8_t)(pcdc->linecoding.bitrate >> 8);
|
||||
buff[2] = (uint8_t)(pcdc->linecoding.bitrate >> 16);
|
||||
buff[3] = (uint8_t)(pcdc->linecoding.bitrate >> 24);
|
||||
buff[4] = (uint8_t)(pcdc->linecoding.format);
|
||||
buff[5] = (uint8_t)(pcdc->linecoding.parity);
|
||||
buff[6] = (uint8_t)(pcdc->linecoding.data);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_class.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb cdc class file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -57,15 +57,9 @@ extern "C" {
|
||||
/**
|
||||
* @brief usb cdc in and out max packet size define
|
||||
*/
|
||||
#define USBD_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_OUT_MAXPACKET_SIZE 0x40
|
||||
#define USBD_CMD_MAXPACKET_SIZE 0x08
|
||||
|
||||
/**
|
||||
* @brief usb cdc class request code define
|
||||
*/
|
||||
#define SET_LINE_CODING 0x20
|
||||
#define GET_LINE_CODING 0x21
|
||||
#define USBD_CDC_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_CDC_OUT_MAXPACKET_SIZE 0x40
|
||||
#define USBD_CDC_CMD_MAXPACKET_SIZE 0x08
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -76,15 +70,19 @@ extern "C" {
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief usb cdc class set line coding struct
|
||||
* @brief usb cdc class struct
|
||||
*/
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
uint32_t bitrate; /* line coding baud rate */
|
||||
uint8_t format; /* line coding foramt */
|
||||
uint8_t parity; /* line coding parity */
|
||||
uint8_t data; /* line coding data bit */
|
||||
}linecoding_type;
|
||||
uint32_t alt_setting;
|
||||
uint8_t g_rx_buff[USBD_CDC_OUT_MAXPACKET_SIZE];
|
||||
uint8_t g_cmd[USBD_CDC_CMD_MAXPACKET_SIZE];
|
||||
uint8_t g_req;
|
||||
uint16_t g_len, g_rxlen;
|
||||
__IO uint8_t g_tx_completed, g_rx_completed;
|
||||
linecoding_type linecoding;
|
||||
}cdc_struct_type;
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -93,7 +91,7 @@ typedef struct
|
||||
/** @defgroup USB_cdc_class_exported_functions
|
||||
* @{
|
||||
*/
|
||||
extern usbd_class_handler class_handler;
|
||||
extern usbd_class_handler cdc_class_handler;
|
||||
uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data);
|
||||
error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_desc.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb cdc device descriptor
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -42,18 +42,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];
|
||||
@@ -61,7 +61,7 @@ static uint8_t g_usbd_desc_buffer[256];
|
||||
/**
|
||||
* @brief device descriptor handler structure
|
||||
*/
|
||||
usbd_desc_handler desc_handler =
|
||||
usbd_desc_handler cdc_desc_handler =
|
||||
{
|
||||
get_device_descriptor,
|
||||
get_device_qualifier,
|
||||
@@ -81,7 +81,7 @@ usbd_desc_handler 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 */
|
||||
@@ -91,10 +91,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_CDC_VENDOR_ID), /* idVendor */
|
||||
HBYTE(USBD_CDC_VENDOR_ID), /* idVendor */
|
||||
LBYTE(USBD_CDC_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_CDC_PRODUCT_ID), /* idProduct */
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
USB_MFC_STRING, /* Index of manufacturer string */
|
||||
@@ -109,12 +109,12 @@ 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_CDC_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_CDC_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
HBYTE(USBD_CDC_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
0x02, /* bNumInterfaces: 2 interface */
|
||||
0x01, /* bConfigurationValue: configuration value */
|
||||
0x00, /* iConfiguration: index of string descriptor describing
|
||||
@@ -135,8 +135,8 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
0x05, /* bFunctionLength: size of this descriptor in bytes */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
USBD_CDC_SUBTYPE_HEADER, /* bDescriptorSubtype: Header function Descriptor 0x00*/
|
||||
LBYTE(BCD_NUM),
|
||||
HBYTE(BCD_NUM), /* bcdCDC: USB class definitions for communications */
|
||||
LBYTE(CDC_BCD_NUM),
|
||||
HBYTE(CDC_BCD_NUM), /* bcdCDC: USB class definitions for communications */
|
||||
|
||||
0x05, /* bFunctionLength: size of this descriptor in bytes */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
@@ -159,9 +159,9 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_CDC_INT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_INTERRUPT, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_CMD_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_CMD_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
LBYTE(USBD_CDC_CMD_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_CDC_CMD_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
CDC_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
|
||||
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
|
||||
@@ -178,16 +178,16 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_CDC_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
LBYTE(USBD_CDC_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_CDC_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_CDC_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
LBYTE(USBD_CDC_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_CDC_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
|
||||
@@ -197,9 +197,9 @@ 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_string_lang_id[USBD_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD static uint8_t g_string_lang_id[USBD_CDC_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_CDC_SIZ_STRING_LANGID,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
0x09,
|
||||
0x04,
|
||||
@@ -211,42 +211,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_CDC_SIZ_STRING_SERIAL] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_SERIAL,
|
||||
USBD_CDC_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_CDC_CONFIG_DESC_SIZE,
|
||||
g_usbd_configuration
|
||||
};
|
||||
|
||||
/* langid descriptor */
|
||||
usbd_desc_t langid_descriptor =
|
||||
static usbd_desc_t langid_descriptor =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_CDC_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_CDC_SIZ_STRING_SERIAL,
|
||||
g_string_serial
|
||||
};
|
||||
|
||||
usbd_desc_t vp_desc;
|
||||
static usbd_desc_t vp_desc;
|
||||
|
||||
/**
|
||||
* @brief standard usb unicode convert
|
||||
@@ -254,7 +254,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;
|
||||
@@ -328,7 +328,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;
|
||||
}
|
||||
@@ -338,7 +338,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;
|
||||
}
|
||||
@@ -348,7 +348,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;
|
||||
}
|
||||
@@ -358,7 +358,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;
|
||||
}
|
||||
@@ -368,7 +368,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;
|
||||
}
|
||||
@@ -379,9 +379,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_CDC_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -391,9 +391,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_CDC_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -403,7 +403,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;
|
||||
@@ -414,9 +414,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_CDC_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -426,9 +426,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_CDC_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_desc.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb cdc descriptor header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -46,51 +46,36 @@ extern "C" {
|
||||
/** @defgroup USB_cdc_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief usb bcd number define
|
||||
*/
|
||||
#define BCD_NUM 0x0110
|
||||
#define CDC_BCD_NUM 0x0110
|
||||
|
||||
/**
|
||||
* @brief usb vendor id and product id define
|
||||
*/
|
||||
#define USBD_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRODUCT_ID 0x5740
|
||||
#define USBD_CDC_VENDOR_ID 0x2E3C
|
||||
#define USBD_CDC_PRODUCT_ID 0x5740
|
||||
|
||||
/**
|
||||
* @brief usb descriptor size define
|
||||
*/
|
||||
#define USBD_CONFIG_DESC_SIZE 67
|
||||
#define USBD_SIZ_STRING_LANGID 4
|
||||
#define USBD_SIZ_STRING_SERIAL 0x1A
|
||||
#define USBD_CDC_CONFIG_DESC_SIZE 67
|
||||
#define USBD_CDC_SIZ_STRING_LANGID 4
|
||||
#define USBD_CDC_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
/**
|
||||
* @brief usb string define(vendor, product configuration, interface)
|
||||
*/
|
||||
#define USBD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_DESC_PRODUCT_STRING "AT32 Virtual Com Port "
|
||||
#define USBD_DESC_CONFIGURATION_STRING "Virtual ComPort Config"
|
||||
#define USBD_DESC_INTERFACE_STRING "Virtual ComPort Interface"
|
||||
#define USBD_CDC_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_CDC_DESC_PRODUCT_STRING "AT32 Virtual Com Port "
|
||||
#define USBD_CDC_DESC_CONFIGURATION_STRING "Virtual ComPort Config"
|
||||
#define USBD_CDC_DESC_INTERFACE_STRING "Virtual ComPort Interface"
|
||||
|
||||
/**
|
||||
* @brief usb endpoint interval define
|
||||
*/
|
||||
#define HID_BINTERVAL_TIME 0xFF
|
||||
|
||||
/**
|
||||
* @brief usb hid class descriptor define
|
||||
*/
|
||||
#define USBD_CDC_CS_INTERFACE 0x24
|
||||
#define USBD_CDC_CS_ENDPOINT 0x25
|
||||
|
||||
/**
|
||||
* @brief usb hid class sub-type define
|
||||
*/
|
||||
#define USBD_CDC_SUBTYPE_HEADER 0x00
|
||||
#define USBD_CDC_SUBTYPE_CMF 0x01
|
||||
#define USBD_CDC_SUBTYPE_ACM 0x02
|
||||
#define USBD_CDC_SUBTYPE_UFD 0x06
|
||||
#define CDC_HID_BINTERVAL_TIME 0xFF
|
||||
|
||||
/**
|
||||
* @brief usb mcu id address deine
|
||||
@@ -98,14 +83,11 @@ extern "C" {
|
||||
#define MCU_ID1 (0x1FFFF7E8)
|
||||
#define MCU_ID2 (0x1FFFF7EC)
|
||||
#define MCU_ID3 (0x1FFFF7F0)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
extern uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN];
|
||||
extern uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE];
|
||||
extern usbd_desc_handler desc_handler;
|
||||
extern usbd_desc_handler cdc_desc_handler;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_keyboard_class.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb cdc and keyboard class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -40,36 +40,24 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
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);
|
||||
usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup);
|
||||
usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *setup);
|
||||
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);
|
||||
static usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup);
|
||||
static usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *setup);
|
||||
|
||||
void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len);
|
||||
/* usb rx and tx buffer */
|
||||
static uint32_t alt_setting = 0;
|
||||
static uint32_t hid_protocol = 0;
|
||||
static uint32_t hid_set_idle = 0;
|
||||
static uint8_t hid_state;
|
||||
uint8_t hid_set_report[64];
|
||||
static uint8_t g_rx_buff[USBD_OUT_MAXPACKET_SIZE];
|
||||
static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len);
|
||||
|
||||
static uint8_t g_cmd[USBD_CMD_MAXPACKET_SIZE];
|
||||
static uint8_t g_req;
|
||||
static uint16_t g_len, g_rxlen;
|
||||
__IO uint8_t g_tx_completed = 1, g_rx_completed = 0;
|
||||
|
||||
__IO uint8_t g_keyboard_tx_completed = 0;
|
||||
vcp_keyboard_type vcp_keyboard_struct;
|
||||
|
||||
#define SHIFT 0x80
|
||||
const unsigned char _asciimap[128] =
|
||||
const static unsigned char _asciimap[128] =
|
||||
{
|
||||
0x00,// NUL
|
||||
0x00,// SOH
|
||||
@@ -202,7 +190,7 @@ const unsigned char _asciimap[128] =
|
||||
0 // DEL
|
||||
};
|
||||
|
||||
linecoding_type linecoding =
|
||||
linecoding_type linecoding_vcpkybrd =
|
||||
{
|
||||
115200,
|
||||
0x00,
|
||||
@@ -225,6 +213,7 @@ usbd_class_handler cdc_keyboard_class_handler =
|
||||
class_out_handler,
|
||||
class_sof_handler,
|
||||
class_event_handler,
|
||||
&vcp_keyboard_struct
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -232,29 +221,34 @@ usbd_class_handler cdc_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;
|
||||
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_CDC_INT_EPT, EPT_INT_TYPE, USBD_CMD_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_VCPKYBRD_CDC_INT_EPT, EPT_INT_TYPE, USBD_VCPKYBRD_CMD_MAXPACKET_SIZE);
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_CDC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_VCPKYBRD_CDC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_VCPKYBRD_IN_MAXPACKET_SIZE);
|
||||
|
||||
/* open out endpoint */
|
||||
usbd_ept_open(pudev, USBD_CDC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_VCPKYBRD_CDC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_VCPKYBRD_OUT_MAXPACKET_SIZE);
|
||||
|
||||
/* open hid in endpoint */
|
||||
usbd_ept_open(pudev, USBD_HID_IN_EPT, EPT_INT_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_VCPKYBRD_HID_IN_EPT, EPT_INT_TYPE, USBD_VCPKYBRD_IN_MAXPACKET_SIZE);
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, g_rx_buff, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_VCPKYBRD_CDC_BULK_OUT_EPT, vcpkybrd->g_rx_buff, USBD_VCPKYBRD_OUT_MAXPACKET_SIZE);
|
||||
|
||||
g_tx_completed = 1;
|
||||
g_keyboard_tx_completed = 1;
|
||||
vcpkybrd->g_tx_completed = 1;
|
||||
vcpkybrd->g_keyboard_tx_completed = 1;
|
||||
|
||||
vcpkybrd->linecoding.bitrate = linecoding_vcpkybrd.bitrate;
|
||||
vcpkybrd->linecoding.data = linecoding_vcpkybrd.data;
|
||||
vcpkybrd->linecoding.format = linecoding_vcpkybrd.format;
|
||||
vcpkybrd->linecoding.parity = linecoding_vcpkybrd.parity;
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -263,22 +257,22 @@ 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 in endpoint */
|
||||
usbd_ept_close(pudev, USBD_CDC_INT_EPT);
|
||||
usbd_ept_close(pudev, USBD_VCPKYBRD_CDC_INT_EPT);
|
||||
|
||||
/* close in endpoint */
|
||||
usbd_ept_close(pudev, USBD_CDC_BULK_IN_EPT);
|
||||
usbd_ept_close(pudev, USBD_VCPKYBRD_CDC_BULK_IN_EPT);
|
||||
|
||||
/* close out endpoint */
|
||||
usbd_ept_close(pudev, USBD_CDC_BULK_OUT_EPT);
|
||||
usbd_ept_close(pudev, USBD_VCPKYBRD_CDC_BULK_OUT_EPT);
|
||||
|
||||
/* close in endpoint */
|
||||
usbd_ept_close(pudev, USBD_HID_IN_EPT);
|
||||
usbd_ept_close(pudev, USBD_VCPKYBRD_HID_IN_EPT);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -289,14 +283,14 @@ 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;
|
||||
switch(setup->bmRequestType & USB_REQ_RECIPIENT_MASK)
|
||||
{
|
||||
case USB_REQ_RECIPIENT_INTERFACE:
|
||||
if(setup->wIndex == HID_KEYBOARD_INTERFACE)
|
||||
if(setup->wIndex == VCPKYBRD_KEYBOARD_INTERFACE)
|
||||
{
|
||||
keyboard_class_setup_handler(udev, setup);
|
||||
}
|
||||
@@ -318,11 +312,12 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup packet
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
static usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
|
||||
|
||||
switch(setup->bmRequestType & USB_REQ_TYPE_RESERVED)
|
||||
{
|
||||
/* class request */
|
||||
@@ -331,14 +326,14 @@ usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
if(setup->bmRequestType & USB_REQ_DIR_DTH)
|
||||
{
|
||||
usb_vcp_cmd_process(udev, setup->bRequest, g_cmd, setup->wLength);
|
||||
usbd_ctrl_send(pudev, g_cmd, setup->wLength);
|
||||
usb_vcp_cmd_process(udev, setup->bRequest, vcpkybrd->g_cmd, setup->wLength);
|
||||
usbd_ctrl_send(pudev, vcpkybrd->g_cmd, setup->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_req = setup->bRequest;
|
||||
g_len = setup->wLength;
|
||||
usbd_ctrl_recv(pudev, g_cmd, g_len);
|
||||
vcpkybrd->g_req = setup->bRequest;
|
||||
vcpkybrd->g_len = setup->wLength;
|
||||
usbd_ctrl_recv(pudev, vcpkybrd->g_cmd, vcpkybrd->g_len);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -351,10 +346,10 @@ usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&alt_setting, 1);
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&vcpkybrd->alt_setting, 1);
|
||||
break;
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
alt_setting = setup->wValue;
|
||||
vcpkybrd->alt_setting = setup->wValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -373,10 +368,11 @@ usb_sts_type cdc_class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
* @param setup: setup packet
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
static usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
|
||||
uint16_t len;
|
||||
uint8_t *buf;
|
||||
|
||||
@@ -387,20 +383,20 @@ usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
switch(setup->bRequest)
|
||||
{
|
||||
case HID_REQ_SET_PROTOCOL:
|
||||
hid_protocol = (uint8_t)setup->wValue;
|
||||
vcpkybrd->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 *)&vcpkybrd->hid_protocol, 1);
|
||||
break;
|
||||
case HID_REQ_SET_IDLE:
|
||||
hid_set_idle = (uint8_t)(setup->wValue >> 8);
|
||||
vcpkybrd->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 *)&vcpkybrd->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);
|
||||
vcpkybrd->hid_state = HID_REQ_SET_REPORT;
|
||||
usbd_ctrl_recv(pudev, vcpkybrd->hid_set_report, setup->wLength);
|
||||
break;
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
@@ -414,21 +410,21 @@ usb_sts_type keyboard_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_VCPKYBRD_HID_SIZ_REPORT_DESC, setup->wLength);
|
||||
buf = (uint8_t *)g_usbd_vcpkybrd_hid_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_vcpkybrd_hid_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 *)&vcpkybrd->alt_setting, 1);
|
||||
break;
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
alt_setting = setup->wValue;
|
||||
vcpkybrd->alt_setting = setup->wValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -446,7 +442,7 @@ usb_sts_type keyboard_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;
|
||||
|
||||
@@ -460,22 +456,23 @@ 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;
|
||||
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
|
||||
uint32_t recv_len = usbd_get_recv_len(pudev, 0);
|
||||
/* ...user code... */
|
||||
if( g_req == SET_LINE_CODING)
|
||||
if( vcpkybrd->g_req == SET_LINE_CODING)
|
||||
{
|
||||
/* class process */
|
||||
usb_vcp_cmd_process(udev, g_req, g_cmd, recv_len);
|
||||
usb_vcp_cmd_process(udev, vcpkybrd->g_req, vcpkybrd->g_cmd, recv_len);
|
||||
}
|
||||
|
||||
if( hid_state == HID_REQ_SET_REPORT)
|
||||
if( vcpkybrd->hid_state == HID_REQ_SET_REPORT)
|
||||
{
|
||||
/* hid buffer process */
|
||||
hid_state = 0;
|
||||
vcpkybrd->hid_state = 0;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
@@ -486,20 +483,22 @@ 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;
|
||||
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
if((ept_num & 0x7F) == (USBD_CDC_BULK_IN_EPT & 0x7F))
|
||||
if((ept_num & 0x7F) == (USBD_VCPKYBRD_CDC_BULK_IN_EPT & 0x7F))
|
||||
{
|
||||
g_tx_completed = 1;
|
||||
vcpkybrd->g_tx_completed = 1;
|
||||
}
|
||||
if((ept_num & 0x7F) == (USBD_HID_IN_EPT & 0x7F))
|
||||
if((ept_num & 0x7F) == (USBD_VCPKYBRD_HID_IN_EPT & 0x7F))
|
||||
{
|
||||
g_keyboard_tx_completed = 1;
|
||||
vcpkybrd->g_keyboard_tx_completed = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -512,16 +511,17 @@ 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;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* get endpoint receive data length */
|
||||
g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
vcpkybrd->g_rxlen = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
/*set recv flag*/
|
||||
g_rx_completed = 1;
|
||||
vcpkybrd->g_rx_completed = 1;
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -531,7 +531,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;
|
||||
|
||||
@@ -546,7 +546,7 @@ 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;
|
||||
switch(event)
|
||||
@@ -577,25 +577,25 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
* @param recv_data: receive buffer
|
||||
* @retval receive data len
|
||||
*/
|
||||
uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
uint16_t usb_vcpkybrd_vcp_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
{
|
||||
uint16_t i_index = 0;
|
||||
uint16_t tmp_len = g_rxlen;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
if(g_rx_completed == 0)
|
||||
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
|
||||
uint16_t tmp_len = 0;
|
||||
if(vcpkybrd->g_rx_completed == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
g_rx_completed = 0;
|
||||
vcpkybrd->g_rx_completed = 0;
|
||||
|
||||
tmp_len = g_rxlen;
|
||||
for(i_index = 0; i_index < g_rxlen; i_index ++)
|
||||
tmp_len = vcpkybrd->g_rxlen;
|
||||
for(i_index = 0; i_index < vcpkybrd->g_rxlen; i_index ++)
|
||||
{
|
||||
recv_data[i_index] = g_rx_buff[i_index];
|
||||
recv_data[i_index] = vcpkybrd->g_rx_buff[i_index];
|
||||
}
|
||||
|
||||
usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, g_rx_buff, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_VCPKYBRD_CDC_BULK_OUT_EPT, vcpkybrd->g_rx_buff, USBD_VCPKYBRD_OUT_MAXPACKET_SIZE);
|
||||
|
||||
return tmp_len;
|
||||
}
|
||||
@@ -607,14 +607,15 @@ uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data)
|
||||
* @param len: send length
|
||||
* @retval error status
|
||||
*/
|
||||
error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
error_status usb_vcpkybrd_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
{
|
||||
error_status status = SUCCESS;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
if(g_tx_completed)
|
||||
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
|
||||
if(vcpkybrd->g_tx_completed)
|
||||
{
|
||||
g_tx_completed = 0;
|
||||
usbd_ept_send(pudev, USBD_CDC_BULK_IN_EPT, send_data, len);
|
||||
vcpkybrd->g_tx_completed = 0;
|
||||
usbd_ept_send(pudev, USBD_VCPKYBRD_CDC_BULK_IN_EPT, send_data, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -632,25 +633,27 @@ error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
* @param len: buffer length
|
||||
* @retval none
|
||||
*/
|
||||
void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len)
|
||||
static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
vcp_keyboard_type *vcpkybrd = (vcp_keyboard_type *)pudev->class_handler->pdata;
|
||||
switch(cmd)
|
||||
{
|
||||
case SET_LINE_CODING:
|
||||
linecoding.bitrate = (uint32_t)(buff[0] | (buff[1] << 8) | (buff[2] << 16) | (buff[3] <<24));
|
||||
linecoding.format = buff[4];
|
||||
linecoding.parity = buff[5];
|
||||
linecoding.data = buff[6];
|
||||
vcpkybrd->linecoding.bitrate = (uint32_t)(buff[0] | (buff[1] << 8) | (buff[2] << 16) | (buff[3] <<24));
|
||||
vcpkybrd->linecoding.format = buff[4];
|
||||
vcpkybrd->linecoding.parity = buff[5];
|
||||
vcpkybrd->linecoding.data = buff[6];
|
||||
break;
|
||||
|
||||
case GET_LINE_CODING:
|
||||
buff[0] = (uint8_t)linecoding.bitrate;
|
||||
buff[1] = (uint8_t)(linecoding.bitrate >> 8);
|
||||
buff[2] = (uint8_t)(linecoding.bitrate >> 16);
|
||||
buff[3] = (uint8_t)(linecoding.bitrate >> 24);
|
||||
buff[4] = (uint8_t)(linecoding.format);
|
||||
buff[5] = (uint8_t)(linecoding.parity);
|
||||
buff[6] = (uint8_t)(linecoding.data);
|
||||
buff[0] = (uint8_t)vcpkybrd->linecoding.bitrate;
|
||||
buff[1] = (uint8_t)(vcpkybrd->linecoding.bitrate >> 8);
|
||||
buff[2] = (uint8_t)(vcpkybrd->linecoding.bitrate >> 16);
|
||||
buff[3] = (uint8_t)(vcpkybrd->linecoding.bitrate >> 24);
|
||||
buff[4] = (uint8_t)(vcpkybrd->linecoding.format);
|
||||
buff[5] = (uint8_t)(vcpkybrd->linecoding.parity);
|
||||
buff[6] = (uint8_t)(vcpkybrd->linecoding.data);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -665,13 +668,13 @@ void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len)
|
||||
* @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_vcpkybrd_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_VCPKYBRD_HID_IN_EPT, report, len);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -683,7 +686,7 @@ usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len)
|
||||
* @param op: operation
|
||||
* @retval none
|
||||
*/
|
||||
void usb_hid_keyboard_send_char(void *udev, uint8_t ascii_code)
|
||||
void usb_vcpkybrd_keyboard_send_char(void *udev, uint8_t ascii_code)
|
||||
{
|
||||
uint8_t key_data = 0;
|
||||
static uint8_t temp = 0;
|
||||
@@ -712,13 +715,13 @@ void usb_hid_keyboard_send_char(void *udev, uint8_t ascii_code)
|
||||
{
|
||||
keyboard_buf[0] = 0;
|
||||
keyboard_buf[2] = 0;
|
||||
class_send_report(udev, keyboard_buf, 8);
|
||||
usb_vcpkybrd_class_send_report(udev, keyboard_buf, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
keyboard_buf[0] = key_data;
|
||||
keyboard_buf[2] = ascii_code;
|
||||
class_send_report(udev, keyboard_buf, 8);
|
||||
usb_vcpkybrd_class_send_report(udev, keyboard_buf, 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_keyboard_class.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb cdc and keyboard class file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -50,35 +50,19 @@ extern "C" {
|
||||
/**
|
||||
* @brief usb use endpoint define
|
||||
*/
|
||||
#define USBD_CDC_INT_EPT 0x82
|
||||
#define USBD_CDC_BULK_IN_EPT 0x81
|
||||
#define USBD_CDC_BULK_OUT_EPT 0x01
|
||||
#define USBD_HID_IN_EPT 0x83
|
||||
#define USBD_VCPKYBRD_CDC_INT_EPT 0x82
|
||||
#define USBD_VCPKYBRD_CDC_BULK_IN_EPT 0x81
|
||||
#define USBD_VCPKYBRD_CDC_BULK_OUT_EPT 0x01
|
||||
#define USBD_VCPKYBRD_HID_IN_EPT 0x83
|
||||
|
||||
/**
|
||||
* @brief usb in and out max packet size define
|
||||
*/
|
||||
#define USBD_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_OUT_MAXPACKET_SIZE 0x40
|
||||
#define USBD_CMD_MAXPACKET_SIZE 0x08
|
||||
#define USBD_VCPKYBRD_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_VCPKYBRD_OUT_MAXPACKET_SIZE 0x40
|
||||
#define USBD_VCPKYBRD_CMD_MAXPACKET_SIZE 0x08
|
||||
|
||||
/**
|
||||
* @brief usb cdc class request code define
|
||||
*/
|
||||
#define SET_LINE_CODING 0x20
|
||||
#define GET_LINE_CODING 0x21
|
||||
|
||||
/**
|
||||
* @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
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -87,16 +71,24 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief usb cdc class set line coding struct
|
||||
*/
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
uint32_t bitrate; /* line coding baud rate */
|
||||
uint8_t format; /* line coding foramt */
|
||||
uint8_t parity; /* line coding parity */
|
||||
uint8_t data; /* line coding data bit */
|
||||
}linecoding_type;
|
||||
uint32_t alt_setting;
|
||||
uint32_t hid_protocol;
|
||||
uint32_t hid_set_idle;
|
||||
|
||||
uint8_t hid_set_report[64];
|
||||
uint8_t g_rx_buff[USBD_VCPKYBRD_OUT_MAXPACKET_SIZE];
|
||||
uint8_t g_cmd[USBD_VCPKYBRD_CMD_MAXPACKET_SIZE];
|
||||
uint8_t g_req;
|
||||
uint8_t hid_state;
|
||||
uint16_t g_len, g_rxlen;
|
||||
__IO uint8_t g_tx_completed;
|
||||
__IO uint8_t g_rx_completed;
|
||||
__IO uint8_t g_keyboard_tx_completed;
|
||||
|
||||
linecoding_type linecoding;
|
||||
}vcp_keyboard_type;
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -106,11 +98,10 @@ typedef struct
|
||||
* @{
|
||||
*/
|
||||
extern usbd_class_handler cdc_keyboard_class_handler;
|
||||
extern __IO uint8_t g_keyboard_tx_completed;
|
||||
uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data);
|
||||
error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len);
|
||||
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);
|
||||
uint16_t usb_vcpkybrd_vcp_get_rxdata(void *udev, uint8_t *recv_data);
|
||||
error_status usb_vcpkybrd_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len);
|
||||
usb_sts_type usb_vcpkybrd_class_send_report(void *udev, uint8_t *report, uint16_t len);
|
||||
void usb_vcpkybrd_keyboard_send_char(void *udev, uint8_t ascii_code);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_keyboard_desc.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb cdc and keyboard device descriptor
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -40,18 +40,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];
|
||||
@@ -79,7 +79,7 @@ usbd_desc_handler cdc_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 */
|
||||
@@ -89,10 +89,10 @@ ALIGNED_HEAD uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL =
|
||||
0x02, /* bDeviceSubClass */
|
||||
0x01, /* 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_VCPKYBRD_VENDOR_ID), /* idVendor */
|
||||
HBYTE(USBD_VCPKYBRD_VENDOR_ID), /* idVendor */
|
||||
LBYTE(USBD_VCPKYBRD_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_VCPKYBRD_PRODUCT_ID), /* idProduct */
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
USB_MFC_STRING, /* Index of manufacturer string */
|
||||
@@ -107,12 +107,12 @@ 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_VCPKYBRD_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_VCPKYBRD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
HBYTE(USBD_VCPKYBRD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
0x03, /* bNumInterfaces: 2 interface */
|
||||
0x01, /* bConfigurationValue: configuration value */
|
||||
0x00, /* iConfiguration: index of string descriptor describing
|
||||
@@ -131,7 +131,7 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
|
||||
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
CDC_INTERFACE, /* bInterfaceNumber: number of interface */
|
||||
VCPKYBRD_CDC_INTERFACE, /* bInterfaceNumber: number of interface */
|
||||
0x00, /* bAlternateSetting: alternate set */
|
||||
0x01, /* bNumEndpoints: number of endpoints */
|
||||
USB_CLASS_CODE_CDC, /* bInterfaceClass: CDC class code */
|
||||
@@ -142,8 +142,8 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
0x05, /* bFunctionLength: size of this descriptor in bytes */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
USBD_CDC_SUBTYPE_HEADER, /* bDescriptorSubtype: Header function Descriptor 0x00*/
|
||||
LBYTE(BCD_NUM),
|
||||
HBYTE(BCD_NUM), /* bcdCDC: USB class definitions for communications */
|
||||
LBYTE(VCPKYBRD_BCD_NUM),
|
||||
HBYTE(VCPKYBRD_BCD_NUM), /* bcdCDC: USB class definitions for communications */
|
||||
|
||||
0x05, /* bFunctionLength: size of this descriptor in bytes */
|
||||
USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */
|
||||
@@ -164,16 +164,16 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_CDC_INT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USBD_VCPKYBRD_CDC_INT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_INTERRUPT, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_CMD_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_CMD_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
LBYTE(USBD_VCPKYBRD_CMD_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_VCPKYBRD_CMD_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
VCPKYBRD_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
|
||||
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
CDC_DATA_INTERFACE, /* bInterfaceNumber: number of interface */
|
||||
VCPKYBRD_CDC_DATA_INTERFACE, /* bInterfaceNumber: number of interface */
|
||||
0x00, /* bAlternateSetting: alternate set */
|
||||
0x02, /* bNumEndpoints: number of endpoints */
|
||||
USB_CLASS_CODE_CDCDATA, /* bInterfaceClass: CDC-data class code */
|
||||
@@ -183,18 +183,18 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_CDC_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USBD_VCPKYBRD_CDC_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
LBYTE(USBD_VCPKYBRD_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_VCPKYBRD_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_CDC_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USBD_VCPKYBRD_CDC_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
LBYTE(USBD_VCPKYBRD_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_VCPKYBRD_OUT_MAXPACKET_SIZE),/* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
0x08, /* bLength */
|
||||
@@ -208,7 +208,7 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
|
||||
USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */
|
||||
USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */
|
||||
HID_KEYBOARD_INTERFACE, /* bInterfaceNumber: number of interface */
|
||||
VCPKYBRD_KEYBOARD_INTERFACE, /* bInterfaceNumber: number of interface */
|
||||
0x00, /* bAlternateSetting: alternate set */
|
||||
0x01, /* bNumEndpoints: number of endpoints */
|
||||
USB_CLASS_CODE_HID, /* bInterfaceClass: class code hid */
|
||||
@@ -218,21 +218,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(VCPKYBRD_BCD_NUM),
|
||||
HBYTE(VCPKYBRD_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_vcpkybrd_hid_report)),
|
||||
HBYTE(sizeof(g_usbd_vcpkybrd_hid_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_VCPKYBRD_HID_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_VCPKYBRD_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_VCPKYBRD_IN_MAXPACKET_SIZE),/* wMaxPacketSize: maximum packe size this endpoint */
|
||||
VCPKYBRD_HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -241,17 +241,17 @@ 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_hid_usb_desc[9] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_vcpkybrd_hid_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(VCPKYBRD_BCD_NUM),
|
||||
HBYTE(VCPKYBRD_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_vcpkybrd_hid_report)),
|
||||
HBYTE(sizeof(g_usbd_vcpkybrd_hid_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -260,7 +260,7 @@ 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_usbd_hid_report[USBD_HID_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD uint8_t g_usbd_vcpkybrd_hid_report[USBD_VCPKYBRD_HID_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x06, // USAGE (Keyboard)
|
||||
@@ -301,9 +301,9 @@ 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_string_lang_id[USBD_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD static uint8_t g_string_lang_id[USBD_VCPKYBRD_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_VCPKYBRD_SIZ_STRING_LANGID,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
0x09,
|
||||
0x04,
|
||||
@@ -315,42 +315,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_VCPKYBRD_SIZ_STRING_SERIAL] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_SERIAL,
|
||||
USBD_VCPKYBRD_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_VCPKYBRD_CONFIG_DESC_SIZE,
|
||||
g_usbd_configuration
|
||||
};
|
||||
|
||||
/* langid descriptor */
|
||||
usbd_desc_t langid_descriptor =
|
||||
static usbd_desc_t langid_descriptor =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_VCPKYBRD_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_VCPKYBRD_SIZ_STRING_SERIAL,
|
||||
g_string_serial
|
||||
};
|
||||
|
||||
usbd_desc_t vp_desc;
|
||||
static usbd_desc_t vp_desc;
|
||||
|
||||
/**
|
||||
* @brief standard usb unicode convert
|
||||
@@ -358,7 +358,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;
|
||||
@@ -432,7 +432,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;
|
||||
}
|
||||
@@ -442,7 +442,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;
|
||||
}
|
||||
@@ -452,7 +452,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;
|
||||
}
|
||||
@@ -462,7 +462,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;
|
||||
}
|
||||
@@ -472,7 +472,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;
|
||||
}
|
||||
@@ -483,9 +483,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_VCPKYBRD_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -495,9 +495,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_VCPKYBRD_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -507,7 +507,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;
|
||||
@@ -518,9 +518,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_VCPKYBRD_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -530,9 +530,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_VCPKYBRD_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file cdc_keyboard_desc.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb cdc and keyboard descriptor header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -50,67 +50,42 @@ extern "C" {
|
||||
/**
|
||||
* @brief usb bcd number define
|
||||
*/
|
||||
#define BCD_NUM 0x0110
|
||||
#define VCPKYBRD_BCD_NUM 0x0110
|
||||
|
||||
/**
|
||||
* @brief usb vendor id and product id define
|
||||
*/
|
||||
#define USBD_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRODUCT_ID 0x5750
|
||||
#define USBD_VCPKYBRD_VENDOR_ID 0x2E3C
|
||||
#define USBD_VCPKYBRD_PRODUCT_ID 0x5750
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
||||
/**
|
||||
* @brief usb descriptor size define
|
||||
*/
|
||||
#define USBD_CONFIG_DESC_SIZE 108
|
||||
#define USBD_HID_SIZ_REPORT_DESC 63
|
||||
#define USBD_SIZ_STRING_LANGID 4
|
||||
#define USBD_SIZ_STRING_SERIAL 0x1A
|
||||
#define USBD_VCPKYBRD_CONFIG_DESC_SIZE 108
|
||||
#define USBD_VCPKYBRD_HID_SIZ_REPORT_DESC 63
|
||||
#define USBD_VCPKYBRD_SIZ_STRING_LANGID 4
|
||||
#define USBD_VCPKYBRD_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
/**
|
||||
* @brief usb string define(vendor, product configuration, interface)
|
||||
*/
|
||||
#define USBD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_DESC_PRODUCT_STRING "AT32 Composite VCP and Keyboard"
|
||||
#define USBD_DESC_CONFIGURATION_STRING "Composite VCP and Keyboard Config"
|
||||
#define USBD_DESC_INTERFACE_STRING "Composite VCP and Keyboard Interface"
|
||||
#define USBD_VCPKYBRD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_VCPKYBRD_DESC_PRODUCT_STRING "AT32 Composite VCP and Keyboard"
|
||||
#define USBD_VCPKYBRD_DESC_CONFIGURATION_STRING "Composite VCP and Keyboard Config"
|
||||
#define USBD_VCPKYBRD_DESC_INTERFACE_STRING "Composite VCP and Keyboard Interface"
|
||||
|
||||
/**
|
||||
* @brief usb endpoint interval define
|
||||
*/
|
||||
#define HID_BINTERVAL_TIME 0x0A
|
||||
|
||||
/**
|
||||
* @brief usb cdc class descriptor define
|
||||
*/
|
||||
#define USBD_CDC_CS_INTERFACE 0x24
|
||||
#define USBD_CDC_CS_ENDPOINT 0x25
|
||||
|
||||
/**
|
||||
* @brief usb cdc class sub-type define
|
||||
*/
|
||||
#define USBD_CDC_SUBTYPE_HEADER 0x00
|
||||
#define USBD_CDC_SUBTYPE_CMF 0x01
|
||||
#define USBD_CDC_SUBTYPE_ACM 0x02
|
||||
#define USBD_CDC_SUBTYPE_UFD 0x06
|
||||
#define VCPKYBRD_HID_BINTERVAL_TIME 0x0A
|
||||
|
||||
/**
|
||||
* @brief usb interface define
|
||||
*/
|
||||
#define CDC_INTERFACE 0x00
|
||||
#define CDC_DATA_INTERFACE 0x01
|
||||
#define HID_KEYBOARD_INTERFACE 0x02
|
||||
#define VCPKYBRD_CDC_INTERFACE 0x00
|
||||
#define VCPKYBRD_CDC_DATA_INTERFACE 0x01
|
||||
#define VCPKYBRD_KEYBOARD_INTERFACE 0x02
|
||||
|
||||
/**
|
||||
* @brief usb mcu id address deine
|
||||
@@ -122,11 +97,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_vcpkybrd_hid_report[USBD_VCPKYBRD_HID_SIZ_REPORT_DESC];
|
||||
extern uint8_t g_vcpkybrd_hid_usb_desc[9];
|
||||
extern usbd_desc_handler cdc_keyboard_desc_handler;
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file custom_hid_class.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb custom hid class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -40,27 +40,18 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len);
|
||||
/* usb hid rx and tx buffer */
|
||||
static uint8_t g_rxhid_buff[USBD_OUT_MAXPACKET_SIZE];
|
||||
static uint8_t g_txhid_buff[USBD_IN_MAXPACKET_SIZE];
|
||||
|
||||
/* custom 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;
|
||||
uint8_t hid_set_report[64];
|
||||
static void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len);
|
||||
custom_hid_type custom_hid_struct;
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler custom_hid_class_handler =
|
||||
@@ -74,6 +65,7 @@ usbd_class_handler custom_hid_class_handler =
|
||||
class_out_handler,
|
||||
class_sof_handler,
|
||||
class_event_handler,
|
||||
&custom_hid_struct
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -81,19 +73,19 @@ usbd_class_handler custom_hid_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;
|
||||
|
||||
custom_hid_type *pcshid = (custom_hid_type *)pudev->class_handler->pdata;
|
||||
/* open custom hid in endpoint */
|
||||
usbd_ept_open(pudev, USBD_HID_IN_EPT, EPT_INT_TYPE, USBD_IN_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_CUSTOM_HID_IN_EPT, EPT_INT_TYPE, USBD_CUSTOM_IN_MAXPACKET_SIZE);
|
||||
|
||||
/* open custom hid out endpoint */
|
||||
usbd_ept_open(pudev, USBD_HID_OUT_EPT, EPT_INT_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_CUSTOM_HID_OUT_EPT, EPT_INT_TYPE, USBD_CUSTOM_OUT_MAXPACKET_SIZE);
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_HID_OUT_EPT, g_rxhid_buff, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_CUSTOM_HID_OUT_EPT, pcshid->g_rxhid_buff, USBD_CUSTOM_OUT_MAXPACKET_SIZE);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -103,16 +95,16 @@ 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 custom hid in endpoint */
|
||||
usbd_ept_close(pudev, USBD_HID_IN_EPT);
|
||||
usbd_ept_close(pudev, USBD_CUSTOM_HID_IN_EPT);
|
||||
|
||||
/* close custom hid out endpoint */
|
||||
usbd_ept_close(pudev, USBD_HID_OUT_EPT);
|
||||
usbd_ept_close(pudev, USBD_CUSTOM_HID_OUT_EPT);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -123,10 +115,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;
|
||||
custom_hid_type *pcshid = (custom_hid_type *)pudev->class_handler->pdata;
|
||||
uint16_t len;
|
||||
uint8_t *buf;
|
||||
|
||||
@@ -137,20 +130,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;
|
||||
pcshid->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 *)&pcshid->hid_protocol, 1);
|
||||
break;
|
||||
case HID_REQ_SET_IDLE:
|
||||
hid_set_idle = (uint8_t)(setup->wValue >> 8);
|
||||
pcshid->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 *)&pcshid->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);
|
||||
pcshid->hid_state = HID_REQ_SET_REPORT;
|
||||
usbd_ctrl_recv(pudev, pcshid->hid_set_report, setup->wLength);
|
||||
break;
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
@@ -164,21 +157,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_CUSHID_SIZ_REPORT_DESC, setup->wLength);
|
||||
buf = (uint8_t *)g_usbd_custom_hid_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_custom_hid_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 *)&pcshid->alt_setting, 1);
|
||||
break;
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
alt_setting = setup->wValue;
|
||||
pcshid->alt_setting = setup->wValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -196,7 +189,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;
|
||||
|
||||
@@ -210,17 +203,18 @@ 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;
|
||||
custom_hid_type *pcshid = (custom_hid_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( pcshid->hid_state == HID_REQ_SET_REPORT)
|
||||
{
|
||||
/* hid buffer process */
|
||||
usb_hid_buf_process(udev, hid_set_report, recv_len);
|
||||
hid_state = 0;
|
||||
usb_hid_buf_process(udev, pcshid->hid_set_report, recv_len);
|
||||
pcshid->hid_state = 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -232,7 +226,7 @@ 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;
|
||||
|
||||
@@ -249,19 +243,20 @@ 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;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
custom_hid_type *pcshid = (custom_hid_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* get endpoint receive data length */
|
||||
uint32_t recv_len = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
/* hid buffer process */
|
||||
usb_hid_buf_process(udev, g_rxhid_buff, recv_len);
|
||||
usb_hid_buf_process(udev, pcshid->g_rxhid_buff, recv_len);
|
||||
|
||||
/* start receive next packet */
|
||||
usbd_ept_recv(pudev, USBD_HID_OUT_EPT, g_rxhid_buff, recv_len);
|
||||
usbd_ept_recv(pudev, USBD_CUSTOM_HID_OUT_EPT, pcshid->g_rxhid_buff, recv_len);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -271,7 +266,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;
|
||||
|
||||
@@ -286,7 +281,7 @@ 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;
|
||||
switch(event)
|
||||
@@ -318,13 +313,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 custom_hid_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_CUSTOM_HID_IN_EPT, report, len);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -336,15 +331,16 @@ usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len)
|
||||
* @param len: report length
|
||||
* @retval none
|
||||
*/
|
||||
void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
static void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
{
|
||||
uint32_t i_index;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
custom_hid_type *pcshid = (custom_hid_type *)pudev->class_handler->pdata;
|
||||
|
||||
switch(report[0])
|
||||
{
|
||||
case HID_REPORT_ID_2:
|
||||
if(g_rxhid_buff[1] == 0)
|
||||
if(pcshid->g_rxhid_buff[1] == 0)
|
||||
{
|
||||
at32_led_off(LED2);
|
||||
}
|
||||
@@ -354,7 +350,7 @@ void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
}
|
||||
break;
|
||||
case HID_REPORT_ID_3:
|
||||
if(g_rxhid_buff[1] == 0)
|
||||
if(pcshid->g_rxhid_buff[1] == 0)
|
||||
{
|
||||
at32_led_off(LED3);
|
||||
}
|
||||
@@ -364,7 +360,7 @@ void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
}
|
||||
break;
|
||||
case HID_REPORT_ID_4:
|
||||
if(g_rxhid_buff[1] == 0)
|
||||
if(pcshid->g_rxhid_buff[1] == 0)
|
||||
{
|
||||
at32_led_off(LED4);
|
||||
}
|
||||
@@ -376,9 +372,9 @@ void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len)
|
||||
case HID_REPORT_ID_6:
|
||||
for(i_index = 0; i_index < len; i_index ++)
|
||||
{
|
||||
g_txhid_buff[i_index] = report[i_index];
|
||||
pcshid->g_txhid_buff[i_index] = report[i_index];
|
||||
}
|
||||
usbd_ept_send(pudev, USBD_HID_IN_EPT, g_txhid_buff, len);
|
||||
usbd_ept_send(pudev, USBD_CUSTOM_HID_IN_EPT, pcshid->g_txhid_buff, len);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file custom_hid_class.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb hid header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -50,14 +50,14 @@ extern "C" {
|
||||
/**
|
||||
* @brief usb custom hid use endpoint define
|
||||
*/
|
||||
#define USBD_HID_IN_EPT 0x81
|
||||
#define USBD_HID_OUT_EPT 0x01
|
||||
#define USBD_CUSTOM_HID_IN_EPT 0x81
|
||||
#define USBD_CUSTOM_HID_OUT_EPT 0x01
|
||||
|
||||
/**
|
||||
* @brief usb custom hid in and out max packet size define
|
||||
*/
|
||||
#define USBD_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_OUT_MAXPACKET_SIZE 0x40
|
||||
#define USBD_CUSTOM_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_CUSTOM_OUT_MAXPACKET_SIZE 0x40
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -67,17 +67,17 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief usb custom 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
|
||||
typedef struct
|
||||
{
|
||||
uint8_t g_rxhid_buff[USBD_CUSTOM_OUT_MAXPACKET_SIZE];
|
||||
uint8_t g_txhid_buff[USBD_CUSTOM_IN_MAXPACKET_SIZE];
|
||||
|
||||
uint32_t hid_protocol;
|
||||
uint32_t hid_set_idle;
|
||||
uint32_t alt_setting;
|
||||
uint8_t hid_state;
|
||||
uint8_t hid_set_report[64];
|
||||
}custom_hid_type;
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -87,7 +87,7 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
extern usbd_class_handler custom_hid_class_handler;
|
||||
usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len);
|
||||
usb_sts_type custom_hid_class_send_report(void *udev, uint8_t *report, uint16_t len);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file custom_hid_desc.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb hid device descriptor
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -40,19 +40,18 @@
|
||||
/** @defgroup USB_custom_hid_desc_private_functions
|
||||
* @{
|
||||
*/
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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];
|
||||
@@ -60,7 +59,7 @@ static uint8_t g_usbd_desc_buffer[256];
|
||||
/**
|
||||
* @brief custom hid device descriptor handler structure
|
||||
*/
|
||||
usbd_desc_handler hid_desc_handler =
|
||||
usbd_desc_handler custom_hid_desc_handler =
|
||||
{
|
||||
get_device_descriptor,
|
||||
get_device_qualifier,
|
||||
@@ -80,7 +79,7 @@ usbd_desc_handler hid_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 +89,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_CUSHID_VENDOR_ID), /* idVendor */
|
||||
HBYTE(USBD_CUSHID_VENDOR_ID), /* idVendor */
|
||||
LBYTE(USBD_CUSHID_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_CUSHID_PRODUCT_ID), /* idProduct */
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
USB_MFC_STRING, /* Index of manufacturer string */
|
||||
@@ -108,12 +107,12 @@ 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_CUSHID_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_CUSHID_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
HBYTE(USBD_CUSHID_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
0x01, /* bNumInterfaces: 1 interface */
|
||||
0x01, /* bConfigurationValue: configuration value */
|
||||
0x00, /* iConfiguration: index of string descriptor describing
|
||||
@@ -133,29 +132,29 @@ 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(CUSHID_BCD_NUM),
|
||||
HBYTE(CUSHID_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_custom_hid_report)),
|
||||
HBYTE(sizeof(g_usbd_custom_hid_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_CUSTOM_HID_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_CUSTOM_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_CUSTOM_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
CUSHID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_HID_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USBD_CUSTOM_HID_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_INTERRUPT, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
LBYTE(USBD_CUSTOM_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_CUSTOM_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
CUSHID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -164,7 +163,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_custom_hid_report[USBD_CUSHID_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
0x06, 0xFF, 0x00, /* USAGE_PAGE(Vendor Page:0xFF00) */
|
||||
0x09, 0x01, /* USAGE (Demo Kit) */
|
||||
@@ -262,17 +261,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_custom_hid_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(CUSHID_BCD_NUM),
|
||||
HBYTE(CUSHID_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_custom_hid_report)),
|
||||
HBYTE(sizeof(g_usbd_custom_hid_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
};
|
||||
|
||||
|
||||
@@ -282,9 +281,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_CUSHID_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_CUSHID_SIZ_STRING_LANGID,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
0x09,
|
||||
0x04,
|
||||
@@ -296,42 +295,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_CUSHID_SIZ_STRING_SERIAL] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_SERIAL,
|
||||
USBD_CUSHID_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_CUSHID_CONFIG_DESC_SIZE,
|
||||
g_usbd_configuration
|
||||
};
|
||||
|
||||
/* langid descriptor */
|
||||
usbd_desc_t langid_descriptor =
|
||||
static usbd_desc_t langid_descriptor =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_CUSHID_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_CUSHID_SIZ_STRING_SERIAL,
|
||||
g_string_serial
|
||||
};
|
||||
|
||||
usbd_desc_t vp_desc;
|
||||
static usbd_desc_t vp_desc;
|
||||
|
||||
/**
|
||||
* @brief standard usb unicode convert
|
||||
@@ -339,7 +338,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;
|
||||
@@ -413,7 +412,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;
|
||||
}
|
||||
@@ -423,7 +422,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;
|
||||
}
|
||||
@@ -433,7 +432,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;
|
||||
}
|
||||
@@ -443,7 +442,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;
|
||||
}
|
||||
@@ -453,7 +452,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;
|
||||
}
|
||||
@@ -464,9 +463,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_CUSHID_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -476,9 +475,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_CUSHID_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -488,7 +487,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;
|
||||
@@ -499,9 +498,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_CUSHID_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -511,9 +510,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_CUSHID_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file custom_hid_desc.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb custom hid descriptor header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -46,46 +46,40 @@ extern "C" {
|
||||
/** @defgroup USB_custom_hid_desc_definition
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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 CUSHID_BCD_NUM 0x0110
|
||||
|
||||
/**
|
||||
* @brief usb vendor id and product id define
|
||||
*/
|
||||
#define USBD_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRODUCT_ID 0x5745
|
||||
#define USBD_CUSHID_VENDOR_ID 0x2E3C
|
||||
#define USBD_CUSHID_PRODUCT_ID 0x5745
|
||||
|
||||
/**
|
||||
* @brief usb descriptor size define
|
||||
*/
|
||||
#define USBD_CONFIG_DESC_SIZE 41
|
||||
#define USBD_HID_SIZ_REPORT_DESC 126
|
||||
#define USBD_SIZ_STRING_LANGID 4
|
||||
#define USBD_SIZ_STRING_SERIAL 0x1A
|
||||
#define USBD_CUSHID_CONFIG_DESC_SIZE 41
|
||||
#define USBD_CUSHID_SIZ_REPORT_DESC 126
|
||||
#define USBD_CUSHID_SIZ_STRING_LANGID 4
|
||||
#define USBD_CUSHID_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
/**
|
||||
* @brief usb string define(vendor, product configuration, interface)
|
||||
*/
|
||||
#define USBD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_DESC_PRODUCT_STRING "Custom HID"
|
||||
#define USBD_DESC_CONFIGURATION_STRING "Custom HID Config"
|
||||
#define USBD_DESC_INTERFACE_STRING "Custom HID Interface"
|
||||
#define USBD_CUSHID_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_CUSHID_DESC_PRODUCT_STRING "Custom HID"
|
||||
#define USBD_CUSHID_DESC_CONFIGURATION_STRING "Custom HID Config"
|
||||
#define USBD_CUSHID_DESC_INTERFACE_STRING "Custom HID Interface"
|
||||
|
||||
#define CUSHID_BINTERVAL_TIME 0x0A
|
||||
|
||||
/**
|
||||
* @brief usb hid endpoint interval define
|
||||
* @brief usb hid report id define
|
||||
*/
|
||||
#define HID_BINTERVAL_TIME 0x0A
|
||||
|
||||
/**
|
||||
* @brief usb hid report id define
|
||||
*/
|
||||
@@ -99,19 +93,16 @@ extern "C" {
|
||||
/**
|
||||
* @brief usb mcu id address deine
|
||||
*/
|
||||
#define MCU_ID1 (0x1FFFF7E8)
|
||||
#define MCU_ID2 (0x1FFFF7EC)
|
||||
#define MCU_ID3 (0x1FFFF7F0)
|
||||
#define MCU_ID1 (0x1FFFF7E8)
|
||||
#define MCU_ID2 (0x1FFFF7EC)
|
||||
#define MCU_ID3 (0x1FFFF7F0)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
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 usbd_desc_handler hid_desc_handler;
|
||||
extern uint8_t g_usbd_custom_hid_report[USBD_CUSHID_SIZ_REPORT_DESC];
|
||||
extern uint8_t g_custom_hid_usb_desc[9];
|
||||
extern usbd_desc_handler custom_hid_desc_handler;
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file hid_iap_class.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb hid iap class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -41,26 +41,15 @@
|
||||
*/
|
||||
|
||||
|
||||
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);
|
||||
|
||||
void usb_hid_buf_process(void *udev, uint8_t *report, uint16_t len);
|
||||
/* usb hid rx and tx buffer */
|
||||
static uint8_t g_rxhid_buff[USBD_OUT_MAXPACKET_SIZE];
|
||||
|
||||
/* custom 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;
|
||||
uint8_t hid_set_report[64];
|
||||
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);
|
||||
|
||||
iap_info_type iap_info;
|
||||
|
||||
@@ -76,6 +65,7 @@ usbd_class_handler hid_iap_class_handler =
|
||||
class_out_handler,
|
||||
class_sof_handler,
|
||||
class_event_handler,
|
||||
&iap_info
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -83,19 +73,19 @@ usbd_class_handler hid_iap_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;
|
||||
|
||||
iap_info_type *piap = (iap_info_type *)pudev->class_handler->pdata;
|
||||
/* open hid iap in endpoint */
|
||||
usbd_ept_open(pudev, USBD_HID_IN_EPT, EPT_INT_TYPE, USBD_IN_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_HIDIAP_IN_EPT, EPT_INT_TYPE, USBD_HIDIAP_IN_MAXPACKET_SIZE);
|
||||
|
||||
/* open hid iap out endpoint */
|
||||
usbd_ept_open(pudev, USBD_HID_OUT_EPT, EPT_INT_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_HIDIAP_OUT_EPT, EPT_INT_TYPE, USBD_HIDIAP_OUT_MAXPACKET_SIZE);
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_HID_OUT_EPT, g_rxhid_buff, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_HIDIAP_OUT_EPT, piap->g_rxhid_buff, USBD_HIDIAP_OUT_MAXPACKET_SIZE);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -105,16 +95,16 @@ 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 iap in endpoint */
|
||||
usbd_ept_close(pudev, USBD_HID_IN_EPT);
|
||||
usbd_ept_close(pudev, USBD_HIDIAP_IN_EPT);
|
||||
|
||||
/* close hid iap out endpoint */
|
||||
usbd_ept_close(pudev, USBD_HID_OUT_EPT);
|
||||
usbd_ept_close(pudev, USBD_HIDIAP_OUT_EPT);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -125,10 +115,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;
|
||||
iap_info_type *piap = (iap_info_type *)pudev->class_handler->pdata;
|
||||
uint16_t len;
|
||||
uint8_t *buf;
|
||||
|
||||
@@ -139,20 +130,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;
|
||||
piap->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 *)&piap->hid_protocol, 1);
|
||||
break;
|
||||
case HID_REQ_SET_IDLE:
|
||||
hid_set_idle = (uint8_t)(setup->wValue >> 8);
|
||||
piap->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 *)&piap->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);
|
||||
piap->hid_state = HID_REQ_SET_REPORT;
|
||||
usbd_ctrl_recv(pudev, piap->hid_set_report, setup->wLength);
|
||||
break;
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
@@ -166,21 +157,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_HIDIAP_SIZ_REPORT_DESC, setup->wLength);
|
||||
buf = (uint8_t *)g_usbd_hidiap_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_hidiap_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 *)&piap->alt_setting, 1);
|
||||
break;
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
alt_setting = setup->wValue;
|
||||
piap->alt_setting = setup->wValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -198,7 +189,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;
|
||||
|
||||
@@ -212,16 +203,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;
|
||||
iap_info_type *piap = (iap_info_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( piap->hid_state == HID_REQ_SET_REPORT)
|
||||
{
|
||||
/* hid buffer process */
|
||||
hid_state = 0;
|
||||
piap->hid_state = 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -233,7 +225,7 @@ 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;
|
||||
|
||||
@@ -251,19 +243,20 @@ 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;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
iap_info_type *piap = (iap_info_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* get endpoint receive data length */
|
||||
uint32_t recv_len = usbd_get_recv_len(pudev, ept_num);
|
||||
|
||||
/* hid iap process */
|
||||
usbd_hid_iap_process(udev, g_rxhid_buff, recv_len);
|
||||
usbd_hid_iap_process(udev, piap->g_rxhid_buff, recv_len);
|
||||
|
||||
/* start receive next packet */
|
||||
usbd_ept_recv(pudev, USBD_HID_OUT_EPT, g_rxhid_buff, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_HIDIAP_OUT_EPT, piap->g_rxhid_buff, USBD_HIDIAP_OUT_MAXPACKET_SIZE);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -273,7 +266,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;
|
||||
|
||||
@@ -288,7 +281,7 @@ 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;
|
||||
switch(event)
|
||||
@@ -320,13 +313,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_iap_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_HIDIAP_IN_EPT, report, len);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file hid_iap_class.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb hid iap header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -49,23 +49,11 @@ extern "C" {
|
||||
*/
|
||||
|
||||
|
||||
#define USBD_HID_IN_EPT 0x81
|
||||
#define USBD_HID_OUT_EPT 0x01
|
||||
#define USBD_HIDIAP_IN_EPT 0x81
|
||||
#define USBD_HIDIAP_OUT_EPT 0x01
|
||||
|
||||
#define USBD_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_OUT_MAXPACKET_SIZE 0x40
|
||||
|
||||
#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
|
||||
#define USBD_HIDIAP_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_HIDIAP_OUT_MAXPACKET_SIZE 0x40
|
||||
|
||||
#define FLASH_SIZE_REG() ((*(uint32_t *)0x1FFFF7E0) & 0xFFFF) /*Get Flash size*/
|
||||
#define KB_TO_B(kb) ((kb) << 10)
|
||||
@@ -117,8 +105,8 @@ typedef struct
|
||||
{
|
||||
|
||||
uint8_t iap_fifo[HID_IAP_BUFFER_LEN];
|
||||
uint8_t iap_rx[USBD_OUT_MAXPACKET_SIZE];
|
||||
uint8_t iap_tx[USBD_IN_MAXPACKET_SIZE];
|
||||
uint8_t iap_rx[USBD_HIDIAP_OUT_MAXPACKET_SIZE];
|
||||
uint8_t iap_tx[USBD_HIDIAP_IN_MAXPACKET_SIZE];
|
||||
|
||||
uint32_t fifo_length;
|
||||
uint32_t tx_length;
|
||||
@@ -133,14 +121,21 @@ typedef struct
|
||||
uint32_t sector_size;
|
||||
uint32_t flash_size;
|
||||
|
||||
uint32_t respond_flag;
|
||||
|
||||
uint8_t g_rxhid_buff[USBD_HIDIAP_OUT_MAXPACKET_SIZE];
|
||||
uint32_t hid_protocol;
|
||||
uint32_t hid_set_idle;
|
||||
uint32_t alt_setting;
|
||||
uint32_t hid_state;
|
||||
uint8_t hid_set_report[64];
|
||||
|
||||
iap_machine_state_type state;
|
||||
uint8_t respond_flag;
|
||||
}iap_info_type;
|
||||
|
||||
extern usbd_class_handler hid_iap_class_handler;
|
||||
extern iap_info_type iap_info;
|
||||
usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len);
|
||||
|
||||
usb_sts_type usb_iap_class_send_report(void *udev, uint8_t *report, uint16_t len);
|
||||
iap_result_type usbd_hid_iap_process(void *udev, uint8_t *report, uint16_t len);
|
||||
void usbd_hid_iap_in_complete(void *udev);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file hid_iap_desc.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb hid iap device descriptor
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -43,18 +43,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];
|
||||
@@ -82,7 +82,7 @@ usbd_desc_handler hid_iap_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 */
|
||||
@@ -92,10 +92,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_HIDIAP_VENDOR_ID), /* idVendor */
|
||||
HBYTE(USBD_HIDIAP_VENDOR_ID), /* idVendor */
|
||||
LBYTE(USBD_HIDIAP_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_HIDIAP_PRODUCT_ID), /* idProduct */
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
USB_MFC_STRING, /* Index of manufacturer string */
|
||||
@@ -110,12 +110,12 @@ 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_HIDIAP_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_HIDIAP_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
HBYTE(USBD_HIDIAP_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
0x01, /* bNumInterfaces: 1 interface */
|
||||
0x01, /* bConfigurationValue: configuration value */
|
||||
0x00, /* iConfiguration: index of string descriptor describing
|
||||
@@ -135,29 +135,29 @@ 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(HIDIAP_BCD_NUM),
|
||||
HBYTE(HIDIAP_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_hidiap_report)),
|
||||
HBYTE(sizeof(g_usbd_hidiap_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_HIDIAP_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_HIDIAP_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_HIDIAP_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HIDIAP_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_HID_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USBD_HIDIAP_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_INTERRUPT, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
LBYTE(USBD_HIDIAP_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_HIDIAP_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
HIDIAP_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -166,7 +166,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_hidiap_report[USBD_HIDIAP_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
0x06, 0xFF, 0x00, /* USAGE_PAGE(Vendor Page:0xFF00) */
|
||||
0x09, 0x01, /* USAGE (Demo Kit) */
|
||||
@@ -197,17 +197,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_hidiap_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(HIDIAP_BCD_NUM),
|
||||
HBYTE(HIDIAP_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_hidiap_report)),
|
||||
HBYTE(sizeof(g_usbd_hidiap_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
};
|
||||
|
||||
|
||||
@@ -217,9 +217,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_HIDIAP_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_HIDIAP_SIZ_STRING_LANGID,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
0x09,
|
||||
0x04,
|
||||
@@ -231,42 +231,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_HIDIAP_SIZ_STRING_SERIAL] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_SERIAL,
|
||||
USBD_HIDIAP_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_HIDIAP_CONFIG_DESC_SIZE,
|
||||
g_usbd_configuration
|
||||
};
|
||||
|
||||
/* langid descriptor */
|
||||
usbd_desc_t langid_descriptor =
|
||||
static usbd_desc_t langid_descriptor =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_HIDIAP_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_HIDIAP_SIZ_STRING_SERIAL,
|
||||
g_string_serial
|
||||
};
|
||||
|
||||
usbd_desc_t vp_desc;
|
||||
static usbd_desc_t vp_desc;
|
||||
|
||||
/**
|
||||
* @brief standard usb unicode convert
|
||||
@@ -274,7 +274,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;
|
||||
@@ -348,7 +348,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;
|
||||
}
|
||||
@@ -358,7 +358,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;
|
||||
}
|
||||
@@ -368,7 +368,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;
|
||||
}
|
||||
@@ -378,7 +378,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;
|
||||
}
|
||||
@@ -388,7 +388,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;
|
||||
}
|
||||
@@ -399,9 +399,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_HIDIAP_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -411,9 +411,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_HIDIAP_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -423,7 +423,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;
|
||||
@@ -434,9 +434,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_HIDIAP_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -446,9 +446,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_HIDIAP_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file hid_iap_desc.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb hid iap descriptor header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -48,36 +48,28 @@ extern "C" {
|
||||
*/
|
||||
|
||||
|
||||
#define HID_BCD_NUM 0x0110
|
||||
#define HIDIAP_BCD_NUM 0x0110
|
||||
|
||||
#define HID_CLASS_DESC_HID 0x21
|
||||
#define HID_CLASS_DESC_REPORT 0x22
|
||||
#define HID_CLASS_DESC_PHYSICAL 0x23
|
||||
#define USBD_HIDIAP_VENDOR_ID 0x2E3C
|
||||
#define USBD_HIDIAP_PRODUCT_ID 0xAF01
|
||||
|
||||
#define USBD_HIDIAP_CONFIG_DESC_SIZE 41
|
||||
#define USBD_HIDIAP_SIZ_REPORT_DESC 32
|
||||
#define USBD_HIDIAP_SIZ_STRING_LANGID 4
|
||||
#define USBD_HIDIAP_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
#define USBD_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRODUCT_ID 0xAF01
|
||||
#define USBD_HIDIAP_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_HIDIAP_DESC_PRODUCT_STRING "HID IAP"
|
||||
#define USBD_HIDIAP_DESC_CONFIGURATION_STRING "HID IAP Config"
|
||||
#define USBD_HIDIAP_DESC_INTERFACE_STRING "HID IAP Interface"
|
||||
|
||||
#define USBD_CONFIG_DESC_SIZE 41
|
||||
#define USBD_HID_SIZ_REPORT_DESC 32
|
||||
#define USBD_SIZ_STRING_LANGID 4
|
||||
#define USBD_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
#define USBD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_DESC_PRODUCT_STRING "HID IAP"
|
||||
#define USBD_DESC_CONFIGURATION_STRING "HID IAP Config"
|
||||
#define USBD_DESC_INTERFACE_STRING "HID IAP Interface"
|
||||
|
||||
#define HID_BINTERVAL_TIME 0x01
|
||||
#define HIDIAP_BINTERVAL_TIME 0x01
|
||||
|
||||
#define MCU_ID1 (0x1FFFF7E8)
|
||||
#define MCU_ID2 (0x1FFFF7EC)
|
||||
#define MCU_ID3 (0x1FFFF7F0)
|
||||
|
||||
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_hidiap_report[USBD_HIDIAP_SIZ_REPORT_DESC];
|
||||
extern uint8_t g_hidiap_usb_desc[9];
|
||||
|
||||
extern usbd_desc_handler hid_iap_desc_handler;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file keyboard_class.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @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;
|
||||
uint8_t hid_set_report[64];
|
||||
__IO uint8_t hid_suspend_flag = 0;
|
||||
__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,15 +205,16 @@ 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;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
@@ -230,13 +224,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;
|
||||
}
|
||||
@@ -247,10 +241,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;
|
||||
|
||||
@@ -261,20 +256,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);
|
||||
@@ -288,21 +283,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;
|
||||
@@ -320,7 +315,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;
|
||||
|
||||
@@ -334,16 +329,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;
|
||||
@@ -355,14 +351,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;
|
||||
}
|
||||
@@ -373,7 +371,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;
|
||||
|
||||
@@ -385,7 +383,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;
|
||||
|
||||
@@ -400,9 +398,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:
|
||||
@@ -411,7 +411,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;
|
||||
@@ -432,13 +432,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;
|
||||
}
|
||||
@@ -453,8 +453,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)
|
||||
{
|
||||
@@ -475,17 +475,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.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @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.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @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,12 +108,12 @@ 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
|
||||
@@ -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.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file mouse_class.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb hid mouse class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -40,23 +40,17 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
/* 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];
|
||||
mouse_type mouse_struct;
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler mouse_class_handler =
|
||||
@@ -70,6 +64,7 @@ usbd_class_handler mouse_class_handler =
|
||||
class_out_handler,
|
||||
class_sof_handler,
|
||||
class_event_handler,
|
||||
&mouse_struct
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -77,13 +72,13 @@ usbd_class_handler mouse_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;
|
||||
|
||||
/* open hid in endpoint */
|
||||
usbd_ept_open(pudev, USBD_HID_IN_EPT, EPT_INT_TYPE, USBD_IN_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_MOUSE_IN_EPT, EPT_INT_TYPE, USBD_MOUSE_IN_MAXPACKET_SIZE);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -93,13 +88,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_MOUSE_IN_EPT);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -110,10 +105,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;
|
||||
mouse_type *pmouse = (mouse_type *)pudev->class_handler->pdata;
|
||||
uint16_t len;
|
||||
uint8_t *buf;
|
||||
|
||||
@@ -124,20 +120,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;
|
||||
pmouse->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 *)&pmouse->hid_protocol, 1);
|
||||
break;
|
||||
case HID_REQ_SET_IDLE:
|
||||
hid_set_idle = (uint8_t)(setup->wValue >> 8);
|
||||
pmouse->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 *)&pmouse->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);
|
||||
pmouse->hid_state = HID_REQ_SET_REPORT;
|
||||
usbd_ctrl_recv(pudev, pmouse->hid_set_report, setup->wLength);
|
||||
break;
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
@@ -151,21 +147,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_MOUSE_SIZ_REPORT_DESC, setup->wLength);
|
||||
buf = (uint8_t *)g_usbd_mouse_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_mouse_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 *)&pmouse->alt_setting, 1);
|
||||
break;
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
alt_setting = setup->wValue;
|
||||
pmouse->alt_setting = setup->wValue;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -181,7 +177,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;
|
||||
|
||||
@@ -195,16 +191,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;
|
||||
mouse_type *pmouse = (mouse_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( pmouse->hid_state == HID_REQ_SET_REPORT)
|
||||
{
|
||||
/* hid buffer process */
|
||||
hid_state = 0;
|
||||
pmouse->hid_state = 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -216,7 +213,7 @@ 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;
|
||||
|
||||
@@ -233,7 +230,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;
|
||||
|
||||
@@ -245,7 +242,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;
|
||||
|
||||
@@ -260,9 +257,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;
|
||||
mouse_type *pmouse = (mouse_type *)pudev->class_handler->pdata;
|
||||
switch(event)
|
||||
{
|
||||
case USBD_RESET_EVENT:
|
||||
@@ -271,7 +270,7 @@ usb_sts_type class_event_handler(void *udev, usbd_event_type event)
|
||||
|
||||
break;
|
||||
case USBD_SUSPEND_EVENT:
|
||||
hid_suspend_flag = 1;
|
||||
pmouse->hid_suspend_flag = 1;
|
||||
/* ...user code... */
|
||||
|
||||
break;
|
||||
@@ -292,15 +291,15 @@ 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_mouse_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_flush_tx_fifo(pudev, USBD_HID_IN_EPT);
|
||||
usbd_ept_send(pudev, USBD_HID_IN_EPT, report, len);
|
||||
usbd_flush_tx_fifo(pudev, USBD_MOUSE_IN_EPT);
|
||||
usbd_ept_send(pudev, USBD_MOUSE_IN_EPT, report, len);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -314,7 +313,8 @@ usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len)
|
||||
*/
|
||||
void usb_hid_mouse_send(void *udev, uint8_t op)
|
||||
{
|
||||
static uint8_t mouse_buffer[4] = {0, 0, 0, 0};
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
mouse_type *pmouse = (mouse_type *)pudev->class_handler->pdata;
|
||||
int8_t posx = 0, posy = 0, button = 0;
|
||||
switch(op)
|
||||
{
|
||||
@@ -345,11 +345,11 @@ void usb_hid_mouse_send(void *udev, uint8_t op)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
mouse_buffer[0] = button;
|
||||
mouse_buffer[1] = posx;
|
||||
mouse_buffer[2] = posy;
|
||||
pmouse->mouse_buffer[0] = button;
|
||||
pmouse->mouse_buffer[1] = posx;
|
||||
pmouse->mouse_buffer[2] = posy;
|
||||
|
||||
class_send_report(udev, mouse_buffer, 4);
|
||||
usb_mouse_class_send_report(udev, pmouse->mouse_buffer, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file mouse_class.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb hid mouse header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -50,12 +50,12 @@ extern "C" {
|
||||
/**
|
||||
* @brief usb hid use endpoint define
|
||||
*/
|
||||
#define USBD_HID_IN_EPT 0x81
|
||||
#define USBD_MOUSE_IN_EPT 0x81
|
||||
|
||||
/**
|
||||
* @brief usb hid in and out max packet size define
|
||||
*/
|
||||
#define USBD_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_MOUSE_IN_MAXPACKET_SIZE 0x40
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -65,17 +65,6 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
||||
/**
|
||||
* @brief usb hid mouse operation
|
||||
@@ -90,6 +79,18 @@ extern "C" {
|
||||
#define UP_MOVE 5
|
||||
#define DOWN_MOVE 6
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t hid_protocol;
|
||||
uint32_t hid_set_idle;
|
||||
uint32_t alt_setting;
|
||||
|
||||
uint8_t hid_set_report[64];
|
||||
uint8_t mouse_buffer[4];
|
||||
uint8_t hid_state;
|
||||
__IO uint8_t hid_suspend_flag;
|
||||
}mouse_type;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -98,7 +99,7 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
extern usbd_class_handler mouse_class_handler;
|
||||
usb_sts_type class_send_report(void *udev, uint8_t *report, uint16_t len);
|
||||
usb_sts_type usb_mouse_class_send_report(void *udev, uint8_t *report, uint16_t len);
|
||||
void usb_hid_mouse_send(void *udev, uint8_t op);
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file mouse_desc.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb hid mouse 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 mouse_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_MOUSE_VENDOR_ID), /* idVendor */
|
||||
HBYTE(USBD_MOUSE_VENDOR_ID), /* idVendor */
|
||||
LBYTE(USBD_MOUSE_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_MOUSE_PRODUCT_ID), /* idProduct */
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
USB_MFC_STRING, /* Index of manufacturer string */
|
||||
@@ -108,12 +108,12 @@ 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_MOUSE_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_MOUSE_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
HBYTE(USBD_MOUSE_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
0x01, /* bNumInterfaces: 1 interface */
|
||||
0x01, /* bConfigurationValue: configuration value */
|
||||
0x00, /* iConfiguration: index of string descriptor describing
|
||||
@@ -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(MOUSE_BCD_NUM),
|
||||
HBYTE(MOUSE_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_mouse_report)),
|
||||
HBYTE(sizeof(g_usbd_mouse_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_MOUSE_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_MOUSE_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_MOUSE_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
MOUSE_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_mouse_report[USBD_MOUSE_SIZ_REPORT_DESC] ALIGNED_TAIL =
|
||||
{
|
||||
0x05,0x01,
|
||||
0x09,0x02,
|
||||
@@ -212,17 +212,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_mouse_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(MOUSE_BCD_NUM),
|
||||
HBYTE(MOUSE_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_mouse_report)),
|
||||
HBYTE(sizeof(g_usbd_mouse_report)), /* wDescriptorLength: total length of reprot descriptor */
|
||||
};
|
||||
|
||||
|
||||
@@ -232,9 +232,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_MOUSE_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_MOUSE_SIZ_STRING_LANGID,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
0x09,
|
||||
0x04,
|
||||
@@ -246,42 +246,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_MOUSE_SIZ_STRING_SERIAL] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_SERIAL,
|
||||
USBD_MOUSE_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_MOUSE_CONFIG_DESC_SIZE,
|
||||
g_usbd_configuration
|
||||
};
|
||||
|
||||
/* langid descriptor */
|
||||
usbd_desc_t langid_descriptor =
|
||||
static usbd_desc_t langid_descriptor =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_MOUSE_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_MOUSE_SIZ_STRING_SERIAL,
|
||||
g_string_serial
|
||||
};
|
||||
|
||||
usbd_desc_t vp_desc;
|
||||
static usbd_desc_t vp_desc;
|
||||
|
||||
/**
|
||||
* @brief standard usb unicode convert
|
||||
@@ -289,7 +289,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;
|
||||
@@ -363,7 +363,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;
|
||||
}
|
||||
@@ -373,7 +373,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;
|
||||
}
|
||||
@@ -383,7 +383,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;
|
||||
}
|
||||
@@ -393,7 +393,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;
|
||||
}
|
||||
@@ -403,7 +403,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;
|
||||
}
|
||||
@@ -414,9 +414,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_MOUSE_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -426,9 +426,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_MOUSE_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -438,7 +438,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;
|
||||
@@ -449,9 +449,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_MOUSE_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -461,9 +461,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_MOUSE_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file mouse_desc.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb mouse 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 MOUSE_BCD_NUM 0x0110
|
||||
|
||||
/**
|
||||
* @brief usb vendor id and product id define
|
||||
*/
|
||||
#define USBD_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRODUCT_ID 0x5710
|
||||
#define USBD_MOUSE_VENDOR_ID 0x2E3C
|
||||
#define USBD_MOUSE_PRODUCT_ID 0x5710
|
||||
|
||||
/**
|
||||
* @brief usb descriptor size define
|
||||
*/
|
||||
#define USBD_CONFIG_DESC_SIZE 34
|
||||
#define USBD_HID_SIZ_REPORT_DESC 74
|
||||
#define USBD_SIZ_STRING_LANGID 4
|
||||
#define USBD_SIZ_STRING_SERIAL 0x1A
|
||||
#define USBD_MOUSE_CONFIG_DESC_SIZE 34
|
||||
#define USBD_MOUSE_SIZ_REPORT_DESC 74
|
||||
#define USBD_MOUSE_SIZ_STRING_LANGID 4
|
||||
#define USBD_MOUSE_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
/**
|
||||
* @brief usb string define(vendor, product configuration, interface)
|
||||
*/
|
||||
#define USBD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_DESC_PRODUCT_STRING "Mouse"
|
||||
#define USBD_DESC_CONFIGURATION_STRING "Mouse Config"
|
||||
#define USBD_DESC_INTERFACE_STRING "Mouse Interface"
|
||||
#define USBD_MOUSE_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_MOUSE_DESC_PRODUCT_STRING "Mouse"
|
||||
#define USBD_MOUSE_DESC_CONFIGURATION_STRING "Mouse Config"
|
||||
#define USBD_MOUSE_DESC_INTERFACE_STRING "Mouse Interface"
|
||||
|
||||
/**
|
||||
* @brief usb hid endpoint interval define
|
||||
*/
|
||||
#define HID_BINTERVAL_TIME 0x0A
|
||||
#define MOUSE_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_mouse_report[USBD_MOUSE_SIZ_REPORT_DESC];
|
||||
extern uint8_t g_mouse_usb_desc[9];
|
||||
extern usbd_desc_handler mouse_desc_handler;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_bot_scsi.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb mass storage bulk-only transport and scsi command
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -39,15 +39,6 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
msc_type msc_struct;
|
||||
cbw_type cbw_struct;
|
||||
csw_type csw_struct =
|
||||
{
|
||||
CSW_DCSWSIGNATURE,
|
||||
0x00,
|
||||
0x00,
|
||||
CSW_BCSWSTATUS_PASS,
|
||||
};
|
||||
|
||||
#if defined ( __ICCARM__ ) /* iar compiler */
|
||||
#pragma data_alignment=4
|
||||
@@ -113,14 +104,20 @@ ALIGNED_HEAD uint8_t mode_sense10_data[8] ALIGNED_TAIL =
|
||||
void bot_scsi_init(void *udev)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_struct.msc_state = MSC_STATE_MACHINE_IDLE;
|
||||
msc_struct.bot_status = MSC_BOT_STATE_IDLE;
|
||||
msc_struct.max_lun = MSC_SUPPORT_MAX_LUN - 1;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_IDLE;
|
||||
pmsc->bot_status = MSC_BOT_STATE_IDLE;
|
||||
pmsc->max_lun = MSC_SUPPORT_MAX_LUN - 1;
|
||||
|
||||
usb_flush_tx_fifo(pudev->usb_reg, USBD_MSC_BULK_IN_EPT&0x7F);
|
||||
pmsc->csw_struct.dCSWSignature = CSW_DCSWSIGNATURE;
|
||||
pmsc->csw_struct.dCSWDataResidue = 0;
|
||||
pmsc->csw_struct.dCSWSignature = 0;
|
||||
pmsc->csw_struct.dCSWTag = CSW_BCSWSTATUS_PASS;
|
||||
|
||||
usbd_flush_tx_fifo(pudev, USBD_MSC_BULK_IN_EPT&0x7F);
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)&cbw_struct, CBW_CMD_LENGTH);
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,13 +128,14 @@ void bot_scsi_init(void *udev)
|
||||
void bot_scsi_reset(void *udev)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_struct.msc_state = MSC_STATE_MACHINE_IDLE;
|
||||
msc_struct.bot_status = MSC_BOT_STATE_RECOVERY;
|
||||
msc_struct.max_lun = MSC_SUPPORT_MAX_LUN - 1;
|
||||
usb_flush_tx_fifo(pudev->usb_reg, USBD_MSC_BULK_IN_EPT&0x7F);
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_IDLE;
|
||||
pmsc->bot_status = MSC_BOT_STATE_RECOVERY;
|
||||
pmsc->max_lun = MSC_SUPPORT_MAX_LUN - 1;
|
||||
usbd_flush_tx_fifo(pudev, USBD_MSC_BULK_IN_EPT&0x7F);
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)&cbw_struct, CBW_CMD_LENGTH);
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,7 +146,9 @@ void bot_scsi_reset(void *udev)
|
||||
*/
|
||||
void bot_scsi_datain_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
switch(msc_struct.msc_state)
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
switch(pmsc->msc_state)
|
||||
{
|
||||
case MSC_STATE_MACHINE_DATA_IN:
|
||||
if(bot_scsi_cmd_process(udev) != USB_OK)
|
||||
@@ -175,7 +175,9 @@ void bot_scsi_datain_handler(void *udev, uint8_t ept_num)
|
||||
*/
|
||||
void bot_scsi_dataout_handler(void *udev, uint8_t ept_num)
|
||||
{
|
||||
switch(msc_struct.msc_state)
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
switch(pmsc->msc_state)
|
||||
{
|
||||
case MSC_STATE_MACHINE_IDLE:
|
||||
bot_cbw_decode(udev);
|
||||
@@ -198,18 +200,19 @@ void bot_scsi_dataout_handler(void *udev, uint8_t ept_num)
|
||||
void bot_cbw_decode(void *udev)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
csw_struct.dCSWTag = cbw_struct.dCBWTage;
|
||||
csw_struct.dCSWDataResidue = cbw_struct.dCBWDataTransferLength;
|
||||
pmsc->csw_struct.dCSWTag = pmsc->cbw_struct.dCBWTage;
|
||||
pmsc->csw_struct.dCSWDataResidue = pmsc->cbw_struct.dCBWDataTransferLength;
|
||||
|
||||
/* check param */
|
||||
if((cbw_struct.dCBWSignature != CBW_DCBWSIGNATURE) ||
|
||||
if((pmsc->cbw_struct.dCBWSignature != CBW_DCBWSIGNATURE) ||
|
||||
(usbd_get_recv_len(pudev, USBD_MSC_BULK_OUT_EPT) != CBW_CMD_LENGTH)
|
||||
|| (cbw_struct.bCBWLUN > MSC_SUPPORT_MAX_LUN) ||
|
||||
(cbw_struct.bCBWCBLength < 1) || (cbw_struct.bCBWCBLength > 16))
|
||||
|| (pmsc->cbw_struct.bCBWLUN > MSC_SUPPORT_MAX_LUN) ||
|
||||
(pmsc->cbw_struct.bCBWCBLength < 1) || (pmsc->cbw_struct.bCBWCBLength > 16))
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
msc_struct.bot_status = MSC_BOT_STATE_ERROR;
|
||||
pmsc->bot_status = MSC_BOT_STATE_ERROR;
|
||||
bot_scsi_stall(udev);
|
||||
}
|
||||
else
|
||||
@@ -218,17 +221,17 @@ void bot_cbw_decode(void *udev)
|
||||
{
|
||||
bot_scsi_stall(udev);
|
||||
}
|
||||
else if((msc_struct.msc_state != MSC_STATE_MACHINE_DATA_IN) &&
|
||||
(msc_struct.msc_state != MSC_STATE_MACHINE_DATA_OUT) &&
|
||||
(msc_struct.msc_state != MSC_STATE_MACHINE_LAST_DATA))
|
||||
else if((pmsc->msc_state != MSC_STATE_MACHINE_DATA_IN) &&
|
||||
(pmsc->msc_state != MSC_STATE_MACHINE_DATA_OUT) &&
|
||||
(pmsc->msc_state != MSC_STATE_MACHINE_LAST_DATA))
|
||||
{
|
||||
if(msc_struct.data_len == 0)
|
||||
if(pmsc->data_len == 0)
|
||||
{
|
||||
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_PASS);
|
||||
}
|
||||
else if(msc_struct.data_len > 0)
|
||||
else if(pmsc->data_len > 0)
|
||||
{
|
||||
bot_scsi_send_data(udev, msc_struct.data, msc_struct.data_len);
|
||||
bot_scsi_send_data(udev, pmsc->data, pmsc->data_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -244,12 +247,13 @@ void bot_cbw_decode(void *udev)
|
||||
void bot_scsi_send_data(void *udev, uint8_t *buffer, uint32_t len)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
uint32_t data_len = MIN(len, cbw_struct.dCBWDataTransferLength);
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint32_t data_len = MIN(len, pmsc->cbw_struct.dCBWDataTransferLength);
|
||||
|
||||
csw_struct.dCSWDataResidue -= data_len;
|
||||
csw_struct.bCSWStatus = CSW_BCSWSTATUS_PASS;
|
||||
pmsc->csw_struct.dCSWDataResidue -= data_len;
|
||||
pmsc->csw_struct.bCSWStatus = CSW_BCSWSTATUS_PASS;
|
||||
|
||||
msc_struct.msc_state = MSC_STATE_MACHINE_SEND_DATA;
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_SEND_DATA;
|
||||
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT,
|
||||
buffer, data_len);
|
||||
@@ -264,16 +268,17 @@ void bot_scsi_send_data(void *udev, uint8_t *buffer, uint32_t len)
|
||||
void bot_scsi_send_csw(void *udev, uint8_t status)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
csw_struct.bCSWStatus = status;
|
||||
csw_struct.dCSWSignature = CSW_DCSWSIGNATURE;
|
||||
msc_struct.msc_state = MSC_STATE_MACHINE_IDLE;
|
||||
pmsc->csw_struct.bCSWStatus = status;
|
||||
pmsc->csw_struct.dCSWSignature = CSW_DCSWSIGNATURE;
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_IDLE;
|
||||
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT,
|
||||
(uint8_t *)&csw_struct, CSW_CMD_LENGTH);
|
||||
(uint8_t *)&pmsc->csw_struct, CSW_CMD_LENGTH);
|
||||
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT,
|
||||
(uint8_t *)&cbw_struct, CBW_CMD_LENGTH);
|
||||
(uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
@@ -301,7 +306,9 @@ void bot_scsi_sense_code(void *udev, uint8_t sense_key, uint8_t asc)
|
||||
*/
|
||||
usb_sts_type bot_scsi_check_address(void *udev, uint8_t lun, uint32_t blk_offset, uint32_t blk_count)
|
||||
{
|
||||
if((blk_offset + blk_count) > msc_struct.blk_nbr[lun])
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
if((blk_offset + blk_count) > pmsc->blk_nbr[lun])
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, ADDRESS_OUT_OF_RANGE);
|
||||
return USB_FAIL;
|
||||
@@ -317,18 +324,20 @@ usb_sts_type bot_scsi_check_address(void *udev, uint8_t lun, uint32_t blk_offset
|
||||
void bot_scsi_stall(void *udev)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
if((cbw_struct.dCBWDataTransferLength != 0) &&
|
||||
(cbw_struct.bmCBWFlags == 0) &&
|
||||
msc_struct.bot_status == MSC_BOT_STATE_IDLE)
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
if((pmsc->cbw_struct.dCBWDataTransferLength != 0) &&
|
||||
(pmsc->cbw_struct.bmCBWFlags == 0) &&
|
||||
pmsc->bot_status == MSC_BOT_STATE_IDLE)
|
||||
{
|
||||
usbd_set_stall(pudev, USBD_MSC_BULK_OUT_EPT);
|
||||
}
|
||||
usbd_set_stall(pudev, USBD_MSC_BULK_IN_EPT);
|
||||
|
||||
if(msc_struct.bot_status == MSC_BOT_STATE_ERROR)
|
||||
if(pmsc->bot_status == MSC_BOT_STATE_ERROR)
|
||||
{
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT,
|
||||
(uint8_t *)&cbw_struct, CBW_CMD_LENGTH);
|
||||
(uint8_t *)&pmsc->cbw_struct, CBW_CMD_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,13 +350,16 @@ void bot_scsi_stall(void *udev)
|
||||
usb_sts_type bot_scsi_test_unit(void *udev, uint8_t lun)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
if(cbw_struct.dCBWDataTransferLength != 0)
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
if(pmsc->cbw_struct.dCBWDataTransferLength != 0)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
msc_struct.data_len = 0;
|
||||
pmsc->data_len = 0;
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -362,8 +374,10 @@ usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun)
|
||||
uint8_t *pdata;
|
||||
uint32_t trans_len = 0;
|
||||
usb_sts_type status = USB_OK;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
|
||||
if(cbw_struct.CBWCB[1] & 0x01)
|
||||
if(pmsc->cbw_struct.CBWCB[1] & 0x01)
|
||||
{
|
||||
pdata = page00_inquiry_data;
|
||||
trans_len = 5;
|
||||
@@ -371,9 +385,9 @@ usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun)
|
||||
else
|
||||
{
|
||||
pdata = get_inquiry(lun);
|
||||
if(cbw_struct.dCBWDataTransferLength < SCSI_INQUIRY_DATA_LENGTH)
|
||||
if(pmsc->cbw_struct.dCBWDataTransferLength < SCSI_INQUIRY_DATA_LENGTH)
|
||||
{
|
||||
trans_len = cbw_struct.dCBWDataTransferLength;
|
||||
trans_len = pmsc->cbw_struct.dCBWDataTransferLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -381,11 +395,11 @@ usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun)
|
||||
}
|
||||
}
|
||||
|
||||
msc_struct.data_len = trans_len;
|
||||
pmsc->data_len = trans_len;
|
||||
while(trans_len)
|
||||
{
|
||||
trans_len --;
|
||||
msc_struct.data[trans_len] = pdata[trans_len];
|
||||
pmsc->data[trans_len] = pdata[trans_len];
|
||||
}
|
||||
return status;
|
||||
}
|
||||
@@ -398,7 +412,9 @@ usb_sts_type bot_scsi_inquiry(void *udev, uint8_t lun)
|
||||
*/
|
||||
usb_sts_type bot_scsi_start_stop(void *udev, uint8_t lun)
|
||||
{
|
||||
msc_struct.data_len = 0;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
pmsc->data_len = 0;
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
@@ -410,7 +426,9 @@ usb_sts_type bot_scsi_start_stop(void *udev, uint8_t lun)
|
||||
*/
|
||||
usb_sts_type bot_scsi_allow_medium_removal(void *udev, uint8_t lun)
|
||||
{
|
||||
msc_struct.data_len = 0;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
pmsc->data_len = 0;
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
@@ -423,11 +441,13 @@ usb_sts_type bot_scsi_allow_medium_removal(void *udev, uint8_t lun)
|
||||
usb_sts_type bot_scsi_mode_sense6(void *udev, uint8_t lun)
|
||||
{
|
||||
uint8_t data_len = 8;
|
||||
msc_struct.data_len = 8;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
pmsc->data_len = 8;
|
||||
while(data_len)
|
||||
{
|
||||
data_len --;
|
||||
msc_struct.data[data_len] = mode_sense6_data[data_len];
|
||||
pmsc->data[data_len] = mode_sense6_data[data_len];
|
||||
};
|
||||
return USB_OK;
|
||||
}
|
||||
@@ -441,11 +461,13 @@ usb_sts_type bot_scsi_mode_sense6(void *udev, uint8_t lun)
|
||||
usb_sts_type bot_scsi_mode_sense10(void *udev, uint8_t lun)
|
||||
{
|
||||
uint8_t data_len = 8;
|
||||
msc_struct.data_len = 8;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
pmsc->data_len = 8;
|
||||
while(data_len)
|
||||
{
|
||||
data_len --;
|
||||
msc_struct.data[data_len] = mode_sense10_data[data_len];
|
||||
pmsc->data[data_len] = mode_sense10_data[data_len];
|
||||
};
|
||||
return USB_OK;
|
||||
}
|
||||
@@ -458,21 +480,22 @@ usb_sts_type bot_scsi_mode_sense10(void *udev, uint8_t lun)
|
||||
*/
|
||||
usb_sts_type bot_scsi_capacity(void *udev, uint8_t lun)
|
||||
{
|
||||
uint8_t *pdata = msc_struct.data;
|
||||
|
||||
msc_disk_capacity(lun, &msc_struct.blk_nbr[lun], &msc_struct.blk_size[lun]);
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *pdata = pmsc->data;
|
||||
msc_disk_capacity(lun, &pmsc->blk_nbr[lun], &pmsc->blk_size[lun]);
|
||||
|
||||
pdata[0] = (uint8_t)((msc_struct.blk_nbr[lun] - 1) >> 24);
|
||||
pdata[1] = (uint8_t)((msc_struct.blk_nbr[lun] - 1) >> 16);
|
||||
pdata[2] = (uint8_t)((msc_struct.blk_nbr[lun] - 1) >> 8);
|
||||
pdata[3] = (uint8_t)((msc_struct.blk_nbr[lun] - 1));
|
||||
pdata[0] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 24);
|
||||
pdata[1] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 16);
|
||||
pdata[2] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 8);
|
||||
pdata[3] = (uint8_t)((pmsc->blk_nbr[lun] - 1));
|
||||
|
||||
pdata[4] = (uint8_t)((msc_struct.blk_size[lun]) >> 24);
|
||||
pdata[5] = (uint8_t)((msc_struct.blk_size[lun]) >> 16);
|
||||
pdata[6] = (uint8_t)((msc_struct.blk_size[lun]) >> 8);
|
||||
pdata[7] = (uint8_t)((msc_struct.blk_size[lun]));
|
||||
pdata[4] = (uint8_t)((pmsc->blk_size[lun]) >> 24);
|
||||
pdata[5] = (uint8_t)((pmsc->blk_size[lun]) >> 16);
|
||||
pdata[6] = (uint8_t)((pmsc->blk_size[lun]) >> 8);
|
||||
pdata[7] = (uint8_t)((pmsc->blk_size[lun]));
|
||||
|
||||
msc_struct.data_len = 8;
|
||||
pmsc->data_len = 8;
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
@@ -483,28 +506,30 @@ usb_sts_type bot_scsi_capacity(void *udev, uint8_t lun)
|
||||
* @retval status of usb_sts_type
|
||||
*/
|
||||
usb_sts_type bot_scsi_format_capacity(void *udev, uint8_t lun)
|
||||
{
|
||||
uint8_t *pdata = msc_struct.data;
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *pdata = pmsc->data;
|
||||
|
||||
pdata[0] = 0;
|
||||
pdata[1] = 0;
|
||||
pdata[2] = 0;
|
||||
pdata[3] = 0x08;
|
||||
|
||||
msc_disk_capacity(lun, &msc_struct.blk_nbr[lun], &msc_struct.blk_size[lun]);
|
||||
msc_disk_capacity(lun, &pmsc->blk_nbr[lun], &pmsc->blk_size[lun]);
|
||||
|
||||
pdata[4] = (uint8_t)((msc_struct.blk_nbr[lun] - 1) >> 24);
|
||||
pdata[5] = (uint8_t)((msc_struct.blk_nbr[lun] - 1) >> 16);
|
||||
pdata[6] = (uint8_t)((msc_struct.blk_nbr[lun] - 1) >> 8);
|
||||
pdata[7] = (uint8_t)((msc_struct.blk_nbr[lun] - 1));
|
||||
pdata[4] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 24);
|
||||
pdata[5] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 16);
|
||||
pdata[6] = (uint8_t)((pmsc->blk_nbr[lun] - 1) >> 8);
|
||||
pdata[7] = (uint8_t)((pmsc->blk_nbr[lun] - 1));
|
||||
|
||||
pdata[8] = 0x02;
|
||||
|
||||
pdata[9] = (uint8_t)((msc_struct.blk_size[lun]) >> 16);
|
||||
pdata[10] = (uint8_t)((msc_struct.blk_size[lun]) >> 8);
|
||||
pdata[11] = (uint8_t)((msc_struct.blk_size[lun]));
|
||||
pdata[9] = (uint8_t)((pmsc->blk_size[lun]) >> 16);
|
||||
pdata[10] = (uint8_t)((pmsc->blk_size[lun]) >> 8);
|
||||
pdata[11] = (uint8_t)((pmsc->blk_size[lun]));
|
||||
|
||||
msc_struct.data_len = 12;
|
||||
pmsc->data_len = 12;
|
||||
|
||||
return USB_OK;
|
||||
}
|
||||
@@ -518,7 +543,9 @@ usb_sts_type bot_scsi_format_capacity(void *udev, uint8_t lun)
|
||||
usb_sts_type bot_scsi_request_sense(void *udev, uint8_t lun)
|
||||
{
|
||||
uint32_t trans_len = 0x12;
|
||||
uint8_t *pdata = msc_struct.data;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *pdata = pmsc->data;
|
||||
uint8_t *sdata = (uint8_t *)&sense_data;
|
||||
|
||||
while(trans_len)
|
||||
@@ -527,13 +554,13 @@ usb_sts_type bot_scsi_request_sense(void *udev, uint8_t lun)
|
||||
pdata[trans_len] = sdata[trans_len];
|
||||
}
|
||||
|
||||
if(cbw_struct.dCBWDataTransferLength < REQ_SENSE_STANDARD_DATA_LEN)
|
||||
if(pmsc->cbw_struct.dCBWDataTransferLength < REQ_SENSE_STANDARD_DATA_LEN)
|
||||
{
|
||||
msc_struct.data_len = cbw_struct.dCBWDataTransferLength;
|
||||
pmsc->data_len = pmsc->cbw_struct.dCBWDataTransferLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
msc_struct.data_len = REQ_SENSE_STANDARD_DATA_LEN;
|
||||
pmsc->data_len = REQ_SENSE_STANDARD_DATA_LEN;
|
||||
}
|
||||
return USB_OK;
|
||||
}
|
||||
@@ -546,21 +573,23 @@ usb_sts_type bot_scsi_request_sense(void *udev, uint8_t lun)
|
||||
*/
|
||||
usb_sts_type bot_scsi_verify(void *udev, uint8_t lun)
|
||||
{
|
||||
uint8_t *cmd = cbw_struct.CBWCB;
|
||||
if((cbw_struct.CBWCB[1] & 0x02) == 0x02)
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *cmd = pmsc->cbw_struct.CBWCB;
|
||||
if((pmsc->cbw_struct.CBWCB[1] & 0x02) == 0x02)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
msc_struct.blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
|
||||
msc_struct.blk_len = cmd[7] << 8 | cmd[8];
|
||||
pmsc->blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
|
||||
pmsc->blk_len = cmd[7] << 8 | cmd[8];
|
||||
|
||||
if(bot_scsi_check_address(udev, lun, msc_struct.blk_addr, msc_struct.blk_len) != USB_OK)
|
||||
if(bot_scsi_check_address(udev, lun, pmsc->blk_addr, pmsc->blk_len) != USB_OK)
|
||||
{
|
||||
return USB_FAIL;
|
||||
}
|
||||
msc_struct.data_len = 0;
|
||||
pmsc->data_len = 0;
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
@@ -572,52 +601,53 @@ usb_sts_type bot_scsi_verify(void *udev, uint8_t lun)
|
||||
*/
|
||||
usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
{
|
||||
uint8_t *cmd = cbw_struct.CBWCB;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *cmd = pmsc->cbw_struct.CBWCB;
|
||||
uint32_t len;
|
||||
|
||||
if(msc_struct.msc_state == MSC_STATE_MACHINE_IDLE)
|
||||
if(pmsc->msc_state == MSC_STATE_MACHINE_IDLE)
|
||||
{
|
||||
if((cbw_struct.bmCBWFlags & 0x80) != 0x80)
|
||||
if((pmsc->cbw_struct.bmCBWFlags & 0x80) != 0x80)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
msc_struct.blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
|
||||
msc_struct.blk_len = cmd[7] << 8 | cmd[8];
|
||||
pmsc->blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
|
||||
pmsc->blk_len = cmd[7] << 8 | cmd[8];
|
||||
|
||||
if(bot_scsi_check_address(udev, lun, msc_struct.blk_addr, msc_struct.blk_len) != USB_OK)
|
||||
if(bot_scsi_check_address(udev, lun, pmsc->blk_addr, pmsc->blk_len) != USB_OK)
|
||||
{
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
msc_struct.blk_addr *= msc_struct.blk_size[lun];
|
||||
msc_struct.blk_len *= msc_struct.blk_size[lun];
|
||||
pmsc->blk_addr *= pmsc->blk_size[lun];
|
||||
pmsc->blk_len *= pmsc->blk_size[lun];
|
||||
|
||||
if(cbw_struct.dCBWDataTransferLength != msc_struct.blk_len)
|
||||
if(pmsc->cbw_struct.dCBWDataTransferLength != pmsc->blk_len)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
msc_struct.msc_state = MSC_STATE_MACHINE_DATA_IN;
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_DATA_IN;
|
||||
}
|
||||
msc_struct.data_len = MSC_MAX_DATA_BUF_LEN;
|
||||
pmsc->data_len = MSC_MAX_DATA_BUF_LEN;
|
||||
|
||||
len = MIN(msc_struct.blk_len, MSC_MAX_DATA_BUF_LEN);
|
||||
if( msc_disk_read(lun, msc_struct.blk_addr, msc_struct.data, len) != USB_OK)
|
||||
len = MIN(pmsc->blk_len, MSC_MAX_DATA_BUF_LEN);
|
||||
if( msc_disk_read(lun, pmsc->blk_addr, pmsc->data, len) != USB_OK)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_HARDWARE_ERROR, MEDIUM_NOT_PRESENT);
|
||||
return USB_FAIL;
|
||||
}
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT, msc_struct.data, len);
|
||||
msc_struct.blk_addr += len;
|
||||
msc_struct.blk_len -= len;
|
||||
usbd_ept_send(pudev, USBD_MSC_BULK_IN_EPT, pmsc->data, len);
|
||||
pmsc->blk_addr += len;
|
||||
pmsc->blk_len -= len;
|
||||
|
||||
csw_struct.dCSWDataResidue -= len;
|
||||
if(msc_struct.blk_len == 0)
|
||||
pmsc->csw_struct.dCSWDataResidue -= len;
|
||||
if(pmsc->blk_len == 0)
|
||||
{
|
||||
msc_struct.msc_state = MSC_STATE_MACHINE_LAST_DATA;
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_LAST_DATA;
|
||||
}
|
||||
|
||||
return USB_OK;
|
||||
@@ -632,62 +662,63 @@ usb_sts_type bot_scsi_read10(void *udev, uint8_t lun)
|
||||
*/
|
||||
usb_sts_type bot_scsi_write10(void *udev, uint8_t lun)
|
||||
{
|
||||
uint8_t *cmd = cbw_struct.CBWCB;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
uint8_t *cmd = pmsc->cbw_struct.CBWCB;
|
||||
uint32_t len;
|
||||
|
||||
if(msc_struct.msc_state == MSC_STATE_MACHINE_IDLE)
|
||||
if(pmsc->msc_state == MSC_STATE_MACHINE_IDLE)
|
||||
{
|
||||
if((cbw_struct.bmCBWFlags & 0x80) == 0x80)
|
||||
if((pmsc->cbw_struct.bmCBWFlags & 0x80) == 0x80)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
msc_struct.blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
|
||||
msc_struct.blk_len = cmd[7] << 8 | cmd[8];
|
||||
pmsc->blk_addr = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
|
||||
pmsc->blk_len = cmd[7] << 8 | cmd[8];
|
||||
|
||||
if(bot_scsi_check_address(udev, lun, msc_struct.blk_addr, msc_struct.blk_len) != USB_OK)
|
||||
if(bot_scsi_check_address(udev, lun, pmsc->blk_addr, pmsc->blk_len) != USB_OK)
|
||||
{
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
msc_struct.blk_addr *= msc_struct.blk_size[lun];
|
||||
msc_struct.blk_len *= msc_struct.blk_size[lun];
|
||||
pmsc->blk_addr *= pmsc->blk_size[lun];
|
||||
pmsc->blk_len *= pmsc->blk_size[lun];
|
||||
|
||||
if(cbw_struct.dCBWDataTransferLength != msc_struct.blk_len)
|
||||
if(pmsc->cbw_struct.dCBWDataTransferLength != pmsc->blk_len)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_ILLEGAL_REQUEST, INVALID_COMMAND);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
msc_struct.msc_state = MSC_STATE_MACHINE_DATA_OUT;
|
||||
len = MIN(msc_struct.blk_len, MSC_MAX_DATA_BUF_LEN);
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)msc_struct.data, len);
|
||||
pmsc->msc_state = MSC_STATE_MACHINE_DATA_OUT;
|
||||
len = MIN(pmsc->blk_len, MSC_MAX_DATA_BUF_LEN);
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)pmsc->data, len);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
len = MIN(msc_struct.blk_len, MSC_MAX_DATA_BUF_LEN);
|
||||
if(msc_disk_write(lun, msc_struct.blk_addr, msc_struct.data, len) != USB_OK)
|
||||
len = MIN(pmsc->blk_len, MSC_MAX_DATA_BUF_LEN);
|
||||
if(msc_disk_write(lun, pmsc->blk_addr, pmsc->data, len) != USB_OK)
|
||||
{
|
||||
bot_scsi_sense_code(udev, SENSE_KEY_HARDWARE_ERROR, MEDIUM_NOT_PRESENT);
|
||||
return USB_FAIL;
|
||||
}
|
||||
|
||||
msc_struct.blk_addr += len;
|
||||
msc_struct.blk_len -= len;
|
||||
pmsc->blk_addr += len;
|
||||
pmsc->blk_len -= len;
|
||||
|
||||
csw_struct.dCSWDataResidue -= len;
|
||||
pmsc->csw_struct.dCSWDataResidue -= len;
|
||||
|
||||
if(msc_struct.blk_len == 0)
|
||||
if(pmsc->blk_len == 0)
|
||||
{
|
||||
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_PASS);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = MIN(msc_struct.blk_len, MSC_MAX_DATA_BUF_LEN);
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)msc_struct.data, len);
|
||||
len = MIN(pmsc->blk_len, MSC_MAX_DATA_BUF_LEN);
|
||||
usbd_ept_recv(pudev, USBD_MSC_BULK_OUT_EPT, (uint8_t *)pmsc->data, len);
|
||||
}
|
||||
}
|
||||
return USB_OK;
|
||||
@@ -702,13 +733,13 @@ usb_sts_type bot_scsi_write10(void *udev, uint8_t lun)
|
||||
void bot_scsi_clear_feature(void *udev, uint8_t ept_num)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
|
||||
if(msc_struct.bot_status == MSC_BOT_STATE_ERROR)
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
if(pmsc->bot_status == MSC_BOT_STATE_ERROR)
|
||||
{
|
||||
usbd_set_stall(pudev, USBD_MSC_BULK_IN_EPT);
|
||||
msc_struct.bot_status = MSC_BOT_STATE_IDLE;
|
||||
pmsc->bot_status = MSC_BOT_STATE_IDLE;
|
||||
}
|
||||
else if(((ept_num & 0x80) == 0x80) && (msc_struct.bot_status != MSC_BOT_STATE_RECOVERY))
|
||||
else if(((ept_num & 0x80) == 0x80) && (pmsc->bot_status != MSC_BOT_STATE_RECOVERY))
|
||||
{
|
||||
bot_scsi_send_csw(udev, CSW_BCSWSTATUS_FAILED);
|
||||
}
|
||||
@@ -722,54 +753,56 @@ void bot_scsi_clear_feature(void *udev, uint8_t ept_num)
|
||||
usb_sts_type bot_scsi_cmd_process(void *udev)
|
||||
{
|
||||
usb_sts_type status = USB_FAIL;
|
||||
switch(cbw_struct.CBWCB[0])
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
switch(pmsc->cbw_struct.CBWCB[0])
|
||||
{
|
||||
case MSC_CMD_INQUIRY:
|
||||
status = bot_scsi_inquiry(udev, cbw_struct.bCBWLUN);
|
||||
status = bot_scsi_inquiry(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
case MSC_CMD_START_STOP:
|
||||
status = bot_scsi_start_stop(udev, cbw_struct.bCBWLUN);
|
||||
status = bot_scsi_start_stop(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
case MSC_CMD_MODE_SENSE6:
|
||||
status = bot_scsi_mode_sense6(udev, cbw_struct.bCBWLUN);
|
||||
status = bot_scsi_mode_sense6(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
case MSC_CMD_MODE_SENSE10:
|
||||
status = bot_scsi_mode_sense10(udev, cbw_struct.bCBWLUN);
|
||||
status = bot_scsi_mode_sense10(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
case MSC_CMD_ALLOW_MEDIUM_REMOVAL:
|
||||
status = bot_scsi_allow_medium_removal(udev, cbw_struct.bCBWLUN);
|
||||
status = bot_scsi_allow_medium_removal(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
case MSC_CMD_READ_10:
|
||||
status = bot_scsi_read10(udev, cbw_struct.bCBWLUN);
|
||||
status = bot_scsi_read10(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
case MSC_CMD_READ_CAPACITY:
|
||||
status = bot_scsi_capacity(udev, cbw_struct.bCBWLUN);
|
||||
status = bot_scsi_capacity(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
case MSC_CMD_REQUEST_SENSE:
|
||||
status = bot_scsi_request_sense(udev, cbw_struct.bCBWLUN);
|
||||
status = bot_scsi_request_sense(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
case MSC_CMD_TEST_UNIT:
|
||||
status = bot_scsi_test_unit(udev, cbw_struct.bCBWLUN);
|
||||
status = bot_scsi_test_unit(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
case MSC_CMD_VERIFY:
|
||||
status = bot_scsi_verify(udev, cbw_struct.bCBWLUN);
|
||||
status = bot_scsi_verify(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
case MSC_CMD_WRITE_10:
|
||||
status = bot_scsi_write10(udev, cbw_struct.bCBWLUN);
|
||||
status = bot_scsi_write10(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
case MSC_CMD_READ_FORMAT_CAPACITY:
|
||||
status = bot_scsi_format_capacity(udev, cbw_struct.bCBWLUN);
|
||||
status = bot_scsi_format_capacity(udev, pmsc->cbw_struct.bCBWLUN);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_bot_scsi.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb mass storage bulk-only transport and scsi command header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -204,6 +204,12 @@ typedef struct
|
||||
|
||||
uint32_t data_len;
|
||||
uint8_t data[MSC_MAX_DATA_BUF_LEN];
|
||||
|
||||
uint32_t alt_setting;
|
||||
|
||||
cbw_type cbw_struct;
|
||||
csw_type csw_struct;
|
||||
|
||||
}msc_type;
|
||||
|
||||
void bot_scsi_init(void *udev);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_class.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb msc class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -41,22 +41,17 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
/* usb rx and tx buffer */
|
||||
static uint32_t alt_setting = 0;
|
||||
|
||||
extern msc_type msc_struct;
|
||||
extern cbw_type cbw_struct;
|
||||
extern csw_type csw_struct;
|
||||
msc_type msc_struct;
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler msc_class_handler =
|
||||
@@ -70,6 +65,7 @@ usbd_class_handler msc_class_handler =
|
||||
class_out_handler,
|
||||
class_sof_handler,
|
||||
class_event_handler,
|
||||
&msc_struct
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -77,7 +73,7 @@ usbd_class_handler msc_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;
|
||||
@@ -98,7 +94,7 @@ 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;
|
||||
@@ -118,10 +114,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;
|
||||
msc_type *pmsc = (msc_type *)pudev->class_handler->pdata;
|
||||
switch(setup->bmRequestType & USB_REQ_TYPE_RESERVED)
|
||||
{
|
||||
/* class request */
|
||||
@@ -151,17 +148,17 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&alt_setting, 1);
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&pmsc->alt_setting, 1);
|
||||
break;
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
alt_setting = setup->wValue;
|
||||
pmsc->alt_setting = setup->wValue;
|
||||
break;
|
||||
case USB_STD_REQ_CLEAR_FEATURE:
|
||||
usbd_ept_close(pudev, (uint8_t)setup->wIndex);
|
||||
|
||||
if((setup->wIndex & 0x80) == 0x80)
|
||||
{
|
||||
usb_flush_tx_fifo(pudev->usb_reg, setup->wIndex & 0x7F);
|
||||
usbd_flush_tx_fifo(pudev, setup->wIndex & 0x7F);
|
||||
usbd_ept_open(pudev, (uint8_t)setup->wIndex, EPT_BULK_TYPE, USBD_IN_MAXPACKET_SIZE);
|
||||
}
|
||||
else
|
||||
@@ -186,7 +183,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;
|
||||
|
||||
@@ -200,7 +197,7 @@ usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
* @param udev: usb device core handler 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;
|
||||
@@ -215,11 +212,11 @@ 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;
|
||||
usb_flush_tx_fifo(pudev->usb_reg, ept_num&0x7F);
|
||||
usbd_flush_tx_fifo(pudev, ept_num&0x7F);
|
||||
bot_scsi_datain_handler(udev, ept_num);
|
||||
return status;
|
||||
}
|
||||
@@ -230,9 +227,10 @@ 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;
|
||||
|
||||
bot_scsi_dataout_handler(udev, ept_num);
|
||||
return status;
|
||||
}
|
||||
@@ -242,7 +240,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;
|
||||
|
||||
@@ -257,7 +255,7 @@ 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;
|
||||
switch(event)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_class.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb msc class file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_desc.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb msc device descriptor
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -42,18 +42,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];
|
||||
@@ -81,7 +81,7 @@ usbd_desc_handler msc_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 */
|
||||
@@ -91,10 +91,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_MSC_VENDOR_ID), /* idVendor */
|
||||
HBYTE(USBD_MSC_VENDOR_ID), /* idVendor */
|
||||
LBYTE(USBD_MSC_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_MSC_PRODUCT_ID), /* idProduct */
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
USB_MFC_STRING, /* Index of manufacturer string */
|
||||
@@ -109,12 +109,12 @@ 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_MSC_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_MSC_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
HBYTE(USBD_MSC_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
0x01, /* bNumInterfaces: 2 interface */
|
||||
0x01, /* bConfigurationValue: configuration value */
|
||||
0x04, /* iConfiguration: index of string descriptor describing
|
||||
@@ -155,9 +155,9 @@ 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_string_lang_id[USBD_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD static uint8_t g_string_lang_id[USBD_MSC_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_MSC_SIZ_STRING_LANGID,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
0x09,
|
||||
0x04,
|
||||
@@ -169,42 +169,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_MSC_SIZ_STRING_SERIAL] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_SERIAL,
|
||||
USBD_MSC_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_MSC_CONFIG_DESC_SIZE,
|
||||
g_usbd_configuration
|
||||
};
|
||||
|
||||
/* langid descriptor */
|
||||
usbd_desc_t langid_descriptor =
|
||||
static usbd_desc_t langid_descriptor =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_MSC_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_MSC_SIZ_STRING_SERIAL,
|
||||
g_string_serial
|
||||
};
|
||||
|
||||
usbd_desc_t vp_desc;
|
||||
static usbd_desc_t vp_desc;
|
||||
|
||||
/**
|
||||
* @brief standard usb unicode convert
|
||||
@@ -212,7 +212,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;
|
||||
@@ -286,7 +286,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;
|
||||
}
|
||||
@@ -296,7 +296,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;
|
||||
}
|
||||
@@ -306,7 +306,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;
|
||||
}
|
||||
@@ -316,7 +316,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;
|
||||
}
|
||||
@@ -326,7 +326,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;
|
||||
}
|
||||
@@ -337,9 +337,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_MSC_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -349,9 +349,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_MSC_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -361,7 +361,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;
|
||||
@@ -372,9 +372,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_MSC_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -384,9 +384,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_MSC_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file msc_desc.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb msc descriptor header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -47,37 +47,24 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define BCD_NUM 0x0110
|
||||
#define MSC_BCD_NUM 0x0110
|
||||
|
||||
#define USBD_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRODUCT_ID 0x5720
|
||||
#define USBD_MSC_VENDOR_ID 0x2E3C
|
||||
#define USBD_MSC_PRODUCT_ID 0x5720
|
||||
|
||||
#define USBD_CONFIG_DESC_SIZE 32
|
||||
#define USBD_SIZ_STRING_LANGID 4
|
||||
#define USBD_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
#define USBD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_DESC_PRODUCT_STRING "AT32 Mass Storage"
|
||||
#define USBD_DESC_CONFIGURATION_STRING "Mass Storage Config"
|
||||
#define USBD_DESC_INTERFACE_STRING "Mass Storage Interface"
|
||||
|
||||
#define HID_BINTERVAL_TIME 0xFF
|
||||
|
||||
#define USBD_CDC_CS_INTERFACE 0x24
|
||||
#define USBD_CDC_CS_ENDPOINT 0x25
|
||||
|
||||
#define USBD_CDC_SUBTYPE_HEADER 0x00
|
||||
#define USBD_CDC_SUBTYPE_CMF 0x01
|
||||
#define USBD_CDC_SUBTYPE_ACM 0x02
|
||||
#define USBD_CDC_SUBTYPE_UFD 0x06
|
||||
#define USBD_MSC_CONFIG_DESC_SIZE 32
|
||||
#define USBD_MSC_SIZ_STRING_LANGID 4
|
||||
#define USBD_MSC_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
#define USBD_MSC_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_MSC_DESC_PRODUCT_STRING "AT32 Mass Storage"
|
||||
#define USBD_MSC_DESC_CONFIGURATION_STRING "Mass Storage Config"
|
||||
#define USBD_MSC_DESC_INTERFACE_STRING "Mass Storage Interface"
|
||||
|
||||
#define MCU_ID1 (0x1FFFF7E8)
|
||||
#define MCU_ID2 (0x1FFFF7EC)
|
||||
#define MCU_ID3 (0x1FFFF7F0)
|
||||
|
||||
extern uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN];
|
||||
extern uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE];
|
||||
extern usbd_desc_handler msc_desc_handler;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file printer_class.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb printer class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -40,35 +40,28 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
/* usb rx and tx buffer */
|
||||
static uint32_t alt_setting = 0;
|
||||
static uint8_t g_rx_buff[USBD_OUT_MAXPACKET_SIZE];
|
||||
__IO uint8_t g_tx_completed = 1, g_rx_completed = 0;
|
||||
|
||||
uint8_t PRINTER_DEVICE_ID[PRINTER_DEVICE_ID_LEN] =
|
||||
ALIGNED_HEAD static uint8_t printer_device_id[PRINTER_DEVICE_ID_LEN] ALIGNED_TAIL=
|
||||
{
|
||||
0x00, 0x16,
|
||||
'M', 'F', 'G',':','A','r','t','e', 'r', 'y' ,' ',
|
||||
'C','M', 'D', ':', 'E', 'S', 'C', 'P', 'O', 'S',' ',
|
||||
};
|
||||
static uint32_t g_printer_port_status = 0x18;
|
||||
uint8_t g_printer_data[USBD_OUT_MAXPACKET_SIZE];
|
||||
|
||||
/* static variable */
|
||||
|
||||
printer_type printer_struct;
|
||||
|
||||
/* usb device class handler */
|
||||
usbd_class_handler class_handler =
|
||||
usbd_class_handler printer_class_handler =
|
||||
{
|
||||
class_init_handler,
|
||||
class_clear_handler,
|
||||
@@ -79,6 +72,7 @@ usbd_class_handler class_handler =
|
||||
class_out_handler,
|
||||
class_sof_handler,
|
||||
class_event_handler,
|
||||
&printer_struct
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -86,21 +80,23 @@ usbd_class_handler 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;
|
||||
printer_type *pprter = (printer_type *)pudev->class_handler->pdata;
|
||||
|
||||
/* open in endpoint */
|
||||
usbd_ept_open(pudev, USBD_PRINTER_BULK_IN_EPT, EPT_BULK_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_PRINTER_BULK_IN_EPT, EPT_BULK_TYPE, USBD_PRINTER_IN_MAXPACKET_SIZE);
|
||||
|
||||
/* open out endpoint */
|
||||
usbd_ept_open(pudev, USBD_PRINTER_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_open(pudev, USBD_PRINTER_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_PRINTER_OUT_MAXPACKET_SIZE);
|
||||
|
||||
/* set out endpoint to receive status */
|
||||
usbd_ept_recv(pudev, USBD_PRINTER_BULK_OUT_EPT, g_rx_buff, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ept_recv(pudev, USBD_PRINTER_BULK_OUT_EPT, pprter->g_rx_buff, USBD_PRINTER_OUT_MAXPACKET_SIZE);
|
||||
|
||||
g_tx_completed = 1;
|
||||
pprter->g_tx_completed = 1;
|
||||
pprter->g_printer_port_status = 0x18;
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -110,7 +106,7 @@ 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;
|
||||
@@ -130,10 +126,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;
|
||||
printer_type *pprter = (printer_type *)pudev->class_handler->pdata;
|
||||
|
||||
switch(setup->bmRequestType & USB_REQ_TYPE_RESERVED)
|
||||
{
|
||||
@@ -142,13 +139,13 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
switch(setup->bRequest)
|
||||
{
|
||||
case PRINTER_REQ_GET_DEVICE_ID:
|
||||
usbd_ctrl_send(pudev, PRINTER_DEVICE_ID, PRINTER_DEVICE_ID_LEN);
|
||||
usbd_ctrl_send(pudev, printer_device_id, PRINTER_DEVICE_ID_LEN);
|
||||
break;
|
||||
case PRINTER_REQ_GET_PORT_STATUS:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&g_printer_port_status, 1);
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&pprter->g_printer_port_status, 1);
|
||||
break;
|
||||
case PRINTER_REQ_GET_SOFT_RESET:
|
||||
usbd_ctrl_recv(pudev, g_printer_data, USBD_OUT_MAXPACKET_SIZE);
|
||||
usbd_ctrl_recv(pudev, pprter->g_printer_data, USBD_PRINTER_OUT_MAXPACKET_SIZE);
|
||||
break;
|
||||
default:
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
@@ -163,10 +160,10 @@ usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup)
|
||||
usbd_ctrl_unsupport(pudev);
|
||||
break;
|
||||
case USB_STD_REQ_GET_INTERFACE:
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&alt_setting, 1);
|
||||
usbd_ctrl_send(pudev, (uint8_t *)&pprter->alt_setting, 1);
|
||||
break;
|
||||
case USB_STD_REQ_SET_INTERFACE:
|
||||
alt_setting = setup->wValue;
|
||||
pprter->alt_setting = setup->wValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -184,7 +181,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;
|
||||
|
||||
@@ -198,7 +195,7 @@ usb_sts_type class_ept0_tx_handler(void *udev)
|
||||
* @param udev: usb device core handler 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;
|
||||
|
||||
@@ -213,16 +210,17 @@ 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)
|
||||
{
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
printer_type *pprter = (printer_type *)pudev->class_handler->pdata;
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
/* ...user code...
|
||||
trans next packet data
|
||||
*/
|
||||
usbd_flush_tx_fifo(pudev, ept_num);
|
||||
g_tx_completed = 1;
|
||||
pprter->g_tx_completed = 1;
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -233,12 +231,14 @@ 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;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
printer_type *pprter = (printer_type *)pudev->class_handler->pdata;
|
||||
|
||||
/*set recv flag*/
|
||||
g_rx_completed = 1;
|
||||
pprter->g_rx_completed = 1;
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -248,7 +248,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;
|
||||
|
||||
@@ -263,7 +263,7 @@ 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;
|
||||
switch(event)
|
||||
@@ -304,9 +304,10 @@ error_status usb_printer_send_data(void *udev, uint8_t *send_data, uint16_t len)
|
||||
{
|
||||
error_status status = SUCCESS;
|
||||
usbd_core_type *pudev = (usbd_core_type *)udev;
|
||||
if(g_tx_completed)
|
||||
printer_type *pprter = (printer_type *)pudev->class_handler->pdata;
|
||||
if(pprter->g_tx_completed)
|
||||
{
|
||||
g_tx_completed = 0;
|
||||
pprter->g_tx_completed = 0;
|
||||
usbd_ept_send(pudev, USBD_PRINTER_BULK_IN_EPT, send_data, len);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file printer_class.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb cdc class file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -51,8 +51,8 @@ extern "C" {
|
||||
#define USBD_PRINTER_BULK_OUT_EPT 0x01
|
||||
|
||||
|
||||
#define USBD_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_OUT_MAXPACKET_SIZE 0x40
|
||||
#define USBD_PRINTER_IN_MAXPACKET_SIZE 0x40
|
||||
#define USBD_PRINTER_OUT_MAXPACKET_SIZE 0x40
|
||||
|
||||
#define PRINTER_DEVICE_ID_LEN 24
|
||||
|
||||
@@ -64,18 +64,17 @@ typedef enum
|
||||
}printer_req_type;
|
||||
|
||||
|
||||
#define SET_LINE_CODING 0x20
|
||||
#define GET_LINE_CODING 0x21
|
||||
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
uint32_t bitrate;
|
||||
uint8_t format;
|
||||
uint8_t parity;
|
||||
uint8_t data;
|
||||
}linecoding_type;
|
||||
uint32_t alt_setting;
|
||||
uint32_t g_printer_port_status;
|
||||
uint8_t g_rx_buff[USBD_PRINTER_OUT_MAXPACKET_SIZE];
|
||||
uint8_t g_printer_data[USBD_PRINTER_OUT_MAXPACKET_SIZE];
|
||||
__IO uint8_t g_tx_completed;
|
||||
__IO uint8_t g_rx_completed;
|
||||
}printer_type;
|
||||
|
||||
extern usbd_class_handler class_handler;
|
||||
extern usbd_class_handler printer_class_handler;
|
||||
uint16_t usb_printer_get_rxdata(void *udev, uint8_t *recv_data);
|
||||
error_status usb_printer_send_data(void *udev, uint8_t *send_data, uint16_t len);
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file printer_desc.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb printer device descriptor
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -42,18 +42,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];
|
||||
@@ -61,7 +61,7 @@ static uint8_t g_usbd_desc_buffer[256];
|
||||
/**
|
||||
* @brief device descriptor handler structure
|
||||
*/
|
||||
usbd_desc_handler desc_handler =
|
||||
usbd_desc_handler printer_desc_handler =
|
||||
{
|
||||
get_device_descriptor,
|
||||
get_device_qualifier,
|
||||
@@ -81,7 +81,7 @@ usbd_desc_handler 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 */
|
||||
@@ -91,10 +91,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_PRINTER_VENDOR_ID), /* idVendor */
|
||||
HBYTE(USBD_PRINTER_VENDOR_ID), /* idVendor */
|
||||
LBYTE(USBD_PRINTER_PRODUCT_ID), /* idProduct */
|
||||
HBYTE(USBD_PRINTER_PRODUCT_ID), /* idProduct */
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
USB_MFC_STRING, /* Index of manufacturer string */
|
||||
@@ -109,12 +109,12 @@ 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_PRINTER_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_PRINTER_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
HBYTE(USBD_PRINTER_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */
|
||||
0x01, /* bNumInterfaces: 1 interface */
|
||||
0x01, /* bConfigurationValue: configuration value */
|
||||
0x00, /* iConfiguration: index of string descriptor describing
|
||||
@@ -136,16 +136,16 @@ ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL =
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_PRINTER_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
LBYTE(USBD_PRINTER_IN_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_PRINTER_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
|
||||
USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */
|
||||
USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
|
||||
USBD_PRINTER_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */
|
||||
USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */
|
||||
LBYTE(USBD_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */
|
||||
LBYTE(USBD_PRINTER_OUT_MAXPACKET_SIZE),
|
||||
HBYTE(USBD_PRINTER_OUT_MAXPACKET_SIZE),/* wMaxPacketSize: maximum packe size this endpoint */
|
||||
0x00, /* bInterval: interval for polling endpoint for data transfers */
|
||||
};
|
||||
|
||||
@@ -155,9 +155,9 @@ 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_string_lang_id[USBD_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
ALIGNED_HEAD static uint8_t g_string_lang_id[USBD_PRINTER_SIZ_STRING_LANGID] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_PRINTER_SIZ_STRING_LANGID,
|
||||
USB_DESCIPTOR_TYPE_STRING,
|
||||
0x09,
|
||||
0x04,
|
||||
@@ -169,42 +169,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_PRINTER_SIZ_STRING_SERIAL] ALIGNED_TAIL =
|
||||
{
|
||||
USBD_SIZ_STRING_SERIAL,
|
||||
USBD_PRINTER_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_PRINTER_CONFIG_DESC_SIZE,
|
||||
g_usbd_configuration
|
||||
};
|
||||
|
||||
/* langid descriptor */
|
||||
usbd_desc_t langid_descriptor =
|
||||
static usbd_desc_t langid_descriptor =
|
||||
{
|
||||
USBD_SIZ_STRING_LANGID,
|
||||
USBD_PRINTER_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_PRINTER_SIZ_STRING_SERIAL,
|
||||
g_string_serial
|
||||
};
|
||||
|
||||
usbd_desc_t vp_desc;
|
||||
static usbd_desc_t vp_desc;
|
||||
|
||||
/**
|
||||
* @brief standard usb unicode convert
|
||||
@@ -212,7 +212,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;
|
||||
@@ -286,7 +286,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;
|
||||
}
|
||||
@@ -296,7 +296,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;
|
||||
}
|
||||
@@ -306,7 +306,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;
|
||||
}
|
||||
@@ -316,7 +316,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;
|
||||
}
|
||||
@@ -326,7 +326,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;
|
||||
}
|
||||
@@ -337,9 +337,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_PRINTER_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -349,9 +349,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_PRINTER_DESC_PRODUCT_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -361,7 +361,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;
|
||||
@@ -372,9 +372,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_PRINTER_DESC_INTERFACE_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
@@ -384,9 +384,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_PRINTER_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer);
|
||||
vp_desc.descriptor = g_usbd_desc_buffer;
|
||||
return &vp_desc;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file printer_desc.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb printer descriptor header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -47,35 +47,32 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define BCD_NUM 0x0110
|
||||
#define PRINTER_BCD_NUM 0x0110
|
||||
|
||||
#define USBD_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRODUCT_ID 0x57FF
|
||||
#define USBD_PRINTER_VENDOR_ID 0x2E3C
|
||||
#define USBD_PRINTER_PRODUCT_ID 0x57FF
|
||||
|
||||
#define USBD_CONFIG_DESC_SIZE 32
|
||||
#define USBD_SIZ_STRING_LANGID 4
|
||||
#define USBD_SIZ_STRING_SERIAL 0x1A
|
||||
#define USBD_PRINTER_CONFIG_DESC_SIZE 32
|
||||
#define USBD_PRINTER_SIZ_STRING_LANGID 4
|
||||
#define USBD_PRINTER_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
#define USBD_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_DESC_PRODUCT_STRING "AT32 Printer"
|
||||
#define USBD_DESC_CONFIGURATION_STRING "Printer Config"
|
||||
#define USBD_DESC_INTERFACE_STRING "Printer Interface"
|
||||
#define USBD_PRINTER_DESC_MANUFACTURER_STRING "Artery"
|
||||
#define USBD_PRINTER_DESC_PRODUCT_STRING "AT32 Printer"
|
||||
#define USBD_PRINTER_DESC_CONFIGURATION_STRING "Printer Config"
|
||||
#define USBD_PRINTER_DESC_INTERFACE_STRING "Printer Interface"
|
||||
|
||||
#define PRINTER_PROTOCOL_UNIDIRECTIONAL 0x01
|
||||
#define PRINTER_PROTOCOL_BI_DIRECTIONAL 0x02
|
||||
#define PRINTER_PROTOCOL_1284_4 0x03
|
||||
#define PRINTER_PROTOCOL_VENDOR_SPECIFIC 0xFF
|
||||
|
||||
#define HID_BINTERVAL_TIME 0xFF
|
||||
|
||||
#define MCU_ID1 (0x1FFFF7E8)
|
||||
#define MCU_ID2 (0x1FFFF7EC)
|
||||
#define MCU_ID3 (0x1FFFF7F0)
|
||||
|
||||
extern uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN];
|
||||
extern uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE];
|
||||
|
||||
extern usbd_desc_handler desc_handler;
|
||||
extern usbd_desc_handler printer_desc_handler;
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_class.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host hid class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -43,13 +43,13 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
usb_sts_type uhost_init_handler(void *uhost);
|
||||
usb_sts_type uhost_reset_handler(void *uhost);
|
||||
usb_sts_type uhost_request_handler(void *uhost);
|
||||
usb_sts_type uhost_process_handler(void *uhost);
|
||||
static usb_sts_type uhost_init_handler(void *uhost);
|
||||
static usb_sts_type uhost_reset_handler(void *uhost);
|
||||
static usb_sts_type uhost_request_handler(void *uhost);
|
||||
static usb_sts_type uhost_process_handler(void *uhost);
|
||||
|
||||
usbh_hid_type usbh_hid;
|
||||
usbh_class_handler_type uhost_class_handler =
|
||||
usbh_class_handler_type uhost_hid_class_handler =
|
||||
{
|
||||
uhost_init_handler,
|
||||
uhost_reset_handler,
|
||||
@@ -63,7 +63,7 @@
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type uhost_init_handler(void *uhost)
|
||||
static usb_sts_type uhost_init_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usb_sts_type status = USB_OK;
|
||||
@@ -107,6 +107,7 @@ usb_sts_type uhost_init_handler(void *uhost)
|
||||
puhost->dev.address, EPT_INT_TYPE,
|
||||
phid->in_maxpacket,
|
||||
puhost->dev.speed);
|
||||
usbh_set_toggle(puhost, phid->chin, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -121,6 +122,7 @@ usb_sts_type uhost_init_handler(void *uhost)
|
||||
puhost->dev.address, EPT_INT_TYPE,
|
||||
phid->out_maxpacket,
|
||||
puhost->dev.speed);
|
||||
usbh_set_toggle(puhost, phid->chout, 0);
|
||||
}
|
||||
}
|
||||
phid->ctrl_state = USB_HID_STATE_IDLE;
|
||||
@@ -132,7 +134,7 @@ usb_sts_type uhost_init_handler(void *uhost)
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type uhost_reset_handler(void *uhost)
|
||||
static usb_sts_type uhost_reset_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_hid_type *phid = (usbh_hid_type *)puhost->class_handler->pdata;
|
||||
@@ -333,7 +335,7 @@ usb_sts_type usbh_clear_endpoint_feature(usbh_core_type *uhost, uint8_t ept_num,
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type uhost_request_handler(void *uhost)
|
||||
static usb_sts_type uhost_request_handler(void *uhost)
|
||||
{
|
||||
usb_sts_type status = USB_WAIT;
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
@@ -384,7 +386,7 @@ usb_sts_type uhost_request_handler(void *uhost)
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type uhost_process_handler(void *uhost)
|
||||
static usb_sts_type uhost_process_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_hid_type *phid = (usbh_hid_type *)puhost->class_handler->pdata;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_class.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host hid class header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -127,7 +127,7 @@ typedef struct
|
||||
uint32_t buffer[16];
|
||||
}usbh_hid_type;
|
||||
|
||||
extern usbh_class_handler_type uhost_class_handler;
|
||||
extern usbh_class_handler_type uhost_hid_class_handler;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_keyboard.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host hid keyboard type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_keyboard.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host hid keyboard header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_mouse.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host hid mouse type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_hid_mouse.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host hid mouse header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_msc_bot_scsi.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host msc bulk-only transfer and scsi type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -202,10 +202,19 @@ static usb_sts_type usbh_cmd_read(msc_bot_trans_type *bot_trans, uint8_t *cmd, u
|
||||
* @param csw: to the structure of msc_bot_csw_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type usbh_check_csw(msc_bot_cbw_type *cbw, msc_bot_csw_type *csw)
|
||||
usb_sts_type usbh_check_csw(void *uhost, msc_bot_cbw_type *cbw, msc_bot_csw_type *csw)
|
||||
{
|
||||
usb_sts_type status = USB_OK;
|
||||
|
||||
usb_sts_type status = USB_FAIL;
|
||||
if(csw->dCBWSignature == MSC_CSW_SIGNATURE)
|
||||
{
|
||||
if(csw->dCBWTag == cbw->dCBWTag)
|
||||
{
|
||||
if(csw->bCSWStatus == 0)
|
||||
{
|
||||
status = USB_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -219,6 +228,7 @@ usb_sts_type usb_bot_request(void *uhost, msc_bot_trans_type *bot_trans)
|
||||
{
|
||||
usb_sts_type status = USB_WAIT;
|
||||
urb_sts_type urb_status;
|
||||
usb_sts_type clr_status;
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_msc_type *msc_struct = (usbh_msc_type *)bot_trans->msc_struct;
|
||||
switch(bot_trans->bot_state)
|
||||
@@ -254,7 +264,7 @@ usb_sts_type usb_bot_request(void *uhost, msc_bot_trans_type *bot_trans)
|
||||
}
|
||||
else if(urb_status == URB_STALL)
|
||||
{
|
||||
bot_trans->bot_state = BOT_STATE_ERROR;
|
||||
bot_trans->bot_state = BOT_STATE_ERROR_OUT;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -289,7 +299,7 @@ usb_sts_type usb_bot_request(void *uhost, msc_bot_trans_type *bot_trans)
|
||||
}
|
||||
else if(urb_status == URB_STALL)
|
||||
{
|
||||
bot_trans->bot_state = BOT_STATE_ERROR;
|
||||
bot_trans->bot_state = BOT_STATE_ERROR_IN;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -327,7 +337,7 @@ usb_sts_type usb_bot_request(void *uhost, msc_bot_trans_type *bot_trans)
|
||||
}
|
||||
else if(urb_status == URB_STALL)
|
||||
{
|
||||
bot_trans->bot_state = BOT_STATE_ERROR;
|
||||
bot_trans->bot_state = BOT_STATE_ERROR_OUT;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -343,22 +353,32 @@ usb_sts_type usb_bot_request(void *uhost, msc_bot_trans_type *bot_trans)
|
||||
{
|
||||
bot_trans->bot_state = BOT_STATE_SEND_CBW;
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
status = usbh_check_csw(&bot_trans->cbw, &bot_trans->csw);
|
||||
status = usbh_check_csw(uhost, &bot_trans->cbw, &bot_trans->csw);
|
||||
}
|
||||
else if(urb_status == URB_STALL)
|
||||
{
|
||||
bot_trans->bot_state = BOT_STATE_ERROR;
|
||||
bot_trans->bot_state = BOT_STATE_ERROR_IN;
|
||||
}
|
||||
|
||||
break;
|
||||
case BOT_STATE_ERROR:
|
||||
if(usbh_clear_ept_feature(puhost, msc_struct->eptin, 0) == USB_OK)
|
||||
case BOT_STATE_ERROR_IN:
|
||||
clr_status = usbh_clear_ept_feature(puhost, msc_struct->eptin, msc_struct->chin);
|
||||
if(clr_status == USB_OK)
|
||||
{
|
||||
bot_trans->bot_state = BOT_STATE_RECV_CSW;
|
||||
usbh_set_toggle(puhost, msc_struct->chin, 0);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BOT_STATE_ERROR_OUT:
|
||||
clr_status = usbh_clear_ept_feature(puhost, msc_struct->eptout, msc_struct->chout);
|
||||
if(clr_status == USB_OK)
|
||||
{
|
||||
usbh_set_toggle(puhost, msc_struct->chout, 1 - puhost->hch[msc_struct->chout].toggle_out);
|
||||
usbh_set_toggle(puhost, msc_struct->chin, 0);
|
||||
bot_trans->bot_state = BOT_STATE_ERROR_IN;
|
||||
}
|
||||
break;
|
||||
case BOT_STATE_COMPLETE:
|
||||
break;
|
||||
|
||||
@@ -384,19 +404,23 @@ usb_sts_type usbh_msc_bot_scsi_get_inquiry(void *uhost, msc_bot_trans_type *bot
|
||||
switch(bot_trans->cmd_state)
|
||||
{
|
||||
case CMD_STATE_SEND:
|
||||
usbh_bot_cbw(&bot_trans->cbw, MSC_INQUIRY_DATA_LEN, MSC_INQUIRY_CMD_LEN, MSC_CBW_FLAG_IN);
|
||||
usbh_cmd_inquiry(bot_trans, bot_trans->cbw.CBWCB, lun);
|
||||
bot_trans->cmd_state = CMD_STATE_WAIT;
|
||||
bot_trans->bot_state = BOT_STATE_SEND_CBW;
|
||||
usbh_bot_cbw(&bot_trans->cbw, MSC_INQUIRY_DATA_LEN, MSC_INQUIRY_CMD_LEN, MSC_CBW_FLAG_IN);
|
||||
usbh_cmd_inquiry(bot_trans, bot_trans->cbw.CBWCB, lun);
|
||||
bot_trans->cmd_state = CMD_STATE_WAIT;
|
||||
bot_trans->bot_state = BOT_STATE_SEND_CBW;
|
||||
break;
|
||||
|
||||
case CMD_STATE_WAIT:
|
||||
if(usb_bot_request(uhost, bot_trans) == USB_OK)
|
||||
{
|
||||
status = USB_OK;
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
break;
|
||||
status = usb_bot_request(uhost, bot_trans);
|
||||
if(status == USB_OK)
|
||||
{
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
if(status == USB_FAIL)
|
||||
{
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -418,22 +442,26 @@ usb_sts_type usbh_msc_bot_scsi_capacity(void *uhost, msc_bot_trans_type *bot_tra
|
||||
switch(bot_trans->cmd_state)
|
||||
{
|
||||
case CMD_STATE_SEND:
|
||||
usbh_bot_cbw(&bot_trans->cbw, MSC_CAPACITY10_DATA_LEN, MSC_CAPACITY10_CMD_LEN, MSC_CBW_FLAG_IN);
|
||||
usbh_cmd_capacity10(bot_trans, bot_trans->cbw.CBWCB, lun);
|
||||
bot_trans->cmd_state = CMD_STATE_WAIT;
|
||||
bot_trans->bot_state = BOT_STATE_SEND_CBW;
|
||||
break;
|
||||
usbh_bot_cbw(&bot_trans->cbw, MSC_CAPACITY10_DATA_LEN, MSC_CAPACITY10_CMD_LEN, MSC_CBW_FLAG_IN);
|
||||
usbh_cmd_capacity10(bot_trans, bot_trans->cbw.CBWCB, lun);
|
||||
bot_trans->cmd_state = CMD_STATE_WAIT;
|
||||
bot_trans->bot_state = BOT_STATE_SEND_CBW;
|
||||
break;
|
||||
|
||||
case CMD_STATE_WAIT:
|
||||
if(usb_bot_request(uhost, bot_trans) == USB_OK)
|
||||
{
|
||||
status = USB_OK;
|
||||
capacity->blk_nbr = bot_trans->buffer[3] | bot_trans->buffer[2] << 8 |
|
||||
bot_trans->buffer[1] << 16 | bot_trans->buffer[0] << 24;
|
||||
capacity->blk_size = bot_trans->buffer[7] | bot_trans->buffer[6] << 8 ;
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
break;
|
||||
status = usb_bot_request(uhost, bot_trans);
|
||||
if(status == USB_OK)
|
||||
{
|
||||
capacity->blk_nbr = bot_trans->buffer[3] | bot_trans->buffer[2] << 8 |
|
||||
bot_trans->buffer[1] << 16 | bot_trans->buffer[0] << 24;
|
||||
capacity->blk_size = bot_trans->buffer[7] | bot_trans->buffer[6] << 8 ;
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
if(status == USB_FAIL)
|
||||
{
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -454,20 +482,24 @@ usb_sts_type usbh_msc_bot_scsi_test_unit_ready(void *uhost, msc_bot_trans_type *
|
||||
switch(bot_trans->cmd_state)
|
||||
{
|
||||
case CMD_STATE_SEND:
|
||||
usbh_bot_cbw(&bot_trans->cbw, MSC_TEST_UNIT_READY_DATA_LEN,
|
||||
MSC_TEST_UNIT_READY_CMD_LEN, MSC_CBW_FLAG_OUT);
|
||||
usbh_cmd_test_unit_ready(bot_trans, bot_trans->cbw.CBWCB, lun);
|
||||
bot_trans->cmd_state = CMD_STATE_WAIT;
|
||||
bot_trans->bot_state = BOT_STATE_SEND_CBW;
|
||||
usbh_bot_cbw(&bot_trans->cbw, MSC_TEST_UNIT_READY_DATA_LEN,
|
||||
MSC_TEST_UNIT_READY_CMD_LEN, MSC_CBW_FLAG_OUT);
|
||||
usbh_cmd_test_unit_ready(bot_trans, bot_trans->cbw.CBWCB, lun);
|
||||
bot_trans->cmd_state = CMD_STATE_WAIT;
|
||||
bot_trans->bot_state = BOT_STATE_SEND_CBW;
|
||||
break;
|
||||
|
||||
case CMD_STATE_WAIT:
|
||||
if(usb_bot_request(uhost, bot_trans) == USB_OK)
|
||||
{
|
||||
status = USB_OK;
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
break;
|
||||
status = usb_bot_request(uhost, bot_trans);
|
||||
if(status == USB_OK)
|
||||
{
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
if(status == USB_FAIL)
|
||||
{
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -488,20 +520,24 @@ usb_sts_type usbh_msc_bot_scsi_request_sense(void *uhost, msc_bot_trans_type *bo
|
||||
switch(bot_trans->cmd_state)
|
||||
{
|
||||
case CMD_STATE_SEND:
|
||||
usbh_bot_cbw(&bot_trans->cbw, MSC_REQUEST_SENSE_DATA_LEN,
|
||||
MSC_REQUEST_SENSE_CMD_LEN, MSC_CBW_FLAG_IN);
|
||||
usbh_cmd_requset_sense(bot_trans, bot_trans->cbw.CBWCB, lun);
|
||||
bot_trans->cmd_state = CMD_STATE_WAIT;
|
||||
bot_trans->bot_state = BOT_STATE_SEND_CBW;
|
||||
usbh_bot_cbw(&bot_trans->cbw, MSC_REQUEST_SENSE_DATA_LEN,
|
||||
MSC_REQUEST_SENSE_CMD_LEN, MSC_CBW_FLAG_IN);
|
||||
usbh_cmd_requset_sense(bot_trans, bot_trans->cbw.CBWCB, lun);
|
||||
bot_trans->cmd_state = CMD_STATE_WAIT;
|
||||
bot_trans->bot_state = BOT_STATE_SEND_CBW;
|
||||
break;
|
||||
|
||||
case CMD_STATE_WAIT:
|
||||
if(usb_bot_request(uhost, bot_trans) == USB_OK)
|
||||
{
|
||||
status = USB_OK;
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
break;
|
||||
status = usb_bot_request(uhost, bot_trans);
|
||||
if(status == USB_OK)
|
||||
{
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
if(status == USB_FAIL)
|
||||
{
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -526,19 +562,23 @@ usb_sts_type usbh_msc_bot_scsi_write(void *uhost, msc_bot_trans_type *bot_trans,
|
||||
switch(bot_trans->cmd_state)
|
||||
{
|
||||
case CMD_STATE_SEND:
|
||||
usbh_bot_cbw(&bot_trans->cbw, write_len * 512,
|
||||
MSC_WRITE_CMD_LEN, MSC_CBW_FLAG_OUT);
|
||||
usbh_cmd_write(bot_trans, bot_trans->cbw.CBWCB, lun, write_len, address, write_data);
|
||||
bot_trans->cmd_state = CMD_STATE_WAIT;
|
||||
bot_trans->bot_state = BOT_STATE_SEND_CBW;
|
||||
usbh_bot_cbw(&bot_trans->cbw, write_len * 512,
|
||||
MSC_WRITE_CMD_LEN, MSC_CBW_FLAG_OUT);
|
||||
usbh_cmd_write(bot_trans, bot_trans->cbw.CBWCB, lun, write_len, address, write_data);
|
||||
bot_trans->cmd_state = CMD_STATE_WAIT;
|
||||
bot_trans->bot_state = BOT_STATE_SEND_CBW;
|
||||
break;
|
||||
|
||||
case CMD_STATE_WAIT:
|
||||
if(usb_bot_request(uhost, bot_trans) == USB_OK)
|
||||
{
|
||||
status = USB_OK;
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
status = usb_bot_request(uhost, bot_trans);
|
||||
if(status == USB_OK)
|
||||
{
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
if(status == USB_FAIL)
|
||||
{
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -564,20 +604,24 @@ usb_sts_type usbh_msc_bot_scsi_read(void *uhost, msc_bot_trans_type *bot_trans,
|
||||
switch(bot_trans->cmd_state)
|
||||
{
|
||||
case CMD_STATE_SEND:
|
||||
usbh_bot_cbw(&bot_trans->cbw, read_len * 512,
|
||||
MSC_READ_CMD_LEN, MSC_CBW_FLAG_IN);
|
||||
usbh_cmd_read(bot_trans, bot_trans->cbw.CBWCB, lun, read_len, address, read_data);
|
||||
bot_trans->cmd_state = CMD_STATE_WAIT;
|
||||
bot_trans->bot_state = BOT_STATE_SEND_CBW;
|
||||
usbh_bot_cbw(&bot_trans->cbw, read_len * 512,
|
||||
MSC_READ_CMD_LEN, MSC_CBW_FLAG_IN);
|
||||
usbh_cmd_read(bot_trans, bot_trans->cbw.CBWCB, lun, read_len, address, read_data);
|
||||
bot_trans->cmd_state = CMD_STATE_WAIT;
|
||||
bot_trans->bot_state = BOT_STATE_SEND_CBW;
|
||||
break;
|
||||
|
||||
case CMD_STATE_WAIT:
|
||||
if(usb_bot_request(uhost, bot_trans) == USB_OK)
|
||||
{
|
||||
status = USB_OK;
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
break;
|
||||
status = usb_bot_request(uhost, bot_trans);
|
||||
if(status == USB_OK)
|
||||
{
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
if(status == USB_FAIL)
|
||||
{
|
||||
bot_trans->cmd_state = CMD_STATE_SEND;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_msc_bot_scsi.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host msc bulk-only transfer and scsi header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -84,7 +84,8 @@ typedef enum
|
||||
BOT_STATE_DATA_OUT_WAIT,
|
||||
BOT_STATE_RECV_CSW,
|
||||
BOT_STATE_RECV_CSW_WAIT,
|
||||
BOT_STATE_ERROR,
|
||||
BOT_STATE_ERROR_IN,
|
||||
BOT_STATE_ERROR_OUT,
|
||||
BOT_STATE_COMPLETE
|
||||
}msc_bot_state_type;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_msc_class.c
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host msc class type
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -41,18 +41,18 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
usb_sts_type uhost_init_handler(void *uhost);
|
||||
usb_sts_type uhost_reset_handler(void *uhost);
|
||||
usb_sts_type uhost_request_handler(void *uhost);
|
||||
usb_sts_type uhost_process_handler(void *uhost);
|
||||
static usb_sts_type uhost_init_handler(void *uhost);
|
||||
static usb_sts_type uhost_reset_handler(void *uhost);
|
||||
static usb_sts_type uhost_request_handler(void *uhost);
|
||||
static usb_sts_type uhost_process_handler(void *uhost);
|
||||
|
||||
usb_sts_type usbh_msc_get_max_lun(void *uhost, uint8_t *lun);
|
||||
usb_sts_type usbh_msc_clear_feature(void *uhost, uint8_t ept_num);
|
||||
static usb_sts_type usbh_msc_get_max_lun(void *uhost, uint8_t *lun);
|
||||
static usb_sts_type usbh_msc_clear_feature(void *uhost, uint8_t ept_num);
|
||||
|
||||
|
||||
usbh_msc_type usbh_msc;
|
||||
|
||||
usbh_class_handler_type uhost_class_handler =
|
||||
usbh_class_handler_type uhost_msc_class_handler =
|
||||
{
|
||||
uhost_init_handler,
|
||||
uhost_reset_handler,
|
||||
@@ -68,7 +68,7 @@ usbh_class_handler_type uhost_class_handler =
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type uhost_init_handler(void *uhost)
|
||||
static usb_sts_type uhost_init_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usb_sts_type status = USB_OK;
|
||||
@@ -125,7 +125,7 @@ usb_sts_type uhost_init_handler(void *uhost)
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type uhost_reset_handler(void *uhost)
|
||||
static usb_sts_type uhost_reset_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_msc_type *pmsc = (usbh_msc_type *)puhost->class_handler->pdata;
|
||||
@@ -167,7 +167,7 @@ usb_sts_type uhost_reset_handler(void *uhost)
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type uhost_request_handler(void *uhost)
|
||||
static usb_sts_type uhost_request_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_msc_type *pmsc = (usbh_msc_type *)puhost->class_handler->pdata;
|
||||
@@ -210,7 +210,7 @@ usb_sts_type uhost_request_handler(void *uhost)
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type uhost_process_handler(void *uhost)
|
||||
static usb_sts_type uhost_process_handler(void *uhost)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_msc_type *pmsc = (usbh_msc_type *)puhost->class_handler->pdata;
|
||||
@@ -273,13 +273,12 @@ usb_sts_type uhost_process_handler(void *uhost)
|
||||
status = usbh_msc_bot_scsi_request_sense(uhost, &pmsc->bot_trans, pmsc->cur_lun);
|
||||
if(status == USB_OK)
|
||||
{
|
||||
pmsc->l_unit_n[pmsc->cur_lun].state = USBH_MSC_IDLE;
|
||||
pmsc->cur_lun ++;
|
||||
pmsc->l_unit_n[pmsc->cur_lun].state = USBH_MSC_TEST_UNIT_READY;
|
||||
}
|
||||
else if(status == USB_FAIL)
|
||||
{
|
||||
pmsc->l_unit_n[pmsc->cur_lun].ready = MSC_NOT_READY;
|
||||
pmsc->cur_lun ++;
|
||||
pmsc->l_unit_n[pmsc->cur_lun].state = USBH_MSC_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -310,7 +309,7 @@ usb_sts_type uhost_process_handler(void *uhost)
|
||||
* @param lun: max lun buffer
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type usbh_msc_get_max_lun(void *uhost, uint8_t *lun)
|
||||
static usb_sts_type usbh_msc_get_max_lun(void *uhost, uint8_t *lun)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usb_sts_type status = USB_WAIT;
|
||||
@@ -340,7 +339,7 @@ usb_sts_type usbh_msc_get_max_lun(void *uhost, uint8_t *lun)
|
||||
* @param ept_num: endpoint number
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type usbh_msc_clear_feature(void *uhost, uint8_t ept_num)
|
||||
static usb_sts_type usbh_msc_clear_feature(void *uhost, uint8_t ept_num)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usb_sts_type status = USB_WAIT;
|
||||
@@ -376,6 +375,65 @@ msc_error_type usbh_msc_is_ready(void *uhost, uint8_t lun)
|
||||
return pmsc->l_unit_n[lun].ready;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief usb host msc read and write handle
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
* @param address: logical block address
|
||||
* @param data_len: transfer data length
|
||||
* @param buffer: transfer data buffer
|
||||
* @param lun: logical unit number
|
||||
* @retval status: usb_sts_type status
|
||||
*/
|
||||
usb_sts_type usbh_msc_rw_handle(void *uhost, uint32_t address, uint32_t len, uint8_t *buffer, uint8_t lun)
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_msc_type *pmsc = (usbh_msc_type *)puhost->class_handler->pdata;
|
||||
usb_sts_type status = USB_WAIT;
|
||||
switch(pmsc->l_unit_n[lun].state)
|
||||
{
|
||||
case USBH_MSC_READ10:
|
||||
status = usbh_msc_bot_scsi_read(uhost, &pmsc->bot_trans, address, buffer, len, lun);
|
||||
if(status == USB_OK)
|
||||
{
|
||||
pmsc->l_unit_n[lun].state = USBH_MSC_IDLE;
|
||||
}
|
||||
else if(status == USB_FAIL)
|
||||
{
|
||||
pmsc->l_unit_n[lun].state = USBH_MSC_REQUEST_SENSE;
|
||||
status = USB_WAIT;
|
||||
}
|
||||
break;
|
||||
case USBH_MSC_WRITE:
|
||||
status = usbh_msc_bot_scsi_write(uhost, &pmsc->bot_trans, address, buffer, len, lun);
|
||||
if(status == USB_OK)
|
||||
{
|
||||
pmsc->l_unit_n[lun].state = USBH_MSC_IDLE;
|
||||
}
|
||||
else if(status == USB_FAIL)
|
||||
{
|
||||
pmsc->l_unit_n[lun].state = USBH_MSC_REQUEST_SENSE;
|
||||
status = USB_WAIT;
|
||||
}
|
||||
break;
|
||||
case USBH_MSC_REQUEST_SENSE:
|
||||
status = usbh_msc_bot_scsi_request_sense(uhost, &pmsc->bot_trans, lun);
|
||||
if(status == USB_OK)
|
||||
{
|
||||
pmsc->l_unit_n[lun].state = USBH_MSC_IDLE;
|
||||
status = USB_FAIL;
|
||||
}
|
||||
else if(status == USB_FAIL)
|
||||
{
|
||||
USBH_DEBUG("device not support");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief usb host msc read
|
||||
* @param uhost: to the structure of usbh_core_type
|
||||
@@ -389,7 +447,6 @@ usb_sts_type usbh_msc_read(void *uhost, uint32_t address, uint32_t len, uint8_t
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_msc_type *pmsc = (usbh_msc_type *)puhost->class_handler->pdata;
|
||||
usb_sts_type status;
|
||||
uint32_t timeout = 0;
|
||||
if(puhost->conn_sts == 0 || puhost->global_state != USBH_CLASS
|
||||
|| pmsc->l_unit_n[lun].state != USBH_MSC_IDLE)
|
||||
@@ -397,31 +454,20 @@ usb_sts_type usbh_msc_read(void *uhost, uint32_t address, uint32_t len, uint8_t
|
||||
return USB_FAIL;
|
||||
}
|
||||
pmsc->bot_trans.msc_struct = &usbh_msc;
|
||||
pmsc->state = USBH_MSC_READ10;
|
||||
pmsc->l_unit_n[lun].state = USBH_MSC_READ10;
|
||||
pmsc->use_lun = lun;
|
||||
|
||||
timeout = puhost->timer;
|
||||
while(1)
|
||||
|
||||
while(usbh_msc_rw_handle(uhost, address, len, buffer, lun) == USB_WAIT)
|
||||
{
|
||||
if(puhost->conn_sts == 0 || (puhost->timer - timeout) > (len * 10000))
|
||||
{
|
||||
pmsc->l_unit_n[lun].state = USBH_MSC_IDLE;
|
||||
return USB_FAIL;
|
||||
}
|
||||
status = usbh_msc_bot_scsi_read(uhost, &pmsc->bot_trans, address, buffer, len, lun);
|
||||
if(status == USB_OK)
|
||||
{
|
||||
pmsc->l_unit_n[lun].state = USBH_MSC_IDLE;
|
||||
break;
|
||||
}
|
||||
else if(status == USB_FAIL)
|
||||
{
|
||||
pmsc->l_unit_n[lun].state = USBH_MSC_IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -437,7 +483,6 @@ usb_sts_type usbh_msc_write(void *uhost, uint32_t address, uint32_t len, uint8_t
|
||||
{
|
||||
usbh_core_type *puhost = (usbh_core_type *)uhost;
|
||||
usbh_msc_type *pmsc = (usbh_msc_type *)puhost->class_handler->pdata;
|
||||
usb_sts_type status;
|
||||
uint32_t timeout = 0;
|
||||
if(puhost->conn_sts == 0 || puhost->global_state != USBH_CLASS
|
||||
|| pmsc->l_unit_n[lun].state != USBH_MSC_IDLE)
|
||||
@@ -446,31 +491,19 @@ usb_sts_type usbh_msc_write(void *uhost, uint32_t address, uint32_t len, uint8_t
|
||||
}
|
||||
|
||||
pmsc->bot_trans.msc_struct = &usbh_msc;
|
||||
pmsc->state = USBH_MSC_WRITE;
|
||||
pmsc->l_unit_n[lun].state = USBH_MSC_WRITE;
|
||||
pmsc->use_lun = lun;
|
||||
|
||||
timeout = puhost->timer;
|
||||
while(1)
|
||||
while(usbh_msc_rw_handle(uhost, address, len, buffer, lun) == USB_WAIT)
|
||||
{
|
||||
if(puhost->conn_sts == 0 || (puhost->timer - timeout) > (len * 10000))
|
||||
{
|
||||
pmsc->l_unit_n[lun].state = USBH_MSC_IDLE;
|
||||
return USB_FAIL;
|
||||
}
|
||||
status = usbh_msc_bot_scsi_write(uhost, &pmsc->bot_trans, address, buffer, len, lun);
|
||||
if(status == USB_OK)
|
||||
{
|
||||
pmsc->l_unit_n[lun].state = USBH_MSC_IDLE;
|
||||
break;
|
||||
}
|
||||
else if(status == USB_FAIL)
|
||||
{
|
||||
pmsc->l_unit_n[lun].state = USBH_MSC_IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return USB_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file usbh_msc_class.h
|
||||
* @version v2.0.2
|
||||
* @date 2021-12-31
|
||||
* @version v2.0.3
|
||||
* @date 2022-02-11
|
||||
* @brief usb host msc class header file
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
@@ -87,34 +87,6 @@ typedef enum
|
||||
USBH_MSC_STATE_COMPLETE,
|
||||
}usbh_msc_ctrl_state_type;
|
||||
|
||||
///**
|
||||
// * @brief usb msc process state
|
||||
// */
|
||||
//typedef enum
|
||||
//{
|
||||
// USBH_MSC_INIT,
|
||||
// USBH_MSC_INQUIRY,
|
||||
// USBH_MSC_READ_CAPACITY10,
|
||||
// USBH_MSC_READ10,
|
||||
// USBH_MSC_BUSY,
|
||||
// USBH_MSC_ERROR,
|
||||
//}usbh_msc_state_type;
|
||||
|
||||
/**
|
||||
* @brief usb hid descriptor type
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t bcdHID;
|
||||
uint8_t bCountryCode;
|
||||
uint8_t bNumDescriptors;
|
||||
uint8_t bReportDescriptorType;
|
||||
uint16_t wItemLength;
|
||||
}usb_hid_desc_type;
|
||||
|
||||
|
||||
/**
|
||||
* @brief usb msc struct
|
||||
*/
|
||||
@@ -145,11 +117,12 @@ typedef struct
|
||||
uint8_t buffer[64];
|
||||
}usbh_msc_type;
|
||||
|
||||
extern usbh_class_handler_type uhost_class_handler;
|
||||
extern usbh_class_handler_type uhost_msc_class_handler;
|
||||
extern usbh_msc_type usbh_msc;
|
||||
msc_error_type usbh_msc_is_ready(void *uhost, uint8_t lun);
|
||||
usb_sts_type usbh_msc_write(void *uhost, uint32_t address, uint32_t len, uint8_t *buffer, uint8_t lun);
|
||||
usb_sts_type usbh_msc_read(void *uhost, uint32_t address, uint32_t len, uint8_t *buffer, uint8_t lun);
|
||||
usb_sts_type usbh_msc_rw_handle(void *uhost, uint32_t address, uint32_t len, uint8_t *buffer, uint8_t lun);
|
||||
usb_sts_type msc_bot_scsi_init(usbh_msc_type *msc_struct);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user