duplicate emptyline removal (#14027)
[betaflight.git] / src / main / msc / usbd_storage_emfat.c
blob608d5c58b91132f2693a14ae4b2473ebf67736c1
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/usb_msc.h"
38 #include "msc/usbd_storage.h"
39 #include "msc/usbd_storage_emfat.h"
41 #define STORAGE_LUN_NBR 1
43 static const uint8_t STORAGE_Inquirydata[] =
45 0x00, 0x80, 0x02, 0x02,
46 #ifdef USE_HAL_DRIVER
47 (STANDARD_INQUIRY_DATA_LEN - 5),
48 #else
49 (USBD_STD_INQUIRY_LENGTH - 5),
50 #endif
51 0x00, 0x00, 0x00,
52 'B', 'E', 'T', 'A', 'F', 'L', 'T', ' ', // Manufacturer : 8 bytes
53 'O', 'n', 'b', 'o', 'a', 'r', 'd', ' ', // Product : 16 Bytes
54 'F', 'l', 'a', 's', 'h', ' ', ' ', ' ', //
55 ' ', ' ', ' ' ,' ', // Version : 4 Bytes
58 static int8_t STORAGE_Init(uint8_t lun)
60 UNUSED(lun);
62 LED0_OFF;
64 return 0;
67 #ifdef USE_HAL_DRIVER
68 static int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
69 #else
70 static int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint32_t *block_size)
71 #endif
73 UNUSED(lun);
74 *block_size = 512;
75 *block_num = emfat.disk_sectors;
76 return 0;
79 static int8_t STORAGE_IsReady(uint8_t lun)
81 UNUSED(lun);
82 return 0;
85 static int8_t STORAGE_IsWriteProtected(uint8_t lun)
87 UNUSED(lun);
88 return 1;
91 static int8_t STORAGE_Read(
92 uint8_t lun, // logical unit number
93 uint8_t *buf, // Pointer to the buffer to save data
94 uint32_t blk_addr, // address of 1st block to be read
95 uint16_t blk_len) // nmber of blocks to be read
97 UNUSED(lun);
98 mscSetActive();
99 emfat_read(&emfat, buf, blk_addr, blk_len);
100 return 0;
103 static int8_t STORAGE_Write(uint8_t lun,
104 uint8_t *buf,
105 uint32_t blk_addr,
106 uint16_t blk_len)
108 UNUSED(lun);
109 UNUSED(buf);
110 UNUSED(blk_addr);
111 UNUSED(blk_len);
113 return 1;
116 static int8_t STORAGE_GetMaxLun(void)
118 return (STORAGE_LUN_NBR - 1);
121 #ifdef USE_HAL_DRIVER
122 USBD_StorageTypeDef
123 #else
124 USBD_STORAGE_cb_TypeDef
125 #endif
126 USBD_MSC_EMFAT_fops =
128 STORAGE_Init,
129 STORAGE_GetCapacity,
130 STORAGE_IsReady,
131 STORAGE_IsWriteProtected,
132 STORAGE_Read,
133 STORAGE_Write,
134 STORAGE_GetMaxLun,
135 (int8_t *)STORAGE_Inquirydata,