diff --git a/CI/astyle/.astyleignore b/CI/astyle/.astyleignore index da445e4400..a9d01db5ac 100644 --- a/CI/astyle/.astyleignore +++ b/CI/astyle/.astyleignore @@ -1,4 +1,5 @@ .git BUILD CI -system +system/Drivers +system/STM32* diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc/usbd_audio.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc/usbd_audio.h index aa29ce48a6..37a5c4a089 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc/usbd_audio.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc/usbd_audio.h @@ -22,7 +22,7 @@ #define __USB_AUDIO_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -101,17 +101,15 @@ /* Total size of the audio transfer buffer */ #define AUDIO_TOTAL_BUF_SIZE ((uint16_t)(AUDIO_OUT_PACKET * AUDIO_OUT_PACKET_NUM)) - /* Audio Commands enumeration */ -typedef enum -{ +/* Audio Commands enumeration */ +typedef enum { AUDIO_CMD_START = 1, AUDIO_CMD_PLAY, AUDIO_CMD_STOP, -}AUDIO_CMD_TypeDef; +} AUDIO_CMD_TypeDef; -typedef enum -{ +typedef enum { AUDIO_OFFSET_NONE = 0, AUDIO_OFFSET_HALF, AUDIO_OFFSET_FULL, @@ -126,19 +124,17 @@ AUDIO_OffsetTypeDef; /** @defgroup USBD_CORE_Exported_TypesDefinitions * @{ */ - typedef struct -{ - uint8_t cmd; - uint8_t data[USB_MAX_EP0_SIZE]; - uint8_t len; - uint8_t unit; +typedef struct { + uint8_t cmd; + uint8_t data[USB_MAX_EP0_SIZE]; + uint8_t len; + uint8_t unit; } USBD_AUDIO_ControlTypeDef; -typedef struct -{ +typedef struct { uint32_t alt_setting; uint8_t buffer[AUDIO_TOTAL_BUF_SIZE]; AUDIO_OffsetTypeDef offset; @@ -150,16 +146,15 @@ typedef struct USBD_AUDIO_HandleTypeDef; -typedef struct -{ - int8_t (*Init) (uint32_t AudioFreq, uint32_t Volume, uint32_t options); - int8_t (*DeInit) (uint32_t options); - int8_t (*AudioCmd) (uint8_t* pbuf, uint32_t size, uint8_t cmd); - int8_t (*VolumeCtl) (uint8_t vol); - int8_t (*MuteCtl) (uint8_t cmd); - int8_t (*PeriodicTC) (uint8_t cmd); - int8_t (*GetState) (void); -}USBD_AUDIO_ItfTypeDef; +typedef struct { + int8_t (*Init)(uint32_t AudioFreq, uint32_t Volume, uint32_t options); + int8_t (*DeInit)(uint32_t options); + int8_t (*AudioCmd)(uint8_t *pbuf, uint32_t size, uint8_t cmd); + int8_t (*VolumeCtl)(uint8_t vol); + int8_t (*MuteCtl)(uint8_t cmd); + int8_t (*PeriodicTC)(uint8_t cmd); + int8_t (*GetState)(void); +} USBD_AUDIO_ItfTypeDef; /** * @} */ @@ -187,10 +182,10 @@ extern USBD_ClassTypeDef USBD_AUDIO; /** @defgroup USB_CORE_Exported_Functions * @{ */ -uint8_t USBD_AUDIO_RegisterInterface (USBD_HandleTypeDef *pdev, - USBD_AUDIO_ItfTypeDef *fops); +uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev, + USBD_AUDIO_ItfTypeDef *fops); -void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset); +void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset); /** * @} */ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc/usbd_audio_if_template.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc/usbd_audio_if_template.h index 8437087aa3..80942a1cc1 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc/usbd_audio_if_template.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc/usbd_audio_if_template.h @@ -22,7 +22,7 @@ #define __USBD_AUDIO_IF_TEMPLATE_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src/usbd_audio.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src/usbd_audio.c index 8e2b4360e9..b7e12579c8 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src/usbd_audio.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src/usbd_audio.c @@ -53,11 +53,11 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}_audio.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}_audio.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_audio.h" @@ -110,32 +110,32 @@ */ -static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +static uint8_t USBD_AUDIO_Init(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +static uint8_t USBD_AUDIO_DeInit(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev, - USBD_SetupReqTypedef *req); +static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req); -static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length); +static uint8_t *USBD_AUDIO_GetCfgDesc(uint16_t *length); -static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc (uint16_t *length); +static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(uint16_t *length); -static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_AUDIO_EP0_RxReady (USBD_HandleTypeDef *pdev); +static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev); -static uint8_t USBD_AUDIO_EP0_TxReady (USBD_HandleTypeDef *pdev); +static uint8_t USBD_AUDIO_EP0_TxReady(USBD_HandleTypeDef *pdev); -static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev); +static uint8_t USBD_AUDIO_SOF(USBD_HandleTypeDef *pdev); -static uint8_t USBD_AUDIO_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_AUDIO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_AUDIO_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); @@ -149,8 +149,7 @@ static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef * @{ */ -USBD_ClassTypeDef USBD_AUDIO = -{ +USBD_ClassTypeDef USBD_AUDIO = { USBD_AUDIO_Init, USBD_AUDIO_DeInit, USBD_AUDIO_Setup, @@ -168,8 +167,7 @@ USBD_ClassTypeDef USBD_AUDIO = }; /* USB AUDIO device Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALIGN_END = { /* Configuration 1 */ 0x09, /* bLength */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType */ @@ -316,8 +314,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI } ; /* USB Standard Device Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_AUDIO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END= -{ +__ALIGN_BEGIN static uint8_t USBD_AUDIO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = { USB_LEN_DEV_QUALIFIER_DESC, USB_DESC_TYPE_DEVICE_QUALIFIER, 0x00, @@ -345,7 +342,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIE * @param cfgidx: Configuration index * @retval status */ -static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) +static uint8_t USBD_AUDIO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) { USBD_AUDIO_HandleTypeDef *haudio; @@ -354,15 +351,12 @@ static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 1U; /* Allocate Audio structure */ - pdev->pClassData = USBD_malloc(sizeof (USBD_AUDIO_HandleTypeDef)); + pdev->pClassData = USBD_malloc(sizeof(USBD_AUDIO_HandleTypeDef)); - if(pdev->pClassData == NULL) - { + if (pdev->pClassData == NULL) { return USBD_FAIL; - } - else - { - haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData; + } else { + haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData; haudio->alt_setting = 0U; haudio->offset = AUDIO_OFFSET_UNKNOWN; haudio->wr_ptr = 0U; @@ -372,8 +366,7 @@ static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) /* Initialize the Audio output Hardware layer */ if (((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->Init(USBD_AUDIO_FREQ, AUDIO_DEFAULT_VOLUME, - 0U) != 0) - { + 0U) != 0) { return USBD_FAIL; } @@ -391,8 +384,8 @@ static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) * @param cfgidx: Configuration index * @retval status */ -static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev, - uint8_t cfgidx) +static uint8_t USBD_AUDIO_DeInit(USBD_HandleTypeDef *pdev, + uint8_t cfgidx) { /* Open EP OUT */ @@ -400,9 +393,8 @@ static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev, pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 0U; /* DeInit physical Interface components */ - if(pdev->pClassData != NULL) - { - ((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->DeInit(0U); + if (pdev->pClassData != NULL) { + ((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->DeInit(0U); USBD_free(pdev->pClassData); pdev->pClassData = NULL; } @@ -417,8 +409,8 @@ static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev, * @param req: usb requests * @retval status */ -static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev, - USBD_SetupReqTypedef *req) +static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req) { USBD_AUDIO_HandleTypeDef *haudio; uint16_t len; @@ -426,96 +418,80 @@ static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev, uint16_t status_info = 0U; uint8_t ret = USBD_OK; - haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData; + haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData; - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS : - switch (req->bRequest) - { - case AUDIO_REQ_GET_CUR: - AUDIO_REQ_GetCurrent(pdev, req); - break; + switch (req->bmRequest & USB_REQ_TYPE_MASK) { + case USB_REQ_TYPE_CLASS : + switch (req->bRequest) { + case AUDIO_REQ_GET_CUR: + AUDIO_REQ_GetCurrent(pdev, req); + break; - case AUDIO_REQ_SET_CUR: - AUDIO_REQ_SetCurrent(pdev, req); - break; + case AUDIO_REQ_SET_CUR: + AUDIO_REQ_SetCurrent(pdev, req); + break; - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; - } - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; } break; - case USB_REQ_GET_DESCRIPTOR: - if( (req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE) - { - pbuf = USBD_AUDIO_CfgDesc + 18; - len = MIN(USB_AUDIO_DESC_SIZ , req->wLength); - - USBD_CtlSendData (pdev, pbuf, len); + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_GET_DESCRIPTOR: + if ((req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE) { + pbuf = USBD_AUDIO_CfgDesc + 18; + len = MIN(USB_AUDIO_DESC_SIZ, req->wLength); + + USBD_CtlSendData(pdev, pbuf, len); + } + break; + + case USB_REQ_GET_INTERFACE : + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlSendData(pdev, (uint8_t *)(void *)&haudio->alt_setting, 1U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE : + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + if ((uint8_t)(req->wValue) <= USBD_MAX_NUM_INTERFACES) { + haudio->alt_setting = (uint8_t)(req->wValue); + } else { + /* Call the error management function (command will be nacked */ + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; } break; - - case USB_REQ_GET_INTERFACE : - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlSendData (pdev, (uint8_t *)(void *)&haudio->alt_setting, 1U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_SET_INTERFACE : - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if ((uint8_t)(req->wValue) <= USBD_MAX_NUM_INTERFACES) - { - haudio->alt_setting = (uint8_t)(req->wValue); - } - else - { - /* Call the error management function (command will be nacked */ - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - } - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - } - break; - default: - USBD_CtlError (pdev, req); + USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; } return ret; @@ -529,9 +505,9 @@ static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev, * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length) +static uint8_t *USBD_AUDIO_GetCfgDesc(uint16_t *length) { - *length = sizeof (USBD_AUDIO_CfgDesc); + *length = sizeof(USBD_AUDIO_CfgDesc); return USBD_AUDIO_CfgDesc; } @@ -542,8 +518,8 @@ static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length) * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev, - uint8_t epnum) +static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, + uint8_t epnum) { /* Only OUT data are processed */ @@ -556,17 +532,16 @@ static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev, * @param pdev: device instance * @retval status */ -static uint8_t USBD_AUDIO_EP0_RxReady (USBD_HandleTypeDef *pdev) +static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev) { USBD_AUDIO_HandleTypeDef *haudio; - haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData; + haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData; - if (haudio->control.cmd == AUDIO_REQ_SET_CUR) - {/* In this driver, to simplify code, only SET_CUR request is managed */ + if (haudio->control.cmd == AUDIO_REQ_SET_CUR) { + /* In this driver, to simplify code, only SET_CUR request is managed */ - if (haudio->control.unit == AUDIO_OUT_STREAMING_CTRL) - { - ((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->MuteCtl(haudio->control.data[0]); + if (haudio->control.unit == AUDIO_OUT_STREAMING_CTRL) { + ((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->MuteCtl(haudio->control.data[0]); haudio->control.cmd = 0U; haudio->control.len = 0U; } @@ -580,7 +555,7 @@ static uint8_t USBD_AUDIO_EP0_RxReady (USBD_HandleTypeDef *pdev) * @param pdev: device instance * @retval status */ -static uint8_t USBD_AUDIO_EP0_TxReady (USBD_HandleTypeDef *pdev) +static uint8_t USBD_AUDIO_EP0_TxReady(USBD_HandleTypeDef *pdev) { /* Only OUT control data are processed */ return USBD_OK; @@ -591,7 +566,7 @@ static uint8_t USBD_AUDIO_EP0_TxReady (USBD_HandleTypeDef *pdev) * @param pdev: device instance * @retval status */ -static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev) +static uint8_t USBD_AUDIO_SOF(USBD_HandleTypeDef *pdev) { return USBD_OK; } @@ -602,60 +577,46 @@ static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev) * @param pdev: device instance * @retval status */ -void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset) +void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset) { uint32_t cmd = 0U; USBD_AUDIO_HandleTypeDef *haudio; - haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData; + haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData; haudio->offset = offset; - if(haudio->rd_enable == 1U) - { + if (haudio->rd_enable == 1U) { haudio->rd_ptr += (uint16_t)(AUDIO_TOTAL_BUF_SIZE / 2U); - if (haudio->rd_ptr == AUDIO_TOTAL_BUF_SIZE) - { + if (haudio->rd_ptr == AUDIO_TOTAL_BUF_SIZE) { /* roll back */ haudio->rd_ptr = 0U; } } - if(haudio->rd_ptr > haudio->wr_ptr) - { - if((haudio->rd_ptr - haudio->wr_ptr) < AUDIO_OUT_PACKET) - { + if (haudio->rd_ptr > haudio->wr_ptr) { + if ((haudio->rd_ptr - haudio->wr_ptr) < AUDIO_OUT_PACKET) { cmd = AUDIO_TOTAL_BUF_SIZE / 2U + 4U; - } - else - { - if((haudio->rd_ptr - haudio->wr_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET)) - { + } else { + if ((haudio->rd_ptr - haudio->wr_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET)) { cmd = AUDIO_TOTAL_BUF_SIZE / 2U - 4U; } } - } - else - { - if((haudio->wr_ptr - haudio->rd_ptr) < AUDIO_OUT_PACKET) - { + } else { + if ((haudio->wr_ptr - haudio->rd_ptr) < AUDIO_OUT_PACKET) { cmd = AUDIO_TOTAL_BUF_SIZE / 2U - 4U; - } - else - { - if((haudio->wr_ptr - haudio->rd_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET)) - { + } else { + if ((haudio->wr_ptr - haudio->rd_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET)) { cmd = AUDIO_TOTAL_BUF_SIZE / 2U + 4U; } } } - if(haudio->offset == AUDIO_OFFSET_FULL) - { + if (haudio->offset == AUDIO_OFFSET_FULL) { ((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0], cmd, AUDIO_CMD_PLAY); - haudio->offset = AUDIO_OFFSET_NONE; + haudio->offset = AUDIO_OFFSET_NONE; } } @@ -666,7 +627,7 @@ void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset) * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_AUDIO_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum) +static uint8_t USBD_AUDIO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) { return USBD_OK; @@ -678,7 +639,7 @@ static uint8_t USBD_AUDIO_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t ep * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_AUDIO_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum) +static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) { return USBD_OK; @@ -690,36 +651,31 @@ static uint8_t USBD_AUDIO_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t e * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev, - uint8_t epnum) +static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, + uint8_t epnum) { USBD_AUDIO_HandleTypeDef *haudio; - haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData; + haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData; - if (epnum == AUDIO_OUT_EP) - { + if (epnum == AUDIO_OUT_EP) { /* Increment the Buffer pointer or roll it back when all buffers are full */ haudio->wr_ptr += AUDIO_OUT_PACKET; - if (haudio->wr_ptr == AUDIO_TOTAL_BUF_SIZE) - { + if (haudio->wr_ptr == AUDIO_TOTAL_BUF_SIZE) { /* All buffers are full: roll back */ haudio->wr_ptr = 0U; - if(haudio->offset == AUDIO_OFFSET_UNKNOWN) - { + if (haudio->offset == AUDIO_OFFSET_UNKNOWN) { ((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0], AUDIO_TOTAL_BUF_SIZE / 2U, AUDIO_CMD_START); - haudio->offset = AUDIO_OFFSET_NONE; + haudio->offset = AUDIO_OFFSET_NONE; } } - if(haudio->rd_enable == 0U) - { - if (haudio->wr_ptr == (AUDIO_TOTAL_BUF_SIZE / 2U)) - { + if (haudio->rd_enable == 0U) { + if (haudio->wr_ptr == (AUDIO_TOTAL_BUF_SIZE / 2U)) { haudio->rd_enable = 1U; } } @@ -742,12 +698,12 @@ static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev, static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { USBD_AUDIO_HandleTypeDef *haudio; - haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData; + haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData; memset(haudio->control.data, 0, 64U); /* Send the current mute state */ - USBD_CtlSendData (pdev, haudio->control.data, req->wLength); + USBD_CtlSendData(pdev, haudio->control.data, req->wLength); } /** @@ -760,14 +716,13 @@ static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { USBD_AUDIO_HandleTypeDef *haudio; - haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData; + haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData; - if (req->wLength) - { + if (req->wLength) { /* Prepare the reception of the buffer over EP0 */ - USBD_CtlPrepareRx (pdev, - haudio->control.data, - req->wLength); + USBD_CtlPrepareRx(pdev, + haudio->control.data, + req->wLength); haudio->control.cmd = AUDIO_REQ_SET_CUR; /* Set the request value */ haudio->control.len = (uint8_t)req->wLength; /* Set the request data length */ @@ -782,9 +737,9 @@ static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc (uint16_t *length) +static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(uint16_t *length) { - *length = sizeof (USBD_AUDIO_DeviceQualifierDesc); + *length = sizeof(USBD_AUDIO_DeviceQualifierDesc); return USBD_AUDIO_DeviceQualifierDesc; } @@ -793,12 +748,11 @@ static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc (uint16_t *length) * @param fops: Audio interface callback * @retval status */ -uint8_t USBD_AUDIO_RegisterInterface (USBD_HandleTypeDef *pdev, - USBD_AUDIO_ItfTypeDef *fops) +uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev, + USBD_AUDIO_ItfTypeDef *fops) { - if(fops != NULL) - { - pdev->pUserData= fops; + if (fops != NULL) { + pdev->pUserData = fops; } return USBD_OK; } diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src/usbd_audio_if_template.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src/usbd_audio_if_template.c index 24ef04b7c0..cac18958c4 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src/usbd_audio_if_template.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Src/usbd_audio_if_template.c @@ -17,11 +17,11 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}_audio.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}_audio.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_audio_if_template.h" @@ -65,16 +65,15 @@ * @{ */ -static int8_t TEMPLATE_Init (uint32_t AudioFreq, uint32_t Volume, uint32_t options); -static int8_t TEMPLATE_DeInit (uint32_t options); -static int8_t TEMPLATE_AudioCmd (uint8_t* pbuf, uint32_t size, uint8_t cmd); -static int8_t TEMPLATE_VolumeCtl (uint8_t vol); -static int8_t TEMPLATE_MuteCtl (uint8_t cmd); -static int8_t TEMPLATE_PeriodicTC (uint8_t cmd); -static int8_t TEMPLATE_GetState (void); +static int8_t TEMPLATE_Init(uint32_t AudioFreq, uint32_t Volume, uint32_t options); +static int8_t TEMPLATE_DeInit(uint32_t options); +static int8_t TEMPLATE_AudioCmd(uint8_t *pbuf, uint32_t size, uint8_t cmd); +static int8_t TEMPLATE_VolumeCtl(uint8_t vol); +static int8_t TEMPLATE_MuteCtl(uint8_t cmd); +static int8_t TEMPLATE_PeriodicTC(uint8_t cmd); +static int8_t TEMPLATE_GetState(void); -USBD_AUDIO_ItfTypeDef USBD_AUDIO_Template_fops = -{ +USBD_AUDIO_ItfTypeDef USBD_AUDIO_Template_fops = { TEMPLATE_Init, TEMPLATE_DeInit, TEMPLATE_AudioCmd, @@ -123,7 +122,7 @@ static int8_t TEMPLATE_DeInit(uint32_t options) * @param cmd: command opcode * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL */ -static int8_t TEMPLATE_AudioCmd (uint8_t* pbuf, uint32_t size, uint8_t cmd) +static int8_t TEMPLATE_AudioCmd(uint8_t *pbuf, uint32_t size, uint8_t cmd) { return (0); @@ -134,7 +133,7 @@ static int8_t TEMPLATE_AudioCmd (uint8_t* pbuf, uint32_t size, uint8_t cmd) * @param vol: volume level (0..100) * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL */ -static int8_t TEMPLATE_VolumeCtl (uint8_t vol) +static int8_t TEMPLATE_VolumeCtl(uint8_t vol) { return (0); @@ -145,7 +144,7 @@ static int8_t TEMPLATE_VolumeCtl (uint8_t vol) * @param cmd: vmute command * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL */ -static int8_t TEMPLATE_MuteCtl (uint8_t cmd) +static int8_t TEMPLATE_MuteCtl(uint8_t cmd) { return (0); @@ -156,7 +155,7 @@ static int8_t TEMPLATE_MuteCtl (uint8_t cmd) * @param cmd * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL */ -static int8_t TEMPLATE_PeriodicTC (uint8_t cmd) +static int8_t TEMPLATE_PeriodicTC(uint8_t cmd) { return (0); @@ -167,7 +166,7 @@ static int8_t TEMPLATE_PeriodicTC (uint8_t cmd) * @param None * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL */ -static int8_t TEMPLATE_GetState (void) +static int8_t TEMPLATE_GetState(void) { return (0); diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc.h index 1cddfeaf8b..059451722c 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc.h @@ -22,7 +22,7 @@ #define __USB_CDC_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -46,11 +46,11 @@ #define CDC_CMD_EP 0x82U /* EP2 for CDC commands */ #ifndef CDC_HS_BINTERVAL - #define CDC_HS_BINTERVAL 0x10U +#define CDC_HS_BINTERVAL 0x10U #endif /* CDC_HS_BINTERVAL */ #ifndef CDC_FS_BINTERVAL - #define CDC_FS_BINTERVAL 0x10U +#define CDC_FS_BINTERVAL 0x10U #endif /* CDC_FS_BINTERVAL */ /* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */ @@ -90,26 +90,23 @@ /** * @} */ -typedef struct -{ +typedef struct { uint32_t bitrate; uint8_t format; uint8_t paritytype; uint8_t datatype; -}USBD_CDC_LineCodingTypeDef; +} USBD_CDC_LineCodingTypeDef; -typedef struct _USBD_CDC_Itf -{ - int8_t (* Init) (void); - int8_t (* DeInit) (void); - int8_t (* Control) (uint8_t cmd, uint8_t* pbuf, uint16_t length); - int8_t (* Receive) (uint8_t* Buf, uint32_t *Len); +typedef struct _USBD_CDC_Itf { + int8_t (* Init)(void); + int8_t (* DeInit)(void); + int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length); + int8_t (* Receive)(uint8_t *Buf, uint32_t *Len); -}USBD_CDC_ItfTypeDef; +} USBD_CDC_ItfTypeDef; -typedef struct -{ +typedef struct { uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32bits alignment */ uint8_t CmdOpCode; uint8_t CmdLength; @@ -146,19 +143,19 @@ extern USBD_ClassTypeDef USBD_CDC; /** @defgroup USB_CORE_Exported_Functions * @{ */ -uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev, - USBD_CDC_ItfTypeDef *fops); +uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev, + USBD_CDC_ItfTypeDef *fops); -uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev, - uint8_t *pbuff, - uint16_t length); +uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, + uint8_t *pbuff, + uint16_t length); -uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev, - uint8_t *pbuff); +uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, + uint8_t *pbuff); -uint8_t USBD_CDC_ReceivePacket (USBD_HandleTypeDef *pdev); +uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev); -uint8_t USBD_CDC_TransmitPacket (USBD_HandleTypeDef *pdev); +uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev); /** * @} */ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc_if_template.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc_if_template.h index f0be9c13e4..9b46817763 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc_if_template.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc_if_template.h @@ -22,7 +22,7 @@ #define __USBD_CDC_IF_TEMPLATE_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c index 7f94e6c126..882fc30873 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c @@ -50,10 +50,10 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_cdc.h" @@ -100,36 +100,35 @@ */ -static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, - USBD_SetupReqTypedef *req); +static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req); -static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, - uint8_t epnum); +static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, + uint8_t epnum); -static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, +static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev); +static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev); -static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length); +static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length); -static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length); +static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length); -static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length); +static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length); -static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length); +static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length); -uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length); +uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length); /* USB Standard Device Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = { USB_LEN_DEV_QUALIFIER_DESC, USB_DESC_TYPE_DEVICE_QUALIFIER, 0x00, @@ -152,8 +151,7 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_ /* CDC interface class callbacks structure */ -USBD_ClassTypeDef USBD_CDC = -{ +USBD_ClassTypeDef USBD_CDC = { USBD_CDC_Init, USBD_CDC_DeInit, USBD_CDC_Setup, @@ -171,8 +169,7 @@ USBD_ClassTypeDef USBD_CDC = }; /* USB CDC device Configuration Descriptor */ -__ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = { /*Configuration Descriptor*/ 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ @@ -267,8 +264,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = /* USB CDC device Configuration Descriptor */ -__ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = { /*Configuration Descriptor*/ 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ @@ -361,8 +357,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = 0x00 /* bInterval: ignore for Bulk transfer */ } ; -__ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuation Descriptor size */ USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, USB_CDC_CONFIG_DESC_SIZ, @@ -414,7 +409,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIG /*Endpoint 2 Descriptor*/ 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT , /* bDescriptorType: Endpoint */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ CDC_CMD_EP, /* bEndpointAddress */ 0x03, /* bmAttributes: Interrupt */ LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ @@ -468,13 +463,12 @@ __ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIG * @param cfgidx: Configuration index * @retval status */ -static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) +static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) { uint8_t ret = 0U; USBD_CDC_HandleTypeDef *hcdc; - if(pdev->dev_speed == USBD_SPEED_HIGH) - { + if (pdev->dev_speed == USBD_SPEED_HIGH) { /* Open EP IN */ USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK, CDC_DATA_HS_IN_PACKET_SIZE); @@ -487,9 +481,7 @@ static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U; - } - else - { + } else { /* Open EP IN */ USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK, CDC_DATA_FS_IN_PACKET_SIZE); @@ -506,15 +498,12 @@ 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->pClassData = USBD_malloc(sizeof(USBD_CDC_HandleTypeDef)); - if(pdev->pClassData == NULL) - { + if (pdev->pClassData == NULL) { ret = 1U; - } - else - { - hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; + } else { + hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData; /* Init physical Interface components */ ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init(); @@ -523,14 +512,11 @@ static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) hcdc->TxState = 0U; hcdc->RxState = 0U; - if(pdev->dev_speed == USBD_SPEED_HIGH) - { + if (pdev->dev_speed == USBD_SPEED_HIGH) { /* Prepare Out endpoint to receive next packet */ USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer, CDC_DATA_HS_OUT_PACKET_SIZE); - } - else - { + } else { /* Prepare Out endpoint to receive next packet */ USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer, CDC_DATA_FS_OUT_PACKET_SIZE); @@ -546,7 +532,7 @@ static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) * @param cfgidx: Configuration index * @retval status */ -static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) +static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) { uint8_t ret = 0U; @@ -563,8 +549,7 @@ 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->pClassData != NULL) { ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit(); USBD_free(pdev->pClassData); pdev->pClassData = NULL; @@ -580,88 +565,73 @@ static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) * @param req: usb requests * @retval status */ -static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, - USBD_SetupReqTypedef *req) +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->pClassData; uint8_t ifalt = 0U; uint16_t status_info = 0U; uint8_t ret = USBD_OK; - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS : - if (req->wLength) - { - if (req->bmRequest & 0x80U) - { + switch (req->bmRequest & USB_REQ_TYPE_MASK) { + case USB_REQ_TYPE_CLASS : + if (req->wLength) { + if (req->bmRequest & 0x80U) { + ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, + (uint8_t *)(void *)hcdc->data, + req->wLength); + + USBD_CtlSendData(pdev, (uint8_t *)(void *)hcdc->data, req->wLength); + } else { + hcdc->CmdOpCode = req->bRequest; + hcdc->CmdLength = (uint8_t)req->wLength; + + USBD_CtlPrepareRx(pdev, (uint8_t *)(void *)hcdc->data, req->wLength); + } + } else { ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, - (uint8_t *)(void *)hcdc->data, - req->wLength); - - USBD_CtlSendData (pdev, (uint8_t *)(void *)hcdc->data, req->wLength); - } - else - { - hcdc->CmdOpCode = req->bRequest; - hcdc->CmdLength = (uint8_t)req->wLength; - - USBD_CtlPrepareRx (pdev, (uint8_t *)(void *)hcdc->data, req->wLength); - } - } - else - { - ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, - (uint8_t *)(void *)req, 0U); - } - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; + (uint8_t *)(void *)req, 0U); } break; - case USB_REQ_GET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlSendData (pdev, &ifalt, 1U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_SET_INTERFACE: - if (pdev->dev_state != USBD_STATE_CONFIGURED) - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_GET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlSendData(pdev, &ifalt, 1U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE: + if (pdev->dev_state != USBD_STATE_CONFIGURED) { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; } break; default: - USBD_CtlError (pdev, req); + USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; } return ret; @@ -674,29 +644,23 @@ static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, * @param epnum: endpoint number * @retval status */ -static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) +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->pClassData; PCD_HandleTypeDef *hpcd = pdev->pData; - if(pdev->pClassData != NULL) - { - if((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U)) - { + if (pdev->pClassData != NULL) { + if ((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U)) { /* Update the packet total length */ pdev->ep_in[epnum].total_length = 0U; /* Send ZLP */ - USBD_LL_Transmit (pdev, epnum, NULL, 0U); - } - else - { + USBD_LL_Transmit(pdev, epnum, NULL, 0U); + } else { hcdc->TxState = 0U; } return USBD_OK; - } - else - { + } else { return USBD_FAIL; } } @@ -708,23 +672,20 @@ static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) * @param epnum: endpoint number * @retval status */ -static uint8_t USBD_CDC_DataOut (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->pClassData; /* Get the received data length */ - hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum); + 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->pClassData != NULL) { ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength); return USBD_OK; - } - else - { + } else { return USBD_FAIL; } } @@ -735,16 +696,15 @@ static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) * @param pdev: device instance * @retval status */ -static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev) +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->pClassData; - if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU)) - { + if ((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU)) { ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode, (uint8_t *)(void *)hcdc->data, (uint16_t)hcdc->CmdLength); - hcdc->CmdOpCode = 0xFFU; + hcdc->CmdOpCode = 0xFFU; } return USBD_OK; @@ -757,9 +717,9 @@ static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev) * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length) +static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length) { - *length = sizeof (USBD_CDC_CfgFSDesc); + *length = sizeof(USBD_CDC_CfgFSDesc); return USBD_CDC_CfgFSDesc; } @@ -770,9 +730,9 @@ static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length) * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length) +static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length) { - *length = sizeof (USBD_CDC_CfgHSDesc); + *length = sizeof(USBD_CDC_CfgHSDesc); return USBD_CDC_CfgHSDesc; } @@ -783,9 +743,9 @@ static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length) * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length) +static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length) { - *length = sizeof (USBD_CDC_OtherSpeedCfgDesc); + *length = sizeof(USBD_CDC_OtherSpeedCfgDesc); return USBD_CDC_OtherSpeedCfgDesc; } @@ -795,9 +755,9 @@ static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length) * @param length : pointer data length * @retval pointer to descriptor buffer */ -uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length) +uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length) { - *length = sizeof (USBD_CDC_DeviceQualifierDesc); + *length = sizeof(USBD_CDC_DeviceQualifierDesc); return USBD_CDC_DeviceQualifierDesc; } @@ -807,14 +767,13 @@ uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length) * @param fops: CD Interface callback * @retval status */ -uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev, - USBD_CDC_ItfTypeDef *fops) +uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev, + USBD_CDC_ItfTypeDef *fops) { uint8_t ret = USBD_FAIL; - if(fops != NULL) - { - pdev->pUserData= fops; + if (fops != NULL) { + pdev->pUserData = fops; ret = USBD_OK; } @@ -827,11 +786,11 @@ uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev, * @param pbuff: Tx Buffer * @retval status */ -uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev, - uint8_t *pbuff, - uint16_t length) +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->pClassData; hcdc->TxBuffer = pbuff; hcdc->TxLength = length; @@ -846,10 +805,10 @@ uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev, * @param pbuff: Rx Buffer * @retval status */ -uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev, - uint8_t *pbuff) +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->pClassData; hcdc->RxBuffer = pbuff; @@ -864,12 +823,10 @@ 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->pClassData; - if(pdev->pClassData != NULL) - { - if(hcdc->TxState == 0U) - { + if (pdev->pClassData != NULL) { + if (hcdc->TxState == 0U) { /* Tx Transfer in progress */ hcdc->TxState = 1U; @@ -881,14 +838,10 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev) (uint16_t)hcdc->TxLength); return USBD_OK; - } - else - { + } else { return USBD_BUSY; } - } - else - { + } else { return USBD_FAIL; } } @@ -902,21 +855,17 @@ 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->pClassData; /* Suspend or Resume USB Out process */ - if(pdev->pClassData != NULL) - { - if(pdev->dev_speed == USBD_SPEED_HIGH ) - { + if (pdev->pClassData != NULL) { + if (pdev->dev_speed == USBD_SPEED_HIGH) { /* Prepare Out endpoint to receive next packet */ USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer, CDC_DATA_HS_OUT_PACKET_SIZE); - } - else - { + } else { /* Prepare Out endpoint to receive next packet */ USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, @@ -924,9 +873,7 @@ uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev) CDC_DATA_FS_OUT_PACKET_SIZE); } return USBD_OK; - } - else - { + } else { return USBD_FAIL; } } diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc_if_template.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc_if_template.c index 788d0cfa50..a84768de54 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc_if_template.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc_if_template.c @@ -17,10 +17,10 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_cdc_if_template.h" @@ -64,26 +64,24 @@ * @{ */ -static int8_t TEMPLATE_Init (void); -static int8_t TEMPLATE_DeInit (void); -static int8_t TEMPLATE_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length); -static int8_t TEMPLATE_Receive (uint8_t* pbuf, uint32_t *Len); +static int8_t TEMPLATE_Init(void); +static int8_t TEMPLATE_DeInit(void); +static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length); +static int8_t TEMPLATE_Receive(uint8_t *pbuf, uint32_t *Len); -USBD_CDC_ItfTypeDef USBD_CDC_Template_fops = -{ +USBD_CDC_ItfTypeDef USBD_CDC_Template_fops = { TEMPLATE_Init, TEMPLATE_DeInit, TEMPLATE_Control, TEMPLATE_Receive }; -USBD_CDC_LineCodingTypeDef linecoding = - { - 115200, /* baud rate*/ - 0x00, /* stop bits-1*/ - 0x00, /* parity - none*/ - 0x08 /* nb. of bits 8*/ - }; +USBD_CDC_LineCodingTypeDef linecoding = { + 115200, /* baud rate*/ + 0x00, /* stop bits-1*/ + 0x00, /* parity - none*/ + 0x08 /* nb. of bits 8*/ +}; /* Private functions ---------------------------------------------------------*/ @@ -124,62 +122,61 @@ static int8_t TEMPLATE_DeInit(void) * @param Len: Number of data to be sent (in bytes) * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL */ -static int8_t TEMPLATE_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length) +static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length) { - switch (cmd) - { - case CDC_SEND_ENCAPSULATED_COMMAND: - /* Add your code here */ - break; - - case CDC_GET_ENCAPSULATED_RESPONSE: - /* Add your code here */ - break; - - case CDC_SET_COMM_FEATURE: - /* Add your code here */ - break; - - case CDC_GET_COMM_FEATURE: - /* Add your code here */ - break; - - case CDC_CLEAR_COMM_FEATURE: - /* Add your code here */ - break; - - case CDC_SET_LINE_CODING: - linecoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) |\ - (pbuf[2] << 16) | (pbuf[3] << 24)); - linecoding.format = pbuf[4]; - linecoding.paritytype = pbuf[5]; - linecoding.datatype = pbuf[6]; - - /* Add your code here */ - break; - - case CDC_GET_LINE_CODING: - pbuf[0] = (uint8_t)(linecoding.bitrate); - pbuf[1] = (uint8_t)(linecoding.bitrate >> 8); - pbuf[2] = (uint8_t)(linecoding.bitrate >> 16); - pbuf[3] = (uint8_t)(linecoding.bitrate >> 24); - pbuf[4] = linecoding.format; - pbuf[5] = linecoding.paritytype; - pbuf[6] = linecoding.datatype; - - /* Add your code here */ - break; - - case CDC_SET_CONTROL_LINE_STATE: - /* Add your code here */ - break; - - case CDC_SEND_BREAK: - /* Add your code here */ - break; - - default: - break; + switch (cmd) { + case CDC_SEND_ENCAPSULATED_COMMAND: + /* Add your code here */ + break; + + case CDC_GET_ENCAPSULATED_RESPONSE: + /* Add your code here */ + break; + + case CDC_SET_COMM_FEATURE: + /* Add your code here */ + break; + + case CDC_GET_COMM_FEATURE: + /* Add your code here */ + break; + + case CDC_CLEAR_COMM_FEATURE: + /* Add your code here */ + break; + + case CDC_SET_LINE_CODING: + linecoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) | \ + (pbuf[2] << 16) | (pbuf[3] << 24)); + linecoding.format = pbuf[4]; + linecoding.paritytype = pbuf[5]; + linecoding.datatype = pbuf[6]; + + /* Add your code here */ + break; + + case CDC_GET_LINE_CODING: + pbuf[0] = (uint8_t)(linecoding.bitrate); + pbuf[1] = (uint8_t)(linecoding.bitrate >> 8); + pbuf[2] = (uint8_t)(linecoding.bitrate >> 16); + pbuf[3] = (uint8_t)(linecoding.bitrate >> 24); + pbuf[4] = linecoding.format; + pbuf[5] = linecoding.paritytype; + pbuf[6] = linecoding.datatype; + + /* Add your code here */ + break; + + case CDC_SET_CONTROL_LINE_STATE: + /* Add your code here */ + break; + + case CDC_SEND_BREAK: + /* Add your code here */ + break; + + default: + break; } return (0); @@ -201,7 +198,7 @@ static int8_t TEMPLATE_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length) * @param Len: Number of data received (in bytes) * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL */ -static int8_t TEMPLATE_Receive (uint8_t* Buf, uint32_t *Len) +static int8_t TEMPLATE_Receive(uint8_t *Buf, uint32_t *Len) { return (0); diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h index 513aa9fc1c..d22233b074 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h @@ -22,7 +22,7 @@ #define __USB_CUSTOMHID_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -51,18 +51,18 @@ #define USB_CUSTOM_HID_DESC_SIZ 9U #ifndef CUSTOM_HID_HS_BINTERVAL - #define CUSTOM_HID_HS_BINTERVAL 0x05U +#define CUSTOM_HID_HS_BINTERVAL 0x05U #endif /* CUSTOM_HID_HS_BINTERVAL */ #ifndef CUSTOM_HID_FS_BINTERVAL - #define CUSTOM_HID_FS_BINTERVAL 0x05U +#define CUSTOM_HID_FS_BINTERVAL 0x05U #endif /* CUSTOM_HID_FS_BINTERVAL */ #ifndef USBD_CUSTOMHID_OUTREPORT_BUF_SIZE - #define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x02U +#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x02U #endif /* USBD_CUSTOMHID_OUTREPORT_BUF_SIZE */ #ifndef USBD_CUSTOM_HID_REPORT_DESC_SIZE - #define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163U +#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163U #endif /* USBD_CUSTOM_HID_REPORT_DESC_SIZE */ #define CUSTOM_HID_DESCRIPTOR_TYPE 0x21U @@ -84,24 +84,21 @@ /** @defgroup USBD_CORE_Exported_TypesDefinitions * @{ */ -typedef enum -{ +typedef enum { CUSTOM_HID_IDLE = 0U, CUSTOM_HID_BUSY, } CUSTOM_HID_StateTypeDef; -typedef struct _USBD_CUSTOM_HID_Itf -{ +typedef struct _USBD_CUSTOM_HID_Itf { uint8_t *pReport; - int8_t (* Init) (void); - int8_t (* DeInit) (void); - int8_t (* OutEvent) (uint8_t event_idx, uint8_t state); + int8_t (* Init)(void); + int8_t (* DeInit)(void); + int8_t (* OutEvent)(uint8_t event_idx, uint8_t state); -}USBD_CUSTOM_HID_ItfTypeDef; +} USBD_CUSTOM_HID_ItfTypeDef; -typedef struct -{ +typedef struct { uint8_t Report_buf[USBD_CUSTOMHID_OUTREPORT_BUF_SIZE]; uint32_t Protocol; uint32_t IdleState; @@ -137,14 +134,14 @@ extern USBD_ClassTypeDef USBD_CUSTOM_HID; /** @defgroup USB_CORE_Exported_Functions * @{ */ -uint8_t USBD_CUSTOM_HID_SendReport (USBD_HandleTypeDef *pdev, - uint8_t *report, - uint16_t len); +uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev, + uint8_t *report, + uint16_t len); -uint8_t USBD_CUSTOM_HID_RegisterInterface (USBD_HandleTypeDef *pdev, - USBD_CUSTOM_HID_ItfTypeDef *fops); +uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev, + USBD_CUSTOM_HID_ItfTypeDef *fops); /** * @} diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid_if_template.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid_if_template.h index 030c01eee2..98d7fa4430 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid_if_template.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid_if_template.h @@ -22,7 +22,7 @@ #define __USBD_CUSTOMHID_IF_TEMPLATE_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c index c1295e3c2a..97df6671ce 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c @@ -37,10 +37,10 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_customhid.h" @@ -85,27 +85,27 @@ */ -static uint8_t USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -static uint8_t USBD_CUSTOM_HID_DeInit (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev, - USBD_SetupReqTypedef *req); +static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req); -static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc (uint16_t *length); +static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length); -static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc (uint16_t *length); +static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length); -static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc (uint16_t *length); +static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length); -static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc (uint16_t *length); +static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length); -static uint8_t USBD_CUSTOM_HID_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_CUSTOM_HID_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_CUSTOM_HID_EP0_RxReady (USBD_HandleTypeDef *pdev); +static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev); /** * @} */ @@ -114,8 +114,7 @@ static uint8_t USBD_CUSTOM_HID_EP0_RxReady (USBD_HandleTypeDef *pdev); * @{ */ -USBD_ClassTypeDef USBD_CUSTOM_HID = -{ +USBD_ClassTypeDef USBD_CUSTOM_HID = { USBD_CUSTOM_HID_Init, USBD_CUSTOM_HID_DeInit, USBD_CUSTOM_HID_Setup, @@ -133,8 +132,7 @@ USBD_ClassTypeDef USBD_CUSTOM_HID = }; /* USB CUSTOM_HID device FS Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgFSDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgFSDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ USB_CUSTOM_HID_CONFIG_DESC_SIZ, @@ -181,19 +179,18 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgFSDesc[USB_CUSTOM_HID_CONFIG_DES CUSTOM_HID_FS_BINTERVAL, /*bInterval: Polling Interval */ /* 34 */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */ CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/ - 0x03, /* bmAttributes: Interrupt endpoint */ - CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */ + 0x03, /* bmAttributes: Interrupt endpoint */ + CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */ 0x00, - CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */ + CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */ /* 41 */ }; /* USB CUSTOM_HID device HS Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgHSDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgHSDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ USB_CUSTOM_HID_CONFIG_DESC_SIZ, @@ -240,19 +237,18 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgHSDesc[USB_CUSTOM_HID_CONFIG_DES CUSTOM_HID_HS_BINTERVAL, /*bInterval: Polling Interval */ /* 34 */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */ CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/ - 0x03, /* bmAttributes: Interrupt endpoint */ - CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */ + 0x03, /* bmAttributes: Interrupt endpoint */ + CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */ 0x00, - CUSTOM_HID_HS_BINTERVAL, /* bInterval: Polling Interval */ + CUSTOM_HID_HS_BINTERVAL, /* bInterval: Polling Interval */ /* 41 */ }; /* USB CUSTOM_HID device Other Speed Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_OtherSpeedCfgDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_OtherSpeedCfgDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ USB_CUSTOM_HID_CONFIG_DESC_SIZ, @@ -299,19 +295,18 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_OtherSpeedCfgDesc[USB_CUSTOM_HID_CO CUSTOM_HID_FS_BINTERVAL, /*bInterval: Polling Interval */ /* 34 */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */ CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/ - 0x03, /* bmAttributes: Interrupt endpoint */ - CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */ + 0x03, /* bmAttributes: Interrupt endpoint */ + CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */ 0x00, - CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */ + CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */ /* 41 */ }; /* USB CUSTOM_HID device Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_Desc[USB_CUSTOM_HID_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_Desc[USB_CUSTOM_HID_DESC_SIZ] __ALIGN_END = { /* 18 */ 0x09, /*bLength: CUSTOM_HID Descriptor size*/ CUSTOM_HID_DESCRIPTOR_TYPE, /*bDescriptorType: CUSTOM_HID*/ @@ -325,8 +320,7 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_Desc[USB_CUSTOM_HID_DESC_SIZ] __ALI }; /* USB Standard Device Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = { USB_LEN_DEV_QUALIFIER_DESC, USB_DESC_TYPE_DEVICE_QUALIFIER, 0x00, @@ -354,8 +348,8 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_DeviceQualifierDesc[USB_LEN_DEV_QUA * @param cfgidx: Configuration index * @retval status */ -static uint8_t USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev, - uint8_t cfgidx) +static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev, + uint8_t cfgidx) { uint8_t ret = 0U; USBD_CUSTOM_HID_HandleTypeDef *hhid; @@ -372,15 +366,12 @@ static uint8_t USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev, pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].is_used = 1U; - pdev->pClassData = USBD_malloc(sizeof (USBD_CUSTOM_HID_HandleTypeDef)); + pdev->pClassData = USBD_malloc(sizeof(USBD_CUSTOM_HID_HandleTypeDef)); - if(pdev->pClassData == NULL) - { + if (pdev->pClassData == NULL) { ret = 1U; - } - else - { - hhid = (USBD_CUSTOM_HID_HandleTypeDef*) pdev->pClassData; + } else { + hhid = (USBD_CUSTOM_HID_HandleTypeDef *) pdev->pClassData; hhid->state = CUSTOM_HID_IDLE; ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->Init(); @@ -400,8 +391,8 @@ static uint8_t USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev, * @param cfgidx: Configuration index * @retval status */ -static uint8_t USBD_CUSTOM_HID_DeInit (USBD_HandleTypeDef *pdev, - uint8_t cfgidx) +static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, + uint8_t cfgidx) { /* Close CUSTOM_HID EP IN */ USBD_LL_CloseEP(pdev, CUSTOM_HID_EPIN_ADDR); @@ -412,8 +403,7 @@ static uint8_t USBD_CUSTOM_HID_DeInit (USBD_HandleTypeDef *pdev, pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].is_used = 0U; /* FRee allocated memory */ - if(pdev->pClassData != NULL) - { + if (pdev->pClassData != NULL) { ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->DeInit(); USBD_free(pdev->pClassData); pdev->pClassData = NULL; @@ -428,116 +418,100 @@ static uint8_t USBD_CUSTOM_HID_DeInit (USBD_HandleTypeDef *pdev, * @param req: usb requests * @retval status */ -static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev, - USBD_SetupReqTypedef *req) +static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req) { - USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData; + USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData; uint16_t len = 0U; uint8_t *pbuf = NULL; uint16_t status_info = 0U; uint8_t ret = USBD_OK; - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS : - switch (req->bRequest) - { - case CUSTOM_HID_REQ_SET_PROTOCOL: - hhid->Protocol = (uint8_t)(req->wValue); - break; - - case CUSTOM_HID_REQ_GET_PROTOCOL: - USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->Protocol, 1U); - break; - - case CUSTOM_HID_REQ_SET_IDLE: - hhid->IdleState = (uint8_t)(req->wValue >> 8); - break; - - case CUSTOM_HID_REQ_GET_IDLE: - USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->IdleState, 1U); - break; - - case CUSTOM_HID_REQ_SET_REPORT: - hhid->IsReportAvailable = 1U; - USBD_CtlPrepareRx (pdev, hhid->Report_buf, req->wLength); - break; - - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; - } - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_GET_DESCRIPTOR: - if( req->wValue >> 8 == CUSTOM_HID_REPORT_DESC) - { - len = MIN(USBD_CUSTOM_HID_REPORT_DESC_SIZE , req->wLength); - pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->pReport; - } - else - { - if( req->wValue >> 8 == CUSTOM_HID_DESCRIPTOR_TYPE) - { - pbuf = USBD_CUSTOM_HID_Desc; - len = MIN(USB_CUSTOM_HID_DESC_SIZ , req->wLength); - } - } - - USBD_CtlSendData (pdev, pbuf, len); - break; - - case USB_REQ_GET_INTERFACE : - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; + switch (req->bmRequest & USB_REQ_TYPE_MASK) { + case USB_REQ_TYPE_CLASS : + switch (req->bRequest) { + case CUSTOM_HID_REQ_SET_PROTOCOL: + hhid->Protocol = (uint8_t)(req->wValue); + break; + + case CUSTOM_HID_REQ_GET_PROTOCOL: + USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->Protocol, 1U); + break; + + case CUSTOM_HID_REQ_SET_IDLE: + hhid->IdleState = (uint8_t)(req->wValue >> 8); + break; + + case CUSTOM_HID_REQ_GET_IDLE: + USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->IdleState, 1U); + break; + + case CUSTOM_HID_REQ_SET_REPORT: + hhid->IsReportAvailable = 1U; + USBD_CtlPrepareRx(pdev, hhid->Report_buf, req->wLength); + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; } break; - case USB_REQ_SET_INTERFACE : - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - hhid->AltSetting = (uint8_t)(req->wValue); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_GET_DESCRIPTOR: + if (req->wValue >> 8 == CUSTOM_HID_REPORT_DESC) { + len = MIN(USBD_CUSTOM_HID_REPORT_DESC_SIZE, req->wLength); + pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->pReport; + } else { + if (req->wValue >> 8 == CUSTOM_HID_DESCRIPTOR_TYPE) { + pbuf = USBD_CUSTOM_HID_Desc; + len = MIN(USB_CUSTOM_HID_DESC_SIZ, req->wLength); + } + } + + USBD_CtlSendData(pdev, pbuf, len); + break; + + case USB_REQ_GET_INTERFACE : + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE : + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + hhid->AltSetting = (uint8_t)(req->wValue); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; } break; default: - USBD_CtlError (pdev, req); + USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; } return ret; } @@ -549,21 +523,17 @@ static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev, * @param buff: pointer to report * @retval status */ -uint8_t USBD_CUSTOM_HID_SendReport (USBD_HandleTypeDef *pdev, - uint8_t *report, - uint16_t len) +uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev, + uint8_t *report, + uint16_t len) { - USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData; + USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData; - if (pdev->dev_state == USBD_STATE_CONFIGURED ) - { - if(hhid->state == CUSTOM_HID_IDLE) - { + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + if (hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; - USBD_LL_Transmit (pdev, CUSTOM_HID_EPIN_ADDR, report, len); - } - else - { + USBD_LL_Transmit(pdev, CUSTOM_HID_EPIN_ADDR, report, len); + } else { return USBD_BUSY; } } @@ -577,9 +547,9 @@ uint8_t USBD_CUSTOM_HID_SendReport (USBD_HandleTypeDef *pdev, * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc (uint16_t *length) +static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length) { - *length = sizeof (USBD_CUSTOM_HID_CfgFSDesc); + *length = sizeof(USBD_CUSTOM_HID_CfgFSDesc); return USBD_CUSTOM_HID_CfgFSDesc; } @@ -590,9 +560,9 @@ static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc (uint16_t *length) * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc (uint16_t *length) +static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length) { - *length = sizeof (USBD_CUSTOM_HID_CfgHSDesc); + *length = sizeof(USBD_CUSTOM_HID_CfgHSDesc); return USBD_CUSTOM_HID_CfgHSDesc; } @@ -603,9 +573,9 @@ static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc (uint16_t *length) * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc (uint16_t *length) +static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length) { - *length = sizeof (USBD_CUSTOM_HID_OtherSpeedCfgDesc); + *length = sizeof(USBD_CUSTOM_HID_OtherSpeedCfgDesc); return USBD_CUSTOM_HID_OtherSpeedCfgDesc; } @@ -616,8 +586,8 @@ static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc (uint16_t *length) * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_CUSTOM_HID_DataIn (USBD_HandleTypeDef *pdev, - uint8_t epnum) +static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, + uint8_t epnum) { /* 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 */ @@ -633,16 +603,16 @@ static uint8_t USBD_CUSTOM_HID_DataIn (USBD_HandleTypeDef *pdev, * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_CUSTOM_HID_DataOut (USBD_HandleTypeDef *pdev, - uint8_t epnum) +static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, + uint8_t epnum) { - USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData; + USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData; ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0], hhid->Report_buf[1]); - USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR , hhid->Report_buf, + USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf, USBD_CUSTOMHID_OUTREPORT_BUF_SIZE); return USBD_OK; @@ -656,10 +626,9 @@ static uint8_t USBD_CUSTOM_HID_DataOut (USBD_HandleTypeDef *pdev, */ static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev) { - USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData; + USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData; - if (hhid->IsReportAvailable == 1U) - { + if (hhid->IsReportAvailable == 1U) { ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0], hhid->Report_buf[1]); hhid->IsReportAvailable = 0U; @@ -674,9 +643,9 @@ static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev) * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc (uint16_t *length) +static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length) { - *length = sizeof (USBD_CUSTOM_HID_DeviceQualifierDesc); + *length = sizeof(USBD_CUSTOM_HID_DeviceQualifierDesc); return USBD_CUSTOM_HID_DeviceQualifierDesc; } @@ -686,14 +655,13 @@ static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc (uint16_t *length) * @param fops: CUSTOMHID Interface callback * @retval status */ -uint8_t USBD_CUSTOM_HID_RegisterInterface (USBD_HandleTypeDef *pdev, - USBD_CUSTOM_HID_ItfTypeDef *fops) +uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev, + USBD_CUSTOM_HID_ItfTypeDef *fops) { uint8_t ret = USBD_FAIL; - if(fops != NULL) - { - pdev->pUserData= fops; + if (fops != NULL) { + pdev->pUserData = fops; ret = USBD_OK; } diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid_if_template.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid_if_template.c index ef22454746..735d216bec 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid_if_template.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid_if_template.c @@ -3,7 +3,7 @@ * @file usbd_customhid_if_template.c * @author MCD Application Team * @brief USB Device Custom HID interface file. - * This template should be copied to the user folder, renamed and customized + * This template should be copied to the user folder, renamed and customized * following user needs. ****************************************************************************** * @attention @@ -19,10 +19,10 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_customhid_if_template.h" @@ -31,12 +31,11 @@ /* Private macro -------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ -static int8_t TEMPLATE_CUSTOM_HID_Init (void); -static int8_t TEMPLATE_CUSTOM_HID_DeInit (void); -static int8_t TEMPLATE_CUSTOM_HID_OutEvent (uint8_t event_idx, uint8_t state); +static int8_t TEMPLATE_CUSTOM_HID_Init(void); +static int8_t TEMPLATE_CUSTOM_HID_DeInit(void); +static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state); /* Private variables ---------------------------------------------------------*/ -USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops = -{ +USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops = { TEMPLATE_CUSTOM_HID_ReportDesc, TEMPLATE_CUSTOM_HID_Init, TEMPLATE_CUSTOM_HID_DeInit, @@ -79,7 +78,7 @@ static int8_t TEMPLATE_CUSTOM_HID_DeInit(void) * @param state: event state * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL */ -static int8_t TEMPLATE_CUSTOM_HID_OutEvent (uint8_t event_idx, uint8_t state) +static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state) { return (0); diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Inc/usbd_dfu.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Inc/usbd_dfu.h index 12c863bb5e..0da1552ee9 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Inc/usbd_dfu.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Inc/usbd_dfu.h @@ -22,7 +22,7 @@ #define __USB_DFU_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -118,10 +118,9 @@ #define DFU_DETACH_MASK (uint8_t)(1 << 4) #define DFU_STATUS_DEPTH 6U -typedef enum -{ +typedef enum { DFU_DETACH = 0U, - DFU_DNLOAD , + DFU_DNLOAD, DFU_UPLOAD, DFU_GETSTATUS, DFU_CLRSTATUS, @@ -157,13 +156,11 @@ typedef void (*pFunction)(void); * @{ */ -typedef struct -{ - union - { +typedef struct { + union { uint32_t d32[USBD_DFU_XFER_SIZE / 4U]; uint8_t d8[USBD_DFU_XFER_SIZE]; - }buffer; + } buffer; uint32_t wblock_num; uint32_t wlength; @@ -177,14 +174,13 @@ typedef struct } USBD_DFU_HandleTypeDef; -typedef struct -{ - const uint8_t* pStrDesc; - uint16_t (* Init) (void); - uint16_t (* DeInit) (void); - uint16_t (* Erase) (uint32_t Add); - uint16_t (* Write) (uint8_t *src, uint8_t *dest, uint32_t Len); - uint8_t* (* Read) (uint8_t *src, uint8_t *dest, uint32_t Len); +typedef struct { + const uint8_t *pStrDesc; + uint16_t (* Init)(void); + uint16_t (* DeInit)(void); + uint16_t (* Erase)(uint32_t Add); + uint16_t (* Write)(uint8_t *src, uint8_t *dest, uint32_t Len); + uint8_t *(* Read)(uint8_t *src, uint8_t *dest, uint32_t Len); uint16_t (* GetStatus)(uint32_t Add, uint8_t cmd, uint8_t *buff); } USBD_DFU_MediaTypeDef; @@ -215,8 +211,8 @@ extern USBD_ClassTypeDef USBD_DFU; /** @defgroup USB_CORE_Exported_Functions * @{ */ -uint8_t USBD_DFU_RegisterMedia (USBD_HandleTypeDef *pdev, - USBD_DFU_MediaTypeDef *fops); +uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev, + USBD_DFU_MediaTypeDef *fops); /** * @} */ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Inc/usbd_dfu_media_template.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Inc/usbd_dfu_media_template.h index deb52f3389..6805433828 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Inc/usbd_dfu_media_template.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Inc/usbd_dfu_media_template.h @@ -22,7 +22,7 @@ #define __USBD_DFU_MEDIA_TEMPLATE_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Src/usbd_dfu.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Src/usbd_dfu.c index 25da12524d..8054ea7717 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Src/usbd_dfu.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Src/usbd_dfu.c @@ -47,10 +47,10 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_dfu.h" @@ -100,52 +100,52 @@ */ -static uint8_t USBD_DFU_Init (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +static uint8_t USBD_DFU_Init(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -static uint8_t USBD_DFU_DeInit (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +static uint8_t USBD_DFU_DeInit(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -static uint8_t USBD_DFU_Setup (USBD_HandleTypeDef *pdev, - USBD_SetupReqTypedef *req); +static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req); -static uint8_t *USBD_DFU_GetCfgDesc (uint16_t *length); +static uint8_t *USBD_DFU_GetCfgDesc(uint16_t *length); -static uint8_t *USBD_DFU_GetDeviceQualifierDesc (uint16_t *length); +static uint8_t *USBD_DFU_GetDeviceQualifierDesc(uint16_t *length); -static uint8_t USBD_DFU_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_DFU_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_DFU_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_DFU_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_DFU_EP0_RxReady (USBD_HandleTypeDef *pdev); +static uint8_t USBD_DFU_EP0_RxReady(USBD_HandleTypeDef *pdev); -static uint8_t USBD_DFU_EP0_TxReady (USBD_HandleTypeDef *pdev); +static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev); -static uint8_t USBD_DFU_SOF (USBD_HandleTypeDef *pdev); +static uint8_t USBD_DFU_SOF(USBD_HandleTypeDef *pdev); -static uint8_t USBD_DFU_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_DFU_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_DFU_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_DFU_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); #if (USBD_SUPPORT_USER_STRING == 1U) -static uint8_t* USBD_DFU_GetUsrStringDesc ( USBD_HandleTypeDef *pdev, uint8_t index , uint16_t *length); +static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length); #endif -static void DFU_Detach (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); +static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void DFU_Download (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); +static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void DFU_Upload (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); +static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void DFU_GetStatus (USBD_HandleTypeDef *pdev); +static void DFU_GetStatus(USBD_HandleTypeDef *pdev); -static void DFU_ClearStatus (USBD_HandleTypeDef *pdev); +static void DFU_ClearStatus(USBD_HandleTypeDef *pdev); -static void DFU_GetState (USBD_HandleTypeDef *pdev); +static void DFU_GetState(USBD_HandleTypeDef *pdev); -static void DFU_Abort (USBD_HandleTypeDef *pdev); +static void DFU_Abort(USBD_HandleTypeDef *pdev); -static void DFU_Leave (USBD_HandleTypeDef *pdev); +static void DFU_Leave(USBD_HandleTypeDef *pdev); /** @@ -156,8 +156,7 @@ static void DFU_Leave (USBD_HandleTypeDef *pdev); * @{ */ -USBD_ClassTypeDef USBD_DFU = -{ +USBD_ClassTypeDef USBD_DFU = { USBD_DFU_Init, USBD_DFU_DeInit, USBD_DFU_Setup, @@ -178,8 +177,7 @@ USBD_ClassTypeDef USBD_DFU = }; /* USB DFU device Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_DFU_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_DFU_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuation Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ USB_DFU_CONFIG_DESC_SIZ, @@ -246,8 +244,7 @@ __ALIGN_BEGIN static uint8_t USBD_DFU_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_E }; /* USB Standard Device Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_DFU_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_DFU_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = { USB_LEN_DEV_QUALIFIER_DESC, USB_DESC_TYPE_DEVICE_QUALIFIER, 0x00, @@ -275,21 +272,18 @@ __ALIGN_BEGIN static uint8_t USBD_DFU_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_ * @param cfgidx: Configuration index * @retval status */ -static uint8_t USBD_DFU_Init (USBD_HandleTypeDef *pdev, - uint8_t cfgidx) +static uint8_t USBD_DFU_Init(USBD_HandleTypeDef *pdev, + uint8_t cfgidx) { USBD_DFU_HandleTypeDef *hdfu; - /* Allocate Audio structure */ - pdev->pClassData = USBD_malloc(sizeof (USBD_DFU_HandleTypeDef)); + /* Allocate Audio structure */ + pdev->pClassData = USBD_malloc(sizeof(USBD_DFU_HandleTypeDef)); - if(pdev->pClassData == NULL) - { + if (pdev->pClassData == NULL) { return USBD_FAIL; - } - else - { - hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData; + } else { + hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData; hdfu->alt_setting = 0U; hdfu->data_ptr = USBD_DFU_APP_DEFAULT_ADD; @@ -307,8 +301,7 @@ static uint8_t USBD_DFU_Init (USBD_HandleTypeDef *pdev, hdfu->dev_status[5] = 0U; /* Initialize Hardware layer */ - if (((USBD_DFU_MediaTypeDef *)pdev->pUserData)->Init() != USBD_OK) - { + if (((USBD_DFU_MediaTypeDef *)pdev->pUserData)->Init() != USBD_OK) { return USBD_FAIL; } } @@ -322,11 +315,11 @@ static uint8_t USBD_DFU_Init (USBD_HandleTypeDef *pdev, * @param cfgidx: Configuration index * @retval status */ -static uint8_t USBD_DFU_DeInit (USBD_HandleTypeDef *pdev, - uint8_t cfgidx) +static uint8_t USBD_DFU_DeInit(USBD_HandleTypeDef *pdev, + uint8_t cfgidx) { USBD_DFU_HandleTypeDef *hdfu; - hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData; + hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData; hdfu->wblock_num = 0U; hdfu->wlength = 0U; @@ -336,8 +329,7 @@ static uint8_t USBD_DFU_DeInit (USBD_HandleTypeDef *pdev, hdfu->dev_status[4] = DFU_STATE_IDLE; /* DeInit physical Interface components */ - if(pdev->pClassData != NULL) - { + if (pdev->pClassData != NULL) { /* De-Initialize Hardware layer */ ((USBD_DFU_MediaTypeDef *)pdev->pUserData)->DeInit(); USBD_free(pdev->pClassData); @@ -354,8 +346,8 @@ static uint8_t USBD_DFU_DeInit (USBD_HandleTypeDef *pdev, * @param req: usb requests * @retval status */ -static uint8_t USBD_DFU_Setup (USBD_HandleTypeDef *pdev, - USBD_SetupReqTypedef *req) +static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req) { USBD_DFU_HandleTypeDef *hdfu; uint8_t *pbuf = 0U; @@ -363,117 +355,101 @@ static uint8_t USBD_DFU_Setup (USBD_HandleTypeDef *pdev, uint16_t status_info = 0U; uint8_t ret = USBD_OK; - hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData; + hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData; - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS: - switch (req->bRequest) - { - case DFU_DNLOAD: - DFU_Download(pdev, req); - break; + switch (req->bmRequest & USB_REQ_TYPE_MASK) { + case USB_REQ_TYPE_CLASS: + switch (req->bRequest) { + case DFU_DNLOAD: + DFU_Download(pdev, req); + break; - case DFU_UPLOAD: - DFU_Upload(pdev, req); - break; + case DFU_UPLOAD: + DFU_Upload(pdev, req); + break; - case DFU_GETSTATUS: - DFU_GetStatus(pdev); - break; + case DFU_GETSTATUS: + DFU_GetStatus(pdev); + break; - case DFU_CLRSTATUS: - DFU_ClearStatus(pdev); - break; + case DFU_CLRSTATUS: + DFU_ClearStatus(pdev); + break; - case DFU_GETSTATE: - DFU_GetState(pdev); - break; - - case DFU_ABORT: - DFU_Abort(pdev); - break; - - case DFU_DETACH: - DFU_Detach(pdev, req); - break; - - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; - } - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - } - break; + case DFU_GETSTATE: + DFU_GetState(pdev); + break; - case USB_REQ_GET_DESCRIPTOR: - if( (req->wValue >> 8) == DFU_DESCRIPTOR_TYPE) - { - pbuf = USBD_DFU_CfgDesc + (9U * (USBD_DFU_MAX_ITF_NUM + 1U)); - len = MIN(USB_DFU_DESC_SIZ , req->wLength); - } + case DFU_ABORT: + DFU_Abort(pdev); + break; - USBD_CtlSendData (pdev, pbuf, len); - break; + case DFU_DETACH: + DFU_Detach(pdev, req); + break; - case USB_REQ_GET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlSendData (pdev, (uint8_t *)(void *)&hdfu->alt_setting, 1U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; } break; - case USB_REQ_SET_INTERFACE: - if ((uint8_t)(req->wValue) < USBD_DFU_MAX_ITF_NUM) - { - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - hdfu->alt_setting = (uint8_t)(req->wValue); - } - else - { - USBD_CtlError (pdev, req); + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_GET_DESCRIPTOR: + if ((req->wValue >> 8) == DFU_DESCRIPTOR_TYPE) { + pbuf = USBD_DFU_CfgDesc + (9U * (USBD_DFU_MAX_ITF_NUM + 1U)); + len = MIN(USB_DFU_DESC_SIZ, req->wLength); + } + + USBD_CtlSendData(pdev, pbuf, len); + break; + + case USB_REQ_GET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlSendData(pdev, (uint8_t *)(void *)&hdfu->alt_setting, 1U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE: + if ((uint8_t)(req->wValue) < USBD_DFU_MAX_ITF_NUM) { + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + hdfu->alt_setting = (uint8_t)(req->wValue); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + } else { + /* Call the error management function (command will be nacked */ + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + default: + USBD_CtlError(pdev, req); ret = USBD_FAIL; - } - } - else - { - /* Call the error management function (command will be nacked */ - USBD_CtlError (pdev, req); - ret = USBD_FAIL; + break; } break; default: - USBD_CtlError (pdev, req); + USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; } return ret; @@ -487,9 +463,9 @@ static uint8_t USBD_DFU_Setup (USBD_HandleTypeDef *pdev, * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_DFU_GetCfgDesc (uint16_t *length) +static uint8_t *USBD_DFU_GetCfgDesc(uint16_t *length) { - *length = sizeof (USBD_DFU_CfgDesc); + *length = sizeof(USBD_DFU_CfgDesc); return USBD_DFU_CfgDesc; } @@ -500,8 +476,8 @@ static uint8_t *USBD_DFU_GetCfgDesc (uint16_t *length) * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_DFU_DataIn (USBD_HandleTypeDef *pdev, - uint8_t epnum) +static uint8_t USBD_DFU_DataIn(USBD_HandleTypeDef *pdev, + uint8_t epnum) { return USBD_OK; @@ -513,7 +489,7 @@ static uint8_t USBD_DFU_DataIn (USBD_HandleTypeDef *pdev, * @param pdev: device instance * @retval status */ -static uint8_t USBD_DFU_EP0_RxReady (USBD_HandleTypeDef *pdev) +static uint8_t USBD_DFU_EP0_RxReady(USBD_HandleTypeDef *pdev) { return USBD_OK; @@ -524,65 +500,52 @@ static uint8_t USBD_DFU_EP0_RxReady (USBD_HandleTypeDef *pdev) * @param pdev: device instance * @retval status */ -static uint8_t USBD_DFU_EP0_TxReady (USBD_HandleTypeDef *pdev) +static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev) { - uint32_t addr; - USBD_SetupReqTypedef req; - USBD_DFU_HandleTypeDef *hdfu; + uint32_t addr; + USBD_SetupReqTypedef req; + USBD_DFU_HandleTypeDef *hdfu; - hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData; + hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData; - if (hdfu->dev_state == DFU_STATE_DNLOAD_BUSY) - { + if (hdfu->dev_state == DFU_STATE_DNLOAD_BUSY) { /* Decode the Special Command*/ - if (hdfu->wblock_num == 0U) - { - if ((hdfu->buffer.d8[0] == DFU_CMD_GETCOMMANDS) && (hdfu->wlength == 1U)) - { + if (hdfu->wblock_num == 0U) { + if ((hdfu->buffer.d8[0] == DFU_CMD_GETCOMMANDS) && (hdfu->wlength == 1U)) { - } - else if ((hdfu->buffer.d8[0] == DFU_CMD_SETADDRESSPOINTER) && (hdfu->wlength == 5U)) - { + } else if ((hdfu->buffer.d8[0] == DFU_CMD_SETADDRESSPOINTER) && (hdfu->wlength == 5U)) { hdfu->data_ptr = hdfu->buffer.d8[1]; hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[2] << 8; hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[3] << 16; hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[4] << 24; - } - else if ((hdfu->buffer.d8[0] == DFU_CMD_ERASE) && (hdfu->wlength == 5U)) - { + } else if ((hdfu->buffer.d8[0] == DFU_CMD_ERASE) && (hdfu->wlength == 5U)) { hdfu->data_ptr = hdfu->buffer.d8[1]; hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[2] << 8; hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[3] << 16; hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[4] << 24; - if (((USBD_DFU_MediaTypeDef *)pdev->pUserData)->Erase(hdfu->data_ptr) != USBD_OK) - { + if (((USBD_DFU_MediaTypeDef *)pdev->pUserData)->Erase(hdfu->data_ptr) != USBD_OK) { return USBD_FAIL; } - } - else - { + } else { /* Reset the global length and block number */ hdfu->wlength = 0U; hdfu->wblock_num = 0U; /* Call the error management function (command will be nacked) */ req.bmRequest = 0U; req.wLength = 1U; - USBD_CtlError (pdev, &req); + USBD_CtlError(pdev, &req); } } /* Regular Download Command */ - else - { - if (hdfu->wblock_num > 1U) - { + else { + if (hdfu->wblock_num > 1U) { /* Decode the required address */ addr = ((hdfu->wblock_num - 2U) * USBD_DFU_XFER_SIZE) + hdfu->data_ptr; /* Preform the write operation */ if (((USBD_DFU_MediaTypeDef *)pdev->pUserData)->Write(hdfu->buffer.d8, - (uint8_t *)addr, hdfu->wlength) != USBD_OK) - { + (uint8_t *)addr, hdfu->wlength) != USBD_OK) { return USBD_FAIL; } } @@ -600,11 +563,8 @@ static uint8_t USBD_DFU_EP0_TxReady (USBD_HandleTypeDef *pdev) hdfu->dev_status[3] = 0U; hdfu->dev_status[4] = hdfu->dev_state; return USBD_OK; - } - else - { - if (hdfu->dev_state == DFU_STATE_MANIFEST)/* Manifestation in progress */ - { + } else { + if (hdfu->dev_state == DFU_STATE_MANIFEST) { /* Manifestation in progress */ /* Start leaving DFU mode */ DFU_Leave(pdev); } @@ -618,7 +578,7 @@ static uint8_t USBD_DFU_EP0_TxReady (USBD_HandleTypeDef *pdev) * @param pdev: device instance * @retval status */ -static uint8_t USBD_DFU_SOF (USBD_HandleTypeDef *pdev) +static uint8_t USBD_DFU_SOF(USBD_HandleTypeDef *pdev) { return USBD_OK; @@ -630,7 +590,7 @@ static uint8_t USBD_DFU_SOF (USBD_HandleTypeDef *pdev) * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_DFU_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum) +static uint8_t USBD_DFU_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) { return USBD_OK; @@ -642,7 +602,7 @@ static uint8_t USBD_DFU_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnu * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_DFU_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum) +static uint8_t USBD_DFU_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) { return USBD_OK; @@ -654,8 +614,8 @@ static uint8_t USBD_DFU_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epn * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_DFU_DataOut (USBD_HandleTypeDef *pdev, - uint8_t epnum) +static uint8_t USBD_DFU_DataOut(USBD_HandleTypeDef *pdev, + uint8_t epnum) { return USBD_OK; @@ -667,9 +627,9 @@ static uint8_t USBD_DFU_DataOut (USBD_HandleTypeDef *pdev, * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_DFU_GetDeviceQualifierDesc (uint16_t *length) +static uint8_t *USBD_DFU_GetDeviceQualifierDesc(uint16_t *length) { - *length = sizeof (USBD_DFU_DeviceQualifierDesc); + *length = sizeof(USBD_DFU_DeviceQualifierDesc); return USBD_DFU_DeviceQualifierDesc; } @@ -682,18 +642,16 @@ static uint8_t *USBD_DFU_GetDeviceQualifierDesc (uint16_t *length) * @retval pointer to the descriptor table or NULL if the descriptor is not supported. */ #if (USBD_SUPPORT_USER_STRING == 1U) -static uint8_t* USBD_DFU_GetUsrStringDesc (USBD_HandleTypeDef *pdev, uint8_t index , uint16_t *length) +static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length) { static uint8_t USBD_StrDesc[255]; /* Check if the requested string interface is supported */ - if (index <= (USBD_IDX_INTERFACE_STR + USBD_DFU_MAX_ITF_NUM)) - { - USBD_GetString ((uint8_t *)((USBD_DFU_MediaTypeDef *)pdev->pUserData)->pStrDesc, USBD_StrDesc, length); + if (index <= (USBD_IDX_INTERFACE_STR + USBD_DFU_MAX_ITF_NUM)) { + USBD_GetString((uint8_t *)((USBD_DFU_MediaTypeDef *)pdev->pUserData)->pStrDesc, USBD_StrDesc, length); return USBD_StrDesc; } /* Not supported Interface Descriptor index */ - else - { + else { return NULL; } } @@ -704,12 +662,11 @@ static uint8_t* USBD_DFU_GetUsrStringDesc (USBD_HandleTypeDef *pdev, uint8_t ind * @param fops: storage callback * @retval status */ -uint8_t USBD_DFU_RegisterMedia (USBD_HandleTypeDef *pdev, - USBD_DFU_MediaTypeDef *fops) +uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev, + USBD_DFU_MediaTypeDef *fops) { - if(fops != NULL) - { - pdev->pUserData= fops; + if (fops != NULL) { + pdev->pUserData = fops; } return 0U; } @@ -726,14 +683,13 @@ uint8_t USBD_DFU_RegisterMedia (USBD_HandleTypeDef *pdev, */ static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { - USBD_DFU_HandleTypeDef *hdfu; + USBD_DFU_HandleTypeDef *hdfu; - hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData; + hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData; if (hdfu->dev_state == DFU_STATE_IDLE || hdfu->dev_state == DFU_STATE_DNLOAD_SYNC || hdfu->dev_state == DFU_STATE_DNLOAD_IDLE || hdfu->dev_state == DFU_STATE_MANIFEST_SYNC - || hdfu->dev_state == DFU_STATE_UPLOAD_IDLE ) - { + || hdfu->dev_state == DFU_STATE_UPLOAD_IDLE) { /* Update the state machine */ hdfu->dev_state = DFU_STATE_IDLE; hdfu->dev_status[0] = DFU_ERROR_NONE; @@ -747,16 +703,13 @@ static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) } /* Check the detach capability in the DFU functional descriptor */ - if ((USBD_DFU_CfgDesc[12U + (9U * USBD_DFU_MAX_ITF_NUM)]) & DFU_DETACH_MASK) - { + if ((USBD_DFU_CfgDesc[12U + (9U * USBD_DFU_MAX_ITF_NUM)]) & DFU_DETACH_MASK) { /* Perform an Attach-Detach operation on USB bus */ - USBD_Stop (pdev); - USBD_Start (pdev); - } - else - { + USBD_Stop(pdev); + USBD_Start(pdev); + } else { /* Wait for the period of time specified in Detach request */ - USBD_Delay ((uint32_t)req->wValue); + USBD_Delay((uint32_t)req->wValue); } } @@ -769,15 +722,13 @@ static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) */ static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { - USBD_DFU_HandleTypeDef *hdfu; + USBD_DFU_HandleTypeDef *hdfu; - hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData; + hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData; /* Data setup request */ - if (req->wLength > 0U) - { - if ((hdfu->dev_state == DFU_STATE_IDLE) || (hdfu->dev_state == DFU_STATE_DNLOAD_IDLE)) - { + if (req->wLength > 0U) { + if ((hdfu->dev_state == DFU_STATE_IDLE) || (hdfu->dev_state == DFU_STATE_DNLOAD_IDLE)) { /* Update the global length and block number */ hdfu->wblock_num = req->wValue; hdfu->wlength = req->wLength; @@ -787,33 +738,28 @@ static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) hdfu->dev_status[4] = hdfu->dev_state; /* Prepare the reception of the buffer over EP0 */ - USBD_CtlPrepareRx (pdev, (uint8_t*)hdfu->buffer.d8, - (uint16_t)hdfu->wlength); + USBD_CtlPrepareRx(pdev, (uint8_t *)hdfu->buffer.d8, + (uint16_t)hdfu->wlength); } /* Unsupported state */ - else - { + else { /* Call the error management function (command will be nacked */ - USBD_CtlError (pdev, req); + USBD_CtlError(pdev, req); } } /* 0 Data DNLOAD request */ - else - { + else { /* End of DNLOAD operation*/ - if (hdfu->dev_state == DFU_STATE_DNLOAD_IDLE || hdfu->dev_state == DFU_STATE_IDLE ) - { + if (hdfu->dev_state == DFU_STATE_DNLOAD_IDLE || hdfu->dev_state == DFU_STATE_IDLE) { hdfu->manif_state = DFU_MANIFEST_IN_PROGRESS; hdfu->dev_state = DFU_STATE_MANIFEST_SYNC; hdfu->dev_status[1] = 0U; hdfu->dev_status[2] = 0U; hdfu->dev_status[3] = 0U; hdfu->dev_status[4] = hdfu->dev_state; - } - else - { + } else { /* Call the error management function (command will be nacked */ - USBD_CtlError (pdev, req); + USBD_CtlError(pdev, req); } } } @@ -827,27 +773,24 @@ static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) */ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { - USBD_DFU_HandleTypeDef *hdfu; + USBD_DFU_HandleTypeDef *hdfu; - hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData; + hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData; uint8_t *phaddr = NULL; uint32_t addr = 0U; /* Data setup request */ - if (req->wLength > 0U) - { - if ((hdfu->dev_state == DFU_STATE_IDLE) || (hdfu->dev_state == DFU_STATE_UPLOAD_IDLE)) - { + if (req->wLength > 0U) { + if ((hdfu->dev_state == DFU_STATE_IDLE) || (hdfu->dev_state == DFU_STATE_UPLOAD_IDLE)) { /* Update the global length and block number */ hdfu->wblock_num = req->wValue; hdfu->wlength = req->wLength; /* DFU Get Command */ - if (hdfu->wblock_num == 0U) - { + if (hdfu->wblock_num == 0U) { /* Update the state machine */ - hdfu->dev_state = (hdfu->wlength > 3U)? DFU_STATE_IDLE:DFU_STATE_UPLOAD_IDLE; + hdfu->dev_state = (hdfu->wlength > 3U) ? DFU_STATE_IDLE : DFU_STATE_UPLOAD_IDLE; hdfu->dev_status[1] = 0U; hdfu->dev_status[2] = 0U; @@ -860,10 +803,8 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) hdfu->buffer.d8[2] = DFU_CMD_ERASE; /* Send the status data over EP0 */ - USBD_CtlSendData (pdev, (uint8_t *)(&(hdfu->buffer.d8[0])), 3U); - } - else if (hdfu->wblock_num > 1U) - { + USBD_CtlSendData(pdev, (uint8_t *)(&(hdfu->buffer.d8[0])), 3U); + } else if (hdfu->wblock_num > 1U) { hdfu->dev_state = DFU_STATE_UPLOAD_IDLE; hdfu->dev_status[1] = 0U; @@ -877,10 +818,8 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) phaddr = ((USBD_DFU_MediaTypeDef *)pdev->pUserData)->Read((uint8_t *)addr, hdfu->buffer.d8, hdfu->wlength); /* Send the status data over EP0 */ - USBD_CtlSendData (pdev, phaddr, (uint16_t)hdfu->wlength); - } - else /* unsupported hdfu->wblock_num */ - { + USBD_CtlSendData(pdev, phaddr, (uint16_t)hdfu->wlength); + } else { /* unsupported hdfu->wblock_num */ hdfu->dev_state = DFU_ERROR_STALLEDPKT; hdfu->dev_status[1] = 0U; @@ -889,21 +828,19 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) hdfu->dev_status[4] = hdfu->dev_state; /* Call the error management function (command will be nacked */ - USBD_CtlError (pdev, req); + USBD_CtlError(pdev, req); } } /* Unsupported state */ - else - { + else { hdfu->wlength = 0U; hdfu->wblock_num = 0U; /* Call the error management function (command will be nacked */ - USBD_CtlError (pdev, req); + USBD_CtlError(pdev, req); } } /* No Data setup request */ - else - { + else { hdfu->dev_state = DFU_STATE_IDLE; hdfu->dev_status[1] = 0U; @@ -921,73 +858,62 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) */ static void DFU_GetStatus(USBD_HandleTypeDef *pdev) { - USBD_DFU_HandleTypeDef *hdfu; + USBD_DFU_HandleTypeDef *hdfu; - hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData; + hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData; - switch (hdfu->dev_state) - { - case DFU_STATE_DNLOAD_SYNC: - if (hdfu->wlength != 0U) - { - hdfu->dev_state = DFU_STATE_DNLOAD_BUSY; + switch (hdfu->dev_state) { + case DFU_STATE_DNLOAD_SYNC: + if (hdfu->wlength != 0U) { + hdfu->dev_state = DFU_STATE_DNLOAD_BUSY; - hdfu->dev_status[1] = 0U; - hdfu->dev_status[2] = 0U; - hdfu->dev_status[3] = 0U; - hdfu->dev_status[4] = hdfu->dev_state; - - if ((hdfu->wblock_num == 0U) && (hdfu->buffer.d8[0] == DFU_CMD_ERASE)) - { - ((USBD_DFU_MediaTypeDef *)pdev->pUserData)->GetStatus(hdfu->data_ptr, DFU_MEDIA_ERASE, hdfu->dev_status); - } - else - { - ((USBD_DFU_MediaTypeDef *)pdev->pUserData)->GetStatus(hdfu->data_ptr, DFU_MEDIA_PROGRAM, hdfu->dev_status); - } - } - else /* (hdfu->wlength==0)*/ - { - hdfu->dev_state = DFU_STATE_DNLOAD_IDLE; + hdfu->dev_status[1] = 0U; + hdfu->dev_status[2] = 0U; + hdfu->dev_status[3] = 0U; + hdfu->dev_status[4] = hdfu->dev_state; - hdfu->dev_status[1] = 0U; - hdfu->dev_status[2] = 0U; - hdfu->dev_status[3] = 0U; - hdfu->dev_status[4] = hdfu->dev_state; - } - break; + if ((hdfu->wblock_num == 0U) && (hdfu->buffer.d8[0] == DFU_CMD_ERASE)) { + ((USBD_DFU_MediaTypeDef *)pdev->pUserData)->GetStatus(hdfu->data_ptr, DFU_MEDIA_ERASE, hdfu->dev_status); + } else { + ((USBD_DFU_MediaTypeDef *)pdev->pUserData)->GetStatus(hdfu->data_ptr, DFU_MEDIA_PROGRAM, hdfu->dev_status); + } + } else { /* (hdfu->wlength==0)*/ + hdfu->dev_state = DFU_STATE_DNLOAD_IDLE; - case DFU_STATE_MANIFEST_SYNC : - if (hdfu->manif_state == DFU_MANIFEST_IN_PROGRESS) - { - hdfu->dev_state = DFU_STATE_MANIFEST; + hdfu->dev_status[1] = 0U; + hdfu->dev_status[2] = 0U; + hdfu->dev_status[3] = 0U; + hdfu->dev_status[4] = hdfu->dev_state; + } + break; - hdfu->dev_status[1] = 1U; /*bwPollTimeout = 1ms*/ - hdfu->dev_status[2] = 0U; - hdfu->dev_status[3] = 0U; - hdfu->dev_status[4] = hdfu->dev_state; - } - else - { - if ((hdfu->manif_state == DFU_MANIFEST_COMPLETE) && - ((USBD_DFU_CfgDesc[(11U + (9U * USBD_DFU_MAX_ITF_NUM))]) & 0x04U)) - { - hdfu->dev_state = DFU_STATE_IDLE; + case DFU_STATE_MANIFEST_SYNC : + if (hdfu->manif_state == DFU_MANIFEST_IN_PROGRESS) { + hdfu->dev_state = DFU_STATE_MANIFEST; - hdfu->dev_status[1] = 0U; + hdfu->dev_status[1] = 1U; /*bwPollTimeout = 1ms*/ hdfu->dev_status[2] = 0U; hdfu->dev_status[3] = 0U; hdfu->dev_status[4] = hdfu->dev_state; + } else { + if ((hdfu->manif_state == DFU_MANIFEST_COMPLETE) && + ((USBD_DFU_CfgDesc[(11U + (9U * USBD_DFU_MAX_ITF_NUM))]) & 0x04U)) { + hdfu->dev_state = DFU_STATE_IDLE; + + hdfu->dev_status[1] = 0U; + hdfu->dev_status[2] = 0U; + hdfu->dev_status[3] = 0U; + hdfu->dev_status[4] = hdfu->dev_state; + } } - } - break; + break; - default : - break; + default : + break; } /* Send the status data over EP0 */ - USBD_CtlSendData (pdev, (uint8_t *)(&(hdfu->dev_status[0])), 6U); + USBD_CtlSendData(pdev, (uint8_t *)(&(hdfu->dev_status[0])), 6U); } /** @@ -998,12 +924,11 @@ static void DFU_GetStatus(USBD_HandleTypeDef *pdev) */ static void DFU_ClearStatus(USBD_HandleTypeDef *pdev) { - USBD_DFU_HandleTypeDef *hdfu; + USBD_DFU_HandleTypeDef *hdfu; - hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData; + hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData; - if (hdfu->dev_state == DFU_STATE_ERROR) - { + if (hdfu->dev_state == DFU_STATE_ERROR) { hdfu->dev_state = DFU_STATE_IDLE; hdfu->dev_status[0] = DFU_ERROR_NONE;/*bStatus*/ hdfu->dev_status[1] = 0U; @@ -1011,9 +936,8 @@ static void DFU_ClearStatus(USBD_HandleTypeDef *pdev) hdfu->dev_status[3] = 0U; /*bwPollTimeout=0ms*/ hdfu->dev_status[4] = hdfu->dev_state;/*bState*/ hdfu->dev_status[5] = 0U;/*iString*/ - } - else - { /*State Error*/ + } else { + /*State Error*/ hdfu->dev_state = DFU_STATE_ERROR; hdfu->dev_status[0] = DFU_ERROR_UNKNOWN;/*bStatus*/ hdfu->dev_status[1] = 0U; @@ -1032,12 +956,12 @@ static void DFU_ClearStatus(USBD_HandleTypeDef *pdev) */ static void DFU_GetState(USBD_HandleTypeDef *pdev) { - USBD_DFU_HandleTypeDef *hdfu; + USBD_DFU_HandleTypeDef *hdfu; - hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData; + hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData; /* Return the current state of the DFU interface */ - USBD_CtlSendData (pdev, &hdfu->dev_state, 1U); + USBD_CtlSendData(pdev, &hdfu->dev_state, 1U); } /** @@ -1048,14 +972,13 @@ static void DFU_GetState(USBD_HandleTypeDef *pdev) */ static void DFU_Abort(USBD_HandleTypeDef *pdev) { - USBD_DFU_HandleTypeDef *hdfu; + USBD_DFU_HandleTypeDef *hdfu; - hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData; + hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData; if (hdfu->dev_state == DFU_STATE_IDLE || hdfu->dev_state == DFU_STATE_DNLOAD_SYNC || hdfu->dev_state == DFU_STATE_DNLOAD_IDLE || hdfu->dev_state == DFU_STATE_MANIFEST_SYNC - || hdfu->dev_state == DFU_STATE_UPLOAD_IDLE ) - { + || hdfu->dev_state == DFU_STATE_UPLOAD_IDLE) { hdfu->dev_state = DFU_STATE_IDLE; hdfu->dev_status[0] = DFU_ERROR_NONE; hdfu->dev_status[1] = 0U; @@ -1077,14 +1000,13 @@ static void DFU_Abort(USBD_HandleTypeDef *pdev) */ static void DFU_Leave(USBD_HandleTypeDef *pdev) { - USBD_DFU_HandleTypeDef *hdfu; + USBD_DFU_HandleTypeDef *hdfu; - hdfu = (USBD_DFU_HandleTypeDef*) pdev->pClassData; + hdfu = (USBD_DFU_HandleTypeDef *) pdev->pClassData; - hdfu->manif_state = DFU_MANIFEST_COMPLETE; + hdfu->manif_state = DFU_MANIFEST_COMPLETE; - if ((USBD_DFU_CfgDesc[(11U + (9U * USBD_DFU_MAX_ITF_NUM))]) & 0x04U) - { + if ((USBD_DFU_CfgDesc[(11U + (9U * USBD_DFU_MAX_ITF_NUM))]) & 0x04U) { hdfu->dev_state = DFU_STATE_MANIFEST_SYNC; hdfu->dev_status[1] = 0U; @@ -1092,9 +1014,7 @@ static void DFU_Leave(USBD_HandleTypeDef *pdev) hdfu->dev_status[3] = 0U; hdfu->dev_status[4] = hdfu->dev_state; return; - } - else - { + } else { hdfu->dev_state = DFU_STATE_MANIFEST_WAIT_RESET; @@ -1104,7 +1024,7 @@ static void DFU_Leave(USBD_HandleTypeDef *pdev) hdfu->dev_status[4] = hdfu->dev_state; /* Disconnect the USB device */ - USBD_Stop (pdev); + USBD_Stop(pdev); /* DeInitilialize the MAL(Media Access Layer) */ ((USBD_DFU_MediaTypeDef *)pdev->pUserData)->DeInit(); @@ -1113,7 +1033,7 @@ static void DFU_Leave(USBD_HandleTypeDef *pdev) NVIC_SystemReset(); /* This instruction will not be reached (system reset) */ - for(;;){} + for (;;) {} } } diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Src/usbd_dfu_media_template.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Src/usbd_dfu_media_template.c index 7a61fe1496..449bfed90c 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Src/usbd_dfu_media_template.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Src/usbd_dfu_media_template.c @@ -17,10 +17,10 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_dfu_media_template.h" @@ -34,21 +34,20 @@ /* Extern function prototypes ------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ uint16_t MEM_If_Init(void); -uint16_t MEM_If_Erase (uint32_t Add); -uint16_t MEM_If_Write (uint8_t *src, uint8_t *dest, uint32_t Len); -uint8_t *MEM_If_Read (uint8_t *src, uint8_t *dest, uint32_t Len); +uint16_t MEM_If_Erase(uint32_t Add); +uint16_t MEM_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len); +uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len); uint16_t MEM_If_DeInit(void); -uint16_t MEM_If_GetStatus (uint32_t Add, uint8_t Cmd, uint8_t *buffer); +uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer); -USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops = -{ - (uint8_t *)"DFU MEDIA", - MEM_If_Init, - MEM_If_DeInit, - MEM_If_Erase, - MEM_If_Write, - MEM_If_Read, - MEM_If_GetStatus, +USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops = { + (uint8_t *)"DFU MEDIA", + MEM_If_Init, + MEM_If_DeInit, + MEM_If_Erase, + MEM_If_Write, + MEM_If_Read, + MEM_If_GetStatus, }; /** @@ -103,10 +102,10 @@ uint16_t MEM_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len) * @param Len: Number of data to be read (in bytes). * @retval Pointer to the physical address where data should be read. */ -uint8_t *MEM_If_Read (uint8_t *src, uint8_t *dest, uint32_t Len) +uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len) { /* Return a valid address to avoid HardFault */ - return (uint8_t*)(0); + return (uint8_t *)(0); } /** @@ -116,20 +115,19 @@ uint8_t *MEM_If_Read (uint8_t *src, uint8_t *dest, uint32_t Len) * @param cmd: Number of data to be read (in bytes). * @retval Pointer to the physical address where data should be read. */ -uint16_t MEM_If_GetStatus (uint32_t Add, uint8_t Cmd, uint8_t *buffer) +uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer) { - switch (Cmd) - { - case DFU_MEDIA_PROGRAM: + switch (Cmd) { + case DFU_MEDIA_PROGRAM: - break; + break; - case DFU_MEDIA_ERASE: - default: + case DFU_MEDIA_ERASE: + default: - break; + break; } - return (0); + return (0); } /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc/usbd_hid.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc/usbd_hid.h index 34e1ed3152..1f31ec26b1 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc/usbd_hid.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc/usbd_hid.h @@ -22,7 +22,7 @@ #define __USB_HID_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -52,11 +52,11 @@ #define HID_REPORT_DESC 0x22U #ifndef HID_HS_BINTERVAL - #define HID_HS_BINTERVAL 0x07U +#define HID_HS_BINTERVAL 0x07U #endif /* HID_HS_BINTERVAL */ #ifndef HID_FS_BINTERVAL - #define HID_FS_BINTERVAL 0x0AU +#define HID_FS_BINTERVAL 0x0AU #endif /* HID_FS_BINTERVAL */ #define HID_REQ_SET_PROTOCOL 0x0BU @@ -75,16 +75,14 @@ /** @defgroup USBD_CORE_Exported_TypesDefinitions * @{ */ -typedef enum -{ +typedef enum { HID_IDLE = 0, HID_BUSY, } HID_StateTypeDef; -typedef struct -{ +typedef struct { uint32_t Protocol; uint32_t IdleState; uint32_t AltSetting; @@ -118,11 +116,11 @@ extern USBD_ClassTypeDef USBD_HID; /** @defgroup USB_CORE_Exported_Functions * @{ */ -uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev, - uint8_t *report, - uint16_t len); +uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, + uint8_t *report, + uint16_t len); -uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev); +uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev); /** * @} diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c index 2abc3d5e10..d2949b7131 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c @@ -38,10 +38,10 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_hid.h" @@ -90,24 +90,24 @@ */ -static uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev, - USBD_SetupReqTypedef *req); +static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req); -static uint8_t *USBD_HID_GetFSCfgDesc (uint16_t *length); +static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length); -static uint8_t *USBD_HID_GetHSCfgDesc (uint16_t *length); +static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length); -static uint8_t *USBD_HID_GetOtherSpeedCfgDesc (uint16_t *length); +static uint8_t *USBD_HID_GetOtherSpeedCfgDesc(uint16_t *length); -static uint8_t *USBD_HID_GetDeviceQualifierDesc (uint16_t *length); +static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length); -static uint8_t USBD_HID_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum); /** * @} */ @@ -116,8 +116,7 @@ static uint8_t USBD_HID_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum); * @{ */ -USBD_ClassTypeDef USBD_HID = -{ +USBD_ClassTypeDef USBD_HID = { USBD_HID_Init, USBD_HID_DeInit, USBD_HID_Setup, @@ -135,8 +134,7 @@ USBD_ClassTypeDef USBD_HID = }; /* USB HID device FS Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_HID_CfgFSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_HID_CfgFSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ USB_HID_CONFIG_DESC_SIZ, @@ -185,8 +183,7 @@ __ALIGN_BEGIN static uint8_t USBD_HID_CfgFSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIG }; /* USB HID device HS Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_HID_CfgHSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_HID_CfgHSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ USB_HID_CONFIG_DESC_SIZ, @@ -235,8 +232,7 @@ __ALIGN_BEGIN static uint8_t USBD_HID_CfgHSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIG }; /* USB HID device Other Speed Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_HID_OtherSpeedCfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_HID_OtherSpeedCfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ USB_HID_CONFIG_DESC_SIZ, @@ -286,8 +282,7 @@ __ALIGN_BEGIN static uint8_t USBD_HID_OtherSpeedCfgDesc[USB_HID_CONFIG_DESC_SIZ] /* USB HID device Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END = { /* 18 */ 0x09, /*bLength: HID Descriptor size*/ HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/ @@ -301,8 +296,7 @@ __ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END = }; /* USB Standard Device Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = { USB_LEN_DEV_QUALIFIER_DESC, USB_DESC_TYPE_DEVICE_QUALIFIER, 0x00, @@ -315,8 +309,7 @@ __ALIGN_BEGIN static uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_ 0x00, }; -__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END = -{ +__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END = { 0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, @@ -380,16 +373,15 @@ __ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] _ * @param cfgidx: Configuration index * @retval status */ -static uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) +static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) { /* Open EP IN */ 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->pClassData = USBD_malloc(sizeof(USBD_HID_HandleTypeDef)); - if (pdev->pClassData == NULL) - { + if (pdev->pClassData == NULL) { return USBD_FAIL; } @@ -405,16 +397,15 @@ static uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) * @param cfgidx: Configuration index * @retval status */ -static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev, - uint8_t cfgidx) +static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, + uint8_t cfgidx) { /* Close HID EPs */ USBD_LL_CloseEP(pdev, HID_EPIN_ADDR); pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 0U; /* FRee allocated memory */ - if(pdev->pClassData != NULL) - { + if (pdev->pClassData != NULL) { USBD_free(pdev->pClassData); pdev->pClassData = NULL; } @@ -429,112 +420,95 @@ static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev, * @param req: usb requests * @retval status */ -static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev, - USBD_SetupReqTypedef *req) +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->pClassData; uint16_t len = 0U; uint8_t *pbuf = NULL; uint16_t status_info = 0U; USBD_StatusTypeDef ret = USBD_OK; - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS : - switch (req->bRequest) - { - case HID_REQ_SET_PROTOCOL: - hhid->Protocol = (uint8_t)(req->wValue); - break; - - case HID_REQ_GET_PROTOCOL: - USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->Protocol, 1U); - break; - - case HID_REQ_SET_IDLE: - hhid->IdleState = (uint8_t)(req->wValue >> 8); - break; - - case HID_REQ_GET_IDLE: - USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->IdleState, 1U); - break; - - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; - } - break; - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_GET_DESCRIPTOR: - if(req->wValue >> 8 == HID_REPORT_DESC) - { - len = MIN(HID_MOUSE_REPORT_DESC_SIZE , req->wLength); - pbuf = HID_MOUSE_ReportDesc; - } - else if(req->wValue >> 8 == HID_DESCRIPTOR_TYPE) - { - pbuf = USBD_HID_Desc; - len = MIN(USB_HID_DESC_SIZ, req->wLength); + switch (req->bmRequest & USB_REQ_TYPE_MASK) { + case USB_REQ_TYPE_CLASS : + switch (req->bRequest) { + case HID_REQ_SET_PROTOCOL: + hhid->Protocol = (uint8_t)(req->wValue); + break; + + case HID_REQ_GET_PROTOCOL: + USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->Protocol, 1U); + break; + + case HID_REQ_SET_IDLE: + hhid->IdleState = (uint8_t)(req->wValue >> 8); + break; + + case HID_REQ_GET_IDLE: + USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->IdleState, 1U); + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; - } - USBD_CtlSendData (pdev, pbuf, len); break; - - case USB_REQ_GET_INTERFACE : - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_SET_INTERFACE : - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - hhid->AltSetting = (uint8_t)(req->wValue); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_GET_DESCRIPTOR: + if (req->wValue >> 8 == HID_REPORT_DESC) { + len = MIN(HID_MOUSE_REPORT_DESC_SIZE, req->wLength); + pbuf = HID_MOUSE_ReportDesc; + } else if (req->wValue >> 8 == HID_DESCRIPTOR_TYPE) { + pbuf = USBD_HID_Desc; + len = MIN(USB_HID_DESC_SIZ, req->wLength); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } + USBD_CtlSendData(pdev, pbuf, len); + break; + + case USB_REQ_GET_INTERFACE : + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE : + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + hhid->AltSetting = (uint8_t)(req->wValue); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; } break; default: - USBD_CtlError (pdev, req); + USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; } return ret; @@ -547,21 +521,19 @@ static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev, * @param buff: pointer to report * @retval status */ -uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev, - uint8_t *report, - uint16_t len) +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->pClassData; - if (pdev->dev_state == USBD_STATE_CONFIGURED ) - { - if(hhid->state == HID_IDLE) - { + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + if (hhid->state == HID_IDLE) { hhid->state = HID_BUSY; - USBD_LL_Transmit (pdev, - HID_EPIN_ADDR, - report, - len); + USBD_LL_Transmit(pdev, + HID_EPIN_ADDR, + report, + len); } } return USBD_OK; @@ -573,20 +545,17 @@ uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev, * @param pdev: device instance * @retval polling interval */ -uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev) +uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev) { uint32_t polling_interval = 0U; /* HIGH-speed endpoints */ - if(pdev->dev_speed == USBD_SPEED_HIGH) - { - /* Sets the data transfer polling interval for high speed transfers. - Values between 1..16 are allowed. Values correspond to interval - of 2 ^ (bInterval-1). This option (8 ms, corresponds to HID_HS_BINTERVAL */ - polling_interval = (((1U <<(HID_HS_BINTERVAL - 1U))) / 8U); - } - else /* LOW and FULL-speed endpoints */ - { + if (pdev->dev_speed == USBD_SPEED_HIGH) { + /* Sets the data transfer polling interval for high speed transfers. + Values between 1..16 are allowed. Values correspond to interval + of 2 ^ (bInterval-1). This option (8 ms, corresponds to HID_HS_BINTERVAL */ + polling_interval = (((1U << (HID_HS_BINTERVAL - 1U))) / 8U); + } else { /* LOW and FULL-speed endpoints */ /* Sets the data transfer polling interval for low and full speed transfers */ polling_interval = HID_FS_BINTERVAL; @@ -602,9 +571,9 @@ uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev) * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_HID_GetFSCfgDesc (uint16_t *length) +static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length) { - *length = sizeof (USBD_HID_CfgFSDesc); + *length = sizeof(USBD_HID_CfgFSDesc); return USBD_HID_CfgFSDesc; } @@ -615,9 +584,9 @@ static uint8_t *USBD_HID_GetFSCfgDesc (uint16_t *length) * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_HID_GetHSCfgDesc (uint16_t *length) +static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length) { - *length = sizeof (USBD_HID_CfgHSDesc); + *length = sizeof(USBD_HID_CfgHSDesc); return USBD_HID_CfgHSDesc; } @@ -628,9 +597,9 @@ static uint8_t *USBD_HID_GetHSCfgDesc (uint16_t *length) * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_HID_GetOtherSpeedCfgDesc (uint16_t *length) +static uint8_t *USBD_HID_GetOtherSpeedCfgDesc(uint16_t *length) { - *length = sizeof (USBD_HID_OtherSpeedCfgDesc); + *length = sizeof(USBD_HID_OtherSpeedCfgDesc); return USBD_HID_OtherSpeedCfgDesc; } @@ -641,8 +610,8 @@ static uint8_t *USBD_HID_GetOtherSpeedCfgDesc (uint16_t *length) * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_HID_DataIn (USBD_HandleTypeDef *pdev, - uint8_t epnum) +static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, + uint8_t epnum) { /* Ensure that the FIFO is empty before a new transfer, this condition could @@ -658,9 +627,9 @@ static uint8_t USBD_HID_DataIn (USBD_HandleTypeDef *pdev, * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_HID_GetDeviceQualifierDesc (uint16_t *length) +static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length) { - *length = sizeof (USBD_HID_DeviceQualifierDesc); + *length = sizeof(USBD_HID_DeviceQualifierDesc); return USBD_HID_DeviceQualifierDesc; } diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h index b7bc342208..c8f2c59a97 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h @@ -22,7 +22,7 @@ #define __USBD_MSC_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -66,22 +66,20 @@ /** @defgroup USB_CORE_Exported_Types * @{ */ -typedef struct _USBD_STORAGE -{ - int8_t (* Init) (uint8_t lun); - int8_t (* GetCapacity) (uint8_t lun, uint32_t *block_num, uint16_t *block_size); - int8_t (* IsReady) (uint8_t lun); - int8_t (* IsWriteProtected) (uint8_t lun); - int8_t (* Read) (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); +typedef struct _USBD_STORAGE { + int8_t (* Init)(uint8_t lun); + int8_t (* GetCapacity)(uint8_t lun, uint32_t *block_num, uint16_t *block_size); + int8_t (* IsReady)(uint8_t lun); + int8_t (* IsWriteProtected)(uint8_t lun); + int8_t (* Read)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); int8_t (* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); int8_t (* GetMaxLun)(void); int8_t *pInquiry; -}USBD_StorageTypeDef; +} USBD_StorageTypeDef; -typedef struct -{ +typedef struct { uint32_t max_lun; uint32_t interface; uint8_t bot_state; @@ -107,8 +105,8 @@ USBD_MSC_BOT_HandleTypeDef; extern USBD_ClassTypeDef USBD_MSC; #define USBD_MSC_CLASS &USBD_MSC -uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev, - USBD_StorageTypeDef *fops); +uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, + USBD_StorageTypeDef *fops); /** * @} */ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_bot.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_bot.h index 932aaccc4e..2d845f87b6 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_bot.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_bot.h @@ -22,7 +22,7 @@ #define __USBD_MSC_BOT_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -77,8 +77,7 @@ * @{ */ -typedef struct -{ +typedef struct { uint32_t dSignature; uint32_t dTag; uint32_t dDataLength; @@ -91,8 +90,7 @@ typedef struct USBD_MSC_BOT_CBWTypeDef; -typedef struct -{ +typedef struct { uint32_t dSignature; uint32_t dTag; uint32_t dDataResidue; @@ -116,20 +114,20 @@ USBD_MSC_BOT_CSWTypeDef; /** @defgroup USBD_CORE_Exported_FunctionsPrototypes * @{ */ -void MSC_BOT_Init (USBD_HandleTypeDef *pdev); -void MSC_BOT_Reset (USBD_HandleTypeDef *pdev); -void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev); -void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev, - uint8_t epnum); +void MSC_BOT_Init(USBD_HandleTypeDef *pdev); +void MSC_BOT_Reset(USBD_HandleTypeDef *pdev); +void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev); +void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev, + uint8_t epnum); -void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev, - uint8_t epnum); +void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev, + uint8_t epnum); -void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev, - uint8_t CSW_Status); +void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, + uint8_t CSW_Status); -void MSC_BOT_CplClrFeature (USBD_HandleTypeDef *pdev, - uint8_t epnum); +void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, + uint8_t epnum); /** * @} */ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_data.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_data.h index ce9fdec2c5..d9a395102c 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_data.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_data.h @@ -22,7 +22,7 @@ #define __USBD_MSC_DATA_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_scsi.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_scsi.h index a588202fce..9795b4a791 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_scsi.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_scsi.h @@ -22,7 +22,7 @@ #define __USBD_MSC_SCSI_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -132,8 +132,8 @@ typedef struct _SENSE_ITEM { struct _ASCs { char ASC; char ASCQ; - }b; - uint8_t ASC; + } b; + uint8_t ASC; char *pData; } w; } USBD_SCSI_SenseTypeDef; diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_storage_template.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_storage_template.h index 297c0d5e37..d0d85784da 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_storage_template.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_storage_template.h @@ -22,7 +22,7 @@ #define __USBD_MSC_STORAGE_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c index 95cff9b4e3..898af4e7f9 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c @@ -32,11 +32,11 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_msc.h" @@ -80,29 +80,29 @@ /** @defgroup MSC_CORE_Private_FunctionPrototypes * @{ */ -uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, - USBD_SetupReqTypedef *req); +uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req); -uint8_t USBD_MSC_DataIn (USBD_HandleTypeDef *pdev, - uint8_t epnum); +uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, + uint8_t epnum); -uint8_t USBD_MSC_DataOut (USBD_HandleTypeDef *pdev, - uint8_t epnum); +uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, + uint8_t epnum); -uint8_t *USBD_MSC_GetHSCfgDesc (uint16_t *length); +uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length); -uint8_t *USBD_MSC_GetFSCfgDesc (uint16_t *length); +uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length); -uint8_t *USBD_MSC_GetOtherSpeedCfgDesc (uint16_t *length); +uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length); -uint8_t *USBD_MSC_GetDeviceQualifierDescriptor (uint16_t *length); +uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length); /** @@ -115,8 +115,7 @@ uint8_t *USBD_MSC_GetDeviceQualifierDescriptor (uint16_t *length); */ -USBD_ClassTypeDef USBD_MSC = -{ +USBD_ClassTypeDef USBD_MSC = { USBD_MSC_Init, USBD_MSC_DeInit, USBD_MSC_Setup, @@ -135,8 +134,7 @@ USBD_ClassTypeDef USBD_MSC = /* USB Mass storage device Configuration Descriptor */ /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */ -__ALIGN_BEGIN uint8_t USBD_MSC_CfgHSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN uint8_t USBD_MSC_CfgHSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuation Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ @@ -179,8 +177,7 @@ __ALIGN_BEGIN uint8_t USBD_MSC_CfgHSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = /* USB Mass storage device Configuration Descriptor */ /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */ -uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = -{ +uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuation Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ @@ -221,8 +218,7 @@ uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = 0x00 /*Polling interval in milliseconds*/ }; -__ALIGN_BEGIN uint8_t USBD_MSC_OtherSpeedCfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = -{ +__ALIGN_BEGIN uint8_t USBD_MSC_OtherSpeedCfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuation Descriptor size */ USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, @@ -264,8 +260,7 @@ __ALIGN_BEGIN uint8_t USBD_MSC_OtherSpeedCfgDesc[USB_MSC_CONFIG_DESC_SIZ] __AL }; /* USB Standard Device Descriptor */ -__ALIGN_BEGIN uint8_t USBD_MSC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = -{ +__ALIGN_BEGIN uint8_t USBD_MSC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = { USB_LEN_DEV_QUALIFIER_DESC, USB_DESC_TYPE_DEVICE_QUALIFIER, 0x00, @@ -293,10 +288,9 @@ __ALIGN_BEGIN uint8_t USBD_MSC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] * @param cfgidx: configuration index * @retval status */ -uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) +uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) { - if(pdev->dev_speed == USBD_SPEED_HIGH) - { + if (pdev->dev_speed == USBD_SPEED_HIGH) { /* Open EP OUT */ USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET); pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 1U; @@ -304,9 +298,7 @@ uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) /* Open EP IN */ USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET); pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 1U; - } - else - { + } else { /* Open EP OUT */ USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET); pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 1U; @@ -315,10 +307,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->pClassData = USBD_malloc(sizeof(USBD_MSC_BOT_HandleTypeDef)); - if(pdev->pClassData == NULL) - { + if (pdev->pClassData == NULL) { return USBD_FAIL; } @@ -335,8 +326,8 @@ uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) * @param cfgidx: configuration index * @retval status */ -uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev, - uint8_t cfgidx) +uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev, + uint8_t cfgidx) { /* Close MSC EPs */ USBD_LL_CloseEP(pdev, MSC_EPOUT_ADDR); @@ -346,12 +337,11 @@ uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev, USBD_LL_CloseEP(pdev, MSC_EPIN_ADDR); pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 0U; - /* De-Init the BOT layer */ + /* De-Init the BOT layer */ MSC_BOT_DeInit(pdev); /* Free MSC Class Resources */ - if(pdev->pClassData != NULL) - { + if (pdev->pClassData != NULL) { USBD_free(pdev->pClassData); pdev->pClassData = NULL; } @@ -364,149 +354,122 @@ uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev, * @param req: USB request * @retval status */ -uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) +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->pClassData; uint8_t ret = USBD_OK; uint16_t status_info = 0U; - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { + switch (req->bmRequest & USB_REQ_TYPE_MASK) { /* Class request */ - case USB_REQ_TYPE_CLASS: - switch (req->bRequest) - { - case BOT_GET_MAX_LUN: - if((req->wValue == 0U) && (req->wLength == 1U) && - ((req->bmRequest & 0x80U) == 0x80U)) - { - hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData)->GetMaxLun(); - USBD_CtlSendData (pdev, (uint8_t *)(void *)&hmsc->max_lun, 1U); + case USB_REQ_TYPE_CLASS: + switch (req->bRequest) { + case BOT_GET_MAX_LUN: + if ((req->wValue == 0U) && (req->wLength == 1U) && + ((req->bmRequest & 0x80U) == 0x80U)) { + hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData)->GetMaxLun(); + USBD_CtlSendData(pdev, (uint8_t *)(void *)&hmsc->max_lun, 1U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case BOT_RESET : + if ((req->wValue == 0U) && (req->wLength == 0U) && + ((req->bmRequest & 0x80U) != 0x80U)) { + MSC_BOT_Reset(pdev); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; } - else - { - USBD_CtlError(pdev, req); - ret = USBD_FAIL; - } - break; - - case BOT_RESET : - if((req->wValue == 0U) && (req->wLength == 0U) && - ((req->bmRequest & 0x80U) != 0x80U)) - { - MSC_BOT_Reset(pdev); - } - else - { - USBD_CtlError(pdev , req); - ret = USBD_FAIL; - } - break; - - default: - USBD_CtlError(pdev , req); - ret = USBD_FAIL; break; - } - break; /* Interface & Endpoint request */ - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_GET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlSendData (pdev, (uint8_t *)(void *)&hmsc->interface, 1U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_GET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlSendData(pdev, (uint8_t *)(void *)&hmsc->interface, 1U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + hmsc->interface = (uint8_t)(req->wValue); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_CLEAR_FEATURE: + + /* Flush the FIFO and Clear the stall status */ + USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex); + + /* Reactivate the EP */ + USBD_LL_CloseEP(pdev, (uint8_t)req->wIndex); + if ((((uint8_t)req->wIndex) & 0x80U) == 0x80U) { + pdev->ep_in[(uint8_t)req->wIndex & 0xFU].is_used = 0U; + if (pdev->dev_speed == USBD_SPEED_HIGH) { + /* Open EP IN */ + USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK, + MSC_MAX_HS_PACKET); + } else { + /* Open EP IN */ + 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; + } else { + pdev->ep_out[(uint8_t)req->wIndex & 0xFU].is_used = 0U; + if (pdev->dev_speed == USBD_SPEED_HIGH) { + /* Open EP OUT */ + USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, + MSC_MAX_HS_PACKET); + } else { + /* Open EP OUT */ + USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, + MSC_MAX_FS_PACKET); + } + pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 1U; + } + + /* Handle BOT error */ + MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex); + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; } break; - case USB_REQ_SET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - hmsc->interface = (uint8_t)(req->wValue); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_CLEAR_FEATURE: - - /* Flush the FIFO and Clear the stall status */ - USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex); - - /* Reactivate the EP */ - USBD_LL_CloseEP (pdev , (uint8_t)req->wIndex); - if((((uint8_t)req->wIndex) & 0x80U) == 0x80U) - { - pdev->ep_in[(uint8_t)req->wIndex & 0xFU].is_used = 0U; - if(pdev->dev_speed == USBD_SPEED_HIGH) - { - /* Open EP IN */ - USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK, - MSC_MAX_HS_PACKET); - } - else - { - /* Open EP IN */ - 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; - } - else - { - pdev->ep_out[(uint8_t)req->wIndex & 0xFU].is_used = 0U; - if(pdev->dev_speed == USBD_SPEED_HIGH) - { - /* Open EP OUT */ - USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, - MSC_MAX_HS_PACKET); - } - else - { - /* Open EP OUT */ - USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, - MSC_MAX_FS_PACKET); - } - pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 1U; - } - - /* Handle BOT error */ - MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex); - break; - default: - USBD_CtlError (pdev, req); + USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; } return ret; @@ -519,10 +482,10 @@ uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) * @param epnum: endpoint index * @retval status */ -uint8_t USBD_MSC_DataIn (USBD_HandleTypeDef *pdev, - uint8_t epnum) +uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, + uint8_t epnum) { - MSC_BOT_DataIn(pdev , epnum); + MSC_BOT_DataIn(pdev, epnum); return USBD_OK; } @@ -533,10 +496,10 @@ uint8_t USBD_MSC_DataIn (USBD_HandleTypeDef *pdev, * @param epnum: endpoint index * @retval status */ -uint8_t USBD_MSC_DataOut (USBD_HandleTypeDef *pdev, - uint8_t epnum) +uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, + uint8_t epnum) { - MSC_BOT_DataOut(pdev , epnum); + MSC_BOT_DataOut(pdev, epnum); return USBD_OK; } @@ -546,9 +509,9 @@ uint8_t USBD_MSC_DataOut (USBD_HandleTypeDef *pdev, * @param length : pointer data length * @retval pointer to descriptor buffer */ -uint8_t *USBD_MSC_GetHSCfgDesc (uint16_t *length) +uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length) { - *length = sizeof (USBD_MSC_CfgHSDesc); + *length = sizeof(USBD_MSC_CfgHSDesc); return USBD_MSC_CfgHSDesc; } @@ -558,9 +521,9 @@ uint8_t *USBD_MSC_GetHSCfgDesc (uint16_t *length) * @param length : pointer data length * @retval pointer to descriptor buffer */ -uint8_t *USBD_MSC_GetFSCfgDesc (uint16_t *length) +uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length) { - *length = sizeof (USBD_MSC_CfgFSDesc); + *length = sizeof(USBD_MSC_CfgFSDesc); return USBD_MSC_CfgFSDesc; } @@ -570,9 +533,9 @@ uint8_t *USBD_MSC_GetFSCfgDesc (uint16_t *length) * @param length : pointer data length * @retval pointer to descriptor buffer */ -uint8_t *USBD_MSC_GetOtherSpeedCfgDesc (uint16_t *length) +uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length) { - *length = sizeof (USBD_MSC_OtherSpeedCfgDesc); + *length = sizeof(USBD_MSC_OtherSpeedCfgDesc); return USBD_MSC_OtherSpeedCfgDesc; } /** @@ -581,9 +544,9 @@ uint8_t *USBD_MSC_GetOtherSpeedCfgDesc (uint16_t *length) * @param length : pointer data length * @retval pointer to descriptor buffer */ -uint8_t *USBD_MSC_GetDeviceQualifierDescriptor (uint16_t *length) +uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length) { - *length = sizeof (USBD_MSC_DeviceQualifierDesc); + *length = sizeof(USBD_MSC_DeviceQualifierDesc); return USBD_MSC_DeviceQualifierDesc; } @@ -592,11 +555,10 @@ uint8_t *USBD_MSC_GetDeviceQualifierDescriptor (uint16_t *length) * @param fops: storage callback * @retval status */ -uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev, - USBD_StorageTypeDef *fops) +uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, + USBD_StorageTypeDef *fops) { - if(fops != NULL) - { + if (fops != NULL) { pdev->pUserData = fops; } return USBD_OK; diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c index aed9e8e5a1..befc5e43e6 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c @@ -17,11 +17,11 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_msc_bot.h" @@ -76,10 +76,10 @@ /** @defgroup MSC_BOT_Private_FunctionPrototypes * @{ */ -static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev); +static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev); -static void MSC_BOT_SendData (USBD_HandleTypeDef *pdev, uint8_t* pbuf, - uint16_t len); +static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, + uint16_t len); static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev); /** @@ -99,9 +99,9 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev); * @param pdev: device instance * @retval None */ -void MSC_BOT_Init (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->pClassData; hmsc->bot_state = USBD_BOT_IDLE; hmsc->bot_status = USBD_BOT_STATUS_NORMAL; @@ -115,8 +115,8 @@ void MSC_BOT_Init (USBD_HandleTypeDef *pdev) USBD_LL_FlushEP(pdev, MSC_EPIN_ADDR); /* Prapare EP to Receive First BOT Cmd */ - USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw, - USBD_BOT_CBW_LENGTH); + USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw, + USBD_BOT_CBW_LENGTH); } /** @@ -125,16 +125,16 @@ void MSC_BOT_Init (USBD_HandleTypeDef *pdev) * @param pdev: device instance * @retval None */ -void MSC_BOT_Reset (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->pClassData; hmsc->bot_state = USBD_BOT_IDLE; hmsc->bot_status = USBD_BOT_STATUS_RECOVERY; /* Prapare EP to Receive First BOT Cmd */ - USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw, - USBD_BOT_CBW_LENGTH); + USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw, + USBD_BOT_CBW_LENGTH); } /** @@ -143,9 +143,9 @@ void MSC_BOT_Reset (USBD_HandleTypeDef *pdev) * @param pdev: device instance * @retval None */ -void MSC_BOT_DeInit (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->pClassData; hmsc->bot_state = USBD_BOT_IDLE; } @@ -156,30 +156,28 @@ void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev) * @param epnum: endpoint index * @retval None */ -void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev, - uint8_t epnum) +void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev, + uint8_t epnum) { - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData; - - switch (hmsc->bot_state) - { - case USBD_BOT_DATA_IN: - if(SCSI_ProcessCmd(pdev, - hmsc->cbw.bLUN, - &hmsc->cbw.CB[0]) < 0) - { - MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED); - } - break; + USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; + + switch (hmsc->bot_state) { + case USBD_BOT_DATA_IN: + if (SCSI_ProcessCmd(pdev, + hmsc->cbw.bLUN, + &hmsc->cbw.CB[0]) < 0) { + MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); + } + break; - case USBD_BOT_SEND_DATA: - case USBD_BOT_LAST_DATA_IN: - MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED); + case USBD_BOT_SEND_DATA: + case USBD_BOT_LAST_DATA_IN: + MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED); - break; + break; - default: - break; + default: + break; } } /** @@ -189,30 +187,28 @@ void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev, * @param epnum: endpoint index * @retval None */ -void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev, - uint8_t epnum) +void MSC_BOT_DataOut(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->pClassData; - switch (hmsc->bot_state) - { - case USBD_BOT_IDLE: - MSC_BOT_CBW_Decode(pdev); - break; + switch (hmsc->bot_state) { + case USBD_BOT_IDLE: + MSC_BOT_CBW_Decode(pdev); + break; - case USBD_BOT_DATA_OUT: + case USBD_BOT_DATA_OUT: - if(SCSI_ProcessCmd(pdev, - hmsc->cbw.bLUN, - &hmsc->cbw.CB[0]) < 0) - { - MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED); - } + if (SCSI_ProcessCmd(pdev, + hmsc->cbw.bLUN, + &hmsc->cbw.CB[0]) < 0) { + MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); + } - break; + break; - default: - break; + default: + break; } } @@ -222,57 +218,42 @@ void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev, * @param pdev: device instance * @retval None */ -static void MSC_BOT_CBW_Decode (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->pClassData; hmsc->csw.dTag = hmsc->cbw.dTag; hmsc->csw.dDataResidue = hmsc->cbw.dDataLength; - if ((USBD_LL_GetRxDataSize (pdev ,MSC_EPOUT_ADDR) != USBD_BOT_CBW_LENGTH) || + if ((USBD_LL_GetRxDataSize(pdev, MSC_EPOUT_ADDR) != USBD_BOT_CBW_LENGTH) || (hmsc->cbw.dSignature != USBD_BOT_CBW_SIGNATURE) || - (hmsc->cbw.bLUN > 1U) || - (hmsc->cbw.bCBLength < 1U) || (hmsc->cbw.bCBLength > 16U)) - { + (hmsc->cbw.bLUN > 1U) || + (hmsc->cbw.bCBLength < 1U) || (hmsc->cbw.bCBLength > 16U)) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); hmsc->bot_status = USBD_BOT_STATUS_ERROR; MSC_BOT_Abort(pdev); - } - else - { - if(SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) - { - if(hmsc->bot_state == USBD_BOT_NO_DATA) - { - MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED); - } - else - { + } else { + if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) { + if (hmsc->bot_state == USBD_BOT_NO_DATA) { + MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); + } else { MSC_BOT_Abort(pdev); } } /*Burst xfer handled internally*/ else if ((hmsc->bot_state != USBD_BOT_DATA_IN) && (hmsc->bot_state != USBD_BOT_DATA_OUT) && - (hmsc->bot_state != USBD_BOT_LAST_DATA_IN)) - { - if (hmsc->bot_data_length > 0U) - { + (hmsc->bot_state != USBD_BOT_LAST_DATA_IN)) { + if (hmsc->bot_data_length > 0U) { MSC_BOT_SendData(pdev, hmsc->bot_data, hmsc->bot_data_length); - } - else if (hmsc->bot_data_length == 0U) - { - MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED); - } - else - { + } else if (hmsc->bot_data_length == 0U) { + MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED); + } else { MSC_BOT_Abort(pdev); } - } - else - { + } else { return; } } @@ -286,10 +267,10 @@ static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev) * @param len: Data Length * @retval None */ -static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t* pbuf, +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->pClassData; uint16_t length = (uint16_t)MIN(hmsc->cbw.dDataLength, len); @@ -307,21 +288,21 @@ static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t* pbuf, * @param status : CSW status * @retval None */ -void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev, - uint8_t CSW_Status) +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->pClassData; hmsc->csw.dSignature = USBD_BOT_CSW_SIGNATURE; hmsc->csw.bStatus = CSW_Status; hmsc->bot_state = USBD_BOT_IDLE; - USBD_LL_Transmit (pdev, MSC_EPIN_ADDR, (uint8_t *)(void *)&hmsc->csw, - USBD_BOT_CSW_LENGTH); + USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, (uint8_t *)(void *)&hmsc->csw, + USBD_BOT_CSW_LENGTH); /* Prepare EP to Receive next Cmd */ - USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw, - USBD_BOT_CBW_LENGTH); + USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw, + USBD_BOT_CBW_LENGTH); } /** @@ -331,23 +312,21 @@ void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev, * @retval status */ -static void MSC_BOT_Abort (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->pClassData; if ((hmsc->cbw.bmFlags == 0U) && (hmsc->cbw.dDataLength != 0U) && - (hmsc->bot_status == USBD_BOT_STATUS_NORMAL)) - { - USBD_LL_StallEP(pdev, MSC_EPOUT_ADDR ); + (hmsc->bot_status == USBD_BOT_STATUS_NORMAL)) { + USBD_LL_StallEP(pdev, MSC_EPOUT_ADDR); } USBD_LL_StallEP(pdev, MSC_EPIN_ADDR); - if(hmsc->bot_status == USBD_BOT_STATUS_ERROR) - { - USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw, - USBD_BOT_CBW_LENGTH); + if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) { + USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw, + USBD_BOT_CBW_LENGTH); } } @@ -359,21 +338,16 @@ static void MSC_BOT_Abort (USBD_HandleTypeDef *pdev) * @retval None */ -void MSC_BOT_CplClrFeature (USBD_HandleTypeDef *pdev, uint8_t epnum) +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->pClassData; - if(hmsc->bot_status == USBD_BOT_STATUS_ERROR)/* Bad CBW Signature */ - { + if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) { /* Bad CBW Signature */ USBD_LL_StallEP(pdev, MSC_EPIN_ADDR); hmsc->bot_status = USBD_BOT_STATUS_NORMAL; - } - else if(((epnum & 0x80U) == 0x80U) && (hmsc->bot_status != USBD_BOT_STATUS_RECOVERY)) - { - MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED); - } - else - { + } else if (((epnum & 0x80U) == 0x80U) && (hmsc->bot_status != USBD_BOT_STATUS_RECOVERY)) { + MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); + } else { return; } } diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c index bd3937e4b1..d7cdbce99e 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c @@ -17,11 +17,11 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_msc_data.h" @@ -68,35 +68,35 @@ /* USB Mass storage Page 0 Inquiry Data */ const uint8_t MSC_Page00_Inquiry_Data[] = { - 0x00, - 0x00, - 0x00, - (LENGTH_INQUIRY_PAGE00 - 4U), - 0x00, - 0x80, - 0x83 + 0x00, + 0x00, + 0x00, + (LENGTH_INQUIRY_PAGE00 - 4U), + 0x00, + 0x80, + 0x83 }; /* USB Mass storage sense 6 Data */ const uint8_t MSC_Mode_Sense6_data[] = { - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00 + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 }; /* USB Mass storage sense 10 Data */ const uint8_t MSC_Mode_Sense10_data[] = { - 0x00, - 0x06, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00 + 0x00, + 0x06, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00 }; /** * @} diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c index 37fe748628..38476895b2 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c @@ -17,11 +17,11 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_msc_bot.h" @@ -82,18 +82,18 @@ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_RequestSense (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); +static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params); -static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params); +static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); +static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); +static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); +static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); -static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun, - uint32_t blk_offset, uint32_t blk_nbr); +static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun, + uint32_t blk_offset, uint32_t blk_nbr); -static int8_t SCSI_ProcessRead (USBD_HandleTypeDef *pdev, uint8_t lun); -static int8_t SCSI_ProcessWrite (USBD_HandleTypeDef *pdev, uint8_t lun); +static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun); +static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun); /** * @} */ @@ -114,58 +114,57 @@ static int8_t SCSI_ProcessWrite (USBD_HandleTypeDef *pdev, uint8_t lun); */ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd) { - switch (cmd[0]) - { - case SCSI_TEST_UNIT_READY: - SCSI_TestUnitReady(pdev, lun, cmd); - break; - - case SCSI_REQUEST_SENSE: - SCSI_RequestSense (pdev, lun, cmd); - break; - case SCSI_INQUIRY: - SCSI_Inquiry(pdev, lun, cmd); - break; - - case SCSI_START_STOP_UNIT: - SCSI_StartStopUnit(pdev, lun, cmd); - break; - - case SCSI_ALLOW_MEDIUM_REMOVAL: - SCSI_StartStopUnit(pdev, lun, cmd); - break; - - case SCSI_MODE_SENSE6: - SCSI_ModeSense6 (pdev, lun, cmd); - break; - - case SCSI_MODE_SENSE10: - SCSI_ModeSense10 (pdev, lun, cmd); - break; - - case SCSI_READ_FORMAT_CAPACITIES: - SCSI_ReadFormatCapacity(pdev, lun, cmd); - break; - - case SCSI_READ_CAPACITY10: - SCSI_ReadCapacity10(pdev, lun, cmd); - break; - - case SCSI_READ10: - SCSI_Read10(pdev, lun, cmd); - break; - - case SCSI_WRITE10: - SCSI_Write10(pdev, lun, cmd); - break; - - case SCSI_VERIFY10: - SCSI_Verify10(pdev, lun, cmd); - break; - - default: - SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB); - return -1; + switch (cmd[0]) { + case SCSI_TEST_UNIT_READY: + SCSI_TestUnitReady(pdev, lun, cmd); + break; + + case SCSI_REQUEST_SENSE: + SCSI_RequestSense(pdev, lun, cmd); + break; + case SCSI_INQUIRY: + SCSI_Inquiry(pdev, lun, cmd); + break; + + case SCSI_START_STOP_UNIT: + SCSI_StartStopUnit(pdev, lun, cmd); + break; + + case SCSI_ALLOW_MEDIUM_REMOVAL: + SCSI_StartStopUnit(pdev, lun, cmd); + break; + + case SCSI_MODE_SENSE6: + SCSI_ModeSense6(pdev, lun, cmd); + break; + + case SCSI_MODE_SENSE10: + SCSI_ModeSense10(pdev, lun, cmd); + break; + + case SCSI_READ_FORMAT_CAPACITIES: + SCSI_ReadFormatCapacity(pdev, lun, cmd); + break; + + case SCSI_READ_CAPACITY10: + SCSI_ReadCapacity10(pdev, lun, cmd); + break; + + case SCSI_READ10: + SCSI_Read10(pdev, lun, cmd); + break; + + case SCSI_WRITE10: + SCSI_Write10(pdev, lun, cmd); + break; + + case SCSI_VERIFY10: + SCSI_Verify10(pdev, lun, cmd); + break; + + default: + SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB); + return -1; } return 0; } @@ -180,18 +179,16 @@ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd) */ static int8_t SCSI_TestUnitReady(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->pClassData; /* case 9 : Hi > D0 */ - if (hmsc->cbw.dDataLength != 0U) - { + if (hmsc->cbw.dDataLength != 0U) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } - if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0) - { + if (((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); hmsc->bot_state = USBD_BOT_NO_DATA; @@ -211,34 +208,28 @@ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t */ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { - uint8_t* pPage; + 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->pClassData; - if (params[1] & 0x01U)/*Evpd is set*/ - { + if (params[1] & 0x01U) { /*Evpd is set*/ len = LENGTH_INQUIRY_PAGE00; hmsc->bot_data_length = len; - while (len) - { + while (len) { len--; hmsc->bot_data[len] = MSC_Page00_Inquiry_Data[len]; } - } - else - { - pPage = (uint8_t *)(void *)&((USBD_StorageTypeDef *)pdev->pUserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN]; + } else { + pPage = (uint8_t *)(void *) & ((USBD_StorageTypeDef *)pdev->pUserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN]; len = (uint16_t)pPage[4] + 5U; - if (params[4] <= len) - { + if (params[4] <= len) { len = params[4]; } hmsc->bot_data_length = len; - while (len) - { + while (len) { len--; hmsc->bot_data[len] = pPage[len]; } @@ -256,15 +247,12 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *par */ static int8_t SCSI_ReadCapacity10(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->pClassData; - if(((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size) != 0) - { + if (((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size) != 0) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; - } - else - { + } else { hmsc->bot_data[0] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 24); hmsc->bot_data[1] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 16); @@ -289,24 +277,20 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_ */ static int8_t SCSI_ReadFormatCapacity(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->pClassData; uint16_t blk_size; uint32_t blk_nbr; uint16_t i; - for(i = 0U; i < 12U ; i++) - { + for (i = 0U; i < 12U ; i++) { hmsc->bot_data[i] = 0U; } - if(((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &blk_nbr, &blk_size) != 0U) - { + if (((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &blk_nbr, &blk_size) != 0U) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; - } - else - { + } else { hmsc->bot_data[3] = 0x08U; hmsc->bot_data[4] = (uint8_t)((blk_nbr - 1U) >> 24); hmsc->bot_data[5] = (uint8_t)((blk_nbr - 1U) >> 16); @@ -329,14 +313,13 @@ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, ui * @param params: Command parameters * @retval status */ -static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) +static int8_t SCSI_ModeSense6(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->pClassData; uint16_t len = 8U; hmsc->bot_data_length = len; - while (len) - { + while (len) { len--; hmsc->bot_data[len] = MSC_Mode_Sense6_data[len]; } @@ -350,15 +333,14 @@ static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t * * @param params: Command parameters * @retval status */ -static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) +static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *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->pClassData; hmsc->bot_data_length = len; - while (len) - { + while (len) { len--; hmsc->bot_data[len] = MSC_Mode_Sense10_data[len]; } @@ -374,35 +356,32 @@ static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t * @retval status */ -static int8_t SCSI_RequestSense (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) +static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { uint8_t i; - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData; + USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; - for(i = 0U ;i < REQUEST_SENSE_DATA_LEN; i++) - { + for (i = 0U ; i < REQUEST_SENSE_DATA_LEN; i++) { hmsc->bot_data[i] = 0U; } - hmsc->bot_data[0] = 0x70U; - hmsc->bot_data[7] = REQUEST_SENSE_DATA_LEN - 6U; + hmsc->bot_data[0] = 0x70U; + hmsc->bot_data[7] = REQUEST_SENSE_DATA_LEN - 6U; - if((hmsc->scsi_sense_head != hmsc->scsi_sense_tail)) { + if ((hmsc->scsi_sense_head != hmsc->scsi_sense_tail)) { hmsc->bot_data[2] = hmsc->scsi_sense[hmsc->scsi_sense_head].Skey; hmsc->bot_data[12] = hmsc->scsi_sense[hmsc->scsi_sense_head].w.b.ASCQ; hmsc->bot_data[13] = hmsc->scsi_sense[hmsc->scsi_sense_head].w.b.ASC; hmsc->scsi_sense_head++; - if (hmsc->scsi_sense_head == SENSE_LIST_DEEPTH) - { + if (hmsc->scsi_sense_head == SENSE_LIST_DEEPTH) { hmsc->scsi_sense_head = 0U; } } hmsc->bot_data_length = REQUEST_SENSE_DATA_LEN; - if (params[4] <= REQUEST_SENSE_DATA_LEN) - { + if (params[4] <= REQUEST_SENSE_DATA_LEN) { hmsc->bot_data_length = params[4]; } return 0; @@ -419,13 +398,12 @@ static int8_t SCSI_RequestSense (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t */ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_t ASC) { - USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData; + USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; hmsc->scsi_sense[hmsc->scsi_sense_tail].Skey = sKey; hmsc->scsi_sense[hmsc->scsi_sense_tail].w.ASC = ASC << 8; hmsc->scsi_sense_tail++; - if (hmsc->scsi_sense_tail == SENSE_LIST_DEEPTH) - { + if (hmsc->scsi_sense_tail == SENSE_LIST_DEEPTH) { hmsc->scsi_sense_tail = 0U; } } @@ -438,7 +416,7 @@ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_ */ static int8_t SCSI_StartStopUnit(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->pClassData; hmsc->bot_data_length = 0U; return 0; } @@ -452,19 +430,16 @@ 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->pClassData; - if(hmsc->bot_state == USBD_BOT_IDLE) /* Idle */ - { + if (hmsc->bot_state == USBD_BOT_IDLE) { /* Idle */ /* case 10 : Ho <> Di */ - if ((hmsc->cbw.bmFlags & 0x80U) != 0x80U) - { + if ((hmsc->cbw.bmFlags & 0x80U) != 0x80U) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } - if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0) - { + if (((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; } @@ -472,21 +447,19 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) | ((uint32_t)params[3] << 16) | ((uint32_t)params[4] << 8) | - (uint32_t)params[5]; + (uint32_t)params[5]; - hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) | (uint32_t)params[8]; + hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) | (uint32_t)params[8]; - if(SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, - hmsc->scsi_blk_len) < 0) - { + if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, + hmsc->scsi_blk_len) < 0) { return -1; /* error */ } hmsc->bot_state = USBD_BOT_DATA_IN; /* cases 4,5 : Hi <> Dn */ - if (hmsc->cbw.dDataLength != (hmsc->scsi_blk_len * hmsc->scsi_blk_size)) - { + if (hmsc->cbw.dDataLength != (hmsc->scsi_blk_len * hmsc->scsi_blk_size)) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } @@ -504,30 +477,26 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params * @retval status */ -static int8_t SCSI_Write10 (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->pClassData; uint32_t len; - if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */ - { + if (hmsc->bot_state == USBD_BOT_IDLE) { /* Idle */ /* case 8 : Hi <> Do */ - if ((hmsc->cbw.bmFlags & 0x80U) == 0x80U) - { + if ((hmsc->cbw.bmFlags & 0x80U) == 0x80U) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } /* Check whether Media is ready */ - if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0) - { + if (((USBD_StorageTypeDef *)pdev->pUserData)->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->pUserData)->IsWriteProtected(lun) != 0) { SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED); return -1; } @@ -535,23 +504,21 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) | ((uint32_t)params[3] << 16) | ((uint32_t)params[4] << 8) | - (uint32_t)params[5]; + (uint32_t)params[5]; hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) | - (uint32_t)params[8]; + (uint32_t)params[8]; /* check if LBA address is in the right range */ - if(SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, - hmsc->scsi_blk_len) < 0) - { + if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, + hmsc->scsi_blk_len) < 0) { return -1; /* error */ } len = hmsc->scsi_blk_len * hmsc->scsi_blk_size; /* cases 3,11,13 : Hn,Ho <> D0 */ - if (hmsc->cbw.dDataLength != len) - { + if (hmsc->cbw.dDataLength != len) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } @@ -560,10 +527,8 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa /* Prepare EP to receive first data packet */ hmsc->bot_state = USBD_BOT_DATA_OUT; - USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len); - } - else /* Write Process ongoing */ - { + USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len); + } else { /* Write Process ongoing */ return SCSI_ProcessWrite(pdev, lun); } return 0; @@ -578,19 +543,17 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa * @retval status */ -static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params) +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->pClassData; - if ((params[1]& 0x02U) == 0x02U) - { + if ((params[1] & 0x02U) == 0x02U) { SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND); return -1; /* Error, Verify Mode Not supported*/ } - if(SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, - hmsc->scsi_blk_len) < 0) - { + if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, + hmsc->scsi_blk_len) < 0) { return -1; /* error */ } hmsc->bot_data_length = 0U; @@ -605,13 +568,12 @@ static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa * @param blk_nbr: number of block to be processed * @retval status */ -static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun, - uint32_t blk_offset, uint32_t blk_nbr) +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->pClassData; - if ((blk_offset + blk_nbr) > hmsc->scsi_blk_nbr) - { + if ((blk_offset + blk_nbr) > hmsc->scsi_blk_nbr) { SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, ADDRESS_OUT_OF_RANGE); return -1; } @@ -624,23 +586,22 @@ static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun, * @param lun: Logical unit number * @retval status */ -static int8_t SCSI_ProcessRead (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->pClassData; uint32_t len = hmsc->scsi_blk_len * hmsc->scsi_blk_size; len = MIN(len, MSC_MEDIA_PACKET); - if( ((USBD_StorageTypeDef *)pdev->pUserData)->Read(lun, - hmsc->bot_data, - hmsc->scsi_blk_addr, - (len / hmsc->scsi_blk_size)) < 0) - { + if (((USBD_StorageTypeDef *)pdev->pUserData)->Read(lun, + hmsc->bot_data, + hmsc->scsi_blk_addr, + (len / hmsc->scsi_blk_size)) < 0) { SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, UNRECOVERED_READ_ERROR); return -1; } - USBD_LL_Transmit (pdev, MSC_EPIN_ADDR, hmsc->bot_data, len); + USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, hmsc->bot_data, len); hmsc->scsi_blk_addr += (len / hmsc->scsi_blk_size); hmsc->scsi_blk_len -= (len / hmsc->scsi_blk_size); @@ -648,8 +609,7 @@ static int8_t SCSI_ProcessRead (USBD_HandleTypeDef *pdev, uint8_t lun) /* case 6 : Hi = Di */ hmsc->csw.dDataResidue -= len; - if (hmsc->scsi_blk_len == 0U) - { + if (hmsc->scsi_blk_len == 0U) { hmsc->bot_state = USBD_BOT_LAST_DATA_IN; } return 0; @@ -662,17 +622,16 @@ static int8_t SCSI_ProcessRead (USBD_HandleTypeDef *pdev, uint8_t lun) * @retval status */ -static int8_t SCSI_ProcessWrite (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->pClassData; 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, - hmsc->scsi_blk_addr, - (len / hmsc->scsi_blk_size)) < 0) - { + if (((USBD_StorageTypeDef *)pdev->pUserData)->Write(lun, hmsc->bot_data, + hmsc->scsi_blk_addr, + (len / hmsc->scsi_blk_size)) < 0) { SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, WRITE_FAULT); return -1; @@ -684,15 +643,12 @@ static int8_t SCSI_ProcessWrite (USBD_HandleTypeDef *pdev, uint8_t lun) /* case 12 : Ho = Do */ hmsc->csw.dDataResidue -= len; - if (hmsc->scsi_blk_len == 0U) - { - MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED); - } - else - { + if (hmsc->scsi_blk_len == 0U) { + MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED); + } else { len = MIN((hmsc->scsi_blk_len * hmsc->scsi_blk_size), MSC_MEDIA_PACKET); /* Prepare EP to Receive next packet */ - USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len); + USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len); } return 0; diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_storage_template.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_storage_template.c index d9b621d000..a20e685490 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_storage_template.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_storage_template.c @@ -17,11 +17,11 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbd_msc_storage_template.h" @@ -39,27 +39,27 @@ #define STORAGE_BLK_NBR 0x10000 #define STORAGE_BLK_SIZ 0x200 -int8_t STORAGE_Init (uint8_t lun); +int8_t STORAGE_Init(uint8_t lun); -int8_t STORAGE_GetCapacity (uint8_t lun, +int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size); -int8_t STORAGE_IsReady (uint8_t lun); +int8_t STORAGE_IsReady(uint8_t lun); -int8_t STORAGE_IsWriteProtected (uint8_t lun); +int8_t STORAGE_IsWriteProtected(uint8_t lun); -int8_t STORAGE_Read (uint8_t lun, - uint8_t *buf, - uint32_t blk_addr, - uint16_t blk_len); +int8_t STORAGE_Read(uint8_t lun, + uint8_t *buf, + uint32_t blk_addr, + uint16_t blk_len); -int8_t STORAGE_Write (uint8_t lun, - uint8_t *buf, - uint32_t blk_addr, - uint16_t blk_len); +int8_t STORAGE_Write(uint8_t lun, + uint8_t *buf, + uint32_t blk_addr, + uint16_t blk_len); -int8_t STORAGE_GetMaxLun (void); +int8_t STORAGE_GetMaxLun(void); /* USB Mass storage Standard Inquiry Data */ int8_t STORAGE_Inquirydata[] = {//36 @@ -76,11 +76,10 @@ int8_t STORAGE_Inquirydata[] = {//36 'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */ 'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - '0', '.', '0' ,'1', /* Version : 4 Bytes */ + '0', '.', '0', '1', /* Version : 4 Bytes */ }; -USBD_StorageTypeDef USBD_MSC_Template_fops = -{ +USBD_StorageTypeDef USBD_MSC_Template_fops = { STORAGE_Init, STORAGE_GetCapacity, STORAGE_IsReady, @@ -98,7 +97,7 @@ USBD_StorageTypeDef USBD_MSC_Template_fops = * Output : None. * Return : None. *******************************************************************************/ -int8_t STORAGE_Init (uint8_t lun) +int8_t STORAGE_Init(uint8_t lun) { return (0); } @@ -110,7 +109,7 @@ int8_t STORAGE_Init (uint8_t lun) * Output : None. * Return : None. *******************************************************************************/ -int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint16_t *block_size) +int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size) { *block_num = STORAGE_BLK_NBR; *block_size = STORAGE_BLK_SIZ; @@ -124,7 +123,7 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint16_t *block_si * Output : None. * Return : None. *******************************************************************************/ -int8_t STORAGE_IsReady (uint8_t lun) +int8_t STORAGE_IsReady(uint8_t lun) { return (0); } @@ -136,7 +135,7 @@ int8_t STORAGE_IsReady (uint8_t lun) * Output : None. * Return : None. *******************************************************************************/ -int8_t STORAGE_IsWriteProtected (uint8_t lun) +int8_t STORAGE_IsWriteProtected(uint8_t lun) { return 0; } @@ -148,10 +147,10 @@ int8_t STORAGE_IsWriteProtected (uint8_t lun) * Output : None. * Return : None. *******************************************************************************/ -int8_t STORAGE_Read (uint8_t lun, - uint8_t *buf, - uint32_t blk_addr, - uint16_t blk_len) +int8_t STORAGE_Read(uint8_t lun, + uint8_t *buf, + uint32_t blk_addr, + uint16_t blk_len) { return 0; } @@ -162,10 +161,10 @@ int8_t STORAGE_Read (uint8_t lun, * Output : None. * Return : None. *******************************************************************************/ -int8_t STORAGE_Write (uint8_t lun, - uint8_t *buf, - uint32_t blk_addr, - uint16_t blk_len) +int8_t STORAGE_Write(uint8_t lun, + uint8_t *buf, + uint32_t blk_addr, + uint16_t blk_len) { return (0); } @@ -176,7 +175,7 @@ int8_t STORAGE_Write (uint8_t lun, * Output : None. * Return : None. *******************************************************************************/ -int8_t STORAGE_GetMaxLun (void) +int8_t STORAGE_GetMaxLun(void) { return (STORAGE_LUN_NBR - 1); } diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/Template/Inc/usbd_template.h b/system/Middlewares/ST/STM32_USB_Device_Library/Class/Template/Inc/usbd_template.h index e9792e8c81..c461333569 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/Template/Inc/usbd_template.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/Template/Inc/usbd_template.h @@ -22,7 +22,7 @@ #define __USB_TEMPLATE_CORE_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Class/Template/Src/usbd_template.c b/system/Middlewares/ST/STM32_USB_Device_Library/Class/Template/Src/usbd_template.c index 533b89dfc2..3322f48431 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Class/Template/Src/usbd_template.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Class/Template/Src/usbd_template.c @@ -83,32 +83,32 @@ */ -static uint8_t USBD_TEMPLATE_Init (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -static uint8_t USBD_TEMPLATE_DeInit (USBD_HandleTypeDef *pdev, - uint8_t cfgidx); +static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev, + uint8_t cfgidx); -static uint8_t USBD_TEMPLATE_Setup (USBD_HandleTypeDef *pdev, - USBD_SetupReqTypedef *req); +static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req); -static uint8_t *USBD_TEMPLATE_GetCfgDesc (uint16_t *length); +static uint8_t *USBD_TEMPLATE_GetCfgDesc(uint16_t *length); -static uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc (uint16_t *length); +static uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length); -static uint8_t USBD_TEMPLATE_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_TEMPLATE_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_TEMPLATE_EP0_RxReady (USBD_HandleTypeDef *pdev); +static uint8_t USBD_TEMPLATE_EP0_RxReady(USBD_HandleTypeDef *pdev); -static uint8_t USBD_TEMPLATE_EP0_TxReady (USBD_HandleTypeDef *pdev); +static uint8_t USBD_TEMPLATE_EP0_TxReady(USBD_HandleTypeDef *pdev); -static uint8_t USBD_TEMPLATE_SOF (USBD_HandleTypeDef *pdev); +static uint8_t USBD_TEMPLATE_SOF(USBD_HandleTypeDef *pdev); -static uint8_t USBD_TEMPLATE_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_TEMPLATE_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_TEMPLATE_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum); +static uint8_t USBD_TEMPLATE_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); /** * @} @@ -118,8 +118,7 @@ static uint8_t USBD_TEMPLATE_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_ * @{ */ -USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver = -{ +USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver = { USBD_TEMPLATE_Init, USBD_TEMPLATE_DeInit, USBD_TEMPLATE_Setup, @@ -137,11 +136,10 @@ USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver = }; #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 +#pragma data_alignment=4 #endif /* USB TEMPLATE device Configuration Descriptor */ -static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] = -{ +static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] = { 0x09, /* bLength: Configuation Descriptor size */ USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, /* bDescriptorType: Configuration */ USB_TEMPLATE_CONFIG_DESC_SIZ, @@ -159,11 +157,10 @@ static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] = }; #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 +#pragma data_alignment=4 #endif /* USB Standard Device Descriptor */ -static uint8_t USBD_TEMPLATE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] = -{ +static uint8_t USBD_TEMPLATE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] = { USB_LEN_DEV_QUALIFIER_DESC, USB_DESC_TYPE_DEVICE_QUALIFIER, 0x00, @@ -191,8 +188,8 @@ static uint8_t USBD_TEMPLATE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] = * @param cfgidx: Configuration index * @retval status */ -static uint8_t USBD_TEMPLATE_Init (USBD_HandleTypeDef *pdev, - uint8_t cfgidx) +static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev, + uint8_t cfgidx) { uint8_t ret = 0; @@ -207,8 +204,8 @@ static uint8_t USBD_TEMPLATE_Init (USBD_HandleTypeDef *pdev, * @param cfgidx: Configuration index * @retval status */ -static uint8_t USBD_TEMPLATE_DeInit (USBD_HandleTypeDef *pdev, - uint8_t cfgidx) +static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev, + uint8_t cfgidx) { return USBD_OK; @@ -221,37 +218,34 @@ static uint8_t USBD_TEMPLATE_DeInit (USBD_HandleTypeDef *pdev, * @param req: usb requests * @retval status */ -static uint8_t USBD_TEMPLATE_Setup (USBD_HandleTypeDef *pdev, - USBD_SetupReqTypedef *req) +static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req) { USBD_StatusTypeDef ret = USBD_OK; - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS : - switch (req->bRequest) - { - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; + switch (req->bmRequest & USB_REQ_TYPE_MASK) { + case USB_REQ_TYPE_CLASS : + switch (req->bRequest) { + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } + break; + + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } break; - } - break; - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { default: - USBD_CtlError (pdev, req); + USBD_CtlError(pdev, req); ret = USBD_FAIL; break; - } - break; - - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; } return ret; @@ -264,9 +258,9 @@ static uint8_t USBD_TEMPLATE_Setup (USBD_HandleTypeDef *pdev, * @param length : pointer data length * @retval pointer to descriptor buffer */ -static uint8_t *USBD_TEMPLATE_GetCfgDesc (uint16_t *length) +static uint8_t *USBD_TEMPLATE_GetCfgDesc(uint16_t *length) { - *length = sizeof (USBD_TEMPLATE_CfgDesc); + *length = sizeof(USBD_TEMPLATE_CfgDesc); return USBD_TEMPLATE_CfgDesc; } @@ -276,9 +270,9 @@ static uint8_t *USBD_TEMPLATE_GetCfgDesc (uint16_t *length) * @param length : pointer data length * @retval pointer to descriptor buffer */ -uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor (uint16_t *length) +uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor(uint16_t *length) { - *length = sizeof (USBD_TEMPLATE_DeviceQualifierDesc); + *length = sizeof(USBD_TEMPLATE_DeviceQualifierDesc); return USBD_TEMPLATE_DeviceQualifierDesc; } @@ -290,8 +284,8 @@ uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor (uint16_t *length) * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_TEMPLATE_DataIn (USBD_HandleTypeDef *pdev, - uint8_t epnum) +static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev, + uint8_t epnum) { return USBD_OK; @@ -303,7 +297,7 @@ static uint8_t USBD_TEMPLATE_DataIn (USBD_HandleTypeDef *pdev, * @param pdev: device instance * @retval status */ -static uint8_t USBD_TEMPLATE_EP0_RxReady (USBD_HandleTypeDef *pdev) +static uint8_t USBD_TEMPLATE_EP0_RxReady(USBD_HandleTypeDef *pdev) { return USBD_OK; @@ -314,7 +308,7 @@ static uint8_t USBD_TEMPLATE_EP0_RxReady (USBD_HandleTypeDef *pdev) * @param pdev: device instance * @retval status */ -static uint8_t USBD_TEMPLATE_EP0_TxReady (USBD_HandleTypeDef *pdev) +static uint8_t USBD_TEMPLATE_EP0_TxReady(USBD_HandleTypeDef *pdev) { return USBD_OK; @@ -325,7 +319,7 @@ static uint8_t USBD_TEMPLATE_EP0_TxReady (USBD_HandleTypeDef *pdev) * @param pdev: device instance * @retval status */ -static uint8_t USBD_TEMPLATE_SOF (USBD_HandleTypeDef *pdev) +static uint8_t USBD_TEMPLATE_SOF(USBD_HandleTypeDef *pdev) { return USBD_OK; @@ -337,7 +331,7 @@ static uint8_t USBD_TEMPLATE_SOF (USBD_HandleTypeDef *pdev) * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_TEMPLATE_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum) +static uint8_t USBD_TEMPLATE_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) { return USBD_OK; @@ -349,7 +343,7 @@ static uint8_t USBD_TEMPLATE_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_TEMPLATE_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum) +static uint8_t USBD_TEMPLATE_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) { return USBD_OK; @@ -361,8 +355,8 @@ static uint8_t USBD_TEMPLATE_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_ * @param epnum: endpoint index * @retval status */ -static uint8_t USBD_TEMPLATE_DataOut (USBD_HandleTypeDef *pdev, - uint8_t epnum) +static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev, + uint8_t epnum) { return USBD_OK; @@ -374,9 +368,9 @@ static uint8_t USBD_TEMPLATE_DataOut (USBD_HandleTypeDef *pdev, * @param length : pointer data length * @retval pointer to descriptor buffer */ -uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc (uint16_t *length) +uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length) { - *length = sizeof (USBD_TEMPLATE_DeviceQualifierDesc); + *length = sizeof(USBD_TEMPLATE_DeviceQualifierDesc); return USBD_TEMPLATE_DeviceQualifierDesc; } diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_conf_template.h b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_conf_template.h index 7d91fa4068..43fce2c04e 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_conf_template.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_conf_template.h @@ -22,7 +22,7 @@ #define __USBD_CONF_TEMPLATE_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -57,18 +57,18 @@ /* CDC Class Config */ #define USBD_CDC_INTERVAL 2000U - /* DFU Class Config */ +/* DFU Class Config */ #define USBD_DFU_MAX_ITF_NUM 1U #define USBD_DFU_XFERS_IZE 1024U - /* AUDIO Class Config */ +/* AUDIO Class Config */ #define USBD_AUDIO_FREQ 22100U /** @defgroup USBD_Exported_Macros * @{ */ - /* Memory management macros */ +/* Memory management macros */ #define USBD_malloc malloc #define USBD_free free #define USBD_memset memset diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h index 31ec3b026d..883b647388 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h @@ -22,7 +22,7 @@ #define __USBD_CORE_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -84,17 +84,17 @@ */ USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id); USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev); +USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev); +USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev); USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass); -USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev); +USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev); USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup); -USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata); -USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata); +USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); +USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev); USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed); @@ -109,33 +109,33 @@ USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev); USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev); /* USBD Low Level Driver */ -USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev); +USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev); +USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev); USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev, - uint8_t ep_addr, - uint8_t ep_type, - uint16_t ep_mps); - -USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); -USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); -USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); -USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); -uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); -USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr); -USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev, - uint8_t ep_addr, - uint8_t *pbuf, - uint16_t size); +USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev); +USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, + uint8_t ep_addr, + uint8_t ep_type, + uint16_t ep_mps); + +USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); +USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); +USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); +USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); +uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); +USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr); +USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, + uint8_t ep_addr, + uint8_t *pbuf, + uint16_t size); USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size); -uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr); -void USBD_LL_Delay (uint32_t Delay); +uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr); +void USBD_LL_Delay(uint32_t Delay); /** * @} diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h index 9fa2873ad2..b5fe8f0a39 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h @@ -22,7 +22,7 @@ #define __USB_REQUEST_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -73,16 +73,16 @@ * @{ */ -USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); +USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); +USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); +USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); +void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata); +void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata); -void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len); +void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); /** * @} */ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h index b1e7968d2d..34913a51d9 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h @@ -22,7 +22,7 @@ #define __USBD_DEF_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -156,76 +156,71 @@ * @{ */ -typedef struct usb_setup_req -{ +typedef struct usb_setup_req { - uint8_t bmRequest; - uint8_t bRequest; - uint16_t wValue; - uint16_t wIndex; - uint16_t wLength; -}USBD_SetupReqTypedef; + uint8_t bmRequest; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; +} USBD_SetupReqTypedef; struct _USBD_HandleTypeDef; -typedef struct _Device_cb -{ - uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx); - uint8_t (*DeInit) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx); - /* Control Endpoints*/ - uint8_t (*Setup) (struct _USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req); - uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev ); - uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev ); +typedef struct _Device_cb { + uint8_t (*Init)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx); + uint8_t (*DeInit)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx); + /* Control Endpoints*/ + uint8_t (*Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); + uint8_t (*EP0_TxSent)(struct _USBD_HandleTypeDef *pdev); + uint8_t (*EP0_RxReady)(struct _USBD_HandleTypeDef *pdev); /* Class Specific Endpoints*/ - uint8_t (*DataIn) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); - uint8_t (*DataOut) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); - uint8_t (*SOF) (struct _USBD_HandleTypeDef *pdev); - uint8_t (*IsoINIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); - uint8_t (*IsoOUTIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); + uint8_t (*DataIn)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); + uint8_t (*DataOut)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); + uint8_t (*SOF)(struct _USBD_HandleTypeDef *pdev); + uint8_t (*IsoINIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); + uint8_t (*IsoOUTIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); uint8_t *(*GetHSConfigDescriptor)(uint16_t *length); uint8_t *(*GetFSConfigDescriptor)(uint16_t *length); uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length); uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length); #if (USBD_SUPPORT_USER_STRING == 1U) - uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev ,uint8_t index, uint16_t *length); + uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length); #endif } USBD_ClassTypeDef; /* Following USB Device Speed */ -typedef enum -{ +typedef enum { USBD_SPEED_HIGH = 0U, USBD_SPEED_FULL = 1U, USBD_SPEED_LOW = 2U, -}USBD_SpeedTypeDef; +} USBD_SpeedTypeDef; /* Following USB Device status */ typedef enum { USBD_OK = 0U, USBD_BUSY, USBD_FAIL, -}USBD_StatusTypeDef; +} USBD_StatusTypeDef; /* USB Device descriptors structure */ -typedef struct -{ - uint8_t *(*GetDeviceDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); - uint8_t *(*GetLangIDStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); - uint8_t *(*GetManufacturerStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); - uint8_t *(*GetProductStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); - uint8_t *(*GetSerialStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); - uint8_t *(*GetConfigurationStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); - uint8_t *(*GetInterfaceStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); +typedef struct { + uint8_t *(*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); + uint8_t *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); + uint8_t *(*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); + uint8_t *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); + uint8_t *(*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); + uint8_t *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); + uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); #if (USBD_LPM_ENABLED == 1U) - uint8_t *(*GetBOSDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); + uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); #endif } USBD_DescriptorsTypeDef; /* USB Device handle structure */ -typedef struct -{ +typedef struct { uint32_t status; uint32_t is_used; uint32_t total_length; @@ -234,8 +229,7 @@ typedef struct } USBD_EndpointTypeDef; /* USB Device handle structure */ -typedef struct _USBD_HandleTypeDef -{ +typedef struct _USBD_HandleTypeDef { uint8_t id; uint32_t dev_config; uint32_t dev_default_config; @@ -279,12 +273,12 @@ typedef struct _USBD_HandleTypeDef #if defined ( __GNUC__ ) - #ifndef __weak - #define __weak __attribute__((weak)) - #endif /* __weak */ - #ifndef __packed - #define __packed __attribute__((__packed__)) - #endif /* __packed */ +#ifndef __weak +#define __weak __attribute__((weak)) +#endif /* __weak */ +#ifndef __packed +#define __packed __attribute__((__packed__)) +#endif /* __packed */ #endif /* __GNUC__ */ @@ -292,17 +286,17 @@ typedef struct _USBD_HandleTypeDef with the DMA during the transaction process should be 4-bytes aligned */ #if defined (__GNUC__) /* GNU Compiler */ - #define __ALIGN_END __attribute__ ((aligned (4))) - #define __ALIGN_BEGIN +#define __ALIGN_END __attribute__ ((aligned (4))) +#define __ALIGN_BEGIN #else - #define __ALIGN_END - #if defined (__CC_ARM) /* ARM Compiler */ - #define __ALIGN_BEGIN __align(4) - #elif defined (__ICCARM__) /* IAR Compiler */ - #define __ALIGN_BEGIN - #elif defined (__TASKING__) /* TASKING Compiler */ - #define __ALIGN_BEGIN __align(4) - #endif /* __CC_ARM */ +#define __ALIGN_END +#if defined (__CC_ARM) /* ARM Compiler */ +#define __ALIGN_BEGIN __align(4) +#elif defined (__ICCARM__) /* IAR Compiler */ +#define __ALIGN_BEGIN +#elif defined (__TASKING__) /* TASKING Compiler */ +#define __ALIGN_BEGIN __align(4) +#endif /* __CC_ARM */ #endif /* __GNUC__ */ diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h index 0552e00f63..2742f52538 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h @@ -22,7 +22,7 @@ #define __USBD_IOREQ_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -77,27 +77,27 @@ * @{ */ -USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, - uint8_t *pbuf, - uint16_t len); +USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, + uint8_t *pbuf, + uint16_t len); -USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, - uint8_t *pbuf, - uint16_t len); +USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, + uint8_t *pbuf, + uint16_t len); -USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, - uint8_t *pbuf, - uint16_t len); +USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, + uint8_t *pbuf, + uint16_t len); -USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, - uint8_t *pbuf, - uint16_t len); +USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, + uint8_t *pbuf, + uint16_t len); -USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev); +USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev); -USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev); +USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev); -uint32_t USBD_GetRxCount (USBD_HandleTypeDef *pdev, uint8_t ep_addr); +uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr); /** * @} diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_conf_template.c b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_conf_template.c index 983e763eb0..9f7039bfc3 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_conf_template.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_conf_template.c @@ -135,7 +135,7 @@ USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_add */ uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) { - return 0; + return 0; } /** diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c index 8ccf17ee5c..95a64d21e8 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c @@ -88,8 +88,7 @@ USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id) { /* Check whether the USB Host handle is valid */ - if(pdev == NULL) - { + if (pdev == NULL) { #if (USBD_DEBUG_LEVEL > 1U) USBD_ErrLog("Invalid Device handle"); #endif @@ -97,14 +96,12 @@ USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef * } /* Unlink previous class*/ - if(pdev->pClass != NULL) - { + if (pdev->pClass != NULL) { pdev->pClass = NULL; } /* Assign USBD Descriptors */ - if(pdesc != NULL) - { + if (pdesc != NULL) { pdev->pDesc = pdesc; } @@ -131,7 +128,7 @@ USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev) /* Free Class Resources */ pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config); - /* Stop the low level driver */ + /* Stop the low level driver */ USBD_LL_Stop(pdev); /* Initialize low level driver */ @@ -150,14 +147,11 @@ USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev) USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass) { USBD_StatusTypeDef status = USBD_OK; - if(pclass != 0) - { + if (pclass != 0) { /* link the class to the USB Device handle */ pdev->pClass = pclass; status = USBD_OK; - } - else - { + } else { #if (USBD_DEBUG_LEVEL > 1U) USBD_ErrLog("Invalid Class handle"); #endif @@ -173,7 +167,7 @@ USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeD * @param pdev: Device Handle * @retval USBD Status */ -USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev) +USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev) { /* Start the low level driver */ @@ -188,7 +182,7 @@ USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev) * @param pdev: Device Handle * @retval USBD Status */ -USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev) +USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev) { /* Free Class Resources */ pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config); @@ -205,7 +199,7 @@ USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev) * @param pdev: device instance * @retval status */ -USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev) +USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev) { /* Prevent unused argument compilation warning */ UNUSED(pdev); @@ -225,11 +219,9 @@ USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx { USBD_StatusTypeDef ret = USBD_FAIL; - if(pdev->pClass != NULL) - { + if (pdev->pClass != NULL) { /* Set configuration and Start the Class*/ - if(pdev->pClass->Init(pdev, cfgidx) == 0U) - { + if (pdev->pClass->Init(pdev, cfgidx) == 0U) { ret = USBD_OK; } } @@ -266,23 +258,22 @@ USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup) pdev->ep0_data_len = pdev->request.wLength; - switch (pdev->request.bmRequest & 0x1FU) - { - case USB_REQ_RECIPIENT_DEVICE: - USBD_StdDevReq (pdev, &pdev->request); - break; + switch (pdev->request.bmRequest & 0x1FU) { + case USB_REQ_RECIPIENT_DEVICE: + USBD_StdDevReq(pdev, &pdev->request); + break; - case USB_REQ_RECIPIENT_INTERFACE: - USBD_StdItfReq(pdev, &pdev->request); - break; + case USB_REQ_RECIPIENT_INTERFACE: + USBD_StdItfReq(pdev, &pdev->request); + break; - case USB_REQ_RECIPIENT_ENDPOINT: - USBD_StdEPReq(pdev, &pdev->request); - break; + case USB_REQ_RECIPIENT_ENDPOINT: + USBD_StdEPReq(pdev, &pdev->request); + break; - default: - USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U)); - break; + default: + USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U)); + break; } return USBD_OK; @@ -300,34 +291,25 @@ USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, { USBD_EndpointTypeDef *pep; - if(epnum == 0U) - { + if (epnum == 0U) { pep = &pdev->ep_out[0]; - if ( pdev->ep0_state == USBD_EP0_DATA_OUT) - { - if(pep->rem_length > pep->maxpacket) - { + if (pdev->ep0_state == USBD_EP0_DATA_OUT) { + if (pep->rem_length > pep->maxpacket) { pep->rem_length -= pep->maxpacket; - USBD_CtlContinueRx (pdev, - pdata, - (uint16_t)MIN(pep->rem_length, pep->maxpacket)); - } - else - { - if((pdev->pClass->EP0_RxReady != NULL)&& - (pdev->dev_state == USBD_STATE_CONFIGURED)) - { + USBD_CtlContinueRx(pdev, + pdata, + (uint16_t)MIN(pep->rem_length, pep->maxpacket)); + } else { + if ((pdev->pClass->EP0_RxReady != NULL) && + (pdev->dev_state == USBD_STATE_CONFIGURED)) { pdev->pClass->EP0_RxReady(pdev); } USBD_CtlSendStatus(pdev); } - } - else - { - if (pdev->ep0_state == USBD_EP0_STATUS_OUT) - { + } else { + if (pdev->ep0_state == USBD_EP0_STATUS_OUT) { /* * STATUS PHASE completed, update ep0_state to idle */ @@ -335,14 +317,10 @@ USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, USBD_LL_StallEP(pdev, 0U); } } - } - else if((pdev->pClass->DataOut != NULL) && - (pdev->dev_state == USBD_STATE_CONFIGURED)) - { + } else if ((pdev->pClass->DataOut != NULL) && + (pdev->dev_state == USBD_STATE_CONFIGURED)) { pdev->pClass->DataOut(pdev, epnum); - } - else - { + } else { /* should never be in this condition */ return USBD_FAIL; } @@ -362,38 +340,30 @@ USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, { USBD_EndpointTypeDef *pep; - if(epnum == 0U) - { + if (epnum == 0U) { pep = &pdev->ep_in[0]; - if ( pdev->ep0_state == USBD_EP0_DATA_IN) - { - if(pep->rem_length > pep->maxpacket) - { + if (pdev->ep0_state == USBD_EP0_DATA_IN) { + if (pep->rem_length > pep->maxpacket) { pep->rem_length -= pep->maxpacket; - USBD_CtlContinueSendData (pdev, pdata, (uint16_t)pep->rem_length); + USBD_CtlContinueSendData(pdev, pdata, (uint16_t)pep->rem_length); /* Prepare endpoint for premature end of transfer */ - USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U); - } - else - { /* last packet is MPS multiple, so send ZLP packet */ - if((pep->total_length % pep->maxpacket == 0U) && - (pep->total_length >= pep->maxpacket) && - (pep->total_length < pdev->ep0_data_len)) - { + USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); + } else { + /* last packet is MPS multiple, so send ZLP packet */ + if ((pep->total_length % pep->maxpacket == 0U) && + (pep->total_length >= pep->maxpacket) && + (pep->total_length < pdev->ep0_data_len)) { USBD_CtlContinueSendData(pdev, NULL, 0U); pdev->ep0_data_len = 0U; /* Prepare endpoint for premature end of transfer */ - USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U); - } - else - { - if((pdev->pClass->EP0_TxSent != NULL)&& - (pdev->dev_state == USBD_STATE_CONFIGURED)) - { + USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); + } else { + if ((pdev->pClass->EP0_TxSent != NULL) && + (pdev->dev_state == USBD_STATE_CONFIGURED)) { pdev->pClass->EP0_TxSent(pdev); } /* @@ -405,29 +375,21 @@ USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, USBD_CtlReceiveStatus(pdev); } } - } - else - { + } else { if ((pdev->ep0_state == USBD_EP0_STATUS_IN) || - (pdev->ep0_state == USBD_EP0_IDLE)) - { + (pdev->ep0_state == USBD_EP0_IDLE)) { USBD_LL_StallEP(pdev, 0x80U); } } - if (pdev->dev_test_mode == 1U) - { + if (pdev->dev_test_mode == 1U) { USBD_RunTestMode(pdev); pdev->dev_test_mode = 0U; } - } - else if((pdev->pClass->DataIn != NULL) && - (pdev->dev_state == USBD_STATE_CONFIGURED)) - { + } else if ((pdev->pClass->DataIn != NULL) && + (pdev->dev_state == USBD_STATE_CONFIGURED)) { pdev->pClass->DataIn(pdev, epnum); - } - else - { + } else { /* should never be in this condition */ return USBD_FAIL; } @@ -458,11 +420,10 @@ USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev) /* Upon Reset call user call back */ pdev->dev_state = USBD_STATE_DEFAULT; pdev->ep0_state = USBD_EP0_IDLE; - pdev->dev_config= 0U; + pdev->dev_config = 0U; pdev->dev_remote_wakeup = 0U; - if (pdev->pClassData) - { + if (pdev->pClassData) { pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config); } @@ -517,10 +478,8 @@ USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev) USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev) { - if(pdev->dev_state == USBD_STATE_CONFIGURED) - { - if(pdev->pClass->SOF != NULL) - { + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + if (pdev->pClass->SOF != NULL) { pdev->pClass->SOF(pdev); } } diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c index c3e7ecbe80..c1edccee26 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c @@ -68,25 +68,25 @@ /** @defgroup USBD_REQ_Private_FunctionPrototypes * @{ */ -static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev , +static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_SetAddress(USBD_HandleTypeDef *pdev , +static void USBD_SetAddress(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_SetConfig(USBD_HandleTypeDef *pdev , +static void USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_GetConfig(USBD_HandleTypeDef *pdev , +static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_GetStatus(USBD_HandleTypeDef *pdev , +static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_SetFeature(USBD_HandleTypeDef *pdev , +static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_ClrFeature(USBD_HandleTypeDef *pdev , +static void USBD_ClrFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); static uint8_t USBD_GetLen(uint8_t *buf); @@ -108,60 +108,58 @@ static uint8_t USBD_GetLen(uint8_t *buf); * @param req: usb request * @retval status */ -USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) +USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { USBD_StatusTypeDef ret = USBD_OK; - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS: - case USB_REQ_TYPE_VENDOR: - pdev->pClass->Setup(pdev, req); - break; + switch (req->bmRequest & USB_REQ_TYPE_MASK) { + case USB_REQ_TYPE_CLASS: + case USB_REQ_TYPE_VENDOR: + pdev->pClass->Setup(pdev, req); + break; - case USB_REQ_TYPE_STANDARD: + case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_DESCRIPTOR: + switch (req->bRequest) { + case USB_REQ_GET_DESCRIPTOR: - USBD_GetDescriptor (pdev, req); - break; + USBD_GetDescriptor(pdev, req); + break; - case USB_REQ_SET_ADDRESS: - USBD_SetAddress (pdev, req); - break; + case USB_REQ_SET_ADDRESS: + USBD_SetAddress(pdev, req); + break; - case USB_REQ_SET_CONFIGURATION: - USBD_SetConfig (pdev, req); - break; + case USB_REQ_SET_CONFIGURATION: + USBD_SetConfig(pdev, req); + break; - case USB_REQ_GET_CONFIGURATION: - USBD_GetConfig (pdev, req); - break; + case USB_REQ_GET_CONFIGURATION: + USBD_GetConfig(pdev, req); + break; - case USB_REQ_GET_STATUS: - USBD_GetStatus (pdev, req); - break; + case USB_REQ_GET_STATUS: + USBD_GetStatus(pdev, req); + break; - case USB_REQ_SET_FEATURE: - USBD_SetFeature (pdev, req); - break; + case USB_REQ_SET_FEATURE: + USBD_SetFeature(pdev, req); + break; + + case USB_REQ_CLEAR_FEATURE: + USBD_ClrFeature(pdev, req); + break; - case USB_REQ_CLEAR_FEATURE: - USBD_ClrFeature (pdev, req); + default: + USBD_CtlError(pdev, req); + break; + } break; default: USBD_CtlError(pdev, req); break; - } - break; - - default: - USBD_CtlError(pdev, req); - break; } return ret; @@ -174,45 +172,39 @@ USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev , USBD_SetupReqType * @param req: usb request * @retval status */ -USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) +USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { USBD_StatusTypeDef ret = USBD_OK; - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS: - case USB_REQ_TYPE_VENDOR: - case USB_REQ_TYPE_STANDARD: - switch (pdev->dev_state) - { - case USBD_STATE_DEFAULT: - case USBD_STATE_ADDRESSED: - case USBD_STATE_CONFIGURED: - - if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES) - { - ret = (USBD_StatusTypeDef)pdev->pClass->Setup (pdev, req); + switch (req->bmRequest & USB_REQ_TYPE_MASK) { + case USB_REQ_TYPE_CLASS: + case USB_REQ_TYPE_VENDOR: + case USB_REQ_TYPE_STANDARD: + switch (pdev->dev_state) { + case USBD_STATE_DEFAULT: + case USBD_STATE_ADDRESSED: + case USBD_STATE_CONFIGURED: + + if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES) { + ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req); + + if ((req->wLength == 0U) && (ret == USBD_OK)) { + USBD_CtlSendStatus(pdev); + } + } else { + USBD_CtlError(pdev, req); + } + break; - if ((req->wLength == 0U) && (ret == USBD_OK)) - { - USBD_CtlSendStatus(pdev); - } - } - else - { - USBD_CtlError(pdev, req); + default: + USBD_CtlError(pdev, req); + break; } break; default: USBD_CtlError(pdev, req); break; - } - break; - - default: - USBD_CtlError(pdev, req); - break; } return USBD_OK; @@ -225,7 +217,7 @@ USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev , USBD_SetupReqType * @param req: usb request * @retval status */ -USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) +USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { uint8_t ep_addr; @@ -233,162 +225,135 @@ USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTyped USBD_EndpointTypeDef *pep; ep_addr = LOBYTE(req->wIndex); - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - - case USB_REQ_TYPE_CLASS: - case USB_REQ_TYPE_VENDOR: - pdev->pClass->Setup (pdev, req); - break; + switch (req->bmRequest & USB_REQ_TYPE_MASK) { - case USB_REQ_TYPE_STANDARD: - /* Check if it is a class request */ - if ((req->bmRequest & 0x60U) == 0x20U) - { - ret = (USBD_StatusTypeDef)pdev->pClass->Setup (pdev, req); - - return ret; - } - - switch (req->bRequest) - { - - case USB_REQ_SET_FEATURE : - - switch (pdev->dev_state) - { - case USBD_STATE_ADDRESSED: - if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) - { - USBD_LL_StallEP(pdev, ep_addr); - USBD_LL_StallEP(pdev, 0x80U); - } - else - { - USBD_CtlError(pdev, req); - } - break; - - case USBD_STATE_CONFIGURED: - if (req->wValue == USB_FEATURE_EP_HALT) - { - if ((ep_addr != 0x00U) && (ep_addr != 0x80U) && (req->wLength == 0x00U)) - { - USBD_LL_StallEP(pdev, ep_addr); - } - } - USBD_CtlSendStatus(pdev); - - break; - - default: - USBD_CtlError(pdev, req); - break; - } + case USB_REQ_TYPE_CLASS: + case USB_REQ_TYPE_VENDOR: + pdev->pClass->Setup(pdev, req); break; - case USB_REQ_CLEAR_FEATURE : - - switch (pdev->dev_state) - { - case USBD_STATE_ADDRESSED: - if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) - { - USBD_LL_StallEP(pdev, ep_addr); - USBD_LL_StallEP(pdev, 0x80U); - } - else - { - USBD_CtlError(pdev, req); - } - break; + case USB_REQ_TYPE_STANDARD: + /* Check if it is a class request */ + if ((req->bmRequest & 0x60U) == 0x20U) { + ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req); - case USBD_STATE_CONFIGURED: - if (req->wValue == USB_FEATURE_EP_HALT) - { - if ((ep_addr & 0x7FU) != 0x00U) - { - USBD_LL_ClearStallEP(pdev, ep_addr); - } - USBD_CtlSendStatus(pdev); - } - break; - - default: - USBD_CtlError(pdev, req); - break; + return ret; } - break; - - case USB_REQ_GET_STATUS: - switch (pdev->dev_state) - { - case USBD_STATE_ADDRESSED: - if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) - { - USBD_CtlError(pdev, req); - break; - } - pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU]:\ - &pdev->ep_out[ep_addr & 0x7FU]; - - pep->status = 0x0000U; - USBD_CtlSendData (pdev, (uint8_t *)(void *)&pep->status, 2U); + switch (req->bRequest) { + + case USB_REQ_SET_FEATURE : + + switch (pdev->dev_state) { + case USBD_STATE_ADDRESSED: + if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) { + USBD_LL_StallEP(pdev, ep_addr); + USBD_LL_StallEP(pdev, 0x80U); + } else { + USBD_CtlError(pdev, req); + } + break; + + case USBD_STATE_CONFIGURED: + if (req->wValue == USB_FEATURE_EP_HALT) { + if ((ep_addr != 0x00U) && (ep_addr != 0x80U) && (req->wLength == 0x00U)) { + USBD_LL_StallEP(pdev, ep_addr); + } + } + USBD_CtlSendStatus(pdev); + + break; + + default: + USBD_CtlError(pdev, req); + break; + } break; - case USBD_STATE_CONFIGURED: - if((ep_addr & 0x80U) == 0x80U) - { - if (pdev->ep_in[ep_addr & 0xFU].is_used == 0U) - { - USBD_CtlError(pdev, req); - break; + case USB_REQ_CLEAR_FEATURE : + + switch (pdev->dev_state) { + case USBD_STATE_ADDRESSED: + if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) { + USBD_LL_StallEP(pdev, ep_addr); + USBD_LL_StallEP(pdev, 0x80U); + } else { + USBD_CtlError(pdev, req); + } + break; + + case USBD_STATE_CONFIGURED: + if (req->wValue == USB_FEATURE_EP_HALT) { + if ((ep_addr & 0x7FU) != 0x00U) { + USBD_LL_ClearStallEP(pdev, ep_addr); + } + USBD_CtlSendStatus(pdev); + } + break; + + default: + USBD_CtlError(pdev, req); + break; } - } - else - { - if (pdev->ep_out[ep_addr & 0xFU].is_used == 0U) - { - USBD_CtlError(pdev, req); - break; - } - } - - pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU]:\ - &pdev->ep_out[ep_addr & 0x7FU]; + break; - if ((ep_addr == 0x00U) || (ep_addr == 0x80U)) - { - pep->status = 0x0000U; - } - else if(USBD_LL_IsStallEP(pdev, ep_addr)) - { - pep->status = 0x0001U; - } - else - { - pep->status = 0x0000U; + case USB_REQ_GET_STATUS: + switch (pdev->dev_state) { + case USBD_STATE_ADDRESSED: + if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) { + USBD_CtlError(pdev, req); + break; + } + pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : \ + &pdev->ep_out[ep_addr & 0x7FU]; + + pep->status = 0x0000U; + + USBD_CtlSendData(pdev, (uint8_t *)(void *)&pep->status, 2U); + break; + + case USBD_STATE_CONFIGURED: + if ((ep_addr & 0x80U) == 0x80U) { + if (pdev->ep_in[ep_addr & 0xFU].is_used == 0U) { + USBD_CtlError(pdev, req); + break; + } + } else { + if (pdev->ep_out[ep_addr & 0xFU].is_used == 0U) { + USBD_CtlError(pdev, req); + break; + } + } + + pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : \ + &pdev->ep_out[ep_addr & 0x7FU]; + + if ((ep_addr == 0x00U) || (ep_addr == 0x80U)) { + pep->status = 0x0000U; + } else if (USBD_LL_IsStallEP(pdev, ep_addr)) { + pep->status = 0x0001U; + } else { + pep->status = 0x0000U; + } + + USBD_CtlSendData(pdev, (uint8_t *)(void *)&pep->status, 2U); + break; + + default: + USBD_CtlError(pdev, req); + break; } - - USBD_CtlSendData (pdev, (uint8_t *)(void *)&pep->status, 2U); break; - default: - USBD_CtlError(pdev, req); - break; + default: + USBD_CtlError(pdev, req); + break; } break; default: USBD_CtlError(pdev, req); break; - } - break; - - default: - USBD_CtlError(pdev, req); - break; } return ret; @@ -400,116 +365,103 @@ USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTyped * @param req: usb request * @retval status */ -static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev , +static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { uint16_t len; uint8_t *pbuf; - switch (req->wValue >> 8) - { + switch (req->wValue >> 8) { #if (USBD_LPM_ENABLED == 1U) - case USB_DESC_TYPE_BOS: - pbuf = pdev->pDesc->GetBOSDescriptor(pdev->dev_speed, &len); - break; + case USB_DESC_TYPE_BOS: + pbuf = pdev->pDesc->GetBOSDescriptor(pdev->dev_speed, &len); + break; #endif - case USB_DESC_TYPE_DEVICE: - pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len); - break; - - case USB_DESC_TYPE_CONFIGURATION: - if(pdev->dev_speed == USBD_SPEED_HIGH ) - { - pbuf = (uint8_t *)pdev->pClass->GetHSConfigDescriptor(&len); - pbuf[1] = USB_DESC_TYPE_CONFIGURATION; - } - else - { - pbuf = (uint8_t *)pdev->pClass->GetFSConfigDescriptor(&len); - pbuf[1] = USB_DESC_TYPE_CONFIGURATION; - } - break; - - case USB_DESC_TYPE_STRING: - switch ((uint8_t)(req->wValue)) - { - case USBD_IDX_LANGID_STR: - pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev->dev_speed, &len); + case USB_DESC_TYPE_DEVICE: + pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len); break; - case USBD_IDX_MFC_STR: - pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len); + case USB_DESC_TYPE_CONFIGURATION: + if (pdev->dev_speed == USBD_SPEED_HIGH) { + pbuf = (uint8_t *)pdev->pClass->GetHSConfigDescriptor(&len); + pbuf[1] = USB_DESC_TYPE_CONFIGURATION; + } else { + pbuf = (uint8_t *)pdev->pClass->GetFSConfigDescriptor(&len); + pbuf[1] = USB_DESC_TYPE_CONFIGURATION; + } break; - case USBD_IDX_PRODUCT_STR: - pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len); - break; + case USB_DESC_TYPE_STRING: + switch ((uint8_t)(req->wValue)) { + case USBD_IDX_LANGID_STR: + pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev->dev_speed, &len); + break; - case USBD_IDX_SERIAL_STR: - pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len); - break; + case USBD_IDX_MFC_STR: + pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len); + break; - case USBD_IDX_CONFIG_STR: - pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev->dev_speed, &len); - break; + case USBD_IDX_PRODUCT_STR: + pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len); + break; - case USBD_IDX_INTERFACE_STR: - pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len); - break; + case USBD_IDX_SERIAL_STR: + pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len); + break; - default: + case USBD_IDX_CONFIG_STR: + pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev->dev_speed, &len); + break; + + case USBD_IDX_INTERFACE_STR: + pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len); + break; + + default: #if (USBD_SUPPORT_USER_STRING == 1U) - pbuf = pdev->pClass->GetUsrStrDescriptor(pdev, (req->wValue) , &len); - break; + pbuf = pdev->pClass->GetUsrStrDescriptor(pdev, (req->wValue), &len); + break; #else - USBD_CtlError(pdev , req); - return; + USBD_CtlError(pdev, req); + return; #endif - } - break; - case USB_DESC_TYPE_DEVICE_QUALIFIER: - - if(pdev->dev_speed == USBD_SPEED_HIGH) - { - pbuf = (uint8_t *)pdev->pClass->GetDeviceQualifierDescriptor(&len); + } break; - } - else - { - USBD_CtlError(pdev , req); - return; - } + case USB_DESC_TYPE_DEVICE_QUALIFIER: - case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION: - if(pdev->dev_speed == USBD_SPEED_HIGH ) - { - pbuf = (uint8_t *)pdev->pClass->GetOtherSpeedConfigDescriptor(&len); - pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION; - break; - } - else - { - USBD_CtlError(pdev , req); - return; - } + if (pdev->dev_speed == USBD_SPEED_HIGH) { + pbuf = (uint8_t *)pdev->pClass->GetDeviceQualifierDescriptor(&len); + break; + } else { + USBD_CtlError(pdev, req); + return; + } - default: - USBD_CtlError(pdev , req); - return; + case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION: + if (pdev->dev_speed == USBD_SPEED_HIGH) { + pbuf = (uint8_t *)pdev->pClass->GetOtherSpeedConfigDescriptor(&len); + pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION; + break; + } else { + USBD_CtlError(pdev, req); + return; + } + + default: + USBD_CtlError(pdev, req); + return; } - if((len != 0U) && (req->wLength != 0U)) - { + if ((len != 0U) && (req->wLength != 0U)) { len = MIN(len, req->wLength); - USBD_CtlSendData (pdev, pbuf, len); + USBD_CtlSendData(pdev, pbuf, len); } - if(req->wLength == 0U) - { - USBD_CtlSendStatus(pdev); + if (req->wLength == 0U) { + USBD_CtlSendStatus(pdev); } } @@ -520,37 +472,28 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev , * @param req: usb request * @retval status */ -static void USBD_SetAddress(USBD_HandleTypeDef *pdev , +static void USBD_SetAddress(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { uint8_t dev_addr; - if ((req->wIndex == 0U) && (req->wLength == 0U) && (req->wValue < 128U)) - { + if ((req->wIndex == 0U) && (req->wLength == 0U) && (req->wValue < 128U)) { dev_addr = (uint8_t)(req->wValue) & 0x7FU; - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlError(pdev , req); - } - else - { + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlError(pdev, req); + } else { pdev->dev_address = dev_addr; USBD_LL_SetUSBAddress(pdev, dev_addr); USBD_CtlSendStatus(pdev); - if (dev_addr != 0U) - { + if (dev_addr != 0U) { pdev->dev_state = USBD_STATE_ADDRESSED; - } - else - { + } else { pdev->dev_state = USBD_STATE_DEFAULT; } } - } - else - { + } else { USBD_CtlError(pdev, req); } } @@ -568,64 +511,50 @@ static void USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) cfgidx = (uint8_t)(req->wValue); - if (cfgidx > USBD_MAX_NUM_CONFIGURATION) - { + if (cfgidx > USBD_MAX_NUM_CONFIGURATION) { USBD_CtlError(pdev, req); - } - else - { - switch (pdev->dev_state) - { - case USBD_STATE_ADDRESSED: - if (cfgidx) - { - pdev->dev_config = cfgidx; - pdev->dev_state = USBD_STATE_CONFIGURED; - if(USBD_SetClassConfig(pdev, cfgidx) == USBD_FAIL) - { - USBD_CtlError(pdev, req); - return; + } else { + switch (pdev->dev_state) { + case USBD_STATE_ADDRESSED: + if (cfgidx) { + pdev->dev_config = cfgidx; + pdev->dev_state = USBD_STATE_CONFIGURED; + if (USBD_SetClassConfig(pdev, cfgidx) == USBD_FAIL) { + USBD_CtlError(pdev, req); + return; + } + USBD_CtlSendStatus(pdev); + } else { + USBD_CtlSendStatus(pdev); } - USBD_CtlSendStatus(pdev); - } - else - { - USBD_CtlSendStatus(pdev); - } - break; + break; - case USBD_STATE_CONFIGURED: - if (cfgidx == 0U) - { - pdev->dev_state = USBD_STATE_ADDRESSED; - pdev->dev_config = cfgidx; - USBD_ClrClassConfig(pdev, cfgidx); - USBD_CtlSendStatus(pdev); - } - else if (cfgidx != pdev->dev_config) - { - /* Clear old configuration */ - USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config); - - /* set new configuration */ - pdev->dev_config = cfgidx; - if(USBD_SetClassConfig(pdev, cfgidx) == USBD_FAIL) - { - USBD_CtlError(pdev, req); - return; + case USBD_STATE_CONFIGURED: + if (cfgidx == 0U) { + pdev->dev_state = USBD_STATE_ADDRESSED; + pdev->dev_config = cfgidx; + USBD_ClrClassConfig(pdev, cfgidx); + USBD_CtlSendStatus(pdev); + } else if (cfgidx != pdev->dev_config) { + /* Clear old configuration */ + USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config); + + /* set new configuration */ + pdev->dev_config = cfgidx; + if (USBD_SetClassConfig(pdev, cfgidx) == USBD_FAIL) { + USBD_CtlError(pdev, req); + return; + } + USBD_CtlSendStatus(pdev); + } else { + USBD_CtlSendStatus(pdev); } - USBD_CtlSendStatus(pdev); - } - else - { - USBD_CtlSendStatus(pdev); - } - break; + break; - default: - USBD_CtlError(pdev, req); - USBD_ClrClassConfig(pdev, cfgidx); - break; + default: + USBD_CtlError(pdev, req); + USBD_ClrClassConfig(pdev, cfgidx); + break; } } } @@ -639,27 +568,23 @@ static void USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) */ static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { - if (req->wLength != 1U) - { - USBD_CtlError(pdev , req); - } - else - { - switch (pdev->dev_state) - { - case USBD_STATE_DEFAULT: - case USBD_STATE_ADDRESSED: - pdev->dev_default_config = 0U; - USBD_CtlSendData (pdev, (uint8_t *)(void *)&pdev->dev_default_config, 1U); - break; + if (req->wLength != 1U) { + USBD_CtlError(pdev, req); + } else { + switch (pdev->dev_state) { + case USBD_STATE_DEFAULT: + case USBD_STATE_ADDRESSED: + pdev->dev_default_config = 0U; + USBD_CtlSendData(pdev, (uint8_t *)(void *)&pdev->dev_default_config, 1U); + break; - case USBD_STATE_CONFIGURED: - USBD_CtlSendData (pdev, (uint8_t *)(void *)&pdev->dev_config, 1U); - break; + case USBD_STATE_CONFIGURED: + USBD_CtlSendData(pdev, (uint8_t *)(void *)&pdev->dev_config, 1U); + break; - default: - USBD_CtlError(pdev , req); - break; + default: + USBD_CtlError(pdev, req); + break; } } } @@ -673,34 +598,31 @@ static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) */ static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { - switch (pdev->dev_state) - { - case USBD_STATE_DEFAULT: - case USBD_STATE_ADDRESSED: - case USBD_STATE_CONFIGURED: - if(req->wLength != 0x2U) - { - USBD_CtlError(pdev, req); - break; - } + switch (pdev->dev_state) { + case USBD_STATE_DEFAULT: + case USBD_STATE_ADDRESSED: + case USBD_STATE_CONFIGURED: + if (req->wLength != 0x2U) { + USBD_CtlError(pdev, req); + break; + } #if ( USBD_SELF_POWERED == 1U) - pdev->dev_config_status = USB_CONFIG_SELF_POWERED; + pdev->dev_config_status = USB_CONFIG_SELF_POWERED; #else - pdev->dev_config_status = 0U; + pdev->dev_config_status = 0U; #endif - if (pdev->dev_remote_wakeup) - { - pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP; - } + if (pdev->dev_remote_wakeup) { + pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP; + } - USBD_CtlSendData (pdev, (uint8_t *)(void *)&pdev->dev_config_status, 2U); - break; + USBD_CtlSendData(pdev, (uint8_t *)(void *)&pdev->dev_config_status, 2U); + break; - default : - USBD_CtlError(pdev , req); - break; + default : + USBD_CtlError(pdev, req); + break; } } @@ -712,12 +634,11 @@ static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) * @param req: usb request * @retval status */ -static void USBD_SetFeature(USBD_HandleTypeDef *pdev , +static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { - if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) - { + if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) { pdev->dev_remote_wakeup = 1U; USBD_CtlSendStatus(pdev); } @@ -732,24 +653,22 @@ static void USBD_SetFeature(USBD_HandleTypeDef *pdev , * @param req: usb request * @retval status */ -static void USBD_ClrFeature(USBD_HandleTypeDef *pdev , +static void USBD_ClrFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { - switch (pdev->dev_state) - { - case USBD_STATE_DEFAULT: - case USBD_STATE_ADDRESSED: - case USBD_STATE_CONFIGURED: - if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) - { - pdev->dev_remote_wakeup = 0U; - USBD_CtlSendStatus(pdev); - } - break; + switch (pdev->dev_state) { + case USBD_STATE_DEFAULT: + case USBD_STATE_ADDRESSED: + case USBD_STATE_CONFIGURED: + if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) { + pdev->dev_remote_wakeup = 0U; + USBD_CtlSendStatus(pdev); + } + break; - default : - USBD_CtlError(pdev , req); - break; + default : + USBD_CtlError(pdev, req); + break; } } @@ -763,11 +682,11 @@ static void USBD_ClrFeature(USBD_HandleTypeDef *pdev , void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata) { - req->bmRequest = *(uint8_t *) (pdata); - req->bRequest = *(uint8_t *) (pdata + 1); - req->wValue = SWAPBYTE (pdata + 2); - req->wIndex = SWAPBYTE (pdata + 4); - req->wLength = SWAPBYTE (pdata + 6); + req->bmRequest = *(uint8_t *)(pdata); + req->bRequest = *(uint8_t *)(pdata + 1); + req->wValue = SWAPBYTE(pdata + 2); + req->wIndex = SWAPBYTE(pdata + 4); + req->wLength = SWAPBYTE(pdata + 6); } @@ -779,11 +698,11 @@ void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata) * @retval None */ -void USBD_CtlError( USBD_HandleTypeDef *pdev , - USBD_SetupReqTypedef *req) +void USBD_CtlError(USBD_HandleTypeDef *pdev, + USBD_SetupReqTypedef *req) { - USBD_LL_StallEP(pdev , 0x80U); - USBD_LL_StallEP(pdev , 0U); + USBD_LL_StallEP(pdev, 0x80U); + USBD_LL_StallEP(pdev, 0U); } @@ -799,14 +718,12 @@ void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len) { uint8_t idx = 0U; - if (desc != NULL) - { + if (desc != NULL) { *len = (uint16_t)USBD_GetLen(desc) * 2U + 2U; unicode[idx++] = *(uint8_t *)(void *)len; unicode[idx++] = USB_DESC_TYPE_STRING; - while (*desc != '\0') - { + while (*desc != '\0') { unicode[idx++] = *desc++; unicode[idx++] = 0U; } @@ -821,15 +738,14 @@ void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len) */ static uint8_t USBD_GetLen(uint8_t *buf) { - uint8_t len = 0U; + uint8_t len = 0U; - while (*buf != '\0') - { - len++; - buf++; - } + while (*buf != '\0') { + len++; + buf++; + } - return len; + return len; } /** * @} diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_desc_template.c b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_desc_template.c index e8fcd2d78d..6d3a29dd31 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_desc_template.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_desc_template.c @@ -41,13 +41,13 @@ /* Private function prototypes -----------------------------------------------*/ uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t *USBD_Class_ManufacturerStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t *USBD_Class_ProductStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t *USBD_Class_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); #ifdef USB_SUPPORT_USER_STRING_DESC -uint8_t *USBD_Class_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); +uint8_t *USBD_Class_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); #endif /* USB_SUPPORT_USER_STRING_DESC */ /* Private variables ---------------------------------------------------------*/ @@ -63,7 +63,7 @@ USBD_DescriptorsTypeDef Class_Desc = { /* USB Standard Device Descriptor */ #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 +#pragma data_alignment=4 #endif __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = { 0x12, /* bLength */ @@ -88,7 +88,7 @@ __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = { /* USB Standard Device Descriptor */ #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 +#pragma data_alignment=4 #endif __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = { USB_LEN_LANGID_STR_DESC, @@ -97,19 +97,18 @@ __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = { HIBYTE(USBD_LANGID_STRING), }; -uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] = -{ +uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] = { USB_SIZ_STRING_SERIAL, USB_DESC_TYPE_STRING, }; #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 +#pragma data_alignment=4 #endif __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; /* Private functions ---------------------------------------------------------*/ -static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len); +static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len); static void Get_SerialNum(void); /** @@ -121,7 +120,7 @@ static void Get_SerialNum(void); uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { *length = sizeof(USBD_DeviceDesc); - return (uint8_t*)USBD_DeviceDesc; + return (uint8_t *)USBD_DeviceDesc; } /** @@ -133,7 +132,7 @@ uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { *length = sizeof(USBD_LangIDDesc); - return (uint8_t*)USBD_LangIDDesc; + return (uint8_t *)USBD_LangIDDesc; } /** @@ -144,12 +143,9 @@ uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt */ uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { - if(speed == USBD_SPEED_HIGH) - { + if (speed == USBD_SPEED_HIGH) { USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length); - } - else - { + } else { USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length); } return USBD_StrDesc; @@ -180,7 +176,7 @@ uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt /* Update the serial number string descriptor with the data from the unique ID*/ Get_SerialNum(); - return (uint8_t*)USBD_StringSerial; + return (uint8_t *)USBD_StringSerial; } /** @@ -191,12 +187,9 @@ uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt */ uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { - if(speed == USBD_SPEED_HIGH) - { + if (speed == USBD_SPEED_HIGH) { USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length); - } - else - { + } else { USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length); } return USBD_StrDesc; @@ -210,12 +203,9 @@ uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt */ uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { - if(speed == USBD_SPEED_HIGH) - { + if (speed == USBD_SPEED_HIGH) { USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length); - } - else - { + } else { USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length); } return USBD_StrDesc; @@ -230,16 +220,15 @@ static void Get_SerialNum(void) { uint32_t deviceserial0, deviceserial1, deviceserial2; - deviceserial0 = *(uint32_t*)DEVICE_ID1; - deviceserial1 = *(uint32_t*)DEVICE_ID2; - deviceserial2 = *(uint32_t*)DEVICE_ID3; + deviceserial0 = *(uint32_t *)DEVICE_ID1; + deviceserial1 = *(uint32_t *)DEVICE_ID2; + deviceserial2 = *(uint32_t *)DEVICE_ID3; deviceserial0 += deviceserial2; - if (deviceserial0 != 0) - { - IntToUnicode (deviceserial0, &USBD_StringSerial[2] ,8); - IntToUnicode (deviceserial1, &USBD_StringSerial[18] ,4); + if (deviceserial0 != 0) { + IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); + IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); } } @@ -250,24 +239,20 @@ static void Get_SerialNum(void) * @param len: buffer length * @retval None */ -static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len) +static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len) { uint8_t idx = 0; - for( idx = 0 ; idx < len ; idx ++) - { - if( ((value >> 28)) < 0xA ) - { - pbuf[ 2* idx] = (value >> 28) + '0'; - } - else - { - pbuf[2* idx] = (value >> 28) + 'A' - 10; + for (idx = 0 ; idx < len ; idx ++) { + if (((value >> 28)) < 0xA) { + pbuf[ 2 * idx] = (value >> 28) + '0'; + } else { + pbuf[2 * idx] = (value >> 28) + 'A' - 10; } value = value << 4; - pbuf[ 2* idx + 1] = 0; + pbuf[ 2 * idx + 1] = 0; } } diff --git a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c index 5600c37083..1c58dc3f04 100644 --- a/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c +++ b/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c @@ -84,16 +84,16 @@ * @param len: length of data to be sent * @retval status */ -USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf, - uint16_t len) +USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, + uint16_t len) { /* Set EP0 State */ pdev->ep0_state = USBD_EP0_DATA_IN; pdev->ep_in[0].total_length = len; pdev->ep_in[0].rem_length = len; - /* Start the transfer */ - USBD_LL_Transmit (pdev, 0x00U, pbuf, len); + /* Start the transfer */ + USBD_LL_Transmit(pdev, 0x00U, pbuf, len); return USBD_OK; } @@ -106,11 +106,11 @@ USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf, * @param len: length of data to be sent * @retval status */ -USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, - uint8_t *pbuf, uint16_t len) +USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, + uint8_t *pbuf, uint16_t len) { - /* Start the next transfer */ - USBD_LL_Transmit (pdev, 0x00U, pbuf, len); + /* Start the next transfer */ + USBD_LL_Transmit(pdev, 0x00U, pbuf, len); return USBD_OK; } @@ -123,8 +123,8 @@ USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, * @param len: length of data to be received * @retval status */ -USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, - uint16_t len) +USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, uint8_t *pbuf, + uint16_t len) { /* Set EP0 State */ pdev->ep0_state = USBD_EP0_DATA_OUT; @@ -132,7 +132,7 @@ USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, pdev->ep_out[0].rem_length = len; /* Start the transfer */ - USBD_LL_PrepareReceive (pdev, 0U, pbuf, len); + USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); return USBD_OK; } @@ -145,8 +145,8 @@ USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, * @param len: length of data to be received * @retval status */ -USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, - uint16_t len) +USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, uint8_t *pbuf, + uint16_t len) { USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); @@ -159,7 +159,7 @@ USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, * @param pdev: device instance * @retval status */ -USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev) +USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev) { /* Set EP0 State */ pdev->ep0_state = USBD_EP0_STATUS_IN; @@ -176,13 +176,13 @@ USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev) * @param pdev: device instance * @retval status */ -USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev) +USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev) { /* Set EP0 State */ pdev->ep0_state = USBD_EP0_STATUS_OUT; - /* Start the transfer */ - USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U); + /* Start the transfer */ + USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); return USBD_OK; } @@ -194,7 +194,7 @@ USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev) * @param ep_addr: endpoint address * @retval Rx Data blength */ -uint32_t USBD_GetRxCount (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr) { return USBD_LL_GetRxDataSize(pdev, ep_addr); } diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/AUDIO/Inc/usbh_audio.h b/system/Middlewares/ST/STM32_USB_Host_Library/Class/AUDIO/Inc/usbh_audio.h index 195ee44d8f..39338079e0 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/AUDIO/Inc/usbh_audio.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/AUDIO/Inc/usbh_audio.h @@ -22,7 +22,7 @@ #define __USBH_AUDIO_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -51,8 +51,7 @@ */ /* States for AUDIO State Machine */ -typedef enum -{ +typedef enum { AUDIO_INIT = 0, AUDIO_IDLE, AUDIO_CS_REQUESTS, @@ -77,8 +76,7 @@ typedef enum } AUDIO_StateTypeDef; -typedef enum -{ +typedef enum { AUDIO_REQ_INIT = 1, AUDIO_REQ_IDLE, AUDIO_REQ_SET_DEFAULT_IN_INTERFACE, @@ -89,8 +87,7 @@ typedef enum } AUDIO_ReqStateTypeDef; -typedef enum -{ +typedef enum { AUDIO_REQ_SET_VOLUME = 1, AUDIO_REQ_SET_MUTE, AUDIO_REQ_GET_CURR_VOLUME, @@ -102,52 +99,46 @@ typedef enum } AUDIO_CSReqStateTypeDef; -typedef enum -{ - AUDIO_PLAYBACK_INIT = 1, - AUDIO_PLAYBACK_SET_EP, - AUDIO_PLAYBACK_SET_EP_FREQ, - AUDIO_PLAYBACK_PLAY, - AUDIO_PLAYBACK_IDLE, +typedef enum { + AUDIO_PLAYBACK_INIT = 1, + AUDIO_PLAYBACK_SET_EP, + AUDIO_PLAYBACK_SET_EP_FREQ, + AUDIO_PLAYBACK_PLAY, + AUDIO_PLAYBACK_IDLE, } AUDIO_PlayStateTypeDef; -typedef enum -{ - VOLUME_UP = 1, - VOLUME_DOWN = 2, +typedef enum { + VOLUME_UP = 1, + VOLUME_DOWN = 2, } AUDIO_VolumeCtrlTypeDef; -typedef enum -{ - AUDIO_CONTROL_INIT = 1, - AUDIO_CONTROL_CHANGE, - AUDIO_CONTROL_IDLE, - AUDIO_CONTROL_VOLUME_UP, - AUDIO_CONTROL_VOLUME_DOWN, +typedef enum { + AUDIO_CONTROL_INIT = 1, + AUDIO_CONTROL_CHANGE, + AUDIO_CONTROL_IDLE, + AUDIO_CONTROL_VOLUME_UP, + AUDIO_CONTROL_VOLUME_DOWN, } AUDIO_ControlStateTypeDef; -typedef enum -{ - AUDIO_DATA_START_OUT = 1, - AUDIO_DATA_OUT, +typedef enum { + AUDIO_DATA_START_OUT = 1, + AUDIO_DATA_OUT, } AUDIO_ProcessingTypeDef; /* Structure for AUDIO process */ -typedef struct -{ +typedef struct { uint8_t Channels; uint8_t Bits; uint32_t SampleRate; } AUDIO_FormatTypeDef; -typedef struct -{ +typedef struct { uint8_t Ep; uint16_t EpSize; uint8_t AltSettings; @@ -157,8 +148,7 @@ typedef struct } AUDIO_STREAMING_IN_HandleTypeDef; -typedef struct -{ +typedef struct { uint8_t Ep; uint16_t EpSize; uint8_t AltSettings; @@ -169,8 +159,7 @@ typedef struct AUDIO_STREAMING_OUT_HandleTypeDef; -typedef struct -{ +typedef struct { uint8_t mute; uint32_t volumeMin; uint32_t volumeMax; @@ -179,8 +168,7 @@ typedef struct } AUDIO_ControlAttributeTypeDef; -typedef struct -{ +typedef struct { uint8_t Ep; uint16_t EpSize; @@ -212,8 +200,7 @@ typedef struct } AUDIO_InterfaceStreamPropTypeDef; -typedef struct -{ +typedef struct { uint8_t Ep; uint16_t EpSize; @@ -245,8 +232,7 @@ AUDIO_InterfaceControlPropTypeDef; #define AUDIO_MAX_CONTROLS_NBR 5U /*Class-Specific AS(Audio Streaming) Interface Descriptor*/ -typedef struct -{ +typedef struct { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDescriptorSubtype; @@ -257,8 +243,7 @@ typedef struct AUDIO_ASGeneralDescTypeDef; /*Class-Specific AS(Audio Streaming) Format Type Descriptor*/ -typedef struct -{ +typedef struct { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDescriptorSubtype; @@ -272,8 +257,7 @@ typedef struct AUDIO_ASFormatTypeDescTypeDef; /*Class-Specific AS(Audio Streaming) Interface Descriptor*/ -typedef struct -{ +typedef struct { AUDIO_ASGeneralDescTypeDef *GeneralDesc; AUDIO_ASFormatTypeDescTypeDef *FormatTypeDesc; } @@ -281,8 +265,7 @@ AUDIO_ASDescTypeDef; /* 4.3.2 Class-Specific AC Interface Descriptor */ -typedef struct -{ +typedef struct { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDescriptorSubtype; @@ -294,8 +277,7 @@ typedef struct AUDIO_HeaderDescTypeDef; /* 4.3.2.1 Input Terminal Descriptor */ -typedef struct -{ +typedef struct { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDescriptorSubtype; @@ -310,8 +292,7 @@ typedef struct AUDIO_ITDescTypeDef; /* 4.3.2.2 Output Terminal Descriptor */ -typedef struct -{ +typedef struct { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDescriptorSubtype; @@ -324,8 +305,7 @@ typedef struct AUDIO_OTDescTypeDef; /* 4.3.2.3 Feature Descriptor */ -typedef struct -{ +typedef struct { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDescriptorSubtype; @@ -338,8 +318,7 @@ AUDIO_FeatureDescTypeDef; /* 4.3.2.3 Feature Descriptor */ -typedef struct -{ +typedef struct { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDescriptorSubtype; @@ -358,8 +337,7 @@ AUDIO_MixerDescTypeDef; /* 4.3.2.3 Feature Descriptor */ -typedef struct -{ +typedef struct { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDescriptorSubtype; @@ -371,8 +349,7 @@ typedef struct AUDIO_SelectorDescTypeDef; /*Class-Specific AC(Audio Control) Interface Descriptor*/ -typedef struct -{ +typedef struct { AUDIO_HeaderDescTypeDef *HeaderDesc; AUDIO_ITDescTypeDef *InputTerminalDesc [AUDIO_MAX_NUM_IN_TERMINAL]; AUDIO_OTDescTypeDef *OutputTerminalDesc[AUDIO_MAX_NUM_OUT_TERMINAL]; @@ -384,8 +361,7 @@ AUDIO_ACDescTypeDef; /*Class-Specific AC : Global descriptor*/ -typedef struct -{ +typedef struct { AUDIO_ACDescTypeDef cs_desc; /* Only one control descriptor*/ AUDIO_ASDescTypeDef as_desc[AUDIO_MAX_STREAMING_INTERFACE]; @@ -399,8 +375,7 @@ typedef struct AUDIO_ClassSpecificDescTypedef; -typedef struct _AUDIO_Process -{ +typedef struct _AUDIO_Process { AUDIO_ReqStateTypeDef req_state; AUDIO_CSReqStateTypeDef cs_req_state; AUDIO_PlayStateTypeDef play_state; @@ -433,22 +408,22 @@ AUDIO_HandleTypeDef; #define AC_CLASS 0x01U /* A.2 Audio Interface Subclass Codes */ -#define USB_SUBCLASS_AUDIOCONTROL 0x01U -#define USB_SUBCLASS_AUDIOSTREAMING 0x02U -#define USB_SUBCLASS_MIDISTREAMING 0x03U +#define USB_SUBCLASS_AUDIOCONTROL 0x01U +#define USB_SUBCLASS_AUDIOSTREAMING 0x02U +#define USB_SUBCLASS_MIDISTREAMING 0x03U #define USB_DESC_TYPE_CS_INTERFACE 0x24U #define USB_DESC_TYPE_CS_ENDPOINT 0x25U /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */ -#define UAC_HEADER 0x01U -#define UAC_INPUT_TERMINAL 0x02U -#define UAC_OUTPUT_TERMINAL 0x03U -#define UAC_MIXER_UNIT 0x04U -#define UAC_SELECTOR_UNIT 0x05U -#define UAC_FEATURE_UNIT 0x06U -#define UAC_PROCESSING_UNIT 0x07U -#define UAC_EXTENSION_UNIT 0x08U +#define UAC_HEADER 0x01U +#define UAC_INPUT_TERMINAL 0x02U +#define UAC_OUTPUT_TERMINAL 0x03U +#define UAC_MIXER_UNIT 0x04U +#define UAC_SELECTOR_UNIT 0x05U +#define UAC_FEATURE_UNIT 0x06U +#define UAC_PROCESSING_UNIT 0x07U +#define UAC_EXTENSION_UNIT 0x08U /*Audio Class-Specific Endpoint Descriptor Subtypes*/ #define EP_CONTROL_UNDEFINED 0x00U @@ -474,48 +449,48 @@ AUDIO_HandleTypeDef; /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */ -#define UAC_AS_GENERAL 0x01U -#define UAC_FORMAT_TYPE 0x02U -#define UAC_FORMAT_SPECIFIC 0x03U +#define UAC_AS_GENERAL 0x01U +#define UAC_FORMAT_TYPE 0x02U +#define UAC_FORMAT_SPECIFIC 0x03U /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */ -#define UAC_EP_GENERAL 0x01U +#define UAC_EP_GENERAL 0x01U /* A.9 Audio Class-Specific Request Codes */ -#define UAC_SET_ 0x00U -#define UAC_GET_ 0x80U - -#define UAC__CUR 0x01U -#define UAC__MIN 0x02U -#define UAC__MAX 0x03U -#define UAC__RES 0x04U -#define UAC__MEM 0x05U - -#define UAC_SET_CUR (UAC_SET_ | UAC__CUR) -#define UAC_GET_CUR (UAC_GET_ | UAC__CUR) -#define UAC_SET_MIN (UAC_SET_ | UAC__MIN) -#define UAC_GET_MIN (UAC_GET_ | UAC__MIN) -#define UAC_SET_MAX (UAC_SET_ | UAC__MAX) -#define UAC_GET_MAX (UAC_GET_ | UAC__MAX) -#define UAC_SET_RES (UAC_SET_ | UAC__RES) -#define UAC_GET_RES (UAC_GET_ | UAC__RES) -#define UAC_SET_MEM (UAC_SET_ | UAC__MEM) -#define UAC_GET_MEM (UAC_GET_ | UAC__MEM) - -#define UAC_GET_STAT 0xffU +#define UAC_SET_ 0x00U +#define UAC_GET_ 0x80U + +#define UAC__CUR 0x01U +#define UAC__MIN 0x02U +#define UAC__MAX 0x03U +#define UAC__RES 0x04U +#define UAC__MEM 0x05U + +#define UAC_SET_CUR (UAC_SET_ | UAC__CUR) +#define UAC_GET_CUR (UAC_GET_ | UAC__CUR) +#define UAC_SET_MIN (UAC_SET_ | UAC__MIN) +#define UAC_GET_MIN (UAC_GET_ | UAC__MIN) +#define UAC_SET_MAX (UAC_SET_ | UAC__MAX) +#define UAC_GET_MAX (UAC_GET_ | UAC__MAX) +#define UAC_SET_RES (UAC_SET_ | UAC__RES) +#define UAC_GET_RES (UAC_GET_ | UAC__RES) +#define UAC_SET_MEM (UAC_SET_ | UAC__MEM) +#define UAC_GET_MEM (UAC_GET_ | UAC__MEM) + +#define UAC_GET_STAT 0xffU /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */ -#define UAC_MS_HEADER 0x01U -#define UAC_MIDI_IN_JACK 0x02U -#define UAC_MIDI_OUT_JACK 0x03U +#define UAC_MS_HEADER 0x01U +#define UAC_MIDI_IN_JACK 0x02U +#define UAC_MIDI_OUT_JACK 0x03U /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */ -#define UAC_MS_GENERAL 0x01U +#define UAC_MS_GENERAL 0x01U /* Terminals - 2.1 USB Terminal Types */ -#define UAC_TERMINAL_UNDEFINED 0x100U -#define UAC_TERMINAL_STREAMING 0x101U -#define UAC_TERMINAL_VENDOR_SPEC 0x1FFU +#define UAC_TERMINAL_UNDEFINED 0x100U +#define UAC_TERMINAL_STREAMING 0x101U +#define UAC_TERMINAL_VENDOR_SPEC 0x1FFU /** * @} @@ -540,18 +515,18 @@ extern USBH_ClassTypeDef AUDIO_Class; /** @defgroup USBH_AUDIO_CORE_Exported_FunctionsPrototype * @{ */ -USBH_StatusTypeDef USBH_AUDIO_SetFrequency (USBH_HandleTypeDef *phost, - uint16_t SampleRate, - uint8_t NbrChannels, - uint8_t BitPerSample); - -USBH_StatusTypeDef USBH_AUDIO_Play (USBH_HandleTypeDef *phost, uint8_t *buf, uint32_t length); -USBH_StatusTypeDef USBH_AUDIO_Stop (USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_AUDIO_Suspend (USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_AUDIO_Resume (USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_AUDIO_SetVolume (USBH_HandleTypeDef *phost, AUDIO_VolumeCtrlTypeDef volume_ctl); -USBH_StatusTypeDef USBH_AUDIO_ChangeOutBuffer (USBH_HandleTypeDef *phost, uint8_t *buf); -int32_t USBH_AUDIO_GetOutOffset (USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_AUDIO_SetFrequency(USBH_HandleTypeDef *phost, + uint16_t SampleRate, + uint8_t NbrChannels, + uint8_t BitPerSample); + +USBH_StatusTypeDef USBH_AUDIO_Play(USBH_HandleTypeDef *phost, uint8_t *buf, uint32_t length); +USBH_StatusTypeDef USBH_AUDIO_Stop(USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_AUDIO_Suspend(USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_AUDIO_Resume(USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_AUDIO_SetVolume(USBH_HandleTypeDef *phost, AUDIO_VolumeCtrlTypeDef volume_ctl); +USBH_StatusTypeDef USBH_AUDIO_ChangeOutBuffer(USBH_HandleTypeDef *phost, uint8_t *buf); +int32_t USBH_AUDIO_GetOutOffset(USBH_HandleTypeDef *phost); void USBH_AUDIO_FrequencySet(USBH_HandleTypeDef *phost); diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/AUDIO/Src/usbh_audio.c b/system/Middlewares/ST/STM32_USB_Host_Library/Class/AUDIO/Src/usbh_audio.c index fb9b24b34a..8b814fe6ee 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/AUDIO/Src/usbh_audio.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/AUDIO/Src/usbh_audio.c @@ -28,13 +28,13 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" - - "stm32xxxxx_{eval}{discovery}_sdram.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" +- "stm32xxxxx_{eval}{discovery}_sdram.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbh_audio.h" @@ -94,8 +94,8 @@ * @{ */ -static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit (USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_AUDIO_InterfaceDeInit (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit(USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_AUDIO_InterfaceDeInit(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef USBH_AUDIO_Process(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef USBH_AUDIO_SOFProcess(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef USBH_AUDIO_ClassRequest(USBH_HandleTypeDef *phost); @@ -118,11 +118,11 @@ int32_t USBH_AUDIO_FindLinkedUnitOUT(USBH_HandleTypeDef *phost, uint8_t UnitID); static USBH_StatusTypeDef ParseCSDescriptors(AUDIO_ClassSpecificDescTypedef *class_desc, - uint8_t ac_subclass, - uint8_t *pdesc); + uint8_t ac_subclass, + uint8_t *pdesc); -static USBH_StatusTypeDef USBH_AUDIO_Transmit (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_AUDIO_Transmit(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef USBH_AC_SetCur(USBH_HandleTypeDef *phost, @@ -161,19 +161,18 @@ static USBH_StatusTypeDef USBH_AC_GetRes(USBH_HandleTypeDef *phost, uint16_t length); static USBH_StatusTypeDef USBH_AUDIO_SetEndpointControls(USBH_HandleTypeDef *phost, - uint8_t Ep, - uint8_t *buff); + uint8_t Ep, + uint8_t *buff); -static USBH_StatusTypeDef AUDIO_SetVolume (USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel, uint16_t volume); +static USBH_StatusTypeDef AUDIO_SetVolume(USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel, uint16_t volume); -static USBH_StatusTypeDef USBH_AUDIO_InputStream (USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_AUDIO_OutputStream (USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_AUDIO_Control (USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_AUDIO_SetControlAttribute (USBH_HandleTypeDef *phost, uint8_t attrib); +static USBH_StatusTypeDef USBH_AUDIO_InputStream(USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_AUDIO_OutputStream(USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_AUDIO_Control(USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_AUDIO_SetControlAttribute(USBH_HandleTypeDef *phost, uint8_t attrib); static uint32_t USBH_AUDIO_FindLinkedUnit(USBH_HandleTypeDef *phost, uint8_t UnitID); -USBH_ClassTypeDef AUDIO_Class = -{ +USBH_ClassTypeDef AUDIO_Class = { "AUDIO", AC_CLASS, USBH_AUDIO_InterfaceInit, @@ -198,7 +197,7 @@ USBH_ClassTypeDef AUDIO_Class = * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_FAIL ; USBH_StatusTypeDef out_status, in_status ; @@ -209,38 +208,29 @@ static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit (USBH_HandleTypeDef *phost) interface = USBH_FindInterface(phost, AC_CLASS, USB_SUBCLASS_AUDIOCONTROL, 0x00U); - if(interface == 0xFFU) /* Not Valid Interface */ - { - USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name); + if (interface == 0xFFU) { /* Not Valid Interface */ + USBH_DbgLog("Cannot Find the interface for %s class.", phost->pActiveClass->Name); status = USBH_FAIL; - } - else - { + } else { - phost->pActiveClass->pData = (AUDIO_HandleTypeDef *)USBH_malloc (sizeof(AUDIO_HandleTypeDef)); - AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + phost->pActiveClass->pData = (AUDIO_HandleTypeDef *)USBH_malloc(sizeof(AUDIO_HandleTypeDef)); + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; USBH_memset(AUDIO_Handle, 0, sizeof(AUDIO_HandleTypeDef)); /* 1st Step: Find Audio Interfaces */ - out_status = USBH_AUDIO_FindAudioStreamingIN (phost); + out_status = USBH_AUDIO_FindAudioStreamingIN(phost); in_status = USBH_AUDIO_FindAudioStreamingOUT(phost); - if((out_status == USBH_FAIL) && (in_status == USBH_FAIL)) - { - USBH_DbgLog ("%s class configuration not supported.", phost->pActiveClass->Name); - } - else - { + if ((out_status == USBH_FAIL) && (in_status == USBH_FAIL)) { + USBH_DbgLog("%s class configuration not supported.", phost->pActiveClass->Name); + } else { /* 2nd Step: Select Audio Streaming Interfaces with largest endpoint size : default behavior*/ - for (index = 0U; index < AUDIO_MAX_AUDIO_STD_INTERFACE; index ++) - { - if( AUDIO_Handle->stream_out[index].valid == 1U) - { - if(ep_size_out < AUDIO_Handle->stream_out[index].EpSize) - { + for (index = 0U; index < AUDIO_MAX_AUDIO_STD_INTERFACE; index ++) { + if (AUDIO_Handle->stream_out[index].valid == 1U) { + if (ep_size_out < AUDIO_Handle->stream_out[index].EpSize) { ep_size_out = AUDIO_Handle->stream_out[index].EpSize; AUDIO_Handle->headphone.interface = AUDIO_Handle->stream_out[index].interface; AUDIO_Handle->headphone.AltSettings = AUDIO_Handle->stream_out[index].AltSettings; @@ -251,10 +241,8 @@ static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit (USBH_HandleTypeDef *phost) } } - if( AUDIO_Handle->stream_in[index].valid == 1U) - { - if(ep_size_in < AUDIO_Handle->stream_in[index].EpSize) - { + if (AUDIO_Handle->stream_in[index].valid == 1U) { + if (ep_size_in < AUDIO_Handle->stream_in[index].EpSize) { ep_size_in = AUDIO_Handle->stream_in[index].EpSize; AUDIO_Handle->microphone.interface = AUDIO_Handle->stream_in[index].interface; AUDIO_Handle->microphone.AltSettings = AUDIO_Handle->stream_in[index].AltSettings; @@ -266,66 +254,62 @@ static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit (USBH_HandleTypeDef *phost) } } - if(USBH_AUDIO_FindHIDControl(phost) == USBH_OK) - { + if (USBH_AUDIO_FindHIDControl(phost) == USBH_OK) { AUDIO_Handle->control.supported = 1U; } /* 3rd Step: Find and Parse Audio interfaces */ - USBH_AUDIO_ParseCSDescriptors (phost); + USBH_AUDIO_ParseCSDescriptors(phost); /* 4th Step: Open the Audio streaming pipes*/ - if(AUDIO_Handle->headphone.supported == 1U) - { - USBH_AUDIO_BuildHeadphonePath (phost); + if (AUDIO_Handle->headphone.supported == 1U) { + USBH_AUDIO_BuildHeadphonePath(phost); AUDIO_Handle->headphone.Pipe = USBH_AllocPipe(phost, AUDIO_Handle->headphone.Ep); /* Open pipe for IN endpoint */ - USBH_OpenPipe (phost, - AUDIO_Handle->headphone.Pipe, - AUDIO_Handle->headphone.Ep, - phost->device.address, - phost->device.speed, - USB_EP_TYPE_ISOC, - AUDIO_Handle->headphone.EpSize); + USBH_OpenPipe(phost, + AUDIO_Handle->headphone.Pipe, + AUDIO_Handle->headphone.Ep, + phost->device.address, + phost->device.speed, + USB_EP_TYPE_ISOC, + AUDIO_Handle->headphone.EpSize); - USBH_LL_SetToggle (phost, AUDIO_Handle->headphone.Pipe, 0U); + USBH_LL_SetToggle(phost, AUDIO_Handle->headphone.Pipe, 0U); } - if(AUDIO_Handle->microphone.supported == 1U) - { - USBH_AUDIO_BuildMicrophonePath (phost); + if (AUDIO_Handle->microphone.supported == 1U) { + USBH_AUDIO_BuildMicrophonePath(phost); AUDIO_Handle->microphone.Pipe = USBH_AllocPipe(phost, AUDIO_Handle->microphone.Ep); /* Open pipe for IN endpoint */ - USBH_OpenPipe (phost, - AUDIO_Handle->microphone.Pipe, - AUDIO_Handle->microphone.Ep, - phost->device.address, - phost->device.speed, - USB_EP_TYPE_ISOC, - AUDIO_Handle->microphone.EpSize); - - USBH_LL_SetToggle (phost, AUDIO_Handle->microphone.Pipe, 0U); + USBH_OpenPipe(phost, + AUDIO_Handle->microphone.Pipe, + AUDIO_Handle->microphone.Ep, + phost->device.address, + phost->device.speed, + USB_EP_TYPE_ISOC, + AUDIO_Handle->microphone.EpSize); + + USBH_LL_SetToggle(phost, AUDIO_Handle->microphone.Pipe, 0U); } - if(AUDIO_Handle->control.supported == 1U) - { + if (AUDIO_Handle->control.supported == 1U) { AUDIO_Handle->control.Pipe = USBH_AllocPipe(phost, AUDIO_Handle->control.Ep); /* Open pipe for IN endpoint */ - USBH_OpenPipe (phost, - AUDIO_Handle->control.Pipe, - AUDIO_Handle->control.Ep, - phost->device.address, - phost->device.speed, - USB_EP_TYPE_INTR, - AUDIO_Handle->control.EpSize); + USBH_OpenPipe(phost, + AUDIO_Handle->control.Pipe, + AUDIO_Handle->control.Ep, + phost->device.address, + phost->device.speed, + USB_EP_TYPE_INTR, + AUDIO_Handle->control.EpSize); - USBH_LL_SetToggle (phost, AUDIO_Handle->control.Pipe, 0U); + USBH_LL_SetToggle(phost, AUDIO_Handle->control.Pipe, 0U); } @@ -346,34 +330,30 @@ static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_AUDIO_InterfaceDeInit (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_AUDIO_InterfaceDeInit(USBH_HandleTypeDef *phost) { - AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; - if(AUDIO_Handle->microphone.Pipe != 0x00U) - { - USBH_ClosePipe (phost, AUDIO_Handle->microphone.Pipe); - USBH_FreePipe (phost, AUDIO_Handle->microphone.Pipe); + if (AUDIO_Handle->microphone.Pipe != 0x00U) { + USBH_ClosePipe(phost, AUDIO_Handle->microphone.Pipe); + USBH_FreePipe(phost, AUDIO_Handle->microphone.Pipe); AUDIO_Handle->microphone.Pipe = 0U; /* Reset the pipe as Free */ } - if( AUDIO_Handle->headphone.Pipe != 0x00U) - { + if (AUDIO_Handle->headphone.Pipe != 0x00U) { USBH_ClosePipe(phost, AUDIO_Handle->headphone.Pipe); - USBH_FreePipe (phost, AUDIO_Handle->headphone.Pipe); + USBH_FreePipe(phost, AUDIO_Handle->headphone.Pipe); AUDIO_Handle->headphone.Pipe = 0U; /* Reset the pipe as Free */ } - if( AUDIO_Handle->control.Pipe != 0x00U) - { + if (AUDIO_Handle->control.Pipe != 0x00U) { USBH_ClosePipe(phost, AUDIO_Handle->control.Pipe); - USBH_FreePipe (phost, AUDIO_Handle->control.Pipe); + USBH_FreePipe(phost, AUDIO_Handle->control.Pipe); AUDIO_Handle->control.Pipe = 0U; /* Reset the pipe as Free */ } - if(phost->pActiveClass->pData) - { - USBH_free (phost->pActiveClass->pData); + if (phost->pActiveClass->pData) { + USBH_free(phost->pActiveClass->pData); phost->pActiveClass->pData = 0; } return USBH_OK ; @@ -388,151 +368,133 @@ static USBH_StatusTypeDef USBH_AUDIO_InterfaceDeInit (USBH_HandleTypeDef *phost) */ static USBH_StatusTypeDef USBH_AUDIO_ClassRequest(USBH_HandleTypeDef *phost) { - AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; USBH_StatusTypeDef status = USBH_BUSY; USBH_StatusTypeDef req_status = USBH_BUSY; /* Switch AUDIO REQ state machine */ - switch (AUDIO_Handle->req_state) - { - case AUDIO_REQ_INIT: - case AUDIO_REQ_SET_DEFAULT_IN_INTERFACE: - if(AUDIO_Handle->microphone.supported == 1U) - { - req_status = USBH_SetInterface(phost, - AUDIO_Handle->microphone.interface, - 0U); - - if(req_status == USBH_OK) - { - AUDIO_Handle->req_state = AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE; - } + switch (AUDIO_Handle->req_state) { + case AUDIO_REQ_INIT: + case AUDIO_REQ_SET_DEFAULT_IN_INTERFACE: + if (AUDIO_Handle->microphone.supported == 1U) { + req_status = USBH_SetInterface(phost, + AUDIO_Handle->microphone.interface, + 0U); + + if (req_status == USBH_OK) { + AUDIO_Handle->req_state = AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE; + } - } - else - { - AUDIO_Handle->req_state = AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE; + } else { + AUDIO_Handle->req_state = AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; + } + break; + + case AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE: + if (AUDIO_Handle->headphone.supported == 1U) { + req_status = USBH_SetInterface(phost, + AUDIO_Handle->headphone.interface, + 0U); - case AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE: - if(AUDIO_Handle->headphone.supported == 1U) - { - req_status = USBH_SetInterface(phost, - AUDIO_Handle->headphone.interface, - 0U); + if (req_status == USBH_OK) { + AUDIO_Handle->req_state = AUDIO_REQ_CS_REQUESTS; + AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME; - if(req_status == USBH_OK) - { + AUDIO_Handle->temp_feature = AUDIO_Handle->headphone.asociated_feature; + AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels; + } + } else { AUDIO_Handle->req_state = AUDIO_REQ_CS_REQUESTS; AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME; - AUDIO_Handle->temp_feature = AUDIO_Handle->headphone.asociated_feature; - AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels; - } - } - else - { - AUDIO_Handle->req_state = AUDIO_REQ_CS_REQUESTS; - AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME; - #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; + } + break; - case AUDIO_REQ_CS_REQUESTS: - if(USBH_AUDIO_HandleCSRequest (phost) == USBH_OK) - { - AUDIO_Handle->req_state = AUDIO_REQ_SET_IN_INTERFACE; - } - break; + case AUDIO_REQ_CS_REQUESTS: + if (USBH_AUDIO_HandleCSRequest(phost) == USBH_OK) { + AUDIO_Handle->req_state = AUDIO_REQ_SET_IN_INTERFACE; + } + break; - case AUDIO_REQ_SET_IN_INTERFACE: - if(AUDIO_Handle->microphone.supported == 1U) - { - req_status = USBH_SetInterface(phost, - AUDIO_Handle->microphone.interface, - AUDIO_Handle->microphone.AltSettings); + case AUDIO_REQ_SET_IN_INTERFACE: + if (AUDIO_Handle->microphone.supported == 1U) { + req_status = USBH_SetInterface(phost, + AUDIO_Handle->microphone.interface, + AUDIO_Handle->microphone.AltSettings); - if(req_status == USBH_OK) - { + if (req_status == USBH_OK) { + AUDIO_Handle->req_state = AUDIO_REQ_SET_OUT_INTERFACE; + } + } else { AUDIO_Handle->req_state = AUDIO_REQ_SET_OUT_INTERFACE; - } - } - else - { - AUDIO_Handle->req_state = AUDIO_REQ_SET_OUT_INTERFACE; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; - case AUDIO_REQ_SET_OUT_INTERFACE: - if(AUDIO_Handle->headphone.supported == 1U) - { - req_status = USBH_SetInterface(phost, - AUDIO_Handle->headphone.interface, - AUDIO_Handle->headphone.AltSettings); - - if(req_status == USBH_OK) - { - AUDIO_Handle->req_state = AUDIO_REQ_IDLE; } + break; + case AUDIO_REQ_SET_OUT_INTERFACE: + if (AUDIO_Handle->headphone.supported == 1U) { + req_status = USBH_SetInterface(phost, + AUDIO_Handle->headphone.interface, + AUDIO_Handle->headphone.AltSettings); + + if (req_status == USBH_OK) { + AUDIO_Handle->req_state = AUDIO_REQ_IDLE; + } - } - else - { - AUDIO_Handle->req_state = AUDIO_REQ_IDLE; + } else { + AUDIO_Handle->req_state = AUDIO_REQ_IDLE; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; - case AUDIO_REQ_IDLE: - AUDIO_Handle->play_state = AUDIO_PLAYBACK_INIT; - phost->pUser(phost, HOST_USER_CLASS_ACTIVE); - status = USBH_OK; + } + break; + case AUDIO_REQ_IDLE: + AUDIO_Handle->play_state = AUDIO_PLAYBACK_INIT; + phost->pUser(phost, HOST_USER_CLASS_ACTIVE); + status = USBH_OK; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CLASS_EVENT; + phost->os_msg = (uint32_t)USBH_CLASS_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - default: - break; + default: + break; } return status; } @@ -546,86 +508,80 @@ static USBH_StatusTypeDef USBH_AUDIO_ClassRequest(USBH_HandleTypeDef *phost) */ static USBH_StatusTypeDef USBH_AUDIO_CSRequest(USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel) { - AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; USBH_StatusTypeDef status = USBH_BUSY; USBH_StatusTypeDef req_status = USBH_BUSY; uint16_t VolumeCtl, ResolutionCtl; /* Switch AUDIO REQ state machine */ - switch (AUDIO_Handle->cs_req_state) - { - case AUDIO_REQ_GET_VOLUME: - req_status = USBH_AC_GetCur(phost, - UAC_FEATURE_UNIT, /* subtype */ - feature, /* feature */ - VOLUME_CONTROL, /* Selector */ - channel, /* channel */ - 0x02U); /* length */ - if(req_status != USBH_BUSY) - { - AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_MIN_VOLUME; - VolumeCtl = LE16(&(AUDIO_Handle->mem[0])); - AUDIO_Handle->headphone.attribute.volume = (uint32_t)VolumeCtl; - } - break; - - case AUDIO_REQ_GET_MIN_VOLUME: - req_status = USBH_AC_GetMin(phost, - UAC_FEATURE_UNIT, /* subtype */ - feature, /* feature */ - VOLUME_CONTROL, /* Selector */ - channel, /* channel */ - 0x02U); /* length */ - if(req_status != USBH_BUSY) - { - AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_MAX_VOLUME; - VolumeCtl = LE16(&(AUDIO_Handle->mem[0])); - AUDIO_Handle->headphone.attribute.volumeMin = (uint32_t)VolumeCtl; - } - break; - - case AUDIO_REQ_GET_MAX_VOLUME: - req_status = USBH_AC_GetMax(phost, - UAC_FEATURE_UNIT, /* subtype */ - feature, /* feature */ - VOLUME_CONTROL, /* Selector */ - channel, /* channel */ - 0x02U); /* length */ - if(req_status != USBH_BUSY) - { - AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_RESOLUTION; - VolumeCtl = LE16(&(AUDIO_Handle->mem[0])); - AUDIO_Handle->headphone.attribute.volumeMax = (uint32_t)VolumeCtl; - - if (AUDIO_Handle->headphone.attribute.volumeMax < AUDIO_Handle->headphone.attribute.volumeMin) - { - AUDIO_Handle->headphone.attribute.volumeMax = 0xFF00U; + switch (AUDIO_Handle->cs_req_state) { + case AUDIO_REQ_GET_VOLUME: + req_status = USBH_AC_GetCur(phost, + UAC_FEATURE_UNIT, /* subtype */ + feature, /* feature */ + VOLUME_CONTROL, /* Selector */ + channel, /* channel */ + 0x02U); /* length */ + if (req_status != USBH_BUSY) { + AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_MIN_VOLUME; + VolumeCtl = LE16(&(AUDIO_Handle->mem[0])); + AUDIO_Handle->headphone.attribute.volume = (uint32_t)VolumeCtl; } - } - break; - - case AUDIO_REQ_GET_RESOLUTION: - req_status = USBH_AC_GetRes(phost, - UAC_FEATURE_UNIT, /* subtype */ - feature, /* feature */ - VOLUME_CONTROL, /* Selector */ - channel, /* channel */ - 0x02U); /* length */ - if(req_status != USBH_BUSY) - { - AUDIO_Handle->cs_req_state = AUDIO_REQ_CS_IDLE; - ResolutionCtl =LE16(&AUDIO_Handle->mem[0]); - AUDIO_Handle->headphone.attribute.resolution = (uint32_t)ResolutionCtl; - } - break; + break; + case AUDIO_REQ_GET_MIN_VOLUME: + req_status = USBH_AC_GetMin(phost, + UAC_FEATURE_UNIT, /* subtype */ + feature, /* feature */ + VOLUME_CONTROL, /* Selector */ + channel, /* channel */ + 0x02U); /* length */ + if (req_status != USBH_BUSY) { + AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_MAX_VOLUME; + VolumeCtl = LE16(&(AUDIO_Handle->mem[0])); + AUDIO_Handle->headphone.attribute.volumeMin = (uint32_t)VolumeCtl; + } + break; - case AUDIO_REQ_CS_IDLE: - status = USBH_OK; - break; + case AUDIO_REQ_GET_MAX_VOLUME: + req_status = USBH_AC_GetMax(phost, + UAC_FEATURE_UNIT, /* subtype */ + feature, /* feature */ + VOLUME_CONTROL, /* Selector */ + channel, /* channel */ + 0x02U); /* length */ + if (req_status != USBH_BUSY) { + AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_RESOLUTION; + VolumeCtl = LE16(&(AUDIO_Handle->mem[0])); + AUDIO_Handle->headphone.attribute.volumeMax = (uint32_t)VolumeCtl; + + if (AUDIO_Handle->headphone.attribute.volumeMax < AUDIO_Handle->headphone.attribute.volumeMin) { + AUDIO_Handle->headphone.attribute.volumeMax = 0xFF00U; + } + } + break; + + case AUDIO_REQ_GET_RESOLUTION: + req_status = USBH_AC_GetRes(phost, + UAC_FEATURE_UNIT, /* subtype */ + feature, /* feature */ + VOLUME_CONTROL, /* Selector */ + channel, /* channel */ + 0x02U); /* length */ + if (req_status != USBH_BUSY) { + AUDIO_Handle->cs_req_state = AUDIO_REQ_CS_IDLE; + ResolutionCtl = LE16(&AUDIO_Handle->mem[0]); + AUDIO_Handle->headphone.attribute.resolution = (uint32_t)ResolutionCtl; + } + break; - default: - break; + + case AUDIO_REQ_CS_IDLE: + status = USBH_OK; + break; + + default: + break; } return status; } @@ -642,23 +598,19 @@ static USBH_StatusTypeDef USBH_AUDIO_HandleCSRequest(USBH_HandleTypeDef *phost) USBH_StatusTypeDef status = USBH_BUSY; USBH_StatusTypeDef cs_status = USBH_BUSY; - AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; cs_status = USBH_AUDIO_CSRequest(phost, AUDIO_Handle->temp_feature, AUDIO_Handle->temp_channels); - if(cs_status != USBH_BUSY) - { + if (cs_status != USBH_BUSY) { - if(AUDIO_Handle->temp_channels == 1U) - { - AUDIO_Handle->temp_feature = AUDIO_Handle->headphone.asociated_feature; - AUDIO_Handle->temp_channels = 0U; - status = USBH_OK; - } - else - { + if (AUDIO_Handle->temp_channels == 1U) { + AUDIO_Handle->temp_feature = AUDIO_Handle->headphone.asociated_feature; + AUDIO_Handle->temp_channels = 0U; + status = USBH_OK; + } else { AUDIO_Handle->temp_channels--; } AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME; @@ -682,19 +634,17 @@ static USBH_StatusTypeDef USBH_AUDIO_HandleCSRequest(USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_AUDIO_Process (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_AUDIO_Process(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_BUSY; - AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; - if(AUDIO_Handle->headphone.supported == 1U) - { - USBH_AUDIO_OutputStream (phost); + if (AUDIO_Handle->headphone.supported == 1U) { + USBH_AUDIO_OutputStream(phost); } - if(AUDIO_Handle->microphone.supported == 1U) - { - USBH_AUDIO_InputStream (phost); + if (AUDIO_Handle->microphone.supported == 1U) { + USBH_AUDIO_InputStream(phost); } return status; @@ -706,7 +656,7 @@ static USBH_StatusTypeDef USBH_AUDIO_Process (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_AUDIO_SOFProcess (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_AUDIO_SOFProcess(USBH_HandleTypeDef *phost) { return USBH_OK; } @@ -725,14 +675,11 @@ static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingIN(USBH_HandleTypeDef *ph /* Look For AUDIOSTREAMING IN interface */ alt_settings = 0U; - for (interface = 0U; interface < USBH_MAX_NUM_INTERFACES; interface++) - { - if((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == AC_CLASS)&& - (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass == USB_SUBCLASS_AUDIOSTREAMING)) - { - if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80U) && - (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0U)) - { + for (interface = 0U; interface < USBH_MAX_NUM_INTERFACES; interface++) { + if ((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == AC_CLASS) && + (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass == USB_SUBCLASS_AUDIOSTREAMING)) { + if ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80U) && + (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0U)) { AUDIO_Handle->stream_in[alt_settings].Ep = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress; AUDIO_Handle->stream_in[alt_settings].EpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize; AUDIO_Handle->stream_in[alt_settings].interface = phost->device.CfgDesc.Itf_Desc[interface].bInterfaceNumber; @@ -744,9 +691,8 @@ static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingIN(USBH_HandleTypeDef *ph } } - if(alt_settings > 0U) - { - status = USBH_OK; + if (alt_settings > 0U) { + status = USBH_OK; } return status; @@ -763,18 +709,15 @@ static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingOUT(USBH_HandleTypeDef *p USBH_StatusTypeDef status = USBH_FAIL ; AUDIO_HandleTypeDef *AUDIO_Handle; - AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; /* Look For AUDIOSTREAMING IN interface */ alt_settings = 0U; - for (interface = 0U; interface < USBH_MAX_NUM_INTERFACES; interface++) - { - if((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == AC_CLASS)&& - (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass == USB_SUBCLASS_AUDIOSTREAMING)) - { - if(((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80U) == 0x00U) && - (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0U)) - { + for (interface = 0U; interface < USBH_MAX_NUM_INTERFACES; interface++) { + if ((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == AC_CLASS) && + (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass == USB_SUBCLASS_AUDIOSTREAMING)) { + if (((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80U) == 0x00U) && + (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0U)) { AUDIO_Handle->stream_out[alt_settings].Ep = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress; AUDIO_Handle->stream_out[alt_settings].EpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize; AUDIO_Handle->stream_out[alt_settings].interface = phost->device.CfgDesc.Itf_Desc[interface].bInterfaceNumber; @@ -786,9 +729,8 @@ static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingOUT(USBH_HandleTypeDef *p } } - if(alt_settings > 0U) - { - status = USBH_OK; + if (alt_settings > 0U) { + status = USBH_OK; } return status; @@ -805,22 +747,18 @@ static USBH_StatusTypeDef USBH_AUDIO_FindHIDControl(USBH_HandleTypeDef *phost) USBH_StatusTypeDef status = USBH_FAIL; AUDIO_HandleTypeDef *AUDIO_Handle; - AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; /* Look For AUDIOCONTROL interface */ interface = USBH_FindInterface(phost, AC_CLASS, USB_SUBCLASS_AUDIOCONTROL, 0xFFU); - if(interface == 0xFFU) - { + if (interface == 0xFFU) { return USBH_FAIL; } - for (interface = 0U; interface < USBH_MAX_NUM_INTERFACES; interface++) - { - if((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == 0x03U) && /*HID*/ - (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0U)) - { - if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80U) == 0x80U) - { + for (interface = 0U; interface < USBH_MAX_NUM_INTERFACES; interface++) { + if ((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == 0x03U) && /*HID*/ + (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0U)) { + if ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80U) == 0x80U) { AUDIO_Handle->control.Ep = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress; AUDIO_Handle->control.EpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize; AUDIO_Handle->control.interface = phost->device.CfgDesc.Itf_Desc[interface].bInterfaceNumber; @@ -849,7 +787,7 @@ static USBH_StatusTypeDef USBH_AUDIO_ParseCSDescriptors(USBH_HandleTypeDef *phos uint8_t alt_setting; AUDIO_HandleTypeDef *AUDIO_Handle; - AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; pdesc = (USBH_DescHeader_t *)(void *)(phost->device.CfgDesc_Raw); ptr = USB_LEN_CFG_DESC; @@ -858,31 +796,28 @@ static USBH_StatusTypeDef USBH_AUDIO_ParseCSDescriptors(USBH_HandleTypeDef *phos AUDIO_Handle->class_desc.OutputTerminalNum = 0U; AUDIO_Handle->class_desc.ASNum = 0U; - while(ptr < phost->device.CfgDesc.wTotalLength) - { - pdesc = USBH_GetNextDesc((uint8_t*)(void *)pdesc, &ptr); + while (ptr < phost->device.CfgDesc.wTotalLength) { + pdesc = USBH_GetNextDesc((uint8_t *)(void *)pdesc, &ptr); - switch (pdesc->bDescriptorType) - { + switch (pdesc->bDescriptorType) { - case USB_DESC_TYPE_INTERFACE: - itf_number = *((uint8_t *)(void *)pdesc + 2U); - alt_setting = *((uint8_t *)(void *)pdesc + 3U); - itf_index = USBH_FindInterfaceIndex (phost, itf_number, alt_setting); - break; + case USB_DESC_TYPE_INTERFACE: + itf_number = *((uint8_t *)(void *)pdesc + 2U); + alt_setting = *((uint8_t *)(void *)pdesc + 3U); + itf_index = USBH_FindInterfaceIndex(phost, itf_number, alt_setting); + break; - case USB_DESC_TYPE_CS_INTERFACE: - if(itf_number <= phost->device.CfgDesc.bNumInterfaces) - { + case USB_DESC_TYPE_CS_INTERFACE: + if (itf_number <= phost->device.CfgDesc.bNumInterfaces) { - ParseCSDescriptors(&AUDIO_Handle->class_desc, - phost->device.CfgDesc.Itf_Desc[itf_index].bInterfaceSubClass, - (uint8_t *)(void *)pdesc); - } - break; + ParseCSDescriptors(&AUDIO_Handle->class_desc, + phost->device.CfgDesc.Itf_Desc[itf_index].bInterfaceSubClass, + (uint8_t *)(void *)pdesc); + } + break; - default: - break; + default: + break; } } return USBH_OK; @@ -894,55 +829,49 @@ static USBH_StatusTypeDef USBH_AUDIO_ParseCSDescriptors(USBH_HandleTypeDef *phos * @retval USBH Status */ static USBH_StatusTypeDef ParseCSDescriptors(AUDIO_ClassSpecificDescTypedef *class_desc, - uint8_t ac_subclass, - uint8_t *pdesc) + uint8_t ac_subclass, + uint8_t *pdesc) { - if(ac_subclass == USB_SUBCLASS_AUDIOCONTROL) - { - switch(pdesc[2]) - { - case UAC_HEADER: - class_desc->cs_desc.HeaderDesc = (AUDIO_HeaderDescTypeDef *)(void *)pdesc; - break; - - case UAC_INPUT_TERMINAL: - class_desc->cs_desc.InputTerminalDesc[class_desc->InputTerminalNum++] = (AUDIO_ITDescTypeDef*)(void *)pdesc; - break; - - case UAC_OUTPUT_TERMINAL: - class_desc->cs_desc.OutputTerminalDesc[class_desc->OutputTerminalNum++] = (AUDIO_OTDescTypeDef*)(void *)pdesc; - break; + if (ac_subclass == USB_SUBCLASS_AUDIOCONTROL) { + switch (pdesc[2]) { + case UAC_HEADER: + class_desc->cs_desc.HeaderDesc = (AUDIO_HeaderDescTypeDef *)(void *)pdesc; + break; - case UAC_FEATURE_UNIT: - class_desc->cs_desc.FeatureUnitDesc[class_desc->FeatureUnitNum++] = (AUDIO_FeatureDescTypeDef*)(void *)pdesc; - break; + case UAC_INPUT_TERMINAL: + class_desc->cs_desc.InputTerminalDesc[class_desc->InputTerminalNum++] = (AUDIO_ITDescTypeDef *)(void *)pdesc; + break; - case UAC_SELECTOR_UNIT: - class_desc->cs_desc.SelectorUnitDesc[class_desc->SelectorUnitNum++] = (AUDIO_SelectorDescTypeDef*)(void *)pdesc; - break; + case UAC_OUTPUT_TERMINAL: + class_desc->cs_desc.OutputTerminalDesc[class_desc->OutputTerminalNum++] = (AUDIO_OTDescTypeDef *)(void *)pdesc; + break; - case UAC_MIXER_UNIT: - class_desc->cs_desc.MixerUnitDesc[class_desc->MixerUnitNum++] = (AUDIO_MixerDescTypeDef*)(void *)pdesc; - break; + case UAC_FEATURE_UNIT: + class_desc->cs_desc.FeatureUnitDesc[class_desc->FeatureUnitNum++] = (AUDIO_FeatureDescTypeDef *)(void *)pdesc; + break; - default: - break; - } - } - else - { - if(ac_subclass == USB_SUBCLASS_AUDIOSTREAMING) - { - switch(pdesc[2]) - { - case UAC_AS_GENERAL: - class_desc->as_desc[class_desc->ASNum].GeneralDesc = (AUDIO_ASGeneralDescTypeDef*)(void *)pdesc; + case UAC_SELECTOR_UNIT: + class_desc->cs_desc.SelectorUnitDesc[class_desc->SelectorUnitNum++] = (AUDIO_SelectorDescTypeDef *)(void *)pdesc; break; - case UAC_FORMAT_TYPE: - class_desc->as_desc[class_desc->ASNum++].FormatTypeDesc = (AUDIO_ASFormatTypeDescTypeDef*)(void *)pdesc; + + case UAC_MIXER_UNIT: + class_desc->cs_desc.MixerUnitDesc[class_desc->MixerUnitNum++] = (AUDIO_MixerDescTypeDef *)(void *)pdesc; break; + default: break; + } + } else { + if (ac_subclass == USB_SUBCLASS_AUDIOSTREAMING) { + switch (pdesc[2]) { + case UAC_AS_GENERAL: + class_desc->as_desc[class_desc->ASNum].GeneralDesc = (AUDIO_ASGeneralDescTypeDef *)(void *)pdesc; + break; + case UAC_FORMAT_TYPE: + class_desc->as_desc[class_desc->ASNum++].FormatTypeDesc = (AUDIO_ASFormatTypeDescTypeDef *)(void *)pdesc; + break; + default: + break; } } } @@ -965,10 +894,8 @@ static uint32_t USBH_AUDIO_FindLinkedUnit(USBH_HandleTypeDef *phost, uint8_t Uni AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; /* Find Feature Unit */ - for(Index = 0U; Index < AUDIO_Handle->class_desc.FeatureUnitNum; Index ++) - { - if(AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[Index]->bSourceID == UnitID) - { + for (Index = 0U; Index < AUDIO_Handle->class_desc.FeatureUnitNum; Index ++) { + if (AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[Index]->bSourceID == UnitID) { UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[Index]->bUnitID; return (((uint32_t)UnitID << 16U) | (UAC_FEATURE_UNIT << 8U) | (uint32_t)Index); @@ -976,11 +903,9 @@ static uint32_t USBH_AUDIO_FindLinkedUnit(USBH_HandleTypeDef *phost, uint8_t Uni } /* Find Mixer Unit */ - for(Index = 0U; Index < AUDIO_Handle->class_desc.MixerUnitNum; Index ++) - { - if((AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bSourceID0 == UnitID)|| - (AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bSourceID1 == UnitID)) - { + for (Index = 0U; Index < AUDIO_Handle->class_desc.MixerUnitNum; Index ++) { + if ((AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bSourceID0 == UnitID) || + (AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bSourceID1 == UnitID)) { UnitID = AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bUnitID; return ((UnitID << 16U) | (UAC_MIXER_UNIT << 8U) | Index); @@ -988,10 +913,8 @@ static uint32_t USBH_AUDIO_FindLinkedUnit(USBH_HandleTypeDef *phost, uint8_t Uni } /* Find Selector Unit */ - for(Index = 0U; Index < AUDIO_Handle->class_desc.SelectorUnitNum; Index ++) - { - if(AUDIO_Handle->class_desc.cs_desc.SelectorUnitDesc[Index]->bSourceID0 == UnitID) - { + for (Index = 0U; Index < AUDIO_Handle->class_desc.SelectorUnitNum; Index ++) { + if (AUDIO_Handle->class_desc.cs_desc.SelectorUnitDesc[Index]->bSourceID0 == UnitID) { UnitID = AUDIO_Handle->class_desc.cs_desc.SelectorUnitDesc[Index]->bUnitID; return ((UnitID << 16U) | (UAC_SELECTOR_UNIT << 8U) | Index); @@ -999,10 +922,8 @@ static uint32_t USBH_AUDIO_FindLinkedUnit(USBH_HandleTypeDef *phost, uint8_t Uni } /* Find OT Unit */ - for(Index = 0U; Index < AUDIO_Handle->class_desc.OutputTerminalNum; Index ++) - { - if(AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->bSourceID == UnitID) - { + for (Index = 0U; Index < AUDIO_Handle->class_desc.OutputTerminalNum; Index ++) { + if (AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->bSourceID == UnitID) { UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->bTerminalID; return ((UnitID << 16U) | (UAC_OUTPUT_TERMINAL << 8U) | Index); @@ -1026,25 +947,21 @@ static USBH_StatusTypeDef USBH_AUDIO_BuildMicrophonePath(USBH_HandleTypeDef *pho AUDIO_HandleTypeDef *AUDIO_Handle; USBH_StatusTypeDef ret = USBH_OK; - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; /*Find microphone IT*/ - for(terminalIndex = 0U; terminalIndex < AUDIO_Handle->class_desc.InputTerminalNum; terminalIndex++) - { - if(LE16(AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->wTerminalType) == 0x201) - { + for (terminalIndex = 0U; terminalIndex < AUDIO_Handle->class_desc.InputTerminalNum; terminalIndex++) { + if (LE16(AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->wTerminalType) == 0x201) { UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bTerminalID; AUDIO_Handle->microphone.asociated_channels = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bNrChannels; break; } } - do - { + do { value = USBH_AUDIO_FindLinkedUnit(phost, UnitID); - if (!value) - { + if (!value) { return USBH_FAIL; } @@ -1052,30 +969,28 @@ static USBH_StatusTypeDef USBH_AUDIO_BuildMicrophonePath(USBH_HandleTypeDef *pho Type = (uint8_t)((value >> 8U) & 0xFFU); UnitID = (uint8_t)((value >> 16U) & 0xFFU); - switch (Type) - { - case UAC_FEATURE_UNIT: - AUDIO_Handle->microphone.asociated_feature = Index; - break; + switch (Type) { + case UAC_FEATURE_UNIT: + AUDIO_Handle->microphone.asociated_feature = Index; + break; - case UAC_MIXER_UNIT: - AUDIO_Handle->microphone.asociated_mixer = Index; - break; + case UAC_MIXER_UNIT: + AUDIO_Handle->microphone.asociated_mixer = Index; + break; - case UAC_SELECTOR_UNIT: - AUDIO_Handle->microphone.asociated_selector = Index; - break; + case UAC_SELECTOR_UNIT: + AUDIO_Handle->microphone.asociated_selector = Index; + break; - case UAC_OUTPUT_TERMINAL: - AUDIO_Handle->microphone.asociated_terminal = Index; - break; + case UAC_OUTPUT_TERMINAL: + AUDIO_Handle->microphone.asociated_terminal = Index; + break; - default: - ret = USBH_FAIL; - break; + default: + ret = USBH_FAIL; + break; } - } - while ((Type != UAC_OUTPUT_TERMINAL) && (value > 0U)); + } while ((Type != UAC_OUTPUT_TERMINAL) && (value > 0U)); return ret; } @@ -1093,34 +1008,28 @@ static USBH_StatusTypeDef USBH_AUDIO_BuildHeadphonePath(USBH_HandleTypeDef *phos AUDIO_HandleTypeDef *AUDIO_Handle; USBH_StatusTypeDef ret = USBH_OK; - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; /* Find association between audio streaming and microphone */ - for(terminalIndex = 0U; terminalIndex < AUDIO_Handle->class_desc.InputTerminalNum; terminalIndex++) - { - if(LE16(AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->wTerminalType) == 0x101) - { + for (terminalIndex = 0U; terminalIndex < AUDIO_Handle->class_desc.InputTerminalNum; terminalIndex++) { + if (LE16(AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->wTerminalType) == 0x101) { UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bTerminalID; AUDIO_Handle->headphone.asociated_channels = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bNrChannels; break; } } - for(Index = 0U; Index < AUDIO_Handle->class_desc.ASNum; Index++) - { - if(AUDIO_Handle->class_desc.as_desc[Index].GeneralDesc->bTerminalLink == UnitID) - { + for (Index = 0U; Index < AUDIO_Handle->class_desc.ASNum; Index++) { + if (AUDIO_Handle->class_desc.as_desc[Index].GeneralDesc->bTerminalLink == UnitID) { AUDIO_Handle->headphone.asociated_as = Index; break; } } - do - { + do { value = USBH_AUDIO_FindLinkedUnit(phost, UnitID); - if (!value) - { + if (!value) { return USBH_FAIL; } @@ -1128,34 +1037,31 @@ static USBH_StatusTypeDef USBH_AUDIO_BuildHeadphonePath(USBH_HandleTypeDef *phos Type = (uint8_t)((value >> 8U) & 0xFFU); UnitID = (uint8_t)((value >> 16U) & 0xFFU); - switch (Type) - { - case UAC_FEATURE_UNIT: - AUDIO_Handle->headphone.asociated_feature = Index; - break; + switch (Type) { + case UAC_FEATURE_UNIT: + AUDIO_Handle->headphone.asociated_feature = Index; + break; - case UAC_MIXER_UNIT: - AUDIO_Handle->headphone.asociated_mixer = Index; - break; + case UAC_MIXER_UNIT: + AUDIO_Handle->headphone.asociated_mixer = Index; + break; - case UAC_SELECTOR_UNIT: - AUDIO_Handle->headphone.asociated_selector = Index; - break; + case UAC_SELECTOR_UNIT: + AUDIO_Handle->headphone.asociated_selector = Index; + break; - case UAC_OUTPUT_TERMINAL: - AUDIO_Handle->headphone.asociated_terminal = Index; - if(LE16(AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->wTerminalType) != 0x103) - { - return USBH_OK; - } - break; + case UAC_OUTPUT_TERMINAL: + AUDIO_Handle->headphone.asociated_terminal = Index; + if (LE16(AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->wTerminalType) != 0x103) { + return USBH_OK; + } + break; - default: - ret = USBH_FAIL; - break; + default: + ret = USBH_FAIL; + break; } - } - while ((Type != UAC_OUTPUT_TERMINAL) && (value > 0U)); + } while ((Type != UAC_OUTPUT_TERMINAL) && (value > 0U)); return ret; } @@ -1178,51 +1084,49 @@ static USBH_StatusTypeDef USBH_AC_SetCur(USBH_HandleTypeDef *phost, uint8_t channel, uint16_t length) { - uint16_t wValue,wIndex,wLength; - uint8_t UnitID,InterfaceNum; + uint16_t wValue, wIndex, wLength; + uint8_t UnitID, InterfaceNum; AUDIO_HandleTypeDef *AUDIO_Handle; - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; USBH_StatusTypeDef ret = USBH_OK; - switch(subtype) - { - case UAC_INPUT_TERMINAL: - UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; - wValue = (COPY_PROTECT_CONTROL << 8U); - AUDIO_Handle->mem[0] = 0x00U; - - wLength = 1U; - break; - case UAC_FEATURE_UNIT: - UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum ; - /*holds the CS(control selector ) and CN (channel number)*/ - wValue = (uint16_t)((uint32_t)controlSelector << 8U) | (uint16_t)channel; - wLength = length; - break; - - default: - ret = USBH_FAIL; - break; + switch (subtype) { + case UAC_INPUT_TERMINAL: + UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; + wValue = (COPY_PROTECT_CONTROL << 8U); + AUDIO_Handle->mem[0] = 0x00U; + + wLength = 1U; + break; + case UAC_FEATURE_UNIT: + UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum ; + /*holds the CS(control selector ) and CN (channel number)*/ + wValue = (uint16_t)((uint32_t)controlSelector << 8U) | (uint16_t)channel; + wLength = length; + break; + + default: + ret = USBH_FAIL; + break; } - if (ret != USBH_OK) - { + if (ret != USBH_OK) { return ret; } phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE - | USB_REQ_TYPE_CLASS; + | USB_REQ_TYPE_CLASS; phost->Control.setup.b.bRequest = UAC_SET_CUR; phost->Control.setup.b.wValue.w = wValue; phost->Control.setup.b.wIndex.w = wIndex; phost->Control.setup.b.wLength.w = wLength; - return(USBH_CtlReq(phost, (uint8_t *)(void *)(AUDIO_Handle->mem), wLength)); + return (USBH_CtlReq(phost, (uint8_t *)(void *)(AUDIO_Handle->mem), wLength)); } /** @@ -1245,56 +1149,54 @@ static USBH_StatusTypeDef USBH_AC_GetCur(USBH_HandleTypeDef *phost, uint16_t wValue = 0U, wIndex = 0U, wLength = 0U; uint8_t UnitID = 0U, InterfaceNum = 0U; AUDIO_HandleTypeDef *AUDIO_Handle; - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; USBH_StatusTypeDef ret = USBH_OK; - switch(subtype) - { - case UAC_INPUT_TERMINAL: - UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; - wValue = (COPY_PROTECT_CONTROL << 8U); - AUDIO_Handle->mem[0] = 0x00U; - - wLength = 1U; - break; - case UAC_FEATURE_UNIT: - UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; - /*holds the CS(control selector ) and CN (channel number)*/ - wValue = (uint16_t)((uint32_t)controlSelector << 8U) | (uint16_t)channel; - wLength = length; - break; - - case UAC_OUTPUT_TERMINAL: - UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; - wValue = (COPY_PROTECT_CONTROL << 8U); - wLength = 1U; - break; - - default: - ret = USBH_FAIL; - break; + switch (subtype) { + case UAC_INPUT_TERMINAL: + UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; + wValue = (COPY_PROTECT_CONTROL << 8U); + AUDIO_Handle->mem[0] = 0x00U; + + wLength = 1U; + break; + case UAC_FEATURE_UNIT: + UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; + /*holds the CS(control selector ) and CN (channel number)*/ + wValue = (uint16_t)((uint32_t)controlSelector << 8U) | (uint16_t)channel; + wLength = length; + break; + + case UAC_OUTPUT_TERMINAL: + UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; + wValue = (COPY_PROTECT_CONTROL << 8U); + wLength = 1U; + break; + + default: + ret = USBH_FAIL; + break; } - if (ret != USBH_OK) - { + if (ret != USBH_OK) { return ret; } phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \ - USB_REQ_TYPE_CLASS; + USB_REQ_TYPE_CLASS; phost->Control.setup.b.bRequest = UAC_GET_CUR; phost->Control.setup.b.wValue.w = wValue; phost->Control.setup.b.wIndex.w = wIndex; phost->Control.setup.b.wLength.w = wLength; - return(USBH_CtlReq(phost, (uint8_t *)(void *)(AUDIO_Handle->mem) , wLength )); + return (USBH_CtlReq(phost, (uint8_t *)(void *)(AUDIO_Handle->mem), wLength)); } @@ -1318,56 +1220,54 @@ static USBH_StatusTypeDef USBH_AC_GetMax(USBH_HandleTypeDef *phost, uint16_t wValue = 0U, wIndex = 0U, wLength = 0U; uint8_t UnitID = 0U, InterfaceNum = 0U; AUDIO_HandleTypeDef *AUDIO_Handle; - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; USBH_StatusTypeDef ret = USBH_OK; - switch(subtype) - { - case UAC_INPUT_TERMINAL: - UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; - wValue = (COPY_PROTECT_CONTROL << 8U); - AUDIO_Handle->mem[0] = 0x00U; - - wLength = 1U; - break; - case UAC_FEATURE_UNIT: - UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum ; - /*holds the CS(control selector ) and CN (channel number)*/ - wValue = (uint16_t)((uint32_t)controlSelector << 8U) | (uint16_t)channel; - wLength = length; - break; - - case UAC_OUTPUT_TERMINAL: - UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum ; - wValue = (COPY_PROTECT_CONTROL << 8U) ; - wLength = 1U; - break; - - default: - ret = USBH_FAIL; - break; + switch (subtype) { + case UAC_INPUT_TERMINAL: + UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; + wValue = (COPY_PROTECT_CONTROL << 8U); + AUDIO_Handle->mem[0] = 0x00U; + + wLength = 1U; + break; + case UAC_FEATURE_UNIT: + UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum ; + /*holds the CS(control selector ) and CN (channel number)*/ + wValue = (uint16_t)((uint32_t)controlSelector << 8U) | (uint16_t)channel; + wLength = length; + break; + + case UAC_OUTPUT_TERMINAL: + UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum ; + wValue = (COPY_PROTECT_CONTROL << 8U) ; + wLength = 1U; + break; + + default: + ret = USBH_FAIL; + break; } - if (ret != USBH_OK) - { + if (ret != USBH_OK) { return ret; } phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \ - USB_REQ_TYPE_CLASS; + USB_REQ_TYPE_CLASS; phost->Control.setup.b.bRequest = UAC_GET_MAX; phost->Control.setup.b.wValue.w = wValue; phost->Control.setup.b.wIndex.w = wIndex; phost->Control.setup.b.wLength.w = wLength; - return(USBH_CtlReq(phost, (uint8_t *)(void *)(AUDIO_Handle->mem), wLength)); + return (USBH_CtlReq(phost, (uint8_t *)(void *)(AUDIO_Handle->mem), wLength)); } @@ -1391,56 +1291,54 @@ static USBH_StatusTypeDef USBH_AC_GetRes(USBH_HandleTypeDef *phost, uint16_t wValue = 0U, wIndex = 0U, wLength = 0U; uint8_t UnitID = 0U, InterfaceNum = 0U; AUDIO_HandleTypeDef *AUDIO_Handle; - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; USBH_StatusTypeDef ret = USBH_OK; - switch(subtype) - { - case UAC_INPUT_TERMINAL: - UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; - wValue = (COPY_PROTECT_CONTROL << 8U) ; - AUDIO_Handle->mem[0] = 0x00U; - - wLength = 1U; - break; - case UAC_FEATURE_UNIT: - UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; - /*holds the CS(control selector ) and CN (channel number)*/ - wValue = (uint16_t)((uint32_t)controlSelector << 8U) | (uint16_t)channel; - wLength = length; - break; - - case UAC_OUTPUT_TERMINAL: - UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; - wValue = (COPY_PROTECT_CONTROL << 8U) ; - wLength = 1U; - break; - - default: - ret = USBH_FAIL; - break; + switch (subtype) { + case UAC_INPUT_TERMINAL: + UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; + wValue = (COPY_PROTECT_CONTROL << 8U) ; + AUDIO_Handle->mem[0] = 0x00U; + + wLength = 1U; + break; + case UAC_FEATURE_UNIT: + UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; + /*holds the CS(control selector ) and CN (channel number)*/ + wValue = (uint16_t)((uint32_t)controlSelector << 8U) | (uint16_t)channel; + wLength = length; + break; + + case UAC_OUTPUT_TERMINAL: + UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; + wValue = (COPY_PROTECT_CONTROL << 8U) ; + wLength = 1U; + break; + + default: + ret = USBH_FAIL; + break; } - if (ret != USBH_OK) - { + if (ret != USBH_OK) { return ret; } phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE - | USB_REQ_TYPE_CLASS; + | USB_REQ_TYPE_CLASS; phost->Control.setup.b.bRequest = UAC_GET_RES; phost->Control.setup.b.wValue.w = wValue; phost->Control.setup.b.wIndex.w = wIndex; phost->Control.setup.b.wLength.w = wLength; - return(USBH_CtlReq(phost, (uint8_t *)(void *)(AUDIO_Handle->mem), wLength)); + return (USBH_CtlReq(phost, (uint8_t *)(void *)(AUDIO_Handle->mem), wLength)); } @@ -1464,56 +1362,54 @@ static USBH_StatusTypeDef USBH_AC_GetMin(USBH_HandleTypeDef *phost, uint16_t wValue = 0U, wIndex = 0U, wLength = 0U; uint8_t UnitID = 0U, InterfaceNum = 0U; AUDIO_HandleTypeDef *AUDIO_Handle; - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; USBH_StatusTypeDef ret = USBH_OK; - switch(subtype) - { - case UAC_INPUT_TERMINAL: - UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; - wValue = (COPY_PROTECT_CONTROL << 8U); - AUDIO_Handle->mem[0] = 0x00U; - - wLength = 1U; - break; - case UAC_FEATURE_UNIT: - UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; - /*holds the CS(control selector ) and CN (channel number)*/ - wValue = (uint16_t)((uint32_t)controlSelector << 8U) | (uint16_t)channel; - wLength = length; - break; - - case UAC_OUTPUT_TERMINAL: - UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID; - InterfaceNum = 0U; /*Always zero Control Interface */ - wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; - wValue = (COPY_PROTECT_CONTROL << 8U); - wLength = 1U; - break; - - default: - ret = USBH_FAIL; - break; + switch (subtype) { + case UAC_INPUT_TERMINAL: + UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; + wValue = (COPY_PROTECT_CONTROL << 8U); + AUDIO_Handle->mem[0] = 0x00U; + + wLength = 1U; + break; + case UAC_FEATURE_UNIT: + UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; + /*holds the CS(control selector ) and CN (channel number)*/ + wValue = (uint16_t)((uint32_t)controlSelector << 8U) | (uint16_t)channel; + wLength = length; + break; + + case UAC_OUTPUT_TERMINAL: + UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID; + InterfaceNum = 0U; /*Always zero Control Interface */ + wIndex = (uint16_t)((uint32_t)UnitID << 8U) | (uint16_t)InterfaceNum; + wValue = (COPY_PROTECT_CONTROL << 8U); + wLength = 1U; + break; + + default: + ret = USBH_FAIL; + break; } - if (ret != USBH_OK) - { + if (ret != USBH_OK) { return ret; } phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \ - USB_REQ_TYPE_CLASS; + USB_REQ_TYPE_CLASS; phost->Control.setup.b.bRequest = UAC_GET_MIN; phost->Control.setup.b.wValue.w = wValue; phost->Control.setup.b.wIndex.w = wIndex; phost->Control.setup.b.wLength.w = wLength; - return(USBH_CtlReq(phost, (uint8_t *)(void *)(AUDIO_Handle->mem), wLength)); + return (USBH_CtlReq(phost, (uint8_t *)(void *)(AUDIO_Handle->mem), wLength)); } @@ -1525,8 +1421,8 @@ static USBH_StatusTypeDef USBH_AC_GetMin(USBH_HandleTypeDef *phost, * @retval USBH Status */ static USBH_StatusTypeDef USBH_AUDIO_SetEndpointControls(USBH_HandleTypeDef *phost, - uint8_t Ep, - uint8_t *buff) + uint8_t Ep, + uint8_t *buff) { uint16_t wValue, wIndex, wLength; @@ -1535,14 +1431,14 @@ static USBH_StatusTypeDef USBH_AUDIO_SetEndpointControls(USBH_HandleTypeDef *pho wLength = 3U; /*length of the frequency parameter*/ phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_ENDPOINT | \ - USB_REQ_TYPE_CLASS; + USB_REQ_TYPE_CLASS; phost->Control.setup.b.bRequest = UAC_SET_CUR; phost->Control.setup.b.wValue.w = wValue; phost->Control.setup.b.wIndex.w = wIndex; phost->Control.setup.b.wLength.w = wLength; - return(USBH_CtlReq(phost, (uint8_t *)buff, wLength)); + return (USBH_CtlReq(phost, (uint8_t *)buff, wLength)); } @@ -1551,7 +1447,7 @@ static USBH_StatusTypeDef USBH_AUDIO_SetEndpointControls(USBH_HandleTypeDef *pho * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_AUDIO_InputStream (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_AUDIO_InputStream(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_BUSY; @@ -1563,71 +1459,64 @@ static USBH_StatusTypeDef USBH_AUDIO_InputStream (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_AUDIO_Control (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_AUDIO_Control(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_BUSY ; - AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; + AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; uint16_t attribute = 0U; - switch(AUDIO_Handle->control_state) - { - case AUDIO_CONTROL_INIT: - if((phost->Timer & 1U) == 0U) - { - AUDIO_Handle->control.timer = phost->Timer; - USBH_InterruptReceiveData(phost, - (uint8_t *)(void *)(AUDIO_Handle->mem), - (uint8_t)AUDIO_Handle->control.EpSize, - AUDIO_Handle->control.Pipe); - - AUDIO_Handle->temp_feature = AUDIO_Handle->headphone.asociated_feature; - AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels; + switch (AUDIO_Handle->control_state) { + case AUDIO_CONTROL_INIT: + if ((phost->Timer & 1U) == 0U) { + AUDIO_Handle->control.timer = phost->Timer; + USBH_InterruptReceiveData(phost, + (uint8_t *)(void *)(AUDIO_Handle->mem), + (uint8_t)AUDIO_Handle->control.EpSize, + AUDIO_Handle->control.Pipe); - AUDIO_Handle->control_state = AUDIO_CONTROL_CHANGE ; - } - break; - - case AUDIO_CONTROL_CHANGE: - if(USBH_LL_GetURBState(phost , AUDIO_Handle->control.Pipe) == USBH_URB_DONE) - { - attribute = LE16(&AUDIO_Handle->mem[0]); - if(USBH_AUDIO_SetControlAttribute (phost, (uint8_t)attribute) == USBH_BUSY) - { - break; + AUDIO_Handle->temp_feature = AUDIO_Handle->headphone.asociated_feature; + AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels; + + AUDIO_Handle->control_state = AUDIO_CONTROL_CHANGE ; } - } + break; - if(( phost->Timer - AUDIO_Handle->control.timer) >= AUDIO_Handle->control.Poll) - { - AUDIO_Handle->control.timer = phost->Timer; + case AUDIO_CONTROL_CHANGE: + if (USBH_LL_GetURBState(phost, AUDIO_Handle->control.Pipe) == USBH_URB_DONE) { + attribute = LE16(&AUDIO_Handle->mem[0]); + if (USBH_AUDIO_SetControlAttribute(phost, (uint8_t)attribute) == USBH_BUSY) { + break; + } + } - USBH_InterruptReceiveData(phost, - (uint8_t *)(void *)(AUDIO_Handle->mem), - (uint8_t)AUDIO_Handle->control.EpSize, - AUDIO_Handle->control.Pipe); + if ((phost->Timer - AUDIO_Handle->control.timer) >= AUDIO_Handle->control.Poll) { + AUDIO_Handle->control.timer = phost->Timer; - } - break; + USBH_InterruptReceiveData(phost, + (uint8_t *)(void *)(AUDIO_Handle->mem), + (uint8_t)AUDIO_Handle->control.EpSize, + AUDIO_Handle->control.Pipe); - case AUDIO_CONTROL_VOLUME_UP: - if( USBH_AUDIO_SetControlAttribute (phost, 1U) == USBH_OK) - { - AUDIO_Handle->control_state = AUDIO_CONTROL_INIT; + } + break; + + case AUDIO_CONTROL_VOLUME_UP: + if (USBH_AUDIO_SetControlAttribute(phost, 1U) == USBH_OK) { + AUDIO_Handle->control_state = AUDIO_CONTROL_INIT; + status = USBH_OK; + } + break; + + case AUDIO_CONTROL_VOLUME_DOWN: + if (USBH_AUDIO_SetControlAttribute(phost, 2U) == USBH_OK) { + AUDIO_Handle->control_state = AUDIO_CONTROL_INIT; status = USBH_OK; - } - break; - - case AUDIO_CONTROL_VOLUME_DOWN: - if( USBH_AUDIO_SetControlAttribute (phost, 2U) == USBH_OK) - { - AUDIO_Handle->control_state = AUDIO_CONTROL_INIT; - status = USBH_OK; - } - break; - - case AUDIO_CONTROL_IDLE: - default: - break; + } + break; + + case AUDIO_CONTROL_IDLE: + default: + break; } return status; @@ -1638,25 +1527,21 @@ static USBH_StatusTypeDef USBH_AUDIO_Control (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_AUDIO_OutputStream (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_AUDIO_OutputStream(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_BUSY ; - AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; + AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; uint8_t *buff; - switch(AUDIO_Handle->play_state) - { - case AUDIO_PLAYBACK_INIT: + switch (AUDIO_Handle->play_state) { + case AUDIO_PLAYBACK_INIT: - if( AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bSamFreqType == 0U) - { - AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP_FREQ; - } - else - { - AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP; - } + if (AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bSamFreqType == 0U) { + AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP_FREQ; + } else { + AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP; + } #if (USBH_USE_OS == 1U) phost->os_msg = (uint32_t)USBH_URB_EVENT; @@ -1666,49 +1551,47 @@ static USBH_StatusTypeDef USBH_AUDIO_OutputStream (USBH_HandleTypeDef *phost) (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case AUDIO_PLAYBACK_SET_EP_FREQ: + case AUDIO_PLAYBACK_SET_EP_FREQ: - buff = (uint8_t*)AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[0]; + buff = (uint8_t *)AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[0]; - status = USBH_AUDIO_SetEndpointControls(phost, AUDIO_Handle->headphone.Ep, buff); - if(status == USBH_OK) - { - AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE; - } - break; + status = USBH_AUDIO_SetEndpointControls(phost, AUDIO_Handle->headphone.Ep, buff); + if (status == USBH_OK) { + AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE; + } + break; - case AUDIO_PLAYBACK_SET_EP: - buff = (uint8_t *)(void *)&AUDIO_Handle->headphone.frequency; - status = USBH_AUDIO_SetEndpointControls(phost,AUDIO_Handle->headphone.Ep, buff); - if(status == USBH_OK) - { - AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE; - USBH_AUDIO_FrequencySet(phost); - } - break; + case AUDIO_PLAYBACK_SET_EP: + buff = (uint8_t *)(void *)&AUDIO_Handle->headphone.frequency; + status = USBH_AUDIO_SetEndpointControls(phost, AUDIO_Handle->headphone.Ep, buff); + if (status == USBH_OK) { + AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE; + USBH_AUDIO_FrequencySet(phost); + } + break; - case AUDIO_PLAYBACK_IDLE: - status = USBH_OK; + case AUDIO_PLAYBACK_IDLE: + status = USBH_OK; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CLASS_EVENT; + phost->os_msg = (uint32_t)USBH_CLASS_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case AUDIO_PLAYBACK_PLAY: - USBH_AUDIO_Transmit(phost); - status = USBH_OK; - break; + case AUDIO_PLAYBACK_PLAY: + USBH_AUDIO_Transmit(phost); + status = USBH_OK; + break; - default: - break; + default: + break; } return status; @@ -1719,78 +1602,69 @@ static USBH_StatusTypeDef USBH_AUDIO_OutputStream (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_AUDIO_Transmit (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_AUDIO_Transmit(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_BUSY ; - AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; - - switch(AUDIO_Handle->processing_state) - { - case AUDIO_DATA_START_OUT: - /* Sync with start of Even Frame */ - if((phost->Timer & 1U) == 0U) - { - AUDIO_Handle->headphone.timer = phost->Timer; - AUDIO_Handle->processing_state = AUDIO_DATA_OUT; - USBH_IsocSendData(phost, - AUDIO_Handle->headphone.buf, - (uint32_t)AUDIO_Handle->headphone.frame_length, - AUDIO_Handle->headphone.Pipe); - - AUDIO_Handle->headphone.partial_ptr = AUDIO_Handle->headphone.frame_length; - AUDIO_Handle->headphone.global_ptr = AUDIO_Handle->headphone.frame_length; - AUDIO_Handle->headphone.cbuf = AUDIO_Handle->headphone.buf; - } - else - { + AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + + switch (AUDIO_Handle->processing_state) { + case AUDIO_DATA_START_OUT: + /* Sync with start of Even Frame */ + if ((phost->Timer & 1U) == 0U) { + AUDIO_Handle->headphone.timer = phost->Timer; + AUDIO_Handle->processing_state = AUDIO_DATA_OUT; + USBH_IsocSendData(phost, + AUDIO_Handle->headphone.buf, + (uint32_t)AUDIO_Handle->headphone.frame_length, + AUDIO_Handle->headphone.Pipe); + + AUDIO_Handle->headphone.partial_ptr = AUDIO_Handle->headphone.frame_length; + AUDIO_Handle->headphone.global_ptr = AUDIO_Handle->headphone.frame_length; + AUDIO_Handle->headphone.cbuf = AUDIO_Handle->headphone.buf; + } else { #if (USBH_USE_OS == 1U) - osDelay(1); - phost->os_msg = (uint32_t)USBH_CLASS_EVENT; + osDelay(1); + phost->os_msg = (uint32_t)USBH_CLASS_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; - - case AUDIO_DATA_OUT: - if((USBH_LL_GetURBState(phost , AUDIO_Handle->headphone.Pipe) == USBH_URB_DONE)&& - (( phost->Timer - AUDIO_Handle->headphone.timer) >= AUDIO_Handle->headphone.Poll)) - { - AUDIO_Handle->headphone.timer = phost->Timer; - - if(AUDIO_Handle->control.supported == 1U) - { - USBH_AUDIO_Control (phost); } + break; - if(AUDIO_Handle->headphone.global_ptr <= AUDIO_Handle->headphone.total_length) - { - USBH_IsocSendData(phost, - AUDIO_Handle->headphone.cbuf, - (uint32_t)AUDIO_Handle->headphone.frame_length, - AUDIO_Handle->headphone.Pipe); + case AUDIO_DATA_OUT: + if ((USBH_LL_GetURBState(phost, AUDIO_Handle->headphone.Pipe) == USBH_URB_DONE) && + ((phost->Timer - AUDIO_Handle->headphone.timer) >= AUDIO_Handle->headphone.Poll)) { + AUDIO_Handle->headphone.timer = phost->Timer; - AUDIO_Handle->headphone.cbuf += AUDIO_Handle->headphone.frame_length; - AUDIO_Handle->headphone.partial_ptr += AUDIO_Handle->headphone.frame_length; - AUDIO_Handle->headphone.global_ptr += AUDIO_Handle->headphone.frame_length; - } - else - { - AUDIO_Handle->headphone.partial_ptr = 0xFFFFFFFFU; - AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE; - USBH_AUDIO_BufferEmptyCallback(phost); + if (AUDIO_Handle->control.supported == 1U) { + USBH_AUDIO_Control(phost); + } + + if (AUDIO_Handle->headphone.global_ptr <= AUDIO_Handle->headphone.total_length) { + USBH_IsocSendData(phost, + AUDIO_Handle->headphone.cbuf, + (uint32_t)AUDIO_Handle->headphone.frame_length, + AUDIO_Handle->headphone.Pipe); + + AUDIO_Handle->headphone.cbuf += AUDIO_Handle->headphone.frame_length; + AUDIO_Handle->headphone.partial_ptr += AUDIO_Handle->headphone.frame_length; + AUDIO_Handle->headphone.global_ptr += AUDIO_Handle->headphone.frame_length; + } else { + AUDIO_Handle->headphone.partial_ptr = 0xFFFFFFFFU; + AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE; + USBH_AUDIO_BufferEmptyCallback(phost); + } } - } - break; + break; - default: - status = USBH_FAIL; - break; + default: + status = USBH_FAIL; + break; } return status; } @@ -1804,10 +1678,10 @@ static USBH_StatusTypeDef USBH_AUDIO_Transmit (USBH_HandleTypeDef *phost) * @param BitPerSample: Bit Per Sample * @retval USBH Status */ -USBH_StatusTypeDef USBH_AUDIO_SetFrequency (USBH_HandleTypeDef *phost, - uint16_t SampleRate, - uint8_t NbrChannels, - uint8_t BitPerSample) +USBH_StatusTypeDef USBH_AUDIO_SetFrequency(USBH_HandleTypeDef *phost, + uint16_t SampleRate, + uint8_t NbrChannels, + uint8_t BitPerSample) { USBH_StatusTypeDef Status = USBH_BUSY; AUDIO_HandleTypeDef *AUDIO_Handle; @@ -1816,40 +1690,31 @@ USBH_StatusTypeDef USBH_AUDIO_SetFrequency (USBH_HandleTypeDef *phost, uint32_t freq_min, freq_max; uint8_t num_supported_freq; - if(phost->gState == HOST_CLASS) - { - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; - if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE) - { + if (phost->gState == HOST_CLASS) { + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + if (AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE) { - if(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bSamFreqType == 0U) - { + if (AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bSamFreqType == 0U) { freq_min = LE24(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[0]); freq_max = LE24(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[1]); - if(( SampleRate >= freq_min)&& (SampleRate <= freq_max)) - { + if ((SampleRate >= freq_min) && (SampleRate <= freq_max)) { change_freq = TRUE; } - } - else - { + } else { num_supported_freq = (AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bLength - 8U) / 3U; - for(index = 0U; index < num_supported_freq; index++) - { - if(SampleRate == LE24(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[index])) - { + for (index = 0U; index < num_supported_freq; index++) { + if (SampleRate == LE24(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[index])) { change_freq = TRUE; break; } } } - if(change_freq == TRUE) - { + if (change_freq == TRUE) { AUDIO_Handle->headphone.frequency = SampleRate; AUDIO_Handle->headphone.frame_length = (SampleRate * BitPerSample * NbrChannels) / 8000U; AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP; @@ -1858,7 +1723,7 @@ USBH_StatusTypeDef USBH_AUDIO_SetFrequency (USBH_HandleTypeDef *phost, } } } - return Status; + return Status; } /** @@ -1869,16 +1734,14 @@ USBH_StatusTypeDef USBH_AUDIO_SetFrequency (USBH_HandleTypeDef *phost, * @param length: total length of the audio data * @retval USBH Status */ -USBH_StatusTypeDef USBH_AUDIO_Play (USBH_HandleTypeDef *phost, uint8_t *buf, uint32_t length) +USBH_StatusTypeDef USBH_AUDIO_Play(USBH_HandleTypeDef *phost, uint8_t *buf, uint32_t length) { USBH_StatusTypeDef Status = USBH_FAIL; AUDIO_HandleTypeDef *AUDIO_Handle; - if(phost->gState == HOST_CLASS) - { - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; - if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE) - { + if (phost->gState == HOST_CLASS) { + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + if (AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE) { AUDIO_Handle->headphone.buf = buf; AUDIO_Handle->headphone.total_length = length; AUDIO_Handle->play_state = AUDIO_PLAYBACK_PLAY; @@ -1905,7 +1768,7 @@ USBH_StatusTypeDef USBH_AUDIO_Play (USBH_HandleTypeDef *phost, uint8_t *buf, uin * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_AUDIO_Stop (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_AUDIO_Stop(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef Status = USBH_FAIL; Status = USBH_AUDIO_Suspend(phost); @@ -1918,16 +1781,14 @@ USBH_StatusTypeDef USBH_AUDIO_Stop (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_AUDIO_Suspend (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_AUDIO_Suspend(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef Status = USBH_FAIL; AUDIO_HandleTypeDef *AUDIO_Handle; - if(phost->gState == HOST_CLASS) - { - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; - if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY) - { + if (phost->gState == HOST_CLASS) { + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + if (AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY) { AUDIO_Handle->control_state = AUDIO_CONTROL_IDLE; AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE; Status = USBH_OK; @@ -1941,16 +1802,14 @@ USBH_StatusTypeDef USBH_AUDIO_Suspend (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_AUDIO_Resume (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_AUDIO_Resume(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef Status = USBH_FAIL; AUDIO_HandleTypeDef *AUDIO_Handle; - if(phost->gState == HOST_CLASS) - { - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; - if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE) - { + if (phost->gState == HOST_CLASS) { + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + if (AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE) { AUDIO_Handle->control_state = AUDIO_CONTROL_INIT; AUDIO_Handle->play_state = AUDIO_PLAYBACK_PLAY; } @@ -1963,15 +1822,13 @@ USBH_StatusTypeDef USBH_AUDIO_Resume (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -int32_t USBH_AUDIO_GetOutOffset (USBH_HandleTypeDef *phost) +int32_t USBH_AUDIO_GetOutOffset(USBH_HandleTypeDef *phost) { AUDIO_HandleTypeDef *AUDIO_Handle; - if(phost->gState == HOST_CLASS) - { - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; - if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY) - { + if (phost->gState == HOST_CLASS) { + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + if (AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY) { return (int32_t)AUDIO_Handle->headphone.partial_ptr; } } @@ -1985,21 +1842,17 @@ int32_t USBH_AUDIO_GetOutOffset (USBH_HandleTypeDef *phost) * @param buf: buffer address * @retval USBH Status */ -USBH_StatusTypeDef USBH_AUDIO_ChangeOutBuffer (USBH_HandleTypeDef *phost, uint8_t *buf) +USBH_StatusTypeDef USBH_AUDIO_ChangeOutBuffer(USBH_HandleTypeDef *phost, uint8_t *buf) { USBH_StatusTypeDef Status = USBH_FAIL; AUDIO_HandleTypeDef *AUDIO_Handle; - if(phost->gState == HOST_CLASS) - { - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; - if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY) - { - if(AUDIO_Handle->headphone.buf <= buf) - { + if (phost->gState == HOST_CLASS) { + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + if (AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY) { + if (AUDIO_Handle->headphone.buf <= buf) { AUDIO_Handle->headphone.cbuf = buf; - if ( AUDIO_Handle->headphone.buf == buf) - { + if (AUDIO_Handle->headphone.buf == buf) { AUDIO_Handle->headphone.partial_ptr = 0U; } Status = USBH_OK; @@ -2016,53 +1869,46 @@ USBH_StatusTypeDef USBH_AUDIO_ChangeOutBuffer (USBH_HandleTypeDef *phost, uint8_ * @param attrib: control attribute * @retval USBH Status */ -static USBH_StatusTypeDef USBH_AUDIO_SetControlAttribute (USBH_HandleTypeDef *phost, uint8_t attrib) +static USBH_StatusTypeDef USBH_AUDIO_SetControlAttribute(USBH_HandleTypeDef *phost, uint8_t attrib) { USBH_StatusTypeDef status = USBH_BUSY; AUDIO_HandleTypeDef *AUDIO_Handle; - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; - switch (attrib) - { - case 0x01: - AUDIO_Handle->headphone.attribute.volume += AUDIO_Handle->headphone.attribute.resolution; - break; + switch (attrib) { + case 0x01: + AUDIO_Handle->headphone.attribute.volume += AUDIO_Handle->headphone.attribute.resolution; + break; - case 0x02: - AUDIO_Handle->headphone.attribute.volume -= AUDIO_Handle->headphone.attribute.resolution; - break; + case 0x02: + AUDIO_Handle->headphone.attribute.volume -= AUDIO_Handle->headphone.attribute.resolution; + break; - default : - status = USBH_FAIL; - break; + default : + status = USBH_FAIL; + break; } - if(AUDIO_Handle->headphone.attribute.volume > AUDIO_Handle->headphone.attribute.volumeMax) - { - AUDIO_Handle->headphone.attribute.volume =AUDIO_Handle->headphone.attribute.volumeMax; + if (AUDIO_Handle->headphone.attribute.volume > AUDIO_Handle->headphone.attribute.volumeMax) { + AUDIO_Handle->headphone.attribute.volume = AUDIO_Handle->headphone.attribute.volumeMax; } - if(AUDIO_Handle->headphone.attribute.volume < AUDIO_Handle->headphone.attribute.volumeMin) - { - AUDIO_Handle->headphone.attribute.volume =AUDIO_Handle->headphone.attribute.volumeMin; + if (AUDIO_Handle->headphone.attribute.volume < AUDIO_Handle->headphone.attribute.volumeMin) { + AUDIO_Handle->headphone.attribute.volume = AUDIO_Handle->headphone.attribute.volumeMin; } - if(AUDIO_SetVolume (phost, + if (AUDIO_SetVolume(phost, AUDIO_Handle->temp_feature, (uint8_t)AUDIO_Handle->temp_channels, - (uint16_t)AUDIO_Handle->headphone.attribute.volume) != USBH_BUSY) - { + (uint16_t)AUDIO_Handle->headphone.attribute.volume) != USBH_BUSY) { - if(AUDIO_Handle->temp_channels == 1U) - { + if (AUDIO_Handle->temp_channels == 1U) { AUDIO_Handle->temp_feature = AUDIO_Handle->headphone.asociated_feature; AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels; status = USBH_OK; - } - else - { + } else { AUDIO_Handle->temp_channels--; } AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME; @@ -2080,18 +1926,15 @@ static USBH_StatusTypeDef USBH_AUDIO_SetControlAttribute (USBH_HandleTypeDef *ph * @param volume: VOLUME_UP/ VOLUME_DOWN * @retval USBH Status */ -USBH_StatusTypeDef USBH_AUDIO_SetVolume (USBH_HandleTypeDef *phost, AUDIO_VolumeCtrlTypeDef volume_ctl) +USBH_StatusTypeDef USBH_AUDIO_SetVolume(USBH_HandleTypeDef *phost, AUDIO_VolumeCtrlTypeDef volume_ctl) { - AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; - - if((volume_ctl == VOLUME_UP) || (volume_ctl == VOLUME_DOWN)) - { - if(phost->gState == HOST_CLASS) - { - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; - if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY) - { - AUDIO_Handle->control_state = (volume_ctl == VOLUME_UP)? AUDIO_CONTROL_VOLUME_UP : AUDIO_CONTROL_VOLUME_DOWN; + AUDIO_HandleTypeDef *AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + + if ((volume_ctl == VOLUME_UP) || (volume_ctl == VOLUME_DOWN)) { + if (phost->gState == HOST_CLASS) { + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; + if (AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY) { + AUDIO_Handle->control_state = (volume_ctl == VOLUME_UP) ? AUDIO_CONTROL_VOLUME_UP : AUDIO_CONTROL_VOLUME_DOWN; return USBH_OK; } } @@ -2108,13 +1951,13 @@ USBH_StatusTypeDef USBH_AUDIO_SetVolume (USBH_HandleTypeDef *phost, AUDIO_Volume * @param volume: new volume * @retval USBH Status */ -static USBH_StatusTypeDef AUDIO_SetVolume (USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel, uint16_t volume) +static USBH_StatusTypeDef AUDIO_SetVolume(USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel, uint16_t volume) { USBH_StatusTypeDef status = USBH_BUSY ; AUDIO_HandleTypeDef *AUDIO_Handle; - AUDIO_Handle = (AUDIO_HandleTypeDef*) phost->pActiveClass->pData; + AUDIO_Handle = (AUDIO_HandleTypeDef *) phost->pActiveClass->pData; AUDIO_Handle->mem[0] = volume; diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc/usbh_cdc.h b/system/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc/usbh_cdc.h index 75b53614b0..d23e07eff6 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc/usbh_cdc.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc/usbh_cdc.h @@ -22,7 +22,7 @@ #define __USBH_CDC_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -135,8 +135,7 @@ */ /* States for CDC State Machine */ -typedef enum -{ +typedef enum { CDC_IDLE = 0U, CDC_SEND_DATA, CDC_SEND_DATA_WAIT, @@ -145,8 +144,7 @@ typedef enum } CDC_DataStateTypeDef; -typedef enum -{ +typedef enum { CDC_IDLE_STATE = 0U, CDC_SET_LINE_CODING_STATE, CDC_GET_LAST_LINE_CODING_STATE, @@ -157,12 +155,10 @@ CDC_StateTypeDef; /*Line coding structure*/ -typedef union _CDC_LineCodingStructure -{ +typedef union _CDC_LineCodingStructure { uint8_t Array[LINE_CODING_STRUCTURE_SIZE]; - struct - { + struct { uint32_t dwDTERate; /*Data terminal rate, in bits per second*/ uint8_t bCharFormat; /*Stop bits @@ -176,7 +172,7 @@ typedef union _CDC_LineCodingStructure 3 - Mark 4 - Space*/ uint8_t bDataBits; /* Data bits (5, 6, 7, 8 or 16). */ - }b; + } b; } CDC_LineCodingTypeDef; @@ -197,8 +193,7 @@ Offset| field | Size | Value | Description | | | | decimal ------|---------------------|-------|------------|------------------------------ */ -typedef struct _FunctionalDescriptorHeader -{ +typedef struct _FunctionalDescriptorHeader { uint8_t bLength; /*Size of this descriptor.*/ uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/ uint8_t bDescriptorSubType; /* Header functional descriptor subtype as*/ @@ -238,8 +233,7 @@ Offset| field | Size | Value | Description | | | | optionally used for call management. ------|---------------------|-------|------------|------------------------------ */ -typedef struct _CallMgmtFunctionalDescriptor -{ +typedef struct _CallMgmtFunctionalDescriptor { uint8_t bLength; /*Size of this functional descriptor, in bytes.*/ uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/ uint8_t bDescriptorSubType; /* Call Management functional descriptor subtype*/ @@ -276,8 +270,7 @@ Offset| field | Size | Value | Description | | | | SubClass code of Abstract Control Model. ------|---------------------|-------|------------|------------------------------ */ -typedef struct _AbstractCntrlMgmtFunctionalDescriptor -{ +typedef struct _AbstractCntrlMgmtFunctionalDescriptor { uint8_t bLength; /*Size of this functional descriptor, in bytes.*/ uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/ uint8_t bDescriptorSubType; /* Abstract Control Management functional @@ -299,8 +292,7 @@ Offset| field | Size | Value | Description | | | | interface in the union. ------|---------------------|-------|------------|------------------------------ */ -typedef struct _UnionFunctionalDescriptor -{ +typedef struct _UnionFunctionalDescriptor { uint8_t bLength; /*Size of this functional descriptor, in bytes*/ uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/ uint8_t bDescriptorSubType; /* Union functional descriptor SubType*/ @@ -310,8 +302,7 @@ typedef struct _UnionFunctionalDescriptor } CDC_UnionFuncDesc_TypeDef; -typedef struct _USBH_CDCInterfaceDesc -{ +typedef struct _USBH_CDCInterfaceDesc { CDC_HeaderFuncDesc_TypeDef CDC_HeaderFuncDesc; CDC_CallMgmtFuncDesc_TypeDef CDC_CallMgmtFuncDesc; CDC_AbstCntrlMgmtFuncDesc_TypeDef CDC_AbstCntrlMgmtFuncDesc; @@ -321,8 +312,7 @@ CDC_InterfaceDesc_Typedef; /* Structure for CDC process */ -typedef struct -{ +typedef struct { uint8_t NotifPipe; uint8_t NotifEp; uint8_t buff[8]; @@ -330,8 +320,7 @@ typedef struct } CDC_CommItfTypedef ; -typedef struct -{ +typedef struct { uint8_t InPipe; uint8_t OutPipe; uint8_t OutEp; @@ -343,8 +332,7 @@ typedef struct CDC_DataItfTypedef ; /* Structure for CDC process */ -typedef struct _CDC_Process -{ +typedef struct _CDC_Process { CDC_CommItfTypedef CommItf; CDC_DataItfTypedef DataItf; uint8_t *pTxData; diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Src/usbh_cdc.c b/system/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Src/usbh_cdc.c index a087a92209..da922aeadc 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Src/usbh_cdc.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Src/usbh_cdc.c @@ -37,13 +37,13 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" - - "stm32xxxxx_{eval}{discovery}_sdram.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" +- "stm32xxxxx_{eval}{discovery}_sdram.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbh_cdc.h" @@ -102,28 +102,27 @@ * @{ */ -static USBH_StatusTypeDef USBH_CDC_InterfaceInit (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_CDC_InterfaceInit(USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_CDC_InterfaceDeInit (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_CDC_InterfaceDeInit(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef USBH_CDC_Process(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef USBH_CDC_SOFProcess(USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_CDC_ClassRequest (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_CDC_ClassRequest(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef GetLineCoding(USBH_HandleTypeDef *phost, - CDC_LineCodingTypeDef *linecoding); + CDC_LineCodingTypeDef *linecoding); static USBH_StatusTypeDef SetLineCoding(USBH_HandleTypeDef *phost, - CDC_LineCodingTypeDef *linecoding); + CDC_LineCodingTypeDef *linecoding); static void CDC_ProcessTransmission(USBH_HandleTypeDef *phost); static void CDC_ProcessReception(USBH_HandleTypeDef *phost); -USBH_ClassTypeDef CDC_Class = -{ +USBH_ClassTypeDef CDC_Class = { "CDC", USB_CDC_CLASS, USBH_CDC_InterfaceInit, @@ -148,7 +147,7 @@ USBH_ClassTypeDef CDC_Class = * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_CDC_InterfaceInit (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_CDC_InterfaceInit(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_FAIL ; @@ -156,23 +155,19 @@ static USBH_StatusTypeDef USBH_CDC_InterfaceInit (USBH_HandleTypeDef *phost) CDC_HandleTypeDef *CDC_Handle; interface = USBH_FindInterface(phost, - COMMUNICATION_INTERFACE_CLASS_CODE, - ABSTRACT_CONTROL_MODEL, - COMMON_AT_COMMAND); + COMMUNICATION_INTERFACE_CLASS_CODE, + ABSTRACT_CONTROL_MODEL, + COMMON_AT_COMMAND); - if(interface == 0xFFU) /* No Valid Interface */ - { - USBH_DbgLog ("Cannot Find the interface for Communication Interface Class.", phost->pActiveClass->Name); - } - else - { - USBH_SelectInterface (phost, interface); - phost->pActiveClass->pData = (CDC_HandleTypeDef *)USBH_malloc (sizeof(CDC_HandleTypeDef)); - CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData; + if (interface == 0xFFU) { /* No Valid Interface */ + USBH_DbgLog("Cannot Find the interface for Communication Interface Class.", phost->pActiveClass->Name); + } else { + USBH_SelectInterface(phost, interface); + phost->pActiveClass->pData = (CDC_HandleTypeDef *)USBH_malloc(sizeof(CDC_HandleTypeDef)); + CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData; /*Collect the notification endpoint address and length*/ - if(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80U) - { + if (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80U) { CDC_Handle->CommItf.NotifEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress; CDC_Handle->CommItf.NotifEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize; } @@ -181,46 +176,37 @@ static USBH_StatusTypeDef USBH_CDC_InterfaceInit (USBH_HandleTypeDef *phost) CDC_Handle->CommItf.NotifPipe = USBH_AllocPipe(phost, CDC_Handle->CommItf.NotifEp); /* Open pipe for Notification endpoint */ - USBH_OpenPipe (phost, - CDC_Handle->CommItf.NotifPipe, - CDC_Handle->CommItf.NotifEp, - phost->device.address, - phost->device.speed, - USB_EP_TYPE_INTR, - CDC_Handle->CommItf.NotifEpSize); + USBH_OpenPipe(phost, + CDC_Handle->CommItf.NotifPipe, + CDC_Handle->CommItf.NotifEp, + phost->device.address, + phost->device.speed, + USB_EP_TYPE_INTR, + CDC_Handle->CommItf.NotifEpSize); - USBH_LL_SetToggle (phost, CDC_Handle->CommItf.NotifPipe, 0U); + USBH_LL_SetToggle(phost, CDC_Handle->CommItf.NotifPipe, 0U); interface = USBH_FindInterface(phost, - DATA_INTERFACE_CLASS_CODE, - RESERVED, - NO_CLASS_SPECIFIC_PROTOCOL_CODE); + DATA_INTERFACE_CLASS_CODE, + RESERVED, + NO_CLASS_SPECIFIC_PROTOCOL_CODE); - if(interface == 0xFFU) /* No Valid Interface */ - { - USBH_DbgLog ("Cannot Find the interface for Data Interface Class.", phost->pActiveClass->Name); - } - else - { + if (interface == 0xFFU) { /* No Valid Interface */ + USBH_DbgLog("Cannot Find the interface for Data Interface Class.", phost->pActiveClass->Name); + } else { /*Collect the class specific endpoint address and length*/ - if(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80U) - { + if (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80U) { CDC_Handle->DataItf.InEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress; CDC_Handle->DataItf.InEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize; - } - else - { + } else { CDC_Handle->DataItf.OutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress; CDC_Handle->DataItf.OutEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize; } - if(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress & 0x80U) - { + if (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress & 0x80U) { CDC_Handle->DataItf.InEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress; CDC_Handle->DataItf.InEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].wMaxPacketSize; - } - else - { + } else { CDC_Handle->DataItf.OutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress; CDC_Handle->DataItf.OutEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].wMaxPacketSize; } @@ -232,26 +218,26 @@ static USBH_StatusTypeDef USBH_CDC_InterfaceInit (USBH_HandleTypeDef *phost) CDC_Handle->DataItf.InPipe = USBH_AllocPipe(phost, CDC_Handle->DataItf.InEp); /* Open channel for OUT endpoint */ - USBH_OpenPipe (phost, - CDC_Handle->DataItf.OutPipe, - CDC_Handle->DataItf.OutEp, - phost->device.address, - phost->device.speed, - USB_EP_TYPE_BULK, - CDC_Handle->DataItf.OutEpSize); + USBH_OpenPipe(phost, + CDC_Handle->DataItf.OutPipe, + CDC_Handle->DataItf.OutEp, + phost->device.address, + phost->device.speed, + USB_EP_TYPE_BULK, + CDC_Handle->DataItf.OutEpSize); /* Open channel for IN endpoint */ - USBH_OpenPipe (phost, - CDC_Handle->DataItf.InPipe, - CDC_Handle->DataItf.InEp, - phost->device.address, - phost->device.speed, - USB_EP_TYPE_BULK, - CDC_Handle->DataItf.InEpSize); + USBH_OpenPipe(phost, + CDC_Handle->DataItf.InPipe, + CDC_Handle->DataItf.InEp, + phost->device.address, + phost->device.speed, + USB_EP_TYPE_BULK, + CDC_Handle->DataItf.InEpSize); CDC_Handle->state = CDC_IDLE_STATE; - USBH_LL_SetToggle (phost, CDC_Handle->DataItf.OutPipe, 0U); - USBH_LL_SetToggle (phost, CDC_Handle->DataItf.InPipe, 0U); + USBH_LL_SetToggle(phost, CDC_Handle->DataItf.OutPipe, 0U); + USBH_LL_SetToggle(phost, CDC_Handle->DataItf.InPipe, 0U); status = USBH_OK; } } @@ -266,34 +252,30 @@ static USBH_StatusTypeDef USBH_CDC_InterfaceInit (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_CDC_InterfaceDeInit (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_CDC_InterfaceDeInit(USBH_HandleTypeDef *phost) { - CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData; + CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData; - if ( CDC_Handle->CommItf.NotifPipe) - { + if (CDC_Handle->CommItf.NotifPipe) { USBH_ClosePipe(phost, CDC_Handle->CommItf.NotifPipe); - USBH_FreePipe (phost, CDC_Handle->CommItf.NotifPipe); + USBH_FreePipe(phost, CDC_Handle->CommItf.NotifPipe); CDC_Handle->CommItf.NotifPipe = 0U; /* Reset the Channel as Free */ } - if ( CDC_Handle->DataItf.InPipe) - { + if (CDC_Handle->DataItf.InPipe) { USBH_ClosePipe(phost, CDC_Handle->DataItf.InPipe); - USBH_FreePipe (phost, CDC_Handle->DataItf.InPipe); + USBH_FreePipe(phost, CDC_Handle->DataItf.InPipe); CDC_Handle->DataItf.InPipe = 0U; /* Reset the Channel as Free */ } - if ( CDC_Handle->DataItf.OutPipe) - { + if (CDC_Handle->DataItf.OutPipe) { USBH_ClosePipe(phost, CDC_Handle->DataItf.OutPipe); - USBH_FreePipe (phost, CDC_Handle->DataItf.OutPipe); + USBH_FreePipe(phost, CDC_Handle->DataItf.OutPipe); CDC_Handle->DataItf.OutPipe = 0U; /* Reset the Channel as Free */ } - if(phost->pActiveClass->pData) - { - USBH_free (phost->pActiveClass->pData); + if (phost->pActiveClass->pData) { + USBH_free(phost->pActiveClass->pData); phost->pActiveClass->pData = 0U; } @@ -307,15 +289,14 @@ static USBH_StatusTypeDef USBH_CDC_InterfaceDeInit (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_CDC_ClassRequest (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_CDC_ClassRequest(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_FAIL ; - CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData; + CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData; /*Issue the get line coding request*/ status = GetLineCoding(phost, &CDC_Handle->LineCoding); - if(status == USBH_OK) - { + if (status == USBH_OK) { phost->pUser(phost, HOST_USER_CLASS_ACTIVE); } return status; @@ -328,78 +309,68 @@ static USBH_StatusTypeDef USBH_CDC_ClassRequest (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_CDC_Process (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_CDC_Process(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_BUSY; USBH_StatusTypeDef req_status = USBH_OK; - CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData; + CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData; - switch(CDC_Handle->state) - { + switch (CDC_Handle->state) { - case CDC_IDLE_STATE: - status = USBH_OK; - break; + case CDC_IDLE_STATE: + status = USBH_OK; + break; - case CDC_SET_LINE_CODING_STATE: - req_status = SetLineCoding(phost, CDC_Handle->pUserLineCoding); + case CDC_SET_LINE_CODING_STATE: + req_status = SetLineCoding(phost, CDC_Handle->pUserLineCoding); - if(req_status == USBH_OK) - { - CDC_Handle->state = CDC_GET_LAST_LINE_CODING_STATE; - } + if (req_status == USBH_OK) { + CDC_Handle->state = CDC_GET_LAST_LINE_CODING_STATE; + } - else - { - if(req_status != USBH_BUSY) - { - CDC_Handle->state = CDC_ERROR_STATE; + else { + if (req_status != USBH_BUSY) { + CDC_Handle->state = CDC_ERROR_STATE; + } } - } - break; + break; - case CDC_GET_LAST_LINE_CODING_STATE: - req_status = GetLineCoding(phost, &(CDC_Handle->LineCoding)); + case CDC_GET_LAST_LINE_CODING_STATE: + req_status = GetLineCoding(phost, &(CDC_Handle->LineCoding)); - if(req_status == USBH_OK) - { - CDC_Handle->state = CDC_IDLE_STATE; + if (req_status == USBH_OK) { + CDC_Handle->state = CDC_IDLE_STATE; - if((CDC_Handle->LineCoding.b.bCharFormat == CDC_Handle->pUserLineCoding->b.bCharFormat) && - (CDC_Handle->LineCoding.b.bDataBits == CDC_Handle->pUserLineCoding->b.bDataBits) && - (CDC_Handle->LineCoding.b.bParityType == CDC_Handle->pUserLineCoding->b.bParityType) && - (CDC_Handle->LineCoding.b.dwDTERate == CDC_Handle->pUserLineCoding->b.dwDTERate)) - { - USBH_CDC_LineCodingChanged(phost); - } - } - else - { - if(req_status != USBH_BUSY) - { - CDC_Handle->state = CDC_ERROR_STATE; + if ((CDC_Handle->LineCoding.b.bCharFormat == CDC_Handle->pUserLineCoding->b.bCharFormat) && + (CDC_Handle->LineCoding.b.bDataBits == CDC_Handle->pUserLineCoding->b.bDataBits) && + (CDC_Handle->LineCoding.b.bParityType == CDC_Handle->pUserLineCoding->b.bParityType) && + (CDC_Handle->LineCoding.b.dwDTERate == CDC_Handle->pUserLineCoding->b.dwDTERate)) { + USBH_CDC_LineCodingChanged(phost); + } + } else { + if (req_status != USBH_BUSY) { + CDC_Handle->state = CDC_ERROR_STATE; + } } - } - break; + break; - case CDC_TRANSFER_DATA: - CDC_ProcessTransmission(phost); - CDC_ProcessReception(phost); - break; + case CDC_TRANSFER_DATA: + CDC_ProcessTransmission(phost); + CDC_ProcessReception(phost); + break; - case CDC_ERROR_STATE: - req_status = USBH_ClrFeature(phost, 0x00U); + case CDC_ERROR_STATE: + req_status = USBH_ClrFeature(phost, 0x00U); - if(req_status == USBH_OK ) - { - /*Change the state to waiting*/ - CDC_Handle->state = CDC_IDLE_STATE ; - } - break; + if (req_status == USBH_OK) { + /*Change the state to waiting*/ + CDC_Handle->state = CDC_IDLE_STATE ; + } + break; - default: - break; + default: + break; } @@ -412,7 +383,7 @@ static USBH_StatusTypeDef USBH_CDC_Process (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_CDC_SOFProcess (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_CDC_SOFProcess(USBH_HandleTypeDef *phost) { return USBH_OK; } @@ -426,10 +397,9 @@ static USBH_StatusTypeDef USBH_CDC_SOFProcess (USBH_HandleTypeDef *phost) */ USBH_StatusTypeDef USBH_CDC_Stop(USBH_HandleTypeDef *phost) { - CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData; + CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData; - if(phost->gState == HOST_CLASS) - { + if (phost->gState == HOST_CLASS) { CDC_Handle->state = CDC_IDLE_STATE; USBH_ClosePipe(phost, CDC_Handle->CommItf.NotifPipe); @@ -448,7 +418,7 @@ static USBH_StatusTypeDef GetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodin { phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_TYPE_CLASS | \ - USB_REQ_RECIPIENT_INTERFACE; + USB_REQ_RECIPIENT_INTERFACE; phost->Control.setup.b.bRequest = CDC_GET_LINE_CODING; phost->Control.setup.b.wValue.w = 0U; @@ -491,10 +461,9 @@ static USBH_StatusTypeDef SetLineCoding(USBH_HandleTypeDef *phost, USBH_StatusTypeDef USBH_CDC_SetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecoding) { - CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData; + CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData; - if(phost->gState == HOST_CLASS) - { + if (phost->gState == HOST_CLASS) { CDC_Handle->state = CDC_SET_LINE_CODING_STATE; CDC_Handle->pUserLineCoding = linecoding; @@ -519,15 +488,12 @@ USBH_StatusTypeDef USBH_CDC_SetLineCoding(USBH_HandleTypeDef *phost, USBH_StatusTypeDef USBH_CDC_GetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecoding) { - CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData; + CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData; - if((phost->gState == HOST_CLASS) || (phost->gState == HOST_CLASS_REQUEST)) - { + if ((phost->gState == HOST_CLASS) || (phost->gState == HOST_CLASS_REQUEST)) { *linecoding = CDC_Handle->LineCoding; return USBH_OK; - } - else - { + } else { return USBH_FAIL; } } @@ -540,14 +506,11 @@ USBH_StatusTypeDef USBH_CDC_GetLineCoding(USBH_HandleTypeDef *phost, uint16_t USBH_CDC_GetLastReceivedDataSize(USBH_HandleTypeDef *phost) { uint32_t dataSize; - CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData; + CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData; - if(phost->gState == HOST_CLASS) - { + if (phost->gState == HOST_CLASS) { dataSize = USBH_LL_GetLastXferSize(phost, CDC_Handle->DataItf.InPipe); - } - else - { + } else { dataSize = 0U; } @@ -562,10 +525,9 @@ uint16_t USBH_CDC_GetLastReceivedDataSize(USBH_HandleTypeDef *phost) USBH_StatusTypeDef USBH_CDC_Transmit(USBH_HandleTypeDef *phost, uint8_t *pbuff, uint32_t length) { USBH_StatusTypeDef Status = USBH_BUSY; - CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData; + CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData; - if((CDC_Handle->state == CDC_IDLE_STATE) || (CDC_Handle->state == CDC_TRANSFER_DATA)) - { + if ((CDC_Handle->state == CDC_IDLE_STATE) || (CDC_Handle->state == CDC_TRANSFER_DATA)) { CDC_Handle->pTxData = pbuff; CDC_Handle->TxDataLength = length; CDC_Handle->state = CDC_TRANSFER_DATA; @@ -593,10 +555,9 @@ USBH_StatusTypeDef USBH_CDC_Transmit(USBH_HandleTypeDef *phost, uint8_t *pbuff, USBH_StatusTypeDef USBH_CDC_Receive(USBH_HandleTypeDef *phost, uint8_t *pbuff, uint32_t length) { USBH_StatusTypeDef Status = USBH_BUSY; - CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData; + CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData; - if((CDC_Handle->state == CDC_IDLE_STATE) || (CDC_Handle->state == CDC_TRANSFER_DATA)) - { + if ((CDC_Handle->state == CDC_IDLE_STATE) || (CDC_Handle->state == CDC_TRANSFER_DATA)) { CDC_Handle->pRxData = pbuff; CDC_Handle->RxDataLength = length; CDC_Handle->state = CDC_TRANSFER_DATA; @@ -622,88 +583,74 @@ USBH_StatusTypeDef USBH_CDC_Receive(USBH_HandleTypeDef *phost, uint8_t *pbuff, */ static void CDC_ProcessTransmission(USBH_HandleTypeDef *phost) { - CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData; + CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData; USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE; - switch (CDC_Handle->data_tx_state) - { - case CDC_SEND_DATA: - if (CDC_Handle->TxDataLength > CDC_Handle->DataItf.OutEpSize) - { - USBH_BulkSendData (phost, - CDC_Handle->pTxData, - CDC_Handle->DataItf.OutEpSize, - CDC_Handle->DataItf.OutPipe, - 1U); - } - else - { - USBH_BulkSendData (phost, - CDC_Handle->pTxData, - (uint16_t)CDC_Handle->TxDataLength, - CDC_Handle->DataItf.OutPipe, - 1U); - } + switch (CDC_Handle->data_tx_state) { + case CDC_SEND_DATA: + if (CDC_Handle->TxDataLength > CDC_Handle->DataItf.OutEpSize) { + USBH_BulkSendData(phost, + CDC_Handle->pTxData, + CDC_Handle->DataItf.OutEpSize, + CDC_Handle->DataItf.OutPipe, + 1U); + } else { + USBH_BulkSendData(phost, + CDC_Handle->pTxData, + (uint16_t)CDC_Handle->TxDataLength, + CDC_Handle->DataItf.OutPipe, + 1U); + } - CDC_Handle->data_tx_state = CDC_SEND_DATA_WAIT; - break; + CDC_Handle->data_tx_state = CDC_SEND_DATA_WAIT; + break; - case CDC_SEND_DATA_WAIT: + case CDC_SEND_DATA_WAIT: - URB_Status = USBH_LL_GetURBState(phost, CDC_Handle->DataItf.OutPipe); + URB_Status = USBH_LL_GetURBState(phost, CDC_Handle->DataItf.OutPipe); - /* Check the status done for transmission */ - if (URB_Status == USBH_URB_DONE) - { - if (CDC_Handle->TxDataLength > CDC_Handle->DataItf.OutEpSize) - { - CDC_Handle->TxDataLength -= CDC_Handle->DataItf.OutEpSize; - CDC_Handle->pTxData += CDC_Handle->DataItf.OutEpSize; - } - else - { - CDC_Handle->TxDataLength = 0U; - } + /* Check the status done for transmission */ + if (URB_Status == USBH_URB_DONE) { + if (CDC_Handle->TxDataLength > CDC_Handle->DataItf.OutEpSize) { + CDC_Handle->TxDataLength -= CDC_Handle->DataItf.OutEpSize; + CDC_Handle->pTxData += CDC_Handle->DataItf.OutEpSize; + } else { + CDC_Handle->TxDataLength = 0U; + } - if (CDC_Handle->TxDataLength > 0U) - { - CDC_Handle->data_tx_state = CDC_SEND_DATA; - } - else - { - CDC_Handle->data_tx_state = CDC_IDLE; - USBH_CDC_TransmitCallback(phost); - } + if (CDC_Handle->TxDataLength > 0U) { + CDC_Handle->data_tx_state = CDC_SEND_DATA; + } else { + CDC_Handle->data_tx_state = CDC_IDLE; + USBH_CDC_TransmitCallback(phost); + } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CLASS_EVENT; + phost->os_msg = (uint32_t)USBH_CLASS_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - if (URB_Status == USBH_URB_NOTREADY) - { - CDC_Handle->data_tx_state = CDC_SEND_DATA; + } else { + if (URB_Status == USBH_URB_NOTREADY) { + CDC_Handle->data_tx_state = CDC_SEND_DATA; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CLASS_EVENT; + phost->os_msg = (uint32_t)USBH_CLASS_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif + } } - } - break; + break; - default: - break; + default: + break; } } /** @@ -714,58 +661,53 @@ static void CDC_ProcessTransmission(USBH_HandleTypeDef *phost) static void CDC_ProcessReception(USBH_HandleTypeDef *phost) { - CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData; + CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData; USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE; uint32_t length; - switch(CDC_Handle->data_rx_state) - { + switch (CDC_Handle->data_rx_state) { - case CDC_RECEIVE_DATA: + case CDC_RECEIVE_DATA: - USBH_BulkReceiveData (phost, - CDC_Handle->pRxData, - CDC_Handle->DataItf.InEpSize, - CDC_Handle->DataItf.InPipe); + USBH_BulkReceiveData(phost, + CDC_Handle->pRxData, + CDC_Handle->DataItf.InEpSize, + CDC_Handle->DataItf.InPipe); - CDC_Handle->data_rx_state = CDC_RECEIVE_DATA_WAIT; + CDC_Handle->data_rx_state = CDC_RECEIVE_DATA_WAIT; - break; + break; - case CDC_RECEIVE_DATA_WAIT: + case CDC_RECEIVE_DATA_WAIT: - URB_Status = USBH_LL_GetURBState(phost, CDC_Handle->DataItf.InPipe); + URB_Status = USBH_LL_GetURBState(phost, CDC_Handle->DataItf.InPipe); - /*Check the status done for reception*/ - if(URB_Status == USBH_URB_DONE) - { - length = USBH_LL_GetLastXferSize(phost, CDC_Handle->DataItf.InPipe); + /*Check the status done for reception*/ + if (URB_Status == USBH_URB_DONE) { + length = USBH_LL_GetLastXferSize(phost, CDC_Handle->DataItf.InPipe); - if(((CDC_Handle->RxDataLength - length) > 0U) && (length > CDC_Handle->DataItf.InEpSize)) - { - CDC_Handle->RxDataLength -= length ; - CDC_Handle->pRxData += length; - CDC_Handle->data_rx_state = CDC_RECEIVE_DATA; - } - else - { - CDC_Handle->data_rx_state = CDC_IDLE; - USBH_CDC_ReceiveCallback(phost); - } + if (((CDC_Handle->RxDataLength - length) > 0U) && (length > CDC_Handle->DataItf.InEpSize)) { + CDC_Handle->RxDataLength -= length ; + CDC_Handle->pRxData += length; + CDC_Handle->data_rx_state = CDC_RECEIVE_DATA; + } else { + CDC_Handle->data_rx_state = CDC_IDLE; + USBH_CDC_ReceiveCallback(phost); + } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CLASS_EVENT; + phost->os_msg = (uint32_t)USBH_CLASS_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; + } + break; - default: - break; + default: + break; } } @@ -779,7 +721,7 @@ __weak void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost) } - /** +/** * @brief The function informs user that data have been sent * @param pdev: Selected device * @retval None @@ -789,7 +731,7 @@ __weak void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost) } - /** +/** * @brief The function informs user that Settings have been changed * @param pdev: Selected device * @retval None diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid.h b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid.h index d150d94161..774bc8827c 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid.h @@ -22,7 +22,7 @@ #define __USBH_HID_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -100,9 +100,8 @@ /* States for HID State Machine */ -typedef enum -{ - HID_INIT= 0, +typedef enum { + HID_INIT = 0, HID_IDLE, HID_SEND_DATA, HID_BUSY, @@ -113,8 +112,7 @@ typedef enum } HID_StateTypeDef; -typedef enum -{ +typedef enum { HID_REQ_INIT = 0, HID_REQ_IDLE, HID_REQ_GET_REPORT_DESC, @@ -126,8 +124,7 @@ typedef enum } HID_CtlStateTypeDef; -typedef enum -{ +typedef enum { HID_MOUSE = 0x01, HID_KEYBOARD = 0x02, HID_UNKNOWN = 0xFF, @@ -135,54 +132,51 @@ typedef enum HID_TypeTypeDef; -typedef struct _HID_ReportData -{ - uint8_t ReportID; - uint8_t ReportType; - uint16_t UsagePage; - uint32_t Usage[HID_MAX_USAGE]; - uint32_t NbrUsage; - uint32_t UsageMin; - uint32_t UsageMax; - int32_t LogMin; - int32_t LogMax; - int32_t PhyMin; - int32_t PhyMax; - int32_t UnitExp; - uint32_t Unit; - uint32_t ReportSize; - uint32_t ReportCnt; - uint32_t Flag; - uint32_t PhyUsage; - uint32_t AppUsage; - uint32_t LogUsage; +typedef struct _HID_ReportData { + uint8_t ReportID; + uint8_t ReportType; + uint16_t UsagePage; + uint32_t Usage[HID_MAX_USAGE]; + uint32_t NbrUsage; + uint32_t UsageMin; + uint32_t UsageMax; + int32_t LogMin; + int32_t LogMax; + int32_t PhyMin; + int32_t PhyMax; + int32_t UnitExp; + uint32_t Unit; + uint32_t ReportSize; + uint32_t ReportCnt; + uint32_t Flag; + uint32_t PhyUsage; + uint32_t AppUsage; + uint32_t LogUsage; } HID_ReportDataTypeDef; typedef struct _HID_ReportIDTypeDef { - uint8_t Size; /* Report size return by the device id */ - uint8_t ReportID; /* Report Id */ - uint8_t Type; /* Report Type (INPUT/OUTPUT/FEATURE) */ + uint8_t Size; /* Report size return by the device id */ + uint8_t ReportID; /* Report Id */ + uint8_t Type; /* Report Type (INPUT/OUTPUT/FEATURE) */ } HID_ReportIDTypeDef; -typedef struct _HID_CollectionTypeDef -{ - uint32_t Usage; - uint8_t Type; - struct _HID_CollectionTypeDef *NextPtr; +typedef struct _HID_CollectionTypeDef { + uint32_t Usage; + uint8_t Type; + struct _HID_CollectionTypeDef *NextPtr; } HID_CollectionTypeDef; typedef struct _HID_AppCollectionTypeDef { - uint32_t Usage; - uint8_t Type; - uint8_t NbrReportFmt; - HID_ReportDataTypeDef ReportData[HID_MAX_NBR_REPORT_FMT]; + uint32_t Usage; + uint8_t Type; + uint8_t NbrReportFmt; + HID_ReportDataTypeDef ReportData[HID_MAX_NBR_REPORT_FMT]; } HID_AppCollectionTypeDef; -typedef struct _HIDDescriptor -{ +typedef struct _HIDDescriptor { uint8_t bLength; uint8_t bDescriptorType; uint16_t bcdHID; /* indicates what endpoint this descriptor is describing */ @@ -194,19 +188,17 @@ typedef struct _HIDDescriptor HID_DescTypeDef; -typedef struct -{ - uint8_t *buf; - uint16_t head; - uint16_t tail; - uint16_t size; - uint8_t lock; +typedef struct { + uint8_t *buf; + uint16_t head; + uint16_t tail; + uint16_t size; + uint8_t lock; } FIFO_TypeDef; /* Structure for HID process */ -typedef struct _HID_Process -{ +typedef struct _HID_Process { uint8_t OutPipe; uint8_t InPipe; HID_StateTypeDef state; @@ -221,7 +213,7 @@ typedef struct _HID_Process uint32_t timer; uint8_t DataReady; HID_DescTypeDef HID_Desc; - USBH_StatusTypeDef ( * Init)(USBH_HandleTypeDef *phost); + USBH_StatusTypeDef(* Init)(USBH_HandleTypeDef *phost); } HID_HandleTypeDef; @@ -276,30 +268,30 @@ extern USBH_ClassTypeDef HID_Class; * @{ */ -USBH_StatusTypeDef USBH_HID_SetReport (USBH_HandleTypeDef *phost, - uint8_t reportType, - uint8_t reportId, - uint8_t* reportBuff, - uint8_t reportLen); +USBH_StatusTypeDef USBH_HID_SetReport(USBH_HandleTypeDef *phost, + uint8_t reportType, + uint8_t reportId, + uint8_t *reportBuff, + uint8_t reportLen); -USBH_StatusTypeDef USBH_HID_GetReport (USBH_HandleTypeDef *phost, - uint8_t reportType, - uint8_t reportId, - uint8_t* reportBuff, - uint8_t reportLen); +USBH_StatusTypeDef USBH_HID_GetReport(USBH_HandleTypeDef *phost, + uint8_t reportType, + uint8_t reportId, + uint8_t *reportBuff, + uint8_t reportLen); -USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor (USBH_HandleTypeDef *phost, - uint16_t length); +USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor(USBH_HandleTypeDef *phost, + uint16_t length); -USBH_StatusTypeDef USBH_HID_GetHIDDescriptor (USBH_HandleTypeDef *phost, - uint16_t length); +USBH_StatusTypeDef USBH_HID_GetHIDDescriptor(USBH_HandleTypeDef *phost, + uint16_t length); -USBH_StatusTypeDef USBH_HID_SetIdle (USBH_HandleTypeDef *phost, - uint8_t duration, - uint8_t reportId); +USBH_StatusTypeDef USBH_HID_SetIdle(USBH_HandleTypeDef *phost, + uint8_t duration, + uint8_t reportId); -USBH_StatusTypeDef USBH_HID_SetProtocol (USBH_HandleTypeDef *phost, - uint8_t protocol); +USBH_StatusTypeDef USBH_HID_SetProtocol(USBH_HandleTypeDef *phost, + uint8_t protocol); void USBH_HID_EventCallback(USBH_HandleTypeDef *phost); diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_keybd.h b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_keybd.h index 7252aa252e..77b702e047 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_keybd.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_keybd.h @@ -22,7 +22,7 @@ #define __USBH_HID_KEYBD_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -270,8 +270,7 @@ #define KEY_RIGHTALT 0xE6 #define KEY_RIGHT_GUI 0xE7 -typedef struct -{ +typedef struct { uint8_t state; uint8_t lctrl; uint8_t lshift; diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_mouse.h b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_mouse.h index 400aed1a39..b95259538e 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_mouse.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_mouse.h @@ -22,7 +22,7 @@ #define __USBH_HID_MOUSE_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -50,8 +50,7 @@ * @{ */ -typedef struct _HID_MOUSE_Info -{ +typedef struct _HID_MOUSE_Info { uint8_t x; uint8_t y; uint8_t buttons[3]; diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_parser.h b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_parser.h index 71da7454a1..d1e12dab88 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_parser.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_parser.h @@ -22,7 +22,7 @@ #define __USBH_HID_PARSER_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -50,8 +50,7 @@ /** @defgroup USBH_HID_PARSER_Exported_Types * @{ */ -typedef struct -{ +typedef struct { uint8_t *data; uint32_t size; uint8_t shift; @@ -66,7 +65,7 @@ typedef struct HID_Report_ItemTypedef; -uint32_t HID_ReadItem (HID_Report_ItemTypedef *ri, uint8_t ndx); +uint32_t HID_ReadItem(HID_Report_ItemTypedef *ri, uint8_t ndx); uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx); diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_usage.h b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_usage.h index 4c70f3ea14..56f0dd7d09 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_usage.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid_usage.h @@ -22,7 +22,7 @@ #define __USDH_HID_USAGE_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /** @addtogroup USBH_LIB diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c index 501d5bdcf4..64059a92f8 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c @@ -31,12 +31,12 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" - - "stm32xxxxx_{eval}{discovery}_sdram.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" +- "stm32xxxxx_{eval}{discovery}_sdram.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbh_hid.h" @@ -97,18 +97,17 @@ * @{ */ -static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_HID_InterfaceDeInit (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_HID_InterfaceInit(USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_HID_InterfaceDeInit(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef USBH_HID_SOFProcess(USBH_HandleTypeDef *phost); -static void USBH_HID_ParseHIDDesc (HID_DescTypeDef *desc, uint8_t *buf); +static void USBH_HID_ParseHIDDesc(HID_DescTypeDef *desc, uint8_t *buf); extern USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost); extern USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost); -USBH_ClassTypeDef HID_Class = -{ +USBH_ClassTypeDef HID_Class = { "HID", USB_HID_CLASS, USBH_HID_InterfaceInit, @@ -134,7 +133,7 @@ USBH_ClassTypeDef HID_Class = * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_HID_InterfaceInit(USBH_HandleTypeDef *phost) { uint8_t max_ep; uint8_t num = 0U; @@ -145,32 +144,24 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost) interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, 0xFFU); - if(interface == 0xFFU) /* No Valid Interface */ - { + if (interface == 0xFFU) { /* No Valid Interface */ status = USBH_FAIL; - USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name); - } - else - { - USBH_SelectInterface (phost, interface); - phost->pActiveClass->pData = (HID_HandleTypeDef *)USBH_malloc (sizeof(HID_HandleTypeDef)); - HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; + USBH_DbgLog("Cannot Find the interface for %s class.", phost->pActiveClass->Name); + } else { + USBH_SelectInterface(phost, interface); + phost->pActiveClass->pData = (HID_HandleTypeDef *)USBH_malloc(sizeof(HID_HandleTypeDef)); + HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; HID_Handle->state = HID_ERROR; /*Decode Bootclass Protocol: Mouse or Keyboard*/ - if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_KEYBRD_BOOT_CODE) - { - USBH_UsrLog ("KeyBoard device found!"); + if (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_KEYBRD_BOOT_CODE) { + USBH_UsrLog("KeyBoard device found!"); HID_Handle->Init = USBH_HID_KeybdInit; - } - else if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_MOUSE_BOOT_CODE) - { - USBH_UsrLog ("Mouse device found!"); + } else if (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_MOUSE_BOOT_CODE) { + USBH_UsrLog("Mouse device found!"); HID_Handle->Init = USBH_HID_MouseInit; - } - else - { - USBH_UsrLog ("Protocol not supported."); + } else { + USBH_UsrLog("Protocol not supported."); return USBH_FAIL; } @@ -180,56 +171,51 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost) HID_Handle->length = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize; HID_Handle->poll = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bInterval ; - if (HID_Handle->poll < HID_MIN_POLL) - { + if (HID_Handle->poll < HID_MIN_POLL) { HID_Handle->poll = HID_MIN_POLL; } /* Check fo available number of endpoints */ /* Find the number of EPs in the Interface Descriptor */ /* Choose the lower number in order not to overrun the buffer allocated */ - max_ep = ( (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bNumEndpoints <= USBH_MAX_NUM_ENDPOINTS) ? + max_ep = ((phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bNumEndpoints <= USBH_MAX_NUM_ENDPOINTS) ? phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bNumEndpoints : - USBH_MAX_NUM_ENDPOINTS); + USBH_MAX_NUM_ENDPOINTS); /* Decode endpoint IN and OUT address from interface descriptor */ - for ( ;num < max_ep; num++) - { - if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress & 0x80U) - { + for (; num < max_ep; num++) { + if (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress & 0x80U) { HID_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress); - HID_Handle->InPipe =\ - USBH_AllocPipe(phost, HID_Handle->InEp); + HID_Handle->InPipe = \ + USBH_AllocPipe(phost, HID_Handle->InEp); /* Open pipe for IN endpoint */ - USBH_OpenPipe (phost, - HID_Handle->InPipe, - HID_Handle->InEp, - phost->device.address, - phost->device.speed, - USB_EP_TYPE_INTR, - HID_Handle->length); + USBH_OpenPipe(phost, + HID_Handle->InPipe, + HID_Handle->InEp, + phost->device.address, + phost->device.speed, + USB_EP_TYPE_INTR, + HID_Handle->length); - USBH_LL_SetToggle (phost, HID_Handle->InPipe, 0U); + USBH_LL_SetToggle(phost, HID_Handle->InPipe, 0U); - } - else - { + } else { HID_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress); - HID_Handle->OutPipe =\ - USBH_AllocPipe(phost, HID_Handle->OutEp); + HID_Handle->OutPipe = \ + USBH_AllocPipe(phost, HID_Handle->OutEp); /* Open pipe for OUT endpoint */ - USBH_OpenPipe (phost, - HID_Handle->OutPipe, - HID_Handle->OutEp, - phost->device.address, - phost->device.speed, - USB_EP_TYPE_INTR, - HID_Handle->length); - - USBH_LL_SetToggle (phost, HID_Handle->OutPipe, 0U); + USBH_OpenPipe(phost, + HID_Handle->OutPipe, + HID_Handle->OutEp, + phost->device.address, + phost->device.speed, + USB_EP_TYPE_INTR, + HID_Handle->length); + + USBH_LL_SetToggle(phost, HID_Handle->OutPipe, 0U); } } @@ -244,27 +230,24 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef static USBH_HID_InterfaceDeInit (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef static USBH_HID_InterfaceDeInit(USBH_HandleTypeDef *phost) { - HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; + HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; - if(HID_Handle->InPipe != 0x00U) - { - USBH_ClosePipe (phost, HID_Handle->InPipe); - USBH_FreePipe (phost, HID_Handle->InPipe); + if (HID_Handle->InPipe != 0x00U) { + USBH_ClosePipe(phost, HID_Handle->InPipe); + USBH_FreePipe(phost, HID_Handle->InPipe); HID_Handle->InPipe = 0U; /* Reset the pipe as Free */ } - if(HID_Handle->OutPipe != 0x00U) - { + if (HID_Handle->OutPipe != 0x00U) { USBH_ClosePipe(phost, HID_Handle->OutPipe); - USBH_FreePipe (phost, HID_Handle->OutPipe); + USBH_FreePipe(phost, HID_Handle->OutPipe); HID_Handle->OutPipe = 0U; /* Reset the pipe as Free */ } - if(phost->pActiveClass->pData) - { - USBH_free (phost->pActiveClass->pData); + if (phost->pActiveClass->pData) { + USBH_free(phost->pActiveClass->pData); } return USBH_OK; @@ -282,69 +265,61 @@ static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost) USBH_StatusTypeDef status = USBH_BUSY; USBH_StatusTypeDef classReqStatus = USBH_BUSY; - HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; + HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; /* Switch HID state machine */ - switch (HID_Handle->ctl_state) - { - case HID_REQ_INIT: - case HID_REQ_GET_HID_DESC: + switch (HID_Handle->ctl_state) { + case HID_REQ_INIT: + case HID_REQ_GET_HID_DESC: - /* Get HID Desc */ - if (USBH_HID_GetHIDDescriptor (phost, USB_HID_DESC_SIZE)== USBH_OK) - { + /* Get HID Desc */ + if (USBH_HID_GetHIDDescriptor(phost, USB_HID_DESC_SIZE) == USBH_OK) { - USBH_HID_ParseHIDDesc(&HID_Handle->HID_Desc, phost->device.Data); - HID_Handle->ctl_state = HID_REQ_GET_REPORT_DESC; - } + USBH_HID_ParseHIDDesc(&HID_Handle->HID_Desc, phost->device.Data); + HID_Handle->ctl_state = HID_REQ_GET_REPORT_DESC; + } - break; - case HID_REQ_GET_REPORT_DESC: + break; + case HID_REQ_GET_REPORT_DESC: - /* Get Report Desc */ - if (USBH_HID_GetHIDReportDescriptor(phost, HID_Handle->HID_Desc.wItemLength) == USBH_OK) - { - /* The descriptor is available in phost->device.Data */ + /* Get Report Desc */ + if (USBH_HID_GetHIDReportDescriptor(phost, HID_Handle->HID_Desc.wItemLength) == USBH_OK) { + /* The descriptor is available in phost->device.Data */ - HID_Handle->ctl_state = HID_REQ_SET_IDLE; - } + HID_Handle->ctl_state = HID_REQ_SET_IDLE; + } - break; + break; - case HID_REQ_SET_IDLE: + case HID_REQ_SET_IDLE: - classReqStatus = USBH_HID_SetIdle (phost, 0U, 0U); + classReqStatus = USBH_HID_SetIdle(phost, 0U, 0U); - /* set Idle */ - if (classReqStatus == USBH_OK) - { - HID_Handle->ctl_state = HID_REQ_SET_PROTOCOL; - } - else - { - if(classReqStatus == USBH_NOT_SUPPORTED) - { + /* set Idle */ + if (classReqStatus == USBH_OK) { HID_Handle->ctl_state = HID_REQ_SET_PROTOCOL; + } else { + if (classReqStatus == USBH_NOT_SUPPORTED) { + HID_Handle->ctl_state = HID_REQ_SET_PROTOCOL; + } } - } - break; + break; - case HID_REQ_SET_PROTOCOL: - /* set protocol */ - if (USBH_HID_SetProtocol (phost, 0U) == USBH_OK) - { - HID_Handle->ctl_state = HID_REQ_IDLE; + case HID_REQ_SET_PROTOCOL: + /* set protocol */ + if (USBH_HID_SetProtocol(phost, 0U) == USBH_OK) { + HID_Handle->ctl_state = HID_REQ_IDLE; - /* all requests performed*/ - phost->pUser(phost, HOST_USER_CLASS_ACTIVE); - status = USBH_OK; - } - break; + /* all requests performed*/ + phost->pUser(phost, HOST_USER_CLASS_ACTIVE); + status = USBH_OK; + } + break; - case HID_REQ_IDLE: - default: - break; + case HID_REQ_IDLE: + default: + break; } return status; @@ -361,118 +336,103 @@ static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost) USBH_StatusTypeDef status = USBH_OK; HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; - switch (HID_Handle->state) - { - case HID_INIT: - HID_Handle->Init(phost); - HID_Handle->state = HID_IDLE; + switch (HID_Handle->state) { + case HID_INIT: + HID_Handle->Init(phost); + HID_Handle->state = HID_IDLE; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; - - case HID_IDLE: - status = USBH_HID_GetReport (phost, 0x01U, 0U, HID_Handle->pData, (uint8_t)HID_Handle->length); - if (status == USBH_OK) - { - USBH_HID_FifoWrite(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length); - HID_Handle->state = HID_SYNC; - } - else if (status == USBH_BUSY) - { - HID_Handle->state = HID_IDLE; - status = USBH_OK; - } - else if (status == USBH_NOT_SUPPORTED) - { - HID_Handle->state = HID_SYNC; - status = USBH_OK; - } - else - { - HID_Handle->state = HID_ERROR; - status = USBH_FAIL; - } + break; + + case HID_IDLE: + status = USBH_HID_GetReport(phost, 0x01U, 0U, HID_Handle->pData, (uint8_t)HID_Handle->length); + if (status == USBH_OK) { + USBH_HID_FifoWrite(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length); + HID_Handle->state = HID_SYNC; + } else if (status == USBH_BUSY) { + HID_Handle->state = HID_IDLE; + status = USBH_OK; + } else if (status == USBH_NOT_SUPPORTED) { + HID_Handle->state = HID_SYNC; + status = USBH_OK; + } else { + HID_Handle->state = HID_ERROR; + status = USBH_FAIL; + } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case HID_SYNC: - /* Sync with start of Even Frame */ - if(phost->Timer & 1U) - { - HID_Handle->state = HID_GET_DATA; - } + case HID_SYNC: + /* Sync with start of Even Frame */ + if (phost->Timer & 1U) { + HID_Handle->state = HID_GET_DATA; + } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; - - case HID_GET_DATA: - USBH_InterruptReceiveData(phost, HID_Handle->pData, - (uint8_t)HID_Handle->length, - HID_Handle->InPipe); - - HID_Handle->state = HID_POLL; - HID_Handle->timer = phost->Timer; - HID_Handle->DataReady = 0U; - break; - - case HID_POLL: - if(USBH_LL_GetURBState(phost , HID_Handle->InPipe) == USBH_URB_DONE) - { - if(HID_Handle->DataReady == 0U) - { - USBH_HID_FifoWrite(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length); - HID_Handle->DataReady = 1U; - USBH_HID_EventCallback(phost); + break; + + case HID_GET_DATA: + USBH_InterruptReceiveData(phost, HID_Handle->pData, + (uint8_t)HID_Handle->length, + HID_Handle->InPipe); + + HID_Handle->state = HID_POLL; + HID_Handle->timer = phost->Timer; + HID_Handle->DataReady = 0U; + break; + + case HID_POLL: + if (USBH_LL_GetURBState(phost, HID_Handle->InPipe) == USBH_URB_DONE) { + if (HID_Handle->DataReady == 0U) { + USBH_HID_FifoWrite(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length); + HID_Handle->DataReady = 1U; + USBH_HID_EventCallback(phost); #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - } - else - { - /* IN Endpoint Stalled */ - if(USBH_LL_GetURBState(phost, HID_Handle->InPipe) == USBH_URB_STALL) - { - /* Issue Clear Feature on interrupt IN endpoint */ - if(USBH_ClrFeature(phost, HID_Handle->ep_addr) == USBH_OK) - { - /* Change state to issue next IN token */ - HID_Handle->state = HID_GET_DATA; + } + } else { + /* IN Endpoint Stalled */ + if (USBH_LL_GetURBState(phost, HID_Handle->InPipe) == USBH_URB_STALL) { + /* Issue Clear Feature on interrupt IN endpoint */ + if (USBH_ClrFeature(phost, HID_Handle->ep_addr) == USBH_OK) { + /* Change state to issue next IN token */ + HID_Handle->state = HID_GET_DATA; + } } } - } - break; + break; - default: - break; + default: + break; } return status; @@ -486,12 +446,10 @@ static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost) */ static USBH_StatusTypeDef USBH_HID_SOFProcess(USBH_HandleTypeDef *phost) { - HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; + HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; - if(HID_Handle->state == HID_POLL) - { - if(( phost->Timer - HID_Handle->timer) >= HID_Handle->poll) - { + if (HID_Handle->state == HID_POLL) { + if ((phost->Timer - HID_Handle->timer) >= HID_Handle->poll) { HID_Handle->state = HID_GET_DATA; #if (USBH_USE_OS == 1U) @@ -515,8 +473,8 @@ static USBH_StatusTypeDef USBH_HID_SOFProcess(USBH_HandleTypeDef *phost) * @param Length : HID Report Descriptor Length * @retval USBH Status */ -USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor (USBH_HandleTypeDef *phost, - uint16_t length) +USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor(USBH_HandleTypeDef *phost, + uint16_t length) { USBH_StatusTypeDef status; @@ -545,8 +503,8 @@ USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor (USBH_HandleTypeDef *phost, * @param Length : HID Descriptor Length * @retval USBH Status */ -USBH_StatusTypeDef USBH_HID_GetHIDDescriptor (USBH_HandleTypeDef *phost, - uint16_t length) +USBH_StatusTypeDef USBH_HID_GetHIDDescriptor(USBH_HandleTypeDef *phost, + uint16_t length) { USBH_StatusTypeDef status; @@ -567,13 +525,13 @@ USBH_StatusTypeDef USBH_HID_GetHIDDescriptor (USBH_HandleTypeDef *phost, * @param reportId : Targeted report ID for Set Idle request * @retval USBH Status */ -USBH_StatusTypeDef USBH_HID_SetIdle (USBH_HandleTypeDef *phost, - uint8_t duration, - uint8_t reportId) +USBH_StatusTypeDef USBH_HID_SetIdle(USBH_HandleTypeDef *phost, + uint8_t duration, + uint8_t reportId) { - phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\ - USB_REQ_TYPE_CLASS; + phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE | \ + USB_REQ_TYPE_CLASS; phost->Control.setup.b.bRequest = USB_HID_SET_IDLE; @@ -596,15 +554,15 @@ USBH_StatusTypeDef USBH_HID_SetIdle (USBH_HandleTypeDef *phost, * @param reportLen : Length of data report to be send * @retval USBH Status */ -USBH_StatusTypeDef USBH_HID_SetReport (USBH_HandleTypeDef *phost, - uint8_t reportType, - uint8_t reportId, - uint8_t* reportBuff, - uint8_t reportLen) +USBH_StatusTypeDef USBH_HID_SetReport(USBH_HandleTypeDef *phost, + uint8_t reportType, + uint8_t reportId, + uint8_t *reportBuff, + uint8_t reportLen) { - phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE |\ - USB_REQ_TYPE_CLASS; + phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE | \ + USB_REQ_TYPE_CLASS; phost->Control.setup.b.bRequest = USB_HID_SET_REPORT; @@ -627,15 +585,15 @@ USBH_StatusTypeDef USBH_HID_SetReport (USBH_HandleTypeDef *phost, * @param reportLen : Length of data report to be send * @retval USBH Status */ -USBH_StatusTypeDef USBH_HID_GetReport (USBH_HandleTypeDef *phost, - uint8_t reportType, - uint8_t reportId, - uint8_t* reportBuff, - uint8_t reportLen) +USBH_StatusTypeDef USBH_HID_GetReport(USBH_HandleTypeDef *phost, + uint8_t reportType, + uint8_t reportId, + uint8_t *reportBuff, + uint8_t reportLen) { - phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE |\ - USB_REQ_TYPE_CLASS; + phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \ + USB_REQ_TYPE_CLASS; phost->Control.setup.b.bRequest = USB_HID_GET_REPORT; @@ -658,15 +616,12 @@ USBH_StatusTypeDef USBH_HID_SetProtocol(USBH_HandleTypeDef *phost, uint8_t protocol) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE - | USB_REQ_TYPE_CLASS; + | USB_REQ_TYPE_CLASS; phost->Control.setup.b.bRequest = USB_HID_SET_PROTOCOL; - if(protocol) - { + if (protocol) { phost->Control.setup.b.wValue.w = 0U; - } - else - { + } else { phost->Control.setup.b.wValue.w = 1U; } @@ -684,16 +639,16 @@ USBH_StatusTypeDef USBH_HID_SetProtocol(USBH_HandleTypeDef *phost, * @param buf: Buffer where the source descriptor is available * @retval None */ -static void USBH_HID_ParseHIDDesc (HID_DescTypeDef *desc, uint8_t *buf) +static void USBH_HID_ParseHIDDesc(HID_DescTypeDef *desc, uint8_t *buf) { - desc->bLength = *(uint8_t *) (buf + 0); - desc->bDescriptorType = *(uint8_t *) (buf + 1); - desc->bcdHID = LE16 (buf + 2); - desc->bCountryCode = *(uint8_t *) (buf + 4); - desc->bNumDescriptors = *(uint8_t *) (buf + 5); - desc->bReportDescriptorType = *(uint8_t *) (buf + 6); - desc->wItemLength = LE16 (buf + 7); + desc->bLength = *(uint8_t *)(buf + 0); + desc->bDescriptorType = *(uint8_t *)(buf + 1); + desc->bcdHID = LE16(buf + 2); + desc->bCountryCode = *(uint8_t *)(buf + 4); + desc->bNumDescriptors = *(uint8_t *)(buf + 5); + desc->bReportDescriptorType = *(uint8_t *)(buf + 6); + desc->wItemLength = LE16(buf + 7); } /** @@ -707,17 +662,12 @@ HID_TypeTypeDef USBH_HID_GetDeviceType(USBH_HandleTypeDef *phost) HID_TypeTypeDef type = HID_UNKNOWN; uint8_t InterfaceProtocol; - if(phost->gState == HOST_CLASS) - { + if (phost->gState == HOST_CLASS) { InterfaceProtocol = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol; - if(InterfaceProtocol == HID_KEYBRD_BOOT_CODE) - { + if (InterfaceProtocol == HID_KEYBRD_BOOT_CODE) { type = HID_KEYBOARD; - } - else - { - if(InterfaceProtocol == HID_MOUSE_BOOT_CODE) - { + } else { + if (InterfaceProtocol == HID_MOUSE_BOOT_CODE) { type = HID_MOUSE; } } @@ -734,18 +684,15 @@ HID_TypeTypeDef USBH_HID_GetDeviceType(USBH_HandleTypeDef *phost) */ uint8_t USBH_HID_GetPollInterval(USBH_HandleTypeDef *phost) { - HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; - - if((phost->gState == HOST_CLASS_REQUEST) || - (phost->gState == HOST_INPUT) || - (phost->gState == HOST_SET_CONFIGURATION) || - (phost->gState == HOST_CHECK_CLASS) || - ((phost->gState == HOST_CLASS))) - { + HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; + + if ((phost->gState == HOST_CLASS_REQUEST) || + (phost->gState == HOST_INPUT) || + (phost->gState == HOST_SET_CONFIGURATION) || + (phost->gState == HOST_CHECK_CLASS) || + ((phost->gState == HOST_CLASS))) { return (uint8_t)(HID_Handle->poll); - } - else - { + } else { return 0U; } } @@ -757,13 +704,13 @@ uint8_t USBH_HID_GetPollInterval(USBH_HandleTypeDef *phost) * @param size: Fifo Size * @retval none */ -void USBH_HID_FifoInit(FIFO_TypeDef * f, uint8_t * buf, uint16_t size) +void USBH_HID_FifoInit(FIFO_TypeDef *f, uint8_t *buf, uint16_t size) { - f->head = 0U; - f->tail = 0U; - f->lock = 0U; - f->size = size; - f->buf = buf; + f->head = 0U; + f->tail = 0U; + f->lock = 0U; + f->size = size; + f->buf = buf; } /** @@ -777,24 +724,19 @@ void USBH_HID_FifoInit(FIFO_TypeDef * f, uint8_t * buf, uint16_t size) uint16_t USBH_HID_FifoRead(FIFO_TypeDef *f, void *buf, uint16_t nbytes) { uint16_t i; - uint8_t * p; - p = (uint8_t*) buf; + uint8_t *p; + p = (uint8_t *) buf; - if(f->lock == 0U) - { + if (f->lock == 0U) { f->lock = 1U; - for(i = 0U; i < nbytes; i++) - { - if( f->tail != f->head) - { + for (i = 0U; i < nbytes; i++) { + if (f->tail != f->head) { *p++ = f->buf[f->tail]; f->tail++; - if( f->tail == f->size) - { + if (f->tail == f->size) { f->tail = 0U; } - } else - { + } else { f->lock = 0U; return i; } @@ -817,24 +759,18 @@ uint16_t USBH_HID_FifoWrite(FIFO_TypeDef *f, void *buf, uint16_t nbytes) { uint16_t i; uint8_t *p; - p = (uint8_t*) buf; - if(f->lock == 0U) - { + p = (uint8_t *) buf; + if (f->lock == 0U) { f->lock = 1U; - for(i = 0U; i < nbytes; i++) - { - if( (f->head + 1U == f->tail) || - ( (f->head + 1U == f->size) && (f->tail == 0U))) - { + for (i = 0U; i < nbytes; i++) { + if ((f->head + 1U == f->tail) || + ((f->head + 1U == f->size) && (f->tail == 0U))) { f->lock = 0U; return i; - } - else - { + } else { f->buf[f->head] = *p++; f->head++; - if( f->head == f->size) - { + if (f->head == f->size) { f->head = 0U; } } diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_keybd.c b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_keybd.c index 338fbfcab2..ad2432a27f 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_keybd.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_keybd.c @@ -19,12 +19,12 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" - - "stm32xxxxx_{eval}{discovery}_sdram.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" +- "stm32xxxxx_{eval}{discovery}_sdram.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbh_hid_keybd.h" @@ -62,7 +62,7 @@ * @} */ #ifndef AZERTY_KEYBOARD - #define QWERTY_KEYBOARD +#define QWERTY_KEYBOARD #endif #define KBD_LEFT_CTRL 0x01 #define KBD_LEFT_SHIFT 0x02 @@ -96,8 +96,8 @@ static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost); HID_KEYBD_Info_TypeDef keybd_info; uint32_t keybd_report_data[2]; -static const HID_Report_ItemTypedef imp_0_lctrl={ - (uint8_t*)(void *)keybd_report_data+0, /*data*/ +static const HID_Report_ItemTypedef imp_0_lctrl = { + (uint8_t *)(void *)keybd_report_data + 0, /*data*/ 1, /*size*/ 0, /*shift*/ 0, /*count (only for array items)*/ @@ -108,8 +108,8 @@ static const HID_Report_ItemTypedef imp_0_lctrl={ 1, /*max value device can report*/ 1 /*resolution*/ }; -static const HID_Report_ItemTypedef imp_0_lshift={ - (uint8_t*)(void *)keybd_report_data+0, /*data*/ +static const HID_Report_ItemTypedef imp_0_lshift = { + (uint8_t *)(void *)keybd_report_data + 0, /*data*/ 1, /*size*/ 1, /*shift*/ 0, /*count (only for array items)*/ @@ -120,8 +120,8 @@ static const HID_Report_ItemTypedef imp_0_lshift={ 1, /*max value device can report*/ 1 /*resolution*/ }; -static const HID_Report_ItemTypedef imp_0_lalt={ - (uint8_t*)(void *)keybd_report_data+0, /*data*/ +static const HID_Report_ItemTypedef imp_0_lalt = { + (uint8_t *)(void *)keybd_report_data + 0, /*data*/ 1, /*size*/ 2, /*shift*/ 0, /*count (only for array items)*/ @@ -132,8 +132,8 @@ static const HID_Report_ItemTypedef imp_0_lalt={ 1, /*max value device can report*/ 1 /*resolution*/ }; -static const HID_Report_ItemTypedef imp_0_lgui={ - (uint8_t*)(void *)keybd_report_data+0, /*data*/ +static const HID_Report_ItemTypedef imp_0_lgui = { + (uint8_t *)(void *)keybd_report_data + 0, /*data*/ 1, /*size*/ 3, /*shift*/ 0, /*count (only for array items)*/ @@ -144,8 +144,8 @@ static const HID_Report_ItemTypedef imp_0_lgui={ 1, /*max value device can report*/ 1 /*resolution*/ }; -static const HID_Report_ItemTypedef imp_0_rctrl={ - (uint8_t*)(void *)keybd_report_data+0, /*data*/ +static const HID_Report_ItemTypedef imp_0_rctrl = { + (uint8_t *)(void *)keybd_report_data + 0, /*data*/ 1, /*size*/ 4, /*shift*/ 0, /*count (only for array items)*/ @@ -156,8 +156,8 @@ static const HID_Report_ItemTypedef imp_0_rctrl={ 1, /*max value device can report*/ 1 /*resolution*/ }; -static const HID_Report_ItemTypedef imp_0_rshift={ - (uint8_t*)(void *)keybd_report_data+0, /*data*/ +static const HID_Report_ItemTypedef imp_0_rshift = { + (uint8_t *)(void *)keybd_report_data + 0, /*data*/ 1, /*size*/ 5, /*shift*/ 0, /*count (only for array items)*/ @@ -168,8 +168,8 @@ static const HID_Report_ItemTypedef imp_0_rshift={ 1, /*max value device can report*/ 1 /*resolution*/ }; -static const HID_Report_ItemTypedef imp_0_ralt={ - (uint8_t*)(void *)keybd_report_data+0, /*data*/ +static const HID_Report_ItemTypedef imp_0_ralt = { + (uint8_t *)(void *)keybd_report_data + 0, /*data*/ 1, /*size*/ 6, /*shift*/ 0, /*count (only for array items)*/ @@ -180,8 +180,8 @@ static const HID_Report_ItemTypedef imp_0_ralt={ 1, /*max value device can report*/ 1 /*resolution*/ }; -static const HID_Report_ItemTypedef imp_0_rgui={ - (uint8_t*)(void *)keybd_report_data+0, /*data*/ +static const HID_Report_ItemTypedef imp_0_rgui = { + (uint8_t *)(void *)keybd_report_data + 0, /*data*/ 1, /*size*/ 7, /*shift*/ 0, /*count (only for array items)*/ @@ -194,7 +194,7 @@ static const HID_Report_ItemTypedef imp_0_rgui={ }; static const HID_Report_ItemTypedef imp_0_key_array = { - (uint8_t*)(void *)keybd_report_data + 2, /*data*/ + (uint8_t *)(void *)keybd_report_data + 2, /*data*/ 8, /*size*/ 0, /*shift*/ 6, /*count (only for array items)*/ @@ -252,9 +252,9 @@ static const uint8_t HID_KEYBRD_Key[] = { 'c', 'v', 'b', 'n', ',', ';', ':', '!', '\0', '\0', '\0', '\0', '\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\r', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '7', '4', '1','\0', '/', + '\0', '\0', '\0', '\0', '\0', '\0', '\0', '7', '4', '1', '\0', '/', '8', '5', '2', '0', '*', '9', '6', '3', '.', '-', '+', '\0', - '\n', '\0', '\0', '\0', '\0', '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0', + '\n', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' }; @@ -263,7 +263,7 @@ static const uint8_t HID_KEYBRD_ShiftKey[] = { '+', '\0', '\0', '\0', 'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '*', '\0', 'Q', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', '%', '\0', '\n', '\0', '\0', 'W', 'X', 'C', 'V', 'B', 'N', - '?', '.', '/', '\0', '\0', '\0','\0', '\0', '\0', '\0', '\0', '\0', '\0', + '?', '.', '/', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', @@ -313,24 +313,22 @@ static const uint8_t HID_KEYBRD_Codes[] = { USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost) { uint32_t x; - HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; + HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; - keybd_info.lctrl=keybd_info.lshift = 0U; - keybd_info.lalt=keybd_info.lgui = 0U; - keybd_info.rctrl=keybd_info.rshift = 0U; - keybd_info.ralt=keybd_info.rgui = 0U; + keybd_info.lctrl = keybd_info.lshift = 0U; + keybd_info.lalt = keybd_info.lgui = 0U; + keybd_info.rctrl = keybd_info.rshift = 0U; + keybd_info.ralt = keybd_info.rgui = 0U; - for(x = 0U; x < (sizeof(keybd_report_data)/sizeof(uint32_t)); x++) - { + for (x = 0U; x < (sizeof(keybd_report_data) / sizeof(uint32_t)); x++) { keybd_report_data[x] = 0U; } - if(HID_Handle->length > (sizeof(keybd_report_data)/sizeof(uint32_t))) - { - HID_Handle->length = (sizeof(keybd_report_data)/sizeof(uint32_t)); + if (HID_Handle->length > (sizeof(keybd_report_data) / sizeof(uint32_t))) { + HID_Handle->length = (sizeof(keybd_report_data) / sizeof(uint32_t)); } - HID_Handle->pData = (uint8_t*)(void *)keybd_report_data; + HID_Handle->pData = (uint8_t *)(void *)keybd_report_data; USBH_HID_FifoInit(&HID_Handle->fifo, phost->device.Data, HID_QUEUE_SIZE * sizeof(keybd_report_data)); return USBH_OK; @@ -344,14 +342,11 @@ USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost) */ HID_KEYBD_Info_TypeDef *USBH_HID_GetKeybdInfo(USBH_HandleTypeDef *phost) { - if(USBH_HID_KeybdDecode(phost) == USBH_OK) - { - return &keybd_info; - } - else - { - return NULL; - } + if (USBH_HID_KeybdDecode(phost) == USBH_OK) { + return &keybd_info; + } else { + return NULL; + } } /** @@ -364,27 +359,24 @@ static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost) { uint8_t x; - HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; - if(HID_Handle->length == 0U) - { + HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; + if (HID_Handle->length == 0U) { return USBH_FAIL; } /*Fill report */ - if(USBH_HID_FifoRead(&HID_Handle->fifo, &keybd_report_data, HID_Handle->length) == HID_Handle->length) - { - - keybd_info.lctrl=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lctrl, 0U); - keybd_info.lshift=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lshift, 0U); - keybd_info.lalt=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lalt, 0U); - keybd_info.lgui=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lgui, 0U); - keybd_info.rctrl=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rctrl, 0U); - keybd_info.rshift=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rshift, 0U); - keybd_info.ralt=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_ralt, 0U); - keybd_info.rgui=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rgui, 0U); - - for(x = 0U; x < sizeof(keybd_info.keys); x++) - { - keybd_info.keys[x]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_key_array, x); + if (USBH_HID_FifoRead(&HID_Handle->fifo, &keybd_report_data, HID_Handle->length) == HID_Handle->length) { + + keybd_info.lctrl = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lctrl, 0U); + keybd_info.lshift = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lshift, 0U); + keybd_info.lalt = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lalt, 0U); + keybd_info.lgui = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lgui, 0U); + keybd_info.rctrl = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rctrl, 0U); + keybd_info.rshift = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rshift, 0U); + keybd_info.ralt = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_ralt, 0U); + keybd_info.rgui = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rgui, 0U); + + for (x = 0U; x < sizeof(keybd_info.keys); x++) { + keybd_info.keys[x] = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_key_array, x); } return USBH_OK; @@ -402,13 +394,10 @@ static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost) uint8_t USBH_HID_GetASCIICode(HID_KEYBD_Info_TypeDef *info) { uint8_t output; - if((info->lshift == 1U) || (info->rshift)) - { - output = HID_KEYBRD_ShiftKey[HID_KEYBRD_Codes[info->keys[0]]]; - } - else - { - output = HID_KEYBRD_Key[HID_KEYBRD_Codes[info->keys[0]]]; + if ((info->lshift == 1U) || (info->rshift)) { + output = HID_KEYBRD_ShiftKey[HID_KEYBRD_Codes[info->keys[0]]]; + } else { + output = HID_KEYBRD_Key[HID_KEYBRD_Codes[info->keys[0]]]; } return output; } diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_mouse.c b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_mouse.c index 45984f7af2..d3ba7a4929 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_mouse.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_mouse.c @@ -17,12 +17,12 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" - - "stm32xxxxx_{eval}{discovery}_sdram.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" +- "stm32xxxxx_{eval}{discovery}_sdram.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbh_hid_mouse.h" @@ -87,8 +87,8 @@ uint32_t mouse_report_data[1]; /* Structures defining how to access items in a HID mouse report */ /* Access button 1 state. */ -static const HID_Report_ItemTypedef prop_b1={ - (uint8_t *)(void *)mouse_report_data+0, /*data*/ +static const HID_Report_ItemTypedef prop_b1 = { + (uint8_t *)(void *)mouse_report_data + 0, /*data*/ 1, /*size*/ 0, /*shift*/ 0, /*count (only for array items)*/ @@ -101,8 +101,8 @@ static const HID_Report_ItemTypedef prop_b1={ }; /* Access button 2 state. */ -static const HID_Report_ItemTypedef prop_b2={ - (uint8_t *)(void *)mouse_report_data+0, /*data*/ +static const HID_Report_ItemTypedef prop_b2 = { + (uint8_t *)(void *)mouse_report_data + 0, /*data*/ 1, /*size*/ 1, /*shift*/ 0, /*count (only for array items)*/ @@ -115,8 +115,8 @@ static const HID_Report_ItemTypedef prop_b2={ }; /* Access button 3 state. */ -static const HID_Report_ItemTypedef prop_b3={ - (uint8_t *)(void *)mouse_report_data+0, /*data*/ +static const HID_Report_ItemTypedef prop_b3 = { + (uint8_t *)(void *)mouse_report_data + 0, /*data*/ 1, /*size*/ 2, /*shift*/ 0, /*count (only for array items)*/ @@ -129,8 +129,8 @@ static const HID_Report_ItemTypedef prop_b3={ }; /* Access x coordinate change. */ -static const HID_Report_ItemTypedef prop_x={ - (uint8_t *)(void *)mouse_report_data+1, /*data*/ +static const HID_Report_ItemTypedef prop_x = { + (uint8_t *)(void *)mouse_report_data + 1, /*data*/ 8, /*size*/ 0, /*shift*/ 0, /*count (only for array items)*/ @@ -143,8 +143,8 @@ static const HID_Report_ItemTypedef prop_x={ }; /* Access y coordinate change. */ -static const HID_Report_ItemTypedef prop_y={ - (uint8_t *)(void *)mouse_report_data+2, /*data*/ +static const HID_Report_ItemTypedef prop_y = { + (uint8_t *)(void *)mouse_report_data + 2, /*data*/ 8, /*size*/ 0, /*shift*/ 0, /*count (only for array items)*/ @@ -174,7 +174,7 @@ static const HID_Report_ItemTypedef prop_y={ */ USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost) { - HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; + HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; mouse_info.x = 0U; mouse_info.y = 0U; @@ -184,8 +184,7 @@ USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost) mouse_report_data[0] = 0U; - if(HID_Handle->length > sizeof(mouse_report_data)) - { + if (HID_Handle->length > sizeof(mouse_report_data)) { HID_Handle->length = sizeof(mouse_report_data); } HID_Handle->pData = (uint8_t *)(void *)mouse_report_data; @@ -202,14 +201,11 @@ USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost) */ HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost) { - if(USBH_HID_MouseDecode(phost)== USBH_OK) - { - return &mouse_info; - } - else - { - return NULL; - } + if (USBH_HID_MouseDecode(phost) == USBH_OK) { + return &mouse_info; + } else { + return NULL; + } } /** @@ -222,20 +218,18 @@ static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost) { HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; - if(HID_Handle->length == 0U) - { + if (HID_Handle->length == 0U) { return USBH_FAIL; } /*Fill report */ - if(USBH_HID_FifoRead(&HID_Handle->fifo, &mouse_report_data, HID_Handle->length) == HID_Handle->length) - { + if (USBH_HID_FifoRead(&HID_Handle->fifo, &mouse_report_data, HID_Handle->length) == HID_Handle->length) { /*Decode report */ mouse_info.x = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_x, 0U); mouse_info.y = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_y, 0U); - mouse_info.buttons[0]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b1, 0U); - mouse_info.buttons[1]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b2, 0U); - mouse_info.buttons[2]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b3, 0U); + mouse_info.buttons[0] = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b1, 0U); + mouse_info.buttons[1] = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b2, 0U); + mouse_info.buttons[2] = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b3, 0U); return USBH_OK; } diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_parser.c b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_parser.c index 373002efe7..66cca6e95b 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_parser.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_parser.c @@ -17,12 +17,12 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" - - "stm32xxxxx_{eval}{discovery}_sdram.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" +- "stm32xxxxx_{eval}{discovery}_sdram.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbh_hid_parser.h" @@ -102,59 +102,50 @@ uint32_t HID_ReadItem(HID_Report_ItemTypedef *ri, uint8_t ndx) uint32_t val = 0U; uint32_t x = 0U; uint32_t bofs; - uint8_t *data=ri->data; - uint8_t shift=ri->shift; + uint8_t *data = ri->data; + uint8_t shift = ri->shift; /* get the logical value of the item */ /* if this is an array, wee may need to offset ri->data.*/ - if (ri->count > 0U) - { + if (ri->count > 0U) { /* If app tries to read outside of the array. */ - if (ri->count <= ndx) - { - return(0U); + if (ri->count <= ndx) { + return (0U); } /* calculate bit offset */ - bofs = ndx*ri->size; + bofs = ndx * ri->size; bofs += shift; /* calculate byte offset + shift pair from bit offset. */ - data+=bofs / 8U; - shift=(uint8_t)(bofs % 8U); + data += bofs / 8U; + shift = (uint8_t)(bofs % 8U); } /* read data bytes in little endian order */ - for(x = 0U; x < ((ri->size & 0x7U) ? (ri->size / 8U) + 1U : (ri->size / 8U)); x++) - { - val=(uint32_t)((uint32_t)(*data) << (x * 8U)); + for (x = 0U; x < ((ri->size & 0x7U) ? (ri->size / 8U) + 1U : (ri->size / 8U)); x++) { + val = (uint32_t)((uint32_t)(*data) << (x * 8U)); } - val=(val >> shift) & ((1U << ri->size) - 1U); + val = (val >> shift) & ((1U << ri->size) - 1U); - if (val < ri->logical_min || val > ri->logical_max) - { - return(0U); + if (val < ri->logical_min || val > ri->logical_max) { + return (0U); } /* convert logical value to physical value */ /* See if the number is negative or not. */ - if ((ri->sign) && (val & (1U << (ri->size - 1U)))) - { + if ((ri->sign) && (val & (1U << (ri->size - 1U)))) { /* yes, so sign extend value to 32 bits. */ - uint32_t vs=(uint32_t)((0xffffffffU & ~((1U << (ri->size)) - 1U)) | val); + uint32_t vs = (uint32_t)((0xffffffffU & ~((1U << (ri->size)) - 1U)) | val); - if(ri->resolution == 1U) - { - return((uint32_t)vs); + if (ri->resolution == 1U) { + return ((uint32_t)vs); } - return((uint32_t)(vs * ri->resolution)); - } - else - { - if(ri->resolution == 1U) - { - return(val); + return ((uint32_t)(vs * ri->resolution)); + } else { + if (ri->resolution == 1U) { + return (val); } - return(val*ri->resolution); + return (val * ri->resolution); } } @@ -170,21 +161,18 @@ uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx) uint32_t x; uint32_t mask; uint32_t bofs; - uint8_t *data=ri->data; - uint8_t shift=ri->shift; + uint8_t *data = ri->data; + uint8_t shift = ri->shift; - if (value < ri->physical_min || value > ri->physical_max) - { - return(1U); + if (value < ri->physical_min || value > ri->physical_max) { + return (1U); } - /* if this is an array, wee may need to offset ri->data.*/ - if (ri->count > 0U) - { + /* if this is an array, wee may need to offset ri->data.*/ + if (ri->count > 0U) { /* If app tries to read outside of the array. */ - if (ri->count >= ndx) - { - return(0U); + if (ri->count >= ndx) { + return (0U); } /* calculate bit offset */ bofs = ndx * ri->size; @@ -196,8 +184,7 @@ uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx) } /* Convert physical value to logical value. */ - if (ri->resolution != 1U) - { + if (ri->resolution != 1U) { value = value / ri->resolution; } @@ -205,10 +192,9 @@ uint32_t HID_WriteItem(HID_Report_ItemTypedef *ri, uint32_t value, uint8_t ndx) mask = (1U << ri->size) - 1U; value = (value & mask) << shift; - for(x = 0U; x < ((ri->size & 0x7U) ? (ri->size / 8U) + 1U : (ri->size / 8U)); x++) - { - *(ri->data + x)=(uint8_t)((*(ri->data+x) & ~(mask>>(x* 8U))) | - ((value >> (x * 8U)) & (mask >> (x * 8U)))); + for (x = 0U; x < ((ri->size & 0x7U) ? (ri->size / 8U) + 1U : (ri->size / 8U)); x++) { + *(ri->data + x) = (uint8_t)((*(ri->data + x) & ~(mask >> (x * 8U))) | + ((value >> (x * 8U)) & (mask >> (x * 8U)))); } return 0U; diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc.h b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc.h index 23fd51b9ab..bb7cc6be04 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc.h @@ -22,7 +22,7 @@ #define __USBH_MSC_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -52,8 +52,7 @@ * @{ */ -typedef enum -{ +typedef enum { MSC_INIT = 0, MSC_IDLE, MSC_TEST_UNIT_READY, @@ -67,8 +66,7 @@ typedef enum } MSC_StateTypeDef; -typedef enum -{ +typedef enum { MSC_OK, MSC_NOT_READY, MSC_ERROR, @@ -76,8 +74,7 @@ typedef enum } MSC_ErrorTypeDef; -typedef enum -{ +typedef enum { MSC_REQ_IDLE = 0, MSC_REQ_RESET, MSC_REQ_GET_MAX_LUN, @@ -86,13 +83,12 @@ typedef enum MSC_ReqStateTypeDef; #ifndef MAX_SUPPORTED_LUN - #define MAX_SUPPORTED_LUN 2U +#define MAX_SUPPORTED_LUN 2U #endif /* Structure for LUN */ -typedef struct -{ +typedef struct { MSC_StateTypeDef state; MSC_ErrorTypeDef error; USBH_StatusTypeDef prev_ready_state; @@ -105,8 +101,7 @@ typedef struct MSC_LUNTypeDef; /* Structure for MSC process */ -typedef struct _MSC_Process -{ +typedef struct _MSC_Process { uint32_t max_lun; uint8_t InPipe; uint8_t OutPipe; @@ -173,26 +168,26 @@ extern USBH_ClassTypeDef USBH_msc; */ /* Common APIs */ -uint8_t USBH_MSC_IsReady (USBH_HandleTypeDef *phost); +uint8_t USBH_MSC_IsReady(USBH_HandleTypeDef *phost); /* APIs for LUN */ -uint8_t USBH_MSC_GetMaxLUN (USBH_HandleTypeDef *phost); +uint8_t USBH_MSC_GetMaxLUN(USBH_HandleTypeDef *phost); -uint8_t USBH_MSC_UnitIsReady (USBH_HandleTypeDef *phost, uint8_t lun); +uint8_t USBH_MSC_UnitIsReady(USBH_HandleTypeDef *phost, uint8_t lun); USBH_StatusTypeDef USBH_MSC_GetLUNInfo(USBH_HandleTypeDef *phost, uint8_t lun, MSC_LUNTypeDef *info); USBH_StatusTypeDef USBH_MSC_Read(USBH_HandleTypeDef *phost, - uint8_t lun, - uint32_t address, - uint8_t *pbuf, - uint32_t length); + uint8_t lun, + uint32_t address, + uint8_t *pbuf, + uint32_t length); USBH_StatusTypeDef USBH_MSC_Write(USBH_HandleTypeDef *phost, - uint8_t lun, - uint32_t address, - uint8_t *pbuf, - uint32_t length); + uint8_t lun, + uint32_t address, + uint8_t *pbuf, + uint32_t length); /** * @} */ diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc_bot.h b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc_bot.h index f9bb3a4db1..924f3dc521 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc_bot.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc_bot.h @@ -22,7 +22,7 @@ #define __USBH_MSC_BOT_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -66,12 +66,11 @@ typedef enum { BOT_CMDStateTypeDef; /* CSW Status Definitions */ -typedef enum -{ +typedef enum { - BOT_CSW_CMD_PASSED = 0x00, - BOT_CSW_CMD_FAILED = 0x01, - BOT_CSW_PHASE_ERROR = 0x02, + BOT_CSW_CMD_PASSED = 0x00, + BOT_CSW_CMD_FAILED = 0x01, + BOT_CSW_PHASE_ERROR = 0x02, } BOT_CSWStatusTypeDef; @@ -90,10 +89,8 @@ typedef enum { } BOT_StateTypeDef; -typedef union -{ - struct __CBW - { +typedef union { + struct __CBW { uint32_t Signature; uint32_t Tag; uint32_t DataTransferLength; @@ -101,26 +98,23 @@ typedef union uint8_t LUN; uint8_t CBLength; uint8_t CB[16]; - }field; + } field; uint8_t data[31]; } BOT_CBWTypeDef; -typedef union -{ - struct __CSW - { +typedef union { + struct __CSW { uint32_t Signature; uint32_t Tag; uint32_t DataResidue; uint8_t Status; - }field; + } field; uint8_t data[13]; } BOT_CSWTypeDef; -typedef struct -{ +typedef struct { uint32_t data[16]; BOT_StateTypeDef state; BOT_StateTypeDef prev_state; @@ -194,7 +188,7 @@ USBH_StatusTypeDef USBH_MSC_BOT_REQ_Reset(USBH_HandleTypeDef *phost); USBH_StatusTypeDef USBH_MSC_BOT_REQ_GetMaxLUN(USBH_HandleTypeDef *phost, uint8_t *Maxlun); USBH_StatusTypeDef USBH_MSC_BOT_Init(USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_MSC_BOT_Process (USBH_HandleTypeDef *phost, uint8_t lun); +USBH_StatusTypeDef USBH_MSC_BOT_Process(USBH_HandleTypeDef *phost, uint8_t lun); USBH_StatusTypeDef USBH_MSC_BOT_Error(USBH_HandleTypeDef *phost, uint8_t lun); diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc_scsi.h b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc_scsi.h index f5c28d01b0..4a9c1a7365 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc_scsi.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc_scsi.h @@ -22,7 +22,7 @@ #define __USBH_MSC_SCSI_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -48,31 +48,28 @@ /* Capacity data */ -typedef struct -{ +typedef struct { uint32_t block_nbr; uint16_t block_size; } SCSI_CapacityTypeDef; /* Sense data */ -typedef struct -{ +typedef struct { uint8_t key; uint8_t asc; uint8_t ascq; } SCSI_SenseTypeDef; /* INQUIRY data */ -typedef struct -{ +typedef struct { uint8_t PeripheralQualifier; uint8_t DeviceType; uint8_t RemovableMedia; uint8_t vendor_id[9]; uint8_t product_id[17]; uint8_t revision_id[5]; -}SCSI_StdInquiryDataTypeDef; +} SCSI_StdInquiryDataTypeDef; /** @defgroup USBH_MSC_SCSI_Exported_Defines * @{ @@ -159,32 +156,32 @@ typedef struct /** @defgroup USBH_MSC_SCSI_Exported_FunctionsPrototype * @{ */ -USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady (USBH_HandleTypeDef *phost, - uint8_t lun); +USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady(USBH_HandleTypeDef *phost, + uint8_t lun); -USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity (USBH_HandleTypeDef *phost, - uint8_t lun, - SCSI_CapacityTypeDef *capacity); +USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity(USBH_HandleTypeDef *phost, + uint8_t lun, + SCSI_CapacityTypeDef *capacity); -USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry (USBH_HandleTypeDef *phost, - uint8_t lun, - SCSI_StdInquiryDataTypeDef *inquiry); +USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry(USBH_HandleTypeDef *phost, + uint8_t lun, + SCSI_StdInquiryDataTypeDef *inquiry); -USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense (USBH_HandleTypeDef *phost, - uint8_t lun, - SCSI_SenseTypeDef *sense_data); +USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense(USBH_HandleTypeDef *phost, + uint8_t lun, + SCSI_SenseTypeDef *sense_data); USBH_StatusTypeDef USBH_MSC_SCSI_Write(USBH_HandleTypeDef *phost, - uint8_t lun, - uint32_t address, - uint8_t *pbuf, - uint32_t length); + uint8_t lun, + uint32_t address, + uint8_t *pbuf, + uint32_t length); USBH_StatusTypeDef USBH_MSC_SCSI_Read(USBH_HandleTypeDef *phost, - uint8_t lun, - uint32_t address, - uint8_t *pbuf, - uint32_t length); + uint8_t lun, + uint32_t address, + uint8_t *pbuf, + uint32_t length); /** diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c index 1d4409d82a..266420d3ee 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c @@ -29,12 +29,12 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" - - "stm32xxxxx_{eval}{discovery}_sdram.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" +- "stm32xxxxx_{eval}{discovery}_sdram.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ @@ -95,9 +95,9 @@ * @{ */ -static USBH_StatusTypeDef USBH_MSC_InterfaceInit (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_MSC_InterfaceInit(USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_MSC_InterfaceDeInit (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_MSC_InterfaceDeInit(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost); @@ -107,8 +107,7 @@ static USBH_StatusTypeDef USBH_MSC_SOFProcess(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef USBH_MSC_RdWrProcess(USBH_HandleTypeDef *phost, uint8_t lun); -USBH_ClassTypeDef USBH_msc = -{ +USBH_ClassTypeDef USBH_msc = { "MSC", USB_MSC_CLASS, USBH_MSC_InterfaceInit, @@ -145,7 +144,7 @@ USBH_ClassTypeDef USBH_msc = * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_MSC_InterfaceInit (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_MSC_InterfaceInit(USBH_HandleTypeDef *phost) { uint8_t interface = 0U; USBH_StatusTypeDef status = USBH_FAIL; @@ -153,36 +152,27 @@ static USBH_StatusTypeDef USBH_MSC_InterfaceInit (USBH_HandleTypeDef *phost) interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, MSC_TRANSPARENT, MSC_BOT); - if(interface == 0xFFU) /* Not Valid Interface */ - { - USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name); + if (interface == 0xFFU) { /* Not Valid Interface */ + USBH_DbgLog("Cannot Find the interface for %s class.", phost->pActiveClass->Name); status = USBH_FAIL; - } - else - { - USBH_SelectInterface (phost, interface); + } else { + USBH_SelectInterface(phost, interface); - phost->pActiveClass->pData = (MSC_HandleTypeDef *)USBH_malloc (sizeof(MSC_HandleTypeDef)); - MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + phost->pActiveClass->pData = (MSC_HandleTypeDef *)USBH_malloc(sizeof(MSC_HandleTypeDef)); + MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; - if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress & 0x80U) - { + if (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress & 0x80U) { MSC_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress); MSC_Handle->InEpSize = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize; - } - else - { + } else { MSC_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress); MSC_Handle->OutEpSize = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize; } - if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress & 0x80U) - { + if (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress & 0x80U) { MSC_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress); MSC_Handle->InEpSize = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].wMaxPacketSize; - } - else - { + } else { MSC_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress); MSC_Handle->OutEpSize = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].wMaxPacketSize; } @@ -201,24 +191,24 @@ static USBH_StatusTypeDef USBH_MSC_InterfaceInit (USBH_HandleTypeDef *phost) USBH_memset(MSC_Handle->unit, 0, sizeof(MSC_Handle->unit)); /* Open the new channels */ - USBH_OpenPipe (phost, - MSC_Handle->OutPipe, - MSC_Handle->OutEp, - phost->device.address, - phost->device.speed, - USB_EP_TYPE_BULK, - MSC_Handle->OutEpSize); - - USBH_OpenPipe (phost, - MSC_Handle->InPipe, - MSC_Handle->InEp, - phost->device.address, - phost->device.speed, - USB_EP_TYPE_BULK, - MSC_Handle->InEpSize); - - USBH_LL_SetToggle (phost, MSC_Handle->InPipe, 0U); - USBH_LL_SetToggle (phost, MSC_Handle->OutPipe, 0U); + USBH_OpenPipe(phost, + MSC_Handle->OutPipe, + MSC_Handle->OutEp, + phost->device.address, + phost->device.speed, + USB_EP_TYPE_BULK, + MSC_Handle->OutEpSize); + + USBH_OpenPipe(phost, + MSC_Handle->InPipe, + MSC_Handle->InEp, + phost->device.address, + phost->device.speed, + USB_EP_TYPE_BULK, + MSC_Handle->InEpSize); + + USBH_LL_SetToggle(phost, MSC_Handle->InPipe, 0U); + USBH_LL_SetToggle(phost, MSC_Handle->OutPipe, 0U); status = USBH_OK; } return status; @@ -230,27 +220,24 @@ static USBH_StatusTypeDef USBH_MSC_InterfaceInit (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_MSC_InterfaceDeInit (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_MSC_InterfaceDeInit(USBH_HandleTypeDef *phost) { - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; - if ( MSC_Handle->OutPipe) - { + if (MSC_Handle->OutPipe) { USBH_ClosePipe(phost, MSC_Handle->OutPipe); - USBH_FreePipe (phost, MSC_Handle->OutPipe); + USBH_FreePipe(phost, MSC_Handle->OutPipe); MSC_Handle->OutPipe = 0U; /* Reset the Channel as Free */ } - if ( MSC_Handle->InPipe) - { + if (MSC_Handle->InPipe) { USBH_ClosePipe(phost, MSC_Handle->InPipe); - USBH_FreePipe (phost, MSC_Handle->InPipe); + USBH_FreePipe(phost, MSC_Handle->InPipe); MSC_Handle->InPipe = 0U; /* Reset the Channel as Free */ } - if(phost->pActiveClass->pData) - { - USBH_free (phost->pActiveClass->pData); + if (phost->pActiveClass->pData) { + USBH_free(phost->pActiveClass->pData); phost->pActiveClass->pData = 0; } @@ -266,49 +253,44 @@ static USBH_StatusTypeDef USBH_MSC_InterfaceDeInit (USBH_HandleTypeDef *phost) */ static USBH_StatusTypeDef USBH_MSC_ClassRequest(USBH_HandleTypeDef *phost) { - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; USBH_StatusTypeDef status = USBH_BUSY; uint8_t i; /* Switch MSC REQ state machine */ - switch (MSC_Handle->req_state) - { - case MSC_REQ_IDLE: - case MSC_REQ_GET_MAX_LUN: - /* Issue GetMaxLUN request */ - status = USBH_MSC_BOT_REQ_GetMaxLUN(phost, (uint8_t *)(void *)&MSC_Handle->max_lun); - - /* When devices do not support the GetMaxLun request, this should - be considred as only one logical unit is supported */ - if(status == USBH_NOT_SUPPORTED) - { - MSC_Handle->max_lun = 0U; - status = USBH_OK; - } + switch (MSC_Handle->req_state) { + case MSC_REQ_IDLE: + case MSC_REQ_GET_MAX_LUN: + /* Issue GetMaxLUN request */ + status = USBH_MSC_BOT_REQ_GetMaxLUN(phost, (uint8_t *)(void *)&MSC_Handle->max_lun); + + /* When devices do not support the GetMaxLun request, this should + be considred as only one logical unit is supported */ + if (status == USBH_NOT_SUPPORTED) { + MSC_Handle->max_lun = 0U; + status = USBH_OK; + } - if(status == USBH_OK) - { - MSC_Handle->max_lun = (MSC_Handle->max_lun > MAX_SUPPORTED_LUN)? MAX_SUPPORTED_LUN : (uint8_t )(MSC_Handle->max_lun) + 1U; - USBH_UsrLog ("Number of supported LUN: %lu", (int32_t)(MSC_Handle->max_lun)); + if (status == USBH_OK) { + MSC_Handle->max_lun = (MSC_Handle->max_lun > MAX_SUPPORTED_LUN) ? MAX_SUPPORTED_LUN : (uint8_t)(MSC_Handle->max_lun) + 1U; + USBH_UsrLog("Number of supported LUN: %lu", (int32_t)(MSC_Handle->max_lun)); - for(i = 0U; i < MSC_Handle->max_lun; i++) - { - MSC_Handle->unit[i].prev_ready_state = USBH_FAIL; - MSC_Handle->unit[i].state_changed = 0U; + for (i = 0U; i < MSC_Handle->max_lun; i++) { + MSC_Handle->unit[i].prev_ready_state = USBH_FAIL; + MSC_Handle->unit[i].state_changed = 0U; + } } - } - break; + break; - case MSC_REQ_ERROR : - /* a Clear Feature should be issued here */ - if(USBH_ClrFeature(phost, 0x00U) == USBH_OK) - { - MSC_Handle->req_state = MSC_Handle->prev_req_state; - } - break; + case MSC_REQ_ERROR : + /* a Clear Feature should be issued here */ + if (USBH_ClrFeature(phost, 0x00U) == USBH_OK) { + MSC_Handle->req_state = MSC_Handle->prev_req_state; + } + break; - default: - break; + default: + break; } return status; @@ -322,203 +304,168 @@ static USBH_StatusTypeDef USBH_MSC_ClassRequest(USBH_HandleTypeDef *phost) */ static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost) { - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; USBH_StatusTypeDef error = USBH_BUSY ; USBH_StatusTypeDef scsi_status = USBH_BUSY ; USBH_StatusTypeDef ready_status = USBH_BUSY ; - switch (MSC_Handle->state) - { - case MSC_INIT: - - if(MSC_Handle->current_lun < MSC_Handle->max_lun) - { - - MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_NOT_READY; - /* Switch MSC REQ state machine */ - switch (MSC_Handle->unit[MSC_Handle->current_lun].state) - { - case MSC_INIT: - USBH_UsrLog ("LUN #%d: ", MSC_Handle->current_lun); - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_READ_INQUIRY; - MSC_Handle->timer = phost->Timer; - break; - - case MSC_READ_INQUIRY: - scsi_status = USBH_MSC_SCSI_Inquiry(phost, (uint8_t)MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].inquiry); - - if (scsi_status == USBH_OK) - { - USBH_UsrLog ("Inquiry Vendor : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.vendor_id); - USBH_UsrLog ("Inquiry Product : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.product_id); - USBH_UsrLog ("Inquiry Version : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.revision_id); - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_TEST_UNIT_READY; - } - if (scsi_status == USBH_FAIL) - { - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE; - } - else - { - if(scsi_status == USBH_UNRECOVERED_ERROR) - { - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE; - MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR; - } - } - break; - - case MSC_TEST_UNIT_READY: - ready_status = USBH_MSC_SCSI_TestUnitReady(phost, (uint8_t)MSC_Handle->current_lun); - - if (ready_status == USBH_OK) - { - if(MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state != USBH_OK) - { - MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 1U; - USBH_UsrLog ("MSC Device ready"); - } - else - { - MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0U; - } - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_READ_CAPACITY10; - MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_OK; - MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state = USBH_OK; - } - if (ready_status == USBH_FAIL) - { - /* Media not ready, so try to check again during 10s */ - if( MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state != USBH_FAIL) - { - MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 1U; - USBH_UsrLog ("MSC Device NOT ready"); - } - else - { - MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0U; - } - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE; - MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_NOT_READY; - MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state = USBH_FAIL; - } - else - { - if (ready_status == USBH_UNRECOVERED_ERROR) - { - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE; - MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR; - } - } - break; - - case MSC_READ_CAPACITY10: - scsi_status = USBH_MSC_SCSI_ReadCapacity(phost, (uint8_t)MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].capacity) ; - - if(scsi_status == USBH_OK) - { - if(MSC_Handle->unit[MSC_Handle->current_lun].state_changed == 1U) - { - USBH_UsrLog ("MSC Device capacity : %lu Bytes", \ - (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_nbr * MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_size)); - USBH_UsrLog ("Block number : %lu", (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_nbr)); - USBH_UsrLog ("Block Size : %lu", (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_size)); - } - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE; - MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_OK; - MSC_Handle->current_lun++; - } - else if(scsi_status == USBH_FAIL) - { - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE; - } - else - { - if(scsi_status == USBH_UNRECOVERED_ERROR) - { - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE; - MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR; - } - } - break; + switch (MSC_Handle->state) { + case MSC_INIT: + + if (MSC_Handle->current_lun < MSC_Handle->max_lun) { - case MSC_REQUEST_SENSE: - scsi_status = USBH_MSC_SCSI_RequestSense(phost, (uint8_t)MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].sense); + MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_NOT_READY; + /* Switch MSC REQ state machine */ + switch (MSC_Handle->unit[MSC_Handle->current_lun].state) { + case MSC_INIT: + USBH_UsrLog("LUN #%d: ", MSC_Handle->current_lun); + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_READ_INQUIRY; + MSC_Handle->timer = phost->Timer; + break; - if( scsi_status == USBH_OK) - { - if((MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_UNIT_ATTENTION) || - (MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_NOT_READY) ) - { + case MSC_READ_INQUIRY: + scsi_status = USBH_MSC_SCSI_Inquiry(phost, (uint8_t)MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].inquiry); - if((phost->Timer - MSC_Handle->timer) < 10000U) - { + if (scsi_status == USBH_OK) { + USBH_UsrLog("Inquiry Vendor : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.vendor_id); + USBH_UsrLog("Inquiry Product : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.product_id); + USBH_UsrLog("Inquiry Version : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.revision_id); MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_TEST_UNIT_READY; - break; } - } - - USBH_UsrLog ("Sense Key : %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.key); - USBH_UsrLog ("Additional Sense Code : %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.asc); - USBH_UsrLog ("Additional Sense Code Qualifier: %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.ascq); - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE; - MSC_Handle->current_lun++; - } - if(scsi_status == USBH_FAIL) - { - USBH_UsrLog ("MSC Device NOT ready"); - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_UNRECOVERED_ERROR; - } - else - { - if(scsi_status == USBH_UNRECOVERED_ERROR) - { - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE; - MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR; - } - } - break; + if (scsi_status == USBH_FAIL) { + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE; + } else { + if (scsi_status == USBH_UNRECOVERED_ERROR) { + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE; + MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR; + } + } + break; + + case MSC_TEST_UNIT_READY: + ready_status = USBH_MSC_SCSI_TestUnitReady(phost, (uint8_t)MSC_Handle->current_lun); + + if (ready_status == USBH_OK) { + if (MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state != USBH_OK) { + MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 1U; + USBH_UsrLog("MSC Device ready"); + } else { + MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0U; + } + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_READ_CAPACITY10; + MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_OK; + MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state = USBH_OK; + } + if (ready_status == USBH_FAIL) { + /* Media not ready, so try to check again during 10s */ + if (MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state != USBH_FAIL) { + MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 1U; + USBH_UsrLog("MSC Device NOT ready"); + } else { + MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0U; + } + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE; + MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_NOT_READY; + MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state = USBH_FAIL; + } else { + if (ready_status == USBH_UNRECOVERED_ERROR) { + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE; + MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR; + } + } + break; + + case MSC_READ_CAPACITY10: + scsi_status = USBH_MSC_SCSI_ReadCapacity(phost, (uint8_t)MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].capacity) ; + + if (scsi_status == USBH_OK) { + if (MSC_Handle->unit[MSC_Handle->current_lun].state_changed == 1U) { + USBH_UsrLog("MSC Device capacity : %lu Bytes", \ + (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_nbr * MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_size)); + USBH_UsrLog("Block number : %lu", (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_nbr)); + USBH_UsrLog("Block Size : %lu", (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_size)); + } + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE; + MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_OK; + MSC_Handle->current_lun++; + } else if (scsi_status == USBH_FAIL) { + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE; + } else { + if (scsi_status == USBH_UNRECOVERED_ERROR) { + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE; + MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR; + } + } + break; + + case MSC_REQUEST_SENSE: + scsi_status = USBH_MSC_SCSI_RequestSense(phost, (uint8_t)MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].sense); + + if (scsi_status == USBH_OK) { + if ((MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_UNIT_ATTENTION) || + (MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_NOT_READY)) { + + if ((phost->Timer - MSC_Handle->timer) < 10000U) { + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_TEST_UNIT_READY; + break; + } + } + + USBH_UsrLog("Sense Key : %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.key); + USBH_UsrLog("Additional Sense Code : %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.asc); + USBH_UsrLog("Additional Sense Code Qualifier: %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.ascq); + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE; + MSC_Handle->current_lun++; + } + if (scsi_status == USBH_FAIL) { + USBH_UsrLog("MSC Device NOT ready"); + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_UNRECOVERED_ERROR; + } else { + if (scsi_status == USBH_UNRECOVERED_ERROR) { + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE; + MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR; + } + } + break; - case MSC_UNRECOVERED_ERROR: - MSC_Handle->current_lun++; - break; + case MSC_UNRECOVERED_ERROR: + MSC_Handle->current_lun++; + break; - default: - break; - } + default: + break; + } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CLASS_EVENT; + phost->os_msg = (uint32_t)USBH_CLASS_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - MSC_Handle->current_lun = 0U; - MSC_Handle->state = MSC_IDLE; + } else { + MSC_Handle->current_lun = 0U; + MSC_Handle->state = MSC_IDLE; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CLASS_EVENT; + phost->os_msg = (uint32_t)USBH_CLASS_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - phost->pUser(phost, HOST_USER_CLASS_ACTIVE); - } - break; + phost->pUser(phost, HOST_USER_CLASS_ACTIVE); + } + break; - case MSC_IDLE: - error = USBH_OK; - break; + case MSC_IDLE: + error = USBH_OK; + break; - default: - break; + default: + break; } return error; } @@ -544,114 +491,96 @@ static USBH_StatusTypeDef USBH_MSC_SOFProcess(USBH_HandleTypeDef *phost) */ static USBH_StatusTypeDef USBH_MSC_RdWrProcess(USBH_HandleTypeDef *phost, uint8_t lun) { - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; USBH_StatusTypeDef error = USBH_BUSY ; USBH_StatusTypeDef scsi_status = USBH_BUSY ; /* Switch MSC REQ state machine */ - switch (MSC_Handle->unit[lun].state) - { + switch (MSC_Handle->unit[lun].state) { - case MSC_READ: - scsi_status = USBH_MSC_SCSI_Read(phost,lun, 0U, NULL, 0U); + case MSC_READ: + scsi_status = USBH_MSC_SCSI_Read(phost, lun, 0U, NULL, 0U); - if(scsi_status == USBH_OK) - { - MSC_Handle->unit[lun].state = MSC_IDLE; - error = USBH_OK; - } - else if( scsi_status == USBH_FAIL) - { - MSC_Handle->unit[lun].state = MSC_REQUEST_SENSE; - } - else - { - if(scsi_status == USBH_UNRECOVERED_ERROR) - { - MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR; - error = USBH_FAIL; + if (scsi_status == USBH_OK) { + MSC_Handle->unit[lun].state = MSC_IDLE; + error = USBH_OK; + } else if (scsi_status == USBH_FAIL) { + MSC_Handle->unit[lun].state = MSC_REQUEST_SENSE; + } else { + if (scsi_status == USBH_UNRECOVERED_ERROR) { + MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR; + error = USBH_FAIL; + } } - } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CLASS_EVENT; + phost->os_msg = (uint32_t)USBH_CLASS_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case MSC_WRITE: - scsi_status = USBH_MSC_SCSI_Write(phost,lun, 0U, NULL, 0U); + case MSC_WRITE: + scsi_status = USBH_MSC_SCSI_Write(phost, lun, 0U, NULL, 0U); - if(scsi_status == USBH_OK) - { + if (scsi_status == USBH_OK) { MSC_Handle->unit[lun].state = MSC_IDLE; error = USBH_OK; - } - else if( scsi_status == USBH_FAIL) - { - MSC_Handle->unit[lun].state = MSC_REQUEST_SENSE; - } - else - { - if(scsi_status == USBH_UNRECOVERED_ERROR) - { - MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR; - error = USBH_FAIL; + } else if (scsi_status == USBH_FAIL) { + MSC_Handle->unit[lun].state = MSC_REQUEST_SENSE; + } else { + if (scsi_status == USBH_UNRECOVERED_ERROR) { + MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR; + error = USBH_FAIL; + } } - } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CLASS_EVENT; + phost->os_msg = (uint32_t)USBH_CLASS_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case MSC_REQUEST_SENSE: - scsi_status = USBH_MSC_SCSI_RequestSense(phost, lun, &MSC_Handle->unit[lun].sense); + case MSC_REQUEST_SENSE: + scsi_status = USBH_MSC_SCSI_RequestSense(phost, lun, &MSC_Handle->unit[lun].sense); - if(scsi_status == USBH_OK) - { - USBH_UsrLog ("Sense Key : %x", MSC_Handle->unit[lun].sense.key); - USBH_UsrLog ("Additional Sense Code : %x", MSC_Handle->unit[lun].sense.asc); - USBH_UsrLog ("Additional Sense Code Qualifier: %x", MSC_Handle->unit[lun].sense.ascq); - MSC_Handle->unit[lun].state = MSC_IDLE; - MSC_Handle->unit[lun].error = MSC_ERROR; + if (scsi_status == USBH_OK) { + USBH_UsrLog("Sense Key : %x", MSC_Handle->unit[lun].sense.key); + USBH_UsrLog("Additional Sense Code : %x", MSC_Handle->unit[lun].sense.asc); + USBH_UsrLog("Additional Sense Code Qualifier: %x", MSC_Handle->unit[lun].sense.ascq); + MSC_Handle->unit[lun].state = MSC_IDLE; + MSC_Handle->unit[lun].error = MSC_ERROR; - error = USBH_FAIL; - } - if(scsi_status == USBH_FAIL) - { - USBH_UsrLog ("MSC Device NOT ready"); - } - else - { - if(scsi_status == USBH_UNRECOVERED_ERROR) - { - MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR; error = USBH_FAIL; } - } + if (scsi_status == USBH_FAIL) { + USBH_UsrLog("MSC Device NOT ready"); + } else { + if (scsi_status == USBH_UNRECOVERED_ERROR) { + MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR; + error = USBH_FAIL; + } + } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CLASS_EVENT; + phost->os_msg = (uint32_t)USBH_CLASS_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - default: - break; + default: + break; } return error; @@ -663,17 +592,14 @@ static USBH_StatusTypeDef USBH_MSC_RdWrProcess(USBH_HandleTypeDef *phost, uint8_ * @param phost: Host handle * @retval USBH Status */ -uint8_t USBH_MSC_IsReady (USBH_HandleTypeDef *phost) +uint8_t USBH_MSC_IsReady(USBH_HandleTypeDef *phost) { MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; uint8_t res; - if ((phost->gState == HOST_CLASS) && (MSC_Handle->state == MSC_IDLE)) - { + if ((phost->gState == HOST_CLASS) && (MSC_Handle->state == MSC_IDLE)) { res = 1U; - } - else - { + } else { res = 0U; } @@ -686,13 +612,12 @@ uint8_t USBH_MSC_IsReady (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval logical Unit Number supported */ -uint8_t USBH_MSC_GetMaxLUN (USBH_HandleTypeDef *phost) +uint8_t USBH_MSC_GetMaxLUN(USBH_HandleTypeDef *phost) { - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; - if ((phost->gState == HOST_CLASS) && (MSC_Handle->state == MSC_IDLE)) - { - return (uint8_t)MSC_Handle->max_lun; + if ((phost->gState == HOST_CLASS) && (MSC_Handle->state == MSC_IDLE)) { + return (uint8_t)MSC_Handle->max_lun; } return 0xFFU; @@ -705,17 +630,14 @@ uint8_t USBH_MSC_GetMaxLUN (USBH_HandleTypeDef *phost) * @param lun: logical Unit Number * @retval Lun status (0: not ready / 1: ready) */ -uint8_t USBH_MSC_UnitIsReady (USBH_HandleTypeDef *phost, uint8_t lun) +uint8_t USBH_MSC_UnitIsReady(USBH_HandleTypeDef *phost, uint8_t lun) { - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; uint8_t res; - if ((phost->gState == HOST_CLASS) && (MSC_Handle->unit[lun].error == MSC_OK)) - { + if ((phost->gState == HOST_CLASS) && (MSC_Handle->unit[lun].error == MSC_OK)) { res = 1U; - } - else - { + } else { res = 0U; } @@ -731,14 +653,11 @@ uint8_t USBH_MSC_UnitIsReady (USBH_HandleTypeDef *phost, uint8_t lun) */ USBH_StatusTypeDef USBH_MSC_GetLUNInfo(USBH_HandleTypeDef *phost, uint8_t lun, MSC_LUNTypeDef *info) { - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; - if(phost->gState == HOST_CLASS) - { - USBH_memcpy(info,&MSC_Handle->unit[lun], sizeof(MSC_LUNTypeDef)); + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + if (phost->gState == HOST_CLASS) { + USBH_memcpy(info, &MSC_Handle->unit[lun], sizeof(MSC_LUNTypeDef)); return USBH_OK; - } - else - { + } else { return USBH_FAIL; } } @@ -754,18 +673,17 @@ USBH_StatusTypeDef USBH_MSC_GetLUNInfo(USBH_HandleTypeDef *phost, uint8_t lun, M * @retval USBH Status */ USBH_StatusTypeDef USBH_MSC_Read(USBH_HandleTypeDef *phost, - uint8_t lun, - uint32_t address, - uint8_t *pbuf, - uint32_t length) + uint8_t lun, + uint32_t address, + uint8_t *pbuf, + uint32_t length) { uint32_t timeout; - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; if ((phost->device.is_connected == 0U) || (phost->gState != HOST_CLASS) || - (MSC_Handle->unit[lun].state != MSC_IDLE)) - { + (MSC_Handle->unit[lun].state != MSC_IDLE)) { return USBH_FAIL; } @@ -777,10 +695,8 @@ USBH_StatusTypeDef USBH_MSC_Read(USBH_HandleTypeDef *phost, timeout = phost->Timer; - while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY) - { - if(((phost->Timer - timeout) > (10000U * length)) || (phost->device.is_connected == 0U)) - { + while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY) { + if (((phost->Timer - timeout) > (10000U * length)) || (phost->device.is_connected == 0U)) { MSC_Handle->state = MSC_IDLE; return USBH_FAIL; } @@ -801,18 +717,17 @@ USBH_StatusTypeDef USBH_MSC_Read(USBH_HandleTypeDef *phost, * @retval USBH Status */ USBH_StatusTypeDef USBH_MSC_Write(USBH_HandleTypeDef *phost, - uint8_t lun, - uint32_t address, - uint8_t *pbuf, - uint32_t length) + uint8_t lun, + uint32_t address, + uint8_t *pbuf, + uint32_t length) { uint32_t timeout; - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; if ((phost->device.is_connected == 0U) || (phost->gState != HOST_CLASS) || - (MSC_Handle->unit[lun].state != MSC_IDLE)) - { + (MSC_Handle->unit[lun].state != MSC_IDLE)) { return USBH_FAIL; } @@ -823,10 +738,8 @@ USBH_StatusTypeDef USBH_MSC_Write(USBH_HandleTypeDef *phost, USBH_MSC_SCSI_Write(phost, lun, address, pbuf, length); timeout = phost->Timer; - while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY) - { - if(((phost->Timer - timeout) > (10000U * length)) || (phost->device.is_connected == 0U)) - { + while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY) { + if (((phost->Timer - timeout) > (10000U * length)) || (phost->device.is_connected == 0U)) { MSC_Handle->state = MSC_IDLE; return USBH_FAIL; } diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_bot.c b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_bot.c index 84f98334d7..8708bf5104 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_bot.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_bot.c @@ -17,12 +17,12 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" - - "stm32xxxxx_{eval}{discovery}_sdram.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" +- "stm32xxxxx_{eval}{discovery}_sdram.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbh_msc_bot.h" @@ -109,7 +109,7 @@ USBH_StatusTypeDef USBH_MSC_BOT_REQ_Reset(USBH_HandleTypeDef *phost) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_TYPE_CLASS - | USB_REQ_RECIPIENT_INTERFACE; + | USB_REQ_RECIPIENT_INTERFACE; phost->Control.setup.b.bRequest = USB_REQ_BOT_RESET; phost->Control.setup.b.wValue.w = 0U; @@ -129,7 +129,7 @@ USBH_StatusTypeDef USBH_MSC_BOT_REQ_Reset(USBH_HandleTypeDef *phost) USBH_StatusTypeDef USBH_MSC_BOT_REQ_GetMaxLUN(USBH_HandleTypeDef *phost, uint8_t *Maxlun) { phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_TYPE_CLASS - | USB_REQ_RECIPIENT_INTERFACE; + | USB_REQ_RECIPIENT_INTERFACE; phost->Control.setup.b.bRequest = USB_REQ_GET_MAX_LUN; phost->Control.setup.b.wValue.w = 0U; @@ -150,7 +150,7 @@ USBH_StatusTypeDef USBH_MSC_BOT_REQ_GetMaxLUN(USBH_HandleTypeDef *phost, uint8_t USBH_StatusTypeDef USBH_MSC_BOT_Init(USBH_HandleTypeDef *phost) { - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; MSC_Handle->hbot.cbw.field.Signature = BOT_CBW_SIGNATURE; MSC_Handle->hbot.cbw.field.Tag = BOT_CBW_TAG; @@ -169,355 +169,304 @@ USBH_StatusTypeDef USBH_MSC_BOT_Init(USBH_HandleTypeDef *phost) * @param lun: Logical Unit Number * @retval USBH Status */ -USBH_StatusTypeDef USBH_MSC_BOT_Process (USBH_HandleTypeDef *phost, uint8_t lun) +USBH_StatusTypeDef USBH_MSC_BOT_Process(USBH_HandleTypeDef *phost, uint8_t lun) { USBH_StatusTypeDef status = USBH_BUSY; USBH_StatusTypeDef error = USBH_BUSY; BOT_CSWStatusTypeDef CSW_Status = BOT_CSW_CMD_FAILED; USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE; - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; uint8_t toggle = 0U; - switch (MSC_Handle->hbot.state) - { - case BOT_SEND_CBW: - MSC_Handle->hbot.cbw.field.LUN = lun; - MSC_Handle->hbot.state = BOT_SEND_CBW_WAIT; - USBH_BulkSendData (phost, MSC_Handle->hbot.cbw.data, - BOT_CBW_LENGTH, MSC_Handle->OutPipe, 1U); - - break; - - case BOT_SEND_CBW_WAIT: - - URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->OutPipe); - - if(URB_Status == USBH_URB_DONE) - { - if ( MSC_Handle->hbot.cbw.field.DataTransferLength != 0U) - { - /* If there is Data Transfer Stage */ - if (((MSC_Handle->hbot.cbw.field.Flags) & USB_REQ_DIR_MASK) == USB_D2H) - { - /* Data Direction is IN */ - MSC_Handle->hbot.state = BOT_DATA_IN; - } - else - { - /* Data Direction is OUT */ - MSC_Handle->hbot.state = BOT_DATA_OUT; + switch (MSC_Handle->hbot.state) { + case BOT_SEND_CBW: + MSC_Handle->hbot.cbw.field.LUN = lun; + MSC_Handle->hbot.state = BOT_SEND_CBW_WAIT; + USBH_BulkSendData(phost, MSC_Handle->hbot.cbw.data, + BOT_CBW_LENGTH, MSC_Handle->OutPipe, 1U); + + break; + + case BOT_SEND_CBW_WAIT: + + URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->OutPipe); + + if (URB_Status == USBH_URB_DONE) { + if (MSC_Handle->hbot.cbw.field.DataTransferLength != 0U) { + /* If there is Data Transfer Stage */ + if (((MSC_Handle->hbot.cbw.field.Flags) & USB_REQ_DIR_MASK) == USB_D2H) { + /* Data Direction is IN */ + MSC_Handle->hbot.state = BOT_DATA_IN; + } else { + /* Data Direction is OUT */ + MSC_Handle->hbot.state = BOT_DATA_OUT; + } } - } - else - {/* If there is NO Data Transfer Stage */ - MSC_Handle->hbot.state = BOT_RECEIVE_CSW; - } + else { + /* If there is NO Data Transfer Stage */ + MSC_Handle->hbot.state = BOT_RECEIVE_CSW; + } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else if(URB_Status == USBH_URB_NOTREADY) - { - /* Re-send CBW */ - MSC_Handle->hbot.state = BOT_SEND_CBW; + } else if (URB_Status == USBH_URB_NOTREADY) { + /* Re-send CBW */ + MSC_Handle->hbot.state = BOT_SEND_CBW; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - if(URB_Status == USBH_URB_STALL) - { - MSC_Handle->hbot.state = BOT_ERROR_OUT; + } else { + if (URB_Status == USBH_URB_STALL) { + MSC_Handle->hbot.state = BOT_ERROR_OUT; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif + } } - } - break; + break; - case BOT_DATA_IN: - /* Send first packet */ - USBH_BulkReceiveData (phost, MSC_Handle->hbot.pbuf, - MSC_Handle->InEpSize, MSC_Handle->InPipe); + case BOT_DATA_IN: + /* Send first packet */ + USBH_BulkReceiveData(phost, MSC_Handle->hbot.pbuf, + MSC_Handle->InEpSize, MSC_Handle->InPipe); - MSC_Handle->hbot.state = BOT_DATA_IN_WAIT; + MSC_Handle->hbot.state = BOT_DATA_IN_WAIT; - break; + break; - case BOT_DATA_IN_WAIT: + case BOT_DATA_IN_WAIT: - URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->InPipe); + URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->InPipe); - if(URB_Status == USBH_URB_DONE) - { - /* Adjust Data pointer and data length */ - if(MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->InEpSize) - { + if (URB_Status == USBH_URB_DONE) { + /* Adjust Data pointer and data length */ + if (MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->InEpSize) { MSC_Handle->hbot.pbuf += MSC_Handle->InEpSize; MSC_Handle->hbot.cbw.field.DataTransferLength -= MSC_Handle->InEpSize; - } - else - { - MSC_Handle->hbot.cbw.field.DataTransferLength = 0U; - } + } else { + MSC_Handle->hbot.cbw.field.DataTransferLength = 0U; + } - /* More Data To be Received */ - if(MSC_Handle->hbot.cbw.field.DataTransferLength > 0U) - { - /* Send next packet */ - USBH_BulkReceiveData (phost, MSC_Handle->hbot.pbuf, - MSC_Handle->InEpSize, MSC_Handle->InPipe); - } - else - { - /* If value was 0, and successful transfer, then change the state */ - MSC_Handle->hbot.state = BOT_RECEIVE_CSW; + /* More Data To be Received */ + if (MSC_Handle->hbot.cbw.field.DataTransferLength > 0U) { + /* Send next packet */ + USBH_BulkReceiveData(phost, MSC_Handle->hbot.pbuf, + MSC_Handle->InEpSize, MSC_Handle->InPipe); + } else { + /* If value was 0, and successful transfer, then change the state */ + MSC_Handle->hbot.state = BOT_RECEIVE_CSW; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - } - else if(URB_Status == USBH_URB_STALL) - { - /* This is Data IN Stage STALL Condition */ - MSC_Handle->hbot.state = BOT_ERROR_IN; - - /* Refer to USB Mass-Storage Class : BOT (www.usb.org) - 6.7.2 Host expects to receive data from the device - 3. On a STALL condition receiving data, then: - The host shall accept the data received. - The host shall clear the Bulk-In pipe. - 4. The host shall attempt to receive a CSW.*/ + } + } else if (URB_Status == USBH_URB_STALL) { + /* This is Data IN Stage STALL Condition */ + MSC_Handle->hbot.state = BOT_ERROR_IN; + + /* Refer to USB Mass-Storage Class : BOT (www.usb.org) + 6.7.2 Host expects to receive data from the device + 3. On a STALL condition receiving data, then: + The host shall accept the data received. + The host shall clear the Bulk-In pipe. + 4. The host shall attempt to receive a CSW.*/ #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - } - break; + } else { + } + break; - case BOT_DATA_OUT: + case BOT_DATA_OUT: - USBH_BulkSendData (phost, MSC_Handle->hbot.pbuf, - MSC_Handle->OutEpSize, MSC_Handle->OutPipe, 1U); + USBH_BulkSendData(phost, MSC_Handle->hbot.pbuf, + MSC_Handle->OutEpSize, MSC_Handle->OutPipe, 1U); - MSC_Handle->hbot.state = BOT_DATA_OUT_WAIT; - break; + MSC_Handle->hbot.state = BOT_DATA_OUT_WAIT; + break; - case BOT_DATA_OUT_WAIT: - URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->OutPipe); + case BOT_DATA_OUT_WAIT: + URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->OutPipe); - if(URB_Status == USBH_URB_DONE) - { - /* Adjust Data pointer and data length */ - if(MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->OutEpSize) - { + if (URB_Status == USBH_URB_DONE) { + /* Adjust Data pointer and data length */ + if (MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->OutEpSize) { MSC_Handle->hbot.pbuf += MSC_Handle->OutEpSize; MSC_Handle->hbot.cbw.field.DataTransferLength -= MSC_Handle->OutEpSize; - } - else - { - MSC_Handle->hbot.cbw.field.DataTransferLength = 0U; - } + } else { + MSC_Handle->hbot.cbw.field.DataTransferLength = 0U; + } - /* More Data To be Sent */ - if(MSC_Handle->hbot.cbw.field.DataTransferLength > 0U) - { - USBH_BulkSendData (phost, MSC_Handle->hbot.pbuf, - MSC_Handle->OutEpSize, MSC_Handle->OutPipe, 1U); - } - else - { - /* If value was 0, and successful transfer, then change the state */ - MSC_Handle->hbot.state = BOT_RECEIVE_CSW; - } + /* More Data To be Sent */ + if (MSC_Handle->hbot.cbw.field.DataTransferLength > 0U) { + USBH_BulkSendData(phost, MSC_Handle->hbot.pbuf, + MSC_Handle->OutEpSize, MSC_Handle->OutPipe, 1U); + } else { + /* If value was 0, and successful transfer, then change the state */ + MSC_Handle->hbot.state = BOT_RECEIVE_CSW; + } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } + } - else if(URB_Status == USBH_URB_NOTREADY) - { - /* Resend same data */ - MSC_Handle->hbot.state = BOT_DATA_OUT; + else if (URB_Status == USBH_URB_NOTREADY) { + /* Resend same data */ + MSC_Handle->hbot.state = BOT_DATA_OUT; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } + } - else if(URB_Status == USBH_URB_STALL) - { - MSC_Handle->hbot.state = BOT_ERROR_OUT; + else if (URB_Status == USBH_URB_STALL) { + MSC_Handle->hbot.state = BOT_ERROR_OUT; - /* Refer to USB Mass-Storage Class : BOT (www.usb.org) - 6.7.3 Ho - Host expects to send data to the device - 3. On a STALL condition sending data, then: - " The host shall clear the Bulk-Out pipe. - 4. The host shall attempt to receive a CSW. - */ + /* Refer to USB Mass-Storage Class : BOT (www.usb.org) + 6.7.3 Ho - Host expects to send data to the device + 3. On a STALL condition sending data, then: + " The host shall clear the Bulk-Out pipe. + 4. The host shall attempt to receive a CSW. + */ #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - } - break; + } else { + } + break; - case BOT_RECEIVE_CSW: + case BOT_RECEIVE_CSW: - USBH_BulkReceiveData (phost, MSC_Handle->hbot.csw.data, - BOT_CSW_LENGTH, MSC_Handle->InPipe); + USBH_BulkReceiveData(phost, MSC_Handle->hbot.csw.data, + BOT_CSW_LENGTH, MSC_Handle->InPipe); - MSC_Handle->hbot.state = BOT_RECEIVE_CSW_WAIT; - break; + MSC_Handle->hbot.state = BOT_RECEIVE_CSW_WAIT; + break; - case BOT_RECEIVE_CSW_WAIT: + case BOT_RECEIVE_CSW_WAIT: - URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->InPipe); + URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->InPipe); - /* Decode CSW */ - if(URB_Status == USBH_URB_DONE) - { - MSC_Handle->hbot.state = BOT_SEND_CBW; - MSC_Handle->hbot.cmd_state = BOT_CMD_SEND; - CSW_Status = USBH_MSC_DecodeCSW(phost); + /* Decode CSW */ + if (URB_Status == USBH_URB_DONE) { + MSC_Handle->hbot.state = BOT_SEND_CBW; + MSC_Handle->hbot.cmd_state = BOT_CMD_SEND; + CSW_Status = USBH_MSC_DecodeCSW(phost); - if(CSW_Status == BOT_CSW_CMD_PASSED) - { - status = USBH_OK; - } - else - { - status = USBH_FAIL; - } + if (CSW_Status == BOT_CSW_CMD_PASSED) { + status = USBH_OK; + } else { + status = USBH_FAIL; + } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else if(URB_Status == USBH_URB_STALL) - { - MSC_Handle->hbot.state = BOT_ERROR_IN; + } else if (URB_Status == USBH_URB_STALL) { + MSC_Handle->hbot.state = BOT_ERROR_IN; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - } - break; + } else { + } + break; - case BOT_ERROR_IN: - error = USBH_MSC_BOT_Abort(phost, lun, BOT_DIR_IN); + case BOT_ERROR_IN: + error = USBH_MSC_BOT_Abort(phost, lun, BOT_DIR_IN); - if (error == USBH_OK) - { - MSC_Handle->hbot.state = BOT_RECEIVE_CSW; - } - else if (error == USBH_UNRECOVERED_ERROR) - { - /* This means that there is a STALL Error limit, Do Reset Recovery */ - MSC_Handle->hbot.state = BOT_UNRECOVERED_ERROR; - } - else - { - } - break; + if (error == USBH_OK) { + MSC_Handle->hbot.state = BOT_RECEIVE_CSW; + } else if (error == USBH_UNRECOVERED_ERROR) { + /* This means that there is a STALL Error limit, Do Reset Recovery */ + MSC_Handle->hbot.state = BOT_UNRECOVERED_ERROR; + } else { + } + break; - case BOT_ERROR_OUT: - error = USBH_MSC_BOT_Abort(phost, lun, BOT_DIR_OUT); + case BOT_ERROR_OUT: + error = USBH_MSC_BOT_Abort(phost, lun, BOT_DIR_OUT); - if (error == USBH_OK) - { + if (error == USBH_OK) { - toggle = USBH_LL_GetToggle(phost, MSC_Handle->OutPipe); - USBH_LL_SetToggle(phost, MSC_Handle->OutPipe, 1U - toggle); - USBH_LL_SetToggle(phost, MSC_Handle->InPipe, 0U); - MSC_Handle->hbot.state = BOT_ERROR_IN; - } - else - { - if (error == USBH_UNRECOVERED_ERROR) - { - MSC_Handle->hbot.state = BOT_UNRECOVERED_ERROR; + toggle = USBH_LL_GetToggle(phost, MSC_Handle->OutPipe); + USBH_LL_SetToggle(phost, MSC_Handle->OutPipe, 1U - toggle); + USBH_LL_SetToggle(phost, MSC_Handle->InPipe, 0U); + MSC_Handle->hbot.state = BOT_ERROR_IN; + } else { + if (error == USBH_UNRECOVERED_ERROR) { + MSC_Handle->hbot.state = BOT_UNRECOVERED_ERROR; + } } - } - break; + break; - case BOT_UNRECOVERED_ERROR: - status = USBH_MSC_BOT_REQ_Reset(phost); - if ( status == USBH_OK) - { - MSC_Handle->hbot.state = BOT_SEND_CBW; - } - break; + case BOT_UNRECOVERED_ERROR: + status = USBH_MSC_BOT_REQ_Reset(phost); + if (status == USBH_OK) { + MSC_Handle->hbot.state = BOT_SEND_CBW; + } + break; - default: - break; + default: + break; } return status; } @@ -533,23 +482,22 @@ USBH_StatusTypeDef USBH_MSC_BOT_Process (USBH_HandleTypeDef *phost, uint8_t lun) static USBH_StatusTypeDef USBH_MSC_BOT_Abort(USBH_HandleTypeDef *phost, uint8_t lun, uint8_t dir) { USBH_StatusTypeDef status = USBH_FAIL; - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; - switch (dir) - { - case BOT_DIR_IN : - /* send ClrFeture on Bulk IN endpoint */ - status = USBH_ClrFeature(phost, MSC_Handle->InEp); + switch (dir) { + case BOT_DIR_IN : + /* send ClrFeture on Bulk IN endpoint */ + status = USBH_ClrFeature(phost, MSC_Handle->InEp); - break; + break; - case BOT_DIR_OUT : - /*send ClrFeature on Bulk OUT endpoint */ - status = USBH_ClrFeature(phost, MSC_Handle->OutEp); - break; + case BOT_DIR_OUT : + /*send ClrFeature on Bulk OUT endpoint */ + status = USBH_ClrFeature(phost, MSC_Handle->OutEp); + break; - default: - break; + default: + break; } return status; } @@ -571,98 +519,88 @@ static USBH_StatusTypeDef USBH_MSC_BOT_Abort(USBH_HandleTypeDef *phost, uint8_t static BOT_CSWStatusTypeDef USBH_MSC_DecodeCSW(USBH_HandleTypeDef *phost) { - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; BOT_CSWStatusTypeDef status = BOT_CSW_CMD_FAILED; - /*Checking if the transfer length is different than 13*/ - if(USBH_LL_GetLastXferSize(phost, MSC_Handle->InPipe) != BOT_CSW_LENGTH) - { - /*(4) Hi > Dn (Host expects to receive data from the device, - Device intends to transfer no data) - (5) Hi > Di (Host expects to receive data from the device, - Device intends to send data to the host) - (9) Ho > Dn (Host expects to send data to the device, - Device intends to transfer no data) - (11) Ho > Do (Host expects to send data to the device, - Device intends to receive data from the host)*/ + /*Checking if the transfer length is different than 13*/ + if (USBH_LL_GetLastXferSize(phost, MSC_Handle->InPipe) != BOT_CSW_LENGTH) { + /*(4) Hi > Dn (Host expects to receive data from the device, + Device intends to transfer no data) + (5) Hi > Di (Host expects to receive data from the device, + Device intends to send data to the host) + (9) Ho > Dn (Host expects to send data to the device, + Device intends to transfer no data) + (11) Ho > Do (Host expects to send data to the device, + Device intends to receive data from the host)*/ + + + status = BOT_CSW_PHASE_ERROR; + } else { + /* CSW length is Correct */ + + /* Check validity of the CSW Signature and CSWStatus */ + if (MSC_Handle->hbot.csw.field.Signature == BOT_CSW_SIGNATURE) { + /* Check Condition 1. dCSWSignature is equal to 53425355h */ + + if (MSC_Handle->hbot.csw.field.Tag == MSC_Handle->hbot.cbw.field.Tag) { + /* Check Condition 3. dCSWTag matches the dCBWTag from the + corresponding CBW */ + + if (MSC_Handle->hbot.csw.field.Status == 0U) { + /* Refer to USB Mass-Storage Class : BOT (www.usb.org) + + Hn Host expects no data transfers + Hi Host expects to receive data from the device + Ho Host expects to send data to the device + + Dn Device intends to transfer no data + Di Device intends to send data to the host + Do Device intends to receive data from the host + + Section 6.7 + (1) Hn = Dn (Host expects no data transfers, + Device intends to transfer no data) + (6) Hi = Di (Host expects to receive data from the device, + Device intends to send data to the host) + (12) Ho = Do (Host expects to send data to the device, + Device intends to receive data from the host) + + */ + + status = BOT_CSW_CMD_PASSED; + } else if (MSC_Handle->hbot.csw.field.Status == 1U) { + status = BOT_CSW_CMD_FAILED; + } + else if (MSC_Handle->hbot.csw.field.Status == 2U) { + /* Refer to USB Mass-Storage Class : BOT (www.usb.org) + Section 6.7 + (2) Hn < Di ( Host expects no data transfers, + Device intends to send data to the host) + (3) Hn < Do ( Host expects no data transfers, + Device intends to receive data from the host) + (7) Hi < Di ( Host expects to receive data from the device, + Device intends to send data to the host) + (8) Hi <> Do ( Host expects to receive data from the device, + Device intends to receive data from the host) + (10) Ho <> Di (Host expects to send data to the device, + Di Device intends to send data to the host) + (13) Ho < Do (Host expects to send data to the device, + Device intends to receive data from the host) + */ + + status = BOT_CSW_PHASE_ERROR; + } else { + } + } /* CSW Tag Matching is Checked */ + } /* CSW Signature Correct Checking */ + else { + /* If the CSW Signature is not valid, We sall return the Phase Error to + Upper Layers for Reset Recovery */ status = BOT_CSW_PHASE_ERROR; } - else - { /* CSW length is Correct */ - - /* Check validity of the CSW Signature and CSWStatus */ - if(MSC_Handle->hbot.csw.field.Signature == BOT_CSW_SIGNATURE) - {/* Check Condition 1. dCSWSignature is equal to 53425355h */ - - if(MSC_Handle->hbot.csw.field.Tag == MSC_Handle->hbot.cbw.field.Tag) - { - /* Check Condition 3. dCSWTag matches the dCBWTag from the - corresponding CBW */ - - if(MSC_Handle->hbot.csw.field.Status == 0U) - { - /* Refer to USB Mass-Storage Class : BOT (www.usb.org) - - Hn Host expects no data transfers - Hi Host expects to receive data from the device - Ho Host expects to send data to the device - - Dn Device intends to transfer no data - Di Device intends to send data to the host - Do Device intends to receive data from the host - - Section 6.7 - (1) Hn = Dn (Host expects no data transfers, - Device intends to transfer no data) - (6) Hi = Di (Host expects to receive data from the device, - Device intends to send data to the host) - (12) Ho = Do (Host expects to send data to the device, - Device intends to receive data from the host) - - */ - - status = BOT_CSW_CMD_PASSED; - } - else if(MSC_Handle->hbot.csw.field.Status == 1U) - { - status = BOT_CSW_CMD_FAILED; - } - - else if(MSC_Handle->hbot.csw.field.Status == 2U) - { - /* Refer to USB Mass-Storage Class : BOT (www.usb.org) - Section 6.7 - (2) Hn < Di ( Host expects no data transfers, - Device intends to send data to the host) - (3) Hn < Do ( Host expects no data transfers, - Device intends to receive data from the host) - (7) Hi < Di ( Host expects to receive data from the device, - Device intends to send data to the host) - (8) Hi <> Do ( Host expects to receive data from the device, - Device intends to receive data from the host) - (10) Ho <> Di (Host expects to send data to the device, - Di Device intends to send data to the host) - (13) Ho < Do (Host expects to send data to the device, - Device intends to receive data from the host) - */ - - status = BOT_CSW_PHASE_ERROR; - } - else - { - } - } /* CSW Tag Matching is Checked */ - } /* CSW Signature Correct Checking */ - else - { - /* If the CSW Signature is not valid, We sall return the Phase Error to - Upper Layers for Reset Recovery */ - - status = BOT_CSW_PHASE_ERROR; - } - } /* CSW Length Check*/ + } /* CSW Length Check*/ return status; } diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_scsi.c b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_scsi.c index 2e7bc22764..aabba80ebf 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_scsi.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_scsi.c @@ -17,12 +17,12 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" - - "stm32xxxxx_{eval}{discovery}_sdram.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" +- "stm32xxxxx_{eval}{discovery}_sdram.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbh_msc.h" @@ -100,35 +100,34 @@ * @param lun: Logical Unit Number * @retval USBH Status */ -USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady (USBH_HandleTypeDef *phost, - uint8_t lun) +USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady(USBH_HandleTypeDef *phost, + uint8_t lun) { USBH_StatusTypeDef error = USBH_FAIL ; - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; - switch(MSC_Handle->hbot.cmd_state) - { - case BOT_CMD_SEND: + switch (MSC_Handle->hbot.cmd_state) { + case BOT_CMD_SEND: - /*Prepare the CBW and relevent field*/ - MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_MODE_TEST_UNIT_READY; - MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_OUT; - MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; + /*Prepare the CBW and relevent field*/ + MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_MODE_TEST_UNIT_READY; + MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_OUT; + MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; - USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); - MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_TEST_UNIT_READY; + USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); + MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_TEST_UNIT_READY; - MSC_Handle->hbot.state = BOT_SEND_CBW; - MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; - error = USBH_BUSY; - break; + MSC_Handle->hbot.state = BOT_SEND_CBW; + MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; + error = USBH_BUSY; + break; - case BOT_CMD_WAIT: - error = USBH_MSC_BOT_Process(phost, lun); - break; + case BOT_CMD_WAIT: + error = USBH_MSC_BOT_Process(phost, lun); + break; - default: - break; + default: + break; } return error; @@ -142,49 +141,47 @@ USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady (USBH_HandleTypeDef *phost, * @param capacity: pointer to the capacity structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity (USBH_HandleTypeDef *phost, - uint8_t lun, - SCSI_CapacityTypeDef *capacity) +USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity(USBH_HandleTypeDef *phost, + uint8_t lun, + SCSI_CapacityTypeDef *capacity) { USBH_StatusTypeDef error = USBH_BUSY ; - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; - switch(MSC_Handle->hbot.cmd_state) - { - case BOT_CMD_SEND: + switch (MSC_Handle->hbot.cmd_state) { + case BOT_CMD_SEND: - /*Prepare the CBW and relevent field*/ - MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_READ_CAPACITY10; - MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN; - MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; + /*Prepare the CBW and relevent field*/ + MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_READ_CAPACITY10; + MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN; + MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; - USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); - MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_READ_CAPACITY10; + USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); + MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_READ_CAPACITY10; - MSC_Handle->hbot.state = BOT_SEND_CBW; + MSC_Handle->hbot.state = BOT_SEND_CBW; - MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; - MSC_Handle->hbot.pbuf = (uint8_t *)(void *)MSC_Handle->hbot.data; - error = USBH_BUSY; - break; + MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; + MSC_Handle->hbot.pbuf = (uint8_t *)(void *)MSC_Handle->hbot.data; + error = USBH_BUSY; + break; - case BOT_CMD_WAIT: + case BOT_CMD_WAIT: - error = USBH_MSC_BOT_Process(phost, lun); + error = USBH_MSC_BOT_Process(phost, lun); - if(error == USBH_OK) - { - /*assign the capacity*/ - capacity->block_nbr = MSC_Handle->hbot.pbuf[3] | ((uint32_t)MSC_Handle->hbot.pbuf[2] << 8U) |\ - ((uint32_t)MSC_Handle->hbot.pbuf[1] << 16U) | ((uint32_t)MSC_Handle->hbot.pbuf[0] << 24U); + if (error == USBH_OK) { + /*assign the capacity*/ + capacity->block_nbr = MSC_Handle->hbot.pbuf[3] | ((uint32_t)MSC_Handle->hbot.pbuf[2] << 8U) | \ + ((uint32_t)MSC_Handle->hbot.pbuf[1] << 16U) | ((uint32_t)MSC_Handle->hbot.pbuf[0] << 24U); - /*assign the page length*/ - capacity->block_size = (uint16_t)(MSC_Handle->hbot.pbuf[7] | ((uint32_t)MSC_Handle->hbot.pbuf[6] << 8U)); - } - break; + /*assign the page length*/ + capacity->block_size = (uint16_t)(MSC_Handle->hbot.pbuf[7] | ((uint32_t)MSC_Handle->hbot.pbuf[6] << 8U)); + } + break; - default: - break; + default: + break; } return error; @@ -198,64 +195,59 @@ USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity (USBH_HandleTypeDef *phost, * @param capacity: pointer to the inquiry structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry (USBH_HandleTypeDef *phost, uint8_t lun, - SCSI_StdInquiryDataTypeDef *inquiry) +USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry(USBH_HandleTypeDef *phost, uint8_t lun, + SCSI_StdInquiryDataTypeDef *inquiry) { USBH_StatusTypeDef error = USBH_FAIL; MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; - switch(MSC_Handle->hbot.cmd_state) - { - case BOT_CMD_SEND: + switch (MSC_Handle->hbot.cmd_state) { + case BOT_CMD_SEND: - /*Prepare the CBW and relevent field*/ - MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_INQUIRY; - MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN; - MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; + /*Prepare the CBW and relevent field*/ + MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_INQUIRY; + MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN; + MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; - USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_LENGTH); - MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_INQUIRY; - MSC_Handle->hbot.cbw.field.CB[1] = (lun << 5); - MSC_Handle->hbot.cbw.field.CB[2] = 0U; - MSC_Handle->hbot.cbw.field.CB[3] = 0U; - MSC_Handle->hbot.cbw.field.CB[4] = 0x24U; - MSC_Handle->hbot.cbw.field.CB[5] = 0U; + USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_LENGTH); + MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_INQUIRY; + MSC_Handle->hbot.cbw.field.CB[1] = (lun << 5); + MSC_Handle->hbot.cbw.field.CB[2] = 0U; + MSC_Handle->hbot.cbw.field.CB[3] = 0U; + MSC_Handle->hbot.cbw.field.CB[4] = 0x24U; + MSC_Handle->hbot.cbw.field.CB[5] = 0U; - MSC_Handle->hbot.state = BOT_SEND_CBW; + MSC_Handle->hbot.state = BOT_SEND_CBW; - MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; - MSC_Handle->hbot.pbuf = (uint8_t *)(void *)MSC_Handle->hbot.data; - error = USBH_BUSY; - break; + MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; + MSC_Handle->hbot.pbuf = (uint8_t *)(void *)MSC_Handle->hbot.data; + error = USBH_BUSY; + break; - case BOT_CMD_WAIT: + case BOT_CMD_WAIT: - error = USBH_MSC_BOT_Process(phost, lun); + error = USBH_MSC_BOT_Process(phost, lun); - if(error == USBH_OK) - { - USBH_memset(inquiry, 0, sizeof(SCSI_StdInquiryDataTypeDef)); - /*assign Inquiry Data */ - inquiry->DeviceType = MSC_Handle->hbot.pbuf[0] & 0x1FU; - inquiry->PeripheralQualifier = MSC_Handle->hbot.pbuf[0] >> 5U; + if (error == USBH_OK) { + USBH_memset(inquiry, 0, sizeof(SCSI_StdInquiryDataTypeDef)); + /*assign Inquiry Data */ + inquiry->DeviceType = MSC_Handle->hbot.pbuf[0] & 0x1FU; + inquiry->PeripheralQualifier = MSC_Handle->hbot.pbuf[0] >> 5U; - if (((uint32_t)MSC_Handle->hbot.pbuf[1] & 0x80U) == 0x80U) - { - inquiry->RemovableMedia = 1U; - } - else - { - inquiry->RemovableMedia = 0U; - } + if (((uint32_t)MSC_Handle->hbot.pbuf[1] & 0x80U) == 0x80U) { + inquiry->RemovableMedia = 1U; + } else { + inquiry->RemovableMedia = 0U; + } - USBH_memcpy (inquiry->vendor_id, &MSC_Handle->hbot.pbuf[8], 8U); - USBH_memcpy (inquiry->product_id, &MSC_Handle->hbot.pbuf[16], 16U); - USBH_memcpy (inquiry->revision_id, &MSC_Handle->hbot.pbuf[32], 4U); - } - break; + USBH_memcpy(inquiry->vendor_id, &MSC_Handle->hbot.pbuf[8], 8U); + USBH_memcpy(inquiry->product_id, &MSC_Handle->hbot.pbuf[16], 16U); + USBH_memcpy(inquiry->revision_id, &MSC_Handle->hbot.pbuf[32], 4U); + } + break; - default: - break; + default: + break; } return error; @@ -269,50 +261,48 @@ USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry (USBH_HandleTypeDef *phost, uint8_t lun * @param capacity: pointer to the sense data structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense (USBH_HandleTypeDef *phost, - uint8_t lun, - SCSI_SenseTypeDef *sense_data) +USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense(USBH_HandleTypeDef *phost, + uint8_t lun, + SCSI_SenseTypeDef *sense_data) { USBH_StatusTypeDef error = USBH_FAIL ; - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; - - switch(MSC_Handle->hbot.cmd_state) - { - case BOT_CMD_SEND: - - /*Prepare the CBW and relevent field*/ - MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_REQUEST_SENSE; - MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN; - MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; - - USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); - MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_REQUEST_SENSE; - MSC_Handle->hbot.cbw.field.CB[1] = (lun << 5); - MSC_Handle->hbot.cbw.field.CB[2] = 0U; - MSC_Handle->hbot.cbw.field.CB[3] = 0U; - MSC_Handle->hbot.cbw.field.CB[4] = DATA_LEN_REQUEST_SENSE; - MSC_Handle->hbot.cbw.field.CB[5] = 0U; - - MSC_Handle->hbot.state = BOT_SEND_CBW; - MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; - MSC_Handle->hbot.pbuf = (uint8_t *)(void *)MSC_Handle->hbot.data; - error = USBH_BUSY; - break; - - case BOT_CMD_WAIT: - - error = USBH_MSC_BOT_Process(phost, lun); - - if(error == USBH_OK) - { - sense_data->key = MSC_Handle->hbot.pbuf[2] & 0x0FU; - sense_data->asc = MSC_Handle->hbot.pbuf[12]; - sense_data->ascq = MSC_Handle->hbot.pbuf[13]; - } - break; - - default: - break; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + + switch (MSC_Handle->hbot.cmd_state) { + case BOT_CMD_SEND: + + /*Prepare the CBW and relevent field*/ + MSC_Handle->hbot.cbw.field.DataTransferLength = DATA_LEN_REQUEST_SENSE; + MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN; + MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; + + USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); + MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_REQUEST_SENSE; + MSC_Handle->hbot.cbw.field.CB[1] = (lun << 5); + MSC_Handle->hbot.cbw.field.CB[2] = 0U; + MSC_Handle->hbot.cbw.field.CB[3] = 0U; + MSC_Handle->hbot.cbw.field.CB[4] = DATA_LEN_REQUEST_SENSE; + MSC_Handle->hbot.cbw.field.CB[5] = 0U; + + MSC_Handle->hbot.state = BOT_SEND_CBW; + MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; + MSC_Handle->hbot.pbuf = (uint8_t *)(void *)MSC_Handle->hbot.data; + error = USBH_BUSY; + break; + + case BOT_CMD_WAIT: + + error = USBH_MSC_BOT_Process(phost, lun); + + if (error == USBH_OK) { + sense_data->key = MSC_Handle->hbot.pbuf[2] & 0x0FU; + sense_data->asc = MSC_Handle->hbot.pbuf[12]; + sense_data->ascq = MSC_Handle->hbot.pbuf[13]; + } + break; + + default: + break; } return error; @@ -329,51 +319,50 @@ USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense (USBH_HandleTypeDef *phost, * @retval USBH Status */ USBH_StatusTypeDef USBH_MSC_SCSI_Write(USBH_HandleTypeDef *phost, - uint8_t lun, - uint32_t address, - uint8_t *pbuf, - uint32_t length) + uint8_t lun, + uint32_t address, + uint8_t *pbuf, + uint32_t length) { USBH_StatusTypeDef error = USBH_FAIL ; - MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; + MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; - switch(MSC_Handle->hbot.cmd_state) - { - case BOT_CMD_SEND: + switch (MSC_Handle->hbot.cmd_state) { + case BOT_CMD_SEND: - /*Prepare the CBW and relevent field*/ - MSC_Handle->hbot.cbw.field.DataTransferLength = length * MSC_Handle->unit[0].capacity.block_size; - MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_OUT; - MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; + /*Prepare the CBW and relevent field*/ + MSC_Handle->hbot.cbw.field.DataTransferLength = length * MSC_Handle->unit[0].capacity.block_size; + MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_OUT; + MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; - USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); - MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_WRITE10; + USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); + MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_WRITE10; - /*logical block address*/ - MSC_Handle->hbot.cbw.field.CB[2] = (((uint8_t*)(void *)&address)[3]); - MSC_Handle->hbot.cbw.field.CB[3] = (((uint8_t*)(void *)&address)[2]); - MSC_Handle->hbot.cbw.field.CB[4] = (((uint8_t*)(void *)&address)[1]); - MSC_Handle->hbot.cbw.field.CB[5] = (((uint8_t*)(void *)&address)[0]); + /*logical block address*/ + MSC_Handle->hbot.cbw.field.CB[2] = (((uint8_t *)(void *)&address)[3]); + MSC_Handle->hbot.cbw.field.CB[3] = (((uint8_t *)(void *)&address)[2]); + MSC_Handle->hbot.cbw.field.CB[4] = (((uint8_t *)(void *)&address)[1]); + MSC_Handle->hbot.cbw.field.CB[5] = (((uint8_t *)(void *)&address)[0]); - /*Transfer length */ - MSC_Handle->hbot.cbw.field.CB[7] = (((uint8_t *)(void *)&length)[1]) ; - MSC_Handle->hbot.cbw.field.CB[8] = (((uint8_t *)(void *)&length)[0]) ; + /*Transfer length */ + MSC_Handle->hbot.cbw.field.CB[7] = (((uint8_t *)(void *)&length)[1]) ; + MSC_Handle->hbot.cbw.field.CB[8] = (((uint8_t *)(void *)&length)[0]) ; - MSC_Handle->hbot.state = BOT_SEND_CBW; - MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; - MSC_Handle->hbot.pbuf = pbuf; - error = USBH_BUSY; - break; + MSC_Handle->hbot.state = BOT_SEND_CBW; + MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; + MSC_Handle->hbot.pbuf = pbuf; + error = USBH_BUSY; + break; - case BOT_CMD_WAIT: - error = USBH_MSC_BOT_Process(phost, lun); - break; + case BOT_CMD_WAIT: + error = USBH_MSC_BOT_Process(phost, lun); + break; - default: - break; + default: + break; } return error; @@ -390,50 +379,49 @@ USBH_StatusTypeDef USBH_MSC_SCSI_Write(USBH_HandleTypeDef *phost, * @retval USBH Status */ USBH_StatusTypeDef USBH_MSC_SCSI_Read(USBH_HandleTypeDef *phost, - uint8_t lun, - uint32_t address, - uint8_t *pbuf, - uint32_t length) + uint8_t lun, + uint32_t address, + uint8_t *pbuf, + uint32_t length) { USBH_StatusTypeDef error = USBH_FAIL ; MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; - switch(MSC_Handle->hbot.cmd_state) - { - case BOT_CMD_SEND: + switch (MSC_Handle->hbot.cmd_state) { + case BOT_CMD_SEND: - /*Prepare the CBW and relevent field*/ - MSC_Handle->hbot.cbw.field.DataTransferLength = length * MSC_Handle->unit[0].capacity.block_size; - MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN; - MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; + /*Prepare the CBW and relevent field*/ + MSC_Handle->hbot.cbw.field.DataTransferLength = length * MSC_Handle->unit[0].capacity.block_size; + MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN; + MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH; - USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); - MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_READ10; + USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH); + MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_READ10; - /*logical block address*/ - MSC_Handle->hbot.cbw.field.CB[2] = (((uint8_t*)(void *)&address)[3]); - MSC_Handle->hbot.cbw.field.CB[3] = (((uint8_t*)(void *)&address)[2]); - MSC_Handle->hbot.cbw.field.CB[4] = (((uint8_t*)(void *)&address)[1]); - MSC_Handle->hbot.cbw.field.CB[5] = (((uint8_t*)(void *)&address)[0]); + /*logical block address*/ + MSC_Handle->hbot.cbw.field.CB[2] = (((uint8_t *)(void *)&address)[3]); + MSC_Handle->hbot.cbw.field.CB[3] = (((uint8_t *)(void *)&address)[2]); + MSC_Handle->hbot.cbw.field.CB[4] = (((uint8_t *)(void *)&address)[1]); + MSC_Handle->hbot.cbw.field.CB[5] = (((uint8_t *)(void *)&address)[0]); - /*Transfer length */ - MSC_Handle->hbot.cbw.field.CB[7] = (((uint8_t *)(void *)&length)[1]) ; - MSC_Handle->hbot.cbw.field.CB[8] = (((uint8_t *)(void *)&length)[0]) ; + /*Transfer length */ + MSC_Handle->hbot.cbw.field.CB[7] = (((uint8_t *)(void *)&length)[1]) ; + MSC_Handle->hbot.cbw.field.CB[8] = (((uint8_t *)(void *)&length)[0]) ; - MSC_Handle->hbot.state = BOT_SEND_CBW; - MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; - MSC_Handle->hbot.pbuf = pbuf; - error = USBH_BUSY; - break; + MSC_Handle->hbot.state = BOT_SEND_CBW; + MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT; + MSC_Handle->hbot.pbuf = pbuf; + error = USBH_BUSY; + break; - case BOT_CMD_WAIT: - error = USBH_MSC_BOT_Process(phost, lun); - break; + case BOT_CMD_WAIT: + error = USBH_MSC_BOT_Process(phost, lun); + break; - default: - break; + default: + break; } return error; diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Inc/usbh_mtp.h b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Inc/usbh_mtp.h index ffac223166..0d1e0fa246 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Inc/usbh_mtp.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Inc/usbh_mtp.h @@ -22,7 +22,7 @@ #define __USBH_MTP_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -61,37 +61,33 @@ /** @defgroup USBH_MTP_CORE_Exported_Types * @{ */ -typedef enum -{ +typedef enum { MTP_IDLE = 0, - MTP_GETDEVICEINFO , - MTP_OPENSESSION , - MTP_CLOSESESSION , - MTP_GETSTORAGEIDS , - MTP_GETSTORAGEINFO , + MTP_GETDEVICEINFO, + MTP_OPENSESSION, + MTP_CLOSESESSION, + MTP_GETSTORAGEIDS, + MTP_GETSTORAGEINFO, } MTP_StateTypeDef; -typedef enum -{ +typedef enum { MTP_EVENTS_INIT = 0, - MTP_EVENTS_GETDATA , + MTP_EVENTS_GETDATA, } MTP_EventsStateTypeDef; -typedef struct -{ - MTP_EventsStateTypeDef state; - uint32_t timer; - uint16_t poll; - PTP_EventContainerTypedef container; +typedef struct { + MTP_EventsStateTypeDef state; + uint32_t timer; + uint16_t poll; + PTP_EventContainerTypedef container; } MTP_EventHandleTypedef; -typedef struct -{ +typedef struct { uint32_t CurrentStorageId; uint32_t ObjectFormatCode; @@ -102,8 +98,7 @@ typedef struct MTP_ParamsTypedef; -typedef struct -{ +typedef struct { PTP_DeviceInfoTypedef devinfo; PTP_StorageIDsTypedef storids; PTP_StorageInfoTypedef storinfo[MTP_MAX_STORAGE_UNITS_NBR]; @@ -112,8 +107,7 @@ typedef struct MTP_InfoTypedef; /* Structure for MTP process */ -typedef struct _MTP_Process -{ +typedef struct _MTP_Process { MTP_InfoTypedef info; MTP_ParamsTypedef params; @@ -171,66 +165,66 @@ extern USBH_ClassTypeDef MTP_Class; /** @defgroup USBH_MTP_CORE_Exported_FunctionsPrototype * @{ */ -uint8_t USBH_MTP_IsReady (USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_MTP_SelectStorage (USBH_HandleTypeDef *phost, uint8_t storage_idx); -USBH_StatusTypeDef USBH_MTP_GetNumStorage (USBH_HandleTypeDef *phost, uint8_t *storage_num); -USBH_StatusTypeDef USBH_MTP_GetNumObjects (USBH_HandleTypeDef *phost, - uint32_t storage_idx, - uint32_t objectformatcode, - uint32_t associationOH, - uint32_t* numobs); -USBH_StatusTypeDef USBH_MTP_GetStorageInfo (USBH_HandleTypeDef *phost, - uint8_t storage_idx, - MTP_StorageInfoTypedef *info); - -USBH_StatusTypeDef USBH_MTP_GetObjectHandles (USBH_HandleTypeDef *phost, - uint32_t storage_idx, - uint32_t objectformatcode, - uint32_t associationOH, - PTP_ObjectHandlesTypedef* objecthandles); - -USBH_StatusTypeDef USBH_MTP_GetObjectInfo (USBH_HandleTypeDef *phost, - uint32_t handle, - PTP_ObjectInfoTypedef* objectinfo); - -USBH_StatusTypeDef USBH_MTP_DeleteObject (USBH_HandleTypeDef *phost, +uint8_t USBH_MTP_IsReady(USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_MTP_SelectStorage(USBH_HandleTypeDef *phost, uint8_t storage_idx); +USBH_StatusTypeDef USBH_MTP_GetNumStorage(USBH_HandleTypeDef *phost, uint8_t *storage_num); +USBH_StatusTypeDef USBH_MTP_GetNumObjects(USBH_HandleTypeDef *phost, + uint32_t storage_idx, + uint32_t objectformatcode, + uint32_t associationOH, + uint32_t *numobs); +USBH_StatusTypeDef USBH_MTP_GetStorageInfo(USBH_HandleTypeDef *phost, + uint8_t storage_idx, + MTP_StorageInfoTypedef *info); + +USBH_StatusTypeDef USBH_MTP_GetObjectHandles(USBH_HandleTypeDef *phost, + uint32_t storage_idx, + uint32_t objectformatcode, + uint32_t associationOH, + PTP_ObjectHandlesTypedef *objecthandles); + +USBH_StatusTypeDef USBH_MTP_GetObjectInfo(USBH_HandleTypeDef *phost, uint32_t handle, - uint32_t objectformatcode); + PTP_ObjectInfoTypedef *objectinfo); -USBH_StatusTypeDef USBH_MTP_GetObject (USBH_HandleTypeDef *phost, - uint32_t handle, - uint8_t *object); +USBH_StatusTypeDef USBH_MTP_DeleteObject(USBH_HandleTypeDef *phost, + uint32_t handle, + uint32_t objectformatcode); + +USBH_StatusTypeDef USBH_MTP_GetObject(USBH_HandleTypeDef *phost, + uint32_t handle, + uint8_t *object); USBH_StatusTypeDef USBH_MTP_GetPartialObject(USBH_HandleTypeDef *phost, - uint32_t handle, - uint32_t offset, - uint32_t maxbytes, - uint8_t *object, - uint32_t *len); - -USBH_StatusTypeDef USBH_MTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost, - uint16_t ofc, - uint32_t *propnum, - uint16_t *props); - -USBH_StatusTypeDef USBH_MTP_GetObjectPropDesc (USBH_HandleTypeDef *phost, - uint16_t opc, - uint16_t ofc, - PTP_ObjectPropDescTypeDef *opd); - -USBH_StatusTypeDef USBH_MTP_GetObjectPropList (USBH_HandleTypeDef *phost, - uint32_t handle, - MTP_PropertiesTypedef *pprops, - uint32_t *nrofprops); - -USBH_StatusTypeDef USBH_MTP_SendObject (USBH_HandleTypeDef *phost, - uint32_t handle, - uint8_t *object, - uint32_t size); - -USBH_StatusTypeDef USBH_MTP_GetDevicePropDesc (USBH_HandleTypeDef *phost, - uint16_t propcode, - PTP_DevicePropDescTypdef* devicepropertydesc); + uint32_t handle, + uint32_t offset, + uint32_t maxbytes, + uint8_t *object, + uint32_t *len); + +USBH_StatusTypeDef USBH_MTP_GetObjectPropsSupported(USBH_HandleTypeDef *phost, + uint16_t ofc, + uint32_t *propnum, + uint16_t *props); + +USBH_StatusTypeDef USBH_MTP_GetObjectPropDesc(USBH_HandleTypeDef *phost, + uint16_t opc, + uint16_t ofc, + PTP_ObjectPropDescTypeDef *opd); + +USBH_StatusTypeDef USBH_MTP_GetObjectPropList(USBH_HandleTypeDef *phost, + uint32_t handle, + MTP_PropertiesTypedef *pprops, + uint32_t *nrofprops); + +USBH_StatusTypeDef USBH_MTP_SendObject(USBH_HandleTypeDef *phost, + uint32_t handle, + uint8_t *object, + uint32_t size); + +USBH_StatusTypeDef USBH_MTP_GetDevicePropDesc(USBH_HandleTypeDef *phost, + uint16_t propcode, + PTP_DevicePropDescTypdef *devicepropertydesc); void USBH_MTP_EventsCallback(USBH_HandleTypeDef *phost, uint32_t event, uint32_t param); /** diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Inc/usbh_mtp_ptp.h b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Inc/usbh_mtp_ptp.h index bf0bfc7d6b..b6d6ae4bc7 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Inc/usbh_mtp_ptp.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Inc/usbh_mtp_ptp.h @@ -22,7 +22,7 @@ #define __USBH_MTP_PTP_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -90,7 +90,7 @@ #define PTP_OC_GetStreamInfo 0x1024U #define PTP_OC_GetStream 0x1025U - /* Microsoft / MTP extension codes */ +/* Microsoft / MTP extension codes */ #define PTP_OC_GetObjectPropsSupported 0x9801U #define PTP_OC_GetObjectPropDesc 0x9802U #define PTP_OC_GetObjectPropValue 0x9803U @@ -180,8 +180,7 @@ * @{ */ -typedef enum -{ +typedef enum { PTP_REQ_IDLE = 0, PTP_REQ_SEND, PTP_REQ_WAIT, @@ -189,8 +188,7 @@ typedef enum } PTP_RequestStateTypeDef; -typedef enum -{ +typedef enum { PTP_IDLE = 0, PTP_OP_REQUEST_STATE, PTP_OP_REQUEST_WAIT_STATE, @@ -205,8 +203,7 @@ typedef enum PTP_ProcessStateTypeDef; /* PTP request/response/event general PTP container (transport independent) */ -typedef struct -{ +typedef struct { uint16_t Code; uint32_t SessionID; uint32_t Transaction_ID; @@ -230,8 +227,7 @@ PTP_ContainerTypedef; #define PTP_USB_BULK_REQ_LEN (PTP_USB_BULK_HDR_LEN + 5U * sizeof(uint32_t)) #define PTP_USB_BULK_REQ_RESP_MAX_LEN 63U -typedef struct -{ +typedef struct { uint32_t length; uint16_t type; uint16_t code; @@ -245,8 +241,7 @@ typedef struct PTP_RespContainerTypedef; -typedef struct -{ +typedef struct { uint32_t length; uint16_t type; uint16_t code; @@ -259,8 +254,7 @@ typedef struct } PTP_OpContainerTypedef; -typedef struct -{ +typedef struct { uint32_t length; uint16_t type; uint16_t code; @@ -274,13 +268,12 @@ typedef struct uint32_t param5; } params; uint8_t data[PTP_USB_BULK_PAYLOAD_LEN_READ]; - }payload; + } payload; } PTP_DataContainerTypedef; /* PTP USB Asynchronous Event Interrupt Data Format */ -typedef struct -{ +typedef struct { uint32_t length; uint16_t type; uint16_t code; @@ -292,8 +285,7 @@ typedef struct PTP_EventContainerTypedef; /* Structure for PTP Transport process */ -typedef struct -{ +typedef struct { PTP_ProcessStateTypeDef state; PTP_RequestStateTypeDef req_state; PTP_OpContainerTypedef op_container; @@ -301,27 +293,27 @@ typedef struct PTP_RespContainerTypedef resp_container; /* ptp transaction ID */ - uint32_t transaction_id; + uint32_t transaction_id; /* ptp session ID */ - uint32_t session_id; + uint32_t session_id; /* device flags */ - uint32_t flags; + uint32_t flags; /****** PTP transfer control *******/ /* Data pointer */ - uint8_t *data_ptr; + uint8_t *data_ptr; /* Data length */ - uint32_t data_length; + uint32_t data_length; /* Data length */ - uint32_t data_packet; + uint32_t data_packet; /* Data length */ - uint32_t iteration; + uint32_t iteration; /* Packet Index */ uint32_t data_packet_counter; @@ -329,7 +321,7 @@ typedef struct /****** Object transfer control *******/ /* object pointer */ - uint8_t *object_ptr; + uint8_t *object_ptr; } PTP_HandleTypeDef; @@ -350,8 +342,7 @@ PTP_HandleTypeDef; #define PTP_IMAGE_FORMATS_NBR 100U #define PTP_MAX_STR_SIZE 255U /* PTP device info structure */ -typedef struct -{ +typedef struct { uint16_t StandardVersion; uint32_t VendorExtensionID; uint16_t VendorExtensionVersion; @@ -376,8 +367,7 @@ PTP_DeviceInfoTypedef; #define PTP_MAX_STORAGE_UNITS_NBR 5 /* PTP storageIDs structute (returned by GetStorageIDs) */ -typedef struct -{ +typedef struct { uint32_t n; uint32_t Storage [PTP_MAX_STORAGE_UNITS_NBR]; } @@ -415,8 +405,7 @@ PTP_StorageIDsTypedef; #define PTP_AC_ReadOnly 0x0001U #define PTP_AC_ReadOnly_with_Object_Deletion 0x0002U -typedef struct -{ +typedef struct { uint16_t StorageType; uint16_t FilesystemType; uint16_t AccessCapability; @@ -709,8 +698,7 @@ PTP_StorageInfoTypedef; #define PTP_AT_AncillaryData 0x0007U #define PTP_MAX_HANDLER_NBR 0x255U -typedef struct -{ +typedef struct { uint32_t n; uint32_t Handler[PTP_MAX_HANDLER_NBR]; } @@ -735,8 +723,7 @@ PTP_ObjectHandlesTypedef; #define PTP_oi_filenamelen 52U #define PTP_oi_Filename 53U -typedef struct -{ +typedef struct { uint32_t StorageID; uint16_t ObjectFormat; uint16_t ProtectionStatus; @@ -763,8 +750,7 @@ PTP_ObjectInfoTypedef; /* Object Property Describing Dataset (DevicePropDesc) */ -typedef union _PTP_PropertyValueTypedef -{ +typedef union _PTP_PropertyValueTypedef { char str[PTP_MAX_STR_SIZE]; uint8_t u8; int8_t i8; @@ -777,11 +763,10 @@ typedef union _PTP_PropertyValueTypedef struct array { uint32_t count; union _PTP_PropertyValueTypedef *v; - }a; -}PTP_PropertyValueTypedef; + } a; +} PTP_PropertyValueTypedef; -typedef struct -{ +typedef struct { PTP_PropertyValueTypedef MinimumValue; PTP_PropertyValueTypedef MaximumValue; PTP_PropertyValueTypedef StepSize; @@ -790,8 +775,7 @@ PTP_PropDescRangeFormTypedef; /* Property Describing Dataset, Enum Form */ -typedef struct -{ +typedef struct { uint16_t NumberOfValues; PTP_PropertyValueTypedef SupportedValue[PTP_SUPPORTED_PROPRIETIES_NBR]; } @@ -803,8 +787,7 @@ PTP_PropDescEnumFormTypedef; #define PTP_opd_GetSet 4U #define PTP_opd_FactoryDefaultValue 5U -typedef struct -{ +typedef struct { uint16_t ObjectPropertyCode; uint16_t DataType; uint8_t GetSet; @@ -812,15 +795,14 @@ typedef struct uint32_t GroupCode; uint8_t FormFlag; union { - PTP_PropDescEnumFormTypedef Enum; - PTP_PropDescRangeFormTypedef Range; + PTP_PropDescEnumFormTypedef Enum; + PTP_PropDescRangeFormTypedef Range; } FORM; } PTP_ObjectPropDescTypeDef; /* Metadata lists for MTP operations */ -typedef struct -{ +typedef struct { uint16_t property; uint16_t datatype; uint32_t ObjectHandle; @@ -854,8 +836,7 @@ MTP_PropertiesTypedef; /* Device Property Describing Dataset (DevicePropDesc) */ -typedef struct -{ +typedef struct { uint16_t DevicePropertyCode; uint16_t DataType; uint8_t GetSet; @@ -896,7 +877,7 @@ PTP_DevicePropDescTypdef; #define PTP_DTC_AINT128 (PTP_DTC_ARRAY_MASK | PTP_DTC_INT128) #define PTP_DTC_AUINT128 (PTP_DTC_ARRAY_MASK | PTP_DTC_UINT128) -#define PTP_DTC_STR 0xFFFFU +#define PTP_DTC_STR 0xFFFFU /* PTP Event Codes */ @@ -940,72 +921,72 @@ PTP_DevicePropDescTypdef; * @{ */ USBH_StatusTypeDef USBH_PTP_Init(USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_PTP_Process (USBH_HandleTypeDef *phost); - -USBH_StatusTypeDef USBH_PTP_SendRequest (USBH_HandleTypeDef *phost, PTP_ContainerTypedef *req); -USBH_StatusTypeDef USBH_PTP_GetResponse (USBH_HandleTypeDef *phost, PTP_ContainerTypedef *resp); +USBH_StatusTypeDef USBH_PTP_Process(USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_PTP_OpenSession (USBH_HandleTypeDef *phost, uint32_t session); -USBH_StatusTypeDef USBH_PTP_GetDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info); -USBH_StatusTypeDef USBH_PTP_GetStorageIds (USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *storage_ids); +USBH_StatusTypeDef USBH_PTP_SendRequest(USBH_HandleTypeDef *phost, PTP_ContainerTypedef *req); +USBH_StatusTypeDef USBH_PTP_GetResponse(USBH_HandleTypeDef *phost, PTP_ContainerTypedef *resp); -USBH_StatusTypeDef USBH_PTP_GetStorageInfo (USBH_HandleTypeDef *phost, - uint32_t storage_id, - PTP_StorageInfoTypedef *storage_info); +USBH_StatusTypeDef USBH_PTP_OpenSession(USBH_HandleTypeDef *phost, uint32_t session); +USBH_StatusTypeDef USBH_PTP_GetDeviceInfo(USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info); +USBH_StatusTypeDef USBH_PTP_GetStorageIds(USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *storage_ids); -USBH_StatusTypeDef USBH_PTP_GetNumObjects (USBH_HandleTypeDef *phost, +USBH_StatusTypeDef USBH_PTP_GetStorageInfo(USBH_HandleTypeDef *phost, uint32_t storage_id, - uint32_t objectformatcode, - uint32_t associationOH, - uint32_t* numobs); + PTP_StorageInfoTypedef *storage_info); -USBH_StatusTypeDef USBH_PTP_GetObjectHandles (USBH_HandleTypeDef *phost, - uint32_t storage_id, - uint32_t objectformatcode, - uint32_t associationOH, - PTP_ObjectHandlesTypedef* objecthandles); +USBH_StatusTypeDef USBH_PTP_GetNumObjects(USBH_HandleTypeDef *phost, + uint32_t storage_id, + uint32_t objectformatcode, + uint32_t associationOH, + uint32_t *numobs); -USBH_StatusTypeDef USBH_PTP_GetObjectInfo (USBH_HandleTypeDef *phost, - uint32_t handle, - PTP_ObjectInfoTypedef *object_info); +USBH_StatusTypeDef USBH_PTP_GetObjectHandles(USBH_HandleTypeDef *phost, + uint32_t storage_id, + uint32_t objectformatcode, + uint32_t associationOH, + PTP_ObjectHandlesTypedef *objecthandles); -USBH_StatusTypeDef USBH_PTP_DeleteObject (USBH_HandleTypeDef *phost, +USBH_StatusTypeDef USBH_PTP_GetObjectInfo(USBH_HandleTypeDef *phost, uint32_t handle, - uint32_t objectformatcode); + PTP_ObjectInfoTypedef *object_info); + +USBH_StatusTypeDef USBH_PTP_DeleteObject(USBH_HandleTypeDef *phost, + uint32_t handle, + uint32_t objectformatcode); -USBH_StatusTypeDef USBH_PTP_GetObject (USBH_HandleTypeDef *phost, - uint32_t handle, - uint8_t *object); +USBH_StatusTypeDef USBH_PTP_GetObject(USBH_HandleTypeDef *phost, + uint32_t handle, + uint8_t *object); USBH_StatusTypeDef USBH_PTP_GetPartialObject(USBH_HandleTypeDef *phost, - uint32_t handle, - uint32_t offset, - uint32_t maxbytes, uint8_t *object, - uint32_t *len); - -USBH_StatusTypeDef USBH_PTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost, - uint16_t ofc, - uint32_t *propnum, - uint16_t *props); - -USBH_StatusTypeDef USBH_PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost, - uint16_t opc, - uint16_t ofc, - PTP_ObjectPropDescTypeDef *opd); - -USBH_StatusTypeDef USBH_PTP_GetObjectPropList (USBH_HandleTypeDef *phost, - uint32_t handle, - MTP_PropertiesTypedef *pprops, - uint32_t *nrofprops); - -USBH_StatusTypeDef USBH_PTP_SendObject (USBH_HandleTypeDef *phost, - uint32_t handle, - uint8_t *object, - uint32_t size); - -USBH_StatusTypeDef USBH_PTP_GetDevicePropDesc (USBH_HandleTypeDef *phost, - uint16_t propcode, - PTP_DevicePropDescTypdef* devicepropertydesc); + uint32_t handle, + uint32_t offset, + uint32_t maxbytes, uint8_t *object, + uint32_t *len); + +USBH_StatusTypeDef USBH_PTP_GetObjectPropsSupported(USBH_HandleTypeDef *phost, + uint16_t ofc, + uint32_t *propnum, + uint16_t *props); + +USBH_StatusTypeDef USBH_PTP_GetObjectPropDesc(USBH_HandleTypeDef *phost, + uint16_t opc, + uint16_t ofc, + PTP_ObjectPropDescTypeDef *opd); + +USBH_StatusTypeDef USBH_PTP_GetObjectPropList(USBH_HandleTypeDef *phost, + uint32_t handle, + MTP_PropertiesTypedef *pprops, + uint32_t *nrofprops); + +USBH_StatusTypeDef USBH_PTP_SendObject(USBH_HandleTypeDef *phost, + uint32_t handle, + uint8_t *object, + uint32_t size); + +USBH_StatusTypeDef USBH_PTP_GetDevicePropDesc(USBH_HandleTypeDef *phost, + uint16_t propcode, + PTP_DevicePropDescTypdef *devicepropertydesc); /** * @} diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Src/usbh_mtp.c b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Src/usbh_mtp.c index ae73a53780..1ac7513211 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Src/usbh_mtp.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Src/usbh_mtp.c @@ -30,14 +30,14 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}_audio.c" - - "stm32xxxxx_{eval}{discovery}_sd.c" - - "stm32xxxxx_{eval}{discovery}_lcd.c" - - "stm32xxxxx_{eval}{discovery}_sdram.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}_audio.c" +- "stm32xxxxx_{eval}{discovery}_sd.c" +- "stm32xxxxx_{eval}{discovery}_lcd.c" +- "stm32xxxxx_{eval}{discovery}_sdram.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbh_mtp.h" @@ -95,13 +95,13 @@ * @{ */ -static USBH_StatusTypeDef USBH_MTP_InterfaceInit (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_MTP_InterfaceInit(USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_MTP_InterfaceDeInit (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_MTP_InterfaceDeInit(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef USBH_MTP_Process(USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_MTP_ClassRequest (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_MTP_ClassRequest(USBH_HandleTypeDef *phost); static uint8_t MTP_FindCtlEndpoint(USBH_HandleTypeDef *phost); @@ -109,14 +109,13 @@ static uint8_t MTP_FindDataOutEndpoint(USBH_HandleTypeDef *phost); static uint8_t MTP_FindDataInEndpoint(USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_MTP_SOFProcess (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_MTP_SOFProcess(USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_MTP_Events (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_MTP_Events(USBH_HandleTypeDef *phost); -static void MTP_DecodeEvent (USBH_HandleTypeDef *phost) ; +static void MTP_DecodeEvent(USBH_HandleTypeDef *phost) ; -USBH_ClassTypeDef MTP_Class = -{ +USBH_ClassTypeDef MTP_Class = { "MTP", USB_MTP_CLASS, USBH_MTP_InterfaceInit, @@ -141,7 +140,7 @@ USBH_ClassTypeDef MTP_Class = * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_MTP_InterfaceInit (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_MTP_InterfaceInit(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_OK; uint8_t interface, endpoint; @@ -150,24 +149,20 @@ static USBH_StatusTypeDef USBH_MTP_InterfaceInit (USBH_HandleTypeDef *phost) interface = USBH_FindInterface(phost, USB_MTP_CLASS, 1U, 1U); - if(interface == 0xFFU) /* No Valid Interface */ - { + if (interface == 0xFFU) { /* No Valid Interface */ status = USBH_FAIL; - USBH_DbgLog ("Cannot Find the interface for Still Image Class."); - } - else - { - USBH_SelectInterface (phost, interface); + USBH_DbgLog("Cannot Find the interface for Still Image Class."); + } else { + USBH_SelectInterface(phost, interface); endpoint = MTP_FindCtlEndpoint(phost); - phost->pActiveClass->pData = (MTP_HandleTypeDef *)USBH_malloc (sizeof(MTP_HandleTypeDef)); - MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + phost->pActiveClass->pData = (MTP_HandleTypeDef *)USBH_malloc(sizeof(MTP_HandleTypeDef)); + MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; - if( MTP_Handle == NULL) - { + if (MTP_Handle == NULL) { status = USBH_FAIL; - USBH_DbgLog ("Cannot allocate RAM for MTP Handle"); + USBH_DbgLog("Cannot allocate RAM for MTP Handle"); } /*Collect the control endpoint address and length*/ @@ -177,15 +172,15 @@ static USBH_StatusTypeDef USBH_MTP_InterfaceInit (USBH_HandleTypeDef *phost) MTP_Handle->events.poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bInterval; /* Open pipe for Notification endpoint */ - USBH_OpenPipe (phost, - MTP_Handle->NotificationPipe, - MTP_Handle->NotificationEp, - phost->device.address, - phost->device.speed, - USB_EP_TYPE_INTR, - MTP_Handle->NotificationEpSize); + USBH_OpenPipe(phost, + MTP_Handle->NotificationPipe, + MTP_Handle->NotificationEp, + phost->device.address, + phost->device.speed, + USB_EP_TYPE_INTR, + MTP_Handle->NotificationEpSize); - USBH_LL_SetToggle (phost, MTP_Handle->NotificationPipe, 0U); + USBH_LL_SetToggle(phost, MTP_Handle->NotificationPipe, 0U); endpoint = MTP_FindDataInEndpoint(phost); @@ -196,15 +191,15 @@ static USBH_StatusTypeDef USBH_MTP_InterfaceInit (USBH_HandleTypeDef *phost) MTP_Handle->DataInPipe = USBH_AllocPipe(phost, MTP_Handle->DataInEp); /* Open pipe for DATA IN endpoint */ - USBH_OpenPipe (phost, - MTP_Handle->DataInPipe, - MTP_Handle->DataInEp, - phost->device.address, - phost->device.speed, - USB_EP_TYPE_BULK, - MTP_Handle->DataInEpSize); + USBH_OpenPipe(phost, + MTP_Handle->DataInPipe, + MTP_Handle->DataInEp, + phost->device.address, + phost->device.speed, + USB_EP_TYPE_BULK, + MTP_Handle->DataInEpSize); - USBH_LL_SetToggle (phost, MTP_Handle->DataInPipe, 0U); + USBH_LL_SetToggle(phost, MTP_Handle->DataInPipe, 0U); endpoint = MTP_FindDataOutEndpoint(phost); @@ -214,21 +209,21 @@ static USBH_StatusTypeDef USBH_MTP_InterfaceInit (USBH_HandleTypeDef *phost) MTP_Handle->DataOutPipe = USBH_AllocPipe(phost, MTP_Handle->DataOutEp); /* Open pipe for DATA OUT endpoint */ - USBH_OpenPipe (phost, - MTP_Handle->DataOutPipe, - MTP_Handle->DataOutEp, - phost->device.address, - phost->device.speed, - USB_EP_TYPE_BULK, - MTP_Handle->DataOutEpSize); + USBH_OpenPipe(phost, + MTP_Handle->DataOutPipe, + MTP_Handle->DataOutEp, + phost->device.address, + phost->device.speed, + USB_EP_TYPE_BULK, + MTP_Handle->DataOutEpSize); - USBH_LL_SetToggle (phost, MTP_Handle->DataOutPipe, 0U); + USBH_LL_SetToggle(phost, MTP_Handle->DataOutPipe, 0U); - MTP_Handle->state = MTP_OPENSESSION; - MTP_Handle->is_ready = 0U; - MTP_Handle->events.state = MTP_EVENTS_INIT; - return USBH_PTP_Init(phost); + MTP_Handle->state = MTP_OPENSESSION; + MTP_Handle->is_ready = 0U; + MTP_Handle->events.state = MTP_EVENTS_INIT; + return USBH_PTP_Init(phost); } return status; @@ -243,16 +238,12 @@ static uint8_t MTP_FindCtlEndpoint(USBH_HandleTypeDef *phost) { uint8_t interface, endpoint; - for (interface = 0U; interface < USBH_MAX_NUM_INTERFACES ; interface ++ ) - { - if(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS) - { - for (endpoint = 0U; endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++ ) - { - if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80U)&& - (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0U)&& - ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_INTERRUPT) == USBH_EP_INTERRUPT)) - { + for (interface = 0U; interface < USBH_MAX_NUM_INTERFACES ; interface ++) { + if (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS) { + for (endpoint = 0U; endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++) { + if ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80U) && + (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0U) && + ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_INTERRUPT) == USBH_EP_INTERRUPT)) { return endpoint; } } @@ -272,17 +263,13 @@ static uint8_t MTP_FindDataOutEndpoint(USBH_HandleTypeDef *phost) { uint8_t interface, endpoint; - for (interface = 0U; interface < USBH_MAX_NUM_INTERFACES ; interface ++ ) - { - if(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS) - { - for (endpoint = 0U; endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++ ) - { - - if(((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80U) == 0U)&& - (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0U)&& - ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_BULK) == USBH_EP_BULK)) - { + for (interface = 0U; interface < USBH_MAX_NUM_INTERFACES ; interface ++) { + if (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS) { + for (endpoint = 0U; endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++) { + + if (((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80U) == 0U) && + (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0U) && + ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_BULK) == USBH_EP_BULK)) { return endpoint; } } @@ -301,17 +288,13 @@ static uint8_t MTP_FindDataInEndpoint(USBH_HandleTypeDef *phost) { uint8_t interface, endpoint; - for (interface = 0U; interface < USBH_MAX_NUM_INTERFACES ; interface ++ ) - { - if(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS) - { - for (endpoint = 0U; endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++ ) - { - - if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80U)&& - (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0U)&& - ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_BULK) == USBH_EP_BULK)) - { + for (interface = 0U; interface < USBH_MAX_NUM_INTERFACES ; interface ++) { + if (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS) { + for (endpoint = 0U; endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++) { + + if ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80U) && + (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0U) && + ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_BULK) == USBH_EP_BULK)) { return endpoint; } } @@ -328,34 +311,30 @@ static uint8_t MTP_FindDataInEndpoint(USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_MTP_InterfaceDeInit (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_MTP_InterfaceDeInit(USBH_HandleTypeDef *phost) { - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; - if (MTP_Handle->DataOutPipe) - { + if (MTP_Handle->DataOutPipe) { USBH_ClosePipe(phost, MTP_Handle->DataOutPipe); - USBH_FreePipe (phost, MTP_Handle->DataOutPipe); + USBH_FreePipe(phost, MTP_Handle->DataOutPipe); MTP_Handle->DataOutPipe = 0U; /* Reset the Channel as Free */ } - if (MTP_Handle->DataInPipe) - { + if (MTP_Handle->DataInPipe) { USBH_ClosePipe(phost, MTP_Handle->DataInPipe); - USBH_FreePipe (phost, MTP_Handle->DataInPipe); + USBH_FreePipe(phost, MTP_Handle->DataInPipe); MTP_Handle->DataInPipe = 0U; /* Reset the Channel as Free */ } - if (MTP_Handle->NotificationPipe) - { + if (MTP_Handle->NotificationPipe) { USBH_ClosePipe(phost, MTP_Handle->NotificationPipe); - USBH_FreePipe (phost, MTP_Handle->NotificationPipe); + USBH_FreePipe(phost, MTP_Handle->NotificationPipe); MTP_Handle->NotificationPipe = 0U; /* Reset the Channel as Free */ } - if(phost->pActiveClass->pData) - { - USBH_free (phost->pActiveClass->pData); + if (phost->pActiveClass->pData) { + USBH_free(phost->pActiveClass->pData); phost->pActiveClass->pData = 0U; } return USBH_OK; @@ -368,7 +347,7 @@ static USBH_StatusTypeDef USBH_MTP_InterfaceDeInit (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_MTP_ClassRequest (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_MTP_ClassRequest(USBH_HandleTypeDef *phost) { #if (USBH_USE_OS == 1U) phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; @@ -389,140 +368,133 @@ static USBH_StatusTypeDef USBH_MTP_ClassRequest (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_MTP_Process (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_MTP_Process(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint32_t idx = 0U; - switch(MTP_Handle->state) - { - case MTP_OPENSESSION: + switch (MTP_Handle->state) { + case MTP_OPENSESSION: - status = USBH_PTP_OpenSession (phost, 1U); /* Session '0' is not valid */ + status = USBH_PTP_OpenSession(phost, 1U); /* Session '0' is not valid */ - if(status == USBH_OK) - { - USBH_UsrLog("MTP Session #0 Opened"); - MTP_Handle->state = MTP_GETDEVICEINFO; + if (status == USBH_OK) { + USBH_UsrLog("MTP Session #0 Opened"); + MTP_Handle->state = MTP_GETDEVICEINFO; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; - - case MTP_GETDEVICEINFO: - status = USBH_PTP_GetDeviceInfo (phost, &(MTP_Handle->info.devinfo)); - - if(status == USBH_OK) - { - USBH_DbgLog(">>>>> MTP Device Information"); - USBH_DbgLog("Standard version : %x", MTP_Handle->info.devinfo.StandardVersion); - USBH_DbgLog("Vendor ExtID : %s", (MTP_Handle->info.devinfo.VendorExtensionID == 6)?"MTP": "NOT SUPPORTED"); - USBH_DbgLog("Functional mode : %s", (MTP_Handle->info.devinfo.FunctionalMode == 0U) ? "Standard" : "Vendor"); - USBH_DbgLog("Number of Supported Operation(s) : %d", MTP_Handle->info.devinfo.OperationsSupported_len); - USBH_DbgLog("Number of Supported Events(s) : %d", MTP_Handle->info.devinfo.EventsSupported_len); - USBH_DbgLog("Number of Supported Proprieties : %d", MTP_Handle->info.devinfo.DevicePropertiesSupported_len); - USBH_DbgLog("Manufacturer : %s", MTP_Handle->info.devinfo.Manufacturer); - USBH_DbgLog("Model : %s", MTP_Handle->info.devinfo.Model); - USBH_DbgLog("Device version : %s", MTP_Handle->info.devinfo.DeviceVersion); - USBH_DbgLog("Serial number : %s", MTP_Handle->info.devinfo.SerialNumber); - - MTP_Handle->state = MTP_GETSTORAGEIDS; + } + break; + + case MTP_GETDEVICEINFO: + status = USBH_PTP_GetDeviceInfo(phost, &(MTP_Handle->info.devinfo)); + + if (status == USBH_OK) { + USBH_DbgLog(">>>>> MTP Device Information"); + USBH_DbgLog("Standard version : %x", MTP_Handle->info.devinfo.StandardVersion); + USBH_DbgLog("Vendor ExtID : %s", (MTP_Handle->info.devinfo.VendorExtensionID == 6) ? "MTP" : "NOT SUPPORTED"); + USBH_DbgLog("Functional mode : %s", (MTP_Handle->info.devinfo.FunctionalMode == 0U) ? "Standard" : "Vendor"); + USBH_DbgLog("Number of Supported Operation(s) : %d", MTP_Handle->info.devinfo.OperationsSupported_len); + USBH_DbgLog("Number of Supported Events(s) : %d", MTP_Handle->info.devinfo.EventsSupported_len); + USBH_DbgLog("Number of Supported Proprieties : %d", MTP_Handle->info.devinfo.DevicePropertiesSupported_len); + USBH_DbgLog("Manufacturer : %s", MTP_Handle->info.devinfo.Manufacturer); + USBH_DbgLog("Model : %s", MTP_Handle->info.devinfo.Model); + USBH_DbgLog("Device version : %s", MTP_Handle->info.devinfo.DeviceVersion); + USBH_DbgLog("Serial number : %s", MTP_Handle->info.devinfo.SerialNumber); + + MTP_Handle->state = MTP_GETSTORAGEIDS; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; + } + break; - case MTP_GETSTORAGEIDS: - status = USBH_PTP_GetStorageIds (phost, &(MTP_Handle->info.storids)); + case MTP_GETSTORAGEIDS: + status = USBH_PTP_GetStorageIds(phost, &(MTP_Handle->info.storids)); - if(status == USBH_OK) - { - USBH_DbgLog("Number of storage ID items : %d", MTP_Handle->info.storids.n); - for (idx = 0U; idx < MTP_Handle->info.storids.n; idx ++) - { - USBH_DbgLog("storage#%d ID : %x", idx, MTP_Handle->info.storids.Storage[idx]); - } + if (status == USBH_OK) { + USBH_DbgLog("Number of storage ID items : %d", MTP_Handle->info.storids.n); + for (idx = 0U; idx < MTP_Handle->info.storids.n; idx ++) { + USBH_DbgLog("storage#%d ID : %x", idx, MTP_Handle->info.storids.Storage[idx]); + } - MTP_Handle->current_storage_unit = 0U; - MTP_Handle->state = MTP_GETSTORAGEINFO; + MTP_Handle->current_storage_unit = 0U; + MTP_Handle->state = MTP_GETSTORAGEINFO; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; - - case MTP_GETSTORAGEINFO: - status = USBH_PTP_GetStorageInfo (phost, - MTP_Handle->info.storids.Storage[MTP_Handle->current_storage_unit], - &((MTP_Handle->info.storinfo)[MTP_Handle->current_storage_unit])); - - if(status == USBH_OK) - { - USBH_UsrLog("Volume#%lu: %s [%s]", MTP_Handle->current_storage_unit, - MTP_Handle->info.storinfo[MTP_Handle->current_storage_unit].StorageDescription, - MTP_Handle->info.storinfo[MTP_Handle->current_storage_unit].VolumeLabel); - if(++MTP_Handle->current_storage_unit >= MTP_Handle->info.storids.n) - { - MTP_Handle->state = MTP_IDLE; - MTP_Handle->is_ready = 1U; - MTP_Handle->current_storage_unit = 0U; - MTP_Handle->params.CurrentStorageId = MTP_Handle->info.storids.Storage[0]; - - USBH_UsrLog( "MTP Class initialized."); - USBH_UsrLog("%s is default storage unit", MTP_Handle->info.storinfo[0].StorageDescription); - phost->pUser(phost, HOST_USER_CLASS_ACTIVE); } + break; + + case MTP_GETSTORAGEINFO: + status = USBH_PTP_GetStorageInfo(phost, + MTP_Handle->info.storids.Storage[MTP_Handle->current_storage_unit], + &((MTP_Handle->info.storinfo)[MTP_Handle->current_storage_unit])); + + if (status == USBH_OK) { + USBH_UsrLog("Volume#%lu: %s [%s]", MTP_Handle->current_storage_unit, + MTP_Handle->info.storinfo[MTP_Handle->current_storage_unit].StorageDescription, + MTP_Handle->info.storinfo[MTP_Handle->current_storage_unit].VolumeLabel); + if (++MTP_Handle->current_storage_unit >= MTP_Handle->info.storids.n) { + MTP_Handle->state = MTP_IDLE; + MTP_Handle->is_ready = 1U; + MTP_Handle->current_storage_unit = 0U; + MTP_Handle->params.CurrentStorageId = MTP_Handle->info.storids.Storage[0]; + + USBH_UsrLog("MTP Class initialized."); + USBH_UsrLog("%s is default storage unit", MTP_Handle->info.storinfo[0].StorageDescription); + phost->pUser(phost, HOST_USER_CLASS_ACTIVE); + } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; + } + break; - case MTP_IDLE: - USBH_MTP_Events(phost); + case MTP_IDLE: + USBH_MTP_Events(phost); #if (USBH_USE_OS == 1U) - osDelay(10U); - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + osDelay(10U); + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - status = USBH_OK; - break; + status = USBH_OK; + break; - default: - break; + default: + break; } return status; } @@ -533,7 +505,7 @@ static USBH_StatusTypeDef USBH_MTP_Process (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_MTP_SOFProcess (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_MTP_SOFProcess(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_OK; @@ -546,9 +518,9 @@ static USBH_StatusTypeDef USBH_MTP_SOFProcess (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -uint8_t USBH_MTP_IsReady (USBH_HandleTypeDef *phost) +uint8_t USBH_MTP_IsReady(USBH_HandleTypeDef *phost) { - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; return ((uint8_t)MTP_Handle->is_ready); } @@ -559,13 +531,12 @@ uint8_t USBH_MTP_IsReady (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_MTP_GetNumStorage (USBH_HandleTypeDef *phost, uint8_t *storage_num) +USBH_StatusTypeDef USBH_MTP_GetNumStorage(USBH_HandleTypeDef *phost, uint8_t *storage_num) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; - if(MTP_Handle->is_ready > 0U) - { + if (MTP_Handle->is_ready > 0U) { *storage_num = (uint8_t)MTP_Handle->info.storids.n; status = USBH_OK; } @@ -579,15 +550,14 @@ USBH_StatusTypeDef USBH_MTP_GetNumStorage (USBH_HandleTypeDef *phost, uint8_t *s * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_MTP_SelectStorage (USBH_HandleTypeDef *phost, uint8_t storage_idx) +USBH_StatusTypeDef USBH_MTP_SelectStorage(USBH_HandleTypeDef *phost, uint8_t storage_idx) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; - if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready)) - { - MTP_Handle->params.CurrentStorageId = MTP_Handle->info.storids.Storage[storage_idx]; - status = USBH_OK; + if ((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready)) { + MTP_Handle->params.CurrentStorageId = MTP_Handle->info.storids.Storage[storage_idx]; + status = USBH_OK; } return status; @@ -599,13 +569,12 @@ USBH_StatusTypeDef USBH_MTP_SelectStorage (USBH_HandleTypeDef *phost, uint8_t st * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_MTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint8_t storage_idx, MTP_StorageInfoTypedef *info) +USBH_StatusTypeDef USBH_MTP_GetStorageInfo(USBH_HandleTypeDef *phost, uint8_t storage_idx, MTP_StorageInfoTypedef *info) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; - if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready)) - { + if ((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready)) { *info = MTP_Handle->info.storinfo[storage_idx]; status = USBH_OK; } @@ -618,25 +587,22 @@ USBH_StatusTypeDef USBH_MTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint8_t s * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_MTP_GetNumObjects (USBH_HandleTypeDef *phost, - uint32_t storage_idx, - uint32_t objectformatcode, - uint32_t associationOH, - uint32_t* numobs) +USBH_StatusTypeDef USBH_MTP_GetNumObjects(USBH_HandleTypeDef *phost, + uint32_t storage_idx, + uint32_t objectformatcode, + uint32_t associationOH, + uint32_t *numobs) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint32_t timeout = phost->Timer; - if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready)) - { - while ((status = USBH_PTP_GetNumObjects (phost, - MTP_Handle->info.storids.Storage[storage_idx], - objectformatcode, - associationOH, - numobs)) == USBH_BUSY) - { - if(((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) - { + if ((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready)) { + while ((status = USBH_PTP_GetNumObjects(phost, + MTP_Handle->info.storids.Storage[storage_idx], + objectformatcode, + associationOH, + numobs)) == USBH_BUSY) { + if (((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) { return USBH_FAIL; } } @@ -651,26 +617,23 @@ USBH_StatusTypeDef USBH_MTP_GetNumObjects (USBH_HandleTypeDef *phost, * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_MTP_GetObjectHandles (USBH_HandleTypeDef *phost, - uint32_t storage_idx, - uint32_t objectformatcode, - uint32_t associationOH, - PTP_ObjectHandlesTypedef* objecthandles) +USBH_StatusTypeDef USBH_MTP_GetObjectHandles(USBH_HandleTypeDef *phost, + uint32_t storage_idx, + uint32_t objectformatcode, + uint32_t associationOH, + PTP_ObjectHandlesTypedef *objecthandles) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint32_t timeout = phost->Timer; - if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready)) - { - while ((status = USBH_PTP_GetObjectHandles (phost, - MTP_Handle->info.storids.Storage[storage_idx], - objectformatcode, - associationOH, - objecthandles)) == USBH_BUSY) - { - if(((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) - { + if ((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready)) { + while ((status = USBH_PTP_GetObjectHandles(phost, + MTP_Handle->info.storids.Storage[storage_idx], + objectformatcode, + associationOH, + objecthandles)) == USBH_BUSY) { + if (((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) { return USBH_FAIL; } } @@ -685,20 +648,17 @@ USBH_StatusTypeDef USBH_MTP_GetObjectHandles (USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_MTP_GetObjectInfo (USBH_HandleTypeDef *phost, - uint32_t handle, - PTP_ObjectInfoTypedef* objectinfo) +USBH_StatusTypeDef USBH_MTP_GetObjectInfo(USBH_HandleTypeDef *phost, + uint32_t handle, + PTP_ObjectInfoTypedef *objectinfo) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint32_t timeout = phost->Timer; - if(MTP_Handle->is_ready) - { - while ((status = USBH_PTP_GetObjectInfo (phost, handle, objectinfo)) == USBH_BUSY) - { - if(((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) - { + if (MTP_Handle->is_ready) { + while ((status = USBH_PTP_GetObjectInfo(phost, handle, objectinfo)) == USBH_BUSY) { + if (((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) { return USBH_FAIL; } } @@ -712,20 +672,17 @@ USBH_StatusTypeDef USBH_MTP_GetObjectInfo (USBH_HandleTypeDef *phost, * @param handle : Object Handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_MTP_DeleteObject (USBH_HandleTypeDef *phost, - uint32_t handle, - uint32_t objectformatcode) +USBH_StatusTypeDef USBH_MTP_DeleteObject(USBH_HandleTypeDef *phost, + uint32_t handle, + uint32_t objectformatcode) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint32_t timeout = phost->Timer; - if(MTP_Handle->is_ready) - { - while ((status = USBH_PTP_DeleteObject (phost, handle, objectformatcode)) == USBH_BUSY) - { - if(((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) - { + if (MTP_Handle->is_ready) { + while ((status = USBH_PTP_DeleteObject(phost, handle, objectformatcode)) == USBH_BUSY) { + if (((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) { return USBH_FAIL; } } @@ -740,20 +697,17 @@ USBH_StatusTypeDef USBH_MTP_DeleteObject (USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_MTP_GetObject (USBH_HandleTypeDef *phost, - uint32_t handle, - uint8_t *object) +USBH_StatusTypeDef USBH_MTP_GetObject(USBH_HandleTypeDef *phost, + uint32_t handle, + uint8_t *object) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint32_t timeout = phost->Timer; - if(MTP_Handle->is_ready) - { - while ((status = USBH_PTP_GetObject (phost, handle, object)) == USBH_BUSY) - { - if(((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) - { + if (MTP_Handle->is_ready) { + while ((status = USBH_PTP_GetObject(phost, handle, object)) == USBH_BUSY) { + if (((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) { return USBH_FAIL; } } @@ -769,27 +723,24 @@ USBH_StatusTypeDef USBH_MTP_GetObject (USBH_HandleTypeDef *phost, * @retval USBH Status */ USBH_StatusTypeDef USBH_MTP_GetPartialObject(USBH_HandleTypeDef *phost, - uint32_t handle, - uint32_t offset, - uint32_t maxbytes, - uint8_t *object, - uint32_t *len) + uint32_t handle, + uint32_t offset, + uint32_t maxbytes, + uint8_t *object, + uint32_t *len) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint32_t timeout = phost->Timer; - if(MTP_Handle->is_ready) - { + if (MTP_Handle->is_ready) { while ((status = USBH_PTP_GetPartialObject(phost, - handle, - offset, - maxbytes, - object, - len)) == USBH_BUSY) - { - if(((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) - { + handle, + offset, + maxbytes, + object, + len)) == USBH_BUSY) { + if (((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) { return USBH_FAIL; } } @@ -804,24 +755,21 @@ USBH_StatusTypeDef USBH_MTP_GetPartialObject(USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_MTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost, - uint16_t ofc, - uint32_t *propnum, - uint16_t *props) +USBH_StatusTypeDef USBH_MTP_GetObjectPropsSupported(USBH_HandleTypeDef *phost, + uint16_t ofc, + uint32_t *propnum, + uint16_t *props) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint32_t timeout = phost->Timer; - if(MTP_Handle->is_ready) - { - while ((status = USBH_PTP_GetObjectPropsSupported (phost, - ofc, - propnum, - props)) == USBH_BUSY) - { - if(((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) - { + if (MTP_Handle->is_ready) { + while ((status = USBH_PTP_GetObjectPropsSupported(phost, + ofc, + propnum, + props)) == USBH_BUSY) { + if (((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) { return USBH_FAIL; } } @@ -836,24 +784,21 @@ USBH_StatusTypeDef USBH_MTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_MTP_GetObjectPropDesc (USBH_HandleTypeDef *phost, - uint16_t opc, - uint16_t ofc, - PTP_ObjectPropDescTypeDef *opd) +USBH_StatusTypeDef USBH_MTP_GetObjectPropDesc(USBH_HandleTypeDef *phost, + uint16_t opc, + uint16_t ofc, + PTP_ObjectPropDescTypeDef *opd) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint32_t timeout = phost->Timer; - if(MTP_Handle->is_ready) - { - while ((status = USBH_PTP_GetObjectPropDesc (phost, + if (MTP_Handle->is_ready) { + while ((status = USBH_PTP_GetObjectPropDesc(phost, opc, ofc, - opd)) == USBH_BUSY) - { - if(((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) - { + opd)) == USBH_BUSY) { + if (((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) { return USBH_FAIL; } } @@ -868,24 +813,21 @@ USBH_StatusTypeDef USBH_MTP_GetObjectPropDesc (USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_MTP_GetObjectPropList (USBH_HandleTypeDef *phost, - uint32_t handle, - MTP_PropertiesTypedef *pprops, - uint32_t *nrofprops) +USBH_StatusTypeDef USBH_MTP_GetObjectPropList(USBH_HandleTypeDef *phost, + uint32_t handle, + MTP_PropertiesTypedef *pprops, + uint32_t *nrofprops) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint32_t timeout = phost->Timer; - if(MTP_Handle->is_ready) - { - while ((status = USBH_PTP_GetObjectPropList (phost, + if (MTP_Handle->is_ready) { + while ((status = USBH_PTP_GetObjectPropList(phost, handle, pprops, - nrofprops)) == USBH_BUSY) - { - if(((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) - { + nrofprops)) == USBH_BUSY) { + if (((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) { return USBH_FAIL; } } @@ -900,21 +842,18 @@ USBH_StatusTypeDef USBH_MTP_GetObjectPropList (USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_MTP_SendObject (USBH_HandleTypeDef *phost, - uint32_t handle, - uint8_t *object, - uint32_t size) +USBH_StatusTypeDef USBH_MTP_SendObject(USBH_HandleTypeDef *phost, + uint32_t handle, + uint8_t *object, + uint32_t size) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint32_t timeout = phost->Timer; - if(MTP_Handle->is_ready) - { - while ((status = USBH_PTP_SendObject (phost, handle, object, size)) == USBH_BUSY) - { - if(((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) - { + if (MTP_Handle->is_ready) { + while ((status = USBH_PTP_SendObject(phost, handle, object, size)) == USBH_BUSY) { + if (((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) { return USBH_FAIL; } } @@ -922,52 +861,48 @@ USBH_StatusTypeDef USBH_MTP_SendObject (USBH_HandleTypeDef *phost, return status; } - /** - * @brief Handle HID Control process - * @param phost: Host handle - * @retval USBH Status - */ -static USBH_StatusTypeDef USBH_MTP_Events (USBH_HandleTypeDef *phost) +/** + * @brief Handle HID Control process + * @param phost: Host handle + * @retval USBH Status + */ +static USBH_StatusTypeDef USBH_MTP_Events(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_BUSY ; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; - switch(MTP_Handle->events.state) - { - case MTP_EVENTS_INIT: - if((phost->Timer & 1U) == 0U) - { - MTP_Handle->events.timer = phost->Timer; - USBH_InterruptReceiveData(phost, - (uint8_t *)(void *)&(MTP_Handle->events.container), - (uint8_t)MTP_Handle->NotificationEpSize, - MTP_Handle->NotificationPipe); + switch (MTP_Handle->events.state) { + case MTP_EVENTS_INIT: + if ((phost->Timer & 1U) == 0U) { + MTP_Handle->events.timer = phost->Timer; + USBH_InterruptReceiveData(phost, + (uint8_t *)(void *) & (MTP_Handle->events.container), + (uint8_t)MTP_Handle->NotificationEpSize, + MTP_Handle->NotificationPipe); - MTP_Handle->events.state = MTP_EVENTS_GETDATA ; - } - break; - case MTP_EVENTS_GETDATA: - if(USBH_LL_GetURBState(phost , MTP_Handle->NotificationPipe) == USBH_URB_DONE) - { - MTP_DecodeEvent(phost); - } + MTP_Handle->events.state = MTP_EVENTS_GETDATA ; + } + break; + case MTP_EVENTS_GETDATA: + if (USBH_LL_GetURBState(phost, MTP_Handle->NotificationPipe) == USBH_URB_DONE) { + MTP_DecodeEvent(phost); + } - if(( phost->Timer - MTP_Handle->events.timer) >= MTP_Handle->events.poll) - { - MTP_Handle->events.timer = phost->Timer; + if ((phost->Timer - MTP_Handle->events.timer) >= MTP_Handle->events.poll) { + MTP_Handle->events.timer = phost->Timer; - USBH_InterruptReceiveData(phost, - (uint8_t *)(void *)&(MTP_Handle->events.container), - (uint8_t)MTP_Handle->NotificationEpSize, - MTP_Handle->NotificationPipe); + USBH_InterruptReceiveData(phost, + (uint8_t *)(void *) & (MTP_Handle->events.container), + (uint8_t)MTP_Handle->NotificationEpSize, + MTP_Handle->NotificationPipe); - } - break; + } + break; - default: - break; + default: + break; } return status; @@ -979,9 +914,9 @@ static USBH_StatusTypeDef USBH_MTP_Events (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval None */ -static void MTP_DecodeEvent (USBH_HandleTypeDef *phost) +static void MTP_DecodeEvent(USBH_HandleTypeDef *phost) { - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint16_t code; uint32_t param1; @@ -990,8 +925,7 @@ static void MTP_DecodeEvent (USBH_HandleTypeDef *phost) code = MTP_Handle->events.container.code; param1 = MTP_Handle->events.container.param1; - switch(code) - { + switch (code) { case PTP_EC_Undefined: USBH_DbgLog("EVT: PTP_EC_Undefined in session %u", MTP_Handle->ptp.session_id); break; @@ -1055,7 +989,7 @@ static void MTP_DecodeEvent (USBH_HandleTypeDef *phost) break; } - USBH_MTP_EventsCallback(phost, (uint32_t)code, param1); + USBH_MTP_EventsCallback(phost, (uint32_t)code, param1); } /** @@ -1065,21 +999,18 @@ static void MTP_DecodeEvent (USBH_HandleTypeDef *phost) * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_MTP_GetDevicePropDesc (USBH_HandleTypeDef *phost, - uint16_t propcode, - PTP_DevicePropDescTypdef* devicepropertydesc) +USBH_StatusTypeDef USBH_MTP_GetDevicePropDesc(USBH_HandleTypeDef *phost, + uint16_t propcode, + PTP_DevicePropDescTypdef *devicepropertydesc) { USBH_StatusTypeDef status = USBH_FAIL; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint32_t timeout = phost->Timer; - if(MTP_Handle->is_ready) - { - while ((status = USBH_PTP_GetDevicePropDesc (phost, propcode, devicepropertydesc)) == USBH_BUSY) - { - if(((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) - { + if (MTP_Handle->is_ready) { + while ((status = USBH_PTP_GetDevicePropDesc(phost, propcode, devicepropertydesc)) == USBH_BUSY) { + if (((phost->Timer - timeout) > 5000U) || (phost->device.is_connected == 0U)) { return USBH_FAIL; } } diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Src/usbh_mtp_ptp.c b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Src/usbh_mtp_ptp.c index 32b4c007d0..babbe61094 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Src/usbh_mtp_ptp.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Src/usbh_mtp_ptp.c @@ -17,14 +17,14 @@ ****************************************************************************** */ - /* BSPDependencies - - "stm32xxxxx_{eval}{discovery}.c" - - "stm32xxxxx_{eval}{discovery}_io.c" - - "stm32xxxxx_{eval}{discovery}_audio.c" - - "stm32xxxxx_{eval}{discovery}_sd.c" - - "stm32xxxxx_{eval}{discovery}_lcd.c" - - "stm32xxxxx_{eval}{discovery}_sdram.c" - EndBSPDependencies */ +/* BSPDependencies +- "stm32xxxxx_{eval}{discovery}.c" +- "stm32xxxxx_{eval}{discovery}_io.c" +- "stm32xxxxx_{eval}{discovery}_audio.c" +- "stm32xxxxx_{eval}{discovery}_sd.c" +- "stm32xxxxx_{eval}{discovery}_lcd.c" +- "stm32xxxxx_{eval}{discovery}_sdram.c" +EndBSPDependencies */ /* Includes ------------------------------------------------------------------*/ #include "usbh_mtp_ptp.h" @@ -81,27 +81,27 @@ /** @defgroup USBH_MTP_PTP_Private_FunctionPrototypes * @{ */ -static void PTP_DecodeDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info); -static void PTP_GetStorageIDs (USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *stor_ids); -static void PTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *stor_info); -static void PTP_GetObjectInfo (USBH_HandleTypeDef *phost, PTP_ObjectInfoTypedef *object_info); -static void PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost, PTP_ObjectPropDescTypeDef *opd, uint32_t opdlen); -static void PTP_DecodeDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info); +static void PTP_DecodeDeviceInfo(USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info); +static void PTP_GetStorageIDs(USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *stor_ids); +static void PTP_GetStorageInfo(USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *stor_info); +static void PTP_GetObjectInfo(USBH_HandleTypeDef *phost, PTP_ObjectInfoTypedef *object_info); +static void PTP_GetObjectPropDesc(USBH_HandleTypeDef *phost, PTP_ObjectPropDescTypeDef *opd, uint32_t opdlen); +static void PTP_DecodeDeviceInfo(USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info); static void PTP_GetDevicePropValue(USBH_HandleTypeDef *phost, uint32_t *offset, uint32_t total, - PTP_PropertyValueTypedef* value, + PTP_PropertyValueTypedef *value, uint16_t datatype); -static uint32_t PTP_GetObjectPropList (USBH_HandleTypeDef *phost, - MTP_PropertiesTypedef *props, - uint32_t len); +static uint32_t PTP_GetObjectPropList(USBH_HandleTypeDef *phost, + MTP_PropertiesTypedef *props, + uint32_t len); static void PTP_BufferFullCallback(USBH_HandleTypeDef *phost); -static void PTP_GetString(uint8_t *str, uint8_t* data, uint16_t *len); -static uint32_t PTP_GetArray16 (uint16_t *array, uint8_t *data, uint32_t offset); -static uint32_t PTP_GetArray32 (uint32_t *array, uint8_t *data, uint32_t offset); +static void PTP_GetString(uint8_t *str, uint8_t *data, uint16_t *len); +static uint32_t PTP_GetArray16(uint16_t *array, uint8_t *data, uint32_t offset); +static uint32_t PTP_GetArray32(uint32_t *array, uint8_t *data, uint32_t offset); /** * @} */ @@ -126,7 +126,7 @@ static uint32_t PTP_GetArray32 (uint32_t *array, uint8_t *data, uint32_t offset) */ USBH_StatusTypeDef USBH_PTP_Init(USBH_HandleTypeDef *phost) { - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; /* Set state to idle to be ready for operations */ MTP_Handle->ptp.state = PTP_IDLE; @@ -142,313 +142,268 @@ USBH_StatusTypeDef USBH_PTP_Init(USBH_HandleTypeDef *phost) * @param lun: Logical Unit Number * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_Process (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_PTP_Process(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_BUSY; USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; uint32_t len; - switch (MTP_Handle->ptp.state) - { - case PTP_IDLE: - /*Do Nothing */ - break; - - case PTP_OP_REQUEST_STATE: - USBH_BulkSendData (phost, - (uint8_t*)(void *)&(MTP_Handle->ptp.op_container), - (uint16_t)MTP_Handle->ptp.op_container.length, - MTP_Handle->DataOutPipe, - 1U); - MTP_Handle->ptp.state = PTP_OP_REQUEST_WAIT_STATE; - break; - - case PTP_OP_REQUEST_WAIT_STATE: - URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataOutPipe); - - if(URB_Status == USBH_URB_DONE) - { - if(MTP_Handle->ptp.flags == PTP_DP_NODATA) - { - MTP_Handle->ptp.state = PTP_RESPONSE_STATE; - } - else if(MTP_Handle->ptp.flags == PTP_DP_SENDDATA) - { - MTP_Handle->ptp.state = PTP_DATA_OUT_PHASE_STATE; - } - else if(MTP_Handle->ptp.flags == PTP_DP_GETDATA) - { - MTP_Handle->ptp.state = PTP_DATA_IN_PHASE_STATE; - } - else - { - } + switch (MTP_Handle->ptp.state) { + case PTP_IDLE: + /*Do Nothing */ + break; + + case PTP_OP_REQUEST_STATE: + USBH_BulkSendData(phost, + (uint8_t *)(void *) & (MTP_Handle->ptp.op_container), + (uint16_t)MTP_Handle->ptp.op_container.length, + MTP_Handle->DataOutPipe, + 1U); + MTP_Handle->ptp.state = PTP_OP_REQUEST_WAIT_STATE; + break; + + case PTP_OP_REQUEST_WAIT_STATE: + URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataOutPipe); + + if (URB_Status == USBH_URB_DONE) { + if (MTP_Handle->ptp.flags == PTP_DP_NODATA) { + MTP_Handle->ptp.state = PTP_RESPONSE_STATE; + } else if (MTP_Handle->ptp.flags == PTP_DP_SENDDATA) { + MTP_Handle->ptp.state = PTP_DATA_OUT_PHASE_STATE; + } else if (MTP_Handle->ptp.flags == PTP_DP_GETDATA) { + MTP_Handle->ptp.state = PTP_DATA_IN_PHASE_STATE; + } else { + } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else if(URB_Status == USBH_URB_NOTREADY) - { - /* Resend Request */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + } else if (URB_Status == USBH_URB_NOTREADY) { + /* Resend Request */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else if(URB_Status == USBH_URB_STALL) - { - MTP_Handle->ptp.state = PTP_ERROR; + } else if (URB_Status == USBH_URB_STALL) { + MTP_Handle->ptp.state = PTP_ERROR; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - } - break; + } else { + } + break; - case PTP_DATA_OUT_PHASE_STATE: + case PTP_DATA_OUT_PHASE_STATE: - USBH_BulkSendData (phost, - MTP_Handle->ptp.data_ptr, - MTP_Handle->DataOutEpSize , - MTP_Handle->DataOutPipe, - 1U); + USBH_BulkSendData(phost, + MTP_Handle->ptp.data_ptr, + MTP_Handle->DataOutEpSize, + MTP_Handle->DataOutPipe, + 1U); - MTP_Handle->ptp.state = PTP_DATA_OUT_PHASE_WAIT_STATE; - break; + MTP_Handle->ptp.state = PTP_DATA_OUT_PHASE_WAIT_STATE; + break; - case PTP_DATA_OUT_PHASE_WAIT_STATE: - URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataOutPipe); + case PTP_DATA_OUT_PHASE_WAIT_STATE: + URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataOutPipe); - if(URB_Status == USBH_URB_DONE) - { - /* Adjust Data pointer and data length */ - if(MTP_Handle->ptp.data_length > MTP_Handle->DataOutEpSize) - { - MTP_Handle->ptp.data_ptr += MTP_Handle->DataOutEpSize; - MTP_Handle->ptp.data_length -= MTP_Handle->DataOutEpSize; - MTP_Handle->ptp.data_packet += MTP_Handle->DataOutEpSize; + if (URB_Status == USBH_URB_DONE) { + /* Adjust Data pointer and data length */ + if (MTP_Handle->ptp.data_length > MTP_Handle->DataOutEpSize) { + MTP_Handle->ptp.data_ptr += MTP_Handle->DataOutEpSize; + MTP_Handle->ptp.data_length -= MTP_Handle->DataOutEpSize; + MTP_Handle->ptp.data_packet += MTP_Handle->DataOutEpSize; - if(MTP_Handle->ptp.data_packet >= PTP_USB_BULK_PAYLOAD_LEN_READ) - { - PTP_BufferFullCallback (phost); - MTP_Handle->ptp.data_packet = 0U; - MTP_Handle->ptp.iteration++; - } + if (MTP_Handle->ptp.data_packet >= PTP_USB_BULK_PAYLOAD_LEN_READ) { + PTP_BufferFullCallback(phost); + MTP_Handle->ptp.data_packet = 0U; + MTP_Handle->ptp.iteration++; + } - } - else - { - MTP_Handle->ptp.data_length = 0U; - } + } else { + MTP_Handle->ptp.data_length = 0U; + } - /* More Data To be Sent */ - if(MTP_Handle->ptp.data_length > 0U) - { - USBH_BulkSendData (phost, - MTP_Handle->ptp.data_ptr, - MTP_Handle->DataOutEpSize , - MTP_Handle->DataOutPipe, - 1U); - } - else - { - /* If value was 0, and successful transfer, then change the state */ - MTP_Handle->ptp.state = PTP_RESPONSE_STATE; - } + /* More Data To be Sent */ + if (MTP_Handle->ptp.data_length > 0U) { + USBH_BulkSendData(phost, + MTP_Handle->ptp.data_ptr, + MTP_Handle->DataOutEpSize, + MTP_Handle->DataOutPipe, + 1U); + } else { + /* If value was 0, and successful transfer, then change the state */ + MTP_Handle->ptp.state = PTP_RESPONSE_STATE; + } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } + } - else if(URB_Status == USBH_URB_NOTREADY) - { - /* Resend same data */ - MTP_Handle->ptp.state = PTP_DATA_OUT_PHASE_STATE; + else if (URB_Status == USBH_URB_NOTREADY) { + /* Resend same data */ + MTP_Handle->ptp.state = PTP_DATA_OUT_PHASE_STATE; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } + } - else if(URB_Status == USBH_URB_STALL) - { - MTP_Handle->ptp.state = PTP_ERROR; + else if (URB_Status == USBH_URB_STALL) { + MTP_Handle->ptp.state = PTP_ERROR; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - } - break; - - case PTP_DATA_IN_PHASE_STATE: - /* Send first packet */ - USBH_BulkReceiveData (phost, - MTP_Handle->ptp.data_ptr, - MTP_Handle->DataInEpSize, - MTP_Handle->DataInPipe); - - MTP_Handle->ptp.state = PTP_DATA_IN_PHASE_WAIT_STATE; - break; - - case PTP_DATA_IN_PHASE_WAIT_STATE: - URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataInPipe); - - if(URB_Status == USBH_URB_DONE) - { - len = USBH_LL_GetLastXferSize (phost, MTP_Handle->DataInPipe); - - if( MTP_Handle->ptp.data_packet_counter++ == 0U) - { - /* This is the first packet; so retrieve exact data length from payload */ - MTP_Handle->ptp.data_length = *(uint32_t*)(void *)(MTP_Handle->ptp.data_ptr); - MTP_Handle->ptp.iteration = 0U; + } else { } + break; + + case PTP_DATA_IN_PHASE_STATE: + /* Send first packet */ + USBH_BulkReceiveData(phost, + MTP_Handle->ptp.data_ptr, + MTP_Handle->DataInEpSize, + MTP_Handle->DataInPipe); - if((len >= MTP_Handle->DataInEpSize) && (MTP_Handle->ptp.data_length > 0U)) - { - MTP_Handle->ptp.data_ptr += len; - MTP_Handle->ptp.data_length -= len; - MTP_Handle->ptp.data_packet += len; - - if(MTP_Handle->ptp.data_packet >= PTP_USB_BULK_PAYLOAD_LEN_READ) - { - PTP_BufferFullCallback (phost); - MTP_Handle->ptp.data_packet = 0U; - MTP_Handle->ptp.iteration++; + MTP_Handle->ptp.state = PTP_DATA_IN_PHASE_WAIT_STATE; + break; + + case PTP_DATA_IN_PHASE_WAIT_STATE: + URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataInPipe); + + if (URB_Status == USBH_URB_DONE) { + len = USBH_LL_GetLastXferSize(phost, MTP_Handle->DataInPipe); + + if (MTP_Handle->ptp.data_packet_counter++ == 0U) { + /* This is the first packet; so retrieve exact data length from payload */ + MTP_Handle->ptp.data_length = *(uint32_t *)(void *)(MTP_Handle->ptp.data_ptr); + MTP_Handle->ptp.iteration = 0U; } - /* Continue receiving data*/ - USBH_BulkReceiveData (phost, - MTP_Handle->ptp.data_ptr, - MTP_Handle->DataInEpSize, - MTP_Handle->DataInPipe); - } - else - { - MTP_Handle->ptp.data_length -= len; - MTP_Handle->ptp.state = PTP_RESPONSE_STATE; + if ((len >= MTP_Handle->DataInEpSize) && (MTP_Handle->ptp.data_length > 0U)) { + MTP_Handle->ptp.data_ptr += len; + MTP_Handle->ptp.data_length -= len; + MTP_Handle->ptp.data_packet += len; + + if (MTP_Handle->ptp.data_packet >= PTP_USB_BULK_PAYLOAD_LEN_READ) { + PTP_BufferFullCallback(phost); + MTP_Handle->ptp.data_packet = 0U; + MTP_Handle->ptp.iteration++; + } + + /* Continue receiving data*/ + USBH_BulkReceiveData(phost, + MTP_Handle->ptp.data_ptr, + MTP_Handle->DataInEpSize, + MTP_Handle->DataInPipe); + } else { + MTP_Handle->ptp.data_length -= len; + MTP_Handle->ptp.state = PTP_RESPONSE_STATE; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - } - else if(URB_Status == USBH_URB_STALL) - { - MTP_Handle->ptp.state = PTP_ERROR; + } + } else if (URB_Status == USBH_URB_STALL) { + MTP_Handle->ptp.state = PTP_ERROR; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - } - break; - - case PTP_RESPONSE_STATE: - - USBH_BulkReceiveData (phost, - (uint8_t*)(void *)&(MTP_Handle->ptp.resp_container), - PTP_USB_BULK_REQ_RESP_MAX_LEN , - MTP_Handle->DataInPipe); - - MTP_Handle->ptp.state = PTP_RESPONSE_WAIT_STATE; - break; - - case PTP_RESPONSE_WAIT_STATE: - URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataInPipe); - - if(URB_Status == USBH_URB_DONE) - { - USBH_PTP_GetResponse (phost, &ptp_container); - - if(ptp_container.Code == PTP_RC_OK) - { - status = USBH_OK; - } - else - { - status = USBH_FAIL; - } - MTP_Handle->ptp.req_state = PTP_REQ_SEND; - } - else if(URB_Status == USBH_URB_STALL) - { - MTP_Handle->ptp.state = PTP_ERROR; + } else { + } + break; + + case PTP_RESPONSE_STATE: + + USBH_BulkReceiveData(phost, + (uint8_t *)(void *) & (MTP_Handle->ptp.resp_container), + PTP_USB_BULK_REQ_RESP_MAX_LEN, + MTP_Handle->DataInPipe); + + MTP_Handle->ptp.state = PTP_RESPONSE_WAIT_STATE; + break; + + case PTP_RESPONSE_WAIT_STATE: + URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataInPipe); + + if (URB_Status == USBH_URB_DONE) { + USBH_PTP_GetResponse(phost, &ptp_container); + + if (ptp_container.Code == PTP_RC_OK) { + status = USBH_OK; + } else { + status = USBH_FAIL; + } + MTP_Handle->ptp.req_state = PTP_REQ_SEND; + } else if (URB_Status == USBH_URB_STALL) { + MTP_Handle->ptp.state = PTP_ERROR; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_URB_EVENT; + phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - } - break; + } else { + } + break; - case PTP_ERROR: + case PTP_ERROR: MTP_Handle->ptp.req_state = PTP_REQ_SEND; break; - default: - break; + default: + break; } return status; } @@ -459,16 +414,16 @@ USBH_StatusTypeDef USBH_PTP_Process (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_SendRequest (USBH_HandleTypeDef *phost, PTP_ContainerTypedef *req) +USBH_StatusTypeDef USBH_PTP_SendRequest(USBH_HandleTypeDef *phost, PTP_ContainerTypedef *req) { USBH_StatusTypeDef status = USBH_OK; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; /* Clear PTP Data container*/ USBH_memset(&(MTP_Handle->ptp.op_container), 0, sizeof(PTP_OpContainerTypedef)); /* build appropriate USB container */ - MTP_Handle->ptp.op_container.length = PTP_USB_BULK_REQ_LEN- (sizeof(uint32_t) * (5U - req->Nparam)); + MTP_Handle->ptp.op_container.length = PTP_USB_BULK_REQ_LEN - (sizeof(uint32_t) * (5U - req->Nparam)); MTP_Handle->ptp.op_container.type = PTP_USB_CONTAINER_COMMAND; MTP_Handle->ptp.op_container.code = req->Code; MTP_Handle->ptp.op_container.trans_id = req->Transaction_ID; @@ -487,10 +442,10 @@ USBH_StatusTypeDef USBH_PTP_SendRequest (USBH_HandleTypeDef *phost, PTP_Containe * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_GetResponse (USBH_HandleTypeDef *phost, PTP_ContainerTypedef *resp) +USBH_StatusTypeDef USBH_PTP_GetResponse(USBH_HandleTypeDef *phost, PTP_ContainerTypedef *resp) { USBH_StatusTypeDef status = USBH_OK; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; /* build an appropriate PTPContainer */ resp->Code = MTP_Handle->ptp.resp_container.code; @@ -512,39 +467,36 @@ USBH_StatusTypeDef USBH_PTP_GetResponse (USBH_HandleTypeDef *phost, PTP_Containe */ static void PTP_BufferFullCallback(USBH_HandleTypeDef *phost) { - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + + switch (MTP_Handle->ptp.data_container.code) { + case PTP_OC_GetDeviceInfo: + PTP_DecodeDeviceInfo(phost, &(MTP_Handle->info.devinfo)); + break; - switch (MTP_Handle->ptp.data_container.code) - { - case PTP_OC_GetDeviceInfo: - PTP_DecodeDeviceInfo (phost, &(MTP_Handle->info.devinfo)); - break; + case PTP_OC_GetPartialObject: + case PTP_OC_GetObject: - case PTP_OC_GetPartialObject: - case PTP_OC_GetObject: + /* first packet is in the PTP data payload buffer */ + if (MTP_Handle->ptp.iteration == 0U) { + /* copy it to object */ + USBH_memcpy(MTP_Handle->ptp.object_ptr, MTP_Handle->ptp.data_container.payload.data, PTP_USB_BULK_PAYLOAD_LEN_READ); - /* first packet is in the PTP data payload buffer */ - if(MTP_Handle->ptp.iteration == 0U) - { - /* copy it to object */ - USBH_memcpy(MTP_Handle->ptp.object_ptr, MTP_Handle->ptp.data_container.payload.data, PTP_USB_BULK_PAYLOAD_LEN_READ); + /* next packet should be directly copied to object */ + MTP_Handle->ptp.data_ptr = (MTP_Handle->ptp.object_ptr + PTP_USB_BULK_PAYLOAD_LEN_READ); + } + break; - /* next packet should be directly copied to object */ - MTP_Handle->ptp.data_ptr = (MTP_Handle->ptp.object_ptr + PTP_USB_BULK_PAYLOAD_LEN_READ); - } - break; - - case PTP_OC_SendObject: - /* first packet is in the PTP data payload buffer */ - if(MTP_Handle->ptp.iteration == 0U) - { - /* next packet should be directly copied to object */ - MTP_Handle->ptp.data_ptr = (MTP_Handle->ptp.object_ptr + PTP_USB_BULK_PAYLOAD_LEN_READ); - } - break; + case PTP_OC_SendObject: + /* first packet is in the PTP data payload buffer */ + if (MTP_Handle->ptp.iteration == 0U) { + /* next packet should be directly copied to object */ + MTP_Handle->ptp.data_ptr = (MTP_Handle->ptp.object_ptr + PTP_USB_BULK_PAYLOAD_LEN_READ); + } + break; - default: - break; + default: + break; } @@ -557,62 +509,61 @@ static void PTP_BufferFullCallback(USBH_HandleTypeDef *phost) * @param dev_info: Device info structure * @retval None */ -static void PTP_DecodeDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info) +static void PTP_DecodeDeviceInfo(USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info) { - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint8_t *data = MTP_Handle->ptp.data_container.payload.data; uint32_t totallen; uint16_t len; /* Max device info is PTP_USB_BULK_HS_MAX_PACKET_LEN_READ */ - USBH_DbgLog (" MTP device info size exceeds internal buffer size.\ + USBH_DbgLog(" MTP device info size exceeds internal buffer size.\ only available data are decoded."); - if(MTP_Handle->ptp.iteration == 0U) - { + if (MTP_Handle->ptp.iteration == 0U) { dev_info->StandardVersion = LE16(&data[PTP_di_StandardVersion]); dev_info->VendorExtensionID = LE32(&data[PTP_di_VendorExtensionID]); dev_info->VendorExtensionVersion = LE16(&data[PTP_di_VendorExtensionVersion]); PTP_GetString(dev_info->VendorExtensionDesc, &data[PTP_di_VendorExtensionDesc], &len); totallen = len * 2U + 1U; - dev_info->FunctionalMode = LE16(&data[PTP_di_FunctionalMode+totallen]); - dev_info->OperationsSupported_len = PTP_GetArray16 ((uint16_t *)(void *)&dev_info->OperationsSupported, - data, - PTP_di_OperationsSupported+totallen); + dev_info->FunctionalMode = LE16(&data[PTP_di_FunctionalMode + totallen]); + dev_info->OperationsSupported_len = PTP_GetArray16((uint16_t *)(void *)&dev_info->OperationsSupported, + data, + PTP_di_OperationsSupported + totallen); - totallen=totallen+dev_info->OperationsSupported_len*sizeof(uint16_t)+sizeof(uint32_t); - dev_info->EventsSupported_len = PTP_GetArray16 ((uint16_t *)(void *)&dev_info->EventsSupported, - data, - PTP_di_OperationsSupported+totallen); + totallen = totallen + dev_info->OperationsSupported_len * sizeof(uint16_t) + sizeof(uint32_t); + dev_info->EventsSupported_len = PTP_GetArray16((uint16_t *)(void *)&dev_info->EventsSupported, + data, + PTP_di_OperationsSupported + totallen); - totallen=totallen+dev_info->EventsSupported_len*sizeof(uint16_t)+sizeof(uint32_t); - dev_info->DevicePropertiesSupported_len = PTP_GetArray16 ((uint16_t *)(void *)&dev_info->DevicePropertiesSupported, - data, - PTP_di_OperationsSupported+totallen); + totallen = totallen + dev_info->EventsSupported_len * sizeof(uint16_t) + sizeof(uint32_t); + dev_info->DevicePropertiesSupported_len = PTP_GetArray16((uint16_t *)(void *)&dev_info->DevicePropertiesSupported, + data, + PTP_di_OperationsSupported + totallen); - totallen=totallen+dev_info->DevicePropertiesSupported_len*sizeof(uint16_t)+sizeof(uint32_t); + totallen = totallen + dev_info->DevicePropertiesSupported_len * sizeof(uint16_t) + sizeof(uint32_t); - dev_info->CaptureFormats_len = PTP_GetArray16 ((uint16_t *)(void *)&dev_info->CaptureFormats, - data, - PTP_di_OperationsSupported+totallen); + dev_info->CaptureFormats_len = PTP_GetArray16((uint16_t *)(void *)&dev_info->CaptureFormats, + data, + PTP_di_OperationsSupported + totallen); - totallen=totallen+dev_info->CaptureFormats_len*sizeof(uint16_t)+sizeof(uint32_t); - dev_info->ImageFormats_len = PTP_GetArray16 ((uint16_t *)(void *)&dev_info->ImageFormats, - data, - PTP_di_OperationsSupported+totallen); + totallen = totallen + dev_info->CaptureFormats_len * sizeof(uint16_t) + sizeof(uint32_t); + dev_info->ImageFormats_len = PTP_GetArray16((uint16_t *)(void *)&dev_info->ImageFormats, + data, + PTP_di_OperationsSupported + totallen); - totallen=totallen+dev_info->ImageFormats_len*sizeof(uint16_t)+sizeof(uint32_t); - PTP_GetString(dev_info->Manufacturer, &data[PTP_di_OperationsSupported+totallen], &len); + totallen = totallen + dev_info->ImageFormats_len * sizeof(uint16_t) + sizeof(uint32_t); + PTP_GetString(dev_info->Manufacturer, &data[PTP_di_OperationsSupported + totallen], &len); totallen += len * 2U + 1U; - PTP_GetString(dev_info->Model, &data[PTP_di_OperationsSupported+totallen], &len); + PTP_GetString(dev_info->Model, &data[PTP_di_OperationsSupported + totallen], &len); totallen += len * 2U + 1U; - PTP_GetString(dev_info->DeviceVersion, &data[PTP_di_OperationsSupported+totallen], &len); + PTP_GetString(dev_info->DeviceVersion, &data[PTP_di_OperationsSupported + totallen], &len); totallen += len * 2U + 1U; - PTP_GetString(dev_info->SerialNumber, &data[PTP_di_OperationsSupported+totallen], &len); + PTP_GetString(dev_info->SerialNumber, &data[PTP_di_OperationsSupported + totallen], &len); } } @@ -623,12 +574,12 @@ static void PTP_DecodeDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTyped * @param stor_ids: Storage IDsstructure * @retval None */ -static void PTP_GetStorageIDs (USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *stor_ids) +static void PTP_GetStorageIDs(USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *stor_ids) { - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint8_t *data = MTP_Handle->ptp.data_container.payload.data; - stor_ids->n = PTP_GetArray32 (stor_ids->Storage, data, 0U); + stor_ids->n = PTP_GetArray32(stor_ids->Storage, data, 0U); } @@ -639,22 +590,22 @@ static void PTP_GetStorageIDs (USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef * @param stor_ids: Storage IDsstructure * @retval None */ -static void PTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *stor_info) +static void PTP_GetStorageInfo(USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *stor_info) { - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint8_t *data = MTP_Handle->ptp.data_container.payload.data; uint16_t len; - stor_info->StorageType=LE16(&data[PTP_si_StorageType]); - stor_info->FilesystemType=LE16(&data[PTP_si_FilesystemType]); - stor_info->AccessCapability=LE16(&data[PTP_si_AccessCapability]); - stor_info->MaxCapability=LE64(&data[PTP_si_MaxCapability]); - stor_info->FreeSpaceInBytes=LE64(&data[PTP_si_FreeSpaceInBytes]); - stor_info->FreeSpaceInImages=LE32(&data[PTP_si_FreeSpaceInImages]); + stor_info->StorageType = LE16(&data[PTP_si_StorageType]); + stor_info->FilesystemType = LE16(&data[PTP_si_FilesystemType]); + stor_info->AccessCapability = LE16(&data[PTP_si_AccessCapability]); + stor_info->MaxCapability = LE64(&data[PTP_si_MaxCapability]); + stor_info->FreeSpaceInBytes = LE64(&data[PTP_si_FreeSpaceInBytes]); + stor_info->FreeSpaceInImages = LE32(&data[PTP_si_FreeSpaceInImages]); PTP_GetString(stor_info->StorageDescription, &data[PTP_si_StorageDescription], &len); - PTP_GetString(stor_info->VolumeLabel, &data[PTP_si_StorageDescription+len * 2U + 1U], &len); + PTP_GetString(stor_info->VolumeLabel, &data[PTP_si_StorageDescription + len * 2U + 1U], &len); } /** @@ -664,9 +615,9 @@ static void PTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint32_t storage_id, * @param object_info: object info structure * @retval None */ -static void PTP_GetObjectInfo (USBH_HandleTypeDef *phost, PTP_ObjectInfoTypedef *object_info) +static void PTP_GetObjectInfo(USBH_HandleTypeDef *phost, PTP_ObjectInfoTypedef *object_info) { - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint8_t *data = MTP_Handle->ptp.data_container.payload.data; uint16_t filenamelen; @@ -676,21 +627,20 @@ static void PTP_GetObjectInfo (USBH_HandleTypeDef *phost, PTP_ObjectInfoTypedef object_info->ObjectCompressedSize = LE64(&data[PTP_oi_ObjectCompressedSize]); /* For Samsung Galaxy */ - if ((data[PTP_oi_filenamelen] == 0U) && (data[PTP_oi_filenamelen + 4U] != 0U)) - { + if ((data[PTP_oi_filenamelen] == 0U) && (data[PTP_oi_filenamelen + 4U] != 0U)) { data += 4; } - object_info->ThumbFormat=LE16(&data[PTP_oi_ThumbFormat]); - object_info->ThumbCompressedSize=LE32(&data[PTP_oi_ThumbCompressedSize]); - object_info->ThumbPixWidth=LE32(&data[PTP_oi_ThumbPixWidth]); - object_info->ThumbPixHeight=LE32(&data[PTP_oi_ThumbPixHeight]); - object_info->ImagePixWidth=LE32(&data[PTP_oi_ImagePixWidth]); - object_info->ImagePixHeight=LE32(&data[PTP_oi_ImagePixHeight]); - object_info->ImageBitDepth=LE32(&data[PTP_oi_ImageBitDepth]); - object_info->ParentObject=LE32(&data[PTP_oi_ParentObject]); - object_info->AssociationType=LE16(&data[PTP_oi_AssociationType]); - object_info->AssociationDesc=LE32(&data[PTP_oi_AssociationDesc]); - object_info->SequenceNumber=LE32(&data[PTP_oi_SequenceNumber]); + object_info->ThumbFormat = LE16(&data[PTP_oi_ThumbFormat]); + object_info->ThumbCompressedSize = LE32(&data[PTP_oi_ThumbCompressedSize]); + object_info->ThumbPixWidth = LE32(&data[PTP_oi_ThumbPixWidth]); + object_info->ThumbPixHeight = LE32(&data[PTP_oi_ThumbPixHeight]); + object_info->ImagePixWidth = LE32(&data[PTP_oi_ImagePixWidth]); + object_info->ImagePixHeight = LE32(&data[PTP_oi_ImagePixHeight]); + object_info->ImageBitDepth = LE32(&data[PTP_oi_ImageBitDepth]); + object_info->ParentObject = LE32(&data[PTP_oi_ParentObject]); + object_info->AssociationType = LE16(&data[PTP_oi_AssociationType]); + object_info->AssociationDesc = LE32(&data[PTP_oi_AssociationDesc]); + object_info->SequenceNumber = LE32(&data[PTP_oi_SequenceNumber]); PTP_GetString(object_info->Filename, &data[PTP_oi_filenamelen], &filenamelen); } @@ -702,45 +652,43 @@ static void PTP_GetObjectInfo (USBH_HandleTypeDef *phost, PTP_ObjectInfoTypedef * @param opd: object prop descriptor structure * @retval None */ -static void PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost, PTP_ObjectPropDescTypeDef *opd, uint32_t opdlen) +static void PTP_GetObjectPropDesc(USBH_HandleTypeDef *phost, PTP_ObjectPropDescTypeDef *opd, uint32_t opdlen) { - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint8_t *data = MTP_Handle->ptp.data_container.payload.data; uint32_t offset = 0U, i; - opd->ObjectPropertyCode=LE16(&data[PTP_opd_ObjectPropertyCode]); - opd->DataType=LE16(&data[PTP_opd_DataType]); - opd->GetSet=*(uint8_t *)(&data[PTP_opd_GetSet]); + opd->ObjectPropertyCode = LE16(&data[PTP_opd_ObjectPropertyCode]); + opd->DataType = LE16(&data[PTP_opd_DataType]); + opd->GetSet = *(uint8_t *)(&data[PTP_opd_GetSet]); offset = PTP_opd_FactoryDefaultValue; - PTP_GetDevicePropValue (phost, &offset, opdlen, &opd->FactoryDefaultValue, opd->DataType); + PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FactoryDefaultValue, opd->DataType); - opd->GroupCode=LE32(&data[offset]); - offset+=sizeof(uint32_t); + opd->GroupCode = LE32(&data[offset]); + offset += sizeof(uint32_t); - opd->FormFlag=*(uint8_t *)(&data[offset]); - offset+=sizeof(uint8_t); + opd->FormFlag = *(uint8_t *)(&data[offset]); + offset += sizeof(uint8_t); - switch (opd->FormFlag) - { - case PTP_OPFF_Range: - PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.MinimumValue, opd->DataType); - PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.MaximumValue, opd->DataType); - PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.StepSize, opd->DataType); - break; + switch (opd->FormFlag) { + case PTP_OPFF_Range: + PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.MinimumValue, opd->DataType); + PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.MaximumValue, opd->DataType); + PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.StepSize, opd->DataType); + break; - case PTP_OPFF_Enumeration: + case PTP_OPFF_Enumeration: - opd->FORM.Enum.NumberOfValues = LE16(&data[offset]); - offset+=sizeof(uint16_t); + opd->FORM.Enum.NumberOfValues = LE16(&data[offset]); + offset += sizeof(uint16_t); - for (i = 0U; i < opd->FORM.Enum.NumberOfValues ; i++) - { - PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Enum.SupportedValue[i], opd->DataType); - } - break; - default: - break; + for (i = 0U; i < opd->FORM.Enum.NumberOfValues ; i++) { + PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Enum.SupportedValue[i], opd->DataType); + } + break; + default: + break; } } @@ -754,61 +702,60 @@ static void PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost, PTP_ObjectPropDesc static void PTP_GetDevicePropValue(USBH_HandleTypeDef *phost, uint32_t *offset, uint32_t total, - PTP_PropertyValueTypedef* value, + PTP_PropertyValueTypedef *value, uint16_t datatype) { - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint8_t *data = MTP_Handle->ptp.data_container.payload.data; uint16_t len; - switch (datatype) - { - case PTP_DTC_INT8: - value->i8 = *(int8_t *)(void *)&(data[*offset]); - *offset += 1U; - break; - case PTP_DTC_UINT8: - value->u8 = *(uint8_t *)&(data[*offset]); - *offset += 1U; - break; - case PTP_DTC_INT16: - value->i16 = *(int16_t *)(void *)&(data[*offset]); - *offset += 2U; - break; - case PTP_DTC_UINT16: - value->u16 = LE16(&(data[*offset])); - *offset += 2U; - break; - case PTP_DTC_INT32: - value->i32 = *(int32_t *)(void *)(&(data[*offset])); - *offset += 4U; - break; - case PTP_DTC_UINT32: - value->u32 = LE32(&(data[*offset])); - *offset += 4U; - break; - case PTP_DTC_INT64: - value->i64 = *(int64_t *)(void *)(&(data[*offset])); - *offset += 8U; - break; - case PTP_DTC_UINT64: - value->u64 = LE64(&(data[*offset])); - *offset += 8U; - break; - - case PTP_DTC_UINT128: - *offset += 16U; - break; - case PTP_DTC_INT128: - *offset += 16U; - break; - - case PTP_DTC_STR: - - PTP_GetString((uint8_t *)(void *)value->str, (uint8_t *)&(data[*offset]), &len); - *offset += len * 2U + 1U; - break; - default: - break; + switch (datatype) { + case PTP_DTC_INT8: + value->i8 = *(int8_t *)(void *) & (data[*offset]); + *offset += 1U; + break; + case PTP_DTC_UINT8: + value->u8 = *(uint8_t *) & (data[*offset]); + *offset += 1U; + break; + case PTP_DTC_INT16: + value->i16 = *(int16_t *)(void *) & (data[*offset]); + *offset += 2U; + break; + case PTP_DTC_UINT16: + value->u16 = LE16(&(data[*offset])); + *offset += 2U; + break; + case PTP_DTC_INT32: + value->i32 = *(int32_t *)(void *)(&(data[*offset])); + *offset += 4U; + break; + case PTP_DTC_UINT32: + value->u32 = LE32(&(data[*offset])); + *offset += 4U; + break; + case PTP_DTC_INT64: + value->i64 = *(int64_t *)(void *)(&(data[*offset])); + *offset += 8U; + break; + case PTP_DTC_UINT64: + value->u64 = LE64(&(data[*offset])); + *offset += 8U; + break; + + case PTP_DTC_UINT128: + *offset += 16U; + break; + case PTP_DTC_INT128: + *offset += 16U; + break; + + case PTP_DTC_STR: + + PTP_GetString((uint8_t *)(void *)value->str, (uint8_t *) & (data[*offset]), &len); + *offset += len * 2U + 1U; + break; + default: + break; } } @@ -820,54 +767,51 @@ static void PTP_GetDevicePropValue(USBH_HandleTypeDef *phost, * @param opd: object prop descriptor structure * @retval None */ -static uint32_t PTP_GetObjectPropList (USBH_HandleTypeDef *phost, - MTP_PropertiesTypedef *props, - uint32_t len) +static uint32_t PTP_GetObjectPropList(USBH_HandleTypeDef *phost, + MTP_PropertiesTypedef *props, + uint32_t len) { - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; uint8_t *data = MTP_Handle->ptp.data_container.payload.data; uint32_t prop_count; uint32_t offset = 0U, i; - prop_count = LE32(data); + prop_count = LE32(data); - if (prop_count == 0U) - { - return 0U; - } + if (prop_count == 0U) { + return 0U; + } - data += sizeof(uint32_t); - len -= sizeof(uint32_t); + data += sizeof(uint32_t); + len -= sizeof(uint32_t); - for (i = 0U; i < prop_count; i++) - { - if (len <= 0U) - { - return 0U; - } + for (i = 0U; i < prop_count; i++) { + if (len <= 0U) { + return 0U; + } - props[i].ObjectHandle = LE32(data); - data += sizeof(uint32_t); - len -= sizeof(uint32_t); + props[i].ObjectHandle = LE32(data); + data += sizeof(uint32_t); + len -= sizeof(uint32_t); - props[i].property = LE16(data); - data += sizeof(uint16_t); - len -= sizeof(uint16_t); + props[i].property = LE16(data); + data += sizeof(uint16_t); + len -= sizeof(uint16_t); - props[i].datatype = LE16(data); - data += sizeof(uint16_t); - len -= sizeof(uint16_t); + props[i].datatype = LE16(data); + data += sizeof(uint16_t); + len -= sizeof(uint16_t); - offset = 0U; + offset = 0U; - PTP_GetDevicePropValue(phost, &offset, len, &props[i].propval, props[i].datatype); + PTP_GetDevicePropValue(phost, &offset, len, &props[i].propval, props[i].datatype); - data += offset; - len -= offset; - } + data += offset; + len -= offset; + } - return prop_count; + return prop_count; } /** @@ -877,7 +821,7 @@ static uint32_t PTP_GetObjectPropList (USBH_HandleTypeDef *phost, * @param data: Device info structure * @retval None */ -static void PTP_GetString (uint8_t *str, uint8_t* data, uint16_t *len) +static void PTP_GetString(uint8_t *str, uint8_t *data, uint16_t *len) { uint16_t strlength; uint16_t idx; @@ -886,8 +830,7 @@ static void PTP_GetString (uint8_t *str, uint8_t* data, uint16_t *len) strlength = (uint16_t)(2U * (uint32_t)data[0]); data ++; /* Adjust the offset ignoring the String Len */ - for (idx = 0U; idx < strlength; idx += 2U) - { + for (idx = 0U; idx < strlength; idx += 2U) { /* Copy Only the string and ignore the UNICODE ID, hence add the src */ *str = data[idx]; str++; @@ -903,14 +846,13 @@ static void PTP_GetString (uint8_t *str, uint8_t* data, uint16_t *len) * @retval None */ -static uint32_t PTP_GetArray16 (uint16_t *array, uint8_t *data, uint32_t offset) +static uint32_t PTP_GetArray16(uint16_t *array, uint8_t *data, uint32_t offset) { uint32_t size, idx = 0U; - size=LE32(&data[offset]); - while (size > idx) - { - array[idx] = (uint16_t)data[offset + (sizeof(uint16_t)*(idx + 2U))]; + size = LE32(&data[offset]); + while (size > idx) { + array[idx] = (uint16_t)data[offset + (sizeof(uint16_t) * (idx + 2U))]; idx++; } return size; @@ -924,14 +866,13 @@ static uint32_t PTP_GetArray16 (uint16_t *array, uint8_t *data, uint32_t offset) * @retval None */ -static uint32_t PTP_GetArray32 (uint32_t *array, uint8_t *data, uint32_t offset) +static uint32_t PTP_GetArray32(uint32_t *array, uint8_t *data, uint32_t offset) { uint32_t size, idx = 0U; size = LE32(&data[offset]); - while (size > idx) - { - array[idx] = LE32(&data[offset+(sizeof(uint32_t)*(idx+1U))]); + while (size > idx) { + array[idx] = LE32(&data[offset + (sizeof(uint32_t) * (idx + 1U))]); idx++; } return size; @@ -949,52 +890,51 @@ static uint32_t PTP_GetArray32 (uint32_t *array, uint8_t *data, uint32_t offset) * @param session: Session ID (MUST BE > 0U) * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_OpenSession (USBH_HandleTypeDef *phost, uint32_t session) +USBH_StatusTypeDef USBH_PTP_OpenSession(USBH_HandleTypeDef *phost, uint32_t session) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: - /* Init session params */ - MTP_Handle->ptp.transaction_id = 0x00000000U; - MTP_Handle->ptp.session_id = session; - MTP_Handle->ptp.flags = PTP_DP_NODATA; + /* Init session params */ + MTP_Handle->ptp.transaction_id = 0x00000000U; + MTP_Handle->ptp.session_id = session; + MTP_Handle->ptp.flags = PTP_DP_NODATA; - /* Fill operation request params */ - ptp_container.Code = PTP_OC_OpenSession; - ptp_container.SessionID = session; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Param1 = session; - ptp_container.Nparam = 1U; + /* Fill operation request params */ + ptp_container.Code = PTP_OC_OpenSession; + ptp_container.SessionID = session; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Param1 = session; + ptp_container.Nparam = 1U; - /* convert request packet inti USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); + /* convert request packet inti USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); - break; + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); + break; - default: - break; + default: + break; } return status; } @@ -1006,64 +946,62 @@ USBH_StatusTypeDef USBH_PTP_OpenSession (USBH_HandleTypeDef *phost, uint32_t ses * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_GetDevicePropDesc (USBH_HandleTypeDef *phost, - uint16_t propcode, - PTP_DevicePropDescTypdef* devicepropertydesc) +USBH_StatusTypeDef USBH_PTP_GetDevicePropDesc(USBH_HandleTypeDef *phost, + uint16_t propcode, + PTP_DevicePropDescTypdef *devicepropertydesc) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; uint8_t *data = MTP_Handle->ptp.data_container.payload.data; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: - - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_GETDATA; - MTP_Handle->ptp.data_ptr = (uint8_t *)(void *)&(MTP_Handle->ptp.data_container); - MTP_Handle->ptp.data_length = 0U; - MTP_Handle->ptp.data_packet_counter = 0U; - MTP_Handle->ptp.data_packet = 0U; - - /* Fill operation request params */ - ptp_container.Code = PTP_OC_GetDevicePropDesc; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Param1 = propcode; - ptp_container.Nparam = 1U; - - /* convert request packet into USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); - - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: + + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_GETDATA; + MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container); + MTP_Handle->ptp.data_length = 0U; + MTP_Handle->ptp.data_packet_counter = 0U; + MTP_Handle->ptp.data_packet = 0U; + + /* Fill operation request params */ + ptp_container.Code = PTP_OC_GetDevicePropDesc; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Param1 = propcode; + ptp_container.Nparam = 1U; + + /* convert request packet into USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); + + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); - if(status == USBH_OK) - { - devicepropertydesc->DevicePropertyCode = LE16(&data[PTP_dpd_DevicePropertyCode]); - devicepropertydesc->DataType = LE16(&data[PTP_dpd_DataType]); - devicepropertydesc->GetSet = *(uint8_t *)(&data[PTP_dpd_GetSet]); - devicepropertydesc->FormFlag = PTP_DPFF_None; - } - break; + if (status == USBH_OK) { + devicepropertydesc->DevicePropertyCode = LE16(&data[PTP_dpd_DevicePropertyCode]); + devicepropertydesc->DataType = LE16(&data[PTP_dpd_DataType]); + devicepropertydesc->GetSet = *(uint8_t *)(&data[PTP_dpd_GetSet]); + devicepropertydesc->FormFlag = PTP_DPFF_None; + } + break; - default: - break; + default: + break; } return status; } @@ -1074,58 +1012,56 @@ USBH_StatusTypeDef USBH_PTP_GetDevicePropDesc (USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_GetDeviceInfo (USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info) +USBH_StatusTypeDef USBH_PTP_GetDeviceInfo(USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_GETDATA; - MTP_Handle->ptp.data_ptr = (uint8_t *)(void *)&(MTP_Handle->ptp.data_container); - MTP_Handle->ptp.data_length = 0U; - MTP_Handle->ptp.data_packet_counter = 0U; - MTP_Handle->ptp.data_packet = 0U; + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_GETDATA; + MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container); + MTP_Handle->ptp.data_length = 0U; + MTP_Handle->ptp.data_packet_counter = 0U; + MTP_Handle->ptp.data_packet = 0U; - /* Fill operation request params */ - ptp_container.Code = PTP_OC_GetDeviceInfo; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Nparam = 0U; + /* Fill operation request params */ + ptp_container.Code = PTP_OC_GetDeviceInfo; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Nparam = 0U; - /* convert request packet inti USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); + /* convert request packet inti USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); - if(status == USBH_OK) - { - PTP_DecodeDeviceInfo (phost, dev_info); - } - break; + if (status == USBH_OK) { + PTP_DecodeDeviceInfo(phost, dev_info); + } + break; - default: - break; + default: + break; } return status; } @@ -1137,58 +1073,56 @@ USBH_StatusTypeDef USBH_PTP_GetDeviceInfo (USBH_HandleTypeDef *phost, PTP_Device * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_GetStorageIds (USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *storage_ids) +USBH_StatusTypeDef USBH_PTP_GetStorageIds(USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *storage_ids) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_GETDATA; - MTP_Handle->ptp.data_ptr = (uint8_t *)(void *)&(MTP_Handle->ptp.data_container); - MTP_Handle->ptp.data_length = 0U; - MTP_Handle->ptp.data_packet_counter = 0U; - MTP_Handle->ptp.data_packet = 0U; + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_GETDATA; + MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container); + MTP_Handle->ptp.data_length = 0U; + MTP_Handle->ptp.data_packet_counter = 0U; + MTP_Handle->ptp.data_packet = 0U; - /* Fill operation request params */ - ptp_container.Code = PTP_OC_GetStorageIDs; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Nparam = 0U; + /* Fill operation request params */ + ptp_container.Code = PTP_OC_GetStorageIDs; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Nparam = 0U; - /* convert request packet inti USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); + /* convert request packet inti USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); - if(status == USBH_OK) - { - PTP_GetStorageIDs (phost, storage_ids); - } - break; + if (status == USBH_OK) { + PTP_GetStorageIDs(phost, storage_ids); + } + break; - default: - break; + default: + break; } return status; } @@ -1200,59 +1134,57 @@ USBH_StatusTypeDef USBH_PTP_GetStorageIds (USBH_HandleTypeDef *phost, PTP_Storag * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *storage_info) +USBH_StatusTypeDef USBH_PTP_GetStorageInfo(USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *storage_info) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_GETDATA; - MTP_Handle->ptp.data_ptr = (uint8_t *)(void *)&(MTP_Handle->ptp.data_container); - MTP_Handle->ptp.data_length = 0U; - MTP_Handle->ptp.data_packet_counter = 0U; - MTP_Handle->ptp.data_packet = 0U; + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_GETDATA; + MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container); + MTP_Handle->ptp.data_length = 0U; + MTP_Handle->ptp.data_packet_counter = 0U; + MTP_Handle->ptp.data_packet = 0U; - /* Fill operation request params */ - ptp_container.Code = PTP_OC_GetStorageInfo; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Param1 = storage_id; - ptp_container.Nparam = 1U; + /* Fill operation request params */ + ptp_container.Code = PTP_OC_GetStorageInfo; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Param1 = storage_id; + ptp_container.Nparam = 1U; - /* convert request packet inti USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); + /* convert request packet inti USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); - if(status == USBH_OK) - { - PTP_GetStorageInfo (phost, storage_id, storage_info); - } - break; + if (status == USBH_OK) { + PTP_GetStorageInfo(phost, storage_id, storage_info); + } + break; - default: - break; + default: + break; } return status; } @@ -1264,61 +1196,59 @@ USBH_StatusTypeDef USBH_PTP_GetStorageInfo (USBH_HandleTypeDef *phost, uint32_t * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_GetNumObjects (USBH_HandleTypeDef *phost, - uint32_t storage_id, - uint32_t objectformatcode, - uint32_t associationOH, - uint32_t* numobs) +USBH_StatusTypeDef USBH_PTP_GetNumObjects(USBH_HandleTypeDef *phost, + uint32_t storage_id, + uint32_t objectformatcode, + uint32_t associationOH, + uint32_t *numobs) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_NODATA; + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_NODATA; - /* Fill operation request params */ - ptp_container.Code = PTP_OC_GetNumObjects; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Param1 = storage_id; - ptp_container.Param2 = objectformatcode; - ptp_container.Param3 = associationOH; - ptp_container.Nparam = 3U; + /* Fill operation request params */ + ptp_container.Code = PTP_OC_GetNumObjects; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Param1 = storage_id; + ptp_container.Param2 = objectformatcode; + ptp_container.Param3 = associationOH; + ptp_container.Nparam = 3U; - /* convert request packet into USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); + /* convert request packet into USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); - if(status == USBH_OK) - { - *numobs = MTP_Handle->ptp.resp_container.param1; - } - break; + if (status == USBH_OK) { + *numobs = MTP_Handle->ptp.resp_container.param1; + } + break; - default: - break; + default: + break; } return status; } @@ -1330,67 +1260,65 @@ USBH_StatusTypeDef USBH_PTP_GetNumObjects (USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_GetObjectHandles (USBH_HandleTypeDef *phost, - uint32_t storage_id, - uint32_t objectformatcode, - uint32_t associationOH, - PTP_ObjectHandlesTypedef* objecthandles) +USBH_StatusTypeDef USBH_PTP_GetObjectHandles(USBH_HandleTypeDef *phost, + uint32_t storage_id, + uint32_t objectformatcode, + uint32_t associationOH, + PTP_ObjectHandlesTypedef *objecthandles) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: - - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_GETDATA; - MTP_Handle->ptp.data_ptr = (uint8_t *)(void *)&(MTP_Handle->ptp.data_container); - MTP_Handle->ptp.data_length = 0U; - MTP_Handle->ptp.data_packet_counter = 0U; - MTP_Handle->ptp.data_packet = 0U; - - /* Fill operation request params */ - ptp_container.Code = PTP_OC_GetObjectHandles; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++; - ptp_container.Param1 = storage_id; - ptp_container.Param2 = objectformatcode; - ptp_container.Param3 = associationOH; - ptp_container.Nparam = 3U; - - /* convert request packet into USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); - - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: + + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_GETDATA; + MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container); + MTP_Handle->ptp.data_length = 0U; + MTP_Handle->ptp.data_packet_counter = 0U; + MTP_Handle->ptp.data_packet = 0U; + + /* Fill operation request params */ + ptp_container.Code = PTP_OC_GetObjectHandles; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++; + ptp_container.Param1 = storage_id; + ptp_container.Param2 = objectformatcode; + ptp_container.Param3 = associationOH; + ptp_container.Nparam = 3U; + + /* convert request packet into USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); + + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); - if(status == USBH_OK) - { - objecthandles->n = PTP_GetArray32 (objecthandles->Handler, + if (status == USBH_OK) { + objecthandles->n = PTP_GetArray32(objecthandles->Handler, MTP_Handle->ptp.data_container.payload.data, 0U); - } - break; + } + break; - default: - break; + default: + break; } return status; } @@ -1402,61 +1330,59 @@ USBH_StatusTypeDef USBH_PTP_GetObjectHandles (USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_GetObjectInfo (USBH_HandleTypeDef *phost, - uint32_t handle, - PTP_ObjectInfoTypedef* object_info) +USBH_StatusTypeDef USBH_PTP_GetObjectInfo(USBH_HandleTypeDef *phost, + uint32_t handle, + PTP_ObjectInfoTypedef *object_info) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_GETDATA; - MTP_Handle->ptp.data_ptr = (uint8_t *)(void *)&(MTP_Handle->ptp.data_container); - MTP_Handle->ptp.data_length = 0U; - MTP_Handle->ptp.data_packet_counter = 0U; - MTP_Handle->ptp.data_packet = 0U; + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_GETDATA; + MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container); + MTP_Handle->ptp.data_length = 0U; + MTP_Handle->ptp.data_packet_counter = 0U; + MTP_Handle->ptp.data_packet = 0U; - /* Fill operation request params */ - ptp_container.Code = PTP_OC_GetObjectInfo; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Param1 = handle; - ptp_container.Nparam = 1U; + /* Fill operation request params */ + ptp_container.Code = PTP_OC_GetObjectInfo; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Param1 = handle; + ptp_container.Nparam = 1U; - /* convert request packet into USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); + /* convert request packet into USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); - if(status == USBH_OK) - { - PTP_GetObjectInfo (phost, object_info); - } - break; + if (status == USBH_OK) { + PTP_GetObjectInfo(phost, object_info); + } + break; - default: - break; + default: + break; } return status; } @@ -1468,53 +1394,52 @@ USBH_StatusTypeDef USBH_PTP_GetObjectInfo (USBH_HandleTypeDef *phost, * @param handle : Object Handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_DeleteObject (USBH_HandleTypeDef *phost, - uint32_t handle, - uint32_t objectformatcode) +USBH_StatusTypeDef USBH_PTP_DeleteObject(USBH_HandleTypeDef *phost, + uint32_t handle, + uint32_t objectformatcode) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_NODATA; + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_NODATA; - /* Fill operation request params */ - ptp_container.Code = PTP_OC_DeleteObject; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Param1 = handle; - ptp_container.Param2 = objectformatcode; - ptp_container.Nparam = 2U; + /* Fill operation request params */ + ptp_container.Code = PTP_OC_DeleteObject; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Param1 = handle; + ptp_container.Param2 = objectformatcode; + ptp_container.Nparam = 2U; - /* convert request packet into USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); + /* convert request packet into USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); - break; + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); + break; - default: - break; + default: + break; } return status; } @@ -1526,70 +1451,67 @@ USBH_StatusTypeDef USBH_PTP_DeleteObject (USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_GetObject (USBH_HandleTypeDef *phost, - uint32_t handle, - uint8_t *object) +USBH_StatusTypeDef USBH_PTP_GetObject(USBH_HandleTypeDef *phost, + uint32_t handle, + uint8_t *object) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_GETDATA; - MTP_Handle->ptp.data_ptr = (uint8_t *)(void *)&(MTP_Handle->ptp.data_container); - MTP_Handle->ptp.data_length = 0U; - MTP_Handle->ptp.data_packet_counter = 0U; - MTP_Handle->ptp.data_packet = 0U; + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_GETDATA; + MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container); + MTP_Handle->ptp.data_length = 0U; + MTP_Handle->ptp.data_packet_counter = 0U; + MTP_Handle->ptp.data_packet = 0U; - /* set object control params */ - MTP_Handle->ptp.object_ptr = object; + /* set object control params */ + MTP_Handle->ptp.object_ptr = object; - /* Fill operation request params */ - ptp_container.Code = PTP_OC_GetObject; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Param1 = handle; - ptp_container.Nparam = 1U; + /* Fill operation request params */ + ptp_container.Code = PTP_OC_GetObject; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Param1 = handle; + ptp_container.Nparam = 1U; - /* convert request packet into USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); + /* convert request packet into USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); - if(status == USBH_OK) - { - /* first packet is in the PTP data payload buffer */ - if(MTP_Handle->ptp.iteration == 0U) - { - /* copy it to object */ - USBH_memcpy(MTP_Handle->ptp.object_ptr, MTP_Handle->ptp.data_container.payload.data, PTP_USB_BULK_PAYLOAD_LEN_READ); + if (status == USBH_OK) { + /* first packet is in the PTP data payload buffer */ + if (MTP_Handle->ptp.iteration == 0U) { + /* copy it to object */ + USBH_memcpy(MTP_Handle->ptp.object_ptr, MTP_Handle->ptp.data_container.payload.data, PTP_USB_BULK_PAYLOAD_LEN_READ); + } } - } - break; + break; - default: - break; + default: + break; } return status; } @@ -1602,74 +1524,71 @@ USBH_StatusTypeDef USBH_PTP_GetObject (USBH_HandleTypeDef *phost, * @retval USBH Status */ USBH_StatusTypeDef USBH_PTP_GetPartialObject(USBH_HandleTypeDef *phost, - uint32_t handle, - uint32_t offset, - uint32_t maxbytes, - uint8_t *object, - uint32_t *len) + uint32_t handle, + uint32_t offset, + uint32_t maxbytes, + uint8_t *object, + uint32_t *len) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: - - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_GETDATA; - MTP_Handle->ptp.data_ptr = (uint8_t *)(void *)&(MTP_Handle->ptp.data_container); - MTP_Handle->ptp.data_length = 0U; - MTP_Handle->ptp.data_packet_counter = 0U; - MTP_Handle->ptp.data_packet = 0U; - - /* set object control params */ - MTP_Handle->ptp.object_ptr = object; - - /* Fill operation request params */ - ptp_container.Code = PTP_OC_GetPartialObject; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Param1 = handle; - ptp_container.Param2 = offset; - ptp_container.Param3 = maxbytes; - ptp_container.Nparam = 3U; - - /* convert request packet into USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); - - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: + + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_GETDATA; + MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container); + MTP_Handle->ptp.data_length = 0U; + MTP_Handle->ptp.data_packet_counter = 0U; + MTP_Handle->ptp.data_packet = 0U; + + /* set object control params */ + MTP_Handle->ptp.object_ptr = object; + + /* Fill operation request params */ + ptp_container.Code = PTP_OC_GetPartialObject; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Param1 = handle; + ptp_container.Param2 = offset; + ptp_container.Param3 = maxbytes; + ptp_container.Nparam = 3U; + + /* convert request packet into USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); + + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); - if(status == USBH_OK) - { - *len = MTP_Handle->ptp.resp_container.param1; - /* first packet is in the PTP data payload buffer */ - if(MTP_Handle->ptp.iteration == 0U) - { - /* copy it to object */ - USBH_memcpy(MTP_Handle->ptp.object_ptr, MTP_Handle->ptp.data_container.payload.data, *len); + if (status == USBH_OK) { + *len = MTP_Handle->ptp.resp_container.param1; + /* first packet is in the PTP data payload buffer */ + if (MTP_Handle->ptp.iteration == 0U) { + /* copy it to object */ + USBH_memcpy(MTP_Handle->ptp.object_ptr, MTP_Handle->ptp.data_container.payload.data, *len); + } } - } - break; + break; - default: - break; + default: + break; } return status; } @@ -1681,62 +1600,60 @@ USBH_StatusTypeDef USBH_PTP_GetPartialObject(USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost, - uint16_t ofc, - uint32_t *propnum, - uint16_t *props) +USBH_StatusTypeDef USBH_PTP_GetObjectPropsSupported(USBH_HandleTypeDef *phost, + uint16_t ofc, + uint32_t *propnum, + uint16_t *props) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_GETDATA; - MTP_Handle->ptp.data_ptr = (uint8_t *)(void *)&(MTP_Handle->ptp.data_container); - MTP_Handle->ptp.data_length = 0U; - MTP_Handle->ptp.data_packet_counter = 0U; - MTP_Handle->ptp.data_packet = 0U; + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_GETDATA; + MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container); + MTP_Handle->ptp.data_length = 0U; + MTP_Handle->ptp.data_packet_counter = 0U; + MTP_Handle->ptp.data_packet = 0U; - /* Fill operation request params */ - ptp_container.Code = PTP_OC_GetObjectPropsSupported; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Param1 = ofc; - ptp_container.Nparam = 1U; + /* Fill operation request params */ + ptp_container.Code = PTP_OC_GetObjectPropsSupported; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Param1 = ofc; + ptp_container.Nparam = 1U; - /* convert request packet into USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); + /* convert request packet into USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); - if(status == USBH_OK) - { - *propnum = PTP_GetArray16 (props, MTP_Handle->ptp.data_container.payload.data, 0U); - } - break; + if (status == USBH_OK) { + *propnum = PTP_GetArray16(props, MTP_Handle->ptp.data_container.payload.data, 0U); + } + break; - default: - break; + default: + break; } return status; } @@ -1748,63 +1665,61 @@ USBH_StatusTypeDef USBH_PTP_GetObjectPropsSupported (USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost, - uint16_t opc, - uint16_t ofc, - PTP_ObjectPropDescTypeDef *opd) +USBH_StatusTypeDef USBH_PTP_GetObjectPropDesc(USBH_HandleTypeDef *phost, + uint16_t opc, + uint16_t ofc, + PTP_ObjectPropDescTypeDef *opd) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: - - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_GETDATA; - MTP_Handle->ptp.data_ptr = (uint8_t *)(void *)&(MTP_Handle->ptp.data_container); - MTP_Handle->ptp.data_length = 0U; - MTP_Handle->ptp.data_packet_counter = 0U; - MTP_Handle->ptp.data_packet = 0U; - - /* Fill operation request params */ - ptp_container.Code = PTP_OC_GetObjectPropDesc; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Param1 = opc; - ptp_container.Param2 = ofc; - ptp_container.Nparam = 2U; - - /* convert request packet into USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); - - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: + + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_GETDATA; + MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container); + MTP_Handle->ptp.data_length = 0U; + MTP_Handle->ptp.data_packet_counter = 0U; + MTP_Handle->ptp.data_packet = 0U; + + /* Fill operation request params */ + ptp_container.Code = PTP_OC_GetObjectPropDesc; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Param1 = opc; + ptp_container.Param2 = ofc; + ptp_container.Nparam = 2U; + + /* convert request packet into USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); + + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); - if(status == USBH_OK) - { - PTP_GetObjectPropDesc(phost, opd, MTP_Handle->ptp.data_length); - } - break; + if (status == USBH_OK) { + PTP_GetObjectPropDesc(phost, opd, MTP_Handle->ptp.data_length); + } + break; - default: - break; + default: + break; } return status; } @@ -1816,69 +1731,67 @@ USBH_StatusTypeDef USBH_PTP_GetObjectPropDesc (USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_GetObjectPropList (USBH_HandleTypeDef *phost, - uint32_t handle, - MTP_PropertiesTypedef *pprops, - uint32_t *nrofprops) +USBH_StatusTypeDef USBH_PTP_GetObjectPropList(USBH_HandleTypeDef *phost, + uint32_t handle, + MTP_PropertiesTypedef *pprops, + uint32_t *nrofprops) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: - - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_GETDATA; - MTP_Handle->ptp.data_ptr = (uint8_t *)(void *)&(MTP_Handle->ptp.data_container); - MTP_Handle->ptp.data_length = 0U; - MTP_Handle->ptp.data_packet_counter = 0U; - MTP_Handle->ptp.data_packet = 0U; - - /* copy first packet of the object into data container */ - USBH_memcpy(MTP_Handle->ptp.data_container.payload.data, MTP_Handle->ptp.object_ptr, PTP_USB_BULK_PAYLOAD_LEN_READ); - - /* Fill operation request params */ - ptp_container.Code = PTP_OC_GetObjPropList; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Param1 = handle; - ptp_container.Param2 = 0x00000000U; /* 0x00000000U should be "all formats" */ - ptp_container.Param3 = 0xFFFFFFFFU; /* 0xFFFFFFFFU should be "all properties" */ - ptp_container.Param4 = 0x00000000U; - ptp_container.Param5 = 0xFFFFFFFFU; /* Return full tree below the Param1 handle */ - ptp_container.Nparam = 5U; - - /* convert request packet into USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); - - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: + + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_GETDATA; + MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container); + MTP_Handle->ptp.data_length = 0U; + MTP_Handle->ptp.data_packet_counter = 0U; + MTP_Handle->ptp.data_packet = 0U; + + /* copy first packet of the object into data container */ + USBH_memcpy(MTP_Handle->ptp.data_container.payload.data, MTP_Handle->ptp.object_ptr, PTP_USB_BULK_PAYLOAD_LEN_READ); + + /* Fill operation request params */ + ptp_container.Code = PTP_OC_GetObjPropList; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Param1 = handle; + ptp_container.Param2 = 0x00000000U; /* 0x00000000U should be "all formats" */ + ptp_container.Param3 = 0xFFFFFFFFU; /* 0xFFFFFFFFU should be "all properties" */ + ptp_container.Param4 = 0x00000000U; + ptp_container.Param5 = 0xFFFFFFFFU; /* Return full tree below the Param1 handle */ + ptp_container.Nparam = 5U; + + /* convert request packet into USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); + + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); - if(status == USBH_OK) - { - PTP_GetObjectPropList (phost, pprops, MTP_Handle->ptp.data_length); - } - break; + if (status == USBH_OK) { + PTP_GetObjectPropList(phost, pprops, MTP_Handle->ptp.data_length); + } + break; - default: - break; + default: + break; } return status; } @@ -1890,61 +1803,60 @@ USBH_StatusTypeDef USBH_PTP_GetObjectPropList (USBH_HandleTypeDef *phost, * @param dev_info: Device info structure * @retval USBH Status */ -USBH_StatusTypeDef USBH_PTP_SendObject (USBH_HandleTypeDef *phost, - uint32_t handle, - uint8_t *object, - uint32_t size) +USBH_StatusTypeDef USBH_PTP_SendObject(USBH_HandleTypeDef *phost, + uint32_t handle, + uint8_t *object, + uint32_t size) { USBH_StatusTypeDef status = USBH_BUSY; - MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; + MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData; PTP_ContainerTypedef ptp_container; - switch(MTP_Handle->ptp.req_state) - { - case PTP_REQ_SEND: + switch (MTP_Handle->ptp.req_state) { + case PTP_REQ_SEND: - /* Set operation request type */ - MTP_Handle->ptp.flags = PTP_DP_SENDDATA; - MTP_Handle->ptp.data_ptr = (uint8_t *)(void *)&(MTP_Handle->ptp.data_container); - MTP_Handle->ptp.data_packet_counter = 0U; - MTP_Handle->ptp.data_packet = 0U; - MTP_Handle->ptp.iteration = 0U; + /* Set operation request type */ + MTP_Handle->ptp.flags = PTP_DP_SENDDATA; + MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container); + MTP_Handle->ptp.data_packet_counter = 0U; + MTP_Handle->ptp.data_packet = 0U; + MTP_Handle->ptp.iteration = 0U; - /* set object control params */ - MTP_Handle->ptp.object_ptr = object; - MTP_Handle->ptp.data_length = size; + /* set object control params */ + MTP_Handle->ptp.object_ptr = object; + MTP_Handle->ptp.data_length = size; - /* Fill operation request params */ - ptp_container.Code = PTP_OC_SendObject; - ptp_container.SessionID = MTP_Handle->ptp.session_id; - ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; - ptp_container.Nparam = 0U; + /* Fill operation request params */ + ptp_container.Code = PTP_OC_SendObject; + ptp_container.SessionID = MTP_Handle->ptp.session_id; + ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++; + ptp_container.Nparam = 0U; - /* convert request packet into USB raw packet*/ - USBH_PTP_SendRequest (phost, &ptp_container); + /* convert request packet into USB raw packet*/ + USBH_PTP_SendRequest(phost, &ptp_container); - /* Setup State machine and start transfer */ - MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; - MTP_Handle->ptp.req_state = PTP_REQ_WAIT; - status = USBH_BUSY; + /* Setup State machine and start transfer */ + MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE; + MTP_Handle->ptp.req_state = PTP_REQ_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case PTP_REQ_WAIT: - status = USBH_PTP_Process(phost); - break; + case PTP_REQ_WAIT: + status = USBH_PTP_Process(phost); + break; - default: - break; + default: + break; } return status; } diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/Template/Inc/usbh_template.h b/system/Middlewares/ST/STM32_USB_Host_Library/Class/Template/Inc/usbh_template.h index a5f53d0c4b..c496130ce7 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/Template/Inc/usbh_template.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/Template/Inc/usbh_template.h @@ -22,7 +22,7 @@ #define __USBH_TEMPLATE_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -90,8 +90,8 @@ extern USBH_ClassTypeDef TEMPLATE_Class; /** @defgroup USBH_TEMPLATE_CLASS_Exported_FunctionsPrototype * @{ */ -USBH_StatusTypeDef USBH_TEMPLATE_IOProcess (USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_TEMPLATE_Init (USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_TEMPLATE_IOProcess(USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_TEMPLATE_Init(USBH_HandleTypeDef *phost); /** * @} */ diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Class/Template/Src/usbh_template.c b/system/Middlewares/ST/STM32_USB_Host_Library/Class/Template/Src/usbh_template.c index 9ad0e6b3bd..9f73bca8da 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Class/Template/Src/usbh_template.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Class/Template/Src/usbh_template.c @@ -75,17 +75,16 @@ * @{ */ -static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceInit (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceInit(USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceDeInit (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceDeInit(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef USBH_TEMPLATE_Process(USBH_HandleTypeDef *phost); -static USBH_StatusTypeDef USBH_TEMPLATE_ClassRequest (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_TEMPLATE_ClassRequest(USBH_HandleTypeDef *phost); -USBH_ClassTypeDef TEMPLATE_Class = -{ +USBH_ClassTypeDef TEMPLATE_Class = { "TEMPLATE", USB_TEMPLATE_CLASS, USBH_TEMPLATE_InterfaceInit, @@ -108,7 +107,7 @@ USBH_ClassTypeDef TEMPLATE_Class = * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceInit (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceInit(USBH_HandleTypeDef *phost) { return USBH_OK; @@ -122,7 +121,7 @@ static USBH_StatusTypeDef USBH_TEMPLATE_InterfaceInit (USBH_HandleTypeDef *phost * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_TEMPLATE_InterfaceDeInit (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_TEMPLATE_InterfaceDeInit(USBH_HandleTypeDef *phost) { return USBH_OK; @@ -135,7 +134,7 @@ USBH_StatusTypeDef USBH_TEMPLATE_InterfaceDeInit (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_TEMPLATE_ClassRequest (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_TEMPLATE_ClassRequest(USBH_HandleTypeDef *phost) { return USBH_OK; @@ -148,7 +147,7 @@ static USBH_StatusTypeDef USBH_TEMPLATE_ClassRequest (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_TEMPLATE_Process (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_TEMPLATE_Process(USBH_HandleTypeDef *phost) { return USBH_OK; @@ -161,26 +160,22 @@ static USBH_StatusTypeDef USBH_TEMPLATE_Process (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_TEMPLATE_Init (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_TEMPLATE_Init(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef Status = USBH_BUSY; #if (USBH_USE_OS == 1U) osEvent event; - event = osMessageGet( phost->class_ready_event, osWaitForever ); + event = osMessageGet(phost->class_ready_event, osWaitForever); - if( event.status == osEventMessage ) - { - if(event.value.v == USBH_CLASS_EVENT) - { + if (event.status == osEventMessage) { + if (event.value.v == USBH_CLASS_EVENT) { #else - while ((Status == USBH_BUSY) || (Status == USBH_FAIL)) - { + while ((Status == USBH_BUSY) || (Status == USBH_FAIL)) { /* Host background process */ USBH_Process(phost); - if(phost->gState == HOST_CLASS) - { + if (phost->gState == HOST_CLASS) { #endif Status = USBH_OK; } @@ -194,12 +189,10 @@ USBH_StatusTypeDef USBH_TEMPLATE_Init (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_TEMPLATE_IOProcess (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_TEMPLATE_IOProcess(USBH_HandleTypeDef *phost) { - if (phost->device.is_connected == 1U) - { - if(phost->gState == HOST_CLASS) - { + if (phost->device.is_connected == 1U) { + if (phost->gState == HOST_CLASS) { USBH_TEMPLATE_Process(phost); } } diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_conf_template.h b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_conf_template.h index f1deac0e13..e48c5ba57f 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_conf_template.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_conf_template.h @@ -22,7 +22,7 @@ #define __USBH_CONF_TEMPLATE_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -58,7 +58,7 @@ * @{ */ - /* Memory management macros */ +/* Memory management macros */ #define USBH_malloc malloc #define USBH_free free #define USBH_memset memset diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h index ef1a8f9ec6..aff1dfd401 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h @@ -21,7 +21,7 @@ #define __USBH_CORE_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -92,78 +92,78 @@ USBH_StatusTypeDef USBH_DeInit(USBH_HandleTypeDef *phost); USBH_StatusTypeDef USBH_RegisterClass(USBH_HandleTypeDef *phost, USBH_ClassTypeDef *pclass); USBH_StatusTypeDef USBH_SelectInterface(USBH_HandleTypeDef *phost, uint8_t interface); uint8_t USBH_FindInterface(USBH_HandleTypeDef *phost, - uint8_t Class, - uint8_t SubClass, - uint8_t Protocol); + uint8_t Class, + uint8_t SubClass, + uint8_t Protocol); uint8_t USBH_GetActiveClass(USBH_HandleTypeDef *phost); uint8_t USBH_FindInterfaceIndex(USBH_HandleTypeDef *phost, uint8_t interface_number, uint8_t alt_settings); -uint8_t USBH_IsPortEnabled (USBH_HandleTypeDef *phost); +uint8_t USBH_IsPortEnabled(USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_Start (USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_Stop (USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_Process (USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_ReEnumerate (USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_Start(USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_Stop(USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_ReEnumerate(USBH_HandleTypeDef *phost); /* USBH Low Level Driver */ -USBH_StatusTypeDef USBH_LL_Init (USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_LL_DeInit (USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_LL_Start (USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_LL_Stop (USBH_HandleTypeDef *phost); - -USBH_StatusTypeDef USBH_LL_Connect (USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_LL_Disconnect (USBH_HandleTypeDef *phost); -USBH_SpeedTypeDef USBH_LL_GetSpeed (USBH_HandleTypeDef *phost); -USBH_StatusTypeDef USBH_LL_ResetPort (USBH_HandleTypeDef *phost); -uint32_t USBH_LL_GetLastXferSize (USBH_HandleTypeDef *phost, - uint8_t pipe); - -USBH_StatusTypeDef USBH_LL_DriverVBUS (USBH_HandleTypeDef *phost, - uint8_t state); - -USBH_StatusTypeDef USBH_LL_OpenPipe (USBH_HandleTypeDef *phost, - uint8_t pipe, - uint8_t epnum, - uint8_t dev_address, - uint8_t speed, - uint8_t ep_type, - uint16_t mps); - -USBH_StatusTypeDef USBH_LL_ClosePipe (USBH_HandleTypeDef *phost, - uint8_t pipe); - -USBH_StatusTypeDef USBH_LL_SubmitURB (USBH_HandleTypeDef *phost, - uint8_t pipe, - uint8_t direction, - uint8_t ep_type, - uint8_t token, - uint8_t* pbuff, - uint16_t length, - uint8_t do_ping); - -USBH_URBStateTypeDef USBH_LL_GetURBState (USBH_HandleTypeDef *phost, - uint8_t pipe); +USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_LL_DeInit(USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_LL_Start(USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_LL_Stop(USBH_HandleTypeDef *phost); + +USBH_StatusTypeDef USBH_LL_Connect(USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_LL_Disconnect(USBH_HandleTypeDef *phost); +USBH_SpeedTypeDef USBH_LL_GetSpeed(USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_LL_ResetPort(USBH_HandleTypeDef *phost); +uint32_t USBH_LL_GetLastXferSize(USBH_HandleTypeDef *phost, + uint8_t pipe); + +USBH_StatusTypeDef USBH_LL_DriverVBUS(USBH_HandleTypeDef *phost, + uint8_t state); + +USBH_StatusTypeDef USBH_LL_OpenPipe(USBH_HandleTypeDef *phost, + uint8_t pipe, + uint8_t epnum, + uint8_t dev_address, + uint8_t speed, + uint8_t ep_type, + uint16_t mps); + +USBH_StatusTypeDef USBH_LL_ClosePipe(USBH_HandleTypeDef *phost, + uint8_t pipe); + +USBH_StatusTypeDef USBH_LL_SubmitURB(USBH_HandleTypeDef *phost, + uint8_t pipe, + uint8_t direction, + uint8_t ep_type, + uint8_t token, + uint8_t *pbuff, + uint16_t length, + uint8_t do_ping); + +USBH_URBStateTypeDef USBH_LL_GetURBState(USBH_HandleTypeDef *phost, + uint8_t pipe); #if (USBH_USE_OS == 1U) -USBH_StatusTypeDef USBH_LL_NotifyURBChange (USBH_HandleTypeDef *phost); +USBH_StatusTypeDef USBH_LL_NotifyURBChange(USBH_HandleTypeDef *phost); #endif -USBH_StatusTypeDef USBH_LL_SetToggle (USBH_HandleTypeDef *phost, - uint8_t pipe, uint8_t toggle); +USBH_StatusTypeDef USBH_LL_SetToggle(USBH_HandleTypeDef *phost, + uint8_t pipe, uint8_t toggle); -uint8_t USBH_LL_GetToggle (USBH_HandleTypeDef *phost, uint8_t pipe); +uint8_t USBH_LL_GetToggle(USBH_HandleTypeDef *phost, uint8_t pipe); -void USBH_LL_PortDisabled (USBH_HandleTypeDef *phost); -void USBH_LL_PortEnabled (USBH_HandleTypeDef *phost); +void USBH_LL_PortDisabled(USBH_HandleTypeDef *phost); +void USBH_LL_PortEnabled(USBH_HandleTypeDef *phost); /* USBH Time base */ -void USBH_LL_SetTimer (USBH_HandleTypeDef *phost, uint32_t time); -void USBH_LL_IncTimer (USBH_HandleTypeDef *phost); +void USBH_LL_SetTimer(USBH_HandleTypeDef *phost, uint32_t time); +void USBH_LL_IncTimer(USBH_HandleTypeDef *phost); -void USBH_Delay (uint32_t Delay); +void USBH_Delay(uint32_t Delay); /** * @} diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_ctlreq.h b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_ctlreq.h index 3e98b69610..8d9814bec8 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_ctlreq.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_ctlreq.h @@ -22,7 +22,7 @@ #define __USBH_CTLREQ_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -86,34 +86,34 @@ extern uint8_t USBH_CfgDesc[512]; /** @defgroup USBH_CTLREQ_Exported_FunctionsPrototype * @{ */ -USBH_StatusTypeDef USBH_CtlReq (USBH_HandleTypeDef *phost, uint8_t *buff, - uint16_t length); +USBH_StatusTypeDef USBH_CtlReq(USBH_HandleTypeDef *phost, uint8_t *buff, + uint16_t length); -USBH_StatusTypeDef USBH_GetDescriptor (USBH_HandleTypeDef *phost, - uint8_t req_type, uint16_t value_idx, - uint8_t* buff, uint16_t length); +USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost, + uint8_t req_type, uint16_t value_idx, + uint8_t *buff, uint16_t length); -USBH_StatusTypeDef USBH_Get_DevDesc (USBH_HandleTypeDef *phost, uint8_t length); +USBH_StatusTypeDef USBH_Get_DevDesc(USBH_HandleTypeDef *phost, uint8_t length); -USBH_StatusTypeDef USBH_Get_StringDesc (USBH_HandleTypeDef *phost, - uint8_t string_index, uint8_t *buff, - uint16_t length); +USBH_StatusTypeDef USBH_Get_StringDesc(USBH_HandleTypeDef *phost, + uint8_t string_index, uint8_t *buff, + uint16_t length); -USBH_StatusTypeDef USBH_SetCfg (USBH_HandleTypeDef *phost, uint16_t cfg_idx); +USBH_StatusTypeDef USBH_SetCfg(USBH_HandleTypeDef *phost, uint16_t cfg_idx); -USBH_StatusTypeDef USBH_Get_CfgDesc (USBH_HandleTypeDef *phost,uint16_t length); +USBH_StatusTypeDef USBH_Get_CfgDesc(USBH_HandleTypeDef *phost, uint16_t length); -USBH_StatusTypeDef USBH_SetAddress (USBH_HandleTypeDef *phost, - uint8_t DeviceAddress); +USBH_StatusTypeDef USBH_SetAddress(USBH_HandleTypeDef *phost, + uint8_t DeviceAddress); -USBH_StatusTypeDef USBH_SetInterface (USBH_HandleTypeDef *phost, uint8_t ep_num, - uint8_t altSetting); +USBH_StatusTypeDef USBH_SetInterface(USBH_HandleTypeDef *phost, uint8_t ep_num, + uint8_t altSetting); -USBH_StatusTypeDef USBH_SetFeature (USBH_HandleTypeDef *phost, uint8_t wValue); +USBH_StatusTypeDef USBH_SetFeature(USBH_HandleTypeDef *phost, uint8_t wValue); -USBH_StatusTypeDef USBH_ClrFeature (USBH_HandleTypeDef *phost, uint8_t ep_num); +USBH_StatusTypeDef USBH_ClrFeature(USBH_HandleTypeDef *phost, uint8_t ep_num); -USBH_DescHeader_t *USBH_GetNextDesc (uint8_t *pbuf, uint16_t *ptr); +USBH_DescHeader_t *USBH_GetNextDesc(uint8_t *pbuf, uint16_t *ptr); /** * @} */ diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_def.h b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_def.h index b4f8f2d50b..42ba923133 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_def.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_def.h @@ -22,7 +22,7 @@ #define USBH_DEF_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -168,7 +168,7 @@ #define USB_EP_DIR_MSK 0x80U #ifndef USBH_MAX_PIPES_NBR - #define USBH_MAX_PIPES_NBR 15U +#define USBH_MAX_PIPES_NBR 15U #endif /* USBH_MAX_PIPES_NBR */ #define USBH_DEVICE_ADDRESS_DEFAULT 0x00U @@ -195,11 +195,9 @@ ConfigurationDescriptor.wTotalLength) -typedef union -{ +typedef union { uint16_t w; - struct BW - { + struct BW { uint8_t msb; uint8_t lsb; } @@ -208,12 +206,10 @@ typedef union uint16_t_uint8_t; -typedef union _USB_Setup -{ +typedef union _USB_Setup { uint32_t d8[2]; - struct _SetupPkt_Struc - { + struct _SetupPkt_Struc { uint8_t bmRequestType; uint8_t bRequest; uint16_t_uint8_t wValue; @@ -223,15 +219,13 @@ typedef union _USB_Setup } USB_Setup_TypeDef; -typedef struct _DescHeader -{ - uint8_t bLength; - uint8_t bDescriptorType; +typedef struct _DescHeader { + uint8_t bLength; + uint8_t bDescriptorType; } USBH_DescHeader_t; -typedef struct _DeviceDescriptor -{ +typedef struct _DeviceDescriptor { uint8_t bLength; uint8_t bDescriptorType; uint16_t bcdUSB; /* USB Specification Number which device complies too */ @@ -252,8 +246,7 @@ typedef struct _DeviceDescriptor } USBH_DevDescTypeDef; -typedef struct _EndpointDescriptor -{ +typedef struct _EndpointDescriptor { uint8_t bLength; uint8_t bDescriptorType; uint8_t bEndpointAddress; /* indicates what endpoint this descriptor is describing */ @@ -263,8 +256,7 @@ typedef struct _EndpointDescriptor } USBH_EpDescTypeDef; -typedef struct _InterfaceDescriptor -{ +typedef struct _InterfaceDescriptor { uint8_t bLength; uint8_t bDescriptorType; uint8_t bInterfaceNumber; @@ -279,8 +271,7 @@ typedef struct _InterfaceDescriptor USBH_InterfaceDescTypeDef; -typedef struct _ConfigurationDescriptor -{ +typedef struct _ConfigurationDescriptor { uint8_t bLength; uint8_t bDescriptorType; uint16_t wTotalLength; /* Total Length of Data Returned */ @@ -295,32 +286,29 @@ USBH_CfgDescTypeDef; /* Following USB Host status */ -typedef enum -{ +typedef enum { USBH_OK = 0, USBH_BUSY, USBH_FAIL, USBH_NOT_SUPPORTED, USBH_UNRECOVERED_ERROR, USBH_ERROR_SPEED_UNKNOWN, -}USBH_StatusTypeDef; +} USBH_StatusTypeDef; /** @defgroup USBH_CORE_Exported_Types * @{ */ -typedef enum -{ +typedef enum { USBH_SPEED_HIGH = 0U, USBH_SPEED_FULL = 1U, USBH_SPEED_LOW = 2U, -}USBH_SpeedTypeDef; +} USBH_SpeedTypeDef; /* Following states are used for gState */ -typedef enum -{ +typedef enum { HOST_IDLE = 0U, HOST_DEV_WAIT_FOR_ATTACHMENT, HOST_DEV_ATTACHED, @@ -335,11 +323,10 @@ typedef enum HOST_CLASS, HOST_SUSPENDED, HOST_ABORT_STATE, -}HOST_StateTypeDef; +} HOST_StateTypeDef; /* Following states are used for EnumerationState */ -typedef enum -{ +typedef enum { ENUM_IDLE = 0U, ENUM_GET_FULL_DEV_DESC, ENUM_SET_ADDR, @@ -351,8 +338,7 @@ typedef enum } ENUM_StateTypeDef; /* Following states are used for CtrlXferStateMachine */ -typedef enum -{ +typedef enum { CTRL_IDLE = 0U, CTRL_SETUP, CTRL_SETUP_WAIT, @@ -367,12 +353,11 @@ typedef enum CTRL_ERROR, CTRL_STALLED, CTRL_COMPLETE -}CTRL_StateTypeDef; +} CTRL_StateTypeDef; /* Following states are used for RequestState */ -typedef enum -{ +typedef enum { CMD_IDLE = 0U, CMD_SEND, CMD_WAIT @@ -385,10 +370,9 @@ typedef enum { USBH_URB_NYET, USBH_URB_ERROR, USBH_URB_STALL -}USBH_URBStateTypeDef; +} USBH_URBStateTypeDef; -typedef enum -{ +typedef enum { USBH_PORT_EVENT = 1U, USBH_URB_EVENT, USBH_CONTROL_EVENT, @@ -398,8 +382,7 @@ typedef enum USBH_OSEventTypeDef; /* Control request structure */ -typedef struct -{ +typedef struct { uint8_t pipe_in; uint8_t pipe_out; uint8_t pipe_size; @@ -413,8 +396,7 @@ typedef struct } USBH_CtrlTypeDef; /* Attached device structure */ -typedef struct -{ +typedef struct { #if (USBH_KEEP_CFG_DESCRIPTOR == 1U) uint8_t CfgDesc_Raw[USBH_MAX_SIZE_CONFIGURATION]; #endif @@ -427,39 +409,37 @@ typedef struct USBH_DevDescTypeDef DevDesc; USBH_CfgDescTypeDef CfgDesc; -}USBH_DeviceTypeDef; +} USBH_DeviceTypeDef; struct _USBH_HandleTypeDef; /* USB Host Class structure */ -typedef struct -{ +typedef struct { const char *Name; uint8_t ClassCode; - USBH_StatusTypeDef (*Init) (struct _USBH_HandleTypeDef *phost); - USBH_StatusTypeDef (*DeInit) (struct _USBH_HandleTypeDef *phost); - USBH_StatusTypeDef (*Requests) (struct _USBH_HandleTypeDef *phost); - USBH_StatusTypeDef (*BgndProcess) (struct _USBH_HandleTypeDef *phost); - USBH_StatusTypeDef (*SOFProcess) (struct _USBH_HandleTypeDef *phost); - void* pData; + USBH_StatusTypeDef(*Init)(struct _USBH_HandleTypeDef *phost); + USBH_StatusTypeDef(*DeInit)(struct _USBH_HandleTypeDef *phost); + USBH_StatusTypeDef(*Requests)(struct _USBH_HandleTypeDef *phost); + USBH_StatusTypeDef(*BgndProcess)(struct _USBH_HandleTypeDef *phost); + USBH_StatusTypeDef(*SOFProcess)(struct _USBH_HandleTypeDef *phost); + void *pData; } USBH_ClassTypeDef; /* USB Host handle structure */ -typedef struct _USBH_HandleTypeDef -{ +typedef struct _USBH_HandleTypeDef { __IO HOST_StateTypeDef gState; /* Host State Machine Value */ ENUM_StateTypeDef EnumState; /* Enumeration state Machine */ CMD_StateTypeDef RequestState; USBH_CtrlTypeDef Control; USBH_DeviceTypeDef device; - USBH_ClassTypeDef* pClass[USBH_MAX_NUM_SUPPORTED_CLASS]; - USBH_ClassTypeDef* pActiveClass; + USBH_ClassTypeDef *pClass[USBH_MAX_NUM_SUPPORTED_CLASS]; + USBH_ClassTypeDef *pActiveClass; uint32_t ClassNumber; uint32_t Pipes[15]; __IO uint32_t Timer; uint8_t id; - void* pData; - void (* pUser )(struct _USBH_HandleTypeDef *pHandle, uint8_t id); + void *pData; + void (* pUser)(struct _USBH_HandleTypeDef *pHandle, uint8_t id); #if (USBH_USE_OS == 1U) #if osCMSIS < 0x20000 @@ -476,12 +456,12 @@ typedef struct _USBH_HandleTypeDef #if defined ( __GNUC__ ) - #ifndef __weak - #define __weak __attribute__((weak)) - #endif /* __weak */ - #ifndef __packed - #define __packed __attribute__((__packed__)) - #endif /* __packed */ +#ifndef __weak +#define __weak __attribute__((weak)) +#endif /* __weak */ +#ifndef __packed +#define __packed __attribute__((__packed__)) +#endif /* __packed */ #endif /* __GNUC__ */ #ifdef __cplusplus diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_ioreq.h b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_ioreq.h index d0b2fc1fe2..1389d8c30e 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_ioreq.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_ioreq.h @@ -22,7 +22,7 @@ #define __USBH_IOREQ_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -86,53 +86,53 @@ /** @defgroup USBH_IOREQ_Exported_FunctionsPrototype * @{ */ -USBH_StatusTypeDef USBH_CtlSendSetup (USBH_HandleTypeDef *phost, - uint8_t *buff, - uint8_t pipe_num); +USBH_StatusTypeDef USBH_CtlSendSetup(USBH_HandleTypeDef *phost, + uint8_t *buff, + uint8_t pipe_num); -USBH_StatusTypeDef USBH_CtlSendData (USBH_HandleTypeDef *phost, - uint8_t *buff, - uint16_t length, - uint8_t pipe_num, - uint8_t do_ping); +USBH_StatusTypeDef USBH_CtlSendData(USBH_HandleTypeDef *phost, + uint8_t *buff, + uint16_t length, + uint8_t pipe_num, + uint8_t do_ping); USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost, - uint8_t *buff, - uint16_t length, - uint8_t pipe_num); + uint8_t *buff, + uint16_t length, + uint8_t pipe_num); USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost, - uint8_t *buff, - uint16_t length, - uint8_t pipe_num); + uint8_t *buff, + uint16_t length, + uint8_t pipe_num); -USBH_StatusTypeDef USBH_BulkSendData (USBH_HandleTypeDef *phost, - uint8_t *buff, - uint16_t length, - uint8_t pipe_num, - uint8_t do_ping ); +USBH_StatusTypeDef USBH_BulkSendData(USBH_HandleTypeDef *phost, + uint8_t *buff, + uint16_t length, + uint8_t pipe_num, + uint8_t do_ping); USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost, - uint8_t *buff, - uint8_t length, - uint8_t pipe_num); + uint8_t *buff, + uint8_t length, + uint8_t pipe_num); USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost, - uint8_t *buff, - uint8_t length, - uint8_t pipe_num); + uint8_t *buff, + uint8_t length, + uint8_t pipe_num); USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost, - uint8_t *buff, - uint32_t length, - uint8_t pipe_num); + uint8_t *buff, + uint32_t length, + uint8_t pipe_num); USBH_StatusTypeDef USBH_IsocSendData(USBH_HandleTypeDef *phost, - uint8_t *buff, - uint32_t length, - uint8_t pipe_num); + uint8_t *buff, + uint32_t length, + uint8_t pipe_num); /** * @} */ diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_pipes.h b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_pipes.h index 5d7cfd6288..73dd1b904b 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_pipes.h +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_pipes.h @@ -22,7 +22,7 @@ #define __USBH_PIPES_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -74,22 +74,22 @@ * @{ */ -USBH_StatusTypeDef USBH_OpenPipe (USBH_HandleTypeDef *phost, - uint8_t pipe_num, - uint8_t epnum, - uint8_t dev_address, - uint8_t speed, - uint8_t ep_type, - uint16_t mps); +USBH_StatusTypeDef USBH_OpenPipe(USBH_HandleTypeDef *phost, + uint8_t pipe_num, + uint8_t epnum, + uint8_t dev_address, + uint8_t speed, + uint8_t ep_type, + uint16_t mps); -USBH_StatusTypeDef USBH_ClosePipe (USBH_HandleTypeDef *phost, - uint8_t pipe_num); +USBH_StatusTypeDef USBH_ClosePipe(USBH_HandleTypeDef *phost, + uint8_t pipe_num); -uint8_t USBH_AllocPipe (USBH_HandleTypeDef *phost, - uint8_t ep_addr); +uint8_t USBH_AllocPipe(USBH_HandleTypeDef *phost, + uint8_t ep_addr); -USBH_StatusTypeDef USBH_FreePipe (USBH_HandleTypeDef *phost, - uint8_t idx); +USBH_StatusTypeDef USBH_FreePipe(USBH_HandleTypeDef *phost, + uint8_t idx); diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_conf_template.c b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_conf_template.c index 9f850f0919..fa8391b7b2 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_conf_template.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_conf_template.c @@ -26,7 +26,7 @@ * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_LL_Init (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef *phost) { return USBH_OK; @@ -38,7 +38,7 @@ USBH_StatusTypeDef USBH_LL_Init (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_LL_DeInit (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_LL_DeInit(USBH_HandleTypeDef *phost) { return USBH_OK; @@ -62,7 +62,7 @@ USBH_StatusTypeDef USBH_LL_Start(USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_LL_Stop (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_LL_Stop(USBH_HandleTypeDef *phost) { return USBH_OK; @@ -74,7 +74,7 @@ USBH_StatusTypeDef USBH_LL_Stop (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Speeds */ -USBH_SpeedTypeDef USBH_LL_GetSpeed (USBH_HandleTypeDef *phost) +USBH_SpeedTypeDef USBH_LL_GetSpeed(USBH_HandleTypeDef *phost) { USBH_SpeedTypeDef speed = USBH_SPEED_FULL; @@ -88,7 +88,7 @@ USBH_SpeedTypeDef USBH_LL_GetSpeed (USBH_HandleTypeDef *phost) * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_LL_ResetPort (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_LL_ResetPort(USBH_HandleTypeDef *phost) { return USBH_OK; @@ -101,9 +101,9 @@ USBH_StatusTypeDef USBH_LL_ResetPort (USBH_HandleTypeDef *phost) * @param pipe: Pipe index * @retval Packet Size */ -uint32_t USBH_LL_GetLastXferSize (USBH_HandleTypeDef *phost, uint8_t pipe) +uint32_t USBH_LL_GetLastXferSize(USBH_HandleTypeDef *phost, uint8_t pipe) { - return 0; + return 0; } /** @@ -118,7 +118,7 @@ uint32_t USBH_LL_GetLastXferSize (USBH_HandleTypeDef *phost, uint8_t pipe) * @param mps: Endpoint Max Packet Size * @retval USBH Status */ -USBH_StatusTypeDef USBH_LL_OpenPipe (USBH_HandleTypeDef *phost, +USBH_StatusTypeDef USBH_LL_OpenPipe(USBH_HandleTypeDef *phost, uint8_t pipe_num, uint8_t epnum, uint8_t dev_address, @@ -137,7 +137,7 @@ USBH_StatusTypeDef USBH_LL_OpenPipe (USBH_HandleTypeDef *phost, * @param pipe_num: Pipe index * @retval USBH Status */ -USBH_StatusTypeDef USBH_LL_ClosePipe (USBH_HandleTypeDef *phost, uint8_t pipe) +USBH_StatusTypeDef USBH_LL_ClosePipe(USBH_HandleTypeDef *phost, uint8_t pipe) { return USBH_OK; } @@ -171,14 +171,14 @@ USBH_StatusTypeDef USBH_LL_ClosePipe (USBH_HandleTypeDef *phost, uint8_t pip * @retval Status */ -USBH_StatusTypeDef USBH_LL_SubmitURB (USBH_HandleTypeDef *phost, - uint8_t pipe, - uint8_t direction , - uint8_t ep_type, - uint8_t token, - uint8_t* pbuff, - uint16_t length, - uint8_t do_ping ) +USBH_StatusTypeDef USBH_LL_SubmitURB(USBH_HandleTypeDef *phost, + uint8_t pipe, + uint8_t direction, + uint8_t ep_type, + uint8_t token, + uint8_t *pbuff, + uint16_t length, + uint8_t do_ping) { return USBH_OK; @@ -199,7 +199,7 @@ USBH_StatusTypeDef USBH_LL_SubmitURB (USBH_HandleTypeDef *phost, * @arg URB_ERROR * @arg URB_STALL */ -USBH_URBStateTypeDef USBH_LL_GetURBState (USBH_HandleTypeDef *phost, uint8_t pipe) +USBH_URBStateTypeDef USBH_LL_GetURBState(USBH_HandleTypeDef *phost, uint8_t pipe) { return USBH_URB_IDLE; } @@ -215,7 +215,7 @@ USBH_URBStateTypeDef USBH_LL_GetURBState (USBH_HandleTypeDef *phost, uint8_t pi * @retval Status */ -USBH_StatusTypeDef USBH_LL_DriverVBUS (USBH_HandleTypeDef *phost, uint8_t state) +USBH_StatusTypeDef USBH_LL_DriverVBUS(USBH_HandleTypeDef *phost, uint8_t state) { return USBH_OK; @@ -230,7 +230,7 @@ USBH_StatusTypeDef USBH_LL_DriverVBUS (USBH_HandleTypeDef *phost, uint8_t state * @param toggle: toggle (0/1) * @retval Status */ -USBH_StatusTypeDef USBH_LL_SetToggle (USBH_HandleTypeDef *phost, uint8_t pipe, uint8_t toggle) +USBH_StatusTypeDef USBH_LL_SetToggle(USBH_HandleTypeDef *phost, uint8_t pipe, uint8_t toggle) { return USBH_OK; @@ -243,7 +243,7 @@ USBH_StatusTypeDef USBH_LL_SetToggle (USBH_HandleTypeDef *phost, uint8_t pip * @param pipe: Pipe index * @retval toggle (0/1) */ -uint8_t USBH_LL_GetToggle (USBH_HandleTypeDef *phost, uint8_t pipe) +uint8_t USBH_LL_GetToggle(USBH_HandleTypeDef *phost, uint8_t pipe) { uint8_t toggle = 0; @@ -256,7 +256,7 @@ uint8_t USBH_LL_GetToggle (USBH_HandleTypeDef *phost, uint8_t pipe) * @param Delay: Delay in ms * @retval None */ -void USBH_Delay (uint32_t Delay) +void USBH_Delay(uint32_t Delay) { } diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c index 8465983a8c..e2e5185fe2 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c @@ -74,8 +74,8 @@ osThreadAttr_t USBH_Thread_Atrr; /** @defgroup USBH_CORE_Private_Functions * @{ */ -static USBH_StatusTypeDef USBH_HandleEnum (USBH_HandleTypeDef *phost); -static void USBH_HandleSof (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_HandleEnum(USBH_HandleTypeDef *phost); +static void USBH_HandleSof(USBH_HandleTypeDef *phost); static USBH_StatusTypeDef DeInitStateMachine(USBH_HandleTypeDef *phost); #if (USBH_USE_OS == 1U) @@ -96,8 +96,7 @@ static void USBH_Process_OS(void *argument); USBH_StatusTypeDef USBH_Init(USBH_HandleTypeDef *phost, void (*pUsrFunc)(USBH_HandleTypeDef *phost, uint8_t id), uint8_t id) { /* Check whether the USB Host handle is valid */ - if(phost == NULL) - { + if (phost == NULL) { USBH_ErrLog("Invalid Host handle"); return USBH_FAIL; } @@ -113,8 +112,7 @@ USBH_StatusTypeDef USBH_Init(USBH_HandleTypeDef *phost, void (*pUsrFunc)(USBH_H DeInitStateMachine(phost); /* Assign User process */ - if(pUsrFunc != NULL) - { + if (pUsrFunc != NULL) { phost->pUser = pUsrFunc; } @@ -123,7 +121,7 @@ USBH_StatusTypeDef USBH_Init(USBH_HandleTypeDef *phost, void (*pUsrFunc)(USBH_H /* Create USB Host Queue */ osMessageQDef(USBH_Queue, MSGQUEUE_OBJECTS, uint16_t); - phost->os_event = osMessageCreate (osMessageQ(USBH_Queue), NULL); + phost->os_event = osMessageCreate(osMessageQ(USBH_Queue), NULL); /* Create USB Host Task */ #if defined (USBH_PROCESS_STACK_SIZE) @@ -132,12 +130,12 @@ USBH_StatusTypeDef USBH_Init(USBH_HandleTypeDef *phost, void (*pUsrFunc)(USBH_H osThreadDef(USBH_Thread, USBH_Process_OS, USBH_PROCESS_PRIO, 0U, 8U * configMINIMAL_STACK_SIZE); #endif /* defined (USBH_PROCESS_STACK_SIZE) */ - phost->thread = osThreadCreate (osThread(USBH_Thread), phost); + phost->thread = osThreadCreate(osThread(USBH_Thread), phost); #else /* Create USB Host Queue */ - phost->os_event = osMessageQueueNew (MSGQUEUE_OBJECTS, sizeof(uint32_t), NULL); + phost->os_event = osMessageQueueNew(MSGQUEUE_OBJECTS, sizeof(uint32_t), NULL); /* Create USB Host Task */ USBH_Thread_Atrr.name = "USBH_Queue"; @@ -170,9 +168,8 @@ USBH_StatusTypeDef USBH_DeInit(USBH_HandleTypeDef *phost) { DeInitStateMachine(phost); - if(phost->pData != NULL) - { - USBH_free (phost->pActiveClass->pData); + if (phost->pData != NULL) { + USBH_free(phost->pActiveClass->pData); phost->pActiveClass->pData = NULL; USBH_LL_Stop(phost); } @@ -191,13 +188,11 @@ static USBH_StatusTypeDef DeInitStateMachine(USBH_HandleTypeDef *phost) uint32_t i = 0U; /* Clear Pipes flags*/ - for ( ; i < USBH_MAX_PIPES_NBR; i++) - { + for (; i < USBH_MAX_PIPES_NBR; i++) { phost->Pipes[i] = 0U; } - for(i = 0U; i< USBH_MAX_DATA_BUFFER; i++) - { + for (i = 0U; i < USBH_MAX_DATA_BUFFER; i++) { phost->device.Data[i] = 0U; } @@ -227,22 +222,16 @@ USBH_StatusTypeDef USBH_RegisterClass(USBH_HandleTypeDef *phost, USBH_ClassType { USBH_StatusTypeDef status = USBH_OK; - if(pclass != 0) - { - if(phost->ClassNumber < USBH_MAX_NUM_SUPPORTED_CLASS) - { + if (pclass != 0) { + if (phost->ClassNumber < USBH_MAX_NUM_SUPPORTED_CLASS) { /* link the class to the USB Host handle */ phost->pClass[phost->ClassNumber++] = pclass; status = USBH_OK; - } - else - { + } else { USBH_ErrLog("Max Class Number reached"); status = USBH_FAIL; } - } - else - { + } else { USBH_ErrLog("Invalid Class handle"); status = USBH_FAIL; } @@ -261,17 +250,14 @@ USBH_StatusTypeDef USBH_SelectInterface(USBH_HandleTypeDef *phost, uint8_t inter { USBH_StatusTypeDef status = USBH_OK; - if(interface < phost->device.CfgDesc.bNumInterfaces) - { + if (interface < phost->device.CfgDesc.bNumInterfaces) { phost->device.current_interface = interface; - USBH_UsrLog ("Switching to Interface (#%d)", interface); - USBH_UsrLog ("Class : %xh", phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass ); - USBH_UsrLog ("SubClass : %xh", phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass ); - USBH_UsrLog ("Protocol : %xh", phost->device.CfgDesc.Itf_Desc[interface].bInterfaceProtocol ); - } - else - { - USBH_ErrLog ("Cannot Select This Interface."); + USBH_UsrLog("Switching to Interface (#%d)", interface); + USBH_UsrLog("Class : %xh", phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass); + USBH_UsrLog("SubClass : %xh", phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass); + USBH_UsrLog("Protocol : %xh", phost->device.CfgDesc.Itf_Desc[interface].bInterfaceProtocol); + } else { + USBH_ErrLog("Cannot Select This Interface."); status = USBH_FAIL; } return status; @@ -286,7 +272,7 @@ USBH_StatusTypeDef USBH_SelectInterface(USBH_HandleTypeDef *phost, uint8_t inter */ uint8_t USBH_GetActiveClass(USBH_HandleTypeDef *phost) { - return (phost->device.CfgDesc.Itf_Desc[0].bInterfaceClass); + return (phost->device.CfgDesc.Itf_Desc[0].bInterfaceClass); } /** * @brief USBH_FindInterface @@ -307,13 +293,11 @@ uint8_t USBH_FindInterface(USBH_HandleTypeDef *phost, uint8_t Class, uint8_t Su pif = (USBH_InterfaceDescTypeDef *)0; pcfg = &phost->device.CfgDesc; - while (if_ix < USBH_MAX_NUM_INTERFACES) - { + while (if_ix < USBH_MAX_NUM_INTERFACES) { pif = &pcfg->Itf_Desc[if_ix]; - if(((pif->bInterfaceClass == Class) || (Class == 0xFFU))&& - ((pif->bInterfaceSubClass == SubClass) || (SubClass == 0xFFU))&& - ((pif->bInterfaceProtocol == Protocol) || (Protocol == 0xFFU))) - { + if (((pif->bInterfaceClass == Class) || (Class == 0xFFU)) && + ((pif->bInterfaceSubClass == SubClass) || (SubClass == 0xFFU)) && + ((pif->bInterfaceProtocol == Protocol) || (Protocol == 0xFFU))) { return if_ix; } if_ix++; @@ -339,11 +323,9 @@ uint8_t USBH_FindInterfaceIndex(USBH_HandleTypeDef *phost, uint8_t interface_nu pif = (USBH_InterfaceDescTypeDef *)0; pcfg = &phost->device.CfgDesc; - while (if_ix < USBH_MAX_NUM_INTERFACES) - { + while (if_ix < USBH_MAX_NUM_INTERFACES) { pif = &pcfg->Itf_Desc[if_ix]; - if((pif->bInterfaceNumber == interface_number) && (pif->bAlternateSetting == alt_settings)) - { + if ((pif->bInterfaceNumber == interface_number) && (pif->bAlternateSetting == alt_settings)) { return if_ix; } if_ix++; @@ -357,13 +339,13 @@ uint8_t USBH_FindInterfaceIndex(USBH_HandleTypeDef *phost, uint8_t interface_nu * @param phost: Host Handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_Start (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_Start(USBH_HandleTypeDef *phost) { /* Start the low level driver */ USBH_LL_Start(phost); /* Activate VBUS on the port */ - USBH_LL_DriverVBUS (phost, TRUE); + USBH_LL_DriverVBUS(phost, TRUE); return USBH_OK; } @@ -374,17 +356,17 @@ USBH_StatusTypeDef USBH_Start (USBH_HandleTypeDef *phost) * @param phost: Host Handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_Stop (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_Stop(USBH_HandleTypeDef *phost) { /* Stop and cleanup the low level driver */ USBH_LL_Stop(phost); /* DeActivate VBUS on the port */ - USBH_LL_DriverVBUS (phost, FALSE); + USBH_LL_DriverVBUS(phost, FALSE); /* FRee Control Pipes */ - USBH_FreePipe (phost, phost->Control.pipe_in); - USBH_FreePipe (phost, phost->Control.pipe_out); + USBH_FreePipe(phost, phost->Control.pipe_in); + USBH_FreePipe(phost, phost->Control.pipe_out); return USBH_OK; } @@ -433,274 +415,241 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost) uint8_t idx = 0U; /* check for Host port events */ - if (((USBH_IsPortEnabled(phost) == 0U)) && (phost->gState != HOST_IDLE)) - { - if(phost->gState != HOST_DEV_DISCONNECTED) - { + if (((USBH_IsPortEnabled(phost) == 0U)) && (phost->gState != HOST_IDLE)) { + if (phost->gState != HOST_DEV_DISCONNECTED) { phost->gState = HOST_DEV_DISCONNECTED; } } - switch (phost->gState) - { - case HOST_IDLE : + switch (phost->gState) { + case HOST_IDLE : - if (phost->device.is_connected) - { - /* Wait for 200 ms after connection */ - phost->gState = HOST_DEV_WAIT_FOR_ATTACHMENT; - USBH_Delay(200U); - USBH_LL_ResetPort(phost); + if (phost->device.is_connected) { + /* Wait for 200 ms after connection */ + phost->gState = HOST_DEV_WAIT_FOR_ATTACHMENT; + USBH_Delay(200U); + USBH_LL_ResetPort(phost); #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_PORT_EVENT; + phost->os_msg = (uint32_t)USBH_PORT_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; + } + break; - case HOST_DEV_WAIT_FOR_ATTACHMENT: /* Wait for Port Eabled */ + case HOST_DEV_WAIT_FOR_ATTACHMENT: /* Wait for Port Eabled */ - if (phost->device.PortEnabled == 1U) - { - phost->gState = HOST_DEV_ATTACHED; - } - break; + if (phost->device.PortEnabled == 1U) { + phost->gState = HOST_DEV_ATTACHED; + } + break; - case HOST_DEV_ATTACHED : + case HOST_DEV_ATTACHED : - USBH_UsrLog("USB Device Attached"); + USBH_UsrLog("USB Device Attached"); - /* Wait for 100 ms after Reset */ - USBH_Delay(100U); + /* Wait for 100 ms after Reset */ + USBH_Delay(100U); - phost->device.speed = USBH_LL_GetSpeed(phost); + phost->device.speed = USBH_LL_GetSpeed(phost); - phost->gState = HOST_ENUMERATION; + phost->gState = HOST_ENUMERATION; - phost->Control.pipe_out = USBH_AllocPipe (phost, 0x00U); - phost->Control.pipe_in = USBH_AllocPipe (phost, 0x80U); + phost->Control.pipe_out = USBH_AllocPipe(phost, 0x00U); + phost->Control.pipe_in = USBH_AllocPipe(phost, 0x80U); - /* Open Control pipes */ - USBH_OpenPipe (phost, - phost->Control.pipe_in, - 0x80U, - phost->device.address, - phost->device.speed, - USBH_EP_CONTROL, - (uint16_t)phost->Control.pipe_size); + /* Open Control pipes */ + USBH_OpenPipe(phost, + phost->Control.pipe_in, + 0x80U, + phost->device.address, + phost->device.speed, + USBH_EP_CONTROL, + (uint16_t)phost->Control.pipe_size); - /* Open Control pipes */ - USBH_OpenPipe (phost, - phost->Control.pipe_out, - 0x00U, - phost->device.address, - phost->device.speed, - USBH_EP_CONTROL, - (uint16_t)phost->Control.pipe_size); + /* Open Control pipes */ + USBH_OpenPipe(phost, + phost->Control.pipe_out, + 0x00U, + phost->device.address, + phost->device.speed, + USBH_EP_CONTROL, + (uint16_t)phost->Control.pipe_size); #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_PORT_EVENT; + phost->os_msg = (uint32_t)USBH_PORT_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; - - case HOST_ENUMERATION: - /* Check for enumeration status */ - if ( USBH_HandleEnum(phost) == USBH_OK) - { - /* The function shall return USBH_OK when full enumeration is complete */ - USBH_UsrLog ("Enumeration done."); - phost->device.current_interface = 0U; - if(phost->device.DevDesc.bNumConfigurations == 1U) - { - USBH_UsrLog ("This device has only 1 configuration."); - phost->gState = HOST_SET_CONFIGURATION; + break; + + case HOST_ENUMERATION: + /* Check for enumeration status */ + if (USBH_HandleEnum(phost) == USBH_OK) { + /* The function shall return USBH_OK when full enumeration is complete */ + USBH_UsrLog("Enumeration done."); + phost->device.current_interface = 0U; + if (phost->device.DevDesc.bNumConfigurations == 1U) { + USBH_UsrLog("This device has only 1 configuration."); + phost->gState = HOST_SET_CONFIGURATION; + + } else { + phost->gState = HOST_INPUT; + } } - else - { - phost->gState = HOST_INPUT; - } - - } - break; + break; - case HOST_INPUT: - { - /* user callback for end of device basic enumeration */ - if(phost->pUser != NULL) - { - phost->pUser(phost, HOST_USER_SELECT_CONFIGURATION); - phost->gState = HOST_SET_CONFIGURATION; + case HOST_INPUT: { + /* user callback for end of device basic enumeration */ + if (phost->pUser != NULL) { + phost->pUser(phost, HOST_USER_SELECT_CONFIGURATION); + phost->gState = HOST_SET_CONFIGURATION; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif + } + } + break; + + case HOST_SET_CONFIGURATION: + /* set configuration */ + if (USBH_SetCfg(phost, (uint16_t)phost->device.CfgDesc.bConfigurationValue) == USBH_OK) { + phost->gState = HOST_SET_WAKEUP_FEATURE; + USBH_UsrLog("Default configuration set."); } - } - break; - - case HOST_SET_CONFIGURATION: - /* set configuration */ - if (USBH_SetCfg(phost, (uint16_t)phost->device.CfgDesc.bConfigurationValue) == USBH_OK) - { - phost->gState = HOST_SET_WAKEUP_FEATURE; - USBH_UsrLog ("Default configuration set."); - } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_PORT_EVENT; + phost->os_msg = (uint32_t)USBH_PORT_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case HOST_SET_WAKEUP_FEATURE: + case HOST_SET_WAKEUP_FEATURE: - if ((phost->device.CfgDesc.bmAttributes) & (1U << 5)) - { - if (USBH_SetFeature(phost, FEATURE_SELECTOR_REMOTEWAKEUP) == USBH_OK) - { - USBH_UsrLog ("Device remote wakeup enabled"); + if ((phost->device.CfgDesc.bmAttributes) & (1U << 5)) { + if (USBH_SetFeature(phost, FEATURE_SELECTOR_REMOTEWAKEUP) == USBH_OK) { + USBH_UsrLog("Device remote wakeup enabled"); + phost->gState = HOST_CHECK_CLASS; + } + } else { phost->gState = HOST_CHECK_CLASS; } - } - else - { - phost->gState = HOST_CHECK_CLASS; - } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_PORT_EVENT; + phost->os_msg = (uint32_t)USBH_PORT_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case HOST_CHECK_CLASS: + case HOST_CHECK_CLASS: - if(phost->ClassNumber == 0U) - { - USBH_UsrLog ("No Class has been registered."); - } - else - { - phost->pActiveClass = NULL; - - for (idx = 0U; idx < USBH_MAX_NUM_SUPPORTED_CLASS; idx++) - { - if(phost->pClass[idx]->ClassCode == phost->device.CfgDesc.Itf_Desc[0].bInterfaceClass) - { - phost->pActiveClass = phost->pClass[idx]; - } - } + if (phost->ClassNumber == 0U) { + USBH_UsrLog("No Class has been registered."); + } else { + phost->pActiveClass = NULL; - if(phost->pActiveClass != NULL) - { - if(phost->pActiveClass->Init(phost)== USBH_OK) - { - phost->gState = HOST_CLASS_REQUEST; - USBH_UsrLog ("%s class started.", phost->pActiveClass->Name); - - /* Inform user that a class has been activated */ - phost->pUser(phost, HOST_USER_CLASS_SELECTED); + for (idx = 0U; idx < USBH_MAX_NUM_SUPPORTED_CLASS; idx++) { + if (phost->pClass[idx]->ClassCode == phost->device.CfgDesc.Itf_Desc[0].bInterfaceClass) { + phost->pActiveClass = phost->pClass[idx]; + } } - else - { + + if (phost->pActiveClass != NULL) { + if (phost->pActiveClass->Init(phost) == USBH_OK) { + phost->gState = HOST_CLASS_REQUEST; + USBH_UsrLog("%s class started.", phost->pActiveClass->Name); + + /* Inform user that a class has been activated */ + phost->pUser(phost, HOST_USER_CLASS_SELECTED); + } else { + phost->gState = HOST_ABORT_STATE; + USBH_UsrLog("Device not supporting %s class.", phost->pActiveClass->Name); + } + } else { phost->gState = HOST_ABORT_STATE; - USBH_UsrLog ("Device not supporting %s class.", phost->pActiveClass->Name); + USBH_UsrLog("No registered class for this device."); } } - else - { - phost->gState = HOST_ABORT_STATE; - USBH_UsrLog ("No registered class for this device."); - } - } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case HOST_CLASS_REQUEST: - /* process class standard control requests state machine */ - if(phost->pActiveClass != NULL) - { - status = phost->pActiveClass->Requests(phost); + case HOST_CLASS_REQUEST: + /* process class standard control requests state machine */ + if (phost->pActiveClass != NULL) { + status = phost->pActiveClass->Requests(phost); - if(status == USBH_OK) - { - phost->gState = HOST_CLASS; - } - } - else - { - phost->gState = HOST_ABORT_STATE; - USBH_ErrLog ("Invalid Class Driver."); + if (status == USBH_OK) { + phost->gState = HOST_CLASS; + } + } else { + phost->gState = HOST_ABORT_STATE; + USBH_ErrLog("Invalid Class Driver."); #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } + } - break; - case HOST_CLASS: - /* process class state machine */ - if(phost->pActiveClass != NULL) - { - phost->pActiveClass->BgndProcess(phost); - } - break; + break; + case HOST_CLASS: + /* process class state machine */ + if (phost->pActiveClass != NULL) { + phost->pActiveClass->BgndProcess(phost); + } + break; - case HOST_DEV_DISCONNECTED : + case HOST_DEV_DISCONNECTED : - DeInitStateMachine(phost); + DeInitStateMachine(phost); - /* Re-Initilaize Host for new Enumeration */ - if(phost->pActiveClass != NULL) - { - phost->pActiveClass->DeInit(phost); - phost->pActiveClass = NULL; - } - break; + /* Re-Initilaize Host for new Enumeration */ + if (phost->pActiveClass != NULL) { + phost->pActiveClass->DeInit(phost); + phost->pActiveClass = NULL; + } + break; - case HOST_ABORT_STATE: - default : - break; + case HOST_ABORT_STATE: + default : + break; } - return USBH_OK; + return USBH_OK; } @@ -710,201 +659,186 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost) * @param phost: Host Handle * @retval USBH_Status */ -static USBH_StatusTypeDef USBH_HandleEnum (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_HandleEnum(USBH_HandleTypeDef *phost) { USBH_StatusTypeDef Status = USBH_BUSY; - switch (phost->EnumState) - { - case ENUM_IDLE: - /* Get Device Desc for only 1st 8 bytes : To get EP0 MaxPacketSize */ - if ( USBH_Get_DevDesc(phost, 8U) == USBH_OK) - { - phost->Control.pipe_size = phost->device.DevDesc.bMaxPacketSize; - - phost->EnumState = ENUM_GET_FULL_DEV_DESC; - - /* modify control channels configuration for MaxPacket size */ - USBH_OpenPipe (phost, - phost->Control.pipe_in, - 0x80U, - phost->device.address, - phost->device.speed, - USBH_EP_CONTROL, - (uint16_t)phost->Control.pipe_size); + switch (phost->EnumState) { + case ENUM_IDLE: + /* Get Device Desc for only 1st 8 bytes : To get EP0 MaxPacketSize */ + if (USBH_Get_DevDesc(phost, 8U) == USBH_OK) { + phost->Control.pipe_size = phost->device.DevDesc.bMaxPacketSize; + + phost->EnumState = ENUM_GET_FULL_DEV_DESC; + + /* modify control channels configuration for MaxPacket size */ + USBH_OpenPipe(phost, + phost->Control.pipe_in, + 0x80U, + phost->device.address, + phost->device.speed, + USBH_EP_CONTROL, + (uint16_t)phost->Control.pipe_size); + + /* Open Control pipes */ + USBH_OpenPipe(phost, + phost->Control.pipe_out, + 0x00U, + phost->device.address, + phost->device.speed, + USBH_EP_CONTROL, + (uint16_t)phost->Control.pipe_size); - /* Open Control pipes */ - USBH_OpenPipe (phost, - phost->Control.pipe_out, - 0x00U, - phost->device.address, - phost->device.speed, - USBH_EP_CONTROL, - (uint16_t)phost->Control.pipe_size); + } + break; - } - break; + case ENUM_GET_FULL_DEV_DESC: + /* Get FULL Device Desc */ + if (USBH_Get_DevDesc(phost, USB_DEVICE_DESC_SIZE) == USBH_OK) { + USBH_UsrLog("PID: %xh", phost->device.DevDesc.idProduct); + USBH_UsrLog("VID: %xh", phost->device.DevDesc.idVendor); - case ENUM_GET_FULL_DEV_DESC: - /* Get FULL Device Desc */ - if ( USBH_Get_DevDesc(phost, USB_DEVICE_DESC_SIZE)== USBH_OK) - { - USBH_UsrLog("PID: %xh", phost->device.DevDesc.idProduct ); - USBH_UsrLog("VID: %xh", phost->device.DevDesc.idVendor ); + phost->EnumState = ENUM_SET_ADDR; - phost->EnumState = ENUM_SET_ADDR; + } + break; + + case ENUM_SET_ADDR: + /* set address */ + if (USBH_SetAddress(phost, USBH_DEVICE_ADDRESS) == USBH_OK) { + USBH_Delay(2U); + phost->device.address = USBH_DEVICE_ADDRESS; + + /* user callback for device address assigned */ + USBH_UsrLog("Address (#%d) assigned.", phost->device.address); + phost->EnumState = ENUM_GET_CFG_DESC; + + /* modify control channels to update device address */ + USBH_OpenPipe(phost, + phost->Control.pipe_in, + 0x80U, + phost->device.address, + phost->device.speed, + USBH_EP_CONTROL, + (uint16_t)phost->Control.pipe_size); + + /* Open Control pipes */ + USBH_OpenPipe(phost, + phost->Control.pipe_out, + 0x00U, + phost->device.address, + phost->device.speed, + USBH_EP_CONTROL, + (uint16_t)phost->Control.pipe_size); + } + break; - } - break; - - case ENUM_SET_ADDR: - /* set address */ - if ( USBH_SetAddress(phost, USBH_DEVICE_ADDRESS) == USBH_OK) - { - USBH_Delay(2U); - phost->device.address = USBH_DEVICE_ADDRESS; - - /* user callback for device address assigned */ - USBH_UsrLog("Address (#%d) assigned.", phost->device.address); - phost->EnumState = ENUM_GET_CFG_DESC; - - /* modify control channels to update device address */ - USBH_OpenPipe (phost, - phost->Control.pipe_in, - 0x80U, - phost->device.address, - phost->device.speed, - USBH_EP_CONTROL, - (uint16_t)phost->Control.pipe_size); + case ENUM_GET_CFG_DESC: + /* get standard configuration descriptor */ + if (USBH_Get_CfgDesc(phost, + USB_CONFIGURATION_DESC_SIZE) == USBH_OK) { + phost->EnumState = ENUM_GET_FULL_CFG_DESC; + } + break; - /* Open Control pipes */ - USBH_OpenPipe (phost, - phost->Control.pipe_out, - 0x00U, - phost->device.address, - phost->device.speed, - USBH_EP_CONTROL, - (uint16_t)phost->Control.pipe_size); - } - break; - - case ENUM_GET_CFG_DESC: - /* get standard configuration descriptor */ - if ( USBH_Get_CfgDesc(phost, - USB_CONFIGURATION_DESC_SIZE) == USBH_OK) - { - phost->EnumState = ENUM_GET_FULL_CFG_DESC; - } - break; - - case ENUM_GET_FULL_CFG_DESC: - /* get FULL config descriptor (config, interface, endpoints) */ - if (USBH_Get_CfgDesc(phost, - phost->device.CfgDesc.wTotalLength) == USBH_OK) - { - phost->EnumState = ENUM_GET_MFC_STRING_DESC; - } - break; - - case ENUM_GET_MFC_STRING_DESC: - if (phost->device.DevDesc.iManufacturer != 0U) - { /* Check that Manufacturer String is available */ - - if ( USBH_Get_StringDesc(phost, - phost->device.DevDesc.iManufacturer, - phost->device.Data, - 0xFFU) == USBH_OK) - { - /* User callback for Manufacturing string */ - USBH_UsrLog("Manufacturer : %s", (char *)(void*)phost->device.Data); - phost->EnumState = ENUM_GET_PRODUCT_STRING_DESC; + case ENUM_GET_FULL_CFG_DESC: + /* get FULL config descriptor (config, interface, endpoints) */ + if (USBH_Get_CfgDesc(phost, + phost->device.CfgDesc.wTotalLength) == USBH_OK) { + phost->EnumState = ENUM_GET_MFC_STRING_DESC; + } + break; + + case ENUM_GET_MFC_STRING_DESC: + if (phost->device.DevDesc.iManufacturer != 0U) { + /* Check that Manufacturer String is available */ + + if (USBH_Get_StringDesc(phost, + phost->device.DevDesc.iManufacturer, + phost->device.Data, + 0xFFU) == USBH_OK) { + /* User callback for Manufacturing string */ + USBH_UsrLog("Manufacturer : %s", (char *)(void *)phost->device.Data); + phost->EnumState = ENUM_GET_PRODUCT_STRING_DESC; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - } - else - { - USBH_UsrLog("Manufacturer : N/A"); - phost->EnumState = ENUM_GET_PRODUCT_STRING_DESC; + } + } else { + USBH_UsrLog("Manufacturer : N/A"); + phost->EnumState = ENUM_GET_PRODUCT_STRING_DESC; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; - - case ENUM_GET_PRODUCT_STRING_DESC: - if (phost->device.DevDesc.iProduct != 0U) - { /* Check that Product string is available */ - if ( USBH_Get_StringDesc(phost, - phost->device.DevDesc.iProduct, - phost->device.Data, - 0xFFU) == USBH_OK) - { - /* User callback for Product string */ - USBH_UsrLog("Product : %s", (char *)(void *)phost->device.Data); - phost->EnumState = ENUM_GET_SERIALNUM_STRING_DESC; } - } - else - { - USBH_UsrLog("Product : N/A"); - phost->EnumState = ENUM_GET_SERIALNUM_STRING_DESC; + break; + + case ENUM_GET_PRODUCT_STRING_DESC: + if (phost->device.DevDesc.iProduct != 0U) { + /* Check that Product string is available */ + if (USBH_Get_StringDesc(phost, + phost->device.DevDesc.iProduct, + phost->device.Data, + 0xFFU) == USBH_OK) { + /* User callback for Product string */ + USBH_UsrLog("Product : %s", (char *)(void *)phost->device.Data); + phost->EnumState = ENUM_GET_SERIALNUM_STRING_DESC; + } + } else { + USBH_UsrLog("Product : N/A"); + phost->EnumState = ENUM_GET_SERIALNUM_STRING_DESC; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; - - case ENUM_GET_SERIALNUM_STRING_DESC: - if (phost->device.DevDesc.iSerialNumber != 0U) - { /* Check that Serial number string is available */ - if ( USBH_Get_StringDesc(phost, - phost->device.DevDesc.iSerialNumber, - phost->device.Data, - 0xFFU) == USBH_OK) - { - /* User callback for Serial number string */ - USBH_UsrLog("Serial Number : %s", (char *)(void*)phost->device.Data); - Status = USBH_OK; } - } - else - { - USBH_UsrLog("Serial Number : N/A"); - Status = USBH_OK; + break; + + case ENUM_GET_SERIALNUM_STRING_DESC: + if (phost->device.DevDesc.iSerialNumber != 0U) { + /* Check that Serial number string is available */ + if (USBH_Get_StringDesc(phost, + phost->device.DevDesc.iSerialNumber, + phost->device.Data, + 0xFFU) == USBH_OK) { + /* User callback for Serial number string */ + USBH_UsrLog("Serial Number : %s", (char *)(void *)phost->device.Data); + Status = USBH_OK; + } + } else { + USBH_UsrLog("Serial Number : N/A"); + Status = USBH_OK; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; + phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - break; + } + break; - default: - break; + default: + break; } return Status; } @@ -915,7 +849,7 @@ static USBH_StatusTypeDef USBH_HandleEnum (USBH_HandleTypeDef *phost) * @param phost: Host Handle * @retval None */ -void USBH_LL_SetTimer (USBH_HandleTypeDef *phost, uint32_t time) +void USBH_LL_SetTimer(USBH_HandleTypeDef *phost, uint32_t time) { phost->Timer = time; } @@ -925,7 +859,7 @@ void USBH_LL_SetTimer (USBH_HandleTypeDef *phost, uint32_t time) * @param phost: Host Handle * @retval None */ -void USBH_LL_IncTimer (USBH_HandleTypeDef *phost) +void USBH_LL_IncTimer(USBH_HandleTypeDef *phost) { phost->Timer ++; USBH_HandleSof(phost); @@ -937,10 +871,9 @@ void USBH_LL_IncTimer (USBH_HandleTypeDef *phost) * @param phost: Host Handle * @retval None */ -static void USBH_HandleSof (USBH_HandleTypeDef *phost) +static void USBH_HandleSof(USBH_HandleTypeDef *phost) { - if((phost->gState == HOST_CLASS)&&(phost->pActiveClass != NULL)) - { + if ((phost->gState == HOST_CLASS) && (phost->pActiveClass != NULL)) { phost->pActiveClass->SOFProcess(phost); } } @@ -951,7 +884,7 @@ static void USBH_HandleSof (USBH_HandleTypeDef *phost) * @param phost: Host Handle * @retval None */ -void USBH_LL_PortEnabled (USBH_HandleTypeDef *phost) +void USBH_LL_PortEnabled(USBH_HandleTypeDef *phost) { phost->device.PortEnabled = 1U; @@ -964,7 +897,7 @@ void USBH_LL_PortEnabled (USBH_HandleTypeDef *phost) * @param phost: Host Handle * @retval None */ -void USBH_LL_PortDisabled (USBH_HandleTypeDef *phost) +void USBH_LL_PortDisabled(USBH_HandleTypeDef *phost) { phost->device.PortEnabled = 0U; @@ -979,7 +912,7 @@ void USBH_LL_PortDisabled (USBH_HandleTypeDef *phost) */ uint8_t USBH_IsPortEnabled(USBH_HandleTypeDef *phost) { - return(phost->device.PortEnabled); + return (phost->device.PortEnabled); } @@ -989,21 +922,16 @@ uint8_t USBH_IsPortEnabled(USBH_HandleTypeDef *phost) * @param phost: Host Handle * @retval USBH_Status */ -USBH_StatusTypeDef USBH_LL_Connect (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_LL_Connect(USBH_HandleTypeDef *phost) { - if(phost->gState == HOST_IDLE ) - { + if (phost->gState == HOST_IDLE) { phost->device.is_connected = 1U; - if(phost->pUser != NULL) - { + if (phost->pUser != NULL) { phost->pUser(phost, HOST_USER_CONNECTION); } - } - else - { - if (phost->device.PortEnabled == 1U) - { + } else { + if (phost->device.PortEnabled == 1U) { phost->gState = HOST_DEV_ATTACHED; } } @@ -1026,19 +954,18 @@ USBH_StatusTypeDef USBH_LL_Connect (USBH_HandleTypeDef *phost) * @param phost: Host Handle * @retval USBH_Status */ -USBH_StatusTypeDef USBH_LL_Disconnect (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_LL_Disconnect(USBH_HandleTypeDef *phost) { /*Stop Host */ USBH_LL_Stop(phost); /* FRee Control Pipes */ - USBH_FreePipe (phost, phost->Control.pipe_in); - USBH_FreePipe (phost, phost->Control.pipe_out); + USBH_FreePipe(phost, phost->Control.pipe_in); + USBH_FreePipe(phost, phost->Control.pipe_out); phost->device.is_connected = 0U; - if(phost->pUser != NULL) - { + if (phost->pUser != NULL) { phost->pUser(phost, HOST_USER_DISCONNECTION); } USBH_UsrLog("USB Device disconnected"); @@ -1073,11 +1000,9 @@ static void USBH_Process_OS(void const *argument) { osEvent event; - for(;;) - { + for (;;) { event = osMessageGet(((USBH_HandleTypeDef *)argument)->os_event, osWaitForever); - if(event.status == osEventMessage) - { + if (event.status == osEventMessage) { USBH_Process((USBH_HandleTypeDef *)argument); } } @@ -1087,12 +1012,10 @@ static void USBH_Process_OS(void *argument) { osStatus_t status; - for(;;) - { + for (;;) { status = osMessageQueueGet(((USBH_HandleTypeDef *)argument)->os_event, &((USBH_HandleTypeDef *)argument)->os_msg, NULL, osWaitForever); - if (status == osOK) - { + if (status == osOK) { USBH_Process((USBH_HandleTypeDef *)argument); } } @@ -1105,7 +1028,7 @@ static void USBH_Process_OS(void *argument) * @param phost: Host handle * @retval USBH Status */ -USBH_StatusTypeDef USBH_LL_NotifyURBChange (USBH_HandleTypeDef *phost) +USBH_StatusTypeDef USBH_LL_NotifyURBChange(USBH_HandleTypeDef *phost) { phost->os_msg = (uint32_t)USBH_PORT_EVENT; diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ctlreq.c b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ctlreq.c index 91cbee756e..8d3389fcde 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ctlreq.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ctlreq.c @@ -70,17 +70,17 @@ /** @defgroup USBH_CTLREQ_Private_FunctionPrototypes * @{ */ -static USBH_StatusTypeDef USBH_HandleControl (USBH_HandleTypeDef *phost); +static USBH_StatusTypeDef USBH_HandleControl(USBH_HandleTypeDef *phost); -static void USBH_ParseDevDesc (USBH_DevDescTypeDef *dev_desc, uint8_t *buf, - uint16_t length); +static void USBH_ParseDevDesc(USBH_DevDescTypeDef *dev_desc, uint8_t *buf, + uint16_t length); -static void USBH_ParseCfgDesc (USBH_CfgDescTypeDef *cfg_desc, uint8_t *buf, - uint16_t length); +static void USBH_ParseCfgDesc(USBH_CfgDescTypeDef *cfg_desc, uint8_t *buf, + uint16_t length); -static void USBH_ParseEPDesc (USBH_EpDescTypeDef *ep_descriptor, uint8_t *buf); -static void USBH_ParseStringDesc (uint8_t* psrc, uint8_t* pdest, uint16_t length); -static void USBH_ParseInterfaceDesc (USBH_InterfaceDescTypeDef *if_descriptor, uint8_t *buf); +static void USBH_ParseEPDesc(USBH_EpDescTypeDef *ep_descriptor, uint8_t *buf); +static void USBH_ParseStringDesc(uint8_t *psrc, uint8_t *pdest, uint16_t length); +static void USBH_ParseInterfaceDesc(USBH_InterfaceDescTypeDef *if_descriptor, uint8_t *buf); /** @@ -105,12 +105,11 @@ USBH_StatusTypeDef USBH_Get_DevDesc(USBH_HandleTypeDef *phost, uint8_t length) { USBH_StatusTypeDef status; - if((status = USBH_GetDescriptor(phost, - USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD, - USB_DESC_DEVICE, - phost->device.Data, - (uint16_t)length)) == USBH_OK) - { + if ((status = USBH_GetDescriptor(phost, + USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD, + USB_DESC_DEVICE, + phost->device.Data, + (uint16_t)length)) == USBH_OK) { /* Commands successfully sent and Response Received */ USBH_ParseDevDesc(&phost->device.DevDesc, phost->device.Data, (uint16_t)length); @@ -128,7 +127,7 @@ USBH_StatusTypeDef USBH_Get_DevDesc(USBH_HandleTypeDef *phost, uint8_t length) * @retval USBH Status */ USBH_StatusTypeDef USBH_Get_CfgDesc(USBH_HandleTypeDef *phost, - uint16_t length) + uint16_t length) { USBH_StatusTypeDef status; @@ -138,17 +137,16 @@ USBH_StatusTypeDef USBH_Get_CfgDesc(USBH_HandleTypeDef *phost, #else pData = phost->device.Data; #endif - if((status = USBH_GetDescriptor(phost, - USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD, - USB_DESC_CONFIGURATION, - pData, - length)) == USBH_OK) - { + if ((status = USBH_GetDescriptor(phost, + USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD, + USB_DESC_CONFIGURATION, + pData, + length)) == USBH_OK) { /* Commands successfully sent and Response Received */ - USBH_ParseCfgDesc (&phost->device.CfgDesc, - pData, - length); + USBH_ParseCfgDesc(&phost->device.CfgDesc, + pData, + length); } return status; @@ -166,19 +164,18 @@ USBH_StatusTypeDef USBH_Get_CfgDesc(USBH_HandleTypeDef *phost, * @retval USBH Status */ USBH_StatusTypeDef USBH_Get_StringDesc(USBH_HandleTypeDef *phost, - uint8_t string_index, - uint8_t *buff, - uint16_t length) + uint8_t string_index, + uint8_t *buff, + uint16_t length) { USBH_StatusTypeDef status; - if((status = USBH_GetDescriptor(phost, - USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD, - USB_DESC_STRING | string_index, - phost->device.Data, - length)) == USBH_OK) - { + if ((status = USBH_GetDescriptor(phost, + USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD, + USB_DESC_STRING | string_index, + phost->device.Data, + length)) == USBH_OK) { /* Commands successfully sent and Response Received */ - USBH_ParseStringDesc(phost->device.Data,buff, length); + USBH_ParseStringDesc(phost->device.Data, buff, length); } return status; } @@ -195,23 +192,19 @@ USBH_StatusTypeDef USBH_Get_StringDesc(USBH_HandleTypeDef *phost, * @retval USBH Status */ USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost, - uint8_t req_type, - uint16_t value_idx, - uint8_t* buff, - uint16_t length) + uint8_t req_type, + uint16_t value_idx, + uint8_t *buff, + uint16_t length) { - if(phost->RequestState == CMD_SEND) - { + if (phost->RequestState == CMD_SEND) { phost->Control.setup.b.bmRequestType = USB_D2H | req_type; phost->Control.setup.b.bRequest = USB_REQ_GET_DESCRIPTOR; phost->Control.setup.b.wValue.w = value_idx; - if ((value_idx & 0xff00U) == USB_DESC_STRING) - { + if ((value_idx & 0xff00U) == USB_DESC_STRING) { phost->Control.setup.b.wIndex.w = 0x0409U; - } - else - { + } else { phost->Control.setup.b.wIndex.w = 0U; } phost->Control.setup.b.wLength.w = length; @@ -229,10 +222,9 @@ USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost, USBH_StatusTypeDef USBH_SetAddress(USBH_HandleTypeDef *phost, uint8_t DeviceAddress) { - if(phost->RequestState == CMD_SEND) - { + if (phost->RequestState == CMD_SEND) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_DEVICE | \ - USB_REQ_TYPE_STANDARD; + USB_REQ_TYPE_STANDARD; phost->Control.setup.b.bRequest = USB_REQ_SET_ADDRESS; @@ -252,10 +244,9 @@ USBH_StatusTypeDef USBH_SetAddress(USBH_HandleTypeDef *phost, */ USBH_StatusTypeDef USBH_SetCfg(USBH_HandleTypeDef *phost, uint16_t cfg_idx) { - if(phost->RequestState == CMD_SEND) - { + if (phost->RequestState == CMD_SEND) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_DEVICE - | USB_REQ_TYPE_STANDARD; + | USB_REQ_TYPE_STANDARD; phost->Control.setup.b.bRequest = USB_REQ_SET_CONFIGURATION; phost->Control.setup.b.wValue.w = cfg_idx; @@ -263,7 +254,7 @@ USBH_StatusTypeDef USBH_SetCfg(USBH_HandleTypeDef *phost, uint16_t cfg_idx) phost->Control.setup.b.wLength.w = 0U; } - return USBH_CtlReq(phost, 0U , 0U); + return USBH_CtlReq(phost, 0U, 0U); } /** @@ -276,17 +267,16 @@ USBH_StatusTypeDef USBH_SetCfg(USBH_HandleTypeDef *phost, uint16_t cfg_idx) USBH_StatusTypeDef USBH_SetInterface(USBH_HandleTypeDef *phost, uint8_t ep_num, uint8_t altSetting) { - if(phost->RequestState == CMD_SEND) - { + if (phost->RequestState == CMD_SEND) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE - | USB_REQ_TYPE_STANDARD; + | USB_REQ_TYPE_STANDARD; phost->Control.setup.b.bRequest = USB_REQ_SET_INTERFACE; phost->Control.setup.b.wValue.w = altSetting; phost->Control.setup.b.wIndex.w = ep_num; phost->Control.setup.b.wLength.w = 0U; } - return USBH_CtlReq(phost, 0U , 0U); + return USBH_CtlReq(phost, 0U, 0U); } /** @@ -298,10 +288,9 @@ USBH_StatusTypeDef USBH_SetInterface(USBH_HandleTypeDef *phost, uint8_t ep_num, */ USBH_StatusTypeDef USBH_SetFeature(USBH_HandleTypeDef *phost, uint8_t wValue) { - if(phost->RequestState == CMD_SEND) - { + if (phost->RequestState == CMD_SEND) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_DEVICE - | USB_REQ_TYPE_STANDARD; + | USB_REQ_TYPE_STANDARD; phost->Control.setup.b.bRequest = USB_REQ_SET_FEATURE; phost->Control.setup.b.wValue.w = wValue; @@ -322,17 +311,16 @@ USBH_StatusTypeDef USBH_SetFeature(USBH_HandleTypeDef *phost, uint8_t wValue) */ USBH_StatusTypeDef USBH_ClrFeature(USBH_HandleTypeDef *phost, uint8_t ep_num) { - if(phost->RequestState == CMD_SEND) - { + if (phost->RequestState == CMD_SEND) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_ENDPOINT - | USB_REQ_TYPE_STANDARD; + | USB_REQ_TYPE_STANDARD; phost->Control.setup.b.bRequest = USB_REQ_CLEAR_FEATURE; phost->Control.setup.b.wValue.w = FEATURE_SELECTOR_ENDPOINT; phost->Control.setup.b.wIndex.w = ep_num; phost->Control.setup.b.wLength.w = 0U; } - return USBH_CtlReq(phost, 0U , 0U); + return USBH_CtlReq(phost, 0U, 0U); } /** @@ -343,27 +331,27 @@ USBH_StatusTypeDef USBH_ClrFeature(USBH_HandleTypeDef *phost, uint8_t ep_num) * @param length: Length of the descriptor * @retval None */ -static void USBH_ParseDevDesc (USBH_DevDescTypeDef* dev_desc, uint8_t *buf, - uint16_t length) +static void USBH_ParseDevDesc(USBH_DevDescTypeDef *dev_desc, uint8_t *buf, + uint16_t length) { - dev_desc->bLength = *(uint8_t *) (buf + 0); - dev_desc->bDescriptorType = *(uint8_t *) (buf + 1); - dev_desc->bcdUSB = LE16 (buf + 2); - dev_desc->bDeviceClass = *(uint8_t *) (buf + 4); - dev_desc->bDeviceSubClass = *(uint8_t *) (buf + 5); - dev_desc->bDeviceProtocol = *(uint8_t *) (buf + 6); - dev_desc->bMaxPacketSize = *(uint8_t *) (buf + 7); - - if (length > 8U) - { /* For 1st time after device connection, Host may issue only 8 bytes for + dev_desc->bLength = *(uint8_t *)(buf + 0); + dev_desc->bDescriptorType = *(uint8_t *)(buf + 1); + dev_desc->bcdUSB = LE16(buf + 2); + dev_desc->bDeviceClass = *(uint8_t *)(buf + 4); + dev_desc->bDeviceSubClass = *(uint8_t *)(buf + 5); + dev_desc->bDeviceProtocol = *(uint8_t *)(buf + 6); + dev_desc->bMaxPacketSize = *(uint8_t *)(buf + 7); + + if (length > 8U) { + /* For 1st time after device connection, Host may issue only 8 bytes for Device Descriptor Length */ - dev_desc->idVendor = LE16 (buf + 8); - dev_desc->idProduct = LE16 (buf + 10); - dev_desc->bcdDevice = LE16 (buf + 12); - dev_desc->iManufacturer = *(uint8_t *) (buf + 14); - dev_desc->iProduct = *(uint8_t *) (buf + 15); - dev_desc->iSerialNumber = *(uint8_t *) (buf + 16); - dev_desc->bNumConfigurations = *(uint8_t *) (buf + 17); + dev_desc->idVendor = LE16(buf + 8); + dev_desc->idProduct = LE16(buf + 10); + dev_desc->bcdDevice = LE16(buf + 12); + dev_desc->iManufacturer = *(uint8_t *)(buf + 14); + dev_desc->iProduct = *(uint8_t *)(buf + 15); + dev_desc->iSerialNumber = *(uint8_t *)(buf + 16); + dev_desc->bNumConfigurations = *(uint8_t *)(buf + 17); } } @@ -375,8 +363,8 @@ static void USBH_ParseDevDesc (USBH_DevDescTypeDef* dev_desc, uint8_t *buf, * @param length: Length of the descriptor * @retval None */ -static void USBH_ParseCfgDesc (USBH_CfgDescTypeDef* cfg_desc, uint8_t *buf, - uint16_t length) +static void USBH_ParseCfgDesc(USBH_CfgDescTypeDef *cfg_desc, uint8_t *buf, + uint16_t length) { USBH_InterfaceDescTypeDef *pif ; USBH_EpDescTypeDef *pep; @@ -388,39 +376,34 @@ static void USBH_ParseCfgDesc (USBH_CfgDescTypeDef* cfg_desc, uint8_t *buf, pdesc = (USBH_DescHeader_t *)(void *)buf; /* Parse configuration descriptor */ - cfg_desc->bLength = *(uint8_t *) (buf + 0); - cfg_desc->bDescriptorType = *(uint8_t *) (buf + 1); - cfg_desc->wTotalLength = LE16 (buf + 2); - cfg_desc->bNumInterfaces = *(uint8_t *) (buf + 4); - cfg_desc->bConfigurationValue = *(uint8_t *) (buf + 5); - cfg_desc->iConfiguration = *(uint8_t *) (buf + 6); - cfg_desc->bmAttributes = *(uint8_t *) (buf + 7); - cfg_desc->bMaxPower = *(uint8_t *) (buf + 8); - - - if (length > USB_CONFIGURATION_DESC_SIZE) - { + cfg_desc->bLength = *(uint8_t *)(buf + 0); + cfg_desc->bDescriptorType = *(uint8_t *)(buf + 1); + cfg_desc->wTotalLength = LE16(buf + 2); + cfg_desc->bNumInterfaces = *(uint8_t *)(buf + 4); + cfg_desc->bConfigurationValue = *(uint8_t *)(buf + 5); + cfg_desc->iConfiguration = *(uint8_t *)(buf + 6); + cfg_desc->bmAttributes = *(uint8_t *)(buf + 7); + cfg_desc->bMaxPower = *(uint8_t *)(buf + 8); + + + if (length > USB_CONFIGURATION_DESC_SIZE) { ptr = USB_LEN_CFG_DESC; pif = (USBH_InterfaceDescTypeDef *)0; - while ((if_ix < USBH_MAX_NUM_INTERFACES) && (ptr < cfg_desc->wTotalLength)) - { + while ((if_ix < USBH_MAX_NUM_INTERFACES) && (ptr < cfg_desc->wTotalLength)) { pdesc = USBH_GetNextDesc((uint8_t *)(void *)pdesc, &ptr); - if (pdesc->bDescriptorType == USB_DESC_TYPE_INTERFACE) - { + if (pdesc->bDescriptorType == USB_DESC_TYPE_INTERFACE) { pif = &cfg_desc->Itf_Desc[if_ix]; - USBH_ParseInterfaceDesc (pif, (uint8_t *)(void *)pdesc); + USBH_ParseInterfaceDesc(pif, (uint8_t *)(void *)pdesc); ep_ix = 0U; pep = (USBH_EpDescTypeDef *)0; - while ((ep_ix < pif->bNumEndpoints) && (ptr < cfg_desc->wTotalLength)) - { - pdesc = USBH_GetNextDesc((uint8_t*)(void *)pdesc, &ptr); - if (pdesc->bDescriptorType == USB_DESC_TYPE_ENDPOINT) - { + while ((ep_ix < pif->bNumEndpoints) && (ptr < cfg_desc->wTotalLength)) { + pdesc = USBH_GetNextDesc((uint8_t *)(void *)pdesc, &ptr); + if (pdesc->bDescriptorType == USB_DESC_TYPE_ENDPOINT) { pep = &cfg_desc->Itf_Desc[if_ix].Ep_Desc[ep_ix]; - USBH_ParseEPDesc (pep, (uint8_t *)(void *)pdesc); + USBH_ParseEPDesc(pep, (uint8_t *)(void *)pdesc); ep_ix++; } } @@ -439,18 +422,18 @@ static void USBH_ParseCfgDesc (USBH_CfgDescTypeDef* cfg_desc, uint8_t *buf, * @param buf: Buffer where the descriptor data is available * @retval None */ -static void USBH_ParseInterfaceDesc (USBH_InterfaceDescTypeDef *if_descriptor, - uint8_t *buf) +static void USBH_ParseInterfaceDesc(USBH_InterfaceDescTypeDef *if_descriptor, + uint8_t *buf) { - if_descriptor->bLength = *(uint8_t *) (buf + 0); - if_descriptor->bDescriptorType = *(uint8_t *) (buf + 1); - if_descriptor->bInterfaceNumber = *(uint8_t *) (buf + 2); - if_descriptor->bAlternateSetting = *(uint8_t *) (buf + 3); - if_descriptor->bNumEndpoints = *(uint8_t *) (buf + 4); - if_descriptor->bInterfaceClass = *(uint8_t *) (buf + 5); - if_descriptor->bInterfaceSubClass = *(uint8_t *) (buf + 6); - if_descriptor->bInterfaceProtocol = *(uint8_t *) (buf + 7); - if_descriptor->iInterface = *(uint8_t *) (buf + 8); + if_descriptor->bLength = *(uint8_t *)(buf + 0); + if_descriptor->bDescriptorType = *(uint8_t *)(buf + 1); + if_descriptor->bInterfaceNumber = *(uint8_t *)(buf + 2); + if_descriptor->bAlternateSetting = *(uint8_t *)(buf + 3); + if_descriptor->bNumEndpoints = *(uint8_t *)(buf + 4); + if_descriptor->bInterfaceClass = *(uint8_t *)(buf + 5); + if_descriptor->bInterfaceSubClass = *(uint8_t *)(buf + 6); + if_descriptor->bInterfaceProtocol = *(uint8_t *)(buf + 7); + if_descriptor->iInterface = *(uint8_t *)(buf + 8); } /** @@ -460,16 +443,16 @@ static void USBH_ParseInterfaceDesc (USBH_InterfaceDescTypeDef *if_descriptor, * @param buf: Buffer where the parsed descriptor stored * @retval None */ -static void USBH_ParseEPDesc (USBH_EpDescTypeDef *ep_descriptor, - uint8_t *buf) +static void USBH_ParseEPDesc(USBH_EpDescTypeDef *ep_descriptor, + uint8_t *buf) { - ep_descriptor->bLength = *(uint8_t *) (buf + 0); - ep_descriptor->bDescriptorType = *(uint8_t *) (buf + 1); - ep_descriptor->bEndpointAddress = *(uint8_t *) (buf + 2); - ep_descriptor->bmAttributes = *(uint8_t *) (buf + 3); - ep_descriptor->wMaxPacketSize = LE16 (buf + 4); - ep_descriptor->bInterval = *(uint8_t *) (buf + 6); + ep_descriptor->bLength = *(uint8_t *)(buf + 0); + ep_descriptor->bDescriptorType = *(uint8_t *)(buf + 1); + ep_descriptor->bEndpointAddress = *(uint8_t *)(buf + 2); + ep_descriptor->bmAttributes = *(uint8_t *)(buf + 3); + ep_descriptor->wMaxPacketSize = LE16(buf + 4); + ep_descriptor->bInterval = *(uint8_t *)(buf + 6); } /** @@ -480,7 +463,7 @@ static void USBH_ParseEPDesc (USBH_EpDescTypeDef *ep_descriptor, * @param length: Length of the descriptor * @retval None */ -static void USBH_ParseStringDesc (uint8_t* psrc, uint8_t* pdest, uint16_t length) +static void USBH_ParseStringDesc(uint8_t *psrc, uint8_t *pdest, uint16_t length) { uint16_t strlength; uint16_t idx; @@ -492,8 +475,7 @@ static void USBH_ParseStringDesc (uint8_t* psrc, uint8_t* pdest, uint16_t length /* Check which is lower size, the Size of string or the length of bytes read from the device */ - if (psrc[1] == USB_DESC_TYPE_STRING) - { + if (psrc[1] == USB_DESC_TYPE_STRING) { /* Make sure the Descriptor is String Type */ /* psrc[0] contains Size of Descriptor, subtract 2 to get the length of string */ @@ -502,8 +484,7 @@ static void USBH_ParseStringDesc (uint8_t* psrc, uint8_t* pdest, uint16_t length /* Adjust the offset ignoring the String Len and Descriptor type */ psrc += 2U; - for (idx = 0U; idx < strlength; idx += 2U) - { + for (idx = 0U; idx < strlength; idx += 2U) { /* Copy Only the string and ignore the UNICODE ID, hence add the src */ *pdest = psrc[idx]; pdest++; @@ -519,15 +500,15 @@ static void USBH_ParseStringDesc (uint8_t* psrc, uint8_t* pdest, uint16_t length * @param ptr: data pointer inside the cfg descriptor * @retval next header */ -USBH_DescHeader_t *USBH_GetNextDesc (uint8_t *pbuf, uint16_t *ptr) +USBH_DescHeader_t *USBH_GetNextDesc(uint8_t *pbuf, uint16_t *ptr) { USBH_DescHeader_t *pnext; *ptr += ((USBH_DescHeader_t *)(void *)pbuf)->bLength; pnext = (USBH_DescHeader_t *)(void *)((uint8_t *)(void *)pbuf + \ - ((USBH_DescHeader_t *)(void *)pbuf)->bLength); + ((USBH_DescHeader_t *)(void *)pbuf)->bLength); - return(pnext); + return (pnext); } @@ -541,62 +522,55 @@ USBH_DescHeader_t *USBH_GetNextDesc (uint8_t *pbuf, uint16_t *ptr) * @param length: length of the response * @retval USBH Status */ -USBH_StatusTypeDef USBH_CtlReq (USBH_HandleTypeDef *phost, - uint8_t *buff, - uint16_t length) +USBH_StatusTypeDef USBH_CtlReq(USBH_HandleTypeDef *phost, + uint8_t *buff, + uint16_t length) { USBH_StatusTypeDef status; status = USBH_BUSY; - switch (phost->RequestState) - { - case CMD_SEND: - /* Start a SETUP transfer */ - phost->Control.buff = buff; - phost->Control.length = length; - phost->Control.state = CTRL_SETUP; - phost->RequestState = CMD_WAIT; - status = USBH_BUSY; + switch (phost->RequestState) { + case CMD_SEND: + /* Start a SETUP transfer */ + phost->Control.buff = buff; + phost->Control.length = length; + phost->Control.state = CTRL_SETUP; + phost->RequestState = CMD_WAIT; + status = USBH_BUSY; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - break; + break; - case CMD_WAIT: - status = USBH_HandleControl(phost); - if (status == USBH_OK) - { - /* Commands successfully sent and Response Received */ - phost->RequestState = CMD_SEND; - phost->Control.state =CTRL_IDLE; - status = USBH_OK; - } - else if (status == USBH_NOT_SUPPORTED) - { - /* Commands successfully sent and Response Received */ - phost->RequestState = CMD_SEND; - phost->Control.state = CTRL_IDLE; - status = USBH_NOT_SUPPORTED; - } - else - { - if (status == USBH_FAIL) - { - /* Failure Mode */ + case CMD_WAIT: + status = USBH_HandleControl(phost); + if (status == USBH_OK) { + /* Commands successfully sent and Response Received */ phost->RequestState = CMD_SEND; - status = USBH_FAIL; + phost->Control.state = CTRL_IDLE; + status = USBH_OK; + } else if (status == USBH_NOT_SUPPORTED) { + /* Commands successfully sent and Response Received */ + phost->RequestState = CMD_SEND; + phost->Control.state = CTRL_IDLE; + status = USBH_NOT_SUPPORTED; + } else { + if (status == USBH_FAIL) { + /* Failure Mode */ + phost->RequestState = CMD_SEND; + status = USBH_FAIL; + } } - } - break; + break; - default: - break; + default: + break; } return status; } @@ -607,380 +581,342 @@ USBH_StatusTypeDef USBH_CtlReq (USBH_HandleTypeDef *phost, * @param phost: Host Handle * @retval USBH Status */ -static USBH_StatusTypeDef USBH_HandleControl (USBH_HandleTypeDef *phost) +static USBH_StatusTypeDef USBH_HandleControl(USBH_HandleTypeDef *phost) { uint8_t direction; USBH_StatusTypeDef status = USBH_BUSY; USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE; - switch (phost->Control.state) - { - case CTRL_SETUP: - /* send a SETUP packet */ - USBH_CtlSendSetup (phost, (uint8_t *)(void *)phost->Control.setup.d8, - phost->Control.pipe_out); - - phost->Control.state = CTRL_SETUP_WAIT; - break; - - case CTRL_SETUP_WAIT: - - URB_Status = USBH_LL_GetURBState(phost, phost->Control.pipe_out); - /* case SETUP packet sent successfully */ - if(URB_Status == USBH_URB_DONE) - { - direction = (phost->Control.setup.b.bmRequestType & USB_REQ_DIR_MASK); - - /* check if there is a data stage */ - if (phost->Control.setup.b.wLength.w != 0U) - { - if (direction == USB_D2H) - { - /* Data Direction is IN */ - phost->Control.state = CTRL_DATA_IN; - } - else - { - /* Data Direction is OUT */ - phost->Control.state = CTRL_DATA_OUT; - } - } - /* No DATA stage */ - else - { - /* If there is No Data Transfer Stage */ - if (direction == USB_D2H) - { - /* Data Direction is IN */ - phost->Control.state = CTRL_STATUS_OUT; + switch (phost->Control.state) { + case CTRL_SETUP: + /* send a SETUP packet */ + USBH_CtlSendSetup(phost, (uint8_t *)(void *)phost->Control.setup.d8, + phost->Control.pipe_out); + + phost->Control.state = CTRL_SETUP_WAIT; + break; + + case CTRL_SETUP_WAIT: + + URB_Status = USBH_LL_GetURBState(phost, phost->Control.pipe_out); + /* case SETUP packet sent successfully */ + if (URB_Status == USBH_URB_DONE) { + direction = (phost->Control.setup.b.bmRequestType & USB_REQ_DIR_MASK); + + /* check if there is a data stage */ + if (phost->Control.setup.b.wLength.w != 0U) { + if (direction == USB_D2H) { + /* Data Direction is IN */ + phost->Control.state = CTRL_DATA_IN; + } else { + /* Data Direction is OUT */ + phost->Control.state = CTRL_DATA_OUT; + } } - else - { - /* Data Direction is OUT */ - phost->Control.state = CTRL_STATUS_IN; + /* No DATA stage */ + else { + /* If there is No Data Transfer Stage */ + if (direction == USB_D2H) { + /* Data Direction is IN */ + phost->Control.state = CTRL_STATUS_OUT; + } else { + /* Data Direction is OUT */ + phost->Control.state = CTRL_STATUS_IN; + } } - } #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - if((URB_Status == USBH_URB_ERROR) || (URB_Status == USBH_URB_NOTREADY)) - { - phost->Control.state = CTRL_ERROR; + } else { + if ((URB_Status == USBH_URB_ERROR) || (URB_Status == USBH_URB_NOTREADY)) { + phost->Control.state = CTRL_ERROR; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif + } } - } - break; + break; - case CTRL_DATA_IN: - /* Issue an IN token */ - phost->Control.timer = (uint16_t)phost->Timer; - USBH_CtlReceiveData(phost, - phost->Control.buff, - phost->Control.length, - phost->Control.pipe_in); + case CTRL_DATA_IN: + /* Issue an IN token */ + phost->Control.timer = (uint16_t)phost->Timer; + USBH_CtlReceiveData(phost, + phost->Control.buff, + phost->Control.length, + phost->Control.pipe_in); - phost->Control.state = CTRL_DATA_IN_WAIT; - break; + phost->Control.state = CTRL_DATA_IN_WAIT; + break; - case CTRL_DATA_IN_WAIT: + case CTRL_DATA_IN_WAIT: - URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_in); + URB_Status = USBH_LL_GetURBState(phost, phost->Control.pipe_in); - /* check is DATA packet transferred successfully */ - if (URB_Status == USBH_URB_DONE) - { - phost->Control.state = CTRL_STATUS_OUT; + /* check is DATA packet transferred successfully */ + if (URB_Status == USBH_URB_DONE) { + phost->Control.state = CTRL_STATUS_OUT; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } + } - /* manage error cases*/ - if (URB_Status == USBH_URB_STALL) - { - /* In stall case, return to previous machine state*/ - status = USBH_NOT_SUPPORTED; + /* manage error cases*/ + if (URB_Status == USBH_URB_STALL) { + /* In stall case, return to previous machine state*/ + status = USBH_NOT_SUPPORTED; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - if (URB_Status == USBH_URB_ERROR) - { - /* Device error */ - phost->Control.state = CTRL_ERROR; + } else { + if (URB_Status == USBH_URB_ERROR) { + /* Device error */ + phost->Control.state = CTRL_ERROR; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif + } } - } - break; + break; - case CTRL_DATA_OUT: + case CTRL_DATA_OUT: - USBH_CtlSendData (phost, - phost->Control.buff, - phost->Control.length , - phost->Control.pipe_out, - 1U); - phost->Control.timer = (uint16_t)phost->Timer; - phost->Control.state = CTRL_DATA_OUT_WAIT; - break; + USBH_CtlSendData(phost, + phost->Control.buff, + phost->Control.length, + phost->Control.pipe_out, + 1U); + phost->Control.timer = (uint16_t)phost->Timer; + phost->Control.state = CTRL_DATA_OUT_WAIT; + break; - case CTRL_DATA_OUT_WAIT: + case CTRL_DATA_OUT_WAIT: - URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_out); + URB_Status = USBH_LL_GetURBState(phost, phost->Control.pipe_out); - if (URB_Status == USBH_URB_DONE) - { /* If the Setup Pkt is sent successful, then change the state */ - phost->Control.state = CTRL_STATUS_IN; + if (URB_Status == USBH_URB_DONE) { + /* If the Setup Pkt is sent successful, then change the state */ + phost->Control.state = CTRL_STATUS_IN; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } + } - /* handle error cases */ - else if (URB_Status == USBH_URB_STALL) - { - /* In stall case, return to previous machine state*/ - phost->Control.state = CTRL_STALLED; - status = USBH_NOT_SUPPORTED; + /* handle error cases */ + else if (URB_Status == USBH_URB_STALL) { + /* In stall case, return to previous machine state*/ + phost->Control.state = CTRL_STALLED; + status = USBH_NOT_SUPPORTED; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else if (URB_Status == USBH_URB_NOTREADY) - { - /* Nack received from device */ - phost->Control.state = CTRL_DATA_OUT; + } else if (URB_Status == USBH_URB_NOTREADY) { + /* Nack received from device */ + phost->Control.state = CTRL_DATA_OUT; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - if (URB_Status == USBH_URB_ERROR) - { - /* device error */ - phost->Control.state = CTRL_ERROR; - status = USBH_FAIL; + } else { + if (URB_Status == USBH_URB_ERROR) { + /* device error */ + phost->Control.state = CTRL_ERROR; + status = USBH_FAIL; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif + } } - } - break; + break; - case CTRL_STATUS_IN: - /* Send 0 bytes out packet */ - USBH_CtlReceiveData (phost, - 0U, - 0U, - phost->Control.pipe_in); - phost->Control.timer = (uint16_t)phost->Timer; - phost->Control.state = CTRL_STATUS_IN_WAIT; + case CTRL_STATUS_IN: + /* Send 0 bytes out packet */ + USBH_CtlReceiveData(phost, + 0U, + 0U, + phost->Control.pipe_in); + phost->Control.timer = (uint16_t)phost->Timer; + phost->Control.state = CTRL_STATUS_IN_WAIT; - break; + break; - case CTRL_STATUS_IN_WAIT: + case CTRL_STATUS_IN_WAIT: - URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_in); + URB_Status = USBH_LL_GetURBState(phost, phost->Control.pipe_in); - if ( URB_Status == USBH_URB_DONE) - { /* Control transfers completed, Exit the State Machine */ - phost->Control.state = CTRL_COMPLETE; - status = USBH_OK; + if (URB_Status == USBH_URB_DONE) { + /* Control transfers completed, Exit the State Machine */ + phost->Control.state = CTRL_COMPLETE; + status = USBH_OK; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else if (URB_Status == USBH_URB_ERROR) - { - phost->Control.state = CTRL_ERROR; + } else if (URB_Status == USBH_URB_ERROR) { + phost->Control.state = CTRL_ERROR; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - if(URB_Status == USBH_URB_STALL) - { - /* Control transfers completed, Exit the State Machine */ - status = USBH_NOT_SUPPORTED; + } else { + if (URB_Status == USBH_URB_STALL) { + /* Control transfers completed, Exit the State Machine */ + status = USBH_NOT_SUPPORTED; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif + } } - } - break; - - case CTRL_STATUS_OUT: - USBH_CtlSendData (phost, - 0U, - 0U, - phost->Control.pipe_out, - 1U); - phost->Control.timer = (uint16_t)phost->Timer; - phost->Control.state = CTRL_STATUS_OUT_WAIT; - break; - - case CTRL_STATUS_OUT_WAIT: - - URB_Status = USBH_LL_GetURBState(phost , phost->Control.pipe_out); - if (URB_Status == USBH_URB_DONE) - { - status = USBH_OK; - phost->Control.state = CTRL_COMPLETE; + break; + + case CTRL_STATUS_OUT: + USBH_CtlSendData(phost, + 0U, + 0U, + phost->Control.pipe_out, + 1U); + phost->Control.timer = (uint16_t)phost->Timer; + phost->Control.state = CTRL_STATUS_OUT_WAIT; + break; + + case CTRL_STATUS_OUT_WAIT: + + URB_Status = USBH_LL_GetURBState(phost, phost->Control.pipe_out); + if (URB_Status == USBH_URB_DONE) { + status = USBH_OK; + phost->Control.state = CTRL_COMPLETE; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else if (URB_Status == USBH_URB_NOTREADY) - { - phost->Control.state = CTRL_STATUS_OUT; + } else if (URB_Status == USBH_URB_NOTREADY) { + phost->Control.state = CTRL_STATUS_OUT; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } - else - { - if (URB_Status == USBH_URB_ERROR) - { - phost->Control.state = CTRL_ERROR; + } else { + if (URB_Status == USBH_URB_ERROR) { + phost->Control.state = CTRL_ERROR; #if (USBH_USE_OS == 1U) - phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; + phost->os_msg = (uint32_t)USBH_CONTROL_EVENT; #if (osCMSIS < 0x20000U) - (void)osMessagePut(phost->os_event, phost->os_msg, 0U); + (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else - (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); + (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL); #endif #endif - } + } - } - break; - - case CTRL_ERROR: - /* - After a halt condition is encountered or an error is detected by the - host, a control endpoint is allowed to recover by accepting the next Setup - PID; i.e., recovery actions via some other pipe are not required for control - endpoints. For the Default Control Pipe, a device reset will ultimately be - required to clear the halt or error condition if the next Setup PID is not - accepted. - */ - if (++ phost->Control.errorcount <= USBH_MAX_ERROR_COUNT) - { - /* try to recover control */ - USBH_LL_Stop(phost); - - /* Do the transmission again, starting from SETUP Packet */ - phost->Control.state = CTRL_SETUP; - phost->RequestState = CMD_SEND; - } - else - { - phost->pUser(phost, HOST_USER_UNRECOVERED_ERROR); - phost->Control.errorcount = 0U; - USBH_ErrLog("Control error"); - status = USBH_FAIL; - } - break; + } + break; + + case CTRL_ERROR: + /* + After a halt condition is encountered or an error is detected by the + host, a control endpoint is allowed to recover by accepting the next Setup + PID; i.e., recovery actions via some other pipe are not required for control + endpoints. For the Default Control Pipe, a device reset will ultimately be + required to clear the halt or error condition if the next Setup PID is not + accepted. + */ + if (++ phost->Control.errorcount <= USBH_MAX_ERROR_COUNT) { + /* try to recover control */ + USBH_LL_Stop(phost); + + /* Do the transmission again, starting from SETUP Packet */ + phost->Control.state = CTRL_SETUP; + phost->RequestState = CMD_SEND; + } else { + phost->pUser(phost, HOST_USER_UNRECOVERED_ERROR); + phost->Control.errorcount = 0U; + USBH_ErrLog("Control error"); + status = USBH_FAIL; + } + break; - default: - break; + default: + break; } return status; } diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ioreq.c b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ioreq.c index 5ea2d1d4b5..8e2d0e35da 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ioreq.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ioreq.c @@ -90,19 +90,19 @@ * @param pipe_num: Pipe Number * @retval USBH Status */ -USBH_StatusTypeDef USBH_CtlSendSetup (USBH_HandleTypeDef *phost, - uint8_t *buff, - uint8_t pipe_num) +USBH_StatusTypeDef USBH_CtlSendSetup(USBH_HandleTypeDef *phost, + uint8_t *buff, + uint8_t pipe_num) { - USBH_LL_SubmitURB (phost, /* Driver handle */ - pipe_num, /* Pipe index */ - 0U, /* Direction : OUT */ - USBH_EP_CONTROL, /* EP type */ - USBH_PID_SETUP, /* Type setup */ - buff, /* data buffer */ - USBH_SETUP_PKT_SIZE, /* data length */ - 0U); + USBH_LL_SubmitURB(phost, /* Driver handle */ + pipe_num, /* Pipe index */ + 0U, /* Direction : OUT */ + USBH_EP_CONTROL, /* EP type */ + USBH_PID_SETUP, /* Type setup */ + buff, /* data buffer */ + USBH_SETUP_PKT_SIZE, /* data length */ + 0U); return USBH_OK; } @@ -116,25 +116,24 @@ USBH_StatusTypeDef USBH_CtlSendSetup (USBH_HandleTypeDef *phost, * @param pipe_num: Pipe Number * @retval USBH Status */ -USBH_StatusTypeDef USBH_CtlSendData (USBH_HandleTypeDef *phost, - uint8_t *buff, - uint16_t length, - uint8_t pipe_num, - uint8_t do_ping ) +USBH_StatusTypeDef USBH_CtlSendData(USBH_HandleTypeDef *phost, + uint8_t *buff, + uint16_t length, + uint8_t pipe_num, + uint8_t do_ping) { - if(phost->device.speed != USBH_SPEED_HIGH) - { + if (phost->device.speed != USBH_SPEED_HIGH) { do_ping = 0U; } - USBH_LL_SubmitURB (phost, /* Driver handle */ - pipe_num, /* Pipe index */ - 0U, /* Direction : OUT */ - USBH_EP_CONTROL, /* EP type */ - USBH_PID_DATA, /* Type Data */ - buff, /* data buffer */ - length, /* data length */ - do_ping); /* do ping (HS Only)*/ + USBH_LL_SubmitURB(phost, /* Driver handle */ + pipe_num, /* Pipe index */ + 0U, /* Direction : OUT */ + USBH_EP_CONTROL, /* EP type */ + USBH_PID_DATA, /* Type Data */ + buff, /* data buffer */ + length, /* data length */ + do_ping); /* do ping (HS Only)*/ return USBH_OK; } @@ -150,18 +149,18 @@ USBH_StatusTypeDef USBH_CtlSendData (USBH_HandleTypeDef *phost, * @retval USBH Status. */ USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost, - uint8_t* buff, - uint16_t length, - uint8_t pipe_num) + uint8_t *buff, + uint16_t length, + uint8_t pipe_num) { - USBH_LL_SubmitURB (phost, /* Driver handle */ - pipe_num, /* Pipe index */ - 1U, /* Direction : IN */ - USBH_EP_CONTROL, /* EP type */ - USBH_PID_DATA, /* Type Data */ - buff, /* data buffer */ - length, /* data length */ - 0U); + USBH_LL_SubmitURB(phost, /* Driver handle */ + pipe_num, /* Pipe index */ + 1U, /* Direction : IN */ + USBH_EP_CONTROL, /* EP type */ + USBH_PID_DATA, /* Type Data */ + buff, /* data buffer */ + length, /* data length */ + 0U); return USBH_OK; } @@ -176,25 +175,24 @@ USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost, * @param pipe_num: Pipe Number * @retval USBH Status */ -USBH_StatusTypeDef USBH_BulkSendData (USBH_HandleTypeDef *phost, - uint8_t *buff, - uint16_t length, - uint8_t pipe_num, - uint8_t do_ping) +USBH_StatusTypeDef USBH_BulkSendData(USBH_HandleTypeDef *phost, + uint8_t *buff, + uint16_t length, + uint8_t pipe_num, + uint8_t do_ping) { - if(phost->device.speed != USBH_SPEED_HIGH) - { + if (phost->device.speed != USBH_SPEED_HIGH) { do_ping = 0U; } - USBH_LL_SubmitURB (phost, /* Driver handle */ - pipe_num, /* Pipe index */ - 0U, /* Direction : IN */ - USBH_EP_BULK, /* EP type */ - USBH_PID_DATA, /* Type Data */ - buff, /* data buffer */ - length, /* data length */ - do_ping); /* do ping (HS Only)*/ + USBH_LL_SubmitURB(phost, /* Driver handle */ + pipe_num, /* Pipe index */ + 0U, /* Direction : IN */ + USBH_EP_BULK, /* EP type */ + USBH_PID_DATA, /* Type Data */ + buff, /* data buffer */ + length, /* data length */ + do_ping); /* do ping (HS Only)*/ return USBH_OK; } @@ -209,18 +207,18 @@ USBH_StatusTypeDef USBH_BulkSendData (USBH_HandleTypeDef *phost, * @retval USBH Status. */ USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost, - uint8_t *buff, - uint16_t length, - uint8_t pipe_num) + uint8_t *buff, + uint16_t length, + uint8_t pipe_num) { - USBH_LL_SubmitURB (phost, /* Driver handle */ - pipe_num, /* Pipe index */ - 1U, /* Direction : IN */ - USBH_EP_BULK, /* EP type */ - USBH_PID_DATA, /* Type Data */ - buff, /* data buffer */ - length, /* data length */ - 0U); + USBH_LL_SubmitURB(phost, /* Driver handle */ + pipe_num, /* Pipe index */ + 1U, /* Direction : IN */ + USBH_EP_BULK, /* EP type */ + USBH_PID_DATA, /* Type Data */ + buff, /* data buffer */ + length, /* data length */ + 0U); return USBH_OK; } @@ -235,18 +233,18 @@ USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost, * @retval USBH Status. */ USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost, - uint8_t *buff, - uint8_t length, - uint8_t pipe_num) + uint8_t *buff, + uint8_t length, + uint8_t pipe_num) { - USBH_LL_SubmitURB (phost, /* Driver handle */ - pipe_num, /* Pipe index */ - 1U, /* Direction : IN */ - USBH_EP_INTERRUPT, /* EP type */ - USBH_PID_DATA, /* Type Data */ - buff, /* data buffer */ - (uint16_t)length, /* data length */ - 0U); + USBH_LL_SubmitURB(phost, /* Driver handle */ + pipe_num, /* Pipe index */ + 1U, /* Direction : IN */ + USBH_EP_INTERRUPT, /* EP type */ + USBH_PID_DATA, /* Type Data */ + buff, /* data buffer */ + (uint16_t)length, /* data length */ + 0U); return USBH_OK; } @@ -261,18 +259,18 @@ USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost, * @retval USBH Status. */ USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost, - uint8_t *buff, - uint8_t length, - uint8_t pipe_num) + uint8_t *buff, + uint8_t length, + uint8_t pipe_num) { - USBH_LL_SubmitURB (phost, /* Driver handle */ - pipe_num, /* Pipe index */ - 0U, /* Direction : OUT */ - USBH_EP_INTERRUPT, /* EP type */ - USBH_PID_DATA, /* Type Data */ - buff, /* data buffer */ - (uint16_t)length, /* data length */ - 0U); + USBH_LL_SubmitURB(phost, /* Driver handle */ + pipe_num, /* Pipe index */ + 0U, /* Direction : OUT */ + USBH_EP_INTERRUPT, /* EP type */ + USBH_PID_DATA, /* Type Data */ + buff, /* data buffer */ + (uint16_t)length, /* data length */ + 0U); return USBH_OK; } @@ -287,18 +285,18 @@ USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost, * @retval USBH Status. */ USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost, - uint8_t *buff, - uint32_t length, - uint8_t pipe_num) + uint8_t *buff, + uint32_t length, + uint8_t pipe_num) { - USBH_LL_SubmitURB (phost, /* Driver handle */ - pipe_num, /* Pipe index */ - 1U, /* Direction : IN */ - USBH_EP_ISO, /* EP type */ - USBH_PID_DATA, /* Type Data */ - buff, /* data buffer */ - (uint16_t)length, /* data length */ - 0U); + USBH_LL_SubmitURB(phost, /* Driver handle */ + pipe_num, /* Pipe index */ + 1U, /* Direction : IN */ + USBH_EP_ISO, /* EP type */ + USBH_PID_DATA, /* Type Data */ + buff, /* data buffer */ + (uint16_t)length, /* data length */ + 0U); return USBH_OK; @@ -314,18 +312,18 @@ USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost, * @retval USBH Status. */ USBH_StatusTypeDef USBH_IsocSendData(USBH_HandleTypeDef *phost, - uint8_t *buff, - uint32_t length, - uint8_t pipe_num) + uint8_t *buff, + uint32_t length, + uint8_t pipe_num) { - USBH_LL_SubmitURB (phost, /* Driver handle */ - pipe_num, /* Pipe index */ - 0U, /* Direction : OUT */ - USBH_EP_ISO, /* EP type */ - USBH_PID_DATA, /* Type Data */ - buff, /* data buffer */ - (uint16_t)length, /* data length */ - 0U); + USBH_LL_SubmitURB(phost, /* Driver handle */ + pipe_num, /* Pipe index */ + 0U, /* Direction : OUT */ + USBH_EP_ISO, /* EP type */ + USBH_PID_DATA, /* Type Data */ + buff, /* data buffer */ + (uint16_t)length, /* data length */ + 0U); return USBH_OK; } diff --git a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_pipes.c b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_pipes.c index 7dd5110cbe..bf5647582c 100644 --- a/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_pipes.c +++ b/system/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_pipes.c @@ -68,7 +68,7 @@ /** @defgroup USBH_PIPES_Private_Functions * @{ */ -static uint16_t USBH_GetFreePipe (USBH_HandleTypeDef *phost); +static uint16_t USBH_GetFreePipe(USBH_HandleTypeDef *phost); /** @@ -82,22 +82,22 @@ static uint16_t USBH_GetFreePipe (USBH_HandleTypeDef *phost); * @param mps: max pkt size * @retval USBH Status */ -USBH_StatusTypeDef USBH_OpenPipe (USBH_HandleTypeDef *phost, - uint8_t pipe_num, - uint8_t epnum, - uint8_t dev_address, - uint8_t speed, - uint8_t ep_type, - uint16_t mps) +USBH_StatusTypeDef USBH_OpenPipe(USBH_HandleTypeDef *phost, + uint8_t pipe_num, + uint8_t epnum, + uint8_t dev_address, + uint8_t speed, + uint8_t ep_type, + uint16_t mps) { USBH_LL_OpenPipe(phost, - pipe_num, - epnum, - dev_address, - speed, - ep_type, - mps); + pipe_num, + epnum, + dev_address, + speed, + ep_type, + mps); return USBH_OK; @@ -110,8 +110,8 @@ USBH_StatusTypeDef USBH_OpenPipe (USBH_HandleTypeDef *phost, * @param pipe_num: Pipe Number * @retval USBH Status */ -USBH_StatusTypeDef USBH_ClosePipe (USBH_HandleTypeDef *phost, - uint8_t pipe_num) +USBH_StatusTypeDef USBH_ClosePipe(USBH_HandleTypeDef *phost, + uint8_t pipe_num) { USBH_LL_ClosePipe(phost, pipe_num); @@ -127,15 +127,14 @@ USBH_StatusTypeDef USBH_ClosePipe (USBH_HandleTypeDef *phost, * @param ep_addr: End point for which the Pipe to be allocated * @retval Pipe number */ -uint8_t USBH_AllocPipe (USBH_HandleTypeDef *phost, uint8_t ep_addr) +uint8_t USBH_AllocPipe(USBH_HandleTypeDef *phost, uint8_t ep_addr) { uint16_t pipe; pipe = USBH_GetFreePipe(phost); - if (pipe != 0xFFFFU) - { - phost->Pipes[pipe] = 0x8000U | ep_addr; + if (pipe != 0xFFFFU) { + phost->Pipes[pipe] = 0x8000U | ep_addr; } return (uint8_t)pipe; } @@ -147,13 +146,12 @@ uint8_t USBH_AllocPipe (USBH_HandleTypeDef *phost, uint8_t ep_addr) * @param idx: Pipe number to be freed * @retval USBH Status */ -USBH_StatusTypeDef USBH_FreePipe (USBH_HandleTypeDef *phost, uint8_t idx) +USBH_StatusTypeDef USBH_FreePipe(USBH_HandleTypeDef *phost, uint8_t idx) { - if(idx < 11U) - { - phost->Pipes[idx] &= 0x7FFFU; - } - return USBH_OK; + if (idx < 11U) { + phost->Pipes[idx] &= 0x7FFFU; + } + return USBH_OK; } /** @@ -162,16 +160,14 @@ USBH_StatusTypeDef USBH_FreePipe (USBH_HandleTypeDef *phost, uint8_t idx) * Get a free Pipe number for allocation to a device endpoint * @retval idx: Free Pipe number */ -static uint16_t USBH_GetFreePipe (USBH_HandleTypeDef *phost) +static uint16_t USBH_GetFreePipe(USBH_HandleTypeDef *phost) { uint8_t idx = 0U; - for (idx = 0U ; idx < 11U ; idx++) - { - if ((phost->Pipes[idx] & 0x8000U) == 0U) - { - return (uint16_t)idx; - } + for (idx = 0U ; idx < 11U ; idx++) { + if ((phost->Pipes[idx] & 0x8000U) == 0U) { + return (uint16_t)idx; + } } return 0xFFFFU; }