feat(fw): Only show SD card in USB storage mode (#3045)

* Only attach SD card in USB storage mode

* Added compile time option FWDRIVE (default OFF) to enable attaching also the firmware drive via USB, when attached in mass storage mode.

* Re-trigger GitHub Actions

* chore: Trailing whitespace cleanup
This commit is contained in:
Risto
2023-01-26 14:39:31 +10:00
committed by GitHub
parent d952333037
commit 5acaa79c1c
3 changed files with 88 additions and 69 deletions
+5
View File
@@ -59,6 +59,7 @@ option(TBS_RELEASE "Used to build TBS released firmware" OFF)
option(IMRC_RELEASE "Used to build IMRC released firmware" OFF) option(IMRC_RELEASE "Used to build IMRC released firmware" OFF)
option(HARDWARE_TRAINER_MULTI "Allow multi trainer" OFF) option(HARDWARE_TRAINER_MULTI "Allow multi trainer" OFF)
option(BOOTLOADER "Include Bootloader" ON) option(BOOTLOADER "Include Bootloader" ON)
option(FWDRIVE "Attach also firmware drive with USB" OFF)
# since we reset all default CMAKE compiler flags for firmware builds, provide an alternate way for user to specify additional flags. # since we reset all default CMAKE compiler flags for firmware builds, provide an alternate way for user to specify additional flags.
set(FIRMWARE_C_FLAGS "" CACHE STRING "Additional flags for firmware target c compiler (note: all CMAKE_C_FLAGS[_*] are ignored for firmware/bootloader).") set(FIRMWARE_C_FLAGS "" CACHE STRING "Additional flags for firmware target c compiler (note: all CMAKE_C_FLAGS[_*] are ignored for firmware/bootloader).")
@@ -453,6 +454,10 @@ else()
endif() endif()
add_definitions(-DDEFAULT_TEMPLATE_SETUP=${DEFAULT_TEMPLATE_SETUP}) add_definitions(-DDEFAULT_TEMPLATE_SETUP=${DEFAULT_TEMPLATE_SETUP})
if(FWDRIVE)
add_definitions(-DFWDRIVE)
endif()
set(SRC set(SRC
${SRC} ${SRC}
opentx.cpp opentx.cpp
@@ -58,7 +58,7 @@
#define USBD_VID_PID_CODES 0x1209 // https://pid.codes #define USBD_VID_PID_CODES 0x1209 // https://pid.codes
#define USBD_LANGID_STRING 0x409 #define USBD_LANGID_STRING 0x409
#define USBD_MANUFACTURER_STRING "OpenTX" #define USBD_MANUFACTURER_STRING "EdgeTX"
#define USBD_SERIALNUMBER_FS_STRING "00000000001B" #define USBD_SERIALNUMBER_FS_STRING "00000000001B"
#if defined(BOOT) #if defined(BOOT)
@@ -44,12 +44,14 @@ extern "C" {
enum MassstorageLuns { enum MassstorageLuns {
STORAGE_SDCARD_LUN, STORAGE_SDCARD_LUN,
#if defined(FWDRIVE)
STORAGE_EEPROM_LUN, STORAGE_EEPROM_LUN,
#endif
STORAGE_LUN_NBR STORAGE_LUN_NBR
}; };
/* USB Mass storage Standard Inquiry Data */ /* USB Mass storage Standard Inquiry Data */
const unsigned char STORAGE_Inquirydata[] = { //36 const unsigned char STORAGE_Inquirydata[] = {
/* LUN 0 */ /* LUN 0 */
0x00, 0x00,
0x80, 0x80,
@@ -63,6 +65,7 @@ const unsigned char STORAGE_Inquirydata[] = { //36
USB_PRODUCT, /* Product : 16 Bytes */ USB_PRODUCT, /* Product : 16 Bytes */
'R', 'a', 'd', 'i', 'o', ' ', ' ', ' ', 'R', 'a', 'd', 'i', 'o', ' ', ' ', ' ',
'1', '.', '0', '0', /* Version : 4 Bytes */ '1', '.', '0', '0', /* Version : 4 Bytes */
#if defined(FWDRIVE)
/* LUN 1 */ /* LUN 1 */
0x00, 0x00,
0x80, 0x80,
@@ -76,12 +79,15 @@ const unsigned char STORAGE_Inquirydata[] = { //36
USB_PRODUCT, /* Product : 16 Bytes */ USB_PRODUCT, /* Product : 16 Bytes */
'R', 'a', 'd', 'i', 'o', ' ', ' ', ' ', 'R', 'a', 'd', 'i', 'o', ' ', ' ', ' ',
'1', '.', '0' ,'0', /* Version : 4 Bytes */ '1', '.', '0' ,'0', /* Version : 4 Bytes */
#endif
}; };
#if defined(FWDRIVE)
#define RESERVED_SECTORS (1 /*Boot*/ + 2 /*Fat table */ + 1 /*Root dir*/ + 8 /* one cluster for firmware.txt */) #define RESERVED_SECTORS (1 /*Boot*/ + 2 /*Fat table */ + 1 /*Root dir*/ + 8 /* one cluster for firmware.txt */)
int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count); int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count);
int32_t fat12Read(uint8_t * buffer, uint16_t sector, uint16_t count ); int32_t fat12Read(uint8_t * buffer, uint16_t sector, uint16_t count );
#endif
int8_t STORAGE_Init (uint8_t lun); int8_t STORAGE_Init (uint8_t lun);
@@ -105,7 +111,7 @@ int8_t STORAGE_Write (uint8_t lun,
int8_t STORAGE_GetMaxLun (void); int8_t STORAGE_GetMaxLun (void);
const USBD_STORAGE_cb_TypeDef USBD_MICRO_SDIO_fops = // modified my OpenTX const USBD_STORAGE_cb_TypeDef USBD_MICRO_SDIO_fops =
{ {
STORAGE_Init, STORAGE_Init,
STORAGE_GetCapacity, STORAGE_GetCapacity,
@@ -117,7 +123,7 @@ const USBD_STORAGE_cb_TypeDef USBD_MICRO_SDIO_fops = // modified my OpenTX
(int8_t *)STORAGE_Inquirydata, (int8_t *)STORAGE_Inquirydata,
}; };
const USBD_STORAGE_cb_TypeDef * const USBD_STORAGE_fops = &USBD_MICRO_SDIO_fops; // modified my OpenTX const USBD_STORAGE_cb_TypeDef * const USBD_STORAGE_fops = &USBD_MICRO_SDIO_fops;
#if defined(__cplusplus) && !defined(SIMU) #if defined(__cplusplus) && !defined(SIMU)
} }
@@ -149,6 +155,7 @@ int8_t STORAGE_Init (uint8_t lun)
*/ */
int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_size) int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_size)
{ {
#if defined(FWDRIVE)
if (lun == STORAGE_EEPROM_LUN) { if (lun == STORAGE_EEPROM_LUN) {
*block_size = BLOCK_SIZE; *block_size = BLOCK_SIZE;
#if defined(EEPROM) #if defined(EEPROM)
@@ -158,6 +165,7 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si
#endif #endif
return 0; return 0;
} }
#endif
if (!SD_CARD_PRESENT()) if (!SD_CARD_PRESENT())
return -1; return -1;
@@ -182,7 +190,9 @@ uint8_t lunReady[STORAGE_LUN_NBR];
void usbInitLUNs() void usbInitLUNs()
{ {
lunReady[STORAGE_SDCARD_LUN] = 1; lunReady[STORAGE_SDCARD_LUN] = 1;
#if defined(FWDRIVE)
lunReady[STORAGE_EEPROM_LUN] = 1; lunReady[STORAGE_EEPROM_LUN] = 1;
#endif
} }
/** /**
@@ -192,12 +202,11 @@ void usbInitLUNs()
*/ */
int8_t STORAGE_IsReady (uint8_t lun) int8_t STORAGE_IsReady (uint8_t lun)
{ {
#if defined(EEPROM) #if defined(FWDRIVE) && defined(EEPROM)
if (lun == STORAGE_EEPROM_LUN) { if (lun == STORAGE_EEPROM_LUN) {
return (lunReady[STORAGE_EEPROM_LUN] != 0) ? 0 : -1; return (lunReady[STORAGE_EEPROM_LUN] != 0) ? 0 : -1;
} }
#endif #endif
return (lunReady[STORAGE_SDCARD_LUN] != 0 && SD_CARD_PRESENT()) ? 0 : -1; return (lunReady[STORAGE_SDCARD_LUN] != 0 && SD_CARD_PRESENT()) ? 0 : -1;
} }
@@ -227,9 +236,11 @@ int8_t STORAGE_Read (uint8_t lun,
{ {
WATCHDOG_SUSPEND(100/*1s*/); WATCHDOG_SUSPEND(100/*1s*/);
#if defined(FWDRIVE)
if (lun == STORAGE_EEPROM_LUN) { if (lun == STORAGE_EEPROM_LUN) {
return (fat12Read(buf, blk_addr, blk_len) == 0) ? 0 : -1; return (fat12Read(buf, blk_addr, blk_len) == 0) ? 0 : -1;
} }
#endif
// read without cache // read without cache
return (__disk_read(0, buf, blk_addr, blk_len) == RES_OK) ? 0 : -1; return (__disk_read(0, buf, blk_addr, blk_len) == RES_OK) ? 0 : -1;
@@ -250,9 +261,11 @@ int8_t STORAGE_Write (uint8_t lun,
{ {
WATCHDOG_SUSPEND(100/*1s*/); WATCHDOG_SUSPEND(100/*1s*/);
#if defined(FWDRIVE)
if (lun == STORAGE_EEPROM_LUN) { if (lun == STORAGE_EEPROM_LUN) {
return (fat12Write(buf, blk_addr, blk_len) == 0) ? 0 : -1; return (fat12Write(buf, blk_addr, blk_len) == 0) ? 0 : -1;
} }
#endif
// write without cache // write without cache
return (__disk_write(0, buf, blk_addr, blk_len) == RES_OK) ? 0 : -1; return (__disk_write(0, buf, blk_addr, blk_len) == RES_OK) ? 0 : -1;
@@ -269,7 +282,7 @@ int8_t STORAGE_GetMaxLun (void)
return STORAGE_LUN_NBR - 1; return STORAGE_LUN_NBR - 1;
} }
#if defined(FWDRIVE)
/* Firmware.txt */ /* Firmware.txt */
const char firmware_txt[] = const char firmware_txt[] =
#if defined(BOOT) #if defined(BOOT)
@@ -622,3 +635,4 @@ int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count)
#endif #endif
return 0 ; return 0 ;
} }
#endif