Skip to content

Commit 9a8ef51

Browse files
small fixes to examples and tests, added javadoc everywhere
1 parent d4da8ea commit 9a8ef51

File tree

8 files changed

+229
-76
lines changed

8 files changed

+229
-76
lines changed

Diff for: examples/BackupInternalPartitions/BackupInternalPartitions.ino

+21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1+
/*
2+
BackupInternalPartitions
13
4+
This code demonstrates how the "Arduino_UnifiedStorage" can be used to access multiple partitions on the internal storage,
5+
and transfer information to a USB Mass storage device.
6+
7+
In the setup function, the code initializes serial communication, mounts both USB & internal storage.
8+
It then creates a root directory in the internal storage and creates a subdirectory with files inside it.
9+
10+
The "addSomeFakeFiles" function generates random files in the specified folder, simulating real data.
11+
12+
Afterward, it copies files from internal storage to USB storage and moves folders from each partition internal storage to USB storage.
13+
14+
The "move" function is responsible for transferring folders and files between storage locations.
15+
16+
The "backupPartitionsC33" and "backupPartitionsH7" functions backup partitions based on the board type, as each have a different default scheme.
17+
18+
Created: 31th August 2023
19+
By: Cristian Dragomir
20+
21+
Source: https://github.com/arduino-libraries/Arduino_UnifiedStorage/blob/main/examples/BackupInternalPartitions/BackupInternalPartitions.ino
22+
*/
223

324
#include <Arduino_UnifiedStorage.h>
425

Diff for: examples/PortentaH7Logger/PortentaH7Logger.ino

-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ INSTRUCTIONS
1414
* You can do that by flashing the QSPIFormat example that can be found in the STM32H747_System folder
1515
* Open the serial monitor and select answer with "Y" when this appears "Do you want to use partition scheme 1? Y/[n]"
1616
* Reboot the board
17-
* Connect a RS485-enabled device to see the debugging output.
1817
* This sketch will log data, and check if there is any USB MSD Device connected to the USB Port of the Opta.
1918
The USB device is mounted and unmounted after every update operation. The first status LED is on when the USB drive is mounted.
2019
So as long as the status LED is off you can safely remove the drive.
@@ -24,13 +23,11 @@ INSTRUCTIONS
2423
#include "Arduino_UnifiedStorage.h"
2524
#include <vector>
2625

27-
2826
constexpr auto baudrate { 115200 };
2927

3028
#if defined(ARDUINO_PORTENTA_H7_M7)
3129
#define USB_MOUNTED_LED LED_BLUE
3230
#elif defined(ARDUINO_PORTENTA_C33)
33-
#define USB_MOUNTED_LED LEDB
3431
#endif
3532

3633

Diff for: examples/tests/TestFileOperations/TestFileOperations.ino

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SDStorage sd = SDStorage();
1414
#endif
1515

1616
#if defined(HAS_QSPI)
17-
InternalStorage internal = InternalStorage(2, "user", FS_FAT);
17+
InternalStorage internal = InternalStorage();
1818
#endif
1919

2020

@@ -312,17 +312,15 @@ void setup(){
312312
while(!Serial);
313313

314314
#if defined(HAS_SD)
315-
sd.formatFAT();
316315
runTests(&sd, "SD");
317316
#endif
318317

319318
#if defined(HAS_USB)
320-
usb.formatFAT();
319+
321320
runTests(&usb, "USB");
322321
#endif
323322

324323
#if defined(HAS_QSPI)
325-
internal.formatFAT();
326324
runTests(&internal, "QSPI");
327325
#endif
328326

Diff for: examples/tests/TestFolderOperations/TestFolderOperations.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SDStorage sd = SDStorage();
1313
#endif
1414

1515
#if defined(HAS_QSPI)
16-
InternalStorage internal = InternalStorage(2, "user", FS_FAT);
16+
InternalStorage internal = InternalStorage();
1717
#endif
1818

1919
void printFolderContents(Folder dir, int indentation = 0) {

Diff for: examples/tests/TestRepeatedFormatMount/TestRepeatedFormatMount.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SDStorage sd = SDStorage();
1313
#endif
1414

1515
#if defined(HAS_QSPI)
16-
InternalStorage internal = InternalStorage(2, "user", FS_FAT);
16+
InternalStorage internal = InternalStorage();
1717
#endif
1818

1919
void runRepeatedMountTest(Arduino_UnifiedStorage * storage, String storageType, int n = 10){

Diff for: src/InternalStorage.h

+87-34
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,96 @@
1-
2-
31
#ifndef InternalStorage_H
42
#define InternalStorage_H
53

64
#include "Arduino_UnifiedStorage.h"
75

8-
9-
10-
6+
/**
7+
* Represents internal storage using the Arduino Unified Storage library.
8+
*/
119
class InternalStorage : public Arduino_UnifiedStorage {
12-
13-
14-
public:
15-
InternalStorage();
16-
// Override begin() method for SD card initialization
17-
InternalStorage(int partition, const char * name, FileSystems fs);
18-
19-
int begin() override;
20-
21-
int begin(FileSystems fs) override;
22-
23-
int unmount() override;
24-
25-
Folder getRootFolder() override;
26-
27-
void setQSPIPartition(int partition);
28-
29-
void setQSPIPartitionName(const char * name);
30-
31-
int formatFAT();
32-
33-
int formatLittleFS();
34-
35-
36-
#if defined(ARDUINO_PORTENTA_C33)
37-
BlockDevice * getBlockDevice();
38-
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)
39-
mbed::BlockDevice * getBlockDevice();
40-
#endif
10+
public:
11+
/**
12+
* Default constructor for the InternalStorage class.
13+
*/
14+
InternalStorage();
15+
16+
/**
17+
* Constructs an InternalStorage object with the specified partition, name, and file system.
18+
*
19+
* @param partition The partition number.
20+
* @param name The name of the partition.
21+
* @param fs The desired file system (FS_FAT or FS_LITTLEFS).
22+
*/
23+
InternalStorage(int partition, const char *name, FileSystems fs);
24+
25+
/**
26+
* Initializes the internal storage.
27+
*
28+
* @return 1 if successful, 0 if failed.
29+
*/
30+
int begin() override;
31+
32+
/**
33+
* Initializes the internal storage with the specified file system.
34+
*
35+
* @param fs The desired file system (FS_FAT or FS_LITTLEFS).
36+
* @return 1 if successful, 0 if failed.
37+
*/
38+
int begin(FileSystems fs) override;
39+
40+
/**
41+
* Unmounts the internal storage.
42+
*
43+
* @return 1 if successful, 0 if failed.
44+
*/
45+
int unmount() override;
46+
47+
/**
48+
* Retrieves the root folder of the internal storage.
49+
*
50+
* @return The root folder as a Folder object.
51+
*/
52+
Folder getRootFolder() override;
53+
54+
/**
55+
* Sets the QSPI partition number.
56+
*
57+
* @param partition The partition number.
58+
*/
59+
void setQSPIPartition(int partition);
60+
61+
/**
62+
* Sets the QSPI partition name.
63+
*
64+
* @param name The name of the partition.
65+
*/
66+
void setQSPIPartitionName(const char *name);
67+
68+
/**
69+
* Formats the internal storage with the FAT file system.
70+
*
71+
* @return 1 if successful, 0 if failed.
72+
*/
73+
int formatFAT();
74+
75+
/**
76+
* Formats the internal storage with the LittleFS file system.
77+
*
78+
* @return 1 if successful, 0 if failed.
79+
*/
80+
int formatLittleFS();
81+
82+
/**
83+
* Retrieves the block device associated with the internal storage.
84+
*
85+
* @return The block device as a BlockDevice object.
86+
*/
87+
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA)
88+
mbed::BlockDevice *getBlockDevice();
89+
#endif
90+
91+
#if defined(ARDUINO_PORTENTA_C33)
92+
BlockDevice *getBlockDevice();
93+
#endif
4194

4295

4396
private:

Diff for: src/SDStorage.h

+39-1
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,57 @@
77

88
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_C33) || !defined(ARDUINO_OPTA)
99

10+
/**
11+
* Represents an SD card storage using the Arduino Unified Storage library.
12+
*/
1013
class SDStorage: public Arduino_UnifiedStorage {
1114
public:
15+
/**
16+
* Default constructor for the SDStorage class.
17+
*/
1218
SDStorage();
13-
// Override begin() method for SD card initialization
19+
20+
/**
21+
* Initializes the SD card storage.
22+
*
23+
* @return 1 if successful, 0 if failed.
24+
*/
1425
int begin() override ;
1526

27+
/**
28+
* Initializes the SD card storage with the specified file system.
29+
*
30+
* @param fs The desired file system (FS_FAT or FS_LITTLEFS).
31+
* @return 1 if successful, 0 if failed.
32+
*/
1633
int begin(FileSystems fs) override;
1734

35+
/**
36+
* Unmounts the SD card storage.
37+
*
38+
* @return 1 if successful, 0 if failed.
39+
*/
1840
int unmount() override;
1941

42+
/**
43+
* Retrieves the root folder of the SD card storage.
44+
*
45+
* @return The root folder as a Folder object.
46+
*/
2047
Folder getRootFolder() override;
2148

49+
/**
50+
* Formats the SD card storage with the FAT file system.
51+
*
52+
* @return 1 if successful, 0 if failed.
53+
*/
2254
int formatFAT() override;
55+
56+
/**
57+
* Formats the SD card storage with the LittleFS file system.
58+
*
59+
* @return 1 if successful, 0 if failed.
60+
*/
2361

2462
int formatLittleFS() override;
2563
private:

0 commit comments

Comments
 (0)