Commit 0ea73d2d authored by Damien George's avatar Damien George

stm32/usbdev: Simplify pointers to MSC state and block dev operations.

parent f8f17f48
......@@ -72,6 +72,9 @@ typedef struct {
uint32_t scsi_blk_addr_in_blks;
uint32_t scsi_blk_len;
// operations of the underlying block device
USBD_StorageTypeDef *bdev_ops;
} USBD_MSC_BOT_HandleTypeDef;
typedef enum {
......@@ -98,8 +101,6 @@ typedef struct _usbd_cdc_msc_hid_state_t {
uint8_t *hid_desc;
const uint8_t *hid_report_desc;
USBD_StorageTypeDef *MSC_fops;
USBD_CDC_HandleTypeDef CDC_ClassData;
USBD_MSC_BOT_HandleTypeDef MSC_BOT_ClassData;
USBD_HID_HandleTypeDef HID_ClassData;
......@@ -108,7 +109,6 @@ typedef struct _usbd_cdc_msc_hid_state_t {
__ALIGN_BEGIN uint8_t usbd_config_desc[MAX_TEMPLATE_CONFIG_DESC_SIZE] __ALIGN_END;
void *cdc;
void *msc;
void *hid;
} usbd_cdc_msc_hid_state_t;
......@@ -132,7 +132,9 @@ uint8_t USBD_GetMode(usbd_cdc_msc_hid_state_t *usbd);
uint8_t USBD_CDC_ReceivePacket(usbd_cdc_msc_hid_state_t *usbd, uint8_t *buf);
uint8_t USBD_CDC_TransmitPacket(usbd_cdc_msc_hid_state_t *usbd, size_t len, const uint8_t *buf);
uint8_t USBD_MSC_RegisterStorage(usbd_cdc_msc_hid_state_t *usbd, USBD_StorageTypeDef *fops);
static inline void USBD_MSC_RegisterStorage(usbd_cdc_msc_hid_state_t *usbd, USBD_StorageTypeDef *fops) {
usbd->MSC_BOT_ClassData.bdev_ops = fops;
}
uint8_t USBD_HID_ReceivePacket(usbd_cdc_msc_hid_state_t *usbd, uint8_t *buf);
int USBD_HID_CanSendReport(usbd_cdc_msc_hid_state_t *usbd);
......
......@@ -662,9 +662,6 @@ static uint8_t USBD_CDC_MSC_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
USBD_EP_TYPE_BULK,
MSC_MAX_PACKET);
// Set the MSC data for SCSI and BOT to reference it
usbd->msc = &usbd->MSC_BOT_ClassData;
// Init the BOT layer
MSC_BOT_Init(pdev);
}
......@@ -715,7 +712,7 @@ static uint8_t USBD_CDC_MSC_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
USBD_LL_CloseEP(pdev, CDC_CMD_EP);
}
if ((usbd->usbd_mode & USBD_MODE_MSC) && usbd->msc) {
if (usbd->usbd_mode & USBD_MODE_MSC) {
// MSC component
// close endpoints
......@@ -724,9 +721,6 @@ static uint8_t USBD_CDC_MSC_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
// DeInit the BOT layer
MSC_BOT_DeInit(pdev);
// clear the state pointer
usbd->msc = NULL;
}
if (usbd->usbd_mode & USBD_MODE_HID) {
......@@ -788,7 +782,7 @@ static uint8_t USBD_CDC_MSC_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTyp
switch (req->bRequest) {
case BOT_GET_MAX_LUN:
if ((req->wValue == 0) && (req->wLength == 1) && ((req->bmRequest & 0x80) == 0x80)) {
usbd->MSC_BOT_ClassData.max_lun = usbd->MSC_fops->GetMaxLun();
usbd->MSC_BOT_ClassData.max_lun = usbd->MSC_BOT_ClassData.bdev_ops->GetMaxLun();
USBD_CtlSendData(pdev, (uint8_t *)&usbd->MSC_BOT_ClassData.max_lun, 1);
} else {
USBD_CtlError(pdev, req);
......@@ -992,16 +986,6 @@ uint8_t USBD_CDC_ReceivePacket(usbd_cdc_msc_hid_state_t *usbd, uint8_t *buf) {
return USBD_OK;
}
uint8_t USBD_MSC_RegisterStorage(usbd_cdc_msc_hid_state_t *usbd, USBD_StorageTypeDef *fops) {
if (fops == NULL) {
return USBD_FAIL;
} else {
usbd->MSC_fops = fops;
usbd->pdev->pUserData = fops; // MSC uses pUserData because SCSI and BOT reference it
return USBD_OK;
}
}
// prepare OUT endpoint for reception
uint8_t USBD_HID_ReceivePacket(usbd_cdc_msc_hid_state_t *usbd, uint8_t *buf) {
// Suspend or Resume USB Out process
......
......@@ -104,7 +104,7 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev);
*/
void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
{
USBD_MSC_BOT_HandleTypeDef *hmsc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->msc;
USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->bot_state = USBD_BOT_IDLE;
hmsc->bot_status = USBD_BOT_STATUS_NORMAL;
......@@ -112,7 +112,7 @@ void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
hmsc->scsi_sense_tail = 0;
hmsc->scsi_sense_head = 0;
((USBD_StorageTypeDef *)pdev->pUserData)->Init(0);
hmsc->bdev_ops->Init(0);
USBD_LL_FlushEP(pdev, MSC_OUT_EP);
USBD_LL_FlushEP(pdev, MSC_IN_EP);
......@@ -132,7 +132,7 @@ void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
*/
void MSC_BOT_Reset (USBD_HandleTypeDef *pdev)
{
USBD_MSC_BOT_HandleTypeDef *hmsc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->msc;
USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->bot_state = USBD_BOT_IDLE;
hmsc->bot_status = USBD_BOT_STATUS_RECOVERY;
......@@ -152,7 +152,7 @@ void MSC_BOT_Reset (USBD_HandleTypeDef *pdev)
*/
void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev)
{
USBD_MSC_BOT_HandleTypeDef *hmsc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->msc;
USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->bot_state = USBD_BOT_IDLE;
}
......@@ -166,7 +166,7 @@ void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev)
void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev,
uint8_t epnum)
{
USBD_MSC_BOT_HandleTypeDef *hmsc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->msc;
USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
switch (hmsc->bot_state)
{
......@@ -199,7 +199,7 @@ void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev,
void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
uint8_t epnum)
{
USBD_MSC_BOT_HandleTypeDef *hmsc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->msc;
USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
switch (hmsc->bot_state)
{
......@@ -231,7 +231,7 @@ void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
*/
static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
{
USBD_MSC_BOT_HandleTypeDef *hmsc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->msc;
USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->csw.dTag = hmsc->cbw.dTag;
hmsc->csw.dDataResidue = hmsc->cbw.dDataLength;
......@@ -300,7 +300,7 @@ static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev,
uint8_t* buf,
uint16_t len)
{
USBD_MSC_BOT_HandleTypeDef *hmsc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->msc;
USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
len = MIN (hmsc->cbw.dDataLength, len);
hmsc->csw.dDataResidue -= len;
......@@ -320,7 +320,7 @@ static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev,
void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
uint8_t CSW_Status)
{
USBD_MSC_BOT_HandleTypeDef *hmsc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->msc;
USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
hmsc->csw.dSignature = USBD_BOT_CSW_SIGNATURE;
hmsc->csw.bStatus = CSW_Status;
......@@ -348,7 +348,7 @@ void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
static void MSC_BOT_Abort (USBD_HandleTypeDef *pdev)
{
USBD_MSC_BOT_HandleTypeDef *hmsc = ((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->msc;
USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
if ((hmsc->cbw.bmFlags == 0) &&
(hmsc->cbw.dDataLength != 0) &&
......@@ -377,7 +377,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_cdc_msc_hid_state_t*)pdev->pClassData)->msc;
USBD_MSC_BOT_HandleTypeDef *hmsc = &((usbd_cdc_msc_hid_state_t*)pdev->pClassData)->MSC_BOT_ClassData;
if(hmsc->bot_status == USBD_BOT_STATUS_ERROR )/* Bad CBW Signature */
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment