Skip to content

Commit 38f181d

Browse files
Merge pull request #1 from cristidragomir97/refactorings
Refactorings
2 parents 12b6e76 + a5f54ee commit 38f181d

16 files changed

+72
-1164
lines changed
-5.43 MB
Binary file not shown.

examples/AdvancedInternalStorage/AdvancedInternalStorage.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <Arduino.h>
21
#include <Arduino_UnifiedStorage.h>
32
#include <vector>
43

src/Arduino_UnifiedStorage.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55

66
#include "Arduino.h"
77
#include "Arduino_POSIXStorage.h"
8+
#include "Boards.h"
9+
#include "Utils.h"
10+
#include "Types.h"
11+
#include "Partitioning.h"
12+
813
#include "Folder.h"
914
#include "UFile.h"
10-
#include "Utils.h"
15+
16+
17+
1118

1219

1320

@@ -52,15 +59,17 @@ class Arduino_UnifiedStorage {
5259
};
5360

5461

55-
#if defined(ARDUINO_PORTENTA_C33) || defined(ARDUINO_PORTENTA_H7_M7)
56-
#include "USBStorage.h"
57-
#include "SDStorage.h"
58-
#include "InternalStorage.h"
59-
#elif defined(ARDUINO_OPTA)
60-
#include "USBStorage.h"
61-
#include "InternalStorage.h"
62-
#endif
62+
#if defined(HAS_USB)
63+
#include "USBStorage.h"
64+
#endif
65+
66+
#if defined(HAS_SD)
67+
#include "SDStorage.h"
68+
#endif
6369

70+
#if defined(HAS_QSPI)
71+
#include "InternalStorage.h"
72+
#endif
6473

6574
#endif
6675

src/Boards.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#if defined(ARDUINO_PORTENTA_C33)
2+
#define HAS_SD
3+
#define HAS_USB
4+
#define HAS_QSPI
5+
#define USES_RENESAS_CORE
6+
#endif
7+
8+
#if defined(ARDUINO_PORTENTA_H7_M7)
9+
#define HAS_SD
10+
#define HAS_USB
11+
#define HAS_QSPI
12+
#define USES_MBED_CORE
13+
#endif
14+
15+
#if defined(ARDUINO_OPTA)
16+
#define HAS_USB
17+
#define HAS_QSPI
18+
#define USES_MBED_CORE
19+
#endif
20+
21+
#if defined(ARDUINO_NICLA_VISION)
22+
#define HAS_QSPI
23+
#define USES_MBED_CORE
24+
#endif
25+
26+
27+
28+
29+

src/Folder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#ifndef Folder_H
22
#define Folder_H
33

4+
45
#include "Utils.h"
56
#include "UFile.h"
6-
7-
7+
#include <vector>
88

99
class UFile;
1010
/**

src/InternalStorage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ bool InternalStorage::partition(std::vector<Partition> partitions){
2020
Partitioning::partitionDrive(QSPIFBlockDeviceType::get_default_instance(), partitions);
2121
}
2222

23+
24+
2325
bool InternalStorage::begin(){
2426
this -> blockDevice = BlockDeviceType::get_default_instance();
2527
this -> userData = new MBRBlockDeviceType(this->blockDevice, this->partitionNumber);

src/InternalStorage.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#define InternalStorage_H
33

44
#include "Arduino_UnifiedStorage.h"
5-
#include "Partitioning.h"
65
#include "Types.h"
6+
7+
78
/**
89
* Represents internal storage using the Arduino Unified Storage library.
910
*/
@@ -83,6 +84,8 @@ class InternalStorage : public Arduino_UnifiedStorage {
8384
BlockDeviceType *getBlockDevice();
8485

8586
static bool partition(std::vector<Partition> partitions);
87+
// partition() -> one Partition
88+
// restoreDefaultPartitions();
8689

8790

8891
private:

src/Partitioning.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020

2121
bool Partitioning::isPartitionSchemeValid(BlockDeviceType * bd, std::vector<Partition> partitions){
22-
size_t driveSize = bd -> size() / 1024;
22+
size_t driveSize = bd -> size() / 1024; //
2323
int totalSize = 0;
2424

2525
for (size_t i = 1; i < partitions.size() + 1; ++i) {

src/Partitioning.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
#include "Arduino.h"
3-
#include "Arduino_POSIXStorage.h"
43
#include "Types.h"
4+
#include "Arduino_POSIXStorage.h"
55
#include <vector>
66

77
struct Partition {
@@ -17,6 +17,5 @@ class Partitioning{
1717
static bool isPartitionSchemeValid(BlockDeviceType * bd, std::vector<Partition> partitions);
1818
static bool formatPartition(BlockDeviceType * bd, int partitionNumber, FileSystems fs);
1919
static bool createAndFormatPartitions(BlockDeviceType * bd, std::vector<Partition> partitions);
20-
21-
20+
2221
};

src/SDStorage.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include "Arduino_UnifiedStorage.h"
77

8-
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_C33) || !defined(ARDUINO_OPTA)
98

109
/**
1110
* Represents an SD card storage using the Arduino Unified Storage library.
@@ -59,5 +58,3 @@ class SDStorage: public Arduino_UnifiedStorage {
5958
};
6059

6160
#endif
62-
63-
#endif

src/Types.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#if defined(ARDUINO_PORTENTA_C33)
1+
2+
#include "Boards.h"
3+
4+
#if defined(USES_RENESAS_CORE)
25
#include "BlockDevice.h"
36
#include "MBRBlockDevice.h"
47
#include "LittleFileSystem.h"
@@ -11,9 +14,10 @@
1114
typedef LittleFileSystem LittleFileSystemType;
1215
typedef FileSystem FileSystemType;
1316

14-
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_OPTA)
17+
#elif defined(USES_MBED_CORE)
1518
#include "QSPIFBlockDevice.h"
1619
#include "MBRBlockDevice.h"
20+
#include "LittleFileSystem.h"
1721
#include "FATFileSystem.h"
1822

1923
typedef QSPIFBlockDevice QSPIFBlockDeviceType;
@@ -22,5 +26,4 @@
2226
typedef mbed::FATFileSystem FATFileSystemType;
2327
typedef mbed::LittleFileSystem LittleFileSystemType;
2428
typedef mbed::FileSystem FileSystemType;
25-
2629
#endif

src/UFile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <Arduino.h>
55
#include <string.h>
6+
#include <vector>
67
#include "Utils.h"
78

89
class Folder;

src/USBStorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ void USBStorage::onConnect(void (* const callbackFunction)()){
2020
register_hotplug_callback(DEV_USB, callbackFunction);
2121
}
2222

23-
void USBStorage::removeConnectCallback(){
23+
void USBStorage::removeOnConnectCallback(){
2424
deregister_hotplug_callback(DEV_USB);
2525
}
2626

2727
void USBStorage::onDisconnect(void (* const callbackFunction)()){
2828
register_unplug_callback(DEV_USB, callbackFunction);
2929
}
3030

31-
void USBStorage::removeDisconnectCallback(){
31+
void USBStorage::removeOnDisconnectCallback(){
3232
deregister_unplug_callback(DEV_USB);
3333
}
3434

src/USBStorage.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#include "Arduino_UnifiedStorage.h"
1+
22

33
#ifndef USBStorage_H
44
#define USBStorage_H
55

6+
#include "Arduino_UnifiedStorage.h"
67
/**
78
* Represents a USB storage using the Arduino Unified Storage library.
89
*/
@@ -59,19 +60,18 @@ class USBStorage : public Arduino_UnifiedStorage {
5960

6061
void onConnect(void (* const callbackFunction)());
6162

62-
void removeConnectCallback();
63+
void removeOnConnectCallback();
6364

6465
void onDisconnect(void (* const callbackFunction)());
6566

66-
void removeDisconnectCallback();
67+
void removeOnDisconnectCallback();
6768

6869

6970
private:
7071
FileSystems fileSystem = FS_FAT;
7172
bool mounted = false;
7273
unsigned long previousMillis;
73-
unsigned int interval = 500;
74-
74+
unsigned int interval = 500; // document what this does too, make it constexp (mountRetryInterval)
7575
};
7676

7777
#endif

src/Utils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "Arduino.h"
88
#include "Arduino_POSIXStorage.h"
99
#include <iostream>
10-
#include <vector>
1110

1211

1312

0 commit comments

Comments
 (0)