diff --git a/lib/ZuluSCSI_platform_RP2040/msc_device.c b/lib/ZuluSCSI_platform_RP2040/msc_device.c index b51ac510..aff133bd 100644 --- a/lib/ZuluSCSI_platform_RP2040/msc_device.c +++ b/lib/ZuluSCSI_platform_RP2040/msc_device.c @@ -23,7 +23,7 @@ * * This file is part of the TinyUSB stack. */ -#ifdef PLATFORM_CARDREADER +#ifdef PLATFORM_MASS_STORAGE #include "tusb_option.h" @@ -951,4 +951,4 @@ static void proc_write10_new_data(uint8_t rhport, mscd_interface_t* p_msc, uint3 } #endif -#endif // PLATFORM_CARDREADER \ No newline at end of file +#endif // PLATFORM_MASS_STORAGE \ No newline at end of file diff --git a/lib/ZuluSCSI_platform_RP2040/rp_msc_reader.cpp b/lib/ZuluSCSI_platform_RP2040/rp_msc_reader.cpp index 9b964d79..f7d08842 100644 --- a/lib/ZuluSCSI_platform_RP2040/rp_msc_reader.cpp +++ b/lib/ZuluSCSI_platform_RP2040/rp_msc_reader.cpp @@ -1,5 +1,25 @@ -/* TODO - Header. By ZZJ. */ -#ifdef PLATFORM_CARDREADER +/** + * Copyright (c) 2023 zigzagjoe + * + * ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version.  + * + * https://www.gnu.org/licenses/gpl-3.0.html + * ---- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version.  + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details.  + * + * You should have received a copy of the GNU General Public License + * along with this program.  If not, see . +**/ + +#ifdef PLATFORM_MASS_STORAGE #include #include @@ -56,7 +76,7 @@ volatile bool unitReady = false; // returns true if card reader mode should be entered // this probably become part of zuluscsi proper, if this code is upstreamed -bool shouldEnterReader() { +bool shouldStartMassStorage() { #ifdef ZULUSCSI_PICO // check if we're USB powered, if not, exit immediately // pin on the wireless module, see https://github.com/earlephilhower/arduino-pico/discussions/835 @@ -78,7 +98,7 @@ bool shouldEnterReader() { // card reader operation loop // assumption that SD card was enumerated and is working -void runCardReader() { +void startMassStorage() { // blink twice to indicate entering card reader mode. LED_ON(); @@ -89,7 +109,7 @@ void runCardReader() { delay(50); LED_OFF(); - logmsg("SD card reader mode entered."); + logmsg("SD card exposed as a mass storage device."); logmsg("USB MSC buffer size: ", CFG_TUD_MSC_EP_BUFSIZE); // MSC is ready for read/write @@ -120,7 +140,7 @@ void runCardReader() { delay(30); } - logmsg("Card ejected, leaving cardreader mode."); + logmsg("Mass storage device ejected, booting ZuluSCSI as normal."); // blink twice to indicate we are leaving reader mode LED_OFF(); @@ -292,4 +312,4 @@ extern "C" void tud_msc_write10_complete_cb(uint8_t lun) { SD.card()->syncDevice(); } -#endif // PLATFORM_CARDREADER \ No newline at end of file +#endif // PLATFORM_MASS_STORAGE \ No newline at end of file diff --git a/lib/ZuluSCSI_platform_RP2040/rp_msc_reader.h b/lib/ZuluSCSI_platform_RP2040/rp_msc_reader.h index ab063f79..66ae95ec 100644 --- a/lib/ZuluSCSI_platform_RP2040/rp_msc_reader.h +++ b/lib/ZuluSCSI_platform_RP2040/rp_msc_reader.h @@ -1,16 +1,35 @@ -/* TODO - Header. By ZZJ. */ -#ifdef PLATFORM_CARDREADER +/** + * Copyright (c) 2023 zigzagjoe + * + * ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version.  + * + * https://www.gnu.org/licenses/gpl-3.0.html + * ---- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version.  + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details.  + * + * You should have received a copy of the GNU General Public License + * along with this program.  If not, see . +**/ +#ifdef PLATFORM_MASS_STORAGE #ifndef RP_MSC_READER_H #define RP_MSC_READER_H // wait up to this long during init sequence for USB enumeration to enter card reader #define CR_ENUM_TIMEOUT 1000 -// true if we should enter cardreader mode -bool shouldEnterReader(); +// true if we should start the mass storage device mode +bool shouldStartMassStorage(); -// run cardreader mode. does not return currently -void runCardReader(); +// exposed the SD card as a mass storage device. does not return currently +void startMassStorage(); #endif #endif \ No newline at end of file diff --git a/lib/ZuluSCSI_platform_RP2040/tusb_config.h b/lib/ZuluSCSI_platform_RP2040/tusb_config.h index d5e04741..a93c788f 100644 --- a/lib/ZuluSCSI_platform_RP2040/tusb_config.h +++ b/lib/ZuluSCSI_platform_RP2040/tusb_config.h @@ -81,7 +81,7 @@ #define CFG_TUD_CDC_EP_BUFSIZE (64) -#ifndef PLATFORM_CARDREADER +#ifndef PLATFORM_MASS_STORAGE // standard value. #define CFG_TUD_MSC_EP_BUFSIZE (64) #else diff --git a/platformio.ini b/platformio.ini index d8d5a997..7e4962e7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -167,7 +167,7 @@ build_flags = -DCYW43_LWIP=0 -DCYW43_USE_OTP_MAC=0 ; -DPIO_FRAMEWORK_ARDUINO_NO_USB - -DPLATFORM_CARDREADER + -DPLATFORM_MASS_STORAGE ; Variant of RP2040 platform, based on Raspberry Pico board and a carrier PCB ; Part of the ZuluSCSI_RP2040 platform, but with different pins. @@ -234,7 +234,7 @@ build_flags = -DCYW43_LWIP=0 -DCYW43_USE_OTP_MAC=0 ; -DPIO_FRAMEWORK_ARDUINO_NO_USB - -DPLATFORM_CARDREADER + -DPLATFORM_MASS_STORAGE ; Variant of RP2040 platform, based on Raspberry Pico board and a carrier PCB ; Differs in pinout from ZuluSCSI_RP2040 platform, but shares most of the code. diff --git a/src/ZuluSCSI.cpp b/src/ZuluSCSI.cpp index 6771a9c5..3a20d01d 100644 --- a/src/ZuluSCSI.cpp +++ b/src/ZuluSCSI.cpp @@ -9,6 +9,7 @@ * * This work incorporates work by following * Copyright (c) 2023 joshua stein + * Copyright (c) 2023 zigzagjoe * * This file is free software: you may copy, redistribute and/or modify it * under the terms of the GNU General Public License as published by the @@ -751,19 +752,6 @@ extern "C" void zuluscsi_setup(void) ini_gets("SCSI", "System", "", presetName, sizeof(presetName), CONFIGFILE); scsi_system_settings_t *cfg = g_scsi_settings.initSystem(presetName); - #ifdef PLATFORM_CARDREADER - if (g_scsi_settings.getSystem()->enableUSBMassStorage) - { - // right now, we initialize early to allow config file edits to take effect immediately on eject - // perform checks (USB power, have we been enumerated, etc?) and waits up to a second for enumeration - if (shouldEnterReader()) - { - logmsg("SD Card opened as a mass storage device"); - runCardReader(); - } - } - #endif - int boot_delay_ms = cfg->initPreDelay; if (boot_delay_ms > 0) { @@ -802,6 +790,23 @@ extern "C" void zuluscsi_main_loop(void) static uint32_t sd_card_check_time = 0; static uint32_t last_request_time = 0; + #ifdef PLATFORM_MASS_STORAGE + static bool check_mass_storage = true; + if (check_mass_storage && g_scsi_settings.getSystem()->enableUSBMassStorage) + { + check_mass_storage = false; + // right now, we initialize early to allow config file edits to take effect immediately on eject + // perform checks (USB power, have we been enumerated, etc?) and waits up to a second for enumeration + if (shouldStartMassStorage()) + { + logmsg("SD Card opened as a mass storage device"); + startMassStorage(); + zuluscsi_setup(); + } + } + #endif + + platform_reset_watchdog(); platform_poll(); diskEjectButtonUpdate(true);