2 * Derived from github.com/fetisov/emfat/project/StorageMode.c
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
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,
52 (STANDARD_INQUIRY_DATA_LEN
- 5),
54 (USBD_STD_INQUIRY_LENGTH
- 5),
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
)
73 static int8_t STORAGE_GetCapacity(uint8_t lun
, uint32_t *block_num
, uint16_t *block_size
)
75 static int8_t STORAGE_GetCapacity(uint8_t lun
, uint32_t *block_num
, uint32_t *block_size
)
80 *block_num
= emfat
.disk_sectors
;
84 static int8_t STORAGE_IsReady(uint8_t lun
)
90 static int8_t STORAGE_IsWriteProtected(uint8_t lun
)
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
104 emfat_read(&emfat
, buf
, blk_addr
, blk_len
);
109 static int8_t STORAGE_Write(uint8_t lun
,
122 static int8_t STORAGE_GetMaxLun(void)
124 return (STORAGE_LUN_NBR
- 1);
127 #ifdef USE_HAL_DRIVER
130 USBD_STORAGE_cb_TypeDef
132 USBD_MSC_EMFAT_fops
=
137 STORAGE_IsWriteProtected
,
141 (int8_t *)STORAGE_Inquirydata
,