mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-12 19:10:32 +03:00
[G4][LIB] Modify USB Middleware library for addition of HID and MSC
MSC updates
This commit is contained in:
parent
a8b589de88
commit
7dfac1aaea
8 changed files with 120 additions and 130 deletions
|
@ -508,18 +508,18 @@ static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||
USBD_LL_OpenEP(pdev, CDC_CMD_EP, USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE);
|
||||
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 1U;
|
||||
|
||||
pdev->pClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef));
|
||||
pdev->pCDC_ClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef));
|
||||
|
||||
if(pdev->pClassData == NULL)
|
||||
if(pdev->pCDC_ClassData == NULL)
|
||||
{
|
||||
ret = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
hcdc = (USBD_CDC_HandleTypeDef*) pdev->pCDC_ClassData;
|
||||
|
||||
/* Init physical Interface components */
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init();
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pCDC_UserData)->Init();
|
||||
|
||||
/* Init Xfer states */
|
||||
hcdc->TxState = 0U;
|
||||
|
@ -567,11 +567,11 @@ static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
if(pdev->pClassData != NULL)
|
||||
if(pdev->pCDC_ClassData != NULL)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||
USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pCDC_UserData)->DeInit();
|
||||
USBD_free(pdev->pCDC_ClassData);
|
||||
pdev->pCDC_ClassData = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -587,7 +587,7 @@ static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pCDC_ClassData;
|
||||
uint8_t ifalt = 0U;
|
||||
uint16_t status_info = 0U;
|
||||
uint8_t ret = USBD_OK;
|
||||
|
@ -599,7 +599,7 @@ static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
|||
{
|
||||
if (req->bmRequest & 0x80U)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pCDC_UserData)->Control(req->bRequest,
|
||||
(uint8_t *)(void *)hcdc->data,
|
||||
req->wLength);
|
||||
|
||||
|
@ -615,7 +615,7 @@ static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
|||
}
|
||||
else
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pCDC_UserData)->Control(req->bRequest,
|
||||
(uint8_t *)(void *)req, 0U);
|
||||
}
|
||||
break;
|
||||
|
@ -680,10 +680,10 @@ static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
|||
*/
|
||||
static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)pdev->pCDC_ClassData;
|
||||
PCD_HandleTypeDef *hpcd = pdev->pData;
|
||||
|
||||
if(pdev->pClassData != NULL)
|
||||
if(pdev->pCDC_ClassData != NULL)
|
||||
{
|
||||
if((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U))
|
||||
{
|
||||
|
@ -714,16 +714,16 @@ static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||
*/
|
||||
static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pCDC_ClassData;
|
||||
|
||||
/* Get the received data length */
|
||||
hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum);
|
||||
|
||||
/* USB data will be immediately processed, this allow next USB traffic being
|
||||
NAKed till the end of the application Xfer */
|
||||
if(pdev->pClassData != NULL)
|
||||
if(pdev->pCDC_ClassData != NULL)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pCDC_UserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
@ -741,11 +741,11 @@ static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||
*/
|
||||
static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pCDC_ClassData;
|
||||
|
||||
if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
||||
if((pdev->pCDC_UserData != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode,
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pCDC_UserData)->Control(hcdc->CmdOpCode,
|
||||
(uint8_t *)(void *)hcdc->data,
|
||||
(uint16_t)hcdc->CmdLength);
|
||||
hcdc->CmdOpCode = 0xFFU;
|
||||
|
@ -818,7 +818,7 @@ uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
|||
|
||||
if(fops != NULL)
|
||||
{
|
||||
pdev->pUserData= fops;
|
||||
pdev->pCDC_UserData= fops;
|
||||
ret = USBD_OK;
|
||||
}
|
||||
|
||||
|
@ -835,7 +835,7 @@ uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
|||
uint8_t *pbuff,
|
||||
uint16_t length)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pCDC_ClassData;
|
||||
|
||||
hcdc->TxBuffer = pbuff;
|
||||
hcdc->TxLength = length;
|
||||
|
@ -853,7 +853,7 @@ uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
|||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pCDC_ClassData;
|
||||
|
||||
hcdc->RxBuffer = pbuff;
|
||||
|
||||
|
@ -868,9 +868,9 @@ uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
|||
*/
|
||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pCDC_ClassData;
|
||||
|
||||
if(pdev->pClassData != NULL)
|
||||
if(pdev->pCDC_ClassData != NULL)
|
||||
{
|
||||
if(hcdc->TxState == 0U)
|
||||
{
|
||||
|
@ -906,10 +906,10 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
|||
*/
|
||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pCDC_ClassData;
|
||||
|
||||
/* Suspend or Resume USB Out process */
|
||||
if(pdev->pClassData != NULL)
|
||||
if(pdev->pCDC_ClassData != NULL)
|
||||
{
|
||||
if(pdev->dev_speed == USBD_SPEED_HIGH )
|
||||
{
|
||||
|
|
|
@ -41,12 +41,12 @@
|
|||
/** @defgroup USBD_HID_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define HID_EPIN_ADDR 0x81U
|
||||
#define HID_EPIN_SIZE 0x04U
|
||||
#define HID_EPIN_ADDR 0x83U
|
||||
#define HID_EPIN_SIZE 0x08U
|
||||
|
||||
#define USB_HID_CONFIG_DESC_SIZ 34U
|
||||
#define USB_HID_DESC_SIZ 9U
|
||||
#define HID_MOUSE_REPORT_DESC_SIZE 74U
|
||||
#define HID_MOUSE_REPORT_DESC_SIZE 38U
|
||||
|
||||
#define HID_DESCRIPTOR_TYPE 0x21U
|
||||
#define HID_REPORT_DESC 0x22U
|
||||
|
|
|
@ -317,52 +317,26 @@ __ALIGN_BEGIN static uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_
|
|||
|
||||
__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END =
|
||||
{
|
||||
0x05, 0x01,
|
||||
0x09, 0x02,
|
||||
0xA1, 0x01,
|
||||
0x09, 0x01,
|
||||
|
||||
0xA1, 0x00,
|
||||
0x05, 0x09,
|
||||
0x19, 0x01,
|
||||
0x29, 0x03,
|
||||
|
||||
0x15, 0x00,
|
||||
0x25, 0x01,
|
||||
0x95, 0x03,
|
||||
0x75, 0x01,
|
||||
|
||||
0x81, 0x02,
|
||||
0x95, 0x01,
|
||||
0x75, 0x05,
|
||||
0x81, 0x01,
|
||||
|
||||
0x05, 0x01,
|
||||
0x09, 0x30,
|
||||
0x09, 0x31,
|
||||
0x09, 0x38,
|
||||
|
||||
0x15, 0x81,
|
||||
0x25, 0x7F,
|
||||
0x75, 0x08,
|
||||
0x95, 0x03,
|
||||
|
||||
0x81, 0x06,
|
||||
0xC0, 0x09,
|
||||
0x3c, 0x05,
|
||||
0xff, 0x09,
|
||||
|
||||
0x01, 0x15,
|
||||
0x00, 0x25,
|
||||
0x01, 0x75,
|
||||
0x01, 0x95,
|
||||
|
||||
0x02, 0xb1,
|
||||
0x22, 0x75,
|
||||
0x06, 0x95,
|
||||
0x01, 0xb1,
|
||||
|
||||
0x01, 0xc0
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x05, // USAGE (Game Pad)
|
||||
0xa1, 0x01, // COLLECTION (Application)
|
||||
0xa1, 0x00, // COLLECTION (Physical)
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x30, // USAGE (X)
|
||||
0x09, 0x31, // USAGE (Y)
|
||||
0x09, 0x32, // USAGE (Z)
|
||||
0x09, 0x33, // USAGE (Rx)
|
||||
0x09, 0x35, // USAGE (Rz)
|
||||
0x09, 0x34, // USAGE (Ry)
|
||||
0x09, 0x40, // USAGE (Vx)
|
||||
0x09, 0x38, // USAGE (Wheel)
|
||||
0x15, 0x81, // LOGICAL_MINIMUM (-127)
|
||||
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
0x95, 0x08, // REPORT_COUNT (8)
|
||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
0xc0, // END_COLLECTION
|
||||
0xc0 /* END_COLLECTION */
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -388,14 +362,14 @@ static uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||
USBD_LL_OpenEP(pdev, HID_EPIN_ADDR, USBD_EP_TYPE_INTR, HID_EPIN_SIZE);
|
||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||
|
||||
pdev->pClassData = USBD_malloc(sizeof (USBD_HID_HandleTypeDef));
|
||||
pdev->pHID_ClassData = USBD_malloc(sizeof (USBD_HID_HandleTypeDef));
|
||||
|
||||
if (pdev->pClassData == NULL)
|
||||
if (pdev->pHID_ClassData == NULL)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
((USBD_HID_HandleTypeDef *)pdev->pClassData)->state = HID_IDLE;
|
||||
((USBD_HID_HandleTypeDef *)pdev->pHID_ClassData)->state = HID_IDLE;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
@ -417,10 +391,10 @@ static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev,
|
|||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 0U;
|
||||
|
||||
/* FRee allocated memory */
|
||||
if(pdev->pClassData != NULL)
|
||||
if(pdev->pHID_ClassData != NULL)
|
||||
{
|
||||
USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
USBD_free(pdev->pHID_ClassData);
|
||||
pdev->pHID_ClassData = NULL;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
|
@ -436,7 +410,7 @@ static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev,
|
|||
static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef*) pdev->pHID_ClassData;
|
||||
uint16_t len = 0U;
|
||||
uint8_t *pbuf = NULL;
|
||||
uint16_t status_info = 0U;
|
||||
|
@ -555,7 +529,7 @@ uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev,
|
|||
uint8_t *report,
|
||||
uint16_t len)
|
||||
{
|
||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef*)pdev->pHID_ClassData;
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED )
|
||||
{
|
||||
|
@ -652,7 +626,7 @@ static uint8_t USBD_HID_DataIn (USBD_HandleTypeDef *pdev,
|
|||
|
||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
||||
be caused by a new transfer before the end of the previous transfer */
|
||||
((USBD_HID_HandleTypeDef *)pdev->pClassData)->state = HID_IDLE;
|
||||
((USBD_HID_HandleTypeDef *)pdev->pHID_ClassData)->state = HID_IDLE;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -317,9 +317,9 @@ uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET);
|
||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||
}
|
||||
pdev->pClassData = USBD_malloc(sizeof (USBD_MSC_BOT_HandleTypeDef));
|
||||
pdev->pMSC_ClassData = USBD_malloc(sizeof (USBD_MSC_BOT_HandleTypeDef));
|
||||
|
||||
if(pdev->pClassData == NULL)
|
||||
if(pdev->pMSC_ClassData == NULL)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
@ -354,10 +354,10 @@ uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev,
|
|||
MSC_BOT_DeInit(pdev);
|
||||
|
||||
/* Free MSC Class Resources */
|
||||
if(pdev->pClassData != NULL)
|
||||
if(pdev->pMSC_ClassData != NULL)
|
||||
{
|
||||
USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
USBD_free(pdev->pMSC_ClassData);
|
||||
pdev->pMSC_ClassData = NULL;
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
@ -370,7 +370,7 @@ uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev,
|
|||
*/
|
||||
uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pMSC_ClassData;
|
||||
uint8_t ret = USBD_OK;
|
||||
uint16_t status_info = 0U;
|
||||
|
||||
|
@ -385,7 +385,7 @@ uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||
if((req->wValue == 0U) && (req->wLength == 1U) &&
|
||||
((req->bmRequest & 0x80U) == 0x80U))
|
||||
{
|
||||
hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData)->GetMaxLun();
|
||||
hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pMSC_UserData)->GetMaxLun();
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hmsc->max_lun, 1U);
|
||||
}
|
||||
else
|
||||
|
@ -601,7 +601,7 @@ uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev,
|
|||
{
|
||||
if(fops != NULL)
|
||||
{
|
||||
pdev->pUserData = fops;
|
||||
pdev->pMSC_UserData = fops;
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev);
|
|||
*/
|
||||
void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
hmsc->bot_state = USBD_BOT_IDLE;
|
||||
hmsc->bot_status = USBD_BOT_STATUS_NORMAL;
|
||||
|
@ -109,7 +109,7 @@ void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
|
|||
hmsc->scsi_sense_tail = 0U;
|
||||
hmsc->scsi_sense_head = 0U;
|
||||
|
||||
((USBD_StorageTypeDef *)pdev->pUserData)->Init(0U);
|
||||
((USBD_StorageTypeDef *)pdev->pMSC_UserData)->Init(0U);
|
||||
|
||||
USBD_LL_FlushEP(pdev, MSC_EPOUT_ADDR);
|
||||
USBD_LL_FlushEP(pdev, MSC_EPIN_ADDR);
|
||||
|
@ -127,7 +127,7 @@ void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
|
|||
*/
|
||||
void MSC_BOT_Reset (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
hmsc->bot_state = USBD_BOT_IDLE;
|
||||
hmsc->bot_status = USBD_BOT_STATUS_RECOVERY;
|
||||
|
@ -145,7 +145,7 @@ void MSC_BOT_Reset (USBD_HandleTypeDef *pdev)
|
|||
*/
|
||||
void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
hmsc->bot_state = USBD_BOT_IDLE;
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev,
|
|||
{
|
||||
UNUSED(epnum);
|
||||
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
switch (hmsc->bot_state)
|
||||
{
|
||||
|
@ -196,7 +196,7 @@ void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
|
|||
{
|
||||
UNUSED(epnum);
|
||||
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
switch (hmsc->bot_state)
|
||||
{
|
||||
|
@ -228,7 +228,7 @@ void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
|
|||
*/
|
||||
static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
hmsc->csw.dTag = hmsc->cbw.dTag;
|
||||
hmsc->csw.dDataResidue = hmsc->cbw.dDataLength;
|
||||
|
@ -293,7 +293,7 @@ static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
|
|||
static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t* pbuf,
|
||||
uint16_t len)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
uint16_t length = (uint16_t)MIN(hmsc->cbw.dDataLength, len);
|
||||
|
||||
|
@ -314,7 +314,7 @@ static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t* pbuf,
|
|||
void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
|
||||
uint8_t CSW_Status)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
hmsc->csw.dSignature = USBD_BOT_CSW_SIGNATURE;
|
||||
hmsc->csw.bStatus = CSW_Status;
|
||||
|
@ -337,7 +337,7 @@ void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
|
|||
|
||||
static void MSC_BOT_Abort (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
if ((hmsc->cbw.bmFlags == 0U) &&
|
||||
(hmsc->cbw.dDataLength != 0U) &&
|
||||
|
@ -365,7 +365,7 @@ static void MSC_BOT_Abort (USBD_HandleTypeDef *pdev)
|
|||
|
||||
void MSC_BOT_CplClrFeature (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
if(hmsc->bot_status == USBD_BOT_STATUS_ERROR)/* Bad CBW Signature */
|
||||
{
|
||||
|
|
|
@ -182,7 +182,7 @@ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||
{
|
||||
UNUSED(params);
|
||||
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
/* case 9 : Hi > D0 */
|
||||
if (hmsc->cbw.dDataLength != 0U)
|
||||
|
@ -192,7 +192,7 @@ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||
return -1;
|
||||
}
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
if(((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsReady(lun) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
hmsc->bot_state = USBD_BOT_NO_DATA;
|
||||
|
@ -215,7 +215,7 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *par
|
|||
{
|
||||
uint8_t* pPage;
|
||||
uint16_t len;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
if (params[1] & 0x01U)/*Evpd is set*/
|
||||
{
|
||||
|
@ -230,7 +230,7 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *par
|
|||
}
|
||||
else
|
||||
{
|
||||
pPage = (uint8_t *)(void *)&((USBD_StorageTypeDef *)pdev->pUserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN];
|
||||
pPage = (uint8_t *)(void *)&((USBD_StorageTypeDef *)pdev->pMSC_UserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN];
|
||||
len = (uint16_t)pPage[4] + 5U;
|
||||
|
||||
if (params[4] <= len)
|
||||
|
@ -260,9 +260,9 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_
|
|||
{
|
||||
UNUSED(params);
|
||||
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size) != 0)
|
||||
if(((USBD_StorageTypeDef *)pdev->pMSC_UserData)->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
return -1;
|
||||
|
@ -295,7 +295,7 @@ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, ui
|
|||
{
|
||||
UNUSED(params);
|
||||
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
uint16_t blk_size;
|
||||
uint32_t blk_nbr;
|
||||
|
@ -306,7 +306,7 @@ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, ui
|
|||
hmsc->bot_data[i] = 0U;
|
||||
}
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &blk_nbr, &blk_size) != 0U)
|
||||
if(((USBD_StorageTypeDef *)pdev->pMSC_UserData)->GetCapacity(lun, &blk_nbr, &blk_size) != 0U)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
return -1;
|
||||
|
@ -340,7 +340,7 @@ static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *
|
|||
UNUSED(lun);
|
||||
UNUSED(params);
|
||||
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
uint16_t len = 8U;
|
||||
hmsc->bot_data_length = len;
|
||||
|
||||
|
@ -349,6 +349,12 @@ static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *
|
|||
len--;
|
||||
hmsc->bot_data[len] = MSC_Mode_Sense6_data[len];
|
||||
}
|
||||
|
||||
// set bit 7 of the device configuration byte to indicate write protection
|
||||
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
|
||||
hmsc->bot_data[2] = hmsc->bot_data[2] | (1 << 7);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -365,7 +371,7 @@ static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||
UNUSED(params);
|
||||
|
||||
uint16_t len = 8U;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
hmsc->bot_data_length = len;
|
||||
|
||||
|
@ -375,6 +381,11 @@ static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||
hmsc->bot_data[len] = MSC_Mode_Sense10_data[len];
|
||||
}
|
||||
|
||||
// set bit 7 of the device configuration byte to indicate write protection
|
||||
if (((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0) {
|
||||
hmsc->bot_data[3] = hmsc->bot_data[3] | (1 << 7);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -391,7 +402,7 @@ static int8_t SCSI_RequestSense (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||
UNUSED(lun);
|
||||
|
||||
uint8_t i;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
for(i = 0U ;i < REQUEST_SENSE_DATA_LEN; i++)
|
||||
{
|
||||
|
@ -435,7 +446,7 @@ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_
|
|||
{
|
||||
UNUSED(lun);
|
||||
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
|
||||
hmsc->scsi_sense[hmsc->scsi_sense_tail].Skey = sKey;
|
||||
hmsc->scsi_sense[hmsc->scsi_sense_tail].w.ASC = ASC << 8;
|
||||
|
@ -457,7 +468,7 @@ static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||
UNUSED(lun);
|
||||
UNUSED(params);
|
||||
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pMSC_ClassData;
|
||||
hmsc->bot_data_length = 0U;
|
||||
return 0;
|
||||
}
|
||||
|
@ -471,7 +482,7 @@ static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||
*/
|
||||
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pMSC_ClassData;
|
||||
|
||||
if(hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
|
||||
{
|
||||
|
@ -482,7 +493,7 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
|||
return -1;
|
||||
}
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
if(((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsReady(lun) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
return -1;
|
||||
|
@ -525,7 +536,7 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
|||
|
||||
static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pMSC_ClassData;
|
||||
uint32_t len;
|
||||
|
||||
if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
|
||||
|
@ -538,14 +549,14 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
|||
}
|
||||
|
||||
/* Check whether Media is ready */
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
if(((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsReady(lun) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check If media is write-protected */
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->IsWriteProtected(lun) != 0)
|
||||
if(((USBD_StorageTypeDef *)pdev->pMSC_UserData)->IsWriteProtected(lun) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED);
|
||||
return -1;
|
||||
|
@ -599,7 +610,7 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
|||
|
||||
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pMSC_ClassData;
|
||||
|
||||
if ((params[1]& 0x02U) == 0x02U)
|
||||
{
|
||||
|
@ -627,7 +638,7 @@ static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
|||
static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||
uint32_t blk_offset, uint32_t blk_nbr)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pMSC_ClassData;
|
||||
|
||||
if ((blk_offset + blk_nbr) > hmsc->scsi_blk_nbr)
|
||||
{
|
||||
|
@ -645,12 +656,12 @@ static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun,
|
|||
*/
|
||||
static int8_t SCSI_ProcessRead (USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pMSC_ClassData;
|
||||
uint32_t len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
||||
|
||||
len = MIN(len, MSC_MEDIA_PACKET);
|
||||
|
||||
if( ((USBD_StorageTypeDef *)pdev->pUserData)->Read(lun,
|
||||
if( ((USBD_StorageTypeDef *)pdev->pMSC_UserData)->Read(lun,
|
||||
hmsc->bot_data,
|
||||
hmsc->scsi_blk_addr,
|
||||
(len / hmsc->scsi_blk_size)) < 0)
|
||||
|
@ -683,12 +694,12 @@ static int8_t SCSI_ProcessRead (USBD_HandleTypeDef *pdev, uint8_t lun)
|
|||
|
||||
static int8_t SCSI_ProcessWrite (USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pMSC_ClassData;
|
||||
uint32_t len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
||||
|
||||
len = MIN(len, MSC_MEDIA_PACKET);
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->Write(lun, hmsc->bot_data,
|
||||
if(((USBD_StorageTypeDef *)pdev->pMSC_UserData)->Write(lun, hmsc->bot_data,
|
||||
hmsc->scsi_blk_addr,
|
||||
(len / hmsc->scsi_blk_size)) < 0)
|
||||
{
|
||||
|
|
|
@ -255,8 +255,13 @@ typedef struct _USBD_HandleTypeDef
|
|||
USBD_SetupReqTypedef request;
|
||||
USBD_DescriptorsTypeDef *pDesc;
|
||||
USBD_ClassTypeDef *pClass;
|
||||
void *pClassData;
|
||||
void *pUserData;
|
||||
//WARNING: When updating this middleware add this to structure:
|
||||
void *pCDC_ClassData;
|
||||
void *pCDC_UserData;
|
||||
void *pHID_ClassData;
|
||||
void *pHID_UserData;
|
||||
void *pMSC_ClassData;
|
||||
void *pMSC_UserData;
|
||||
void *pData;
|
||||
} USBD_HandleTypeDef;
|
||||
|
||||
|
|
|
@ -456,7 +456,7 @@ USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
|
|||
pdev->dev_config= 0U;
|
||||
pdev->dev_remote_wakeup = 0U;
|
||||
|
||||
if (pdev->pClassData)
|
||||
if (pdev->pMSC_ClassData || pdev->pCDC_ClassData || pdev->pHID_ClassData)
|
||||
{
|
||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue