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/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,
48 (STANDARD_INQUIRY_DATA_LEN
- 5),
50 (USBD_STD_INQUIRY_LENGTH
- 5),
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
)
69 static int8_t STORAGE_GetCapacity(uint8_t lun
, uint32_t *block_num
, uint16_t *block_size
)
71 static int8_t STORAGE_GetCapacity(uint8_t lun
, uint32_t *block_num
, uint32_t *block_size
)
76 *block_num
= emfat
.disk_sectors
;
80 static int8_t STORAGE_IsReady(uint8_t lun
)
86 static int8_t STORAGE_IsWriteProtected(uint8_t lun
)
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
100 emfat_read(&emfat
, buf
, blk_addr
, blk_len
);
104 static int8_t STORAGE_Write(uint8_t lun
,
117 static int8_t STORAGE_GetMaxLun(void)
119 return (STORAGE_LUN_NBR
- 1);
122 #ifdef USE_HAL_DRIVER
125 USBD_STORAGE_cb_TypeDef
127 USBD_MSC_EMFAT_fops
=
132 STORAGE_IsWriteProtected
,
136 (int8_t *)STORAGE_Inquirydata
,