lv_ufs.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /**
  2. * @file lv_ufs.h
  3. * Implementation of RAM file system which do NOT support directories.
  4. * The API is compatible with the lv_fs_int module.
  5. */
  6. #ifndef LV_UFS_H
  7. #define LV_UFS_H
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /*********************
  12. * INCLUDES
  13. *********************/
  14. #include "../../lv_conf.h"
  15. #if USE_LV_FILESYSTEM
  16. #include <stdbool.h>
  17. #include "lv_fs.h"
  18. #include "lv_mem.h"
  19. /*********************
  20. * DEFINES
  21. *********************/
  22. #define UFS_LETTER 'U'
  23. /**********************
  24. * TYPEDEFS
  25. **********************/
  26. /*Description of a file entry */
  27. typedef struct
  28. {
  29. char * fn_d;
  30. void * data_d;
  31. uint32_t size; /*Data length in bytes*/
  32. uint16_t oc; /*Open Count*/
  33. uint8_t const_data :1;
  34. }lv_ufs_ent_t;
  35. /*File descriptor, used to handle opening an entry more times simultaneously
  36. Contains unique informations about the specific opening*/
  37. typedef struct
  38. {
  39. lv_ufs_ent_t* ent; /*Pointer to the entry*/
  40. uint32_t rwp; /*Read Write Pointer*/
  41. uint8_t ar :1; /*1: Access for read is enabled */
  42. uint8_t aw :1; /*1: Access for write is enabled */
  43. }lv_ufs_file_t;
  44. /* Read directory descriptor.
  45. * It is used to to iterate through the entries in a directory*/
  46. typedef struct
  47. {
  48. lv_ufs_ent_t * last_ent;
  49. }lv_ufs_dir_t;
  50. /**********************
  51. * GLOBAL PROTOTYPES
  52. **********************/
  53. /**
  54. * Create a driver for ufs and initialize it.
  55. */
  56. void lv_ufs_init(void);
  57. /**
  58. * Give the state of the ufs
  59. * @return true if ufs is initialized and can be used else false
  60. */
  61. bool lv_ufs_ready(void);
  62. /**
  63. * Open a file in ufs
  64. * @param file_p pointer to a lv_ufs_file_t variable
  65. * @param fn name of the file. There are no directories so e.g. "myfile.txt"
  66. * @param mode element of 'fs_mode_t' enum or its 'OR' connection (e.g. FS_MODE_WR | FS_MODE_RD)
  67. * @return LV_FS_RES_OK: no error, the file is opened
  68. * any error from lv_fs_res_t enum
  69. */
  70. lv_fs_res_t lv_ufs_open (void * file_p, const char * fn, lv_fs_mode_t mode);
  71. /**
  72. * Create a file with a constant data
  73. * @param fn name of the file (directories are not supported)
  74. * @param const_p pointer to a constant data
  75. * @param len length of the data pointed by 'const_p' in bytes
  76. * @return LV_FS_RES_OK: no error, the file is read
  77. * any error from lv_fs_res_t enum
  78. */
  79. lv_fs_res_t lv_ufs_create_const(const char * fn, const void * const_p, uint32_t len);
  80. /**
  81. * Close an opened file
  82. * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
  83. * @return LV_FS_RES_OK: no error, the file is read
  84. * any error from lv_fs_res_t enum
  85. */
  86. lv_fs_res_t lv_ufs_close (void * file_p);
  87. /**
  88. * Remove a file. The file can not be opened.
  89. * @param fn '\0' terminated string
  90. * @return LV_FS_RES_OK: no error, the file is removed
  91. * LV_FS_RES_DENIED: the file was opened, remove failed
  92. */
  93. lv_fs_res_t lv_ufs_remove(const char * fn);
  94. /**
  95. * Read data from an opened file
  96. * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
  97. * @param buf pointer to a memory block where to store the read data
  98. * @param btr number of Bytes To Read
  99. * @param br the real number of read bytes (Byte Read)
  100. * @return LV_FS_RES_OK: no error, the file is read
  101. * any error from lv_fs_res_t enum
  102. */
  103. lv_fs_res_t lv_ufs_read (void * file_p, void * buf, uint32_t btr, uint32_t * br);
  104. /**
  105. * Write data to an opened file
  106. * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
  107. * @param buf pointer to a memory block which content will be written
  108. * @param btw the number Bytes To Write
  109. * @param bw The real number of written bytes (Byte Written)
  110. * @return LV_FS_RES_OK: no error, the file is read
  111. * any error from lv_fs_res_t enum
  112. */
  113. lv_fs_res_t lv_ufs_write (void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
  114. /**
  115. * Set the read write pointer. Also expand the file size if necessary.
  116. * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
  117. * @param pos the new position of read write pointer
  118. * @return LV_FS_RES_OK: no error, the file is read
  119. * any error from lv_fs_res_t enum
  120. */
  121. lv_fs_res_t lv_ufs_seek (void * file_p, uint32_t pos);
  122. /**
  123. * Give the position of the read write pointer
  124. * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
  125. * @param pos_p pointer to to store the result
  126. * @return LV_FS_RES_OK: no error, the file is read
  127. * any error from lv_fs_res_t enum
  128. */
  129. lv_fs_res_t lv_ufs_tell (void * file_p, uint32_t * pos_p);
  130. /**
  131. * Truncate the file size to the current position of the read write pointer
  132. * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
  133. * @return LV_FS_RES_OK: no error, the file is read
  134. * any error from lv_fs_res_t enum
  135. */
  136. lv_fs_res_t lv_ufs_trunc (void * file_p);
  137. /**
  138. * Give the size of the file in bytes
  139. * @param file_p file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
  140. * @param size_p pointer to store the size
  141. * @return LV_FS_RES_OK: no error, the file is read
  142. * any error from lv_fs_res_t enum
  143. */
  144. lv_fs_res_t lv_ufs_size (void * file_p, uint32_t * size_p);
  145. /**
  146. * Initialize a lv_ufs_read_dir_t variable to directory reading
  147. * @param rddir_p pointer to a 'ufs_read_dir_t' variable
  148. * @param path uFS doesn't support folders so it has to be ""
  149. * @return LV_FS_RES_OK or any error from lv_fs_res_t enum
  150. */
  151. lv_fs_res_t lv_ufs_dir_open(void * rddir_p, const char * path);
  152. /**
  153. * Read the next file name
  154. * @param dir_p pointer to an initialized 'ufs_read_dir_t' variable
  155. * @param fn pointer to buffer to sore the file name
  156. * @return LV_FS_RES_OK or any error from lv_fs_res_t enum
  157. */
  158. lv_fs_res_t lv_ufs_dir_read(void * dir_p, char * fn);
  159. /**
  160. * Close the directory reading
  161. * @param rddir_p pointer to an initialized 'ufs_read_dir_t' variable
  162. * @return LV_FS_RES_OK or any error from lv_fs_res_t enum
  163. */
  164. lv_fs_res_t lv_ufs_dir_close(void * rddir_p);
  165. /**
  166. * Give the size of a drive
  167. * @param total_p pointer to store the total size [kB]
  168. * @param free_p pointer to store the free site [kB]
  169. * @return LV_FS_RES_OK or any error from 'fs_res_t'
  170. */
  171. lv_fs_res_t lv_ufs_free (uint32_t * total_p, uint32_t * free_p);
  172. /**********************
  173. * MACROS
  174. **********************/
  175. #endif /*USE_LV_FILESYSTEM*/
  176. #ifdef __cplusplus
  177. } /* extern "C" */
  178. #endif
  179. #endif