Data Gator
Hardware and software documentation for the Data Gator project.
Loading...
Searching...
No Matches
SDCard.hpp
Go to the documentation of this file.
1
7
#ifndef SDCARD_H
8
#define SDCARD_H
12
13
//#include <Debug.h>
14
#include <SD.h>
15
#include <SPI.h>
16
17
// For ESP32 these can be assigned to nearly any GPIO pins.
18
#define TT_CLK 14
19
#define TT_MISO 25
20
#define TT_MOSI 13
21
#define TT_SS 2
22
28
class
SDCard
{
29
public
:
32
using
File
= fs::File;
33
34
public
:
35
SDCard
() =
default
;
36
39
explicit
operator
bool
()
const
{
return
mCard !=
nullptr
; }
40
55
bool
begin
(
uint8_t
clkPin
=
TT_CLK
,
uint8_t
misoPin
=
TT_MISO
,
56
uint8_t
mosiPin
=
TT_MOSI
,
uint8_t
ssPin
=
TT_SS
,
57
SPIClass
*
spi
= &
SPI
) {
58
//debugMsg("SDCard::begin()");
59
60
// Connect to the SD Card API.
61
mCard = &
SD
;
62
63
// Start SPI with the specified pins.
64
// Probably need an API that takes the SPI
65
spi
->begin(
clkPin
,
misoPin
,
mosiPin
,
ssPin
);
66
67
//debugMsg("Initializing SD card...");
68
69
if
(!mCard->begin(
ssPin
, *
spi
)) {
70
//debugMsg("initialization failed!");
71
return
false
;
72
}
73
//debugMsg("initialization done.");
74
//debugLog(mCard->cardSize());
75
return
true
;
76
}
77
79
void
end
() { mCard->end(); }
80
92
File
open
(
const
char
*path,
const
char
*
mode
=
FILE_READ
,
93
const
bool
create
=
false
) {
94
return
mCard->open(path,
mode
,
create
);
95
}
96
97
File
open
(
const
String
&path,
const
char
*
mode
=
FILE_READ
,
98
const
bool
create
=
false
) {
99
return
mCard->open(path,
mode
,
create
);
100
}
102
109
bool
exists
(
const
char
*path) {
return
mCard->exists(path); }
110
bool
exists
(
const
String
&path) {
return
mCard->exists(path); }
112
119
bool
remove
(
const
char
*path) {
return
mCard->remove(path); }
120
bool
remove
(
const
String
&path) {
return
mCard->remove(path); }
122
130
bool
rename
(
const
char
*
pathFrom
,
const
char
*
pathTo
) {
131
return
mCard->rename(
pathFrom
,
pathTo
);
132
}
133
bool
rename
(
const
String
&
pathFrom
,
const
String
&
pathTo
) {
134
return
mCard->rename(
pathFrom
,
pathTo
);
135
}
137
148
bool
mkdir
(
const
char
*path) {
return
mCard->mkdir(path); }
149
bool
mkdir
(
const
String
&path) {
return
mCard->mkdir(path); }
151
160
bool
rmdir
(
const
char
*path) {
return
mCard->rmdir(path); }
161
bool
rmdir
(
const
String
&path) {
return
mCard->rmdir(path); }
163
164
private
:
165
fs::SDFS *mCard;
166
};
167
168
#endif
// SDCARD_H
TT_SS
#define TT_SS
SPI CS/SS chip select pin.
Definition
SDCard.hpp:21
TT_CLK
#define TT_CLK
Support for SD Card.
Definition
SDCard.hpp:18
TT_MOSI
#define TT_MOSI
SPI MOSI mapping.
Definition
SDCard.hpp:20
TT_MISO
#define TT_MISO
SPI MISO pin mapping.
Definition
SDCard.hpp:19
SDCard
Thin wrapper around ESP32 SD card API.
Definition
SDCard.hpp:28
SDCard::end
void end()
Terminate connection to SD Card and associated SPI interface.
Definition
SDCard.hpp:79
SDCard::rename
bool rename(const char *pathFrom, const char *pathTo)
Definition
SDCard.hpp:130
SDCard::exists
bool exists(const char *path)
Definition
SDCard.hpp:109
SDCard::rmdir
bool rmdir(const char *path)
Definition
SDCard.hpp:160
SDCard::begin
bool begin(uint8_t clkPin=TT_CLK, uint8_t misoPin=TT_MISO, uint8_t mosiPin=TT_MOSI, uint8_t ssPin=TT_SS, SPIClass *spi=&SPI)
Definition
SDCard.hpp:55
SDCard::File
fs::File File
Definition
SDCard.hpp:32
SDCard::remove
bool remove(const char *path)
Definition
SDCard.hpp:119
SDCard::mkdir
bool mkdir(const char *path)
Definition
SDCard.hpp:148
SDCard::open
File open(const char *path, const char *mode=FILE_READ, const bool create=false)
Definition
SDCard.hpp:92
reset_count
int reset_count
number of resets retrieved for NVS
Definition
scheduler.hpp:31
include
SDCard.hpp
Generated by
1.10.0