/*
* @file hv_drv_UsbCoreUtils.h
* @brief Header file of user configuration.
*
* @author HiView SoC Software Team
* @version 1.0.0
* @date 2022-06-15
*/


#ifndef __HV_DRV_USB_CORE_UTILS_H
#define __HV_DRV_USB_CORE_UTILS_H

#include "hv_comm_DataType.h"
#include "hv_drv_UsbFatfs.h"
#include "hv_vos_Comm.h"


#define USBSPEED_LOW   1
#define USBSPEED_FULL  2
#define USBSPEED_HIGH  3
#define HV_CONFIG_USB_SPEED     USBSPEED_HIGH

/**
 * @brief Define the usb type.
 */
typedef struct _HvDrvUsbType
{
    UCHAR8     ucClass;
    UCHAR8     ucSubClass;
    UCHAR8     ucProtocol;
}HvDrvUsbType;


/**
 * @brief Set the type of the USB device to determine whether it is a USB flash drive device.
 * @param[in] ucClass Should be 0x08.
 * @param[in] ucSubClass Should be 0x06.
 * @param[in] ucProtocol Should be 0x50.
 * @return None
 */
void Hv_Drv_USB_SetDeviceType(UCHAR8 ucClass, UCHAR8 ucSubClass, UCHAR8 ucProtocol);


/**
 * @brief Check whether the connected device is a USB flash drive.
 * @param[in] None
 * @return BOOL HV_TRUE:u-disk, HV_FALSE:others
 */
BOOL Hv_Drv_USB_CheckStorageDev(void);

/**
 * @brief Get the class of usb device.
 * @param[in] None
 * @return None
 */
UCHAR8 Hv_Drv_USB_GetClass(void);

/**
 * @brief Get the subclass of usb device.
 * @param[in] None
 * @return None
 */
UCHAR8 Hv_Drv_USB_GetSubClass(void);

/**
 * @brief Get the protocol of usb device.
 * @param[in] None
 * @return None
 */
UCHAR8 Hv_Drv_USB_GetProtocol(void);

/**
 * @brief Set the connect state of usb device.
 * @param[in] bStatus HV_TRUE:Connected
 * @return None
 */
void Hv_Drv_USB_SetConnect(BOOL bStatus);

/**
 * @brief Get the connect state of usb device.
 * @param[in] None
 * @return BOOL HV_TRUE:Connected
 */
BOOL Hv_Drv_USB_GetConnect(void);

/**
 * @brief Do mount u-disk and return the result.
 * @param[in] pstFatfs Point to the FATFS
 * @return Status HV_SUCCESS:Mount u-disk ok, HV_FAILURE:Mount fail
 */
Status Hv_Drv_USB_MountDev(FATFS *pstFatfs);

/**
 * @brief Do find the specified file in u-disk and return the result.
 * @param[in] pstFile Pointer to the file object
 * @param[in] pcPath Indicates the file name
 * @return Status HV_SUCCESS:Found the specified file successfully, HV_FAILURE:Not found the specified file
 */
Status Hv_Drv_USB_FindFile(FIL *       pstFile, const TCHAR *pcPath);

/**
 * @brief Get the length of the file after it is found.
 * @param[in] pstFile Pointer to the file object
 * @return UINT32 Length of the file.
 */
UINT32 Hv_Drv_USB_GetFileSize(FIL *       pstFile);

/**
 * @brief Close the file.
 * @param[in] pstFile Pointer to the file object
 * @return Status HV_SUCCESS:Close successfully.
 */
Status Hv_Drv_USB_CloseFile(FIL *       pstFile);

/**
 * @brief Unmount the u-disk.
 * @param[in] None
 * @return Status HV_SUCCESS:unmount successfully.
 */
Status Hv_Drv_USB_UnmountDev(void);

/**
 * @brief Seek File Read/Write Pointer
 * @param[in] pstFile Pointer to the file object
 * @param[in] offset File pointer(offset) from top of file
 * @return Status HV_SUCCESS:set seek successfully.
 */
Status Hv_Drv_USB_SetFileSeek(FIL *pstFile, FSIZE_t offset);

/**
 * @brief Read file
 * @param[in] pstFile Pointer to the file object
 * @param[in] buff Pointer to data buffer
 * @param[in] uiRdLen Number of bytes to read
 * @param[in] uiRdLenRet Pointer to number of bytes read
 * @return Status HV_SUCCESS:set seek successfully.
 */
Status Hv_Drv_USB_ReadFile(FIL *pstFile, void *buff, UINT32 uiRdLen, UINT32 *uiRdLenRet);


/**
 * @brief Search the folder and print all the file names.
 * @param[in] pcPath Indicates the file name
 * @return VOID.
 */
VOID Hv_Drv_USB_ListFiles(const char* path);

/**
 * @brief 检查当前存储设备是否已经被Mounted.
 * @param[in] pstFile Pointer to the file object
 * @return BOOL.
 */
BOOL Hv_Drv_USB_GetMounted(const FATFS* pstFatfs);


#endif /* __USB_UTILS_H */
