first commit
This commit is contained in:
+235
@@ -0,0 +1,235 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_dfu.h
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief Header file for the usbd_dfu.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_DFU_H
|
||||
#define __USB_DFU_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DFU
|
||||
* @brief This file is the Header file for usbd_dfu.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_DFU_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define USB_DFU_CONFIG_DESC_SIZ (18 + (9 * USBD_DFU_MAX_ITF_NUM))
|
||||
#define USB_DFU_DESC_SIZ 9
|
||||
|
||||
#define DFU_DESCRIPTOR_TYPE 0x21
|
||||
|
||||
|
||||
/**************************************************/
|
||||
/* DFU Requests DFU states */
|
||||
/**************************************************/
|
||||
#define APP_STATE_IDLE 0
|
||||
#define APP_STATE_DETACH 1
|
||||
#define DFU_STATE_IDLE 2
|
||||
#define DFU_STATE_DNLOAD_SYNC 3
|
||||
#define DFU_STATE_DNLOAD_BUSY 4
|
||||
#define DFU_STATE_DNLOAD_IDLE 5
|
||||
#define DFU_STATE_MANIFEST_SYNC 6
|
||||
#define DFU_STATE_MANIFEST 7
|
||||
#define DFU_STATE_MANIFEST_WAIT_RESET 8
|
||||
#define DFU_STATE_UPLOAD_IDLE 9
|
||||
#define DFU_STATE_ERROR 10
|
||||
|
||||
/**************************************************/
|
||||
/* DFU errors */
|
||||
/**************************************************/
|
||||
#define DFU_ERROR_NONE 0x00
|
||||
#define DFU_ERROR_TARGET 0x01
|
||||
#define DFU_ERROR_FILE 0x02
|
||||
#define DFU_ERROR_WRITE 0x03
|
||||
#define DFU_ERROR_ERASE 0x04
|
||||
#define DFU_ERROR_CHECK_ERASED 0x05
|
||||
#define DFU_ERROR_PROG 0x06
|
||||
#define DFU_ERROR_VERIFY 0x07
|
||||
#define DFU_ERROR_ADDRESS 0x08
|
||||
#define DFU_ERROR_NOTDONE 0x09
|
||||
#define DFU_ERROR_FIRMWARE 0x0A
|
||||
#define DFU_ERROR_VENDOR 0x0B
|
||||
#define DFU_ERROR_USB 0x0C
|
||||
#define DFU_ERROR_POR 0x0D
|
||||
#define DFU_ERROR_UNKNOWN 0x0E
|
||||
#define DFU_ERROR_STALLEDPKT 0x0F
|
||||
|
||||
/**************************************************/
|
||||
/* DFU Manifestation State */
|
||||
/**************************************************/
|
||||
#define DFU_MANIFEST_COMPLETE 0x00
|
||||
#define DFU_MANIFEST_IN_PROGRESS 0x01
|
||||
|
||||
|
||||
/**************************************************/
|
||||
/* Special Commands with Download Request */
|
||||
/**************************************************/
|
||||
#define DFU_CMD_GETCOMMANDS 0x00
|
||||
#define DFU_CMD_SETADDRESSPOINTER 0x21
|
||||
#define DFU_CMD_ERASE 0x41
|
||||
|
||||
#define DFU_MEDIA_ERASE 0x00
|
||||
#define DFU_MEDIA_PROGRAM 0x01
|
||||
|
||||
/**************************************************/
|
||||
/* Other defines */
|
||||
/**************************************************/
|
||||
/* Bit Detach capable = bit 3 in bmAttributes field */
|
||||
#define DFU_DETACH_MASK (uint8_t)(1 << 4)
|
||||
#define DFU_STATUS_DEPTH (6)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DFU_DETACH = 0,
|
||||
DFU_DNLOAD ,
|
||||
DFU_UPLOAD,
|
||||
DFU_GETSTATUS,
|
||||
DFU_CLRSTATUS,
|
||||
DFU_GETSTATE,
|
||||
DFU_ABORT
|
||||
} DFU_RequestTypeDef;
|
||||
|
||||
typedef void (*pFunction)(void);
|
||||
|
||||
|
||||
/********** Descriptor of DFU interface 0 Alternate setting n ****************/
|
||||
#define USBD_DFU_IF_DESC(n) 0x09, /* bLength: Interface Descriptor size */ \
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
0x00, /* bInterfaceNumber: Number of Interface */ \
|
||||
(n), /* bAlternateSetting: Alternate setting */ \
|
||||
0x00, /* bNumEndpoints*/ \
|
||||
0xFE, /* bInterfaceClass: Application Specific Class Code */ \
|
||||
0x01, /* bInterfaceSubClass : Device Firmware Upgrade Code */ \
|
||||
0x02, /* nInterfaceProtocol: DFU mode protocol */ \
|
||||
USBD_IDX_INTERFACE_STR + (n) + 1 /* iInterface: Index of string descriptor */ \
|
||||
|
||||
#define TRANSFER_SIZE_BYTES(size) ((uint8_t)(size)), /* XFERSIZEB0 */\
|
||||
((uint8_t)(size >> 8)) /* XFERSIZEB1 */
|
||||
|
||||
#define IS_PROTECTED_AREA(add) (uint8_t)(((add >= 0x08000000) && (add < (APP_DEFAULT_ADD)))? 1:0)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
uint32_t d32[USBD_DFU_XFER_SIZE/4];
|
||||
uint8_t d8[USBD_DFU_XFER_SIZE];
|
||||
}buffer;
|
||||
|
||||
uint8_t dev_state;
|
||||
uint8_t dev_status[DFU_STATUS_DEPTH];
|
||||
uint8_t manif_state;
|
||||
|
||||
uint32_t wblock_num;
|
||||
uint32_t wlength;
|
||||
uint32_t data_ptr;
|
||||
__IO uint32_t alt_setting;
|
||||
|
||||
}
|
||||
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);
|
||||
uint16_t (* GetStatus)(uint32_t Add, uint8_t cmd, uint8_t *buff);
|
||||
}
|
||||
USBD_DFU_MediaTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_DFU;
|
||||
#define USBD_DFU_CLASS &USBD_DFU
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_DFU_RegisterMedia (USBD_HandleTypeDef *pdev,
|
||||
USBD_DFU_MediaTypeDef *fops);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_DFU_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_dfu_media_template.h
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief header file for the usbd_dfu_media_template.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_DFU_MEDIA_TEMPLATE_H
|
||||
#define __USBD_DFU_MEDIA_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_dfu.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MEDIA
|
||||
* @brief header file for the usbd_dfu_media_template.c file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MEDIA_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MEDIA_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_MEDIA_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MEDIA_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
extern USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MEDIA_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_DFU_MEDIA_TEMPLATE_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+1107
File diff suppressed because it is too large
Load Diff
+139
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_dfu_media_template.c
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief Memory management layer
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_dfu_media_template.h"
|
||||
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* 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_DeInit(void);
|
||||
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,
|
||||
|
||||
};
|
||||
/**
|
||||
* @brief MEM_If_Init
|
||||
* Memory initialization routine.
|
||||
* @param None
|
||||
* @retval 0 if operation is successful, MAL_FAIL else.
|
||||
*/
|
||||
uint16_t MEM_If_Init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MEM_If_DeInit
|
||||
* Memory deinitialization routine.
|
||||
* @param None
|
||||
* @retval 0 if operation is successful, MAL_FAIL else.
|
||||
*/
|
||||
uint16_t MEM_If_DeInit(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MEM_If_Erase
|
||||
* Erase sector.
|
||||
* @param Add: Address of sector to be erased.
|
||||
* @retval 0 if operation is successful, MAL_FAIL else.
|
||||
*/
|
||||
uint16_t MEM_If_Erase(uint32_t Add)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MEM_If_Write
|
||||
* Memory write routine.
|
||||
* @param Add: Address to be written to.
|
||||
* @param Len: Number of data to be written (in bytes).
|
||||
* @retval 0 if operation is successful, MAL_FAIL else.
|
||||
*/
|
||||
uint16_t MEM_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MEM_If_Read
|
||||
* Memory read routine.
|
||||
* @param Add: Address to be read from.
|
||||
* @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)
|
||||
{
|
||||
/* Return a valid address to avoid HardFault */
|
||||
return (uint8_t*)(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Flash_If_GetStatus
|
||||
* Memory read routine.
|
||||
* @param Add: Address to be read from.
|
||||
* @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)
|
||||
{
|
||||
switch (Cmd)
|
||||
{
|
||||
case DFU_MEDIA_PROGRAM:
|
||||
|
||||
break;
|
||||
|
||||
case DFU_MEDIA_ERASE:
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_conf_template.h
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief Header file for the usbd_conf_template.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_CONF_TEMPLATE_H
|
||||
#define __USBD_CONF_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32fxxx.h" /* replace 'stm32xxx' with your HAL driver header filename, ex: stm32f4xx.h */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CONF
|
||||
* @brief USB device low level driver configuration file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CONF_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define USBD_MAX_NUM_INTERFACES 1
|
||||
#define USBD_MAX_NUM_CONFIGURATION 1
|
||||
#define USBD_MAX_STR_DESC_SIZ 0x100
|
||||
#define USBD_SUPPORT_USER_STRING 0
|
||||
#define USBD_SELF_POWERED 1
|
||||
#define USBD_DEBUG_LEVEL 2
|
||||
|
||||
/* MSC Class Config */
|
||||
#define MSC_MEDIA_PACKET 8192
|
||||
|
||||
/* CDC Class Config */
|
||||
#define USBD_CDC_INTERVAL 2000
|
||||
|
||||
/* DFU Class Config */
|
||||
#define USBD_DFU_MAX_ITF_NUM 1
|
||||
#define USBD_DFU_XFERS_IZE 1024
|
||||
|
||||
/* AUDIO Class Config */
|
||||
#define USBD_AUDIO_FREQ 22100
|
||||
|
||||
/** @defgroup USBD_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Memory management macros */
|
||||
#define USBD_malloc malloc
|
||||
#define USBD_free free
|
||||
#define USBD_memset memset
|
||||
#define USBD_memcpy memcpy
|
||||
|
||||
/* DEBUG macros */
|
||||
|
||||
|
||||
#if (USBD_DEBUG_LEVEL > 0)
|
||||
#define USBD_UsrLog(...) printf(__VA_ARGS__);\
|
||||
printf("\n");
|
||||
#else
|
||||
#define USBD_UsrLog(...)
|
||||
#endif
|
||||
|
||||
|
||||
#if (USBD_DEBUG_LEVEL > 1)
|
||||
|
||||
#define USBD_ErrLog(...) printf("ERROR: ") ;\
|
||||
printf(__VA_ARGS__);\
|
||||
printf("\n");
|
||||
#else
|
||||
#define USBD_ErrLog(...)
|
||||
#endif
|
||||
|
||||
|
||||
#if (USBD_DEBUG_LEVEL > 2)
|
||||
#define USBD_DbgLog(...) printf("DEBUG : ") ;\
|
||||
printf(__VA_ARGS__);\
|
||||
printf("\n");
|
||||
#else
|
||||
#define USBD_DbgLog(...)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CONF_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CONF_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CONF_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CONF_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_CONF_TEMPLATE_H */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_core.h
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief Header file for usbd_core.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_CORE_H
|
||||
#define __USBD_CORE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_conf.h"
|
||||
#include "usbd_def.h"
|
||||
#include "usbd_ioreq.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE
|
||||
* @brief This file is the Header file for usbd_core.c file
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
#define USBD_SOF USBD_LL_SOF
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
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_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
|
||||
|
||||
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_Reset(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed);
|
||||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
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_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_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);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_CORE_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_req.h
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief Header file for the usbd_req.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_REQUEST_H
|
||||
#define __USB_REQUEST_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_def.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ
|
||||
* @brief header file for the usbd_req.c file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
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_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata);
|
||||
|
||||
void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_REQUEST_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+330
@@ -0,0 +1,330 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_def.h
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief General defines for the usb device library
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_DEF_H
|
||||
#define __USBD_DEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_conf.h"
|
||||
|
||||
/** @addtogroup STM32_USBD_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_DEF
|
||||
* @brief general defines for the usb device library file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_DEF_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
|
||||
#define USB_LEN_DEV_QUALIFIER_DESC 0x0A
|
||||
#define USB_LEN_DEV_DESC 0x12
|
||||
#define USB_LEN_CFG_DESC 0x09
|
||||
#define USB_LEN_IF_DESC 0x09
|
||||
#define USB_LEN_EP_DESC 0x07
|
||||
#define USB_LEN_OTG_DESC 0x03
|
||||
#define USB_LEN_LANGID_STR_DESC 0x04
|
||||
#define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09
|
||||
|
||||
#define USBD_IDX_LANGID_STR 0x00
|
||||
#define USBD_IDX_MFC_STR 0x01
|
||||
#define USBD_IDX_PRODUCT_STR 0x02
|
||||
#define USBD_IDX_SERIAL_STR 0x03
|
||||
#define USBD_IDX_CONFIG_STR 0x04
|
||||
#define USBD_IDX_INTERFACE_STR 0x05
|
||||
|
||||
#define USB_REQ_TYPE_STANDARD 0x00
|
||||
#define USB_REQ_TYPE_CLASS 0x20
|
||||
#define USB_REQ_TYPE_VENDOR 0x40
|
||||
#define USB_REQ_TYPE_MASK 0x60
|
||||
|
||||
#define USB_REQ_RECIPIENT_DEVICE 0x00
|
||||
#define USB_REQ_RECIPIENT_INTERFACE 0x01
|
||||
#define USB_REQ_RECIPIENT_ENDPOINT 0x02
|
||||
#define USB_REQ_RECIPIENT_MASK 0x03
|
||||
|
||||
#define USB_REQ_GET_STATUS 0x00
|
||||
#define USB_REQ_CLEAR_FEATURE 0x01
|
||||
#define USB_REQ_SET_FEATURE 0x03
|
||||
#define USB_REQ_SET_ADDRESS 0x05
|
||||
#define USB_REQ_GET_DESCRIPTOR 0x06
|
||||
#define USB_REQ_SET_DESCRIPTOR 0x07
|
||||
#define USB_REQ_GET_CONFIGURATION 0x08
|
||||
#define USB_REQ_SET_CONFIGURATION 0x09
|
||||
#define USB_REQ_GET_INTERFACE 0x0A
|
||||
#define USB_REQ_SET_INTERFACE 0x0B
|
||||
#define USB_REQ_SYNCH_FRAME 0x0C
|
||||
|
||||
#define USB_DESC_TYPE_DEVICE 1
|
||||
#define USB_DESC_TYPE_CONFIGURATION 2
|
||||
#define USB_DESC_TYPE_STRING 3
|
||||
#define USB_DESC_TYPE_INTERFACE 4
|
||||
#define USB_DESC_TYPE_ENDPOINT 5
|
||||
#define USB_DESC_TYPE_DEVICE_QUALIFIER 6
|
||||
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7
|
||||
#define USB_DESC_TYPE_BOS 0x0F
|
||||
|
||||
#define USB_CONFIG_REMOTE_WAKEUP 2
|
||||
#define USB_CONFIG_SELF_POWERED 1
|
||||
|
||||
#define USB_FEATURE_EP_HALT 0
|
||||
#define USB_FEATURE_REMOTE_WAKEUP 1
|
||||
#define USB_FEATURE_TEST_MODE 2
|
||||
|
||||
#define USB_DEVICE_CAPABITY_TYPE 0x10
|
||||
|
||||
#define USB_HS_MAX_PACKET_SIZE 512
|
||||
#define USB_FS_MAX_PACKET_SIZE 64
|
||||
#define USB_MAX_EP0_SIZE 64
|
||||
|
||||
/* Device Status */
|
||||
#define USBD_STATE_DEFAULT 1
|
||||
#define USBD_STATE_ADDRESSED 2
|
||||
#define USBD_STATE_CONFIGURED 3
|
||||
#define USBD_STATE_SUSPENDED 4
|
||||
|
||||
|
||||
/* EP0 State */
|
||||
#define USBD_EP0_IDLE 0
|
||||
#define USBD_EP0_SETUP 1
|
||||
#define USBD_EP0_DATA_IN 2
|
||||
#define USBD_EP0_DATA_OUT 3
|
||||
#define USBD_EP0_STATUS_IN 4
|
||||
#define USBD_EP0_STATUS_OUT 5
|
||||
#define USBD_EP0_STALL 6
|
||||
|
||||
#define USBD_EP_TYPE_CTRL 0
|
||||
#define USBD_EP_TYPE_ISOC 1
|
||||
#define USBD_EP_TYPE_BULK 2
|
||||
#define USBD_EP_TYPE_INTR 3
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_DEF_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct usb_setup_req
|
||||
{
|
||||
|
||||
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 );
|
||||
/* 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 *(*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 == 1)
|
||||
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev ,uint8_t index, uint16_t *length);
|
||||
#endif
|
||||
|
||||
} USBD_ClassTypeDef;
|
||||
|
||||
/* Following USB Device Speed */
|
||||
typedef enum
|
||||
{
|
||||
USBD_SPEED_HIGH = 0,
|
||||
USBD_SPEED_FULL = 1,
|
||||
USBD_SPEED_LOW = 2,
|
||||
}USBD_SpeedTypeDef;
|
||||
|
||||
/* Following USB Device status */
|
||||
typedef enum {
|
||||
USBD_OK = 0,
|
||||
USBD_BUSY,
|
||||
USBD_FAIL,
|
||||
}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);
|
||||
#if (USBD_LPM_ENABLED == 1)
|
||||
uint8_t *(*GetBOSDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
||||
#endif
|
||||
} USBD_DescriptorsTypeDef;
|
||||
|
||||
/* USB Device handle structure */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t status;
|
||||
uint32_t total_length;
|
||||
uint32_t rem_length;
|
||||
uint32_t maxpacket;
|
||||
} USBD_EndpointTypeDef;
|
||||
|
||||
/* USB Device handle structure */
|
||||
typedef struct _USBD_HandleTypeDef
|
||||
{
|
||||
uint8_t id;
|
||||
uint32_t dev_config;
|
||||
uint32_t dev_default_config;
|
||||
uint32_t dev_config_status;
|
||||
USBD_SpeedTypeDef dev_speed;
|
||||
USBD_EndpointTypeDef ep_in[15];
|
||||
USBD_EndpointTypeDef ep_out[15];
|
||||
uint32_t ep0_state;
|
||||
uint32_t ep0_data_len;
|
||||
uint8_t dev_state;
|
||||
uint8_t dev_old_state;
|
||||
uint8_t dev_address;
|
||||
uint8_t dev_connection_status;
|
||||
uint8_t dev_test_mode;
|
||||
uint32_t dev_remote_wakeup;
|
||||
|
||||
USBD_SetupReqTypedef request;
|
||||
USBD_DescriptorsTypeDef *pDesc;
|
||||
USBD_ClassTypeDef *pClass;
|
||||
void *pClassData;
|
||||
void *pUserData;
|
||||
void *pData;
|
||||
} USBD_HandleTypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_DEF_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
#define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \
|
||||
(((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8))
|
||||
|
||||
#define LOBYTE(x) ((uint8_t)(x & 0x00FF))
|
||||
#define HIBYTE(x) ((uint8_t)((x & 0xFF00) >>8))
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
#ifndef __weak
|
||||
#define __weak __attribute__((weak))
|
||||
#endif /* __weak */
|
||||
#ifndef __packed
|
||||
#define __packed __attribute__((__packed__))
|
||||
#endif /* __packed */
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
|
||||
/* In HS mode and when the DMA is used, all variables and data structures dealing
|
||||
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
|
||||
#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 */
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DEF_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DEF_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_DEF_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ioreq.h
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief Header file for the usbd_ioreq.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_IOREQ_H
|
||||
#define __USBD_IOREQ_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_def.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ
|
||||
* @brief header file for the usbd_ioreq.c file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *buf,
|
||||
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_CtlContinueRx (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint16_t USBD_GetRxCount (USBD_HandleTypeDef *pdev ,
|
||||
uint8_t epnum);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_IOREQ_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_conf_template.c
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief USB Device configuration and interface file
|
||||
* This template should be copied to the user folder, renamed and customized
|
||||
* following user needs.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_core.h"
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Initializes the Low Level portion of the Device driver.
|
||||
* @param pdev: Device handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-Initializes the Low Level portion of the Device driver.
|
||||
* @param pdev: Device handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Starts the Low Level portion of the Device driver.
|
||||
* @param pdev: Device handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stops the Low Level portion of the Device driver.
|
||||
* @param pdev: Device handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Opens an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @param ep_type: Endpoint Type
|
||||
* @param ep_mps: Endpoint Max Packet Size
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr,
|
||||
uint8_t ep_type,
|
||||
uint16_t ep_mps)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Closes an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Flushes an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a Stall condition on an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears a Stall condition on an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns Stall condition.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval Stall (1: Yes, 0: No)
|
||||
*/
|
||||
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assigns a USB address to the device.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Transmits data over an endpoint.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @param pbuf: Pointer to data to be sent
|
||||
* @param size: Data size
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr,
|
||||
uint8_t *pbuf,
|
||||
uint16_t size)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Prepares an endpoint for reception.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @param pbuf: Pointer to data to be received
|
||||
* @param size: Data size
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr,
|
||||
uint8_t *pbuf,
|
||||
uint16_t size)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the last transferred packet size.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval Recived Data Size
|
||||
*/
|
||||
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delays routine for the USB Device Library.
|
||||
* @param Delay: Delay in ms
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_LL_Delay(uint32_t Delay)
|
||||
{
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
+569
@@ -0,0 +1,569 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_core.c
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief This file provides all the USBD core functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup STM32_USBD_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_Init
|
||||
* Initializes the device stack and load the class driver
|
||||
* @param pdev: device instance
|
||||
* @param pdesc: Descriptor structure address
|
||||
* @param id: Low level core index
|
||||
* @retval None
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id)
|
||||
{
|
||||
/* Check whether the USB Host handle is valid */
|
||||
if(pdev == NULL)
|
||||
{
|
||||
USBD_ErrLog("Invalid Device handle");
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
/* Unlink previous class*/
|
||||
if(pdev->pClass != NULL)
|
||||
{
|
||||
pdev->pClass = NULL;
|
||||
}
|
||||
|
||||
/* Assign USBD Descriptors */
|
||||
if(pdesc != NULL)
|
||||
{
|
||||
pdev->pDesc = pdesc;
|
||||
}
|
||||
|
||||
/* Set Device initial State */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
pdev->id = id;
|
||||
/* Initialize low level driver */
|
||||
USBD_LL_Init(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DeInit
|
||||
* Re-Initialize th device library
|
||||
* @param pdev: device instance
|
||||
* @retval status: status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Set Default State */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
|
||||
/* Free Class Resources */
|
||||
pdev->pClass->DeInit(pdev, pdev->dev_config);
|
||||
|
||||
/* Stop the low level driver */
|
||||
USBD_LL_Stop(pdev);
|
||||
|
||||
/* Initialize low level driver */
|
||||
USBD_LL_DeInit(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_RegisterClass
|
||||
* Link class driver to Device Core.
|
||||
* @param pDevice : Device Handle
|
||||
* @param pclass: Class handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass)
|
||||
{
|
||||
USBD_StatusTypeDef status = USBD_OK;
|
||||
if(pclass != 0)
|
||||
{
|
||||
/* link the class to the USB Device handle */
|
||||
pdev->pClass = pclass;
|
||||
status = USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_ErrLog("Invalid Class handle");
|
||||
status = USBD_FAIL;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Start
|
||||
* Start the USB Device Core.
|
||||
* @param pdev: Device Handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
/* Start the low level driver */
|
||||
USBD_LL_Start(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Stop
|
||||
* Stop the USB Device Core.
|
||||
* @param pdev: Device Handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Free Class Resources */
|
||||
pdev->pClass->DeInit(pdev, pdev->dev_config);
|
||||
|
||||
/* Stop the low level driver */
|
||||
USBD_LL_Stop(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_RunTestMode
|
||||
* Launch test mode process
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_SetClassConfig
|
||||
* Configure device and start the interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: configuration index
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_FAIL;
|
||||
|
||||
if(pdev->pClass != NULL)
|
||||
{
|
||||
/* Set configuration and Start the Class*/
|
||||
if(pdev->pClass->Init(pdev, cfgidx) == 0)
|
||||
{
|
||||
ret = USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (1) { asm("nop"); }
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_ClrClassConfig
|
||||
* Clear current configuration
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: configuration index
|
||||
* @retval status: USBD_StatusTypeDef
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
/* Clear configuration and De-initialize the Class process*/
|
||||
pdev->pClass->DeInit(pdev, cfgidx);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_SetupStage
|
||||
* Handle the setup stage
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup)
|
||||
{
|
||||
|
||||
USBD_ParseSetupRequest(&pdev->request, psetup);
|
||||
|
||||
pdev->ep0_state = USBD_EP0_SETUP;
|
||||
pdev->ep0_data_len = pdev->request.wLength;
|
||||
|
||||
switch (pdev->request.bmRequest & 0x1F)
|
||||
{
|
||||
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_ENDPOINT:
|
||||
USBD_StdEPReq(pdev, &pdev->request);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_LL_StallEP(pdev , pdev->request.bmRequest & 0x80);
|
||||
break;
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DataOutStage
|
||||
* Handle data OUT stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata)
|
||||
{
|
||||
USBD_EndpointTypeDef *pep;
|
||||
|
||||
if(epnum == 0)
|
||||
{
|
||||
pep = &pdev->ep_out[0];
|
||||
|
||||
if ( pdev->ep0_state == USBD_EP0_DATA_OUT)
|
||||
{
|
||||
if(pep->rem_length > pep->maxpacket)
|
||||
{
|
||||
pep->rem_length -= pep->maxpacket;
|
||||
|
||||
USBD_CtlContinueRx (pdev,
|
||||
pdata,
|
||||
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->pClass->DataOut != NULL)&&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
{
|
||||
pdev->pClass->DataOut(pdev, epnum);
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DataInStage
|
||||
* Handle data in stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev ,uint8_t epnum, uint8_t *pdata)
|
||||
{
|
||||
USBD_EndpointTypeDef *pep;
|
||||
|
||||
if(epnum == 0)
|
||||
{
|
||||
pep = &pdev->ep_in[0];
|
||||
|
||||
if ( pdev->ep0_state == USBD_EP0_DATA_IN)
|
||||
{
|
||||
if(pep->rem_length > pep->maxpacket)
|
||||
{
|
||||
pep->rem_length -= pep->maxpacket;
|
||||
|
||||
USBD_CtlContinueSendData (pdev,
|
||||
pdata,
|
||||
pep->rem_length);
|
||||
|
||||
/* Prepare endpoint for premature end of transfer */
|
||||
USBD_LL_PrepareReceive (pdev,
|
||||
0,
|
||||
NULL,
|
||||
0);
|
||||
}
|
||||
else
|
||||
{ /* last packet is MPS multiple, so send ZLP packet */
|
||||
if((pep->total_length % pep->maxpacket == 0) &&
|
||||
(pep->total_length >= pep->maxpacket) &&
|
||||
(pep->total_length < pdev->ep0_data_len ))
|
||||
{
|
||||
|
||||
USBD_CtlContinueSendData(pdev , NULL, 0);
|
||||
pdev->ep0_data_len = 0;
|
||||
|
||||
/* Prepare endpoint for premature end of transfer */
|
||||
USBD_LL_PrepareReceive (pdev,
|
||||
0,
|
||||
NULL,
|
||||
0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if((pdev->pClass->EP0_TxSent != NULL)&&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
{
|
||||
pdev->pClass->EP0_TxSent(pdev);
|
||||
}
|
||||
USBD_CtlReceiveStatus(pdev);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pdev->dev_test_mode == 1)
|
||||
{
|
||||
USBD_RunTestMode(pdev);
|
||||
pdev->dev_test_mode = 0;
|
||||
}
|
||||
}
|
||||
else if((pdev->pClass->DataIn != NULL)&&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
{
|
||||
pdev->pClass->DataIn(pdev, epnum);
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_LL_Reset
|
||||
* Handle Reset event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Open EP0 OUT */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
0x00,
|
||||
USBD_EP_TYPE_CTRL,
|
||||
USB_MAX_EP0_SIZE);
|
||||
|
||||
pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE;
|
||||
|
||||
/* Open EP0 IN */
|
||||
USBD_LL_OpenEP(pdev,
|
||||
0x80,
|
||||
USBD_EP_TYPE_CTRL,
|
||||
USB_MAX_EP0_SIZE);
|
||||
|
||||
pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE;
|
||||
/* Upon Reset call user call back */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
|
||||
if (pdev->pClassData)
|
||||
pdev->pClass->DeInit(pdev, pdev->dev_config);
|
||||
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_LL_Reset
|
||||
* Handle Reset event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed)
|
||||
{
|
||||
pdev->dev_speed = speed;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Suspend
|
||||
* Handle Suspend event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
pdev->dev_old_state = pdev->dev_state;
|
||||
pdev->dev_state = USBD_STATE_SUSPENDED;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Resume
|
||||
* Handle Resume event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
pdev->dev_state = pdev->dev_old_state;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_SOF
|
||||
* Handle SOF event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
if(pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if(pdev->pClass->SOF != NULL)
|
||||
{
|
||||
pdev->pClass->SOF(pdev);
|
||||
}
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_IsoINIncomplete
|
||||
* Handle iso in incomplete event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_IsoOUTIncomplete
|
||||
* Handle iso out incomplete event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DevConnected
|
||||
* Handle device connection event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DevDisconnected
|
||||
* Handle device disconnection event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Free Class Resources */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
pdev->pClass->DeInit(pdev, pdev->dev_config);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
+782
@@ -0,0 +1,782 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_req.c
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief This file provides the standard USB requests following chapter 9.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ctlreq.h"
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ
|
||||
* @brief USB standard requests module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_SetAddress(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_SetConfig(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_GetConfig(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_GetStatus(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_SetFeature(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t USBD_GetLen(uint8_t *buf);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_StdDevReq
|
||||
* Handle standard usb device requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
|
||||
USBD_GetDescriptor (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_GET_CONFIGURATION:
|
||||
USBD_GetConfig (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_CLEAR_FEATURE:
|
||||
USBD_ClrFeature (pdev , req);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_StdItfReq
|
||||
* Handle standard usb interface requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_CONFIGURED:
|
||||
|
||||
if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES)
|
||||
{
|
||||
pdev->pClass->Setup (pdev, req);
|
||||
|
||||
if((req->wLength == 0)&& (ret == USBD_OK))
|
||||
{
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev , req);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_StdEPReq
|
||||
* Handle standard usb endpoint requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req)
|
||||
{
|
||||
|
||||
uint8_t ep_addr;
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
USBD_EndpointTypeDef *pep;
|
||||
ep_addr = LOBYTE(req->wIndex);
|
||||
|
||||
/* Check if it is a class request */
|
||||
if ((req->bmRequest & 0x60) == 0x20)
|
||||
{
|
||||
pdev->pClass->Setup (pdev, req);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
switch (req->bRequest)
|
||||
{
|
||||
|
||||
case USB_REQ_SET_FEATURE :
|
||||
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if ((ep_addr != 0x00) && (ep_addr != 0x80))
|
||||
{
|
||||
USBD_LL_StallEP(pdev , ep_addr);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (req->wValue == USB_FEATURE_EP_HALT)
|
||||
{
|
||||
if ((ep_addr != 0x00) && (ep_addr != 0x80))
|
||||
{
|
||||
USBD_LL_StallEP(pdev , ep_addr);
|
||||
|
||||
}
|
||||
}
|
||||
pdev->pClass->Setup (pdev, req);
|
||||
USBD_CtlSendStatus(pdev);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE :
|
||||
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if ((ep_addr != 0x00) && (ep_addr != 0x80))
|
||||
{
|
||||
USBD_LL_StallEP(pdev , ep_addr);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (req->wValue == USB_FEATURE_EP_HALT)
|
||||
{
|
||||
if ((ep_addr & 0x7F) != 0x00)
|
||||
{
|
||||
USBD_LL_ClearStallEP(pdev , ep_addr);
|
||||
pdev->pClass->Setup (pdev, req);
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_STATUS:
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if ((ep_addr & 0x7F) != 0x00)
|
||||
{
|
||||
USBD_LL_StallEP(pdev , ep_addr);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
pep = ((ep_addr & 0x80) == 0x80) ? &pdev->ep_in[ep_addr & 0x7F]:\
|
||||
&pdev->ep_out[ep_addr & 0x7F];
|
||||
if(USBD_LL_IsStallEP(pdev, ep_addr))
|
||||
{
|
||||
pep->status = 0x0001;
|
||||
}
|
||||
else
|
||||
{
|
||||
pep->status = 0x0000;
|
||||
}
|
||||
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&pep->status,
|
||||
2);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_GetDescriptor
|
||||
* Handle Get Descriptor requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
uint16_t len;
|
||||
uint8_t *pbuf;
|
||||
|
||||
|
||||
switch (req->wValue >> 8)
|
||||
{
|
||||
#if (USBD_LPM_ENABLED == 1)
|
||||
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);
|
||||
break;
|
||||
|
||||
case USBD_IDX_MFC_STR:
|
||||
pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len);
|
||||
break;
|
||||
|
||||
case USBD_IDX_PRODUCT_STR:
|
||||
pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len);
|
||||
break;
|
||||
|
||||
case USBD_IDX_SERIAL_STR:
|
||||
pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len);
|
||||
break;
|
||||
|
||||
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 == 1)
|
||||
pbuf = pdev->pClass->GetUsrStrDescriptor(pdev, (req->wValue) , &len);
|
||||
break;
|
||||
#else
|
||||
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_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 != 0)&& (req->wLength != 0))
|
||||
{
|
||||
|
||||
len = MIN(len , req->wLength);
|
||||
|
||||
USBD_CtlSendData (pdev,
|
||||
pbuf,
|
||||
len);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_SetAddress
|
||||
* Set device address
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetAddress(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
uint8_t dev_addr;
|
||||
|
||||
if ((req->wIndex == 0) && (req->wLength == 0))
|
||||
{
|
||||
dev_addr = (uint8_t)(req->wValue) & 0x7F;
|
||||
|
||||
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 != 0)
|
||||
{
|
||||
pdev->dev_state = USBD_STATE_ADDRESSED;
|
||||
}
|
||||
else
|
||||
{
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev , req);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_SetConfig
|
||||
* Handle Set device configuration request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetConfig(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
|
||||
static uint8_t cfgidx;
|
||||
|
||||
cfgidx = (uint8_t)(req->wValue);
|
||||
|
||||
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;
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (cfgidx == 0)
|
||||
{
|
||||
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 , 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);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_GetConfig
|
||||
* Handle Get device configuration request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_GetConfig(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
|
||||
if (req->wLength != 1)
|
||||
{
|
||||
USBD_CtlError(pdev , req);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (pdev->dev_state )
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
pdev->dev_default_config = 0;
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&pdev->dev_default_config,
|
||||
1);
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&pdev->dev_config,
|
||||
1);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_GetStatus
|
||||
* Handle Get Status request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_GetStatus(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
|
||||
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
case USBD_STATE_CONFIGURED:
|
||||
|
||||
#if ( USBD_SELF_POWERED == 1)
|
||||
pdev->dev_config_status = USB_CONFIG_SELF_POWERED;
|
||||
#else
|
||||
pdev->dev_config_status = 0;
|
||||
#endif
|
||||
|
||||
if (pdev->dev_remote_wakeup)
|
||||
{
|
||||
pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP;
|
||||
}
|
||||
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)& pdev->dev_config_status,
|
||||
2);
|
||||
break;
|
||||
|
||||
default :
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_SetFeature
|
||||
* Handle Set device feature request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetFeature(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
|
||||
if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
|
||||
{
|
||||
pdev->dev_remote_wakeup = 1;
|
||||
pdev->pClass->Setup (pdev, req);
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_ClrFeature
|
||||
* Handle clear device feature request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
|
||||
{
|
||||
pdev->dev_remote_wakeup = 0;
|
||||
pdev->pClass->Setup (pdev, req);
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
USBD_CtlError(pdev , req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_ParseSetupRequest
|
||||
* Copy buffer into setup structure
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlError
|
||||
* Handle USB low level Error
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void USBD_CtlError( USBD_HandleTypeDef *pdev ,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_LL_StallEP(pdev , 0x80);
|
||||
USBD_LL_StallEP(pdev , 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_GetString
|
||||
* Convert Ascii string into unicode one
|
||||
* @param desc : descriptor buffer
|
||||
* @param unicode : Formatted string buffer (unicode)
|
||||
* @param len : descriptor length
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
|
||||
{
|
||||
uint8_t idx = 0;
|
||||
|
||||
if (desc != NULL)
|
||||
{
|
||||
*len = USBD_GetLen(desc) * 2 + 2;
|
||||
unicode[idx++] = *len;
|
||||
unicode[idx++] = USB_DESC_TYPE_STRING;
|
||||
|
||||
while (*desc != '\0')
|
||||
{
|
||||
unicode[idx++] = *desc++;
|
||||
unicode[idx++] = 0x00;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_GetLen
|
||||
* return the string length
|
||||
* @param buf : pointer to the ascii string buffer
|
||||
* @retval string length
|
||||
*/
|
||||
static uint8_t USBD_GetLen(uint8_t *buf)
|
||||
{
|
||||
uint8_t len = 0;
|
||||
|
||||
while (*buf != '\0')
|
||||
{
|
||||
len++;
|
||||
buf++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+236
@@ -0,0 +1,236 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ioreq.c
|
||||
* @author MCD Application Team
|
||||
* @version V2.4.2
|
||||
* @date 11-December-2015
|
||||
* @brief This file provides the IO requests APIs for control endpoints.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ
|
||||
* @brief control I/O requests module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlSendData
|
||||
* send data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be sent
|
||||
* @retval status
|
||||
*/
|
||||
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, 0x00, pbuf, len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlContinueSendData
|
||||
* continue sending data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be sent
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len)
|
||||
{
|
||||
/* Start the next transfer */
|
||||
USBD_LL_Transmit (pdev, 0x00, pbuf, len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlPrepareRx
|
||||
* receive data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be received
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len)
|
||||
{
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_DATA_OUT;
|
||||
pdev->ep_out[0].total_length = len;
|
||||
pdev->ep_out[0].rem_length = len;
|
||||
/* Start the transfer */
|
||||
USBD_LL_PrepareReceive (pdev,
|
||||
0,
|
||||
pbuf,
|
||||
len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlContinueRx
|
||||
* continue receive data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be received
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len)
|
||||
{
|
||||
|
||||
USBD_LL_PrepareReceive (pdev,
|
||||
0,
|
||||
pbuf,
|
||||
len);
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_CtlSendStatus
|
||||
* send zero lzngth packet on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_STATUS_IN;
|
||||
|
||||
/* Start the transfer */
|
||||
USBD_LL_Transmit (pdev, 0x00, NULL, 0);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlReceiveStatus
|
||||
* receive zero lzngth packet on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_STATUS_OUT;
|
||||
|
||||
/* Start the transfer */
|
||||
USBD_LL_PrepareReceive ( pdev,
|
||||
0,
|
||||
NULL,
|
||||
0);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_GetRxCount
|
||||
* returns the received data length
|
||||
* @param pdev: device instance
|
||||
* @param ep_addr: endpoint address
|
||||
* @retval Rx Data blength
|
||||
*/
|
||||
uint16_t USBD_GetRxCount (USBD_HandleTypeDef *pdev , uint8_t ep_addr)
|
||||
{
|
||||
return USBD_LL_GetRxDataSize(pdev, ep_addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+233
@@ -0,0 +1,233 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_msc.h
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file contains all the prototypes for the usbh_msc.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive ----------------------------------------------*/
|
||||
#ifndef __USBH_MSC_H
|
||||
#define __USBH_MSC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_msc_bot.h"
|
||||
#include "usbh_msc_scsi.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_MSC_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_CORE
|
||||
* @brief This file is the Header file for usbh_msc.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_CORE_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MSC_INIT = 0,
|
||||
MSC_IDLE,
|
||||
MSC_TEST_UNIT_READY,
|
||||
MSC_READ_CAPACITY10,
|
||||
MSC_READ_INQUIRY,
|
||||
MSC_REQUEST_SENSE,
|
||||
MSC_READ,
|
||||
MSC_WRITE,
|
||||
MSC_UNRECOVERED_ERROR,
|
||||
MSC_PERIODIC_CHECK,
|
||||
}
|
||||
MSC_StateTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MSC_OK,
|
||||
MSC_NOT_READY,
|
||||
MSC_ERROR,
|
||||
|
||||
}
|
||||
MSC_ErrorTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MSC_REQ_IDLE = 0,
|
||||
MSC_REQ_RESET,
|
||||
MSC_REQ_GET_MAX_LUN,
|
||||
MSC_REQ_ERROR,
|
||||
}
|
||||
MSC_ReqStateTypeDef;
|
||||
|
||||
#ifndef MAX_SUPPORTED_LUN
|
||||
#define MAX_SUPPORTED_LUN 2
|
||||
#endif
|
||||
|
||||
|
||||
/* Structure for LUN */
|
||||
typedef struct
|
||||
{
|
||||
MSC_StateTypeDef state;
|
||||
MSC_ErrorTypeDef error;
|
||||
USBH_StatusTypeDef prev_ready_state;
|
||||
SCSI_CapacityTypeDef capacity;
|
||||
SCSI_SenseTypeDef sense;
|
||||
SCSI_StdInquiryDataTypeDef inquiry;
|
||||
uint8_t state_changed;
|
||||
|
||||
}
|
||||
MSC_LUNTypeDef;
|
||||
|
||||
/* Structure for MSC process */
|
||||
typedef struct _MSC_Process
|
||||
{
|
||||
uint32_t max_lun;
|
||||
uint8_t InPipe;
|
||||
uint8_t OutPipe;
|
||||
uint8_t OutEp;
|
||||
uint8_t InEp;
|
||||
uint16_t OutEpSize;
|
||||
uint16_t InEpSize;
|
||||
MSC_StateTypeDef state;
|
||||
MSC_ErrorTypeDef error;
|
||||
MSC_ReqStateTypeDef req_state;
|
||||
MSC_ReqStateTypeDef prev_req_state;
|
||||
BOT_HandleTypeDef hbot;
|
||||
MSC_LUNTypeDef unit[MAX_SUPPORTED_LUN];
|
||||
uint16_t current_lun;
|
||||
uint16_t rw_lun;
|
||||
uint32_t timer;
|
||||
}
|
||||
MSC_HandleTypeDef;
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_CORE_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define USB_REQ_BOT_RESET 0xFF
|
||||
#define USB_REQ_GET_MAX_LUN 0xFE
|
||||
|
||||
|
||||
/* MSC Class Codes */
|
||||
#define USB_MSC_CLASS 0x08
|
||||
|
||||
/* Interface Descriptor field values for HID Boot Protocol */
|
||||
#define MSC_BOT 0x50
|
||||
#define MSC_TRANSPARENT 0x06
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
extern USBH_ClassTypeDef USBH_msc;
|
||||
#define USBH_MSC_CLASS &USBH_msc
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_CORE_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Common APIs */
|
||||
uint8_t USBH_MSC_IsReady (USBH_HandleTypeDef *phost);
|
||||
|
||||
/* APIs for LUN */
|
||||
int8_t USBH_MSC_GetMaxLUN (USBH_HandleTypeDef *phost);
|
||||
|
||||
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);
|
||||
|
||||
USBH_StatusTypeDef USBH_MSC_Write(USBH_HandleTypeDef *phost,
|
||||
uint8_t lun,
|
||||
uint32_t address,
|
||||
uint8_t *pbuf,
|
||||
uint32_t length);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBH_MSC_H */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
|
||||
+241
@@ -0,0 +1,241 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_msc_bot.h
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief Header file for usbh_msc_bot.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive ----------------------------------------------*/
|
||||
#ifndef __USBH_MSC_BOT_H
|
||||
#define __USBH_MSC_BOT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_msc_bot.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_MSC_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_BOT
|
||||
* @brief This file is the Header file for usbh_msc_bot.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_BOT_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
BOT_OK = 0,
|
||||
BOT_FAIL = 1,
|
||||
BOT_PHASE_ERROR = 2,
|
||||
BOT_BUSY = 3
|
||||
}
|
||||
BOT_StatusTypeDef;
|
||||
|
||||
typedef enum {
|
||||
BOT_CMD_IDLE = 0,
|
||||
BOT_CMD_SEND,
|
||||
BOT_CMD_WAIT,
|
||||
}
|
||||
BOT_CMDStateTypeDef;
|
||||
|
||||
/* CSW Status Definitions */
|
||||
typedef enum
|
||||
{
|
||||
|
||||
BOT_CSW_CMD_PASSED = 0x00,
|
||||
BOT_CSW_CMD_FAILED = 0x01,
|
||||
BOT_CSW_PHASE_ERROR = 0x02,
|
||||
}
|
||||
BOT_CSWStatusTypeDef;
|
||||
|
||||
typedef enum {
|
||||
BOT_SEND_CBW = 1,
|
||||
BOT_SEND_CBW_WAIT,
|
||||
BOT_DATA_IN,
|
||||
BOT_DATA_IN_WAIT,
|
||||
BOT_DATA_OUT,
|
||||
BOT_DATA_OUT_WAIT,
|
||||
BOT_RECEIVE_CSW,
|
||||
BOT_RECEIVE_CSW_WAIT,
|
||||
BOT_ERROR_IN,
|
||||
BOT_ERROR_OUT,
|
||||
BOT_UNRECOVERED_ERROR
|
||||
}
|
||||
BOT_StateTypeDef;
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct __CBW
|
||||
{
|
||||
uint32_t Signature;
|
||||
uint32_t Tag;
|
||||
uint32_t DataTransferLength;
|
||||
uint8_t Flags;
|
||||
uint8_t LUN;
|
||||
uint8_t CBLength;
|
||||
uint8_t CB[16];
|
||||
}field;
|
||||
uint8_t data[31];
|
||||
}
|
||||
BOT_CBWTypeDef;
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct __CSW
|
||||
{
|
||||
uint32_t Signature;
|
||||
uint32_t Tag;
|
||||
uint32_t DataResidue;
|
||||
uint8_t Status;
|
||||
}field;
|
||||
uint8_t data[13];
|
||||
}
|
||||
BOT_CSWTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t data[16];
|
||||
BOT_StateTypeDef state;
|
||||
BOT_StateTypeDef prev_state;
|
||||
BOT_CMDStateTypeDef cmd_state;
|
||||
BOT_CBWTypeDef cbw;
|
||||
uint8_t Reserved1;
|
||||
BOT_CSWTypeDef csw;
|
||||
uint8_t Reserved2[3];
|
||||
uint8_t *pbuf;
|
||||
}
|
||||
BOT_HandleTypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_BOT_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define BOT_CBW_SIGNATURE 0x43425355
|
||||
#define BOT_CBW_TAG 0x20304050
|
||||
#define BOT_CSW_SIGNATURE 0x53425355
|
||||
#define BOT_CBW_LENGTH 31
|
||||
#define BOT_CSW_LENGTH 13
|
||||
|
||||
|
||||
|
||||
#define BOT_SEND_CSW_DISABLE 0
|
||||
#define BOT_SEND_CSW_ENABLE 1
|
||||
|
||||
#define BOT_DIR_IN 0
|
||||
#define BOT_DIR_OUT 1
|
||||
#define BOT_DIR_BOTH 2
|
||||
|
||||
#define BOT_PAGE_LENGTH 512
|
||||
|
||||
|
||||
#define BOT_CBW_CB_LENGTH 16
|
||||
|
||||
|
||||
#define USB_REQ_BOT_RESET 0xFF
|
||||
#define USB_REQ_GET_MAX_LUN 0xFE
|
||||
|
||||
#define MAX_BULK_STALL_COUNT_LIMIT 0x04 /* If STALL is seen on Bulk
|
||||
Endpoint continuously, this means
|
||||
that device and Host has phase error
|
||||
Hence a Reset is needed */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_BOT_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_BOT_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_BOT_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
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_Error(USBH_HandleTypeDef *phost, uint8_t lun);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBH_MSC_BOT_H__ */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_msc_scsi.h
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief Header file for usbh_msc_scsi.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive ----------------------------------------------*/
|
||||
#ifndef __USBH_MSC_SCSI_H
|
||||
#define __USBH_MSC_SCSI_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_core.h"
|
||||
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_MSC_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI
|
||||
* @brief This file is the Header file for usbh_msc_scsi.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
// Capacity data.
|
||||
typedef struct
|
||||
{
|
||||
uint32_t block_nbr;
|
||||
uint16_t block_size;
|
||||
} SCSI_CapacityTypeDef;
|
||||
|
||||
|
||||
// Sense data.
|
||||
typedef struct
|
||||
{
|
||||
uint8_t key;
|
||||
uint8_t asc;
|
||||
uint8_t ascq;
|
||||
} SCSI_SenseTypeDef;
|
||||
|
||||
// INQUIRY data.
|
||||
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;
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define OPCODE_TEST_UNIT_READY 0x00
|
||||
#define OPCODE_READ_CAPACITY10 0x25
|
||||
#define OPCODE_READ10 0x28
|
||||
#define OPCODE_WRITE10 0x2A
|
||||
#define OPCODE_REQUEST_SENSE 0x03
|
||||
#define OPCODE_INQUIRY 0x12
|
||||
|
||||
#define DATA_LEN_MODE_TEST_UNIT_READY 0
|
||||
#define DATA_LEN_READ_CAPACITY10 8
|
||||
#define DATA_LEN_INQUIRY 36
|
||||
#define DATA_LEN_REQUEST_SENSE 14
|
||||
|
||||
#define CBW_CB_LENGTH 16
|
||||
#define CBW_LENGTH 10
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define SCSI_SENSE_KEY_NO_SENSE 0x00
|
||||
#define SCSI_SENSE_KEY_RECOVERED_ERROR 0x01
|
||||
#define SCSI_SENSE_KEY_NOT_READY 0x02
|
||||
#define SCSI_SENSE_KEY_MEDIUM_ERROR 0x03
|
||||
#define SCSI_SENSE_KEY_HARDWARE_ERROR 0x04
|
||||
#define SCSI_SENSE_KEY_ILLEGAL_REQUEST 0x05
|
||||
#define SCSI_SENSE_KEY_UNIT_ATTENTION 0x06
|
||||
#define SCSI_SENSE_KEY_DATA_PROTECT 0x07
|
||||
#define SCSI_SENSE_KEY_BLANK_CHECK 0x08
|
||||
#define SCSI_SENSE_KEY_VENDOR_SPECIFIC 0x09
|
||||
#define SCSI_SENSE_KEY_COPY_ABORTED 0x0A
|
||||
#define SCSI_SENSE_KEY_ABORTED_COMMAND 0x0B
|
||||
#define SCSI_SENSE_KEY_VOLUME_OVERFLOW 0x0D
|
||||
#define SCSI_SENSE_KEY_MISCOMPARE 0x0E
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define SCSI_ASC_NO_ADDITIONAL_SENSE_INFORMATION 0x00
|
||||
#define SCSI_ASC_LOGICAL_UNIT_NOT_READY 0x04
|
||||
#define SCSI_ASC_INVALID_FIELD_IN_CDB 0x24
|
||||
#define SCSI_ASC_WRITE_PROTECTED 0x27
|
||||
#define SCSI_ASC_FORMAT_ERROR 0x31
|
||||
#define SCSI_ASC_INVALID_COMMAND_OPERATION_CODE 0x20
|
||||
#define SCSI_ASC_NOT_READY_TO_READY_CHANGE 0x28
|
||||
#define SCSI_ASC_MEDIUM_NOT_PRESENT 0x3A
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define SCSI_ASCQ_FORMAT_COMMAND_FAILED 0x01
|
||||
#define SCSI_ASCQ_INITIALIZING_COMMAND_REQUIRED 0x02
|
||||
#define SCSI_ASCQ_OPERATION_IN_PROGRESS 0x07
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup _Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
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_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_Write(USBH_HandleTypeDef *phost,
|
||||
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);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBH_MSC_SCSI_H */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
+805
@@ -0,0 +1,805 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_msc.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file implements the MSC class driver functions
|
||||
* ===================================================================
|
||||
* MSC Class Description
|
||||
* ===================================================================
|
||||
* This module manages the MSC class V1.0 following the "Universal
|
||||
* Serial Bus Mass Storage Class (MSC) Bulk-Only Transport (BOT) Version 1.0
|
||||
* Sep. 31, 1999".
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - Bulk-Only Transport protocol
|
||||
* - Subclass : SCSI transparent command set (ref. SCSI Primary Commands - 3 (SPC-3))
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "usbh_msc.h"
|
||||
#include "usbh_msc_bot.h"
|
||||
#include "usbh_msc_scsi.h"
|
||||
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_MSC_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_CORE
|
||||
* @brief This file includes the mass storage related functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_CORE_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_CORE_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_CORE_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_CORE_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_CORE_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
static USBH_StatusTypeDef USBH_MSC_InterfaceInit (USBH_HandleTypeDef *phost);
|
||||
|
||||
static USBH_StatusTypeDef USBH_MSC_InterfaceDeInit (USBH_HandleTypeDef *phost);
|
||||
|
||||
static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost);
|
||||
|
||||
static USBH_StatusTypeDef USBH_MSC_ClassRequest(USBH_HandleTypeDef *phost);
|
||||
|
||||
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 =
|
||||
{
|
||||
"MSC",
|
||||
USB_MSC_CLASS,
|
||||
USBH_MSC_InterfaceInit,
|
||||
USBH_MSC_InterfaceDeInit,
|
||||
USBH_MSC_ClassRequest,
|
||||
USBH_MSC_Process,
|
||||
USBH_MSC_SOFProcess,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_CORE_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_InterfaceInit
|
||||
* The function init the MSC class.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_MSC_InterfaceInit (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
uint8_t interface = 0;
|
||||
USBH_StatusTypeDef status = USBH_FAIL ;
|
||||
MSC_HandleTypeDef *MSC_Handle;
|
||||
|
||||
interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, MSC_TRANSPARENT, MSC_BOT);
|
||||
|
||||
if(interface == 0xFF) /* Not Valid Interface */
|
||||
{
|
||||
USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name);
|
||||
status = USBH_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
USBH_SelectInterface (phost, interface);
|
||||
|
||||
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 & 0x80)
|
||||
{
|
||||
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
|
||||
{
|
||||
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 & 0x80)
|
||||
{
|
||||
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
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
MSC_Handle->current_lun = 0;
|
||||
MSC_Handle->rw_lun = 0;
|
||||
MSC_Handle->state = MSC_INIT;
|
||||
MSC_Handle->error = MSC_OK;
|
||||
MSC_Handle->req_state = MSC_REQ_IDLE;
|
||||
MSC_Handle->OutPipe = USBH_AllocPipe(phost, MSC_Handle->OutEp);
|
||||
MSC_Handle->InPipe = USBH_AllocPipe(phost, MSC_Handle->InEp);
|
||||
|
||||
USBH_MSC_BOT_Init(phost);
|
||||
|
||||
/* De-Initialize LUNs information */
|
||||
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,0);
|
||||
USBH_LL_SetToggle (phost, MSC_Handle->OutPipe,0);
|
||||
status = USBH_OK;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_InterfaceDeInit
|
||||
* The function DeInit the Pipes used for the MSC class.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_MSC_InterfaceDeInit (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
if ( MSC_Handle->OutPipe)
|
||||
{
|
||||
USBH_ClosePipe(phost, MSC_Handle->OutPipe);
|
||||
USBH_FreePipe (phost, MSC_Handle->OutPipe);
|
||||
MSC_Handle->OutPipe = 0; /* Reset the Channel as Free */
|
||||
}
|
||||
|
||||
if ( MSC_Handle->InPipe)
|
||||
{
|
||||
USBH_ClosePipe(phost, MSC_Handle->InPipe);
|
||||
USBH_FreePipe (phost, MSC_Handle->InPipe);
|
||||
MSC_Handle->InPipe = 0; /* Reset the Channel as Free */
|
||||
}
|
||||
|
||||
if(phost->pActiveClass->pData)
|
||||
{
|
||||
USBH_free (phost->pActiveClass->pData);
|
||||
phost->pActiveClass->pData = 0;
|
||||
}
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_ClassRequest
|
||||
* The function is responsible for handling Standard requests
|
||||
* for MSC class.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_MSC_ClassRequest(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
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 *)&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 = 0;
|
||||
status = USBH_OK;
|
||||
}
|
||||
|
||||
if(status == USBH_OK)
|
||||
{
|
||||
MSC_Handle->max_lun = (uint8_t )(MSC_Handle->max_lun) + 1;
|
||||
USBH_UsrLog ("Number of supported LUN: %lu", (int32_t)(MSC_Handle->max_lun));
|
||||
|
||||
for(i = 0; i < MSC_Handle->max_lun; i++)
|
||||
{
|
||||
MSC_Handle->unit[i].prev_ready_state = USBH_FAIL;
|
||||
MSC_Handle->unit[i].state_changed = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MSC_REQ_ERROR :
|
||||
/* a Clear Feature should be issued here */
|
||||
if(USBH_ClrFeature(phost, 0x00) == USBH_OK)
|
||||
{
|
||||
MSC_Handle->req_state = MSC_Handle->prev_req_state;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_Process
|
||||
* The function is for managing state machine for MSC data transfers
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
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;
|
||||
|
||||
case MSC_READ_INQUIRY:
|
||||
scsi_status = USBH_MSC_SCSI_Inquiry(phost, 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, 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 = 1;
|
||||
USBH_UsrLog ("MSC Device ready");
|
||||
}
|
||||
else
|
||||
{
|
||||
MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0;
|
||||
}
|
||||
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 = 1;
|
||||
USBH_UsrLog ("MSC Device NOT ready");
|
||||
}
|
||||
else
|
||||
{
|
||||
MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0;
|
||||
}
|
||||
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,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 == 1)
|
||||
{
|
||||
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, 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) < 10000)
|
||||
{
|
||||
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;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
MSC_Handle->current_lun = 0;
|
||||
MSC_Handle->state = MSC_IDLE;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
|
||||
#endif
|
||||
phost->pUser(phost, HOST_USER_CLASS_ACTIVE);
|
||||
}
|
||||
break;
|
||||
|
||||
case MSC_IDLE:
|
||||
error = USBH_OK;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_SOFProcess
|
||||
* The function is for SOF state
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_MSC_SOFProcess(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
/**
|
||||
* @brief USBH_MSC_RdWrProcess
|
||||
* The function is for managing state machine for MSC I/O Process
|
||||
* @param phost: Host handle
|
||||
* @param lun: logical Unit Number
|
||||
* @retval USBH Status
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_MSC_RdWrProcess(USBH_HandleTypeDef *phost, uint8_t lun)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
case MSC_READ:
|
||||
scsi_status = USBH_MSC_SCSI_Read(phost,lun, 0, NULL, 0) ;
|
||||
|
||||
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 == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case MSC_WRITE:
|
||||
scsi_status = USBH_MSC_SCSI_Write(phost,lun, 0, NULL, 0) ;
|
||||
|
||||
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 == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
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 == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_IsReady
|
||||
* The function check if the MSC function is ready
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
uint8_t USBH_MSC_IsReady (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
if(phost->gState == HOST_CLASS)
|
||||
{
|
||||
return (MSC_Handle->state == MSC_IDLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_GetMaxLUN
|
||||
* The function return the Max LUN supported
|
||||
* @param phost: Host handle
|
||||
* @retval logical Unit Number supported
|
||||
*/
|
||||
int8_t USBH_MSC_GetMaxLUN (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
if ((phost->gState == HOST_CLASS) && (MSC_Handle->state == MSC_IDLE))
|
||||
{
|
||||
return MSC_Handle->max_lun;
|
||||
}
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_UnitIsReady
|
||||
* The function check whether a LUN is ready
|
||||
* @param phost: Host handle
|
||||
* @param lun: logical Unit Number
|
||||
* @retval Lun status (0: not ready / 1: ready)
|
||||
*/
|
||||
uint8_t USBH_MSC_UnitIsReady (USBH_HandleTypeDef *phost, uint8_t lun)
|
||||
{
|
||||
MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
if(phost->gState == HOST_CLASS)
|
||||
{
|
||||
return (MSC_Handle->unit[lun].error == MSC_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_GetLUNInfo
|
||||
* The function return a LUN information
|
||||
* @param phost: Host handle
|
||||
* @param lun: logical Unit Number
|
||||
* @retval USBH Status
|
||||
*/
|
||||
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));
|
||||
return USBH_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBH_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_Read
|
||||
* The function performs a Read operation
|
||||
* @param phost: Host handle
|
||||
* @param lun: logical Unit Number
|
||||
* @param address: sector address
|
||||
* @param pbuf: pointer to data
|
||||
* @param length: number of sector to read
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_MSC_Read(USBH_HandleTypeDef *phost,
|
||||
uint8_t lun,
|
||||
uint32_t address,
|
||||
uint8_t *pbuf,
|
||||
uint32_t length)
|
||||
{
|
||||
uint32_t timeout;
|
||||
MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
if ((phost->device.is_connected == 0) ||
|
||||
(phost->gState != HOST_CLASS) ||
|
||||
(MSC_Handle->unit[lun].state != MSC_IDLE))
|
||||
{
|
||||
return USBH_FAIL;
|
||||
}
|
||||
MSC_Handle->state = MSC_READ;
|
||||
MSC_Handle->unit[lun].state = MSC_READ;
|
||||
MSC_Handle->rw_lun = lun;
|
||||
USBH_MSC_SCSI_Read(phost,
|
||||
lun,
|
||||
address,
|
||||
pbuf,
|
||||
length);
|
||||
|
||||
timeout = phost->Timer;
|
||||
|
||||
while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY)
|
||||
{
|
||||
if(((phost->Timer - timeout) > (10000 * length)) || (phost->device.is_connected == 0))
|
||||
{
|
||||
MSC_Handle->state = MSC_IDLE;
|
||||
return USBH_FAIL;
|
||||
}
|
||||
}
|
||||
MSC_Handle->state = MSC_IDLE;
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_Write
|
||||
* The function performs a Write operation
|
||||
* @param phost: Host handle
|
||||
* @param lun: logical Unit Number
|
||||
* @param address: sector address
|
||||
* @param pbuf: pointer to data
|
||||
* @param length: number of sector to write
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_MSC_Write(USBH_HandleTypeDef *phost,
|
||||
uint8_t lun,
|
||||
uint32_t address,
|
||||
uint8_t *pbuf,
|
||||
uint32_t length)
|
||||
{
|
||||
uint32_t timeout;
|
||||
MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
|
||||
|
||||
if ((phost->device.is_connected == 0) ||
|
||||
(phost->gState != HOST_CLASS) ||
|
||||
(MSC_Handle->unit[lun].state != MSC_IDLE))
|
||||
{
|
||||
return USBH_FAIL;
|
||||
}
|
||||
MSC_Handle->state = MSC_WRITE;
|
||||
MSC_Handle->unit[lun].state = MSC_WRITE;
|
||||
MSC_Handle->rw_lun = lun;
|
||||
USBH_MSC_SCSI_Write(phost,
|
||||
lun,
|
||||
address,
|
||||
pbuf,
|
||||
length);
|
||||
|
||||
timeout = phost->Timer;
|
||||
while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY)
|
||||
{
|
||||
if(((phost->Timer - timeout) > (10000 * length)) || (phost->device.is_connected == 0))
|
||||
{
|
||||
MSC_Handle->state = MSC_IDLE;
|
||||
return USBH_FAIL;
|
||||
}
|
||||
}
|
||||
MSC_Handle->state = MSC_IDLE;
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+633
@@ -0,0 +1,633 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_msc_bot.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file includes the BOT protocol related functions
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_msc_bot.h"
|
||||
#include "usbh_msc.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_MSC_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_BOT
|
||||
* @brief This file includes the mass storage related functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_BOT_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_BOT_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_BOT_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_BOT_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_BOT_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_MSC_BOT_Abort(USBH_HandleTypeDef *phost, uint8_t lun, uint8_t dir);
|
||||
static BOT_CSWStatusTypeDef USBH_MSC_DecodeCSW(USBH_HandleTypeDef *phost);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_BOT_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_BOT_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_BOT_REQ_Reset
|
||||
* The function the MSC BOT Reset request.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
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;
|
||||
|
||||
phost->Control.setup.b.bRequest = USB_REQ_BOT_RESET;
|
||||
phost->Control.setup.b.wValue.w = 0;
|
||||
phost->Control.setup.b.wIndex.w = 0;
|
||||
phost->Control.setup.b.wLength.w = 0;
|
||||
|
||||
return USBH_CtlReq(phost, 0 , 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_BOT_REQ_GetMaxLUN
|
||||
* The function the MSC BOT GetMaxLUN request.
|
||||
* @param phost: Host handle
|
||||
* @param Maxlun: pointer to Maxlun variable
|
||||
* @retval USBH Status
|
||||
*/
|
||||
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;
|
||||
|
||||
phost->Control.setup.b.bRequest = USB_REQ_GET_MAX_LUN;
|
||||
phost->Control.setup.b.wValue.w = 0;
|
||||
phost->Control.setup.b.wIndex.w = 0;
|
||||
phost->Control.setup.b.wLength.w = 1;
|
||||
|
||||
return USBH_CtlReq(phost, Maxlun , 1 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_BOT_Init
|
||||
* The function Initializes the BOT protocol.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_MSC_BOT_Init(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
|
||||
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;
|
||||
MSC_Handle->hbot.state = BOT_SEND_CBW;
|
||||
MSC_Handle->hbot.cmd_state = BOT_CMD_SEND;
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_BOT_Process
|
||||
* The function handle the BOT protocol.
|
||||
* @param phost: Host handle
|
||||
* @param lun: Logical Unit Number
|
||||
* @retval USBH Status
|
||||
*/
|
||||
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;
|
||||
uint8_t toggle = 0;
|
||||
|
||||
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,
|
||||
1);
|
||||
|
||||
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 != 0 )
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
#endif
|
||||
|
||||
}
|
||||
else if(URB_Status == USBH_URB_NOTREADY)
|
||||
{
|
||||
/* Re-send CBW */
|
||||
MSC_Handle->hbot.state = BOT_SEND_CBW;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
else if(URB_Status == USBH_URB_STALL)
|
||||
{
|
||||
MSC_Handle->hbot.state = BOT_ERROR_OUT;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
break;
|
||||
|
||||
case BOT_DATA_IN_WAIT:
|
||||
|
||||
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)
|
||||
{
|
||||
MSC_Handle->hbot.pbuf += MSC_Handle->InEpSize;
|
||||
MSC_Handle->hbot.cbw.field.DataTransferLength -= MSC_Handle->InEpSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
MSC_Handle->hbot.cbw.field.DataTransferLength = 0;
|
||||
}
|
||||
|
||||
/* More Data To be Received */
|
||||
if(MSC_Handle->hbot.cbw.field.DataTransferLength > 0)
|
||||
{
|
||||
/* 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 == 1)
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
#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.*/
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case BOT_DATA_OUT:
|
||||
|
||||
USBH_BulkSendData (phost,
|
||||
MSC_Handle->hbot.pbuf,
|
||||
MSC_Handle->OutEpSize ,
|
||||
MSC_Handle->OutPipe,
|
||||
1);
|
||||
|
||||
|
||||
MSC_Handle->hbot.state = BOT_DATA_OUT_WAIT;
|
||||
break;
|
||||
|
||||
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)
|
||||
{
|
||||
MSC_Handle->hbot.pbuf += MSC_Handle->OutEpSize;
|
||||
MSC_Handle->hbot.cbw.field.DataTransferLength -= MSC_Handle->OutEpSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
MSC_Handle->hbot.cbw.field.DataTransferLength = 0;
|
||||
}
|
||||
|
||||
/* More Data To be Sent */
|
||||
if(MSC_Handle->hbot.cbw.field.DataTransferLength > 0)
|
||||
{
|
||||
USBH_BulkSendData (phost,
|
||||
MSC_Handle->hbot.pbuf,
|
||||
MSC_Handle->OutEpSize ,
|
||||
MSC_Handle->OutPipe,
|
||||
1);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If value was 0, and successful transfer, then change the state */
|
||||
MSC_Handle->hbot.state = BOT_RECEIVE_CSW;
|
||||
}
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
else if(URB_Status == USBH_URB_NOTREADY)
|
||||
{
|
||||
/* Resend same data */
|
||||
MSC_Handle->hbot.state = BOT_DATA_OUT;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case BOT_RECEIVE_CSW:
|
||||
|
||||
USBH_BulkReceiveData (phost,
|
||||
MSC_Handle->hbot.csw.data,
|
||||
BOT_CSW_LENGTH ,
|
||||
MSC_Handle->InPipe);
|
||||
|
||||
MSC_Handle->hbot.state = BOT_RECEIVE_CSW_WAIT;
|
||||
break;
|
||||
|
||||
case BOT_RECEIVE_CSW_WAIT:
|
||||
|
||||
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);
|
||||
|
||||
if(CSW_Status == BOT_CSW_CMD_PASSED)
|
||||
{
|
||||
status = USBH_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = USBH_FAIL;
|
||||
}
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
else if(URB_Status == USBH_URB_STALL)
|
||||
{
|
||||
MSC_Handle->hbot.state = BOT_ERROR_IN;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
break;
|
||||
|
||||
case BOT_ERROR_OUT:
|
||||
error = USBH_MSC_BOT_Abort(phost, lun, BOT_DIR_OUT);
|
||||
|
||||
if ( error == USBH_OK)
|
||||
{
|
||||
|
||||
toggle = USBH_LL_GetToggle(phost, MSC_Handle->OutPipe);
|
||||
USBH_LL_SetToggle(phost, MSC_Handle->OutPipe, 1- toggle);
|
||||
USBH_LL_SetToggle(phost, MSC_Handle->InPipe, 0);
|
||||
MSC_Handle->hbot.state = BOT_ERROR_IN;
|
||||
}
|
||||
else if (error == USBH_UNRECOVERED_ERROR)
|
||||
{
|
||||
MSC_Handle->hbot.state = BOT_UNRECOVERED_ERROR;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_BOT_Abort
|
||||
* The function handle the BOT Abort process.
|
||||
* @param phost: Host handle
|
||||
* @param lun: Logical Unit Number
|
||||
* @param dir: direction (0: out / 1 : in)
|
||||
* @retval USBH Status
|
||||
*/
|
||||
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;
|
||||
|
||||
switch (dir)
|
||||
{
|
||||
case BOT_DIR_IN :
|
||||
/* send ClrFeture on Bulk IN endpoint */
|
||||
status = USBH_ClrFeature(phost, MSC_Handle->InEp);
|
||||
|
||||
break;
|
||||
|
||||
case BOT_DIR_OUT :
|
||||
/*send ClrFeature on Bulk OUT endpoint */
|
||||
status = USBH_ClrFeature(phost, MSC_Handle->OutEp);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_BOT_DecodeCSW
|
||||
* This function decodes the CSW received by the device and updates the
|
||||
* same to upper layer.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
* @notes
|
||||
* Refer to USB Mass-Storage Class : BOT (www.usb.org)
|
||||
* 6.3.1 Valid CSW Conditions :
|
||||
* The host shall consider the CSW valid when:
|
||||
* 1. dCSWSignature is equal to 53425355h
|
||||
* 2. the CSW is 13 (Dh) bytes in length,
|
||||
* 3. dCSWTag matches the dCBWTag from the corresponding CBW.
|
||||
*/
|
||||
|
||||
static BOT_CSWStatusTypeDef USBH_MSC_DecodeCSW(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
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)*/
|
||||
|
||||
|
||||
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 == 0)
|
||||
{
|
||||
/* 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 == 1)
|
||||
{
|
||||
status = BOT_CSW_CMD_FAILED;
|
||||
}
|
||||
|
||||
else if(MSC_Handle->hbot.csw.field.Status == 2)
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
} /* 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*/
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
|
||||
+458
@@ -0,0 +1,458 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_msc_scsi.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file implements the SCSI commands
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_msc.h"
|
||||
#include "usbh_msc_scsi.h"
|
||||
#include "usbh_msc_bot.h"
|
||||
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_MSC_CLASS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI
|
||||
* @brief This file includes the mass storage related functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_MSC_SCSI_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_SCSI_TestUnitReady
|
||||
* Issue TestUnitReady command.
|
||||
* @param phost: Host handle
|
||||
* @param lun: Logical Unit Number
|
||||
* @retval USBH Status
|
||||
*/
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
case BOT_CMD_WAIT:
|
||||
error = USBH_MSC_BOT_Process(phost, lun);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_SCSI_ReadCapacity
|
||||
* Issue Read Capacity command.
|
||||
* @param phost: Host handle
|
||||
* @param lun: Logical Unit Number
|
||||
* @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 error = USBH_BUSY ;
|
||||
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_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;
|
||||
|
||||
MSC_Handle->hbot.state = BOT_SEND_CBW;
|
||||
|
||||
MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
|
||||
MSC_Handle->hbot.pbuf = (uint8_t *)MSC_Handle->hbot.data;
|
||||
error = USBH_BUSY;
|
||||
break;
|
||||
|
||||
case BOT_CMD_WAIT:
|
||||
|
||||
error = USBH_MSC_BOT_Process(phost, lun);
|
||||
|
||||
if(error == USBH_OK)
|
||||
{
|
||||
/*assign the capacity*/
|
||||
capacity->block_nbr = MSC_Handle->hbot.pbuf[3] | (MSC_Handle->hbot.pbuf[2] << 8) |\
|
||||
(MSC_Handle->hbot.pbuf[1] << 16) | (MSC_Handle->hbot.pbuf[0] << 24);
|
||||
|
||||
/*assign the page length*/
|
||||
capacity->block_size = MSC_Handle->hbot.pbuf[7] | (MSC_Handle->hbot.pbuf[6] << 8);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_SCSI_Inquiry
|
||||
* Issue Inquiry command.
|
||||
* @param phost: Host handle
|
||||
* @param lun: Logical Unit Number
|
||||
* @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 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_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] = 0;
|
||||
MSC_Handle->hbot.cbw.field.CB[3] = 0;
|
||||
MSC_Handle->hbot.cbw.field.CB[4] = 0x24;
|
||||
MSC_Handle->hbot.cbw.field.CB[5] = 0;
|
||||
|
||||
MSC_Handle->hbot.state = BOT_SEND_CBW;
|
||||
|
||||
MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
|
||||
MSC_Handle->hbot.pbuf = (uint8_t *)MSC_Handle->hbot.data;
|
||||
error = USBH_BUSY;
|
||||
break;
|
||||
|
||||
case BOT_CMD_WAIT:
|
||||
|
||||
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] & 0x1F;
|
||||
inquiry->PeripheralQualifier = MSC_Handle->hbot.pbuf[0] >> 5;
|
||||
inquiry->RemovableMedia = (MSC_Handle->hbot.pbuf[1] & 0x80)== 0x80;
|
||||
USBH_memcpy (inquiry->vendor_id, &MSC_Handle->hbot.pbuf[8], 8);
|
||||
USBH_memcpy (inquiry->product_id, &MSC_Handle->hbot.pbuf[16], 16);
|
||||
USBH_memcpy (inquiry->revision_id, &MSC_Handle->hbot.pbuf[32], 4);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_SCSI_RequestSense
|
||||
* Issue RequestSense command.
|
||||
* @param phost: Host handle
|
||||
* @param lun: Logical Unit Number
|
||||
* @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 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] = 0;
|
||||
MSC_Handle->hbot.cbw.field.CB[3] = 0;
|
||||
MSC_Handle->hbot.cbw.field.CB[4] = DATA_LEN_REQUEST_SENSE;
|
||||
MSC_Handle->hbot.cbw.field.CB[5] = 0;
|
||||
|
||||
MSC_Handle->hbot.state = BOT_SEND_CBW;
|
||||
MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
|
||||
MSC_Handle->hbot.pbuf = (uint8_t *)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] & 0x0F;
|
||||
sense_data->asc = MSC_Handle->hbot.pbuf[12];
|
||||
sense_data->ascq = MSC_Handle->hbot.pbuf[13];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_SCSI_Write
|
||||
* Issue write10 command.
|
||||
* @param phost: Host handle
|
||||
* @param lun: Logical Unit Number
|
||||
* @param address: sector address
|
||||
* @param pbuf: pointer to data
|
||||
* @param length: number of sector to write
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_MSC_SCSI_Write(USBH_HandleTypeDef *phost,
|
||||
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:
|
||||
|
||||
/*Prepare the CBW and relevent field*/
|
||||
MSC_Handle->hbot.cbw.field.DataTransferLength = length * 512;
|
||||
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;
|
||||
|
||||
/*logical block address*/
|
||||
MSC_Handle->hbot.cbw.field.CB[2] = (((uint8_t*)&address)[3]);
|
||||
MSC_Handle->hbot.cbw.field.CB[3] = (((uint8_t*)&address)[2]);
|
||||
MSC_Handle->hbot.cbw.field.CB[4] = (((uint8_t*)&address)[1]);
|
||||
MSC_Handle->hbot.cbw.field.CB[5] = (((uint8_t*)&address)[0]);
|
||||
|
||||
|
||||
/*Transfer length */
|
||||
MSC_Handle->hbot.cbw.field.CB[7] = (((uint8_t *)&length)[1]) ;
|
||||
MSC_Handle->hbot.cbw.field.CB[8] = (((uint8_t *)&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;
|
||||
|
||||
case BOT_CMD_WAIT:
|
||||
error = USBH_MSC_BOT_Process(phost, lun);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_MSC_SCSI_Read
|
||||
* Issue Read10 command.
|
||||
* @param phost: Host handle
|
||||
* @param lun: Logical Unit Number
|
||||
* @param address: sector address
|
||||
* @param pbuf: pointer to data
|
||||
* @param length: number of sector to read
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_MSC_SCSI_Read(USBH_HandleTypeDef *phost,
|
||||
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:
|
||||
|
||||
/*Prepare the CBW and relevent field*/
|
||||
MSC_Handle->hbot.cbw.field.DataTransferLength = length * 512;
|
||||
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;
|
||||
|
||||
/*logical block address*/
|
||||
MSC_Handle->hbot.cbw.field.CB[2] = (((uint8_t*)&address)[3]);
|
||||
MSC_Handle->hbot.cbw.field.CB[3] = (((uint8_t*)&address)[2]);
|
||||
MSC_Handle->hbot.cbw.field.CB[4] = (((uint8_t*)&address)[1]);
|
||||
MSC_Handle->hbot.cbw.field.CB[5] = (((uint8_t*)&address)[0]);
|
||||
|
||||
|
||||
/*Transfer length */
|
||||
MSC_Handle->hbot.cbw.field.CB[7] = (((uint8_t *)&length)[1]) ;
|
||||
MSC_Handle->hbot.cbw.field.CB[8] = (((uint8_t *)&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;
|
||||
|
||||
case BOT_CMD_WAIT:
|
||||
error = USBH_MSC_BOT_Process(phost, lun);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_conf_template.h
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief Header file for usbh_conf_template.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBH_CONF_TEMPLATE_H
|
||||
#define __USBH_CONF_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f4xx.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/** @addtogroup USBH_OTG_DRIVER
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CONF
|
||||
* @brief usb otg low level driver configuration file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CONF_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define USBH_MAX_NUM_ENDPOINTS 2
|
||||
#define USBH_MAX_NUM_INTERFACES 2
|
||||
#define USBH_MAX_NUM_CONFIGURATION 1
|
||||
#define USBH_KEEP_CFG_DESCRIPTOR 1
|
||||
#define USBH_MAX_NUM_SUPPORTED_CLASS 1
|
||||
#define USBH_MAX_SIZE_CONFIGURATION 0x200
|
||||
#define USBH_MAX_DATA_BUFFER 0x200
|
||||
#define USBH_DEBUG_LEVEL 2
|
||||
#define USBH_USE_OS 1
|
||||
|
||||
/** @defgroup USBH_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Memory management macros */
|
||||
#define USBH_malloc malloc
|
||||
#define USBH_free free
|
||||
#define USBH_memset memset
|
||||
#define USBH_memcpy memcpy
|
||||
|
||||
/* DEBUG macros */
|
||||
|
||||
|
||||
#if (USBH_DEBUG_LEVEL > 0)
|
||||
#define USBH_UsrLog(...) printf(__VA_ARGS__);\
|
||||
printf("\n");
|
||||
#else
|
||||
#define USBH_UsrLog(...)
|
||||
#endif
|
||||
|
||||
|
||||
#if (USBH_DEBUG_LEVEL > 1)
|
||||
|
||||
#define USBH_ErrLog(...) printf("ERROR: ") ;\
|
||||
printf(__VA_ARGS__);\
|
||||
printf("\n");
|
||||
#else
|
||||
#define USBH_ErrLog(...)
|
||||
#endif
|
||||
|
||||
|
||||
#if (USBH_DEBUG_LEVEL > 2)
|
||||
#define USBH_DbgLog(...) printf("DEBUG : ") ;\
|
||||
printf(__VA_ARGS__);\
|
||||
printf("\n");
|
||||
#else
|
||||
#define USBH_DbgLog(...)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CONF_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CONF_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CONF_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CONF_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBH_CONF_TEMPLATE_H */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_core.h
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief Header file for usbh_core.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive ----------------------------------------------*/
|
||||
#ifndef __USBH_CORE_H
|
||||
#define __USBH_CORE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_conf.h"
|
||||
#include "usbh_def.h"
|
||||
#include "usbh_ioreq.h"
|
||||
#include "usbh_pipes.h"
|
||||
#include "usbh_ctlreq.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_LIB_CORE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CORE
|
||||
* @brief This file is the Header file for usbh_core.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CORE_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#define HOST_USER_SELECT_CONFIGURATION 1
|
||||
#define HOST_USER_CLASS_ACTIVE 2
|
||||
#define HOST_USER_CLASS_SELECTED 3
|
||||
#define HOST_USER_CONNECTION 4
|
||||
#define HOST_USER_DISCONNECTION 5
|
||||
#define HOST_USER_UNRECOVERED_ERROR 6
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBH_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CORE_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
USBH_StatusTypeDef USBH_Init(USBH_HandleTypeDef *phost, void (*pUsrFunc)(USBH_HandleTypeDef *phost, uint8_t ), uint8_t id);
|
||||
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 USBH_GetActiveClass(USBH_HandleTypeDef *phost);
|
||||
|
||||
uint8_t USBH_FindInterfaceIndex(USBH_HandleTypeDef *phost,
|
||||
uint8_t interface_number,
|
||||
uint8_t alt_settings);
|
||||
|
||||
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 );
|
||||
USBH_StatusTypeDef USBH_LL_DriverVBUS (USBH_HandleTypeDef *phost, uint8_t );
|
||||
|
||||
USBH_StatusTypeDef USBH_LL_OpenPipe (USBH_HandleTypeDef *phost, uint8_t, uint8_t, uint8_t, uint8_t , uint8_t, uint16_t );
|
||||
USBH_StatusTypeDef USBH_LL_ClosePipe (USBH_HandleTypeDef *phost, uint8_t );
|
||||
USBH_StatusTypeDef USBH_LL_SubmitURB (USBH_HandleTypeDef *phost, uint8_t, uint8_t,uint8_t, uint8_t, uint8_t*, uint16_t, uint8_t );
|
||||
USBH_URBStateTypeDef USBH_LL_GetURBState (USBH_HandleTypeDef *phost, uint8_t );
|
||||
#if (USBH_USE_OS == 1)
|
||||
USBH_StatusTypeDef USBH_LL_NotifyURBChange (USBH_HandleTypeDef *phost);
|
||||
#endif
|
||||
USBH_StatusTypeDef USBH_LL_SetToggle (USBH_HandleTypeDef *phost, uint8_t , uint8_t );
|
||||
uint8_t USBH_LL_GetToggle (USBH_HandleTypeDef *phost, uint8_t );
|
||||
|
||||
/* USBH Time base */
|
||||
void USBH_Delay (uint32_t Delay);
|
||||
void USBH_LL_SetTimer (USBH_HandleTypeDef *phost, uint32_t );
|
||||
void USBH_LL_IncTimer (USBH_HandleTypeDef *phost);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBH_CORE_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_ctlreq.h
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief Header file for usbh_ctlreq.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive ----------------------------------------------*/
|
||||
#ifndef __USBH_CTLREQ_H
|
||||
#define __USBH_CTLREQ_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_core.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_LIB_CORE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CTLREQ
|
||||
* @brief This file is the
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CTLREQ_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/*Standard Feature Selector for clear feature command*/
|
||||
#define FEATURE_SELECTOR_ENDPOINT 0X00
|
||||
#define FEATURE_SELECTOR_DEVICE 0X01
|
||||
|
||||
|
||||
#define INTERFACE_DESC_TYPE 0x04
|
||||
#define ENDPOINT_DESC_TYPE 0x05
|
||||
#define INTERFACE_DESC_SIZE 0x09
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CTLREQ_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CTLREQ_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CTLREQ_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
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_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_StringDesc(USBH_HandleTypeDef *phost,
|
||||
uint8_t string_index,
|
||||
uint8_t *buff,
|
||||
uint16_t length);
|
||||
|
||||
USBH_StatusTypeDef USBH_SetCfg(USBH_HandleTypeDef *phost,
|
||||
uint16_t configuration_value);
|
||||
|
||||
USBH_StatusTypeDef USBH_Get_CfgDesc(USBH_HandleTypeDef *phost,
|
||||
uint16_t length);
|
||||
|
||||
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_ClrFeature(USBH_HandleTypeDef *phost,
|
||||
uint8_t ep_num);
|
||||
|
||||
USBH_DescHeader_t *USBH_GetNextDesc (uint8_t *pbuf,
|
||||
uint16_t *ptr);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBH_CTLREQ_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
+490
@@ -0,0 +1,490 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_def.h
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief Definitions used in the USB host library
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive ----------------------------------------------*/
|
||||
#ifndef USBH_DEF_H
|
||||
#define USBH_DEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_conf.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_LIB_CORE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_DEF
|
||||
* @brief This file is includes USB descriptors
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
|
||||
#define ValBit(VAR,POS) (VAR & (1 << POS))
|
||||
#define SetBit(VAR,POS) (VAR |= (1 << POS))
|
||||
#define ClrBit(VAR,POS) (VAR &= ((1 << POS)^255))
|
||||
|
||||
#define LE16(addr) (((uint16_t)(*((uint8_t *)(addr))))\
|
||||
+ (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8))
|
||||
|
||||
#define LE16S(addr) (uint16_t)(LE16((addr)))
|
||||
|
||||
#define LE32(addr) ((((uint32_t)(*(((uint8_t *)(addr)) + 0))) + \
|
||||
(((uint32_t)(*(((uint8_t *)(addr)) + 1))) << 8) + \
|
||||
(((uint32_t)(*(((uint8_t *)(addr)) + 2))) << 16) + \
|
||||
(((uint32_t)(*(((uint8_t *)(addr)) + 3))) << 24)))
|
||||
|
||||
#define LE64(addr) ((((uint64_t)(*(((uint8_t *)(addr)) + 0))) + \
|
||||
(((uint64_t)(*(((uint8_t *)(addr)) + 1))) << 8) +\
|
||||
(((uint64_t)(*(((uint8_t *)(addr)) + 2))) << 16) +\
|
||||
(((uint64_t)(*(((uint8_t *)(addr)) + 3))) << 24) +\
|
||||
(((uint64_t)(*(((uint8_t *)(addr)) + 4))) << 32) +\
|
||||
(((uint64_t)(*(((uint8_t *)(addr)) + 5))) << 40) +\
|
||||
(((uint64_t)(*(((uint8_t *)(addr)) + 6))) << 48) +\
|
||||
(((uint64_t)(*(((uint8_t *)(addr)) + 7))) << 56)))
|
||||
|
||||
|
||||
#define LE24(addr) ((((uint32_t)(*(((uint8_t *)(addr)) + 0))) + \
|
||||
(((uint32_t)(*(((uint8_t *)(addr)) + 1))) << 8) + \
|
||||
(((uint32_t)(*(((uint8_t *)(addr)) + 2))) << 16)))
|
||||
|
||||
|
||||
#define LE32S(addr) (int32_t)(LE32((addr)))
|
||||
|
||||
|
||||
|
||||
#define USB_LEN_DESC_HDR 0x02
|
||||
#define USB_LEN_DEV_DESC 0x12
|
||||
#define USB_LEN_CFG_DESC 0x09
|
||||
#define USB_LEN_IF_DESC 0x09
|
||||
#define USB_LEN_EP_DESC 0x07
|
||||
#define USB_LEN_OTG_DESC 0x03
|
||||
#define USB_LEN_SETUP_PKT 0x08
|
||||
|
||||
/* bmRequestType :D7 Data Phase Transfer Direction */
|
||||
#define USB_REQ_DIR_MASK 0x80
|
||||
#define USB_H2D 0x00
|
||||
#define USB_D2H 0x80
|
||||
|
||||
/* bmRequestType D6..5 Type */
|
||||
#define USB_REQ_TYPE_STANDARD 0x00
|
||||
#define USB_REQ_TYPE_CLASS 0x20
|
||||
#define USB_REQ_TYPE_VENDOR 0x40
|
||||
#define USB_REQ_TYPE_RESERVED 0x60
|
||||
|
||||
/* bmRequestType D4..0 Recipient */
|
||||
#define USB_REQ_RECIPIENT_DEVICE 0x00
|
||||
#define USB_REQ_RECIPIENT_INTERFACE 0x01
|
||||
#define USB_REQ_RECIPIENT_ENDPOINT 0x02
|
||||
#define USB_REQ_RECIPIENT_OTHER 0x03
|
||||
|
||||
/* Table 9-4. Standard Request Codes */
|
||||
/* bRequest , Value */
|
||||
#define USB_REQ_GET_STATUS 0x00
|
||||
#define USB_REQ_CLEAR_FEATURE 0x01
|
||||
#define USB_REQ_SET_FEATURE 0x03
|
||||
#define USB_REQ_SET_ADDRESS 0x05
|
||||
#define USB_REQ_GET_DESCRIPTOR 0x06
|
||||
#define USB_REQ_SET_DESCRIPTOR 0x07
|
||||
#define USB_REQ_GET_CONFIGURATION 0x08
|
||||
#define USB_REQ_SET_CONFIGURATION 0x09
|
||||
#define USB_REQ_GET_INTERFACE 0x0A
|
||||
#define USB_REQ_SET_INTERFACE 0x0B
|
||||
#define USB_REQ_SYNCH_FRAME 0x0C
|
||||
|
||||
/* Table 9-5. Descriptor Types of USB Specifications */
|
||||
#define USB_DESC_TYPE_DEVICE 1
|
||||
#define USB_DESC_TYPE_CONFIGURATION 2
|
||||
#define USB_DESC_TYPE_STRING 3
|
||||
#define USB_DESC_TYPE_INTERFACE 4
|
||||
#define USB_DESC_TYPE_ENDPOINT 5
|
||||
#define USB_DESC_TYPE_DEVICE_QUALIFIER 6
|
||||
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7
|
||||
#define USB_DESC_TYPE_INTERFACE_POWER 8
|
||||
#define USB_DESC_TYPE_HID 0x21
|
||||
#define USB_DESC_TYPE_HID_REPORT 0x22
|
||||
|
||||
|
||||
#define USB_DEVICE_DESC_SIZE 18
|
||||
#define USB_CONFIGURATION_DESC_SIZE 9
|
||||
#define USB_HID_DESC_SIZE 9
|
||||
#define USB_INTERFACE_DESC_SIZE 9
|
||||
#define USB_ENDPOINT_DESC_SIZE 7
|
||||
|
||||
/* Descriptor Type and Descriptor Index */
|
||||
/* Use the following values when calling the function USBH_GetDescriptor */
|
||||
#define USB_DESC_DEVICE ((USB_DESC_TYPE_DEVICE << 8) & 0xFF00)
|
||||
#define USB_DESC_CONFIGURATION ((USB_DESC_TYPE_CONFIGURATION << 8) & 0xFF00)
|
||||
#define USB_DESC_STRING ((USB_DESC_TYPE_STRING << 8) & 0xFF00)
|
||||
#define USB_DESC_INTERFACE ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
|
||||
#define USB_DESC_ENDPOINT ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
|
||||
#define USB_DESC_DEVICE_QUALIFIER ((USB_DESC_TYPE_DEVICE_QUALIFIER << 8) & 0xFF00)
|
||||
#define USB_DESC_OTHER_SPEED_CONFIGURATION ((USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION << 8) & 0xFF00)
|
||||
#define USB_DESC_INTERFACE_POWER ((USB_DESC_TYPE_INTERFACE_POWER << 8) & 0xFF00)
|
||||
#define USB_DESC_HID_REPORT ((USB_DESC_TYPE_HID_REPORT << 8) & 0xFF00)
|
||||
#define USB_DESC_HID ((USB_DESC_TYPE_HID << 8) & 0xFF00)
|
||||
|
||||
|
||||
#define USB_EP_TYPE_CTRL 0x00
|
||||
#define USB_EP_TYPE_ISOC 0x01
|
||||
#define USB_EP_TYPE_BULK 0x02
|
||||
#define USB_EP_TYPE_INTR 0x03
|
||||
|
||||
#define USB_EP_DIR_OUT 0x00
|
||||
#define USB_EP_DIR_IN 0x80
|
||||
#define USB_EP_DIR_MSK 0x80
|
||||
|
||||
#ifndef USBH_MAX_PIPES_NBR
|
||||
#define USBH_MAX_PIPES_NBR 15
|
||||
#endif /* USBH_MAX_PIPES_NBR */
|
||||
|
||||
#define USBH_DEVICE_ADDRESS_DEFAULT 0
|
||||
#define USBH_MAX_ERROR_COUNT 2
|
||||
#define USBH_DEVICE_ADDRESS 1
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#define USBH_CONFIGURATION_DESCRIPTOR_SIZE (USB_CONFIGURATION_DESC_SIZE \
|
||||
+ USB_INTERFACE_DESC_SIZE\
|
||||
+ (USBH_MAX_NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE))
|
||||
|
||||
|
||||
#define CONFIG_DESC_wTOTAL_LENGTH (ConfigurationDescriptorData.ConfigDescfield.\
|
||||
ConfigurationDescriptor.wTotalLength)
|
||||
|
||||
|
||||
typedef union
|
||||
{
|
||||
uint16_t w;
|
||||
struct BW
|
||||
{
|
||||
uint8_t msb;
|
||||
uint8_t lsb;
|
||||
}
|
||||
bw;
|
||||
}
|
||||
uint16_t_uint8_t;
|
||||
|
||||
|
||||
typedef union _USB_Setup
|
||||
{
|
||||
uint32_t d8[2];
|
||||
|
||||
struct _SetupPkt_Struc
|
||||
{
|
||||
uint8_t bmRequestType;
|
||||
uint8_t bRequest;
|
||||
uint16_t_uint8_t wValue;
|
||||
uint16_t_uint8_t wIndex;
|
||||
uint16_t_uint8_t wLength;
|
||||
} b;
|
||||
}
|
||||
USB_Setup_TypeDef;
|
||||
|
||||
typedef struct _DescHeader
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
}
|
||||
USBH_DescHeader_t;
|
||||
|
||||
typedef struct _DeviceDescriptor
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t bcdUSB; /* USB Specification Number which device complies too */
|
||||
uint8_t bDeviceClass;
|
||||
uint8_t bDeviceSubClass;
|
||||
uint8_t bDeviceProtocol;
|
||||
/* If equal to Zero, each interface specifies its own class
|
||||
code if equal to 0xFF, the class code is vendor specified.
|
||||
Otherwise field is valid Class Code.*/
|
||||
uint8_t bMaxPacketSize;
|
||||
uint16_t idVendor; /* Vendor ID (Assigned by USB Org) */
|
||||
uint16_t idProduct; /* Product ID (Assigned by Manufacturer) */
|
||||
uint16_t bcdDevice; /* Device Release Number */
|
||||
uint8_t iManufacturer; /* Index of Manufacturer String Descriptor */
|
||||
uint8_t iProduct; /* Index of Product String Descriptor */
|
||||
uint8_t iSerialNumber; /* Index of Serial Number String Descriptor */
|
||||
uint8_t bNumConfigurations; /* Number of Possible Configurations */
|
||||
}
|
||||
USBH_DevDescTypeDef;
|
||||
|
||||
typedef struct _EndpointDescriptor
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bEndpointAddress; /* indicates what endpoint this descriptor is describing */
|
||||
uint8_t bmAttributes; /* specifies the transfer type. */
|
||||
uint16_t wMaxPacketSize; /* Maximum Packet Size this endpoint is capable of sending or receiving */
|
||||
uint8_t bInterval; /* is used to specify the polling interval of certain transfers. */
|
||||
}
|
||||
USBH_EpDescTypeDef;
|
||||
|
||||
typedef struct _InterfaceDescriptor
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bInterfaceNumber;
|
||||
uint8_t bAlternateSetting; /* Value used to select alternative setting */
|
||||
uint8_t bNumEndpoints; /* Number of Endpoints used for this interface */
|
||||
uint8_t bInterfaceClass; /* Class Code (Assigned by USB Org) */
|
||||
uint8_t bInterfaceSubClass; /* Subclass Code (Assigned by USB Org) */
|
||||
uint8_t bInterfaceProtocol; /* Protocol Code */
|
||||
uint8_t iInterface; /* Index of String Descriptor Describing this interface */
|
||||
USBH_EpDescTypeDef Ep_Desc[USBH_MAX_NUM_ENDPOINTS];
|
||||
}
|
||||
USBH_InterfaceDescTypeDef;
|
||||
|
||||
|
||||
typedef struct _ConfigurationDescriptor
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t wTotalLength; /* Total Length of Data Returned */
|
||||
uint8_t bNumInterfaces; /* Number of Interfaces */
|
||||
uint8_t bConfigurationValue; /* Value to use as an argument to select this configuration*/
|
||||
uint8_t iConfiguration; /*Index of String Descriptor Describing this configuration */
|
||||
uint8_t bmAttributes; /* D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)*/
|
||||
uint8_t bMaxPower; /*Maximum Power Consumption */
|
||||
USBH_InterfaceDescTypeDef Itf_Desc[USBH_MAX_NUM_INTERFACES];
|
||||
}
|
||||
USBH_CfgDescTypeDef;
|
||||
|
||||
|
||||
/* Following USB Host status */
|
||||
typedef enum
|
||||
{
|
||||
USBH_OK = 0,
|
||||
USBH_BUSY,
|
||||
USBH_FAIL,
|
||||
USBH_NOT_SUPPORTED,
|
||||
USBH_UNRECOVERED_ERROR,
|
||||
USBH_ERROR_SPEED_UNKNOWN,
|
||||
}USBH_StatusTypeDef;
|
||||
|
||||
|
||||
/** @defgroup USBH_CORE_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
USBH_SPEED_HIGH = 0,
|
||||
USBH_SPEED_FULL = 1,
|
||||
USBH_SPEED_LOW = 2,
|
||||
|
||||
}USBH_SpeedTypeDef;
|
||||
|
||||
/* Following states are used for gState */
|
||||
typedef enum
|
||||
{
|
||||
HOST_IDLE =0,
|
||||
HOST_DEV_WAIT_FOR_ATTACHMENT,
|
||||
HOST_DEV_ATTACHED,
|
||||
HOST_DEV_DISCONNECTED,
|
||||
HOST_DETECT_DEVICE_SPEED,
|
||||
HOST_ENUMERATION,
|
||||
HOST_CLASS_REQUEST,
|
||||
HOST_INPUT,
|
||||
HOST_SET_CONFIGURATION,
|
||||
HOST_CHECK_CLASS,
|
||||
HOST_CLASS,
|
||||
HOST_SUSPENDED,
|
||||
HOST_ABORT_STATE,
|
||||
}HOST_StateTypeDef;
|
||||
|
||||
/* Following states are used for EnumerationState */
|
||||
typedef enum
|
||||
{
|
||||
ENUM_IDLE = 0,
|
||||
ENUM_GET_FULL_DEV_DESC,
|
||||
ENUM_SET_ADDR,
|
||||
ENUM_GET_CFG_DESC,
|
||||
ENUM_GET_FULL_CFG_DESC,
|
||||
ENUM_GET_MFC_STRING_DESC,
|
||||
ENUM_GET_PRODUCT_STRING_DESC,
|
||||
ENUM_GET_SERIALNUM_STRING_DESC,
|
||||
} ENUM_StateTypeDef;
|
||||
|
||||
/* Following states are used for CtrlXferStateMachine */
|
||||
typedef enum
|
||||
{
|
||||
CTRL_IDLE =0,
|
||||
CTRL_SETUP,
|
||||
CTRL_SETUP_WAIT,
|
||||
CTRL_DATA_IN,
|
||||
CTRL_DATA_IN_WAIT,
|
||||
CTRL_DATA_OUT,
|
||||
CTRL_DATA_OUT_WAIT,
|
||||
CTRL_STATUS_IN,
|
||||
CTRL_STATUS_IN_WAIT,
|
||||
CTRL_STATUS_OUT,
|
||||
CTRL_STATUS_OUT_WAIT,
|
||||
CTRL_ERROR,
|
||||
CTRL_STALLED,
|
||||
CTRL_COMPLETE
|
||||
}CTRL_StateTypeDef;
|
||||
|
||||
|
||||
/* Following states are used for RequestState */
|
||||
typedef enum
|
||||
{
|
||||
CMD_IDLE =0,
|
||||
CMD_SEND,
|
||||
CMD_WAIT
|
||||
} CMD_StateTypeDef;
|
||||
|
||||
typedef enum {
|
||||
USBH_URB_IDLE = 0,
|
||||
USBH_URB_DONE,
|
||||
USBH_URB_NOTREADY,
|
||||
USBH_URB_NYET,
|
||||
USBH_URB_ERROR,
|
||||
USBH_URB_STALL
|
||||
}USBH_URBStateTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
USBH_PORT_EVENT = 1,
|
||||
USBH_URB_EVENT,
|
||||
USBH_CONTROL_EVENT,
|
||||
USBH_CLASS_EVENT,
|
||||
USBH_STATE_CHANGED_EVENT,
|
||||
}
|
||||
USBH_OSEventTypeDef;
|
||||
|
||||
/* Control request structure */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t pipe_in;
|
||||
uint8_t pipe_out;
|
||||
uint8_t pipe_size;
|
||||
uint8_t *buff;
|
||||
uint16_t length;
|
||||
uint16_t timer;
|
||||
USB_Setup_TypeDef setup;
|
||||
CTRL_StateTypeDef state;
|
||||
uint8_t errorcount;
|
||||
|
||||
} USBH_CtrlTypeDef;
|
||||
|
||||
/* Attached device structure */
|
||||
typedef struct
|
||||
{
|
||||
#if (USBH_KEEP_CFG_DESCRIPTOR == 1)
|
||||
uint8_t CfgDesc_Raw[USBH_MAX_SIZE_CONFIGURATION];
|
||||
#endif
|
||||
uint8_t Data[USBH_MAX_DATA_BUFFER];
|
||||
uint8_t address;
|
||||
uint8_t speed;
|
||||
__IO uint8_t is_connected;
|
||||
uint8_t current_interface;
|
||||
USBH_DevDescTypeDef DevDesc;
|
||||
USBH_CfgDescTypeDef CfgDesc;
|
||||
|
||||
}USBH_DeviceTypeDef;
|
||||
|
||||
struct _USBH_HandleTypeDef;
|
||||
|
||||
/* USB Host Class structure */
|
||||
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_ClassTypeDef;
|
||||
|
||||
/* USB Host handle structure */
|
||||
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;
|
||||
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);
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessageQId os_event;
|
||||
osThreadId thread;
|
||||
#endif
|
||||
|
||||
} USBH_HandleTypeDef;
|
||||
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
#ifndef __weak
|
||||
#define __weak __attribute__((weak))
|
||||
#endif /* __weak */
|
||||
#ifndef __packed
|
||||
#define __packed __attribute__((__packed__))
|
||||
#endif /* __packed */
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBH_DEF_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_ioreq.h
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief Header file for usbh_ioreq.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive ----------------------------------------------*/
|
||||
#ifndef __USBH_IOREQ_H
|
||||
#define __USBH_IOREQ_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_conf.h"
|
||||
#include "usbh_core.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_LIB_CORE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_IOREQ
|
||||
* @brief This file is the header file for usbh_ioreq.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_IOREQ_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define USBH_PID_SETUP 0
|
||||
#define USBH_PID_DATA 1
|
||||
|
||||
#define USBH_EP_CONTROL 0
|
||||
#define USBH_EP_ISO 1
|
||||
#define USBH_EP_BULK 2
|
||||
#define USBH_EP_INTERRUPT 3
|
||||
|
||||
#define USBH_SETUP_PKT_SIZE 8
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_IOREQ_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_IOREQ_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_IOREQ_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_IOREQ_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_CtlSendSetup (USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint8_t hc_num);
|
||||
|
||||
USBH_StatusTypeDef USBH_CtlSendData (USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint16_t length,
|
||||
uint8_t hc_num,
|
||||
uint8_t do_ping );
|
||||
|
||||
USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint16_t length,
|
||||
uint8_t hc_num);
|
||||
|
||||
USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint16_t length,
|
||||
uint8_t hc_num);
|
||||
|
||||
USBH_StatusTypeDef USBH_BulkSendData (USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint16_t length,
|
||||
uint8_t hc_num,
|
||||
uint8_t do_ping );
|
||||
|
||||
USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint8_t length,
|
||||
uint8_t hc_num);
|
||||
|
||||
USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint8_t length,
|
||||
uint8_t hc_num);
|
||||
|
||||
|
||||
USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint32_t length,
|
||||
uint8_t hc_num);
|
||||
|
||||
|
||||
USBH_StatusTypeDef USBH_IsocSendData(USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint32_t length,
|
||||
uint8_t hc_num);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBH_IOREQ_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_pipes.h
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief Header file for usbh_pipes.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive ----------------------------------------------*/
|
||||
#ifndef __USBH_PIPES_H
|
||||
#define __USBH_PIPES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_core.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_LIB_CORE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_PIPES
|
||||
* @brief This file is the header file for usbh_pipes.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_PIPES_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_PIPES_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_PIPES_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_PIPES_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_PIPES_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBH_StatusTypeDef USBH_OpenPipe (USBH_HandleTypeDef *phost,
|
||||
uint8_t ch_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);
|
||||
|
||||
uint8_t USBH_AllocPipe (USBH_HandleTypeDef *phost,
|
||||
uint8_t ep_addr);
|
||||
|
||||
USBH_StatusTypeDef USBH_FreePipe (USBH_HandleTypeDef *phost,
|
||||
uint8_t idx);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBH_PIPES_H */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
+271
@@ -0,0 +1,271 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_bsp.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file implements the board support package for the USB host library
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_core.h"
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_Init
|
||||
* Initialize the Low Level portion of the Host driver.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_LL_Init (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_DeInit
|
||||
* De-Initialize the Low Level portion of the Host driver.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_LL_DeInit (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_Start
|
||||
* Start the Low Level portion of the Host driver.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_LL_Start(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_Stop
|
||||
* Stop the Low Level portion of the Host driver.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_LL_Stop (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_GetSpeed
|
||||
* Return the USB Host Speed from the Low Level Driver.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Speeds
|
||||
*/
|
||||
USBH_SpeedTypeDef USBH_LL_GetSpeed (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
USBH_SpeedTypeDef speed = USBH_SPEED_FULL;
|
||||
|
||||
|
||||
return speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_ResetPort
|
||||
* Reset the Host Port of the Low Level Driver.
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_LL_ResetPort (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_GetLastXferSize
|
||||
* Return the last transferred packet size.
|
||||
* @param phost: Host handle
|
||||
* @param pipe: Pipe index
|
||||
* @retval Packet Size
|
||||
*/
|
||||
uint32_t USBH_LL_GetLastXferSize (USBH_HandleTypeDef *phost, uint8_t pipe)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_OpenPipe
|
||||
* Open a pipe of the Low Level Driver.
|
||||
* @param phost: Host handle
|
||||
* @param pipe_num: Pipe index
|
||||
* @param epnum: Endpoint Number
|
||||
* @param dev_address: Device USB address
|
||||
* @param speed: Device Speed
|
||||
* @param ep_type: Endpoint Type
|
||||
* @param mps: Endpoint Max Packet Size
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_LL_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)
|
||||
{
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_ClosePipe
|
||||
* Close a pipe of the Low Level Driver.
|
||||
* @param phost: Host handle
|
||||
* @param pipe_num: Pipe index
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_LL_ClosePipe (USBH_HandleTypeDef *phost, uint8_t pipe)
|
||||
{
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_SubmitURB
|
||||
* Submit a new URB to the low level driver.
|
||||
* @param phost: Host handle
|
||||
* @param pipe: Pipe index
|
||||
* This parameter can be a value from 1 to 15
|
||||
* @param direction : Channel number
|
||||
* This parameter can be one of the these values:
|
||||
* 0 : Output
|
||||
* 1 : Input
|
||||
* @param ep_type : Endpoint Type
|
||||
* This parameter can be one of the these values:
|
||||
* @arg EP_TYPE_CTRL: Control type
|
||||
* @arg EP_TYPE_ISOC: Isochronous type
|
||||
* @arg EP_TYPE_BULK: Bulk type
|
||||
* @arg EP_TYPE_INTR: Interrupt type
|
||||
* @param token : Endpoint Type
|
||||
* This parameter can be one of the these values:
|
||||
* @arg 0: PID_SETUP
|
||||
* @arg 1: PID_DATA
|
||||
* @param pbuff : pointer to URB data
|
||||
* @param length : Length of URB data
|
||||
* @param do_ping : activate do ping protocol (for high speed only)
|
||||
* This parameter can be one of the these values:
|
||||
* 0 : do ping inactive
|
||||
* 1 : do ping active
|
||||
* @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 )
|
||||
{
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_GetURBState
|
||||
* Get a URB state from the low level driver.
|
||||
* @param phost: Host handle
|
||||
* @param pipe: Pipe index
|
||||
* This parameter can be a value from 1 to 15
|
||||
* @retval URB state
|
||||
* This parameter can be one of the these values:
|
||||
* @arg URB_IDLE
|
||||
* @arg URB_DONE
|
||||
* @arg URB_NOTREADY
|
||||
* @arg URB_NYET
|
||||
* @arg URB_ERROR
|
||||
* @arg URB_STALL
|
||||
*/
|
||||
USBH_URBStateTypeDef USBH_LL_GetURBState (USBH_HandleTypeDef *phost, uint8_t pipe)
|
||||
{
|
||||
return USBH_URB_IDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_DriverVBUS
|
||||
* Drive VBUS.
|
||||
* @param phost: Host handle
|
||||
* @param state : VBUS state
|
||||
* This parameter can be one of the these values:
|
||||
* 0 : VBUS Active
|
||||
* 1 : VBUS Inactive
|
||||
* @retval Status
|
||||
*/
|
||||
|
||||
USBH_StatusTypeDef USBH_LL_DriverVBUS (USBH_HandleTypeDef *phost, uint8_t state)
|
||||
{
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_SetToggle
|
||||
* Set toggle for a pipe.
|
||||
* @param phost: Host handle
|
||||
* @param pipe: Pipe index
|
||||
* @param pipe_num: Pipe index
|
||||
* @param toggle: toggle (0/1)
|
||||
* @retval Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_LL_SetToggle (USBH_HandleTypeDef *phost, uint8_t pipe, uint8_t toggle)
|
||||
{
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_GetToggle
|
||||
* Return the current toggle of a pipe.
|
||||
* @param phost: Host handle
|
||||
* @param pipe: Pipe index
|
||||
* @retval toggle (0/1)
|
||||
*/
|
||||
uint8_t USBH_LL_GetToggle (USBH_HandleTypeDef *phost, uint8_t pipe)
|
||||
{
|
||||
uint8_t toggle = 0;
|
||||
|
||||
|
||||
return toggle;
|
||||
}
|
||||
/**
|
||||
* @brief USBH_Delay
|
||||
* Delay routine for the USB Host Library
|
||||
* @param Delay: Delay in ms
|
||||
* @retval None
|
||||
*/
|
||||
void USBH_Delay (uint32_t Delay)
|
||||
{
|
||||
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+933
@@ -0,0 +1,933 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_core.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file implements the functions for the core state machine process
|
||||
* the enumeration and the control transfer process
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "usbh_core.h"
|
||||
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_LIB_CORE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CORE
|
||||
* @brief This file handles the basic enumeration when a device is connected
|
||||
* to the host.
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CORE_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
#define USBH_ADDRESS_DEFAULT 0
|
||||
#define USBH_ADDRESS_ASSIGNED 1
|
||||
#define USBH_MPS_DEFAULT 0x40
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CORE_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CORE_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CORE_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
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 == 1)
|
||||
static void USBH_Process_OS(void const * argument);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief HCD_Init
|
||||
* Initialize the HOST Core.
|
||||
* @param phost: Host Handle
|
||||
* @param pUsrFunc: User Callback
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_Init(USBH_HandleTypeDef *phost, void (*pUsrFunc)(USBH_HandleTypeDef *phost, uint8_t ), uint8_t id)
|
||||
{
|
||||
/* Check whether the USB Host handle is valid */
|
||||
if(phost == NULL)
|
||||
{
|
||||
USBH_ErrLog("Invalid Host handle");
|
||||
return USBH_FAIL;
|
||||
}
|
||||
|
||||
/* Set DRiver ID */
|
||||
phost->id = id;
|
||||
|
||||
/* Unlink class*/
|
||||
phost->pActiveClass = NULL;
|
||||
phost->ClassNumber = 0;
|
||||
|
||||
/* Restore default states and prepare EP0 */
|
||||
DeInitStateMachine(phost);
|
||||
|
||||
/* Assign User process */
|
||||
if(pUsrFunc != NULL)
|
||||
{
|
||||
phost->pUser = pUsrFunc;
|
||||
}
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
|
||||
/* Create USB Host Queue */
|
||||
osMessageQDef(USBH_Queue, 10, uint16_t);
|
||||
phost->os_event = osMessageCreate (osMessageQ(USBH_Queue), NULL);
|
||||
|
||||
/*Create USB Host Task */
|
||||
#if defined (USBH_PROCESS_STACK_SIZE)
|
||||
osThreadDef(USBH_Thread, USBH_Process_OS, USBH_PROCESS_PRIO, 0, USBH_PROCESS_STACK_SIZE);
|
||||
#else
|
||||
osThreadDef(USBH_Thread, USBH_Process_OS, USBH_PROCESS_PRIO, 0, 8 * configMINIMAL_STACK_SIZE);
|
||||
#endif
|
||||
phost->thread = osThreadCreate (osThread(USBH_Thread), phost);
|
||||
#endif
|
||||
|
||||
/* Initialize low level driver */
|
||||
USBH_LL_Init(phost);
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief HCD_Init
|
||||
* De-Initialize the Host portion of the driver.
|
||||
* @param phost: Host Handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_DeInit(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
DeInitStateMachine(phost);
|
||||
|
||||
if(phost->pData != NULL)
|
||||
{
|
||||
phost->pActiveClass->pData = NULL;
|
||||
USBH_LL_Stop(phost);
|
||||
}
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitStateMachine
|
||||
* De-Initialize the Host state machine.
|
||||
* @param phost: Host Handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
static USBH_StatusTypeDef DeInitStateMachine(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
|
||||
/* Clear Pipes flags*/
|
||||
for ( ; i < USBH_MAX_PIPES_NBR; i++)
|
||||
{
|
||||
phost->Pipes[i] = 0;
|
||||
}
|
||||
|
||||
for(i = 0; i< USBH_MAX_DATA_BUFFER; i++)
|
||||
{
|
||||
phost->device.Data[i] = 0;
|
||||
}
|
||||
|
||||
phost->gState = HOST_IDLE;
|
||||
phost->EnumState = ENUM_IDLE;
|
||||
phost->RequestState = CMD_SEND;
|
||||
phost->Timer = 0;
|
||||
|
||||
phost->Control.state = CTRL_SETUP;
|
||||
phost->Control.pipe_size = USBH_MPS_DEFAULT;
|
||||
phost->Control.errorcount = 0;
|
||||
|
||||
phost->device.address = USBH_ADDRESS_DEFAULT;
|
||||
phost->device.speed = USBH_SPEED_FULL;
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_RegisterClass
|
||||
* Link class driver to Host Core.
|
||||
* @param phost : Host Handle
|
||||
* @param pclass: Class handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_RegisterClass(USBH_HandleTypeDef *phost, USBH_ClassTypeDef *pclass)
|
||||
{
|
||||
USBH_StatusTypeDef status = USBH_OK;
|
||||
|
||||
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
|
||||
{
|
||||
USBH_ErrLog("Max Class Number reached");
|
||||
status = USBH_FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBH_ErrLog("Invalid Class handle");
|
||||
status = USBH_FAIL;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_SelectInterface
|
||||
* Select current interface.
|
||||
* @param phost: Host Handle
|
||||
* @param interface: Interface number
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_SelectInterface(USBH_HandleTypeDef *phost, uint8_t interface)
|
||||
{
|
||||
USBH_StatusTypeDef status = USBH_OK;
|
||||
|
||||
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.");
|
||||
status = USBH_FAIL;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_GetActiveClass
|
||||
* Return Device Class.
|
||||
* @param phost: Host Handle
|
||||
* @param interface: Interface index
|
||||
* @retval Class Code
|
||||
*/
|
||||
uint8_t USBH_GetActiveClass(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
return (phost->device.CfgDesc.Itf_Desc[0].bInterfaceClass);
|
||||
}
|
||||
/**
|
||||
* @brief USBH_FindInterface
|
||||
* Find the interface index for a specific class.
|
||||
* @param phost: Host Handle
|
||||
* @param Class: Class code
|
||||
* @param SubClass: SubClass code
|
||||
* @param Protocol: Protocol code
|
||||
* @retval interface index in the configuration structure
|
||||
* @note : (1)interface index 0xFF means interface index not found
|
||||
*/
|
||||
uint8_t USBH_FindInterface(USBH_HandleTypeDef *phost, uint8_t Class, uint8_t SubClass, uint8_t Protocol)
|
||||
{
|
||||
USBH_InterfaceDescTypeDef *pif ;
|
||||
USBH_CfgDescTypeDef *pcfg ;
|
||||
int8_t if_ix = 0;
|
||||
|
||||
pif = (USBH_InterfaceDescTypeDef *)0;
|
||||
pcfg = &phost->device.CfgDesc;
|
||||
|
||||
while (if_ix < USBH_MAX_NUM_INTERFACES)
|
||||
{
|
||||
pif = &pcfg->Itf_Desc[if_ix];
|
||||
if(((pif->bInterfaceClass == Class) || (Class == 0xFF))&&
|
||||
((pif->bInterfaceSubClass == SubClass) || (SubClass == 0xFF))&&
|
||||
((pif->bInterfaceProtocol == Protocol) || (Protocol == 0xFF)))
|
||||
{
|
||||
return if_ix;
|
||||
}
|
||||
if_ix++;
|
||||
}
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_FindInterfaceIndex
|
||||
* Find the interface index for a specific class interface and alternate setting number.
|
||||
* @param phost: Host Handle
|
||||
* @param interface_number: interface number
|
||||
* @param alt_settings : alternate setting number
|
||||
* @retval interface index in the configuration structure
|
||||
* @note : (1)interface index 0xFF means interface index not found
|
||||
*/
|
||||
uint8_t USBH_FindInterfaceIndex(USBH_HandleTypeDef *phost, uint8_t interface_number, uint8_t alt_settings)
|
||||
{
|
||||
USBH_InterfaceDescTypeDef *pif ;
|
||||
USBH_CfgDescTypeDef *pcfg ;
|
||||
int8_t if_ix = 0;
|
||||
|
||||
pif = (USBH_InterfaceDescTypeDef *)0;
|
||||
pcfg = &phost->device.CfgDesc;
|
||||
|
||||
while (if_ix < USBH_MAX_NUM_INTERFACES)
|
||||
{
|
||||
pif = &pcfg->Itf_Desc[if_ix];
|
||||
if((pif->bInterfaceNumber == interface_number) && (pif->bAlternateSetting == alt_settings))
|
||||
{
|
||||
return if_ix;
|
||||
}
|
||||
if_ix++;
|
||||
}
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_Start
|
||||
* Start the USB Host Core.
|
||||
* @param phost: Host Handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
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);
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_Stop
|
||||
* Stop the USB Host Core.
|
||||
* @param phost: Host Handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
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);
|
||||
|
||||
/* FRee Control Pipes */
|
||||
USBH_FreePipe (phost, phost->Control.pipe_in);
|
||||
USBH_FreePipe (phost, phost->Control.pipe_out);
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief HCD_ReEnumerate
|
||||
* Perform a new Enumeration phase.
|
||||
* @param phost: Host Handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_ReEnumerate (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
/*Stop Host */
|
||||
USBH_Stop(phost);
|
||||
|
||||
/*Device has disconnected, so wait for 200 ms */
|
||||
USBH_Delay(200);
|
||||
|
||||
/* Set State machines in default state */
|
||||
DeInitStateMachine(phost);
|
||||
|
||||
/* Start again the host */
|
||||
USBH_Start(phost);
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
|
||||
#endif
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_Process
|
||||
* Background process of the USB Core.
|
||||
* @param phost: Host Handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost)
|
||||
{
|
||||
__IO USBH_StatusTypeDef status = USBH_FAIL;
|
||||
uint8_t idx = 0;
|
||||
|
||||
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(200);
|
||||
USBH_LL_ResetPort(phost);
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case HOST_DEV_WAIT_FOR_ATTACHMENT:
|
||||
break;
|
||||
|
||||
case HOST_DEV_ATTACHED :
|
||||
|
||||
USBH_UsrLog("USB Device Attached");
|
||||
|
||||
/* Wait for 100 ms after Reset */
|
||||
USBH_Delay(100);
|
||||
|
||||
phost->device.speed = USBH_LL_GetSpeed(phost);
|
||||
|
||||
phost->gState = HOST_ENUMERATION;
|
||||
|
||||
phost->Control.pipe_out = USBH_AllocPipe (phost, 0x00);
|
||||
phost->Control.pipe_in = USBH_AllocPipe (phost, 0x80);
|
||||
|
||||
|
||||
/* Open Control pipes */
|
||||
USBH_OpenPipe (phost,
|
||||
phost->Control.pipe_in,
|
||||
0x80,
|
||||
phost->device.address,
|
||||
phost->device.speed,
|
||||
USBH_EP_CONTROL,
|
||||
phost->Control.pipe_size);
|
||||
|
||||
/* Open Control pipes */
|
||||
USBH_OpenPipe (phost,
|
||||
phost->Control.pipe_out,
|
||||
0x00,
|
||||
phost->device.address,
|
||||
phost->device.speed,
|
||||
USBH_EP_CONTROL,
|
||||
phost->Control.pipe_size);
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
|
||||
#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 = 0;
|
||||
if(phost->device.DevDesc.bNumConfigurations == 1)
|
||||
{
|
||||
USBH_UsrLog ("This device has only 1 configuration.");
|
||||
phost->gState = HOST_SET_CONFIGURATION;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
phost->gState = HOST_INPUT;
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case HOST_SET_CONFIGURATION:
|
||||
/* set configuration */
|
||||
if (USBH_SetCfg(phost, phost->device.CfgDesc.bConfigurationValue) == USBH_OK)
|
||||
{
|
||||
phost->gState = HOST_CHECK_CLASS;
|
||||
USBH_UsrLog ("Default configuration set.");
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case HOST_CHECK_CLASS:
|
||||
|
||||
if(phost->ClassNumber == 0)
|
||||
{
|
||||
USBH_UsrLog ("No Class has been registered.");
|
||||
}
|
||||
else
|
||||
{
|
||||
phost->pActiveClass = NULL;
|
||||
|
||||
for (idx = 0; 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->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 ("No registered class for this device.");
|
||||
}
|
||||
}
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
|
||||
#endif
|
||||
break;
|
||||
|
||||
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 (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
break;
|
||||
case HOST_CLASS:
|
||||
/* process class state machine */
|
||||
if(phost->pActiveClass != NULL)
|
||||
{
|
||||
phost->pActiveClass->BgndProcess(phost);
|
||||
}
|
||||
break;
|
||||
|
||||
case HOST_DEV_DISCONNECTED :
|
||||
|
||||
DeInitStateMachine(phost);
|
||||
|
||||
/* Re-Initilaize Host for new Enumeration */
|
||||
if(phost->pActiveClass != NULL)
|
||||
{
|
||||
phost->pActiveClass->DeInit(phost);
|
||||
phost->pActiveClass = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case HOST_ABORT_STATE:
|
||||
default :
|
||||
break;
|
||||
}
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_HandleEnum
|
||||
* This function includes the complete enumeration process
|
||||
* @param phost: Host Handle
|
||||
* @retval USBH_Status
|
||||
*/
|
||||
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, 8) == 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,
|
||||
0x80,
|
||||
phost->device.address,
|
||||
phost->device.speed,
|
||||
USBH_EP_CONTROL,
|
||||
phost->Control.pipe_size);
|
||||
|
||||
/* Open Control pipes */
|
||||
USBH_OpenPipe (phost,
|
||||
phost->Control.pipe_out,
|
||||
0x00,
|
||||
phost->device.address,
|
||||
phost->device.speed,
|
||||
USBH_EP_CONTROL,
|
||||
phost->Control.pipe_size);
|
||||
|
||||
}
|
||||
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 );
|
||||
|
||||
phost->EnumState = ENUM_SET_ADDR;
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case ENUM_SET_ADDR:
|
||||
/* set address */
|
||||
if ( USBH_SetAddress(phost, USBH_DEVICE_ADDRESS) == USBH_OK)
|
||||
{
|
||||
USBH_Delay(2);
|
||||
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,
|
||||
0x80,
|
||||
phost->device.address,
|
||||
phost->device.speed,
|
||||
USBH_EP_CONTROL,
|
||||
phost->Control.pipe_size);
|
||||
|
||||
/* Open Control pipes */
|
||||
USBH_OpenPipe (phost,
|
||||
phost->Control.pipe_out,
|
||||
0x00,
|
||||
phost->device.address,
|
||||
phost->device.speed,
|
||||
USBH_EP_CONTROL,
|
||||
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 != 0)
|
||||
{ /* Check that Manufacturer String is available */
|
||||
|
||||
if ( USBH_Get_StringDesc(phost,
|
||||
phost->device.DevDesc.iManufacturer,
|
||||
phost->device.Data ,
|
||||
0xff) == USBH_OK)
|
||||
{
|
||||
/* User callback for Manufacturing string */
|
||||
USBH_UsrLog("Manufacturer : %s", (char *)phost->device.Data);
|
||||
phost->EnumState = ENUM_GET_PRODUCT_STRING_DESC;
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBH_UsrLog("Manufacturer : N/A");
|
||||
phost->EnumState = ENUM_GET_PRODUCT_STRING_DESC;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case ENUM_GET_PRODUCT_STRING_DESC:
|
||||
if (phost->device.DevDesc.iProduct != 0)
|
||||
{ /* Check that Product string is available */
|
||||
if ( USBH_Get_StringDesc(phost,
|
||||
phost->device.DevDesc.iProduct,
|
||||
phost->device.Data,
|
||||
0xff) == USBH_OK)
|
||||
{
|
||||
/* User callback for Product string */
|
||||
USBH_UsrLog("Product : %s", (char *)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 == 1)
|
||||
osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case ENUM_GET_SERIALNUM_STRING_DESC:
|
||||
if (phost->device.DevDesc.iSerialNumber != 0)
|
||||
{ /* Check that Serial number string is available */
|
||||
if ( USBH_Get_StringDesc(phost,
|
||||
phost->device.DevDesc.iSerialNumber,
|
||||
phost->device.Data,
|
||||
0xff) == USBH_OK)
|
||||
{
|
||||
/* User callback for Serial number string */
|
||||
USBH_UsrLog("Serial Number : %s", (char *)phost->device.Data);
|
||||
Status = USBH_OK;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBH_UsrLog("Serial Number : N/A");
|
||||
Status = USBH_OK;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_SetTimer
|
||||
* Set the initial Host Timer tick
|
||||
* @param phost: Host Handle
|
||||
* @retval None
|
||||
*/
|
||||
void USBH_LL_SetTimer (USBH_HandleTypeDef *phost, uint32_t time)
|
||||
{
|
||||
phost->Timer = time;
|
||||
}
|
||||
/**
|
||||
* @brief USBH_LL_IncTimer
|
||||
* Increment Host Timer tick
|
||||
* @param phost: Host Handle
|
||||
* @retval None
|
||||
*/
|
||||
void USBH_LL_IncTimer (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
phost->Timer ++;
|
||||
USBH_HandleSof(phost);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_HandleSof
|
||||
* Call SOF process
|
||||
* @param phost: Host Handle
|
||||
* @retval None
|
||||
*/
|
||||
void USBH_HandleSof (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
if((phost->gState == HOST_CLASS)&&(phost->pActiveClass != NULL))
|
||||
{
|
||||
phost->pActiveClass->SOFProcess(phost);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief USBH_LL_Connect
|
||||
* Handle USB Host connexion event
|
||||
* @param phost: Host Handle
|
||||
* @retval USBH_Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_LL_Connect (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
if(phost->gState == HOST_IDLE )
|
||||
{
|
||||
phost->device.is_connected = 1;
|
||||
|
||||
if(phost->pUser != NULL)
|
||||
{
|
||||
phost->pUser(phost, HOST_USER_CONNECTION);
|
||||
}
|
||||
}
|
||||
else if(phost->gState == HOST_DEV_WAIT_FOR_ATTACHMENT )
|
||||
{
|
||||
phost->gState = HOST_DEV_ATTACHED ;
|
||||
}
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
|
||||
#endif
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_Disconnect
|
||||
* Handle USB Host disconnection event
|
||||
* @param phost: Host Handle
|
||||
* @retval USBH_Status
|
||||
*/
|
||||
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);
|
||||
|
||||
phost->device.is_connected = 0;
|
||||
|
||||
if(phost->pUser != NULL)
|
||||
{
|
||||
phost->pUser(phost, HOST_USER_DISCONNECTION);
|
||||
}
|
||||
USBH_UsrLog("USB Device disconnected");
|
||||
|
||||
/* Start the low level driver */
|
||||
USBH_LL_Start(phost);
|
||||
|
||||
phost->gState = HOST_DEV_DISCONNECTED;
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0);
|
||||
#endif
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
/**
|
||||
* @brief USB Host Thread task
|
||||
* @param pvParameters not used
|
||||
* @retval None
|
||||
*/
|
||||
static void USBH_Process_OS(void const * argument)
|
||||
{
|
||||
osEvent event;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
event = osMessageGet(((USBH_HandleTypeDef *)argument)->os_event, osWaitForever );
|
||||
|
||||
if( event.status == osEventMessage )
|
||||
{
|
||||
USBH_Process((USBH_HandleTypeDef *)argument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_LL_NotifyURBChange
|
||||
* Notify URB state Change
|
||||
* @param phost: Host handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_LL_NotifyURBChange (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
|
||||
return USBH_OK;
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
+881
@@ -0,0 +1,881 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_ctlreq.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file implements the control requests for device enumeration
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "usbh_ctlreq.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_LIB_CORE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CTLREQ
|
||||
* @brief This file implements the standard requests for device enumeration
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CTLREQ_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CTLREQ_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBH_CTLREQ_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CTLREQ_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CTLREQ_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static USBH_StatusTypeDef USBH_HandleControl (USBH_HandleTypeDef *phost);
|
||||
|
||||
static void USBH_ParseDevDesc (USBH_DevDescTypeDef* , 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);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CTLREQ_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_Get_DevDesc
|
||||
* Issue Get Device Descriptor command to the device. Once the response
|
||||
* received, it parses the device descriptor and updates the status.
|
||||
* @param phost: Host Handle
|
||||
* @param length: Length of the descriptor
|
||||
* @retval USBH Status
|
||||
*/
|
||||
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,
|
||||
length)) == USBH_OK)
|
||||
{
|
||||
/* Commands successfully sent and Response Received */
|
||||
USBH_ParseDevDesc(&phost->device.DevDesc, phost->device.Data, length);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_Get_CfgDesc
|
||||
* Issues Configuration Descriptor to the device. Once the response
|
||||
* received, it parses the configuration descriptor and updates the
|
||||
* status.
|
||||
* @param phost: Host Handle
|
||||
* @param length: Length of the descriptor
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_Get_CfgDesc(USBH_HandleTypeDef *phost,
|
||||
uint16_t length)
|
||||
|
||||
{
|
||||
USBH_StatusTypeDef status;
|
||||
uint8_t *pData;
|
||||
#if (USBH_KEEP_CFG_DESCRIPTOR == 1)
|
||||
pData = phost->device.CfgDesc_Raw;
|
||||
#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)
|
||||
{
|
||||
|
||||
/* Commands successfully sent and Response Received */
|
||||
USBH_ParseCfgDesc (&phost->device.CfgDesc,
|
||||
pData,
|
||||
length);
|
||||
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_Get_StringDesc
|
||||
* Issues string Descriptor command to the device. Once the response
|
||||
* received, it parses the string descriptor and updates the status.
|
||||
* @param phost: Host Handle
|
||||
* @param string_index: String index for the descriptor
|
||||
* @param buff: Buffer address for the descriptor
|
||||
* @param length: Length of the descriptor
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_Get_StringDesc(USBH_HandleTypeDef *phost,
|
||||
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)
|
||||
{
|
||||
/* Commands successfully sent and Response Received */
|
||||
USBH_ParseStringDesc(phost->device.Data,buff, length);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_GetDescriptor
|
||||
* Issues Descriptor command to the device. Once the response received,
|
||||
* it parses the descriptor and updates the status.
|
||||
* @param phost: Host Handle
|
||||
* @param req_type: Descriptor type
|
||||
* @param value_idx: Value for the GetDescriptr request
|
||||
* @param buff: Buffer to store the descriptor
|
||||
* @param length: Length of the descriptor
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost,
|
||||
uint8_t req_type,
|
||||
uint16_t value_idx,
|
||||
uint8_t* buff,
|
||||
uint16_t length )
|
||||
{
|
||||
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 & 0xff00) == USB_DESC_STRING)
|
||||
{
|
||||
phost->Control.setup.b.wIndex.w = 0x0409;
|
||||
}
|
||||
else
|
||||
{
|
||||
phost->Control.setup.b.wIndex.w = 0;
|
||||
}
|
||||
phost->Control.setup.b.wLength.w = length;
|
||||
}
|
||||
return USBH_CtlReq(phost, buff , length );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_SetAddress
|
||||
* This command sets the address to the connected device
|
||||
* @param phost: Host Handle
|
||||
* @param DeviceAddress: Device address to assign
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_SetAddress(USBH_HandleTypeDef *phost,
|
||||
uint8_t DeviceAddress)
|
||||
{
|
||||
if(phost->RequestState == CMD_SEND)
|
||||
{
|
||||
phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_DEVICE | \
|
||||
USB_REQ_TYPE_STANDARD;
|
||||
|
||||
phost->Control.setup.b.bRequest = USB_REQ_SET_ADDRESS;
|
||||
|
||||
phost->Control.setup.b.wValue.w = (uint16_t)DeviceAddress;
|
||||
phost->Control.setup.b.wIndex.w = 0;
|
||||
phost->Control.setup.b.wLength.w = 0;
|
||||
}
|
||||
return USBH_CtlReq(phost, 0 , 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_SetCfg
|
||||
* The command sets the configuration value to the connected device
|
||||
* @param phost: Host Handle
|
||||
* @param cfg_idx: Configuration value
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_SetCfg(USBH_HandleTypeDef *phost,
|
||||
uint16_t cfg_idx)
|
||||
{
|
||||
if(phost->RequestState == CMD_SEND)
|
||||
{
|
||||
phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_DEVICE |\
|
||||
USB_REQ_TYPE_STANDARD;
|
||||
phost->Control.setup.b.bRequest = USB_REQ_SET_CONFIGURATION;
|
||||
phost->Control.setup.b.wValue.w = cfg_idx;
|
||||
phost->Control.setup.b.wIndex.w = 0;
|
||||
phost->Control.setup.b.wLength.w = 0;
|
||||
}
|
||||
|
||||
return USBH_CtlReq(phost, 0 , 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_SetInterface
|
||||
* The command sets the Interface value to the connected device
|
||||
* @param phost: Host Handle
|
||||
* @param altSetting: Interface value
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_SetInterface(USBH_HandleTypeDef *phost,
|
||||
uint8_t ep_num, uint8_t altSetting)
|
||||
{
|
||||
|
||||
if(phost->RequestState == CMD_SEND)
|
||||
{
|
||||
phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE | \
|
||||
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 = 0;
|
||||
}
|
||||
return USBH_CtlReq(phost, 0 , 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_ClrFeature
|
||||
* This request is used to clear or disable a specific feature.
|
||||
* @param phost: Host Handle
|
||||
* @param ep_num: endpoint number
|
||||
* @param hc_num: Host channel number
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_ClrFeature(USBH_HandleTypeDef *phost,
|
||||
uint8_t ep_num)
|
||||
{
|
||||
if(phost->RequestState == CMD_SEND)
|
||||
{
|
||||
phost->Control.setup.b.bmRequestType = USB_H2D |
|
||||
USB_REQ_RECIPIENT_ENDPOINT |
|
||||
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 = 0;
|
||||
}
|
||||
return USBH_CtlReq(phost, 0 , 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_ParseDevDesc
|
||||
* This function Parses the device descriptor
|
||||
* @param dev_desc: device_descriptor destination address
|
||||
* @param buf: Buffer where the source descriptor is available
|
||||
* @param length: Length of the descriptor
|
||||
* @retval None
|
||||
*/
|
||||
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 > 8)
|
||||
{ /* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_ParseCfgDesc
|
||||
* This function Parses the configuration descriptor
|
||||
* @param cfg_desc: Configuration Descriptor address
|
||||
* @param buf: Buffer where the source descriptor is available
|
||||
* @param length: Length of the descriptor
|
||||
* @retval None
|
||||
*/
|
||||
static void USBH_ParseCfgDesc (USBH_CfgDescTypeDef* cfg_desc,
|
||||
uint8_t *buf,
|
||||
uint16_t length)
|
||||
{
|
||||
USBH_InterfaceDescTypeDef *pif ;
|
||||
USBH_EpDescTypeDef *pep;
|
||||
USBH_DescHeader_t *pdesc = (USBH_DescHeader_t *)buf;
|
||||
uint16_t ptr;
|
||||
int8_t if_ix = 0;
|
||||
int8_t ep_ix = 0;
|
||||
|
||||
pdesc = (USBH_DescHeader_t *)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)
|
||||
{
|
||||
ptr = USB_LEN_CFG_DESC;
|
||||
pif = (USBH_InterfaceDescTypeDef *)0;
|
||||
|
||||
|
||||
while ((if_ix < USBH_MAX_NUM_INTERFACES ) && (ptr < cfg_desc->wTotalLength))
|
||||
{
|
||||
pdesc = USBH_GetNextDesc((uint8_t *)pdesc, &ptr);
|
||||
if (pdesc->bDescriptorType == USB_DESC_TYPE_INTERFACE)
|
||||
{
|
||||
pif = &cfg_desc->Itf_Desc[if_ix];
|
||||
USBH_ParseInterfaceDesc (pif, (uint8_t *)pdesc);
|
||||
|
||||
ep_ix = 0;
|
||||
pep = (USBH_EpDescTypeDef *)0;
|
||||
while ((ep_ix < pif->bNumEndpoints) && (ptr < cfg_desc->wTotalLength))
|
||||
{
|
||||
pdesc = USBH_GetNextDesc((uint8_t*) 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 *)pdesc);
|
||||
ep_ix++;
|
||||
}
|
||||
}
|
||||
if_ix++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_ParseInterfaceDesc
|
||||
* This function Parses the interface descriptor
|
||||
* @param if_descriptor : Interface descriptor destination
|
||||
* @param buf: Buffer where the descriptor data is available
|
||||
* @retval None
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_ParseEPDesc
|
||||
* This function Parses the endpoint descriptor
|
||||
* @param ep_descriptor: Endpoint descriptor destination address
|
||||
* @param buf: Buffer where the parsed descriptor stored
|
||||
* @retval None
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_ParseStringDesc
|
||||
* This function Parses the string descriptor
|
||||
* @param psrc: Source pointer containing the descriptor data
|
||||
* @param pdest: Destination address pointer
|
||||
* @param length: Length of the descriptor
|
||||
* @retval None
|
||||
*/
|
||||
static void USBH_ParseStringDesc (uint8_t* psrc,
|
||||
uint8_t* pdest,
|
||||
uint16_t length)
|
||||
{
|
||||
uint16_t strlength;
|
||||
uint16_t idx;
|
||||
|
||||
/* The UNICODE string descriptor is not NULL-terminated. The string length is
|
||||
computed by substracting two from the value of the first byte of the descriptor.
|
||||
*/
|
||||
|
||||
/* 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)
|
||||
{ /* Make sure the Descriptor is String Type */
|
||||
|
||||
/* psrc[0] contains Size of Descriptor, subtract 2 to get the length of string */
|
||||
strlength = ( ( (psrc[0]-2) <= length) ? (psrc[0]-2) :length);
|
||||
psrc += 2; /* Adjust the offset ignoring the String Len and Descriptor type */
|
||||
|
||||
for (idx = 0; idx < strlength; idx+=2 )
|
||||
{/* Copy Only the string and ignore the UNICODE ID, hence add the src */
|
||||
*pdest = psrc[idx];
|
||||
pdest++;
|
||||
}
|
||||
*pdest = 0; /* mark end of string */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_GetNextDesc
|
||||
* This function return the next descriptor header
|
||||
* @param buf: Buffer where the cfg descriptor is available
|
||||
* @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 *pnext;
|
||||
|
||||
*ptr += ((USBH_DescHeader_t *)pbuf)->bLength;
|
||||
pnext = (USBH_DescHeader_t *)((uint8_t *)pbuf + \
|
||||
((USBH_DescHeader_t *)pbuf)->bLength);
|
||||
|
||||
return(pnext);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_CtlReq
|
||||
* USBH_CtlReq sends a control request and provide the status after
|
||||
* completion of the request
|
||||
* @param phost: Host Handle
|
||||
* @param req: Setup Request Structure
|
||||
* @param buff: data buffer address to store the response
|
||||
* @param length: length of the response
|
||||
* @retval USBH Status
|
||||
*/
|
||||
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;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
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_FAIL)
|
||||
{
|
||||
/* Failure Mode */
|
||||
phost->RequestState = CMD_SEND;
|
||||
status = USBH_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_HandleControl
|
||||
* Handles the USB control transfer state machine
|
||||
* @param phost: Host Handle
|
||||
* @retval USBH Status
|
||||
*/
|
||||
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 *)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 != 0 )
|
||||
{
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Data Direction is OUT */
|
||||
phost->Control.state = CTRL_STATUS_IN;
|
||||
}
|
||||
}
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
else if(URB_Status == USBH_URB_ERROR)
|
||||
{
|
||||
phost->Control.state = CTRL_ERROR;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case CTRL_DATA_IN:
|
||||
/* Issue an IN token */
|
||||
phost->Control.timer = phost->Timer;
|
||||
USBH_CtlReceiveData(phost,
|
||||
phost->Control.buff,
|
||||
phost->Control.length,
|
||||
phost->Control.pipe_in);
|
||||
|
||||
phost->Control.state = CTRL_DATA_IN_WAIT;
|
||||
break;
|
||||
|
||||
case CTRL_DATA_IN_WAIT:
|
||||
|
||||
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;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* 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 == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
else if (URB_Status == USBH_URB_ERROR)
|
||||
{
|
||||
/* Device error */
|
||||
phost->Control.state = CTRL_ERROR;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case CTRL_DATA_OUT:
|
||||
|
||||
USBH_CtlSendData (phost,
|
||||
phost->Control.buff,
|
||||
phost->Control.length ,
|
||||
phost->Control.pipe_out,
|
||||
1);
|
||||
phost->Control.timer = phost->Timer;
|
||||
phost->Control.state = CTRL_DATA_OUT_WAIT;
|
||||
break;
|
||||
|
||||
case CTRL_DATA_OUT_WAIT:
|
||||
|
||||
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 (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#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;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
else if (URB_Status == USBH_URB_NOTREADY)
|
||||
{
|
||||
/* Nack received from device */
|
||||
phost->Control.state = CTRL_DATA_OUT;
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
else if (URB_Status == USBH_URB_ERROR)
|
||||
{
|
||||
/* device error */
|
||||
phost->Control.state = CTRL_ERROR;
|
||||
status = USBH_FAIL;
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case CTRL_STATUS_IN:
|
||||
/* Send 0 bytes out packet */
|
||||
USBH_CtlReceiveData (phost,
|
||||
0,
|
||||
0,
|
||||
phost->Control.pipe_in);
|
||||
phost->Control.timer = phost->Timer;
|
||||
phost->Control.state = CTRL_STATUS_IN_WAIT;
|
||||
|
||||
break;
|
||||
|
||||
case CTRL_STATUS_IN_WAIT:
|
||||
|
||||
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 (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
else if (URB_Status == USBH_URB_ERROR)
|
||||
{
|
||||
phost->Control.state = CTRL_ERROR;
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
else if(URB_Status == USBH_URB_STALL)
|
||||
{
|
||||
/* Control transfers completed, Exit the State Machine */
|
||||
status = USBH_NOT_SUPPORTED;
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case CTRL_STATUS_OUT:
|
||||
USBH_CtlSendData (phost,
|
||||
0,
|
||||
0,
|
||||
phost->Control.pipe_out,
|
||||
1);
|
||||
phost->Control.timer = 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 == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
else if (URB_Status == USBH_URB_NOTREADY)
|
||||
{
|
||||
phost->Control.state = CTRL_STATUS_OUT;
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#endif
|
||||
}
|
||||
else if (URB_Status == USBH_URB_ERROR)
|
||||
{
|
||||
phost->Control.state = CTRL_ERROR;
|
||||
|
||||
#if (USBH_USE_OS == 1)
|
||||
osMessagePut ( phost->os_event, USBH_CONTROL_EVENT, 0);
|
||||
#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 = 0;
|
||||
USBH_ErrLog("Control error");
|
||||
status = USBH_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
|
||||
|
||||
+358
@@ -0,0 +1,358 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_ioreq.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file handles the issuing of the USB transactions
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "usbh_ioreq.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_LIB_CORE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_IOREQ
|
||||
* @brief This file handles the standard protocol processing (USB v2.0)
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_IOREQ_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_IOREQ_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBH_IOREQ_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_IOREQ_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/** @defgroup USBH_IOREQ_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_IOREQ_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_CtlSendSetup
|
||||
* Sends the Setup Packet to the Device
|
||||
* @param phost: Host Handle
|
||||
* @param buff: Buffer pointer from which the Data will be send to Device
|
||||
* @param pipe_num: Pipe Number
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_CtlSendSetup (USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint8_t pipe_num)
|
||||
{
|
||||
|
||||
USBH_LL_SubmitURB (phost, /* Driver handle */
|
||||
pipe_num, /* Pipe index */
|
||||
0, /* Direction : OUT */
|
||||
USBH_EP_CONTROL, /* EP type */
|
||||
USBH_PID_SETUP, /* Type setup */
|
||||
buff, /* data buffer */
|
||||
USBH_SETUP_PKT_SIZE, /* data length */
|
||||
0);
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_CtlSendData
|
||||
* Sends a data Packet to the Device
|
||||
* @param phost: Host Handle
|
||||
* @param buff: Buffer pointer from which the Data will be sent to Device
|
||||
* @param length: Length of the data to be sent
|
||||
* @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 )
|
||||
{
|
||||
if(phost->device.speed != USBH_SPEED_HIGH)
|
||||
{
|
||||
do_ping = 0;
|
||||
}
|
||||
|
||||
USBH_LL_SubmitURB (phost, /* Driver handle */
|
||||
pipe_num, /* Pipe index */
|
||||
0, /* 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_CtlReceiveData
|
||||
* Receives the Device Response to the Setup Packet
|
||||
* @param phost: Host Handle
|
||||
* @param buff: Buffer pointer in which the response needs to be copied
|
||||
* @param length: Length of the data to be received
|
||||
* @param pipe_num: Pipe Number
|
||||
* @retval USBH Status.
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost,
|
||||
uint8_t* buff,
|
||||
uint16_t length,
|
||||
uint8_t pipe_num)
|
||||
{
|
||||
USBH_LL_SubmitURB (phost, /* Driver handle */
|
||||
pipe_num, /* Pipe index */
|
||||
1, /* Direction : IN */
|
||||
USBH_EP_CONTROL, /* EP type */
|
||||
USBH_PID_DATA, /* Type Data */
|
||||
buff, /* data buffer */
|
||||
length, /* data length */
|
||||
0);
|
||||
return USBH_OK;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_BulkSendData
|
||||
* Sends the Bulk Packet to the device
|
||||
* @param phost: Host Handle
|
||||
* @param buff: Buffer pointer from which the Data will be sent to Device
|
||||
* @param length: Length of the data to be sent
|
||||
* @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 )
|
||||
{
|
||||
if(phost->device.speed != USBH_SPEED_HIGH)
|
||||
{
|
||||
do_ping = 0;
|
||||
}
|
||||
|
||||
USBH_LL_SubmitURB (phost, /* Driver handle */
|
||||
pipe_num, /* Pipe index */
|
||||
0, /* 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_BulkReceiveData
|
||||
* Receives IN bulk packet from device
|
||||
* @param phost: Host Handle
|
||||
* @param buff: Buffer pointer in which the received data packet to be copied
|
||||
* @param length: Length of the data to be received
|
||||
* @param pipe_num: Pipe Number
|
||||
* @retval USBH Status.
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint16_t length,
|
||||
uint8_t pipe_num)
|
||||
{
|
||||
USBH_LL_SubmitURB (phost, /* Driver handle */
|
||||
pipe_num, /* Pipe index */
|
||||
1, /* Direction : IN */
|
||||
USBH_EP_BULK, /* EP type */
|
||||
USBH_PID_DATA, /* Type Data */
|
||||
buff, /* data buffer */
|
||||
length, /* data length */
|
||||
0);
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_InterruptReceiveData
|
||||
* Receives the Device Response to the Interrupt IN token
|
||||
* @param phost: Host Handle
|
||||
* @param buff: Buffer pointer in which the response needs to be copied
|
||||
* @param length: Length of the data to be received
|
||||
* @param pipe_num: Pipe Number
|
||||
* @retval USBH Status.
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint8_t length,
|
||||
uint8_t pipe_num)
|
||||
{
|
||||
USBH_LL_SubmitURB (phost, /* Driver handle */
|
||||
pipe_num, /* Pipe index */
|
||||
1, /* Direction : IN */
|
||||
USBH_EP_INTERRUPT, /* EP type */
|
||||
USBH_PID_DATA, /* Type Data */
|
||||
buff, /* data buffer */
|
||||
length, /* data length */
|
||||
0);
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_InterruptSendData
|
||||
* Sends the data on Interrupt OUT Endpoint
|
||||
* @param phost: Host Handle
|
||||
* @param buff: Buffer pointer from where the data needs to be copied
|
||||
* @param length: Length of the data to be sent
|
||||
* @param pipe_num: Pipe Number
|
||||
* @retval USBH Status.
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint8_t length,
|
||||
uint8_t pipe_num)
|
||||
{
|
||||
USBH_LL_SubmitURB (phost, /* Driver handle */
|
||||
pipe_num, /* Pipe index */
|
||||
0, /* Direction : OUT */
|
||||
USBH_EP_INTERRUPT, /* EP type */
|
||||
USBH_PID_DATA, /* Type Data */
|
||||
buff, /* data buffer */
|
||||
length, /* data length */
|
||||
0);
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_IsocReceiveData
|
||||
* Receives the Device Response to the Isochronous IN token
|
||||
* @param phost: Host Handle
|
||||
* @param buff: Buffer pointer in which the response needs to be copied
|
||||
* @param length: Length of the data to be received
|
||||
* @param pipe_num: Pipe Number
|
||||
* @retval USBH Status.
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint32_t length,
|
||||
uint8_t pipe_num)
|
||||
{
|
||||
USBH_LL_SubmitURB (phost, /* Driver handle */
|
||||
pipe_num, /* Pipe index */
|
||||
1, /* Direction : IN */
|
||||
USBH_EP_ISO, /* EP type */
|
||||
USBH_PID_DATA, /* Type Data */
|
||||
buff, /* data buffer */
|
||||
length, /* data length */
|
||||
0);
|
||||
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_IsocSendData
|
||||
* Sends the data on Isochronous OUT Endpoint
|
||||
* @param phost: Host Handle
|
||||
* @param buff: Buffer pointer from where the data needs to be copied
|
||||
* @param length: Length of the data to be sent
|
||||
* @param pipe_num: Pipe Number
|
||||
* @retval USBH Status.
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_IsocSendData(USBH_HandleTypeDef *phost,
|
||||
uint8_t *buff,
|
||||
uint32_t length,
|
||||
uint8_t pipe_num)
|
||||
{
|
||||
USBH_LL_SubmitURB (phost, /* Driver handle */
|
||||
pipe_num, /* Pipe index */
|
||||
0, /* Direction : OUT */
|
||||
USBH_EP_ISO, /* EP type */
|
||||
USBH_PID_DATA, /* Type Data */
|
||||
buff, /* data buffer */
|
||||
length, /* data length */
|
||||
0);
|
||||
|
||||
return USBH_OK;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_pipes.c
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.2
|
||||
* @date 07-July-2015
|
||||
* @brief This file implements functions for opening and closing Pipes
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbh_pipes.h"
|
||||
|
||||
/** @addtogroup USBH_LIB
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBH_LIB_CORE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_PIPES
|
||||
* @brief This file includes opening and closing Pipes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_PIPES_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_PIPES_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_PIPES_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_PIPES_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_PIPES_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
static uint16_t USBH_GetFreePipe (USBH_HandleTypeDef *phost);
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBH_Open_Pipe
|
||||
* Open a pipe
|
||||
* @param phost: Host Handle
|
||||
* @param pipe_num: Pipe Number
|
||||
* @param dev_address: USB Device address allocated to attached device
|
||||
* @param speed : USB device speed (Full/Low)
|
||||
* @param ep_type: end point type (Bulk/int/ctl)
|
||||
* @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_LL_OpenPipe(phost,
|
||||
pipe_num,
|
||||
epnum,
|
||||
dev_address,
|
||||
speed,
|
||||
ep_type,
|
||||
mps);
|
||||
|
||||
return USBH_OK;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_ClosePipe
|
||||
* Close a pipe
|
||||
* @param phost: Host Handle
|
||||
* @param pipe_num: Pipe Number
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_ClosePipe (USBH_HandleTypeDef *phost,
|
||||
uint8_t pipe_num)
|
||||
{
|
||||
|
||||
USBH_LL_ClosePipe(phost, pipe_num);
|
||||
|
||||
return USBH_OK;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_Alloc_Pipe
|
||||
* Allocate a new Pipe
|
||||
* @param phost: Host Handle
|
||||
* @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)
|
||||
{
|
||||
uint16_t pipe;
|
||||
|
||||
pipe = USBH_GetFreePipe(phost);
|
||||
|
||||
if (pipe != 0xFFFF)
|
||||
{
|
||||
phost->Pipes[pipe] = 0x8000 | ep_addr;
|
||||
}
|
||||
return pipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_Free_Pipe
|
||||
* Free the USB Pipe
|
||||
* @param phost: Host Handle
|
||||
* @param idx: Pipe number to be freed
|
||||
* @retval USBH Status
|
||||
*/
|
||||
USBH_StatusTypeDef USBH_FreePipe (USBH_HandleTypeDef *phost, uint8_t idx)
|
||||
{
|
||||
if(idx < 11)
|
||||
{
|
||||
phost->Pipes[idx] &= 0x7FFF;
|
||||
}
|
||||
return USBH_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBH_GetFreePipe
|
||||
* @param phost: Host Handle
|
||||
* Get a free Pipe number for allocation to a device endpoint
|
||||
* @retval idx: Free Pipe number
|
||||
*/
|
||||
static uint16_t USBH_GetFreePipe (USBH_HandleTypeDef *phost)
|
||||
{
|
||||
uint8_t idx = 0;
|
||||
|
||||
for (idx = 0 ; idx < 11 ; idx++)
|
||||
{
|
||||
if ((phost->Pipes[idx] & 0x8000) == 0)
|
||||
{
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
return 0xFFFF;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
Vendored
Executable
+180
@@ -0,0 +1,180 @@
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
|
||||
/* */
|
||||
/* Portions COPYRIGHT 2016 STMicroelectronics */
|
||||
/* Portions Copyright (C) 2014, ChaN, all right reserved */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* If a working storage control module is available, it should be */
|
||||
/* attached to the FatFs via a glue function rather than modifying it. */
|
||||
/* This is an example of glue functions to attach various exsisting */
|
||||
/* storage control modules to the FatFs module with a defined API. */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file diskio.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.4.0
|
||||
* @date 23-December-2016
|
||||
* @brief FatFs low level disk I/O module.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "diskio.h"
|
||||
#include "ff_gen_drv.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
extern Disk_drvTypeDef disk;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Gets Disk Status
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS disk_status (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS stat;
|
||||
|
||||
stat = disk.drv[pdrv]->disk_status(disk.lun[pdrv]);
|
||||
return stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes a Drive
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS disk_initialize (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS stat = RES_OK;
|
||||
|
||||
if(disk.is_initialized[pdrv] == 0)
|
||||
{
|
||||
disk.is_initialized[pdrv] = 1;
|
||||
stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads Sector(s)
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @param *buff: Data buffer to store read data
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to read (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
DRESULT disk_read (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
DWORD sector, /* Sector address in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
)
|
||||
{
|
||||
DRESULT res;
|
||||
|
||||
res = disk.drv[pdrv]->disk_read(disk.lun[pdrv], buff, sector, count);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes Sector(s)
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @param *buff: Data to be written
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to write (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT disk_write (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
DWORD sector, /* Sector address in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
DRESULT res;
|
||||
|
||||
res = disk.drv[pdrv]->disk_write(disk.lun[pdrv], buff, sector, count);
|
||||
return res;
|
||||
}
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
|
||||
/**
|
||||
* @brief I/O control operation
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @param cmd: Control code
|
||||
* @param *buff: Buffer to send/receive control data
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT disk_ioctl (
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
DRESULT res;
|
||||
|
||||
res = disk.drv[pdrv]->disk_ioctl(disk.lun[pdrv], cmd, buff);
|
||||
return res;
|
||||
}
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
/**
|
||||
* @brief Gets Time from RTC
|
||||
* @param None
|
||||
* @retval Time in DWORD
|
||||
*/
|
||||
__weak DWORD get_fattime (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
Vendored
Executable
+80
@@ -0,0 +1,80 @@
|
||||
/*-----------------------------------------------------------------------/
|
||||
/ Low level disk interface modlue include file (C)ChaN, 2014 /
|
||||
/-----------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _DISKIO_DEFINED
|
||||
#define _DISKIO_DEFINED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define _USE_WRITE 1 /* 1: Enable disk_write function */
|
||||
#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
|
||||
|
||||
#include "integer.h"
|
||||
|
||||
|
||||
/* Status of Disk Functions */
|
||||
typedef BYTE DSTATUS;
|
||||
|
||||
/* Results of Disk Functions */
|
||||
typedef enum {
|
||||
RES_OK = 0, /* 0: Successful */
|
||||
RES_ERROR, /* 1: R/W Error */
|
||||
RES_WRPRT, /* 2: Write Protected */
|
||||
RES_NOTRDY, /* 3: Not Ready */
|
||||
RES_PARERR /* 4: Invalid Parameter */
|
||||
} DRESULT;
|
||||
|
||||
|
||||
/*---------------------------------------*/
|
||||
/* Prototypes for disk control functions */
|
||||
|
||||
|
||||
DSTATUS disk_initialize (BYTE pdrv);
|
||||
DSTATUS disk_status (BYTE pdrv);
|
||||
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
||||
DWORD get_fattime (void);
|
||||
|
||||
/* Disk Status Bits (DSTATUS) */
|
||||
|
||||
#define STA_NOINIT 0x01 /* Drive not initialized */
|
||||
#define STA_NODISK 0x02 /* No medium in the drive */
|
||||
#define STA_PROTECT 0x04 /* Write protected */
|
||||
|
||||
|
||||
/* Command code for disk_ioctrl fucntion */
|
||||
|
||||
/* Generic command (Used by FatFs) */
|
||||
#define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */
|
||||
#define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */
|
||||
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
|
||||
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
|
||||
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
|
||||
|
||||
/* Generic command (Not used by FatFs) */
|
||||
#define CTRL_POWER 5 /* Get/Set power status */
|
||||
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
|
||||
#define CTRL_EJECT 7 /* Eject media */
|
||||
#define CTRL_FORMAT 8 /* Create physical format on the media */
|
||||
|
||||
/* MMC/SDC specific ioctl command */
|
||||
#define MMC_GET_TYPE 10 /* Get card type */
|
||||
#define MMC_GET_CSD 11 /* Get CSD */
|
||||
#define MMC_GET_CID 12 /* Get CID */
|
||||
#define MMC_GET_OCR 13 /* Get OCR */
|
||||
#define MMC_GET_SDSTAT 14 /* Get SD status */
|
||||
|
||||
/* ATA/CF specific ioctl command */
|
||||
#define ATA_GET_REV 20 /* Get F/W revision */
|
||||
#define ATA_GET_MODEL 21 /* Get model name */
|
||||
#define ATA_GET_SN 22 /* Get serial number */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
Executable
+232
@@ -0,0 +1,232 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file sd_diskio.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.4.0
|
||||
* @date 09-September-2016
|
||||
* @brief SD Disk I/O driver
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <string.h>
|
||||
#include "ff_gen_drv.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Disk status */
|
||||
static volatile DSTATUS Stat = STA_NOINIT;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
DSTATUS SD_initialize (BYTE);
|
||||
DSTATUS SD_status (BYTE);
|
||||
DRESULT SD_read (BYTE, BYTE*, DWORD, UINT);
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT SD_write (BYTE, const BYTE*, DWORD, UINT);
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT SD_ioctl (BYTE, BYTE, void*);
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
const Diskio_drvTypeDef SD_Driver =
|
||||
{
|
||||
SD_initialize,
|
||||
SD_status,
|
||||
SD_read,
|
||||
#if _USE_WRITE == 1
|
||||
SD_write,
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
|
||||
#if _USE_IOCTL == 1
|
||||
SD_ioctl,
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Initializes a Drive
|
||||
* @param lun : not used
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS SD_initialize(BYTE lun)
|
||||
{
|
||||
Stat = STA_NOINIT;
|
||||
|
||||
/* Configure the uSD device */
|
||||
if(BSP_SD_Init() == MSD_OK)
|
||||
{
|
||||
Stat &= ~STA_NOINIT;
|
||||
}
|
||||
|
||||
return Stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets Disk Status
|
||||
* @param lun : not used
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS SD_status(BYTE lun)
|
||||
{
|
||||
Stat = STA_NOINIT;
|
||||
|
||||
if(BSP_SD_GetCardState() == MSD_OK)
|
||||
{
|
||||
Stat &= ~STA_NOINIT;
|
||||
}
|
||||
|
||||
return Stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads Sector(s)
|
||||
* @param lun : not used
|
||||
* @param *buff: Data buffer to store read data
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to read (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
|
||||
{
|
||||
DRESULT res = RES_ERROR;
|
||||
uint32_t timeout = 100000;
|
||||
|
||||
if(BSP_SD_ReadBlocks((uint32_t*)buff,
|
||||
(uint32_t) (sector),
|
||||
count, SD_DATATIMEOUT) == MSD_OK)
|
||||
{
|
||||
while(BSP_SD_GetCardState()!= MSD_OK)
|
||||
{
|
||||
if (timeout-- == 0)
|
||||
{
|
||||
return RES_ERROR;
|
||||
}
|
||||
}
|
||||
res = RES_OK;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes Sector(s)
|
||||
* @param lun : not used
|
||||
* @param *buff: Data to be written
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to write (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
|
||||
{
|
||||
DRESULT res = RES_ERROR;
|
||||
uint32_t timeout = 100000;
|
||||
|
||||
if(BSP_SD_WriteBlocks((uint32_t*)buff,
|
||||
(uint32_t)(sector),
|
||||
count, SD_DATATIMEOUT) == MSD_OK)
|
||||
{
|
||||
while(BSP_SD_GetCardState()!= MSD_OK)
|
||||
{
|
||||
if (timeout-- == 0)
|
||||
{
|
||||
return RES_ERROR;
|
||||
}
|
||||
}
|
||||
res = RES_OK;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
|
||||
/**
|
||||
* @brief I/O control operation
|
||||
* @param lun : not used
|
||||
* @param cmd: Control code
|
||||
* @param *buff: Buffer to send/receive control data
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT SD_ioctl(BYTE lun, BYTE cmd, void *buff)
|
||||
{
|
||||
DRESULT res = RES_ERROR;
|
||||
BSP_SD_CardInfo CardInfo;
|
||||
|
||||
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
/* Make sure that no pending write process */
|
||||
case CTRL_SYNC :
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* Get number of sectors on the disk (DWORD) */
|
||||
case GET_SECTOR_COUNT :
|
||||
BSP_SD_GetCardInfo(&CardInfo);
|
||||
*(DWORD*)buff = CardInfo.LogBlockNbr;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* Get R/W sector size (WORD) */
|
||||
case GET_SECTOR_SIZE :
|
||||
BSP_SD_GetCardInfo(&CardInfo);
|
||||
*(WORD*)buff = CardInfo.LogBlockSize;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* Get erase block size in unit of sector (DWORD) */
|
||||
case GET_BLOCK_SIZE :
|
||||
BSP_SD_GetCardInfo(&CardInfo);
|
||||
*(DWORD*)buff = CardInfo.LogBlockSize;
|
||||
break;
|
||||
|
||||
default:
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
Vendored
Executable
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file sd_diskio.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.4.0
|
||||
* @date 23-December-2016
|
||||
* @brief Header for sd_diskio.c module
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __SD_DISKIO_H
|
||||
#define __SD_DISKIO_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
extern Diskio_drvTypeDef SD_Driver;
|
||||
|
||||
#endif /* __SD_DISKIO_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
Vendored
Executable
+209
@@ -0,0 +1,209 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file sdram_diskio.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.4.0
|
||||
* @date 23-December-2016
|
||||
* @brief SDRAM Disk I/O driver
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <string.h>
|
||||
#include "ff_gen_drv.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Block Size in Bytes */
|
||||
#define BLOCK_SIZE 512
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Disk status */
|
||||
static volatile DSTATUS Stat = STA_NOINIT;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
DSTATUS SDRAMDISK_initialize (BYTE);
|
||||
DSTATUS SDRAMDISK_status (BYTE);
|
||||
DRESULT SDRAMDISK_read (BYTE, BYTE*, DWORD, UINT);
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT SDRAMDISK_write (BYTE, const BYTE*, DWORD, UINT);
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT SDRAMDISK_ioctl (BYTE, BYTE, void*);
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
const Diskio_drvTypeDef SDRAMDISK_Driver =
|
||||
{
|
||||
SDRAMDISK_initialize,
|
||||
SDRAMDISK_status,
|
||||
SDRAMDISK_read,
|
||||
#if _USE_WRITE
|
||||
SDRAMDISK_write,
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
#if _USE_IOCTL == 1
|
||||
SDRAMDISK_ioctl,
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Initializes a Drive
|
||||
* @param lun : not used
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS SDRAMDISK_initialize(BYTE lun)
|
||||
{
|
||||
Stat = STA_NOINIT;
|
||||
|
||||
/* Configure the SDRAM device */
|
||||
BSP_SDRAM_Init();
|
||||
|
||||
Stat &= ~STA_NOINIT;
|
||||
return Stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets Disk Status
|
||||
* @param lun : not used
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS SDRAMDISK_status(BYTE lun)
|
||||
{
|
||||
Stat = STA_NOINIT;
|
||||
|
||||
Stat &= ~STA_NOINIT;
|
||||
|
||||
return Stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads Sector(s)
|
||||
* @param lun : not used
|
||||
* @param *buff: Data buffer to store read data
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to read (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
DRESULT SDRAMDISK_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
|
||||
{
|
||||
uint32_t *pSrcBuffer = (uint32_t *)buff;
|
||||
uint32_t BufferSize = (BLOCK_SIZE * count)/4;
|
||||
uint32_t *pSdramAddress = (uint32_t *) (SDRAM_DEVICE_ADDR + (sector * BLOCK_SIZE));
|
||||
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*pSrcBuffer++ = *(__IO uint32_t *)pSdramAddress++;
|
||||
}
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes Sector(s)
|
||||
* @param lun : not used
|
||||
* @param *buff: Data to be written
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to write (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT SDRAMDISK_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
|
||||
{
|
||||
uint32_t *pDstBuffer = (uint32_t *)buff;
|
||||
uint32_t BufferSize = (BLOCK_SIZE * count)/4 + count;
|
||||
uint32_t *pSramAddress = (uint32_t *) (SDRAM_DEVICE_ADDR + (sector * BLOCK_SIZE));
|
||||
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*(__IO uint32_t *)pSramAddress++ = *pDstBuffer++;
|
||||
}
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
|
||||
/**
|
||||
* @brief I/O control operation
|
||||
* @param lun : not used
|
||||
* @param cmd: Control code
|
||||
* @param *buff: Buffer to send/receive control data
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT SDRAMDISK_ioctl(BYTE lun, BYTE cmd, void *buff)
|
||||
{
|
||||
DRESULT res = RES_ERROR;
|
||||
|
||||
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
/* Make sure that no pending write process */
|
||||
case CTRL_SYNC :
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* Get number of sectors on the disk (DWORD) */
|
||||
case GET_SECTOR_COUNT :
|
||||
*(DWORD*)buff = SDRAM_DEVICE_SIZE / BLOCK_SIZE;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* Get R/W sector size (WORD) */
|
||||
case GET_SECTOR_SIZE :
|
||||
*(WORD*)buff = BLOCK_SIZE;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* Get erase block size in unit of sector (DWORD) */
|
||||
case GET_BLOCK_SIZE :
|
||||
*(DWORD*)buff = BLOCK_SIZE;
|
||||
break;
|
||||
|
||||
default:
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
Vendored
Executable
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file sdram_diskio.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.4.0
|
||||
* @date 23-December-2016
|
||||
* @brief Header for sdram_diskio.c module
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __SDRAM_DISKIO_H
|
||||
#define __SDRAM_DISKIO_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
extern Diskio_drvTypeDef SDRAMDISK_Driver;
|
||||
|
||||
#endif /* __SDRAM_DISKIO_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
UHSDR-active-devel/mchf-eclipse/basesw/ovi40/Middlewares/Third_Party/FatFs/src/drivers/sram_diskio.c
Vendored
Executable
+207
@@ -0,0 +1,207 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file sram_diskio.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.4.0
|
||||
* @date 23-December-2016
|
||||
* @brief SRAM Disk I/O driver
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <string.h>
|
||||
#include "ff_gen_drv.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Block Size in Bytes */
|
||||
#define BLOCK_SIZE 512
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Disk status */
|
||||
static volatile DSTATUS Stat = STA_NOINIT;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
DSTATUS SRAMDISK_initialize (BYTE);
|
||||
DSTATUS SRAMDISK_status (BYTE);
|
||||
DRESULT SRAMDISK_read (BYTE, BYTE*, DWORD, UINT);
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT SRAMDISK_write (BYTE, const BYTE*, DWORD, UINT);
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT SRAMDISK_ioctl (BYTE, BYTE, void*);
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
const Diskio_drvTypeDef SRAMDISK_Driver =
|
||||
{
|
||||
SRAMDISK_initialize,
|
||||
SRAMDISK_status,
|
||||
SRAMDISK_read,
|
||||
#if _USE_WRITE == 1
|
||||
SRAMDISK_write,
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
#if _USE_IOCTL == 1
|
||||
SRAMDISK_ioctl,
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Initializes a Drive
|
||||
* @param lun : not used
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS SRAMDISK_initialize(BYTE lun)
|
||||
{
|
||||
Stat = STA_NOINIT;
|
||||
|
||||
/* Configure the SRAM device */
|
||||
BSP_SRAM_Init();
|
||||
|
||||
Stat &= ~STA_NOINIT;
|
||||
return Stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets Disk Status
|
||||
* @param lun : not used
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS SRAMDISK_status(BYTE lun)
|
||||
{
|
||||
Stat = STA_NOINIT;
|
||||
|
||||
Stat &= ~STA_NOINIT;
|
||||
|
||||
return Stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads Sector(s)
|
||||
* @param lun : not used
|
||||
* @param *buff: Data buffer to store read data
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to read (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
DRESULT SRAMDISK_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
|
||||
{
|
||||
uint32_t BufferSize = (BLOCK_SIZE * count);
|
||||
uint8_t *pSramAddress = (uint8_t *) (SRAM_DEVICE_ADDR + (sector * BLOCK_SIZE));
|
||||
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*buff++ = *(__IO uint8_t *)pSramAddress++;
|
||||
}
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes Sector(s)
|
||||
* @param lun : not used
|
||||
* @param *buff: Data to be written
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to write (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT SRAMDISK_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
|
||||
{
|
||||
uint32_t BufferSize = (BLOCK_SIZE * count) + count;
|
||||
uint8_t *pSramAddress = (uint8_t *) (SRAM_DEVICE_ADDR + (sector * BLOCK_SIZE));
|
||||
|
||||
for(; BufferSize != 0; BufferSize--)
|
||||
{
|
||||
*(__IO uint8_t *)pSramAddress++ = *buff++;
|
||||
}
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
|
||||
/**
|
||||
* @brief I/O control operation
|
||||
* @param lun : not used
|
||||
* @param cmd: Control code
|
||||
* @param *buff: Buffer to send/receive control data
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT SRAMDISK_ioctl(BYTE lun, BYTE cmd, void *buff)
|
||||
{
|
||||
DRESULT res = RES_ERROR;
|
||||
|
||||
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
/* Make sure that no pending write process */
|
||||
case CTRL_SYNC :
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* Get number of sectors on the disk (DWORD) */
|
||||
case GET_SECTOR_COUNT :
|
||||
*(DWORD*)buff = SRAM_DEVICE_SIZE / BLOCK_SIZE;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* Get R/W sector size (WORD) */
|
||||
case GET_SECTOR_SIZE :
|
||||
*(WORD*)buff = BLOCK_SIZE;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* Get erase block size in unit of sector (DWORD) */
|
||||
case GET_BLOCK_SIZE :
|
||||
*(DWORD*)buff = BLOCK_SIZE;
|
||||
break;
|
||||
|
||||
default:
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
UHSDR-active-devel/mchf-eclipse/basesw/ovi40/Middlewares/Third_Party/FatFs/src/drivers/sram_diskio.h
Vendored
Executable
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file sram_diskio.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.4.0
|
||||
* @date 23-December-2016
|
||||
* @brief Header for sram_diskio.c module
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __SRAM_DISKIO_H
|
||||
#define __SRAM_DISKIO_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
extern Diskio_drvTypeDef SRAMDISK_Driver;
|
||||
|
||||
#endif /* __SRAM_DISKIO_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
UHSDR-active-devel/mchf-eclipse/basesw/ovi40/Middlewares/Third_Party/FatFs/src/drivers/usbh_diskio.c
Vendored
Executable
+321
@@ -0,0 +1,321 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_diskio.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.4.0
|
||||
* @date 23-December-2016
|
||||
* @brief USB Key Disk I/O driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <string.h>
|
||||
#include "ff_gen_drv.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
extern USBH_HandleTypeDef HOST_HANDLE;
|
||||
#if _USE_BUFF_WO_ALIGNMENT == 0
|
||||
/* Local buffer use to handle buffer not aligned 32bits*/
|
||||
static DWORD scratch[_MAX_SS / 4];
|
||||
#endif
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
DSTATUS USBH_initialize (BYTE);
|
||||
DSTATUS USBH_status (BYTE);
|
||||
DRESULT USBH_read (BYTE, BYTE*, DWORD, UINT);
|
||||
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT USBH_write (BYTE, const BYTE*, DWORD, UINT);
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT USBH_ioctl (BYTE, BYTE, void*);
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
const Diskio_drvTypeDef USBH_Driver =
|
||||
{
|
||||
USBH_initialize,
|
||||
USBH_status,
|
||||
USBH_read,
|
||||
#if _USE_WRITE == 1
|
||||
USBH_write,
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
#if _USE_IOCTL == 1
|
||||
USBH_ioctl,
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Initializes a Drive
|
||||
* @param lun : lun id
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS USBH_initialize(BYTE lun)
|
||||
{
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets Disk Status
|
||||
* @param lun : lun id
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS USBH_status(BYTE lun)
|
||||
{
|
||||
DRESULT res = RES_ERROR;
|
||||
|
||||
if(USBH_MSC_UnitIsReady(&HOST_HANDLE, lun))
|
||||
{
|
||||
res = RES_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = RES_ERROR;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads Sector(s)
|
||||
* @param lun : lun id
|
||||
* @param *buff: Data buffer to store read data
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to read (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
DRESULT USBH_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
|
||||
{
|
||||
DRESULT res = RES_ERROR;
|
||||
MSC_LUNTypeDef info;
|
||||
USBH_StatusTypeDef status = USBH_OK;
|
||||
|
||||
if ((DWORD)buff & 3) /* DMA Alignment issue, do single up to aligned buffer */
|
||||
{
|
||||
#if _USE_BUFF_WO_ALIGNMENT == 0
|
||||
while ((count--)&&(status == USBH_OK))
|
||||
{
|
||||
status = USBH_MSC_Read(&HOST_HANDLE, lun, sector + count, (uint8_t *)scratch, 1);
|
||||
if(status == USBH_OK)
|
||||
{
|
||||
memcpy (&buff[count * _MAX_SS] ,scratch, _MAX_SS);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
status = USBH_MSC_Read(&HOST_HANDLE, lun, sector, buff, count);
|
||||
}
|
||||
|
||||
if(status == USBH_OK)
|
||||
{
|
||||
res = RES_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
USBH_MSC_GetLUNInfo(&HOST_HANDLE, lun, &info);
|
||||
|
||||
switch (info.sense.asc)
|
||||
{
|
||||
case SCSI_ASC_LOGICAL_UNIT_NOT_READY:
|
||||
case SCSI_ASC_MEDIUM_NOT_PRESENT:
|
||||
case SCSI_ASC_NOT_READY_TO_READY_CHANGE:
|
||||
USBH_ErrLog ("USB Disk is not ready!");
|
||||
res = RES_NOTRDY;
|
||||
break;
|
||||
|
||||
default:
|
||||
res = RES_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes Sector(s)
|
||||
* @param lun : lun id
|
||||
* @param *buff: Data to be written
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to write (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT USBH_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
|
||||
{
|
||||
DRESULT res = RES_ERROR;
|
||||
MSC_LUNTypeDef info;
|
||||
USBH_StatusTypeDef status = USBH_OK;
|
||||
|
||||
if ((DWORD)buff & 3) /* DMA Alignment issue, do single up to aligned buffer */
|
||||
{
|
||||
#if _USE_BUFF_WO_ALIGNMENT == 0
|
||||
while (count--)
|
||||
{
|
||||
memcpy (scratch, &buff[count * _MAX_SS], _MAX_SS);
|
||||
|
||||
status = USBH_MSC_Write(&HOST_HANDLE, lun, sector + count, (BYTE *)scratch, 1) ;
|
||||
if(status == USBH_FAIL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
status = USBH_MSC_Write(&HOST_HANDLE, lun, sector, (BYTE *)buff, count);
|
||||
}
|
||||
|
||||
if(status == USBH_OK)
|
||||
{
|
||||
res = RES_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
USBH_MSC_GetLUNInfo(&HOST_HANDLE, lun, &info);
|
||||
|
||||
switch (info.sense.asc)
|
||||
{
|
||||
case SCSI_ASC_WRITE_PROTECTED:
|
||||
USBH_ErrLog("USB Disk is Write protected!");
|
||||
res = RES_WRPRT;
|
||||
break;
|
||||
|
||||
case SCSI_ASC_LOGICAL_UNIT_NOT_READY:
|
||||
case SCSI_ASC_MEDIUM_NOT_PRESENT:
|
||||
case SCSI_ASC_NOT_READY_TO_READY_CHANGE:
|
||||
USBH_ErrLog("USB Disk is not ready!");
|
||||
res = RES_NOTRDY;
|
||||
break;
|
||||
|
||||
default:
|
||||
res = RES_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
|
||||
/**
|
||||
* @brief I/O control operation
|
||||
* @param lun : lun id
|
||||
* @param cmd: Control code
|
||||
* @param *buff: Buffer to send/receive control data
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT USBH_ioctl(BYTE lun, BYTE cmd, void *buff)
|
||||
{
|
||||
DRESULT res = RES_ERROR;
|
||||
MSC_LUNTypeDef info;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
/* Make sure that no pending write process */
|
||||
case CTRL_SYNC:
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
/* Get number of sectors on the disk (DWORD) */
|
||||
case GET_SECTOR_COUNT :
|
||||
if(USBH_MSC_GetLUNInfo(&HOST_HANDLE, lun, &info) == USBH_OK)
|
||||
{
|
||||
*(DWORD*)buff = info.capacity.block_nbr;
|
||||
res = RES_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = RES_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Get R/W sector size (WORD) */
|
||||
case GET_SECTOR_SIZE :
|
||||
if(USBH_MSC_GetLUNInfo(&HOST_HANDLE, lun, &info) == USBH_OK)
|
||||
{
|
||||
*(DWORD*)buff = info.capacity.block_size;
|
||||
res = RES_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = RES_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Get erase block size in unit of sector (DWORD) */
|
||||
case GET_BLOCK_SIZE :
|
||||
|
||||
if(USBH_MSC_GetLUNInfo(&HOST_HANDLE, lun, &info) == USBH_OK)
|
||||
{
|
||||
*(DWORD*)buff = info.capacity.block_size;
|
||||
res = RES_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = RES_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
UHSDR-active-devel/mchf-eclipse/basesw/ovi40/Middlewares/Third_Party/FatFs/src/drivers/usbh_diskio.h
Vendored
Executable
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_diskio.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.4.0
|
||||
* @date 23-December-2016
|
||||
* @brief Header for usbh_diskio.c module
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBH_DISKIO_H
|
||||
#define __USBH_DISKIO_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
extern Diskio_drvTypeDef USBH_Driver;
|
||||
|
||||
#endif /* __USBH_DISKIO_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
Vendored
Executable
+4752
File diff suppressed because it is too large
Load Diff
Vendored
Executable
+364
@@ -0,0 +1,364 @@
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ FatFs - FAT file system module include R0.11 (C)ChaN, 2015
|
||||
/----------------------------------------------------------------------------/
|
||||
/ FatFs module is a free software that opened under license policy of
|
||||
/ following conditions.
|
||||
/
|
||||
/ Copyright (C) 2015, ChaN, all right reserved.
|
||||
/
|
||||
/ 1. Redistributions of source code must retain the above copyright notice,
|
||||
/ this condition and the following disclaimer.
|
||||
/
|
||||
/ This software is provided by the copyright holder and contributors "AS IS"
|
||||
/ and any warranties related to this software are DISCLAIMED.
|
||||
/ The copyright owner or contributors be NOT LIABLE for any damages caused
|
||||
/ by use of this software.
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef _FATFS
|
||||
#define _FATFS 32020 /* Revision ID */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "integer.h" /* Basic integer types */
|
||||
#include "ffconf.h" /* FatFs configuration options */
|
||||
#if _FATFS != _FFCONF
|
||||
#error Wrong configuration file (ffconf.h).
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Definitions of volume management */
|
||||
|
||||
#if _MULTI_PARTITION /* Multiple partition configuration */
|
||||
typedef struct {
|
||||
BYTE pd; /* Physical drive number */
|
||||
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
||||
} PARTITION;
|
||||
extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
|
||||
#define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */
|
||||
#define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */
|
||||
|
||||
#else /* Single partition configuration */
|
||||
#define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */
|
||||
#define LD2PT(vol) 0 /* Find first valid partition or in SFD */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Type of path name strings on FatFs API */
|
||||
|
||||
#if _LFN_UNICODE /* Unicode string */
|
||||
#if !_USE_LFN
|
||||
#error _LFN_UNICODE must be 0 at non-LFN cfg.
|
||||
#endif
|
||||
#ifndef _INC_TCHAR
|
||||
typedef WCHAR TCHAR;
|
||||
#define _T(x) L ## x
|
||||
#define _TEXT(x) L ## x
|
||||
#endif
|
||||
|
||||
#else /* ANSI/OEM string */
|
||||
#ifndef _INC_TCHAR
|
||||
typedef char TCHAR;
|
||||
#define _T(x) x
|
||||
#define _TEXT(x) x
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* File system object structure (FATFS) */
|
||||
|
||||
typedef struct {
|
||||
union{
|
||||
UINT d32[_MAX_SS/4]; /* Force 32bits alignement */
|
||||
BYTE d8[_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
|
||||
}win;
|
||||
BYTE fs_type; /* FAT sub-type (0:Not mounted) */
|
||||
BYTE drv; /* Physical drive number */
|
||||
BYTE csize; /* Sectors per cluster (1,2,4...128) */
|
||||
BYTE n_fats; /* Number of FAT copies (1 or 2) */
|
||||
BYTE wflag; /* win[] flag (b0:dirty) */
|
||||
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
|
||||
WORD id; /* File system mount ID */
|
||||
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
|
||||
#if _MAX_SS != _MIN_SS
|
||||
WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */
|
||||
#endif
|
||||
#if _FS_REENTRANT
|
||||
_SYNC_t sobj; /* Identifier of sync object */
|
||||
#endif
|
||||
#if !_FS_READONLY
|
||||
DWORD last_clust; /* Last allocated cluster */
|
||||
DWORD free_clust; /* Number of free clusters */
|
||||
#endif
|
||||
#if _FS_RPATH
|
||||
DWORD cdir; /* Current directory start cluster (0:root) */
|
||||
#endif
|
||||
DWORD n_fatent; /* Number of FAT entries, = number of clusters + 2 */
|
||||
DWORD fsize; /* Sectors per FAT */
|
||||
DWORD volbase; /* Volume start sector */
|
||||
DWORD fatbase; /* FAT start sector */
|
||||
DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */
|
||||
DWORD database; /* Data start sector */
|
||||
DWORD winsect; /* Current sector appearing in the win[] */
|
||||
|
||||
} FATFS;
|
||||
|
||||
|
||||
|
||||
/* File object structure (FIL) */
|
||||
|
||||
typedef struct {
|
||||
#if !_FS_TINY
|
||||
union{
|
||||
UINT d32[_MAX_SS/4]; /* Force 32bits alignement */
|
||||
BYTE d8[_MAX_SS]; /* File data read/write buffer */
|
||||
}buf;
|
||||
#endif
|
||||
FATFS* fs; /* Pointer to the related file system object (**do not change order**) */
|
||||
WORD id; /* Owner file system mount ID (**do not change order**) */
|
||||
BYTE flag; /* Status flags */
|
||||
BYTE err; /* Abort flag (error code) */
|
||||
DWORD fptr; /* File read/write pointer (Zeroed on file open) */
|
||||
DWORD fsize; /* File size */
|
||||
DWORD sclust; /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */
|
||||
DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */
|
||||
DWORD dsect; /* Sector number appearing in buf[] (0:invalid) */
|
||||
#if !_FS_READONLY
|
||||
DWORD dir_sect; /* Sector number containing the directory entry */
|
||||
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */
|
||||
#endif
|
||||
#if _USE_FASTSEEK
|
||||
DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */
|
||||
#endif
|
||||
#if _FS_LOCK
|
||||
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
|
||||
#endif
|
||||
|
||||
} FIL;
|
||||
|
||||
|
||||
|
||||
/* Directory object structure (DIR) */
|
||||
|
||||
typedef struct {
|
||||
#if !_FS_TINY
|
||||
union{
|
||||
UINT d32[_MAX_SS/4]; /* Force 32bits alignement */
|
||||
BYTE d8[_MAX_SS]; /* File data read/write buffer */
|
||||
}buf;
|
||||
#endif
|
||||
FATFS* fs; /* Pointer to the owner file system object (**do not change order**) */
|
||||
WORD id; /* Owner file system mount ID (**do not change order**) */
|
||||
WORD index; /* Current read/write index number */
|
||||
DWORD sclust; /* Table start cluster (0:Root dir) */
|
||||
DWORD clust; /* Current cluster */
|
||||
DWORD sect; /* Current sector */
|
||||
BYTE* dir; /* Pointer to the current SFN entry in the win[] */
|
||||
BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
|
||||
#if _FS_LOCK
|
||||
UINT lockid; /* File lock ID (index of file semaphore table Files[]) */
|
||||
#endif
|
||||
#if _USE_LFN
|
||||
WCHAR* lfn; /* Pointer to the LFN working buffer */
|
||||
WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
|
||||
#endif
|
||||
#if _USE_FIND
|
||||
const TCHAR* pat; /* Pointer to the name matching pattern */
|
||||
#endif
|
||||
} DIR;
|
||||
|
||||
|
||||
|
||||
/* File information structure (FILINFO) */
|
||||
|
||||
typedef struct {
|
||||
DWORD fsize; /* File size */
|
||||
WORD fdate; /* Last modified date */
|
||||
WORD ftime; /* Last modified time */
|
||||
BYTE fattrib; /* Attribute */
|
||||
TCHAR fname[13]; /* Short file name (8.3 format) */
|
||||
#if _USE_LFN
|
||||
TCHAR* lfname; /* Pointer to the LFN buffer */
|
||||
UINT lfsize; /* Size of LFN buffer in TCHAR */
|
||||
#endif
|
||||
} FILINFO;
|
||||
|
||||
|
||||
|
||||
/* File function return code (FRESULT) */
|
||||
|
||||
typedef enum {
|
||||
FR_OK = 0, /* (0) Succeeded */
|
||||
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
|
||||
FR_INT_ERR, /* (2) Assertion failed */
|
||||
FR_NOT_READY, /* (3) The physical drive cannot work */
|
||||
FR_NO_FILE, /* (4) Could not find the file */
|
||||
FR_NO_PATH, /* (5) Could not find the path */
|
||||
FR_INVALID_NAME, /* (6) The path name format is invalid */
|
||||
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
|
||||
FR_EXIST, /* (8) Access denied due to prohibited access */
|
||||
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
|
||||
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
|
||||
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
|
||||
FR_NOT_ENABLED, /* (12) The volume has no work area */
|
||||
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
|
||||
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */
|
||||
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
|
||||
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
||||
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
|
||||
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */
|
||||
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
||||
} FRESULT;
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* FatFs module application interface */
|
||||
|
||||
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
|
||||
FRESULT f_close (FIL* fp); /* Close an open file object */
|
||||
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */
|
||||
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */
|
||||
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
|
||||
FRESULT f_lseek (FIL* fp, DWORD ofs); /* Move file pointer of a file object */
|
||||
FRESULT f_truncate (FIL* fp); /* Truncate file */
|
||||
FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */
|
||||
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
|
||||
FRESULT f_closedir (DIR* dp); /* Close an open directory */
|
||||
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
|
||||
FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
|
||||
FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */
|
||||
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
|
||||
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
|
||||
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
|
||||
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
|
||||
FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of the file/dir */
|
||||
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change times-tamp of the file/dir */
|
||||
FRESULT f_chdir (const TCHAR* path); /* Change current directory */
|
||||
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
|
||||
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
|
||||
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
|
||||
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
|
||||
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
|
||||
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
|
||||
FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */
|
||||
FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */
|
||||
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
|
||||
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
|
||||
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
|
||||
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
|
||||
|
||||
#define f_eof(fp) ((int)((fp)->fptr == (fp)->fsize))
|
||||
#define f_error(fp) ((fp)->err)
|
||||
#define f_tell(fp) ((fp)->fptr)
|
||||
#define f_size(fp) ((fp)->fsize)
|
||||
#define f_rewind(fp) f_lseek((fp), 0)
|
||||
#define f_rewinddir(dp) f_readdir((dp), 0)
|
||||
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Additional user defined functions */
|
||||
|
||||
/* RTC function */
|
||||
#if !_FS_READONLY && !_FS_NORTC
|
||||
DWORD get_fattime (void);
|
||||
#endif
|
||||
|
||||
/* Unicode support functions */
|
||||
#if _USE_LFN /* Unicode - OEM code conversion */
|
||||
WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */
|
||||
WCHAR ff_wtoupper (WCHAR chr); /* Unicode upper-case conversion */
|
||||
#if _USE_LFN == 3 /* Memory functions */
|
||||
void* ff_memalloc (UINT msize); /* Allocate memory block */
|
||||
void ff_memfree (void* mblock); /* Free memory block */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Sync functions */
|
||||
#if _FS_REENTRANT
|
||||
int ff_cre_syncobj (BYTE vol, _SYNC_t* sobj); /* Create a sync object */
|
||||
int ff_req_grant (_SYNC_t sobj); /* Lock sync object */
|
||||
void ff_rel_grant (_SYNC_t sobj); /* Unlock sync object */
|
||||
int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Flags and offset address */
|
||||
|
||||
|
||||
/* File access control and file status flags (FIL.flag) */
|
||||
|
||||
#define FA_READ 0x01
|
||||
#define FA_OPEN_EXISTING 0x00
|
||||
|
||||
#if !_FS_READONLY
|
||||
#define FA_WRITE 0x02
|
||||
#define FA_CREATE_NEW 0x04
|
||||
#define FA_CREATE_ALWAYS 0x08
|
||||
#define FA_OPEN_ALWAYS 0x10
|
||||
#define FA__WRITTEN 0x20
|
||||
#define FA__DIRTY 0x40
|
||||
#endif
|
||||
|
||||
|
||||
/* FAT sub type (FATFS.fs_type) */
|
||||
|
||||
#define FS_FAT12 1
|
||||
#define FS_FAT16 2
|
||||
#define FS_FAT32 3
|
||||
|
||||
|
||||
/* File attribute bits for directory entry */
|
||||
|
||||
#define AM_RDO 0x01 /* Read only */
|
||||
#define AM_HID 0x02 /* Hidden */
|
||||
#define AM_SYS 0x04 /* System */
|
||||
#define AM_VOL 0x08 /* Volume label */
|
||||
#define AM_LFN 0x0F /* LFN entry */
|
||||
#define AM_DIR 0x10 /* Directory */
|
||||
#define AM_ARC 0x20 /* Archive */
|
||||
#define AM_MASK 0x3F /* Mask of defined bits */
|
||||
|
||||
|
||||
/* Fast seek feature */
|
||||
#define CREATE_LINKMAP 0xFFFFFFFF
|
||||
|
||||
|
||||
|
||||
/*--------------------------------*/
|
||||
/* Multi-byte word access macros */
|
||||
|
||||
#if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
|
||||
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
|
||||
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
|
||||
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
|
||||
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
|
||||
#else /* Use byte-by-byte access to the FAT structure */
|
||||
#define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
|
||||
#define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
|
||||
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
|
||||
#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _FATFS */
|
||||
Vendored
Executable
+151
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file ff_gen_drv.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.4.0
|
||||
* @date 23-December-2016
|
||||
* @brief FatFs generic low level driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "ff_gen_drv.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
Disk_drvTypeDef disk = {{0},{0},{0},0};
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Links a compatible diskio driver/lun id and increments the number of active
|
||||
* linked drivers.
|
||||
* @note The number of linked drivers (volumes) is up to 10 due to FatFs limits.
|
||||
* @param drv: pointer to the disk IO Driver structure
|
||||
* @param path: pointer to the logical drive path
|
||||
* @param lun : only used for USB Key Disk to add multi-lun management
|
||||
else the paramter must be equal to 0
|
||||
* @retval Returns 0 in case of success, otherwise 1.
|
||||
*/
|
||||
uint8_t FATFS_LinkDriverEx(Diskio_drvTypeDef *drv, char *path, uint8_t lun)
|
||||
{
|
||||
uint8_t ret = 1;
|
||||
uint8_t DiskNum = 0;
|
||||
|
||||
if(disk.nbr <= _VOLUMES)
|
||||
{
|
||||
disk.is_initialized[disk.nbr] = 0;
|
||||
disk.drv[disk.nbr] = drv;
|
||||
disk.lun[disk.nbr] = lun;
|
||||
DiskNum = disk.nbr++;
|
||||
path[0] = DiskNum + '0';
|
||||
path[1] = ':';
|
||||
path[2] = '/';
|
||||
path[3] = 0;
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Links a compatible diskio driver and increments the number of active
|
||||
* linked drivers.
|
||||
* @note The number of linked drivers (volumes) is up to 10 due to FatFs limits
|
||||
* @param drv: pointer to the disk IO Driver structure
|
||||
* @param path: pointer to the logical drive path
|
||||
* @retval Returns 0 in case of success, otherwise 1.
|
||||
*/
|
||||
uint8_t FATFS_LinkDriver(Diskio_drvTypeDef *drv, char *path)
|
||||
{
|
||||
return FATFS_LinkDriverEx(drv, path, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unlinks a diskio driver and decrements the number of active linked
|
||||
* drivers.
|
||||
* @param path: pointer to the logical drive path
|
||||
* @param lun : not used
|
||||
* @retval Returns 0 in case of success, otherwise 1.
|
||||
*/
|
||||
uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun)
|
||||
{
|
||||
uint8_t DiskNum = 0;
|
||||
uint8_t ret = 1;
|
||||
|
||||
if(disk.nbr >= 1)
|
||||
{
|
||||
DiskNum = path[0] - '0';
|
||||
if(disk.drv[DiskNum] != 0)
|
||||
{
|
||||
disk.drv[DiskNum] = 0;
|
||||
disk.lun[DiskNum] = 0;
|
||||
disk.nbr--;
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unlinks a diskio driver and decrements the number of active linked
|
||||
* drivers.
|
||||
* @param path: pointer to the logical drive path
|
||||
* @retval Returns 0 in case of success, otherwise 1.
|
||||
*/
|
||||
uint8_t FATFS_UnLinkDriver(char *path)
|
||||
{
|
||||
return FATFS_UnLinkDriverEx(path, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets number of linked drivers to the FatFs module.
|
||||
* @param None
|
||||
* @retval Number of attached drivers.
|
||||
*/
|
||||
uint8_t FATFS_GetAttachedDriversNbr(void)
|
||||
{
|
||||
return disk.nbr;
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
Vendored
Executable
+107
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file ff_gen_drv.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.4.0
|
||||
* @date 23-December-2016
|
||||
* @brief Header for ff_gen_drv.c module.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __FF_GEN_DRV_H
|
||||
#define __FF_GEN_DRV_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "diskio.h"
|
||||
#include "ff.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Disk IO Driver structure definition
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
DSTATUS (*disk_initialize) (BYTE); /*!< Initialize Disk Drive */
|
||||
DSTATUS (*disk_status) (BYTE); /*!< Get Disk Status */
|
||||
DRESULT (*disk_read) (BYTE, BYTE*, DWORD, UINT); /*!< Read Sector(s) */
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT (*disk_write) (BYTE, const BYTE*, DWORD, UINT); /*!< Write Sector(s) when _USE_WRITE = 0 */
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT (*disk_ioctl) (BYTE, BYTE, void*); /*!< I/O control operation when _USE_IOCTL = 1 */
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
}Diskio_drvTypeDef;
|
||||
|
||||
/**
|
||||
* @brief Global Disk IO Drivers structure definition
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t is_initialized[_VOLUMES];
|
||||
Diskio_drvTypeDef *drv[_VOLUMES];
|
||||
uint8_t lun[_VOLUMES];
|
||||
__IO uint8_t nbr;
|
||||
|
||||
}Disk_drvTypeDef;
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
uint8_t FATFS_LinkDriverEx(Diskio_drvTypeDef *drv, char *path, uint8_t lun);
|
||||
uint8_t FATFS_LinkDriver(Diskio_drvTypeDef *drv, char *path);
|
||||
uint8_t FATFS_UnLinkDriver(char *path);
|
||||
uint8_t FATFS_LinkDriverEx(Diskio_drvTypeDef *drv, char *path, BYTE lun);
|
||||
uint8_t FATFS_UnLinkDriverEx(char *path, BYTE lun);
|
||||
uint8_t FATFS_GetAttachedDriversNbr(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __FF_GEN_DRV_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
Vendored
Executable
+303
@@ -0,0 +1,303 @@
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ FatFs - FAT file system module configuration file R0.11 (C)ChaN, 2015
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _FFCONF
|
||||
#define _FFCONF 32020 /* Revision ID */
|
||||
|
||||
/*-----------------------------------------------------------------------------/
|
||||
/ Additional user header to be used
|
||||
/-----------------------------------------------------------------------------*/
|
||||
/* Replace 'stm32xxx' with the STM32 Serie used, ex: stm32f4xx_hal.h */
|
||||
#include "stm32xxx_hal.h"
|
||||
|
||||
/* If uSD is used, then include the uSD BSP header file.
|
||||
Replace 'stm32xxx' with your EVAL board name, ex: stm324x9i_eval_sd.h
|
||||
*/
|
||||
#include "stm32xxx_eval_sd.h"
|
||||
|
||||
/* If USB Host MSC is used, then need to include the USBH and UBSH MSC core header files */
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_msc.h"
|
||||
/* hUSBH to be updated with the USBH handle defined in the application code */
|
||||
#define HOST_HANDLE hUSBH
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Functions and Buffer Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define _FS_TINY 0 /* 0:Normal or 1:Tiny */
|
||||
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
|
||||
/ At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS
|
||||
/ bytes. Instead of private sector buffer eliminated from the file object,
|
||||
/ common sector buffer in the file system object (FATFS) is used for the file
|
||||
/ data transfer. */
|
||||
|
||||
|
||||
#define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */
|
||||
/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
|
||||
/ Read-only configuration removes writing API functions, f_write(), f_sync(),
|
||||
/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
|
||||
/ and optional writing functions as well. */
|
||||
|
||||
|
||||
#define _FS_MINIMIZE 0 /* 0 to 3 */
|
||||
/* This option defines minimization level to remove some basic API functions.
|
||||
/
|
||||
/ 0: All basic functions are enabled.
|
||||
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_chmod(), f_utime(),
|
||||
/ f_truncate() and f_rename() function are removed.
|
||||
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
|
||||
/ 3: f_lseek() function is removed in addition to 2. */
|
||||
|
||||
|
||||
#define _USE_STRFUNC 2 /* 0:Disable or 1-2:Enable */
|
||||
/* This option switches string functions, f_gets(), f_putc(), f_puts() and
|
||||
/ f_printf().
|
||||
/
|
||||
/ 0: Disable string functions.
|
||||
/ 1: Enable without LF-CRLF conversion.
|
||||
/ 2: Enable with LF-CRLF conversion. */
|
||||
|
||||
|
||||
#define _USE_FIND 0
|
||||
/* This option switches filtered directory read feature and related functions,
|
||||
/ f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define _USE_MKFS 1
|
||||
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define _USE_FASTSEEK 1
|
||||
/* This option switches fast seek feature. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define _USE_LABEL 0
|
||||
/* This option switches volume label functions, f_getlabel() and f_setlabel().
|
||||
/ (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define _USE_FORWARD 0
|
||||
/* This option switches f_forward() function. (0:Disable or 1:Enable)
|
||||
/ To enable it, also _FS_TINY need to be set to 1. */
|
||||
|
||||
#define _USE_BUFF_WO_ALIGNMENT 0
|
||||
/* This option is available only for usbh diskio interface and allow to disable
|
||||
/ the management of the unaligned buffer.
|
||||
/ When STM32 USB OTG HS or FS IP is used with internal DMA enabled, this define
|
||||
/ must be set to 0 to align data into 32bits through an internal scratch buffer
|
||||
/ before being processed by the DMA . Otherwise (DMA not used), this define must
|
||||
/ be set to 1 to avoid Data alignment and improve the performance.
|
||||
/ Please note that if _USE_BUFF_WO_ALIGNMENT is set to 1 and an unaligned 32bits
|
||||
/ buffer is forwarded to the FatFs Write/Read functions, an error will be returned.
|
||||
/ (0: default value or 1: unaligned buffer return an error). */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Locale and Namespace Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define _CODE_PAGE 1252
|
||||
/* This option specifies the OEM code page to be used on the target system.
|
||||
/ Incorrect setting of the code page can cause a file open failure.
|
||||
/
|
||||
/ 932 - Japanese Shift_JIS (DBCS, OEM, Windows)
|
||||
/ 936 - Simplified Chinese GBK (DBCS, OEM, Windows)
|
||||
/ 949 - Korean (DBCS, OEM, Windows)
|
||||
/ 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)
|
||||
/ 1250 - Central Europe (Windows)
|
||||
/ 1251 - Cyrillic (Windows)
|
||||
/ 1252 - Latin 1 (Windows)
|
||||
/ 1253 - Greek (Windows)
|
||||
/ 1254 - Turkish (Windows)
|
||||
/ 1255 - Hebrew (Windows)
|
||||
/ 1256 - Arabic (Windows)
|
||||
/ 1257 - Baltic (Windows)
|
||||
/ 1258 - Vietnam (OEM, Windows)
|
||||
/ 437 - U.S. (OEM)
|
||||
/ 720 - Arabic (OEM)
|
||||
/ 737 - Greek (OEM)
|
||||
/ 775 - Baltic (OEM)
|
||||
/ 850 - Multilingual Latin 1 (OEM)
|
||||
/ 858 - Multilingual Latin 1 + Euro (OEM)
|
||||
/ 852 - Latin 2 (OEM)
|
||||
/ 855 - Cyrillic (OEM)
|
||||
/ 866 - Russian (OEM)
|
||||
/ 857 - Turkish (OEM)
|
||||
/ 862 - Hebrew (OEM)
|
||||
/ 874 - Thai (OEM, Windows)
|
||||
/ 1 - ASCII (No extended character. Valid for only non-LFN configuration.) */
|
||||
|
||||
|
||||
#define _USE_LFN 3
|
||||
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
|
||||
/* The _USE_LFN option switches the LFN feature.
|
||||
/
|
||||
/ 0: Disable LFN feature. _MAX_LFN has no effect.
|
||||
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
|
||||
/ 2: Enable LFN with dynamic working buffer on the STACK.
|
||||
/ 3: Enable LFN with dynamic working buffer on the HEAP.
|
||||
/
|
||||
/ When enable the LFN feature, Unicode handling functions (option/unicode.c) must
|
||||
/ be added to the project. The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes.
|
||||
/ When use stack for the working buffer, take care on stack overflow. When use heap
|
||||
/ memory for the working buffer, memory management functions, ff_memalloc() and
|
||||
/ ff_memfree(), must be added to the project. */
|
||||
|
||||
|
||||
#define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
|
||||
/* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode)
|
||||
/ To use Unicode string for the path name, enable LFN feature and set _LFN_UNICODE
|
||||
/ to 1. This option also affects behavior of string I/O functions. */
|
||||
|
||||
|
||||
#define _STRF_ENCODE 3
|
||||
/* When _LFN_UNICODE is 1, this option selects the character encoding on the file to
|
||||
/ be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
|
||||
/
|
||||
/ 0: ANSI/OEM
|
||||
/ 1: UTF-16LE
|
||||
/ 2: UTF-16BE
|
||||
/ 3: UTF-8
|
||||
/
|
||||
/ When _LFN_UNICODE is 0, this option has no effect. */
|
||||
|
||||
|
||||
#define _FS_RPATH 0
|
||||
/* This option configures relative path feature.
|
||||
/
|
||||
/ 0: Disable relative path feature and remove related functions.
|
||||
/ 1: Enable relative path feature. f_chdir() and f_chdrive() are available.
|
||||
/ 2: f_getcwd() function is available in addition to 1.
|
||||
/
|
||||
/ Note that directory items read via f_readdir() are affected by this option. */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Drive/Volume Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define _VOLUMES 1
|
||||
/* Number of volumes (logical drives) to be used. */
|
||||
|
||||
|
||||
#define _STR_VOLUME_ID 0
|
||||
#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
|
||||
/* _STR_VOLUME_ID option switches string volume ID feature.
|
||||
/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
|
||||
/ number in the path name. _VOLUME_STRS defines the drive ID strings for each
|
||||
/ logical drives. Number of items must be equal to _VOLUMES. Valid characters for
|
||||
/ the drive ID strings are: A-Z and 0-9. */
|
||||
|
||||
|
||||
#define _MULTI_PARTITION 0
|
||||
/* This option switches multi-partition feature. By default (0), each logical drive
|
||||
/ number is bound to the same physical drive number and only an FAT volume found on
|
||||
/ the physical drive will be mounted. When multi-partition feature is enabled (1),
|
||||
/ each logical drive number is bound to arbitrary physical drive and partition
|
||||
/ listed in the VolToPart[]. Also f_fdisk() funciton will be available. */
|
||||
|
||||
|
||||
#define _MIN_SS 512
|
||||
#define _MAX_SS 512
|
||||
/* These options configure the range of sector size to be supported. (512, 1024,
|
||||
/ 2048 or 4096) Always set both 512 for most systems, all type of memory cards and
|
||||
/ harddisk. But a larger value may be required for on-board flash memory and some
|
||||
/ type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured
|
||||
/ to variable sector size and GET_SECTOR_SIZE command must be implemented to the
|
||||
/ disk_ioctl() function. */
|
||||
|
||||
|
||||
#define _USE_TRIM 0
|
||||
/* This option switches ATA-TRIM feature. (0:Disable or 1:Enable)
|
||||
/ To enable Trim feature, also CTRL_TRIM command should be implemented to the
|
||||
/ disk_ioctl() function. */
|
||||
|
||||
|
||||
#define _FS_NOFSINFO 0
|
||||
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
|
||||
/ option, and f_getfree() function at first time after volume mount will force
|
||||
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
|
||||
/
|
||||
/ bit0=0: Use free cluster count in the FSINFO if available.
|
||||
/ bit0=1: Do not trust free cluster count in the FSINFO.
|
||||
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
|
||||
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
|
||||
*/
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ System Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define _FS_NORTC 0
|
||||
#define _NORTC_MON 2
|
||||
#define _NORTC_MDAY 1
|
||||
#define _NORTC_YEAR 2015
|
||||
/* The _FS_NORTC option switches timestamp feature. If the system does not have
|
||||
/ an RTC function or valid timestamp is not needed, set _FS_NORTC to 1 to disable
|
||||
/ the timestamp feature. All objects modified by FatFs will have a fixed timestamp
|
||||
/ defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR.
|
||||
/ When timestamp feature is enabled (_FS_NORTC == 0), get_fattime() function need
|
||||
/ to be added to the project to read current time form RTC. _NORTC_MON,
|
||||
/ _NORTC_MDAY and _NORTC_YEAR have no effect.
|
||||
/ These options have no effect at read-only configuration (_FS_READONLY == 1). */
|
||||
|
||||
|
||||
#define _FS_LOCK 2
|
||||
/* The _FS_LOCK option switches file lock feature to control duplicated file open
|
||||
/ and illegal operation to open objects. This option must be 0 when _FS_READONLY
|
||||
/ is 1.
|
||||
/
|
||||
/ 0: Disable file lock feature. To avoid volume corruption, application program
|
||||
/ should avoid illegal open, remove and rename to the open objects.
|
||||
/ >0: Enable file lock feature. The value defines how many files/sub-directories
|
||||
/ can be opened simultaneously under file lock control. Note that the file
|
||||
/ lock feature is independent of re-entrancy. */
|
||||
|
||||
|
||||
#define _FS_REENTRANT 1
|
||||
#define _FS_TIMEOUT 1000
|
||||
#define _SYNC_t osSemaphoreId
|
||||
/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs
|
||||
/ module itself. Note that regardless of this option, file access to different
|
||||
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
|
||||
/ and f_fdisk() function, are always not re-entrant. Only file/directory access
|
||||
/ to the same volume is under control of this feature.
|
||||
/
|
||||
/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
|
||||
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
|
||||
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
|
||||
/ function, must be added to the project. Samples are available in
|
||||
/ option/syscall.c.
|
||||
/
|
||||
/ The _FS_TIMEOUT defines timeout period in unit of time tick.
|
||||
/ The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
|
||||
/ SemaphoreHandle_t and etc.. */
|
||||
|
||||
|
||||
#define _WORD_ACCESS 0
|
||||
/* The _WORD_ACCESS option is an only platform dependent option. It defines
|
||||
/ which access method is used to the word data on the FAT volume.
|
||||
/
|
||||
/ 0: Byte-by-byte access. Always compatible with all platforms.
|
||||
/ 1: Word access. Do not choose this unless under both the following conditions.
|
||||
/
|
||||
/ * Address misaligned memory access is always allowed to ALL instructions.
|
||||
/ * Byte order on the memory is little-endian.
|
||||
/
|
||||
/ If it is the case, _WORD_ACCESS can also be set to 1 to reduce code size.
|
||||
/ Following table shows allowable settings of some processor types.
|
||||
/
|
||||
/ ARM7TDMI 0 ColdFire 0 V850E 0
|
||||
/ Cortex-M3 0 Z80 0/1 V850ES 0/1
|
||||
/ Cortex-M0 0 x86 0/1 TLCS-870 0/1
|
||||
/ AVR 0/1 RX600(LE) 0/1 TLCS-900 0/1
|
||||
/ AVR32 0 RL78 0 R32C 0
|
||||
/ PIC18 0/1 SH-2 0 M16C 0/1
|
||||
/ PIC24 0 H8S 0 MSP430 0
|
||||
/ PIC32 0 H8/300H 0 8051 0/1
|
||||
*/
|
||||
|
||||
|
||||
#endif /* _FFCONF */
|
||||
Vendored
Executable
+33
@@ -0,0 +1,33 @@
|
||||
/*-------------------------------------------*/
|
||||
/* Integer type definitions for FatFs module */
|
||||
/*-------------------------------------------*/
|
||||
|
||||
#ifndef _FF_INTEGER
|
||||
#define _FF_INTEGER
|
||||
|
||||
#ifdef _WIN32 /* FatFs development platform */
|
||||
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#else /* Embedded platform */
|
||||
|
||||
/* This type MUST be 8 bit */
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
/* These types MUST be 16 bit */
|
||||
typedef short SHORT;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned short WCHAR;
|
||||
|
||||
/* These types MUST be 16 bit or 32 bit */
|
||||
typedef int INT;
|
||||
typedef unsigned int UINT;
|
||||
|
||||
/* These types MUST be 32 bit */
|
||||
typedef long LONG;
|
||||
typedef unsigned long DWORD;
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
Executable
+3798
File diff suppressed because it is too large
Load Diff
Vendored
Executable
+10973
File diff suppressed because it is too large
Load Diff
Vendored
Executable
+8603
File diff suppressed because it is too large
Load Diff
Vendored
Executable
+6829
File diff suppressed because it is too large
Load Diff
Vendored
Executable
+540
@@ -0,0 +1,540 @@
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Unicode - Local code bidirectional converter (C)ChaN, 2012 */
|
||||
/* (SBCS code pages) */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* 437 U.S. (OEM)
|
||||
/ 720 Arabic (OEM)
|
||||
/ 1256 Arabic (Windows)
|
||||
/ 737 Greek (OEM)
|
||||
/ 1253 Greek (Windows)
|
||||
/ 1250 Central Europe (Windows)
|
||||
/ 775 Baltic (OEM)
|
||||
/ 1257 Baltic (Windows)
|
||||
/ 850 Multilingual Latin 1 (OEM)
|
||||
/ 852 Latin 2 (OEM)
|
||||
/ 1252 Latin 1 (Windows)
|
||||
/ 855 Cyrillic (OEM)
|
||||
/ 1251 Cyrillic (Windows)
|
||||
/ 866 Russian (OEM)
|
||||
/ 857 Turkish (OEM)
|
||||
/ 1254 Turkish (Windows)
|
||||
/ 858 Multilingual Latin 1 + Euro (OEM)
|
||||
/ 862 Hebrew (OEM)
|
||||
/ 1255 Hebrew (Windows)
|
||||
/ 874 Thai (OEM, Windows)
|
||||
/ 1258 Vietnam (OEM, Windows)
|
||||
*/
|
||||
|
||||
#include "../ff.h"
|
||||
|
||||
|
||||
#if _CODE_PAGE == 437
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP437(0x80-0xFF) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
|
||||
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
|
||||
0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
|
||||
0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
|
||||
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
|
||||
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
|
||||
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4,
|
||||
0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248,
|
||||
0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 720
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP720(0x80-0xFF) to Unicode conversion table */
|
||||
0x0000, 0x0000, 0x00E9, 0x00E2, 0x0000, 0x00E0, 0x0000, 0x00E7,
|
||||
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0651, 0x0652, 0x00F4, 0x00A4, 0x0640, 0x00FB, 0x00F9,
|
||||
0x0621, 0x0622, 0x0623, 0x0624, 0x00A3, 0x0625, 0x0626, 0x0627,
|
||||
0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,
|
||||
0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
|
||||
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
|
||||
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
|
||||
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x0636, 0x0637, 0x0638, 0x0639, 0x063A, 0x0641, 0x00B5, 0x0642,
|
||||
0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649, 0x064A,
|
||||
0x2261, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F, 0x0650, 0x2248,
|
||||
0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 737
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP737(0x80-0xFF) to Unicode conversion table */
|
||||
0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398,
|
||||
0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, 0x03A0,
|
||||
0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9,
|
||||
0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7, 0x03B8,
|
||||
0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0,
|
||||
0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x03C5, 0x03C6, 0x03C7, 0x03C8,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
|
||||
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
|
||||
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
|
||||
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03C9, 0x03AC, 0x03AD, 0x03AE, 0x03CA, 0x03AF, 0x03CC, 0x03CD,
|
||||
0x03CB, 0x03CE, 0x0386, 0x0388, 0x0389, 0x038A, 0x038C, 0x038E,
|
||||
0x038F, 0x00B1, 0x2265, 0x2264, 0x03AA, 0x03AB, 0x00F7, 0x2248,
|
||||
0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 775
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP775(0x80-0xFF) to Unicode conversion table */
|
||||
0x0106, 0x00FC, 0x00E9, 0x0101, 0x00E4, 0x0123, 0x00E5, 0x0107,
|
||||
0x0142, 0x0113, 0x0156, 0x0157, 0x012B, 0x0179, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x014D, 0x00F6, 0x0122, 0x00A2, 0x015A,
|
||||
0x015B, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x00A4,
|
||||
0x0100, 0x012A, 0x00F3, 0x017B, 0x017C, 0x017A, 0x201D, 0x00A6,
|
||||
0x00A9, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x0141, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0104, 0x010C, 0x0118,
|
||||
0x0116, 0x2563, 0x2551, 0x2557, 0x255D, 0x012E, 0x0160, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0172, 0x016A,
|
||||
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x017D,
|
||||
0x0105, 0x010D, 0x0119, 0x0117, 0x012F, 0x0161, 0x0173, 0x016B,
|
||||
0x017E, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x00D3, 0x00DF, 0x014C, 0x0143, 0x00F5, 0x00D5, 0x00B5, 0x0144,
|
||||
0x0136, 0x0137, 0x013B, 0x013C, 0x0146, 0x0112, 0x0145, 0x2019,
|
||||
0x00AD, 0x00B1, 0x201C, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x201E,
|
||||
0x00B0, 0x2219, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 850
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP850(0x80-0xFF) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
|
||||
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
|
||||
0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
|
||||
0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0,
|
||||
0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3,
|
||||
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
|
||||
0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x0131, 0x00CD, 0x00CE,
|
||||
0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
|
||||
0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE,
|
||||
0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
|
||||
0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8,
|
||||
0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 852
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP852(0x80-0xFF) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x016F, 0x0107, 0x00E7,
|
||||
0x0142, 0x00EB, 0x0150, 0x0151, 0x00EE, 0x0179, 0x00C4, 0x0106,
|
||||
0x00C9, 0x0139, 0x013A, 0x00F4, 0x00F6, 0x013D, 0x013E, 0x015A,
|
||||
0x015B, 0x00D6, 0x00DC, 0x0164, 0x0165, 0x0141, 0x00D7, 0x010D,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x0104, 0x0105, 0x017D, 0x017E,
|
||||
0x0118, 0x0119, 0x00AC, 0x017A, 0x010C, 0x015F, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x011A,
|
||||
0x015E, 0x2563, 0x2551, 0x2557, 0x255D, 0x017B, 0x017C, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0102, 0x0103,
|
||||
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
|
||||
0x0111, 0x0110, 0x010E, 0x00CB, 0x010F, 0x0147, 0x00CD, 0x00CE,
|
||||
0x011B, 0x2518, 0x250C, 0x2588, 0x2584, 0x0162, 0x016E, 0x2580,
|
||||
0x00D3, 0x00DF, 0x00D4, 0x0143, 0x0144, 0x0148, 0x0160, 0x0161,
|
||||
0x0154, 0x00DA, 0x0155, 0x0170, 0x00FD, 0x00DD, 0x0163, 0x00B4,
|
||||
0x00AD, 0x02DD, 0x02DB, 0x02C7, 0x02D8, 0x00A7, 0x00F7, 0x00B8,
|
||||
0x00B0, 0x00A8, 0x02D9, 0x0171, 0x0158, 0x0159, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 855
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP855(0x80-0xFF) to Unicode conversion table */
|
||||
0x0452, 0x0402, 0x0453, 0x0403, 0x0451, 0x0401, 0x0454, 0x0404,
|
||||
0x0455, 0x0405, 0x0456, 0x0406, 0x0457, 0x0407, 0x0458, 0x0408,
|
||||
0x0459, 0x0409, 0x045A, 0x040A, 0x045B, 0x040B, 0x045C, 0x040C,
|
||||
0x045E, 0x040E, 0x045F, 0x040F, 0x044E, 0x042E, 0x044A, 0x042A,
|
||||
0x0430, 0x0410, 0x0431, 0x0411, 0x0446, 0x0426, 0x0434, 0x0414,
|
||||
0x0435, 0x0415, 0x0444, 0x0424, 0x0433, 0x0413, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0445, 0x0425, 0x0438,
|
||||
0x0418, 0x2563, 0x2551, 0x2557, 0x255D, 0x0439, 0x0419, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x043A, 0x041A,
|
||||
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
|
||||
0x043B, 0x041B, 0x043C, 0x041C, 0x043D, 0x041D, 0x043E, 0x041E,
|
||||
0x043F, 0x2518, 0x250C, 0x2588, 0x2584, 0x041F, 0x044F, 0x2580,
|
||||
0x042F, 0x0440, 0x0420, 0x0441, 0x0421, 0x0442, 0x0422, 0x0443,
|
||||
0x0423, 0x0436, 0x0416, 0x0432, 0x0412, 0x044C, 0x042C, 0x2116,
|
||||
0x00AD, 0x044B, 0x042B, 0x0437, 0x0417, 0x0448, 0x0428, 0x044D,
|
||||
0x042D, 0x0449, 0x0429, 0x0447, 0x0427, 0x00A7, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 857
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP857(0x80-0xFF) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
|
||||
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0131, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
|
||||
0x0130, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x015E, 0x015F,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x011E, 0x011F,
|
||||
0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0,
|
||||
0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3,
|
||||
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
|
||||
0x00BA, 0x00AA, 0x00CA, 0x00CB, 0x00C8, 0x0000, 0x00CD, 0x00CE,
|
||||
0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
|
||||
0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x0000,
|
||||
0x00D7, 0x00DA, 0x00DB, 0x00D9, 0x00EC, 0x00FF, 0x00AF, 0x00B4,
|
||||
0x00AD, 0x00B1, 0x0000, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8,
|
||||
0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 858
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP858(0x80-0xFF) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
|
||||
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
|
||||
0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
|
||||
0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0,
|
||||
0x00A9, 0x2563, 0x2551, 0x2557, 0x2550, 0x00A2, 0x00A5, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3,
|
||||
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
|
||||
0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x20AC, 0x00CD, 0x00CE,
|
||||
0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00C6, 0x00CC, 0x2580,
|
||||
0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE,
|
||||
0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
|
||||
0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8,
|
||||
0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 862
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP862(0x80-0xFF) to Unicode conversion table */
|
||||
0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
|
||||
0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
|
||||
0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
|
||||
0x05E8, 0x05E9, 0x05EA, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
|
||||
0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
|
||||
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
|
||||
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
|
||||
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4,
|
||||
0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248,
|
||||
0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 866
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP866(0x80-0xFF) to Unicode conversion table */
|
||||
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
|
||||
0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
|
||||
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
|
||||
0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
|
||||
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
|
||||
0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
|
||||
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
|
||||
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
|
||||
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
|
||||
0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
|
||||
0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040E, 0x045E,
|
||||
0x00B0, 0x2219, 0x00B7, 0x221A, 0x2116, 0x00A4, 0x25A0, 0x00A0
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 874
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP874(0x80-0xFF) to Unicode conversion table */
|
||||
0x20AC, 0x0000, 0x0000, 0x0000, 0x0000, 0x2026, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x00A0, 0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, 0x0E07,
|
||||
0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F,
|
||||
0x0E10, 0x0E11, 0x0E12, 0x0E13, 0x0E14, 0x0E15, 0x0E16, 0x0E17,
|
||||
0x0E18, 0x0E19, 0x0E1A, 0x0E1B, 0x0E1C, 0x0E1D, 0x0E1E, 0x0E1F,
|
||||
0x0E20, 0x0E21, 0x0E22, 0x0E23, 0x0E24, 0x0E25, 0x0E26, 0x0E27,
|
||||
0x0E28, 0x0E29, 0x0E2A, 0x0E2B, 0x0E2C, 0x0E2D, 0x0E2E, 0x0E2F,
|
||||
0x0E30, 0x0E31, 0x0E32, 0x0E33, 0x0E34, 0x0E35, 0x0E36, 0x0E37,
|
||||
0x0E38, 0x0E39, 0x0E3A, 0x0000, 0x0000, 0x0000, 0x0000, 0x0E3F,
|
||||
0x0E40, 0x0E41, 0x0E42, 0x0E43, 0x0E44, 0x0E45, 0x0E46, 0x0E47,
|
||||
0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0E4F,
|
||||
0x0E50, 0x0E51, 0x0E52, 0x0E53, 0x0E54, 0x0E55, 0x0E56, 0x0E57,
|
||||
0x0E58, 0x0E59, 0x0E5A, 0x0E5B, 0x0000, 0x0000, 0x0000, 0x0000
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 1250
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP1250(0x80-0xFF) to Unicode conversion table */
|
||||
0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x0000, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179,
|
||||
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x0000, 0x2122, 0x0161, 0x203A, 0x015B, 0x0165, 0x017E, 0x017A,
|
||||
0x00A0, 0x02C7, 0x02D8, 0x0141, 0x00A4, 0x0104, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x015E, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x017B,
|
||||
0x00B0, 0x00B1, 0x02DB, 0x0142, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x0105, 0x015F, 0x00BB, 0x013D, 0x02DD, 0x013E, 0x017C,
|
||||
0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7,
|
||||
0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E,
|
||||
0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7,
|
||||
0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF,
|
||||
0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7,
|
||||
0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F,
|
||||
0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7,
|
||||
0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 1251
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP1251(0x80-0xFF) to Unicode conversion table */
|
||||
0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F,
|
||||
0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x0000, 0x2111, 0x0459, 0x203A, 0x045A, 0x045C, 0x045B, 0x045F,
|
||||
0x00A0, 0x040E, 0x045E, 0x0408, 0x00A4, 0x0490, 0x00A6, 0x00A7,
|
||||
0x0401, 0x00A9, 0x0404, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x0407,
|
||||
0x00B0, 0x00B1, 0x0406, 0x0456, 0x0491, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x0451, 0x2116, 0x0454, 0x00BB, 0x0458, 0x0405, 0x0455, 0x0457,
|
||||
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
|
||||
0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
|
||||
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
|
||||
0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
|
||||
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
|
||||
0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
|
||||
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
|
||||
0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 1252
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP1252(0x80-0xFF) to Unicode conversion table */
|
||||
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017D, 0x0000,
|
||||
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x017E, 0x0178,
|
||||
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
|
||||
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
|
||||
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
|
||||
0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
|
||||
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
|
||||
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 1253
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP1253(0x80-0xFF) to Unicode conversion table */
|
||||
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x0000, 0x2030, 0x0000, 0x2039, 0x000C, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x0000, 0x2122, 0x0000, 0x203A, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x00A0, 0x0385, 0x0386, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x0000, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x2015,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x0384, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x0388, 0x0389, 0x038A, 0x00BB, 0x038C, 0x00BD, 0x038E, 0x038F,
|
||||
0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
|
||||
0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
|
||||
0x03A0, 0x03A1, 0x0000, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
|
||||
0x03A8, 0x03A9, 0x03AA, 0x03AD, 0x03AC, 0x03AD, 0x03AE, 0x03AF,
|
||||
0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
|
||||
0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
|
||||
0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
|
||||
0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0x0000
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 1254
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP1254(0x80-0xFF) to Unicode conversion table */
|
||||
0x20AC, 0x0000, 0x210A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x0000, 0x0178,
|
||||
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
|
||||
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
|
||||
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
|
||||
0x011E, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00BD, 0x00DC, 0x0130, 0x015E, 0x00DF,
|
||||
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x011F, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
|
||||
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0131, 0x015F, 0x00FF
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 1255
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP1255(0x80-0xFF) to Unicode conversion table */
|
||||
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x02C6, 0x2030, 0x0000, 0x2039, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x02DC, 0x2122, 0x0000, 0x203A, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
|
||||
0x05B0, 0x05B1, 0x05B2, 0x05B3, 0x05B4, 0x05B5, 0x05B6, 0x05B7,
|
||||
0x05B8, 0x05B9, 0x0000, 0x05BB, 0x05BC, 0x05BD, 0x05BE, 0x05BF,
|
||||
0x05C0, 0x05C1, 0x05C2, 0x05C3, 0x05F0, 0x05F1, 0x05F2, 0x05F3,
|
||||
0x05F4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
|
||||
0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
|
||||
0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
|
||||
0x05E8, 0x05E9, 0x05EA, 0x0000, 0x0000, 0x200E, 0x200F, 0x0000
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 1256
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP1256(0x80-0xFF) to Unicode conversion table */
|
||||
0x20AC, 0x067E, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x02C6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688,
|
||||
0x06AF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x06A9, 0x2122, 0x0691, 0x203A, 0x0153, 0x200C, 0x200D, 0x06BA,
|
||||
0x00A0, 0x060C, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x06BE, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x061B, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x061F,
|
||||
0x06C1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,
|
||||
0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,
|
||||
0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x00D7,
|
||||
0x0637, 0x0638, 0x0639, 0x063A, 0x0640, 0x0640, 0x0642, 0x0643,
|
||||
0x00E0, 0x0644, 0x00E2, 0x0645, 0x0646, 0x0647, 0x0648, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0649, 0x064A, 0x00EE, 0x00EF,
|
||||
0x064B, 0x064C, 0x064D, 0x064E, 0x00F4, 0x064F, 0x0650, 0x00F7,
|
||||
0x0651, 0x00F9, 0x0652, 0x00FB, 0x00FC, 0x200E, 0x200F, 0x06D2
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 1257
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP1257(0x80-0xFF) to Unicode conversion table */
|
||||
0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x0000, 0x2030, 0x0000, 0x2039, 0x0000, 0x00A8, 0x02C7, 0x00B8,
|
||||
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x0000, 0x2122, 0x0000, 0x203A, 0x0000, 0x00AF, 0x02DB, 0x0000,
|
||||
0x00A0, 0x0000, 0x00A2, 0x00A3, 0x00A4, 0x0000, 0x00A6, 0x00A7,
|
||||
0x00D8, 0x00A9, 0x0156, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x0157, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00E6,
|
||||
0x0104, 0x012E, 0x0100, 0x0106, 0x00C4, 0x00C5, 0x0118, 0x0112,
|
||||
0x010C, 0x00C9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012A, 0x013B,
|
||||
0x0160, 0x0143, 0x0145, 0x00D3, 0x014C, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x0172, 0x0141, 0x015A, 0x016A, 0x00DC, 0x017B, 0x017D, 0x00DF,
|
||||
0x0105, 0x012F, 0x0101, 0x0107, 0x00E4, 0x00E5, 0x0119, 0x0113,
|
||||
0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C,
|
||||
0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7,
|
||||
0x0173, 0x014E, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x02D9
|
||||
};
|
||||
|
||||
#elif _CODE_PAGE == 1258
|
||||
#define _TBLDEF 1
|
||||
static
|
||||
const WCHAR Tbl[] = { /* CP1258(0x80-0xFF) to Unicode conversion table */
|
||||
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x02C6, 0x2030, 0x0000, 0x2039, 0x0152, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x02DC, 0x2122, 0x0000, 0x203A, 0x0153, 0x0000, 0x0000, 0x0178,
|
||||
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
|
||||
0x00C0, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
|
||||
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x0300, 0x00CD, 0x00CE, 0x00CF,
|
||||
0x0110, 0x00D1, 0x0309, 0x00D3, 0x00D4, 0x01A0, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x01AF, 0x0303, 0x00DF,
|
||||
0x00E0, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0301, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x0111, 0x00F1, 0x0323, 0x00F3, 0x00F4, 0x01A1, 0x00F6, 0x00F7,
|
||||
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x01B0, 0x20AB, 0x00FF
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if !_TBLDEF || !_USE_LFN
|
||||
#error This file is not needed in current configuration. Remove from the project.
|
||||
#endif
|
||||
|
||||
|
||||
WCHAR ff_convert ( /* Converted character, Returns zero on error */
|
||||
WCHAR chr, /* Character code to be converted */
|
||||
UINT dir /* 0: Unicode to OEMCP, 1: OEMCP to Unicode */
|
||||
)
|
||||
{
|
||||
WCHAR c;
|
||||
|
||||
|
||||
if (chr < 0x80) { /* ASCII */
|
||||
c = chr;
|
||||
|
||||
} else {
|
||||
if (dir) { /* OEMCP to Unicode */
|
||||
c = (chr >= 0x100) ? 0 : Tbl[chr - 0x80];
|
||||
|
||||
} else { /* Unicode to OEMCP */
|
||||
for (c = 0; c < 0x80; c++) {
|
||||
if (chr == Tbl[c]) break;
|
||||
}
|
||||
c = (c + 0x80) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
WCHAR ff_wtoupper ( /* Upper converted character */
|
||||
WCHAR chr /* Input character */
|
||||
)
|
||||
{
|
||||
static const WCHAR tbl_lower[] = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0xA1, 0x00A2, 0x00A3, 0x00A5, 0x00AC, 0x00AF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x0FF, 0x101, 0x103, 0x105, 0x107, 0x109, 0x10B, 0x10D, 0x10F, 0x111, 0x113, 0x115, 0x117, 0x119, 0x11B, 0x11D, 0x11F, 0x121, 0x123, 0x125, 0x127, 0x129, 0x12B, 0x12D, 0x12F, 0x131, 0x133, 0x135, 0x137, 0x13A, 0x13C, 0x13E, 0x140, 0x142, 0x144, 0x146, 0x148, 0x14B, 0x14D, 0x14F, 0x151, 0x153, 0x155, 0x157, 0x159, 0x15B, 0x15D, 0x15F, 0x161, 0x163, 0x165, 0x167, 0x169, 0x16B, 0x16D, 0x16F, 0x171, 0x173, 0x175, 0x177, 0x17A, 0x17C, 0x17E, 0x192, 0x3B1, 0x3B2, 0x3B3, 0x3B4, 0x3B5, 0x3B6, 0x3B7, 0x3B8, 0x3B9, 0x3BA, 0x3BB, 0x3BC, 0x3BD, 0x3BE, 0x3BF, 0x3C0, 0x3C1, 0x3C3, 0x3C4, 0x3C5, 0x3C6, 0x3C7, 0x3C8, 0x3C9, 0x3CA, 0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x43E, 0x43F, 0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F, 0x451, 0x452, 0x453, 0x454, 0x455, 0x456, 0x457, 0x458, 0x459, 0x45A, 0x45B, 0x45C, 0x45E, 0x45F, 0x2170, 0x2171, 0x2172, 0x2173, 0x2174, 0x2175, 0x2176, 0x2177, 0x2178, 0x2179, 0x217A, 0x217B, 0x217C, 0x217D, 0x217E, 0x217F, 0xFF41, 0xFF42, 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0xFF4B, 0xFF4C, 0xFF4D, 0xFF4E, 0xFF4F, 0xFF50, 0xFF51, 0xFF52, 0xFF53, 0xFF54, 0xFF55, 0xFF56, 0xFF57, 0xFF58, 0xFF59, 0xFF5A, 0 };
|
||||
static const WCHAR tbl_upper[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x21, 0xFFE0, 0xFFE1, 0xFFE5, 0xFFE2, 0xFFE3, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0x178, 0x100, 0x102, 0x104, 0x106, 0x108, 0x10A, 0x10C, 0x10E, 0x110, 0x112, 0x114, 0x116, 0x118, 0x11A, 0x11C, 0x11E, 0x120, 0x122, 0x124, 0x126, 0x128, 0x12A, 0x12C, 0x12E, 0x130, 0x132, 0x134, 0x136, 0x139, 0x13B, 0x13D, 0x13F, 0x141, 0x143, 0x145, 0x147, 0x14A, 0x14C, 0x14E, 0x150, 0x152, 0x154, 0x156, 0x158, 0x15A, 0x15C, 0x15E, 0x160, 0x162, 0x164, 0x166, 0x168, 0x16A, 0x16C, 0x16E, 0x170, 0x172, 0x174, 0x176, 0x179, 0x17B, 0x17D, 0x191, 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39A, 0x39B, 0x39C, 0x39D, 0x39E, 0x39F, 0x3A0, 0x3A1, 0x3A3, 0x3A4, 0x3A5, 0x3A6, 0x3A7, 0x3A8, 0x3A9, 0x3AA, 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E, 0x41F, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42A, 0x42B, 0x42C, 0x42D, 0x42E, 0x42F, 0x401, 0x402, 0x403, 0x404, 0x405, 0x406, 0x407, 0x408, 0x409, 0x40A, 0x40B, 0x40C, 0x40E, 0x40F, 0x2160, 0x2161, 0x2162, 0x2163, 0x2164, 0x2165, 0x2166, 0x2167, 0x2168, 0x2169, 0x216A, 0x216B, 0x216C, 0x216D, 0x216E, 0x216F, 0xFF21, 0xFF22, 0xFF23, 0xFF24, 0xFF25, 0xFF26, 0xFF27, 0xFF28, 0xFF29, 0xFF2A, 0xFF2B, 0xFF2C, 0xFF2D, 0xFF2E, 0xFF2F, 0xFF30, 0xFF31, 0xFF32, 0xFF33, 0xFF34, 0xFF35, 0xFF36, 0xFF37, 0xFF38, 0xFF39, 0xFF3A, 0 };
|
||||
int i;
|
||||
|
||||
|
||||
for (i = 0; tbl_lower[i] && chr != tbl_lower[i]; i++) ;
|
||||
|
||||
return tbl_lower[i] ? tbl_upper[i] : chr;
|
||||
}
|
||||
Vendored
Executable
+119
@@ -0,0 +1,119 @@
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Sample code of OS dependent controls for FatFs */
|
||||
/* (C)ChaN, 2014 */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
#include <stdlib.h> /* ANSI memory controls */
|
||||
#include "../ff.h"
|
||||
|
||||
#if _FS_REENTRANT
|
||||
/*-----------------------------------------------------------------------
|
||||
Create a Synchronization Object
|
||||
------------------------------------------------------------------------
|
||||
This function is called in f_mount function to create a new
|
||||
synchronization object, such as semaphore and mutex. When a zero is
|
||||
returned, the f_mount function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
int ff_cre_syncobj ( /* TRUE:Function succeeded, FALSE:Could not create due to any error */
|
||||
BYTE vol, /* Corresponding logical drive being processed */
|
||||
_SYNC_t *sobj /* Pointer to return the created sync object */
|
||||
)
|
||||
{
|
||||
int ret;
|
||||
|
||||
osSemaphoreDef(SEM);
|
||||
*sobj = osSemaphoreCreate(osSemaphore(SEM), 1);
|
||||
ret = (*sobj != NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Delete a Synchronization Object */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called in f_mount function to delete a synchronization
|
||||
/ object that created with ff_cre_syncobj function. When a zero is
|
||||
/ returned, the f_mount function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
int ff_del_syncobj ( /* TRUE:Function succeeded, FALSE:Could not delete due to any error */
|
||||
_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
|
||||
)
|
||||
{
|
||||
osSemaphoreDelete (sobj);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Request Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called on entering file functions to lock the volume.
|
||||
/ When a zero is returned, the file function fails with FR_TIMEOUT.
|
||||
*/
|
||||
|
||||
int ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */
|
||||
_SYNC_t sobj /* Sync object to wait */
|
||||
)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if(osSemaphoreWait(sobj, _FS_TIMEOUT) == osOK)
|
||||
{
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Release Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called on leaving file functions to unlock the volume.
|
||||
*/
|
||||
|
||||
void ff_rel_grant (
|
||||
_SYNC_t sobj /* Sync object to be signaled */
|
||||
)
|
||||
{
|
||||
osSemaphoreRelease(sobj);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#if _USE_LFN == 3 /* LFN with a working buffer on the heap */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Allocate a memory block */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
|
||||
*/
|
||||
|
||||
void* ff_memalloc ( /* Returns pointer to the allocated memory block */
|
||||
UINT msize /* Number of bytes to allocate */
|
||||
)
|
||||
{
|
||||
return malloc(msize); /* Allocate a new memory block with POSIX API */
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Free a memory block */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
void ff_memfree (
|
||||
void* mblock /* Pointer to the memory block to free */
|
||||
)
|
||||
{
|
||||
free(mblock); /* Discard the memory block with POSIX API */
|
||||
}
|
||||
|
||||
#endif
|
||||
Vendored
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#include "../ff.h"
|
||||
|
||||
#if _USE_LFN != 0
|
||||
|
||||
#if _CODE_PAGE == 932 /* Japanese Shift_JIS */
|
||||
#include "cc932.c"
|
||||
#elif _CODE_PAGE == 936 /* Simplified Chinese GBK */
|
||||
#include "cc936.c"
|
||||
#elif _CODE_PAGE == 949 /* Korean */
|
||||
#include "cc949.c"
|
||||
#elif _CODE_PAGE == 950 /* Traditional Chinese Big5 */
|
||||
#include "cc950.c"
|
||||
#else /* Single Byte Character-Set */
|
||||
#include "ccsbcs.c"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user