Skip to content

Commit

Permalink
add conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Mar 19, 2021
1 parent 70f511c commit cbf191c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/HAL/STM32/msc_sd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class Sd2CardUSBMscHandler : public USBMscHandler {
public:
DiskIODriver* getDiskIODriver() {
#if ENABLED(MULTI_VOLUME)
#if DEFAULT_SHARED_VOLUME == SD_ONBOARD
#if SHARED_VOLUME_IS(SD_ONBOARD)
return &card.sd2card_sd_spi;
#elif DEFAULT_SHARED_VOLUME == USB_FLASH_DRIVE
#elif SHARED_VOLUME_IS(USB_FLASH_DRIVE)
return &card.sd2card_UsbFlashDrive;
#endif
#else
Expand Down
9 changes: 9 additions & 0 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@
#define SD_DETECT_STATE LOW
#endif
#endif

#if DISABLED(USB_FLASH_DRIVE_SUPPORT) || BOTH(MULTI_VOLUME, VOLUME_SD_ONBOARD)
#if ENABLED(SDIO_SUPPORT)
#define NEED_SD2CARD_SDIO 1
#else
#define NEED_SD2CARD_SPI 1
#endif
#endif

#endif

#if ANY(HAS_GRAPHICAL_TFT, LCD_USE_DMA_FSMC, HAS_FSMC_GRAPHICAL_TFT, HAS_SPI_GRAPHICAL_TFT) || !PIN_EXISTS(SD_DETECT)
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/sd/Sd2Card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "../inc/MarlinConfig.h"

#if ENABLED(SDSUPPORT) && (NONE(USB_FLASH_DRIVE_SUPPORT, SDIO_SUPPORT) || BOTH(MULTI_VOLUME, VOLUME_SD_ONBOARD))
#if NEED_SD2CARD_SPI

/* Enable FAST CRC computations - You can trade speed for FLASH space if
* needed by disabling the following define */
Expand Down Expand Up @@ -670,4 +670,4 @@ bool DiskIODriver_SPI_SD::writeStop() {
return success;
}

#endif // SDSUPPORT
#endif // NEED_SD2CARD_SPI
4 changes: 0 additions & 4 deletions Marlin/src/sd/Sd2Card_sdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

#include "../inc/MarlinConfig.h"

#if ENABLED(SDIO_SUPPORT)

#include "SdInfo.h"
#include "disk_io_driver.h"

Expand All @@ -47,5 +45,3 @@ class DiskIODriver_SDIO : public DiskIODriver {
uint32_t cardSize() { return 0; };
bool isReady() { return true; };
};

#endif // SDIO_SUPPORT
11 changes: 5 additions & 6 deletions Marlin/src/sd/SdVolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,18 @@
#include "usb_flashdrive/Sd2Card_FlashDrive.h"
#endif

#if DISABLED(USB_FLASH_DRIVE_SUPPORT) || BOTH(MULTI_VOLUME, VOLUME_SD_ONBOARD)
#if ENABLED(SDIO_SUPPORT)
#include "Sd2Card_sdio.h"
#else
#include "Sd2Card.h"
#endif
#if NEED_SD2CARD_SDIO
#include "Sd2Card_sdio.h"
#elif NEED_SD2CARD_SPI
#include "Sd2Card.h"
#endif

#include "SdFatConfig.h"
#include "SdFatStructs.h"

//==============================================================================
// SdVolume class

/**
* \brief Cache for an SD data block
*/
Expand Down
37 changes: 19 additions & 18 deletions Marlin/src/sd/cardreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,10 @@ uint8_t CardReader::workDirDepth;
#if ENABLED(USB_FLASH_DRIVE_SUPPORT)
DiskIODriver_USBFlash CardReader::sd2card_UsbFlashDrive;
#endif
#if DISABLED(USB_FLASH_DRIVE_SUPPORT) || BOTH(MULTI_VOLUME, VOLUME_SD_ONBOARD)
#if ENABLED(SDIO_SUPPORT)
DiskIODriver_SDIO CardReader::sd2card_sdio;
#else
DiskIODriver_SPI_SD CardReader::sd2card_sd_spi;
#endif
#if NEED_SD2CARD_SDIO
DiskIODriver_SDIO CardReader::sd2card_sdio;
#elif NEED_SD2CARD_SPI
DiskIODriver_SPI_SD CardReader::sd2card_sd_spi;
#endif

DiskIODriver* CardReader::sd2card = nullptr;
Expand All @@ -144,19 +142,22 @@ SdFile CardReader::file;
uint32_t CardReader::filesize, CardReader::sdpos;

CardReader::CardReader() {
#if ENABLED(MULTI_VOLUME)
#if DEFAULT_SHARED_VOLUME == SD_ONBOARD
changeMedia(&sd2card_sd_spi);
#elif DEFAULT_SHARED_VOLUME == USB_FLASH_DRIVE
changeMedia(&sd2card_UsbFlashDrive);
changeMedia(&
#if ENABLED(MULTI_VOLUME)
#if SHARED_VOLUME_IS(SD_ONBOARD)
sd2card_sd_spi
#elif SHARED_VOLUME_IS(USB_FLASH_DRIVE)
sd2card_UsbFlashDrive
#endif
#elif ENABLED(USB_FLASH_DRIVE_SUPPORT)
sd2card_UsbFlashDrive
#elif ENABLED(SDIO_SUPPORT)
sd2card_sdio
#else
sd2card_sd_spi
#endif
#elif ENABLED(USB_FLASH_DRIVE_SUPPORT)
changeMedia(&sd2card_UsbFlashDrive);
#elif ENABLED(SDIO_SUPPORT)
changeMedia(&sd2card_sdio);
#else
changeMedia(&sd2card_sd_spi);
#endif
);

#if ENABLED(SDCARD_SORT_ALPHA)
sort_count = 0;
#if ENABLED(SDSORT_GCODE)
Expand Down
29 changes: 15 additions & 14 deletions Marlin/src/sd/cardreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,21 @@ extern const char M23_STR[], M24_STR[];
#include "usb_flashdrive/Sd2Card_FlashDrive.h"
#endif

#if DISABLED(USB_FLASH_DRIVE_SUPPORT) || BOTH(MULTI_VOLUME, VOLUME_SD_ONBOARD)
#if ENABLED(SDIO_SUPPORT)
#include "Sd2Card_sdio.h"
#else
#include "Sd2Card.h"
#endif
#if NEED_SD2CARD_SDIO
#include "Sd2Card_sdio.h"
#elif NEED_SD2CARD_SPI
#include "Sd2Card.h"
#endif

#if ENABLED(MULTI_VOLUME)
#define SD_ONBOARD 1
#define USB_FLASH_DRIVE 2
#define SV_SD_ONBOARD 1
#define SV_USB_FLASH_DRIVE 2
#define SHARED_VOLUME_IS(N) (DEFAULT_SHARED_VOLUME == CAT(SV_,N))
#if !SHARED_VOLUME_IS(SD_ONBOARD) && !SHARED_VOLUME_IS(USB_FLASH_DRIVE)
#error "DEFAULT_SHARED_VOLUME must be either SD_ONBOARD or USB_FLASH_DRIVE."
#endif
#endif

typedef struct {
bool saving:1,
logging:1,
Expand Down Expand Up @@ -206,12 +209,10 @@ class CardReader {
#if ENABLED(USB_FLASH_DRIVE_SUPPORT)
static DiskIODriver_USBFlash sd2card_UsbFlashDrive;
#endif
#if DISABLED(USB_FLASH_DRIVE_SUPPORT) || BOTH(MULTI_VOLUME, VOLUME_SD_ONBOARD)
#if ENABLED(SDIO_SUPPORT)
static DiskIODriver_SDIO sd2card_sdio;
#else
static DiskIODriver_SPI_SD sd2card_sd_spi;
#endif
#if NEED_SD2CARD_SDIO
static DiskIODriver_SDIO sd2card_sdio;
#elif NEED_SD2CARD_SPI
static DiskIODriver_SPI_SD sd2card_sd_spi;
#endif

private:
Expand Down

0 comments on commit cbf191c

Please sign in to comment.