-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkitten_sd.cpp
More file actions
84 lines (74 loc) · 1.89 KB
/
kitten_sd.cpp
File metadata and controls
84 lines (74 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <Arduino.h>
#include "kitten_sd.h"
void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if (!root) {
Serial.println("Failed to open directory");
return;
}
if (!root.isDirectory()) {
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
Serial.print(" DIR : ");
Serial.println(file.name());
if (levels) {
listDir(fs, file.path(), levels - 1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
bool initSD() {
// Init SD on HSPI
spiSD.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);
delay(1000);
if (!SD.begin(SD_CS, spiSD)) {
Serial.println("SD FAIL");
tft.setCursor(0, 10);
tft.setTextColor(ST77XX_RED);
tft.println("SD FAIL");
return false;
}
delay(1000);
Serial.println("SD OK!");
tft.setCursor(0, 10);
tft.setTextColor(ST77XX_GREEN);
tft.println("SD OK!");
// Detect Card Type
uint8_t cardType = SD.cardType();
delay(1000);
if (cardType == CARD_NONE) {
Serial.println("No SD card attached");
tft.println("No SD card attached");
return false;
}
Serial.print("SD Card Type: ");
tft.println("SD Card Type: ");
delay(1000);
if (cardType == CARD_MMC) {
Serial.println("MMC");
tft.println("MMC");
} else if (cardType == CARD_SD) {
Serial.println("SDSC");
tft.println("SDSC");
} else if (cardType == CARD_SDHC) {
Serial.println("SDHC");
tft.println("SDHC");
} else {
Serial.println("UNKNOWN");
tft.println("UNKNOWN Card");
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
Serial.printf("SD Card Size: %lluMB\n", cardSize);
return true;
}