Fix WS2812 led definition
[inav.git] / src / main / msc / usbd_storage_emfat.c
blob070df79f8300f94e9ee2d2dc44bbc1a35a38b79d
1 /*
2 * Derived from github.com/fetisov/emfat/project/StorageMode.c
3 */
5 /*
6 * The MIT License (MIT)
8 * Copyright (c) 2015 by Sergey Fetisov <fsenok@gmail.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in all
18 * copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
29 #include <stdbool.h>
31 #include "platform.h"
33 #include "common/utils.h"
35 #include "drivers/light_led.h"
36 #include "drivers/time.h"
37 #include "drivers/flash.h"
39 #include "io/flashfs.h"
41 #include "usbd_storage.h"
42 #include "usbd_storage_emfat.h"
43 #include "emfat_file.h"
46 #define STORAGE_LUN_NBR 1
48 static const uint8_t STORAGE_Inquirydata[] =
50 0x00, 0x80, 0x02, 0x02,
51 #ifdef USE_HAL_DRIVER
52 (STANDARD_INQUIRY_DATA_LEN - 5),
53 #else
54 (USBD_STD_INQUIRY_LENGTH - 5),
55 #endif
56 0x00, 0x00, 0x00,
57 'I', 'N', 'A', 'V', ' ', 'F', 'C', ' ', // Manufacturer : 8 bytes
58 'O', 'n', 'b', 'o', 'a', 'r', 'd', ' ', // Product : 16 Bytes
59 'F', 'l', 'a', 's', 'h', ' ', ' ', ' ', //
60 ' ', ' ', ' ' ,' ', // Version : 4 Bytes
63 static int8_t STORAGE_Init(uint8_t lun)
65 UNUSED(lun);
67 LED0_OFF;
69 return 0;
72 #ifdef USE_HAL_DRIVER
73 static int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
74 #else
75 static int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint32_t *block_size)
76 #endif
78 UNUSED(lun);
79 *block_size = 512;
80 *block_num = emfat.disk_sectors;
81 return 0;
84 static int8_t STORAGE_IsReady(uint8_t lun)
86 UNUSED(lun);
87 return 0;
90 static int8_t STORAGE_IsWriteProtected(uint8_t lun)
92 UNUSED(lun);
93 return 1;
96 static int8_t STORAGE_Read(
97 uint8_t lun, // logical unit number
98 uint8_t *buf, // Pointer to the buffer to save data
99 uint32_t blk_addr, // address of 1st block to be read
100 uint16_t blk_len) // nmber of blocks to be read
102 UNUSED(lun);
103 LED0_ON;
104 emfat_read(&emfat, buf, blk_addr, blk_len);
105 LED0_OFF;
106 return 0;
109 static int8_t STORAGE_Write(uint8_t lun,
110 uint8_t *buf,
111 uint32_t blk_addr,
112 uint16_t blk_len)
114 UNUSED(lun);
115 UNUSED(buf);
116 UNUSED(blk_addr);
117 UNUSED(blk_len);
119 return 1;
122 static int8_t STORAGE_GetMaxLun(void)
124 return (STORAGE_LUN_NBR - 1);
127 #ifdef USE_HAL_DRIVER
128 USBD_StorageTypeDef
129 #else
130 USBD_STORAGE_cb_TypeDef
131 #endif
132 USBD_MSC_EMFAT_fops =
134 STORAGE_Init,
135 STORAGE_GetCapacity,
136 STORAGE_IsReady,
137 STORAGE_IsWriteProtected,
138 STORAGE_Read,
139 STORAGE_Write,
140 STORAGE_GetMaxLun,
141 (int8_t *)STORAGE_Inquirydata,