diskio_impl.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #pragma once
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <stdint.h>
  19. typedef unsigned int UINT;
  20. typedef unsigned char BYTE;
  21. typedef uint32_t DWORD;
  22. #include "diskio.h"
  23. #include "esp_err.h"
  24. /**
  25. * Structure of pointers to disk IO driver functions.
  26. *
  27. * See FatFs documentation for details about these functions
  28. */
  29. typedef struct {
  30. DSTATUS (*init) (unsigned char pdrv); /*!< disk initialization function */
  31. DSTATUS (*status) (unsigned char pdrv); /*!< disk status check function */
  32. DRESULT (*read) (unsigned char pdrv, unsigned char* buff, uint32_t sector, unsigned count); /*!< sector read function */
  33. DRESULT (*write) (unsigned char pdrv, const unsigned char* buff, uint32_t sector, unsigned count); /*!< sector write function */
  34. DRESULT (*ioctl) (unsigned char pdrv, unsigned char cmd, void* buff); /*!< function to get info about disk and do some misc operations */
  35. } ff_diskio_impl_t;
  36. /**
  37. * Register or unregister diskio driver for given drive number.
  38. *
  39. * When FATFS library calls one of disk_xxx functions for driver number pdrv,
  40. * corresponding function in discio_impl for given pdrv will be called.
  41. *
  42. * @param pdrv drive number
  43. * @param discio_impl pointer to ff_diskio_impl_t structure with diskio functions
  44. * or NULL to unregister and free previously registered drive
  45. */
  46. void ff_diskio_register(BYTE pdrv, const ff_diskio_impl_t* discio_impl);
  47. #define ff_diskio_unregister(pdrv_) ff_diskio_register(pdrv_, NULL)
  48. /**
  49. * Get next available drive number
  50. *
  51. * @param out_pdrv pointer to the byte to set if successful
  52. *
  53. * @return ESP_OK on success
  54. * ESP_ERR_NOT_FOUND if all drives are attached
  55. */
  56. esp_err_t ff_diskio_get_drive(BYTE* out_pdrv);
  57. #ifdef __cplusplus
  58. }
  59. #endif