stmhal: Coding style cleanup in usbd_cdc_msc_hid.c.
This commit is contained in:
parent
55d6218b9a
commit
b157a99a8b
@ -51,32 +51,31 @@
|
|||||||
|
|
||||||
#define USB_DESC_TYPE_ASSOCIATION (0x0b)
|
#define USB_DESC_TYPE_ASSOCIATION (0x0b)
|
||||||
|
|
||||||
#define CDC_CMD_PACKET_SIZE 8 // Control Endpoint Packet size
|
#define CDC_CMD_PACKET_SIZE (8) // Control Endpoint Packet size
|
||||||
#define CDC_DATA_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
#define CDC_DATA_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||||
#define CDC_DATA_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
#define CDC_DATA_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||||
|
|
||||||
#define MSC_MAX_PACKET 0x40
|
#define MSC_MAX_PACKET (0x40)
|
||||||
#define USB_MSC_CONFIG_DESC_SIZ 32
|
#define BOT_GET_MAX_LUN (0xfe)
|
||||||
#define BOT_GET_MAX_LUN 0xFE
|
#define BOT_RESET (0xff)
|
||||||
#define BOT_RESET 0xFF
|
|
||||||
|
|
||||||
#define HID_DESCRIPTOR_TYPE 0x21
|
#define HID_DESCRIPTOR_TYPE (0x21)
|
||||||
#define HID_REPORT_DESC 0x22
|
#define HID_REPORT_DESC (0x22)
|
||||||
#define HID_REQ_SET_PROTOCOL 0x0B
|
#define HID_REQ_SET_PROTOCOL (0x0b)
|
||||||
#define HID_REQ_GET_PROTOCOL 0x03
|
#define HID_REQ_GET_PROTOCOL (0x03)
|
||||||
#define HID_REQ_SET_IDLE 0x0A
|
#define HID_REQ_SET_IDLE (0x0a)
|
||||||
#define HID_REQ_GET_IDLE 0x02
|
#define HID_REQ_GET_IDLE (0x02)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HID_IDLE = 0,
|
HID_IDLE = 0,
|
||||||
HID_BUSY,
|
HID_BUSY,
|
||||||
} HID_StateTypeDef;
|
} HID_StateTypeDef;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t Protocol;
|
uint32_t Protocol;
|
||||||
uint32_t IdleState;
|
uint32_t IdleState;
|
||||||
uint32_t AltSetting;
|
uint32_t AltSetting;
|
||||||
HID_StateTypeDef state;
|
HID_StateTypeDef state;
|
||||||
} USBD_HID_HandleTypeDef;
|
} USBD_HID_HandleTypeDef;
|
||||||
|
|
||||||
static uint8_t usbd_mode;
|
static uint8_t usbd_mode;
|
||||||
@ -784,17 +783,17 @@ static uint8_t USBD_CDC_MSC_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTyp
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case BOT_RESET:
|
case BOT_RESET:
|
||||||
if((req->wValue == 0) && (req->wLength == 0) && ((req->bmRequest & 0x80) != 0x80)) {
|
if ((req->wValue == 0) && (req->wLength == 0) && ((req->bmRequest & 0x80) != 0x80)) {
|
||||||
MSC_BOT_Reset(pdev);
|
MSC_BOT_Reset(pdev);
|
||||||
} else {
|
} else {
|
||||||
USBD_CtlError(pdev , req);
|
USBD_CtlError(pdev, req);
|
||||||
return USBD_FAIL;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError(pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
return USBD_FAIL;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
} else if ((usbd_mode & USBD_MODE_HID) && req->wIndex == hid_iface_num) {
|
} else if ((usbd_mode & USBD_MODE_HID) && req->wIndex == hid_iface_num) {
|
||||||
switch (req->bRequest) {
|
switch (req->bRequest) {
|
||||||
@ -834,46 +833,46 @@ static uint8_t USBD_CDC_MSC_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTyp
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_CLEAR_FEATURE:
|
case USB_REQ_CLEAR_FEATURE:
|
||||||
/* Flush the FIFO and Clear the stall status */
|
// Flush the FIFO and Clear the stall status
|
||||||
USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex);
|
USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex);
|
||||||
|
|
||||||
/* Re-activate the EP */
|
// Re-activate the EP
|
||||||
USBD_LL_CloseEP (pdev , (uint8_t)req->wIndex);
|
USBD_LL_CloseEP(pdev, (uint8_t)req->wIndex);
|
||||||
if((((uint8_t)req->wIndex) & 0x80) == 0x80) {
|
if((((uint8_t)req->wIndex) & 0x80) == 0x80) {
|
||||||
/* Open EP IN */
|
// Open EP IN
|
||||||
USBD_LL_OpenEP(pdev, MSC_IN_EP, USBD_EP_TYPE_BULK, MSC_MAX_PACKET);
|
USBD_LL_OpenEP(pdev, MSC_IN_EP, USBD_EP_TYPE_BULK, MSC_MAX_PACKET);
|
||||||
} else {
|
} else {
|
||||||
/* Open EP OUT */
|
// Open EP OUT
|
||||||
USBD_LL_OpenEP(pdev, MSC_OUT_EP, USBD_EP_TYPE_BULK, MSC_MAX_PACKET);
|
USBD_LL_OpenEP(pdev, MSC_OUT_EP, USBD_EP_TYPE_BULK, MSC_MAX_PACKET);
|
||||||
}
|
}
|
||||||
/* Handle BOT error */
|
// Handle BOT error
|
||||||
MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex);
|
MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if ((usbd_mode & USBD_MODE_HID) && req->wIndex == hid_iface_num) {
|
} else if ((usbd_mode & USBD_MODE_HID) && req->wIndex == hid_iface_num) {
|
||||||
switch (req->bRequest) {
|
switch (req->bRequest) {
|
||||||
case USB_REQ_GET_DESCRIPTOR: {
|
case USB_REQ_GET_DESCRIPTOR: {
|
||||||
uint16_t len = 0;
|
uint16_t len = 0;
|
||||||
const uint8_t *pbuf = NULL;
|
const uint8_t *pbuf = NULL;
|
||||||
if (req->wValue >> 8 == HID_REPORT_DESC) {
|
if (req->wValue >> 8 == HID_REPORT_DESC) {
|
||||||
len = hid_desc[HID_DESC_OFFSET_REPORT_DESC_LEN];
|
len = hid_desc[HID_DESC_OFFSET_REPORT_DESC_LEN];
|
||||||
len = MIN(len, req->wLength);
|
len = MIN(len, req->wLength);
|
||||||
pbuf = hid_report_desc;
|
pbuf = hid_report_desc;
|
||||||
} else if (req->wValue >> 8 == HID_DESCRIPTOR_TYPE) {
|
} else if (req->wValue >> 8 == HID_DESCRIPTOR_TYPE) {
|
||||||
len = MIN(HID_SUBDESC_LEN, req->wLength);
|
len = MIN(HID_SUBDESC_LEN, req->wLength);
|
||||||
pbuf = hid_desc + HID_DESC_OFFSET_SUBDESC;
|
pbuf = hid_desc + HID_DESC_OFFSET_SUBDESC;
|
||||||
}
|
}
|
||||||
USBD_CtlSendData(pdev, (uint8_t*)pbuf, len);
|
USBD_CtlSendData(pdev, (uint8_t*)pbuf, len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case USB_REQ_GET_INTERFACE:
|
case USB_REQ_GET_INTERFACE:
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)&HID_ClassData.AltSetting, 1);
|
USBD_CtlSendData (pdev, (uint8_t *)&HID_ClassData.AltSetting, 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_SET_INTERFACE:
|
case USB_REQ_SET_INTERFACE:
|
||||||
HID_ClassData.AltSetting = (uint8_t)(req->wValue);
|
HID_ClassData.AltSetting = (uint8_t)(req->wValue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -887,11 +886,12 @@ static uint8_t EP0_TxSent(USBD_HandleTypeDef *pdev) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static uint8_t USBD_CDC_MSC_HID_EP0_RxReady(USBD_HandleTypeDef *pdev) {
|
static uint8_t USBD_CDC_MSC_HID_EP0_RxReady(USBD_HandleTypeDef *pdev) {
|
||||||
if((CDC_fops != NULL) && (CDC_ClassData.CmdOpCode != 0xFF)) {
|
if ((CDC_fops != NULL) && (CDC_ClassData.CmdOpCode != 0xff)) {
|
||||||
CDC_fops->Control(CDC_ClassData.CmdOpCode, (uint8_t *)CDC_ClassData.data, CDC_ClassData.CmdLength);
|
CDC_fops->Control(CDC_ClassData.CmdOpCode, (uint8_t*)CDC_ClassData.data, CDC_ClassData.CmdLength);
|
||||||
CDC_ClassData.CmdOpCode = 0xFF;
|
CDC_ClassData.CmdOpCode = 0xff;
|
||||||
}
|
}
|
||||||
return USBD_OK;
|
|
||||||
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t USBD_CDC_MSC_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) {
|
static uint8_t USBD_CDC_MSC_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) {
|
||||||
@ -953,81 +953,40 @@ uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_CDC_ItfTypeDef
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint16_t length) {
|
||||||
* @brief USBD_CDC_SetTxBuffer
|
CDC_ClassData.TxBuffer = pbuff;
|
||||||
* @param pdev: device instance
|
CDC_ClassData.TxLength = length;
|
||||||
* @param pbuff: Tx Buffer
|
return USBD_OK;
|
||||||
* @retval status
|
|
||||||
*/
|
|
||||||
uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
|
||||||
uint8_t *pbuff,
|
|
||||||
uint16_t length)
|
|
||||||
{
|
|
||||||
CDC_ClassData.TxBuffer = pbuff;
|
|
||||||
CDC_ClassData.TxLength = length;
|
|
||||||
|
|
||||||
return USBD_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff) {
|
||||||
/**
|
CDC_ClassData.RxBuffer = pbuff;
|
||||||
* @brief USBD_CDC_SetRxBuffer
|
return USBD_OK;
|
||||||
* @param pdev: device instance
|
|
||||||
* @param pbuff: Rx Buffer
|
|
||||||
* @retval status
|
|
||||||
*/
|
|
||||||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
|
||||||
uint8_t *pbuff)
|
|
||||||
{
|
|
||||||
CDC_ClassData.RxBuffer = pbuff;
|
|
||||||
|
|
||||||
return USBD_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// data received on non-control OUT endpoint
|
||||||
* @brief USBD_CDC_DataOut
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev) {
|
||||||
* Data received on non-control Out endpoint
|
if (CDC_ClassData.TxState == 0) {
|
||||||
* @param pdev: device instance
|
// transmit next packet
|
||||||
* @param epnum: endpoint number
|
USBD_LL_Transmit(pdev, CDC_IN_EP, CDC_ClassData.TxBuffer, CDC_ClassData.TxLength);
|
||||||
* @retval status
|
|
||||||
*/
|
// Tx transfer in progress
|
||||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev) {
|
CDC_ClassData.TxState = 1;
|
||||||
if(CDC_ClassData.TxState == 0) {
|
return USBD_OK;
|
||||||
|
} else {
|
||||||
/* Transmit next packet */
|
return USBD_BUSY;
|
||||||
USBD_LL_Transmit(pdev,
|
|
||||||
CDC_IN_EP,
|
|
||||||
CDC_ClassData.TxBuffer,
|
|
||||||
CDC_ClassData.TxLength);
|
|
||||||
|
|
||||||
/* Tx Transfer in progress */
|
|
||||||
CDC_ClassData.TxState = 1;
|
|
||||||
return USBD_OK;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return USBD_BUSY;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prepare OUT endpoint for reception
|
||||||
/**
|
|
||||||
* @brief USBD_CDC_ReceivePacket
|
|
||||||
* prepare OUT Endpoint for reception
|
|
||||||
* @param pdev: device instance
|
|
||||||
* @retval status
|
|
||||||
*/
|
|
||||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev) {
|
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev) {
|
||||||
// Suspend or Resume USB Out process
|
// Suspend or Resume USB Out process
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH) {
|
if (pdev->dev_speed == USBD_SPEED_HIGH) {
|
||||||
return USBD_FAIL;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare Out endpoint to receive next packet */
|
// Prepare Out endpoint to receive next packet
|
||||||
USBD_LL_PrepareReceive(pdev,
|
USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, CDC_ClassData.RxBuffer, CDC_DATA_OUT_PACKET_SIZE);
|
||||||
CDC_OUT_EP,
|
|
||||||
CDC_ClassData.RxBuffer,
|
|
||||||
CDC_DATA_OUT_PACKET_SIZE);
|
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user