Skip to content

Commit fbb315a

Browse files
committed
Fix build errors and warnings
1 parent 464565e commit fbb315a

File tree

6 files changed

+43
-36
lines changed

6 files changed

+43
-36
lines changed

src/Storage/MassStorage.cpp

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
#include <Platform/RepRap.h>
44
#include <ObjectModel/ObjectModel.h>
55

6-
#if HAS_MASS_STORAGE
7-
8-
// Check that the LFN configuration in FatFS is sufficient
9-
static_assert(FF_MAX_LFN >= MaxFilenameLength, "FF_MAX_LFN too small");
10-
11-
#endif
126

137
#if HAS_SBC_INTERFACE
148
# include <SBC/SbcInterface.h>
@@ -18,9 +12,14 @@ static_assert(FF_MAX_LFN >= MaxFilenameLength, "FF_MAX_LFN too small");
1812
# include <GCodes/GCodeBuffer/GCodeBuffer.h>
1913
#endif
2014

15+
#if HAS_MASS_STORAGE
2116
#include <Libraries/Fatfs/ff.h> // for type definitions
2217
#include <Libraries/Fatfs/diskio.h>
2318

19+
// Check that the LFN configuration in FatFS is sufficient
20+
static_assert(FF_MAX_LFN >= MaxFilenameLength, "FF_MAX_LFN too small");
21+
#endif
22+
2423
#include "SdCardVolume.h"
2524

2625
#if SUPPORT_USB_DRIVE
@@ -39,7 +38,6 @@ static_assert(FF_VOLUMES >= NumSdCards);
3938
// No function in here should be called when the caller already owns the shared SPI mutex.
4039

4140
#if HAS_MASS_STORAGE
42-
4341
// Private data and methods
4442

4543
# if SAME70
@@ -877,57 +875,51 @@ bool MassStorage::IsVolumeDetected(size_t slot) noexcept
877875
// This may only be called to mount one volume at a time.
878876
GCodeResult MassStorage::Mount(size_t slot, const StringRef& reply, bool reportSuccess) noexcept
879877
{
880-
if (slot >= GetNumVolumes())
878+
if (slot >= GetNumVolumes()
879+
#if HAS_MASS_STORAGE
880+
|| !storageVolumes[slot]->IsUseable(reply)
881+
#endif
882+
)
881883
{
882884
reply.copy("Volume slot out of range");
883885
return GCodeResult::error;
884886
}
885887

886-
if (!storageVolumes[slot]->IsUseable(reply))
887-
{
888-
return GCodeResult::error;
889-
}
890-
891-
GCodeResult res = GCodeResult::ok;
892-
893888
# if HAS_MASS_STORAGE
894889
MutexLocker lock(fsMutex);
895-
res = storageVolumes[slot]->Mount(reply, reportSuccess);
890+
return storageVolumes[slot]->Mount(reply, reportSuccess);
891+
#else
892+
return GCodeResult::ok;
896893
#endif
897-
898-
return res;
899894
}
900895

901896
// Unmount the volume on specified slot, returning true if done, false if needs to be called again.
902897
// If an error occurs, return true with the error message in 'reply'.
903898
GCodeResult MassStorage::Unmount(size_t slot, const StringRef& reply) noexcept
904899
{
905-
if (slot >= GetNumVolumes())
900+
if (slot >= GetNumVolumes()
901+
#if HAS_MASS_STORAGE
902+
|| !storageVolumes[slot]->IsUseable(reply)
903+
#endif
904+
)
906905
{
907906
reply.copy("Volume slot out of range");
908907
return GCodeResult::error;
909908
}
910909

911-
if (!storageVolumes[slot]->IsUseable(reply))
912-
{
913-
return GCodeResult::error;
914-
}
915-
916-
GCodeResult res = GCodeResult::ok;
917-
918910
# if HAS_MASS_STORAGE
919911
MutexLocker lock(fsMutex);
920-
res = storageVolumes[slot]->Unmount(reply);
912+
return storageVolumes[slot]->Unmount(reply);
913+
#else
914+
return GCodeResult::ok;
921915
#endif
922-
923-
return res;
924916
}
925917

926918
bool MassStorage::IsDriveMounted(size_t slot) noexcept
927919
{
928-
return slot < GetNumVolumes() && storageVolumes[slot]->IsUseable()
920+
return slot < GetNumVolumes()
929921
#if HAS_MASS_STORAGE
930-
&& storageVolumes[slot]->IsMounted()
922+
&& storageVolumes[slot]->IsUseable() && storageVolumes[slot]->IsMounted()
931923
#endif
932924
;
933925
}
@@ -1038,7 +1030,7 @@ void MassStorage::RecordSimulationTime(const char *printingFilePath, uint32_t si
10381030
// Get information about the volume and interface speed on the specified slot
10391031
MassStorage::InfoResult MassStorage::GetVolumeInfo(size_t slot, SdCardReturnedInfo& returnedInfo) noexcept
10401032
{
1041-
if (slot >= GetNumVolumes() && storageVolumes[slot]->IsUseable())
1033+
if (slot >= GetNumVolumes() || !storageVolumes[slot]->IsUseable())
10421034
{
10431035
return InfoResult::badSlot;
10441036
}
@@ -1066,7 +1058,6 @@ const ObjectModel * MassStorage::GetVolume(size_t slot) noexcept
10661058
}
10671059
# endif
10681060

1069-
#endif
10701061

10711062
// Functions called by FatFS to acquire/release mutual exclusion
10721063
extern "C"
@@ -1124,4 +1115,7 @@ extern "C"
11241115
}
11251116
}
11261117

1118+
#endif
1119+
1120+
11271121
// End

src/Storage/MassStorage.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ namespace MassStorage
5656
bool FileExists(const char *filePath) noexcept;
5757
void CloseAllFiles() noexcept;
5858
void Spin() noexcept;
59-
59+
#if HAS_EMBEDDED_FILES && defined(DUET3_MB6HC)
60+
size_t GetNumVolumes() noexcept;
61+
#else
6062
inline size_t GetNumVolumes() noexcept
6163
{
6264
return NumSdCards
@@ -65,6 +67,7 @@ namespace MassStorage
6567
#endif
6668
;
6769
}
70+
#endif // HAS_EMBEDDED_FILES && defined(DUET3_MB6HC)
6871
#endif
6972

7073
#if HAS_MASS_STORAGE || HAS_SBC_INTERFACE

src/Storage/SdCardVolume.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ GCodeResult SdCardVolume::Mount(const StringRef& reply, bool reportSuccess) noex
250250

251251
bool SdCardVolume::IsUseable(const StringRef& reply) const noexcept
252252
{
253-
#if DUET3_MB6HC
253+
#ifdef DUET3_MB6HC
254254
// We have another sd slot if the second one has a valid CS pin
255255
if (slot == 1 && (reprap.GetPlatform().GetBoardType() >= BoardType::Duet3_6HC_v102 || sd1Ports[0].IsValid()))
256256
{

src/Storage/SdCardVolume.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <ObjectModel/ObjectModel.h>
44
#include "StorageVolume.h"
55

6+
#if HAS_MASS_STORAGE
7+
68
class SdCardVolume : public StorageVolume
79
{
810
public:
@@ -75,3 +77,5 @@ class SdCardVolume : public StorageVolume
7577

7678
void DeviceUnmount() noexcept override;
7779
};
80+
81+
#endif

src/Storage/StorageVolume.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include <Platform/RepRap.h>
22

3-
#include "StorageVolume.h"
43
#include "MassStorage.h"
4+
#include "StorageVolume.h"
55

6+
#if HAS_MASS_STORAGE
67
#if SUPPORT_OBJECT_MODEL
78

89
// Object model table and functions
@@ -114,3 +115,5 @@ void StorageVolume::Clear()
114115
}
115116

116117
/*static*/ const StringRef StorageVolume::noReply = StringRef(nullptr, 0);
118+
119+
#endif // HAS_MASS_STORAGE

src/Storage/StorageVolume.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include <General/StringRef.h>
66
#include <ObjectModel/ObjectModel.h>
7+
8+
#if HAS_MASS_STORAGE
79
#include <Libraries/Fatfs/diskio.h>
810

911
class StorageVolume INHERIT_OBJECT_MODEL
@@ -57,3 +59,4 @@ class StorageVolume INHERIT_OBJECT_MODEL
5759
unsigned int InternalUnmount() noexcept;
5860
virtual void DeviceUnmount() noexcept = 0;
5961
};
62+
#endif

0 commit comments

Comments
 (0)