@@ -15,31 +15,39 @@ int d0 = 37;
15
15
int d1 = 38 ;
16
16
int d2 = 33 ;
17
17
int d3 = 34 ;
18
- bool onebit = true ; // set to false for 4-bit. 1-bit will ignore the d1-d3 pins (but d3 must be pulled high)
18
+ bool onebit = true ; // set to false for 4-bit. 1-bit will ignore the d1-d3 pins (but d3 must be pulled high)
19
19
20
- static int32_t onWrite (uint32_t lba, uint32_t offset, uint8_t * buffer, uint32_t bufsize){
20
+ static int32_t onWrite (uint32_t lba, uint32_t offset, uint8_t * buffer, uint32_t bufsize) {
21
21
uint32_t secSize = SD_MMC.sectorSize ();
22
- if (!secSize) return false ; // disk error
22
+ if (!secSize) {
23
+ return false ; // disk error
24
+ }
23
25
log_v (" Write lba: %ld\t offset: %ld\t bufsize: %ld" , lba, offset, bufsize);
24
- for (int x= 0 ; x< bufsize/ secSize; x++) {
26
+ for (int x = 0 ; x < bufsize / secSize; x++) {
25
27
uint8_t blkbuffer[secSize];
26
- memcpy (blkbuffer, (uint8_t *)buffer + secSize*x, secSize);
27
- if (!SD_MMC.writeRAW (blkbuffer, lba + x)) return false ;
28
+ memcpy (blkbuffer, (uint8_t *)buffer + secSize * x, secSize);
29
+ if (!SD_MMC.writeRAW (blkbuffer, lba + x)) {
30
+ return false ;
31
+ }
28
32
}
29
33
return bufsize;
30
34
}
31
35
32
- static int32_t onRead (uint32_t lba, uint32_t offset, void * buffer, uint32_t bufsize){
36
+ static int32_t onRead (uint32_t lba, uint32_t offset, void * buffer, uint32_t bufsize) {
33
37
uint32_t secSize = SD_MMC.sectorSize ();
34
- if (!secSize) return false ; // disk error
38
+ if (!secSize) {
39
+ return false ; // disk error
40
+ }
35
41
log_v (" Read lba: %ld\t offset: %ld\t bufsize: %ld\t sector: %lu" , lba, offset, bufsize, secSize);
36
- for (int x=0 ; x < bufsize/secSize; x++) {
37
- if (!SD_MMC.readRAW ((uint8_t *)buffer + (x * secSize), lba + x)) return false ; // outside of volume boundary
42
+ for (int x = 0 ; x < bufsize / secSize; x++) {
43
+ if (!SD_MMC.readRAW ((uint8_t *)buffer + (x * secSize), lba + x)) {
44
+ return false ; // outside of volume boundary
45
+ }
38
46
}
39
47
return bufsize;
40
48
}
41
49
42
- static bool onStartStop (uint8_t power_condition, bool start, bool load_eject){
50
+ static bool onStartStop (uint8_t power_condition, bool start, bool load_eject) {
43
51
log_i (" Start/Stop power: %u\t start: %d\t eject: %d" , power_condition, start, load_eject);
44
52
return true ;
45
53
}
@@ -58,13 +66,13 @@ static void usbEventCallback(void *arg, esp_event_base_t event_base, int32_t eve
58
66
}
59
67
}
60
68
61
- void setup (){
69
+ void setup () {
62
70
Serial.begin (115200 );
63
71
Serial.println (" Starting Serial" );
64
72
65
73
Serial.println (" Mounting SDcard" );
66
74
SD_MMC.setPins (clk, cmd, d0, d1, d2, d3);
67
- if (!SD_MMC.begin (" /sdcard" , onebit)){
75
+ if (!SD_MMC.begin (" /sdcard" , onebit)) {
68
76
Serial.println (" Mount Failed" );
69
77
return ;
70
78
}
@@ -85,10 +93,10 @@ void setup(){
85
93
USB.begin ();
86
94
USB.onEvent (usbEventCallback);
87
95
88
- Serial.printf (" Card Size: %lluMB\n " , SD_MMC.totalBytes ()/ 1024 / 1024 );
96
+ Serial.printf (" Card Size: %lluMB\n " , SD_MMC.totalBytes () / 1024 / 1024 );
89
97
Serial.printf (" Sector: %d\t Count: %d\n " , SD_MMC.sectorSize (), SD_MMC.numSectors ());
90
98
}
91
99
92
- void loop (){
100
+ void loop () {
93
101
delay (-1 );
94
102
}
0 commit comments