Remove deprecated CLI name command
[betaflight.git] / src / main / msc / usbd_storage_emfat.c
blobd7cebc5f63c43cf09d4032efaf521fae06abd27b
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 "pg/flash.h"
43 #include "usbd_storage.h"
44 #include "usbd_storage_emfat.h"
45 #include "emfat_file.h"
48 #define STORAGE_LUN_NBR 1
50 static const uint8_t STORAGE_Inquirydata[] =
52 0x00, 0x80, 0x02, 0x02,
53 #ifdef USE_HAL_DRIVER
54 (STANDARD_INQUIRY_DATA_LEN - 5),
55 #else
56 (USBD_STD_INQUIRY_LENGTH - 5),
57 #endif
58 0x00, 0x00, 0x00,
59 'B', 'E', 'T', 'A', 'F', 'L', 'T', ' ', // Manufacturer : 8 bytes
60 'O', 'n', 'b', 'o', 'a', 'r', 'd', ' ', // Product : 16 Bytes
61 'F', 'l', 'a', 's', 'h', ' ', ' ', ' ', //
62 ' ', ' ', ' ' ,' ', // Version : 4 Bytes
65 static int8_t STORAGE_Init(uint8_t lun)
67 UNUSED(lun);
69 LED0_ON;
71 #ifdef USE_FLASHFS
72 #ifdef USE_FLASH_CHIP
73 flashInit(flashConfig());
74 #endif
75 flashfsInit();
76 #endif
77 emfat_init_files();
79 delay(1000);
81 LED0_OFF;
83 return 0;
86 #ifdef USE_HAL_DRIVER
87 static int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
88 #else
89 static int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint32_t *block_size)
90 #endif
92 UNUSED(lun);
93 *block_size = 512;
94 *block_num = emfat.disk_sectors;
95 return 0;
98 static int8_t STORAGE_IsReady(uint8_t lun)
100 UNUSED(lun);
101 return 0;
104 static int8_t STORAGE_IsWriteProtected(uint8_t lun)
106 UNUSED(lun);
107 return 1;
110 static int8_t STORAGE_Read(
111 uint8_t lun, // logical unit number
112 uint8_t *buf, // Pointer to the buffer to save data
113 uint32_t blk_addr, // address of 1st block to be read
114 uint16_t blk_len) // nmber of blocks to be read
116 UNUSED(lun);
117 LED0_ON;
118 emfat_read(&emfat, buf, blk_addr, blk_len);
119 LED0_OFF;
120 return 0;
123 static int8_t STORAGE_Write(uint8_t lun,
124 uint8_t *buf,
125 uint32_t blk_addr,
126 uint16_t blk_len)
128 UNUSED(lun);
129 UNUSED(buf);
130 UNUSED(blk_addr);
131 UNUSED(blk_len);
133 return 1;
136 static int8_t STORAGE_GetMaxLun(void)
138 return (STORAGE_LUN_NBR - 1);
141 #ifdef USE_HAL_DRIVER
142 USBD_StorageTypeDef
143 #else
144 USBD_STORAGE_cb_TypeDef
145 #endif
146 USBD_MSC_EMFAT_fops =
148 STORAGE_Init,
149 STORAGE_GetCapacity,
150 STORAGE_IsReady,
151 STORAGE_IsWriteProtected,
152 STORAGE_Read,
153 STORAGE_Write,
154 STORAGE_GetMaxLun,
155 (int8_t *)STORAGE_Inquirydata,