acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
lv_port_fs_template.c (7867B)
1 /** 2 * @file lv_port_fs_templ.c 3 * 4 */ 5 6 /*Copy this file as "lv_port_fs.c" and set this value to "1" to enable content*/ 7 #if 0 8 9 /********************* 10 * INCLUDES 11 *********************/ 12 #include "lv_port_fs_template.h" 13 #include "../../lvgl.h" 14 15 /********************* 16 * DEFINES 17 *********************/ 18 19 /********************** 20 * TYPEDEFS 21 **********************/ 22 23 /********************** 24 * STATIC PROTOTYPES 25 **********************/ 26 static void fs_init(void); 27 28 static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode); 29 static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p); 30 static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br); 31 static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw); 32 static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t whence); 33 static lv_fs_res_t fs_size(lv_fs_drv_t * drv, void * file_p, uint32_t * size_p); 34 static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p); 35 36 static void * fs_dir_open(lv_fs_drv_t * drv, const char * path); 37 static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * rddir_p, char * fn); 38 static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * rddir_p); 39 40 /********************** 41 * STATIC VARIABLES 42 **********************/ 43 44 /********************** 45 * GLOBAL PROTOTYPES 46 **********************/ 47 48 /********************** 49 * MACROS 50 **********************/ 51 52 /********************** 53 * GLOBAL FUNCTIONS 54 **********************/ 55 56 void lv_port_fs_init(void) 57 { 58 /*---------------------------------------------------- 59 * Initialize your storage device and File System 60 * -------------------------------------------------*/ 61 fs_init(); 62 63 /*--------------------------------------------------- 64 * Register the file system interface in LVGL 65 *--------------------------------------------------*/ 66 67 /*Add a simple drive to open images*/ 68 static lv_fs_drv_t fs_drv; 69 lv_fs_drv_init(&fs_drv); 70 71 /*Set up fields...*/ 72 fs_drv.letter = 'P'; 73 fs_drv.open_cb = fs_open; 74 fs_drv.close_cb = fs_close; 75 fs_drv.read_cb = fs_read; 76 fs_drv.write_cb = fs_write; 77 fs_drv.seek_cb = fs_seek; 78 fs_drv.tell_cb = fs_tell; 79 80 fs_drv.dir_close_cb = fs_dir_close; 81 fs_drv.dir_open_cb = fs_dir_open; 82 fs_drv.dir_read_cb = fs_dir_read; 83 84 lv_fs_drv_register(&fs_drv); 85 } 86 87 /********************** 88 * STATIC FUNCTIONS 89 **********************/ 90 91 /*Initialize your Storage device and File system.*/ 92 static void fs_init(void) 93 { 94 /*E.g. for FatFS initialize the SD card and FatFS itself*/ 95 96 /*You code here*/ 97 } 98 99 /** 100 * Open a file 101 * @param drv pointer to a driver where this function belongs 102 * @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt) 103 * @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR 104 * @return a file descriptor or NULL on error 105 */ 106 static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode) 107 { 108 lv_fs_res_t res = LV_FS_RES_NOT_IMP; 109 110 void * f = NULL; 111 112 if(mode == LV_FS_MODE_WR) { 113 /*Open a file for write*/ 114 f = ... /*Add your code here*/ 115 } 116 else if(mode == LV_FS_MODE_RD) { 117 /*Open a file for read*/ 118 f = ... /*Add your code here*/ 119 } 120 else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) { 121 /*Open a file for read and write*/ 122 f = ... /*Add your code here*/ 123 } 124 125 return f; 126 } 127 128 /** 129 * Close an opened file 130 * @param drv pointer to a driver where this function belongs 131 * @param file_p pointer to a file_t variable. (opened with fs_open) 132 * @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum 133 */ 134 static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p) 135 { 136 lv_fs_res_t res = LV_FS_RES_NOT_IMP; 137 138 /*Add your code here*/ 139 140 return res; 141 } 142 143 /** 144 * Read data from an opened file 145 * @param drv pointer to a driver where this function belongs 146 * @param file_p pointer to a file_t variable. 147 * @param buf pointer to a memory block where to store the read data 148 * @param btr number of Bytes To Read 149 * @param br the real number of read bytes (Byte Read) 150 * @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum 151 */ 152 static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br) 153 { 154 lv_fs_res_t res = LV_FS_RES_NOT_IMP; 155 156 /*Add your code here*/ 157 158 return res; 159 } 160 161 /** 162 * Write into a file 163 * @param drv pointer to a driver where this function belongs 164 * @param file_p pointer to a file_t variable 165 * @param buf pointer to a buffer with the bytes to write 166 * @param btw Bytes To Write 167 * @param bw the number of real written bytes (Bytes Written). NULL if unused. 168 * @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum 169 */ 170 static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw) 171 { 172 lv_fs_res_t res = LV_FS_RES_NOT_IMP; 173 174 /*Add your code here*/ 175 176 return res; 177 } 178 179 /** 180 * Set the read write pointer. Also expand the file size if necessary. 181 * @param drv pointer to a driver where this function belongs 182 * @param file_p pointer to a file_t variable. (opened with fs_open ) 183 * @param pos the new position of read write pointer 184 * @param whence tells from where to interpret the `pos`. See @lv_fs_whence_t 185 * @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum 186 */ 187 static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t whence) 188 { 189 lv_fs_res_t res = LV_FS_RES_NOT_IMP; 190 191 /*Add your code here*/ 192 193 return res; 194 } 195 /** 196 * Give the position of the read write pointer 197 * @param drv pointer to a driver where this function belongs 198 * @param file_p pointer to a file_t variable. 199 * @param pos_p pointer to to store the result 200 * @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum 201 */ 202 static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p) 203 { 204 lv_fs_res_t res = LV_FS_RES_NOT_IMP; 205 206 /*Add your code here*/ 207 208 return res; 209 } 210 211 /** 212 * Initialize a 'lv_fs_dir_t' variable for directory reading 213 * @param drv pointer to a driver where this function belongs 214 * @param path path to a directory 215 * @return pointer to the directory read descriptor or NULL on error 216 */ 217 static void * fs_dir_open(lv_fs_drv_t * drv, const char * path) 218 { 219 void * dir = NULL; 220 /*Add your code here*/ 221 dir = ... /*Add your code here*/ 222 return dir; 223 } 224 225 /** 226 * Read the next filename form a directory. 227 * The name of the directories will begin with '/' 228 * @param drv pointer to a driver where this function belongs 229 * @param rddir_p pointer to an initialized 'lv_fs_dir_t' variable 230 * @param fn pointer to a buffer to store the filename 231 * @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum 232 */ 233 static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * rddir_p, char * fn) 234 { 235 lv_fs_res_t res = LV_FS_RES_NOT_IMP; 236 237 /*Add your code here*/ 238 239 return res; 240 } 241 242 /** 243 * Close the directory reading 244 * @param drv pointer to a driver where this function belongs 245 * @param rddir_p pointer to an initialized 'lv_fs_dir_t' variable 246 * @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum 247 */ 248 static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * rddir_p) 249 { 250 lv_fs_res_t res = LV_FS_RES_NOT_IMP; 251 252 /*Add your code here*/ 253 254 return res; 255 } 256 257 #else /*Enable this file at the top*/ 258 259 /*This dummy typedef exists purely to silence -Wpedantic.*/ 260 typedef int keep_pedantic_happy; 261 #endif