Fix WS2812 led definition
[inav.git] / src / main / msc / emfat.h
blobada82fb8cf204daa3f846699c7669d9426835c69
1 /*
2 * Derived from
3 * https://github.com/fetisov/emfat/blob/master/project/emfat.c
4 * version: 1.0 (4.01.2015)
5 */
7 /*
8 * The MIT License (MIT)
10 * Copyright (c) 2015 by Sergey Fetisov <fsenok@gmail.com>
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this software and associated documentation files (the "Software"), to deal
14 * in the Software without restriction, including without limitation the rights
15 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 * copies of the Software, and to permit persons to whom the Software is
17 * furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice shall be included in all
20 * copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * SOFTWARE.
31 #pragma once
33 #include <stddef.h>
34 #include <stdint.h>
35 #include <string.h>
36 #include <stdbool.h>
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
42 struct emfat_entry_s;
43 typedef void (*emfat_readcb_t)(uint8_t *dest, int size, uint32_t offset, struct emfat_entry_s *entry);
44 typedef void (*emfat_writecb_t)(const uint8_t *data, int size, uint32_t offset, struct emfat_entry_s *entry);
46 typedef struct emfat_entry_s {
47 const char *name;
48 bool dir;
49 uint8_t attr;
50 int level;
51 uint32_t offset;
52 uint32_t curr_size;
53 uint32_t max_size;
54 long user_data;
55 uint32_t cma_time[3]; /**< create/mod/access time in unix format */
56 emfat_readcb_t readcb;
57 emfat_writecb_t writecb;
58 struct
60 uint32_t first_clust;
61 uint32_t last_clust;
62 uint32_t last_reserved;
63 uint32_t num_subentry;
64 struct emfat_entry_s *top;
65 struct emfat_entry_s *sub;
66 struct emfat_entry_s *next;
67 } priv;
68 } emfat_entry_t;
70 typedef struct emfat_s {
71 uint64_t vol_size;
72 uint32_t disk_sectors;
73 const char *vol_label;
74 struct {
75 uint32_t boot_lba;
76 uint32_t fsinfo_lba;
77 uint32_t fat1_lba;
78 uint32_t fat2_lba;
79 uint32_t root_lba;
80 uint32_t num_clust;
81 uint32_t free_clust;
82 emfat_entry_t *entries;
83 emfat_entry_t *last_entry;
84 int num_entries;
85 } priv;
86 } emfat_t;
88 bool emfat_init(emfat_t *emfat, const char *label, emfat_entry_t *entries);
89 void emfat_read(emfat_t *emfat, uint8_t *data, uint32_t sector, int num_sectors);
90 void emfat_write(emfat_t *emfat, const uint8_t *data, uint32_t sector, int num_sectors);
92 #define EMFAT_ENCODE_CMA_TIME(D,M,Y,h,m,s) \
93 ((((((Y)-1980) << 9) | ((M) << 5) | (D)) << 16) | \
94 (((h) << 11) | ((m) << 5) | (s >> 1)))
96 static inline uint32_t emfat_encode_cma_time(int D, int M, int Y, int h, int m, int s)
98 return EMFAT_ENCODE_CMA_TIME(D,M,Y,h,m,s);
101 uint32_t emfat_cma_time_from_unix(uint32_t unix_time);
103 #define ATTR_READ 0x01
104 #define ATTR_HIDDEN 0x02
105 #define ATTR_SYSTEM 0x04
106 #define ATTR_VOL_LABEL 0x08
107 #define ATTR_DIR 0x10
108 #define ATTR_ARCHIVE 0x20
109 #define ATTR_LONG_FNAME 0x0F
111 #ifdef __cplusplus
113 #endif