New SPI API supporting DMA
[betaflight.git] / src / main / msc / usbd_storage_emfat.c
blob7d778ec069d0b15cd43792966c0d21bf0e0a7b6c
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"
42 #define STORAGE_LUN_NBR 1
44 static const uint8_t STORAGE_Inquirydata[] =
46 0x00, 0x80, 0x02, 0x02,
47 #ifdef USE_HAL_DRIVER
48 (STANDARD_INQUIRY_DATA_LEN - 5),
49 #else
50 (USBD_STD_INQUIRY_LENGTH - 5),
51 #endif
52 0x00, 0x00, 0x00,
53 'B', 'E', 'T', 'A', 'F', 'L', 'T', ' ', // Manufacturer : 8 bytes
54 'O', 'n', 'b', 'o', 'a', 'r', 'd', ' ', // Product : 16 Bytes
55 'F', 'l', 'a', 's', 'h', ' ', ' ', ' ', //
56 ' ', ' ', ' ' ,' ', // Version : 4 Bytes
59 static int8_t STORAGE_Init(uint8_t lun)
61 UNUSED(lun);
63 LED0_OFF;
65 return 0;
68 #ifdef USE_HAL_DRIVER
69 static int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
70 #else
71 static int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint32_t *block_size)
72 #endif
74 UNUSED(lun);
75 *block_size = 512;
76 *block_num = emfat.disk_sectors;
77 return 0;
80 static int8_t STORAGE_IsReady(uint8_t lun)
82 UNUSED(lun);
83 return 0;
86 static int8_t STORAGE_IsWriteProtected(uint8_t lun)
88 UNUSED(lun);
89 return 1;
92 static int8_t STORAGE_Read(
93 uint8_t lun, // logical unit number
94 uint8_t *buf, // Pointer to the buffer to save data
95 uint32_t blk_addr, // address of 1st block to be read
96 uint16_t blk_len) // nmber of blocks to be read
98 UNUSED(lun);
99 mscSetActive();
100 emfat_read(&emfat, buf, blk_addr, blk_len);
101 return 0;
104 static int8_t STORAGE_Write(uint8_t lun,
105 uint8_t *buf,
106 uint32_t blk_addr,
107 uint16_t blk_len)
109 UNUSED(lun);
110 UNUSED(buf);
111 UNUSED(blk_addr);
112 UNUSED(blk_len);
114 return 1;
117 static int8_t STORAGE_GetMaxLun(void)
119 return (STORAGE_LUN_NBR - 1);
122 #ifdef USE_HAL_DRIVER
123 USBD_StorageTypeDef
124 #else
125 USBD_STORAGE_cb_TypeDef
126 #endif
127 USBD_MSC_EMFAT_fops =
129 STORAGE_Init,
130 STORAGE_GetCapacity,
131 STORAGE_IsReady,
132 STORAGE_IsWriteProtected,
133 STORAGE_Read,
134 STORAGE_Write,
135 STORAGE_GetMaxLun,
136 (int8_t *)STORAGE_Inquirydata,