1 // Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #include <stdint.h> 22 typedef unsigned int UINT; 23 typedef unsigned char BYTE; 24 typedef uint32_t DWORD; 25 26 #define FF_DRV_NOT_USED 0xFF 27 28 #include "diskio.h" 29 #include "esp_err.h" 30 31 /** 32 * Structure of pointers to disk IO driver functions. 33 * 34 * See FatFs documentation for details about these functions 35 */ 36 typedef struct { 37 DSTATUS (*init) (unsigned char pdrv); /*!< disk initialization function */ 38 DSTATUS (*status) (unsigned char pdrv); /*!< disk status check function */ 39 DRESULT (*read) (unsigned char pdrv, unsigned char* buff, uint32_t sector, unsigned count); /*!< sector read function */ 40 DRESULT (*write) (unsigned char pdrv, const unsigned char* buff, uint32_t sector, unsigned count); /*!< sector write function */ 41 DRESULT (*ioctl) (unsigned char pdrv, unsigned char cmd, void* buff); /*!< function to get info about disk and do some misc operations */ 42 } ff_diskio_impl_t; 43 44 /** 45 * Register or unregister diskio driver for given drive number. 46 * 47 * When FATFS library calls one of disk_xxx functions for driver number pdrv, 48 * corresponding function in discio_impl for given pdrv will be called. 49 * 50 * @param pdrv drive number 51 * @param discio_impl pointer to ff_diskio_impl_t structure with diskio functions 52 * or NULL to unregister and free previously registered drive 53 */ 54 void ff_diskio_register(BYTE pdrv, const ff_diskio_impl_t* discio_impl); 55 56 #define ff_diskio_unregister(pdrv_) ff_diskio_register(pdrv_, NULL) 57 58 59 /** 60 * Get next available drive number 61 * 62 * @param out_pdrv pointer to the byte to set if successful 63 * 64 * @return ESP_OK on success 65 * ESP_ERR_NOT_FOUND if all drives are attached 66 */ 67 esp_err_t ff_diskio_get_drive(BYTE* out_pdrv); 68 69 70 #ifdef __cplusplus 71 } 72 #endif 73