Skip to content
This repository was archived by the owner on Feb 21, 2020. It is now read-only.

Commit f69702f

Browse files
committed
SD code cleanup
1 parent 9adbd4d commit f69702f

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

libraries/SD/examples/Full/Full.ino

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,8 @@
33
#define BUFFERSIZE (COUNTOF(wtext) -1)
44
uint32_t file_size = 0, seek_val = FALSE, peek_val = FALSE;
55
uint32_t byteswritten, bytesread = 0;
6-
uint8_t wtext[] = "This is STM32 working with FatFs. It is to test Arduino based on STM32 HAL. \n"
7-
"This is STM32 working with FatFs. It is to test Arduino based on STM32 HAL. \n"
8-
"This is STM32 working with FatFs. It is to test Arduino based on STM32 HAL. \n"
9-
"This is STM32 working with FatFs. It is to test Arduino based on STM32 HAL. \n"
10-
"This is STM32 working with FatFs. It is to test Arduino based on STM32 HAL. \n"
11-
"This is STM32 working with FatFs. It is to test Arduino based on STM32 HAL. \n"
12-
"This is STM32 working with FatFs. It is to test Arduino based on STM32 HAL. \n"
13-
"This is STM32 working with FatFs. It is to test Arduino based on STM32 HAL. \n"
14-
"This is STM32 working with FatFs. It is to test Arduino based on STM32 HAL. \n"
15-
"This is STM32 working with FatFs. It is to test Arduino based on STM32 HAL. \n"
16-
"This is STM32 working with FatFs. It is to test Arduino based on STM32 HAL. \n"
17-
"This is STM32 working with FatFs. It is to test Arduino based on STM32 HAL. \n"
18-
"This is STM32 working with FatFs. It is to test Arduino based on STM32 HAL. \n"; /* File write buffer */
6+
/* File write buffer */
7+
uint8_t wtext[] = "This is the OTTO SD Test working with FatFs. \n";
198

209
uint8_t rtext[BUFFERSIZE];
2110
uint32_t i = 0;
@@ -29,16 +18,23 @@ void setup()
2918
{
3019
delay(10);
3120
}
21+
Serial.begin(9600);
22+
while (!Serial);
3223

3324
/* Test mkdir() method */
25+
Serial.println("Creating 'STM32F4' directory");
3426
SD.mkdir("STM32F4");
27+
Serial.println("Creating 'ARDUINO' directory");
3528
SD.mkdir("ARDUINO");
29+
Serial.println("Creating 'ARDUINO/OTTO' directory");
3630
SD.mkdir("ARDUINO/OTTO");
3731
/* Test open() method */
32+
Serial.println("opening 'STM32F4/Toremove.txt' file");
3833
SD.open("STM32F4/Toremove.txt", FILE_WRITE);
3934
MyFile = SD.open("ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt", FILE_WRITE);
4035

4136
/* Test print() method */
37+
Serial.println("writing \"This is the OTTO SD Test working with FatFs.\" into Toremove.txt file");
4238
byteswritten = MyFile.print((const char*)wtext);
4339
MyFile.close();
4440

@@ -47,13 +43,18 @@ void setup()
4743
for(i = 0; i<10; i++)
4844
{
4945
peek_val = MyFile.peek();
46+
Serial.print("TEXT.txt peek: ");
47+
Serial.println(peek_val);
5048
}
5149

5250
/* Test size() method */
5351
file_size = MyFile.size();
54-
52+
Serial.print("TEXT.txt size: ");
53+
Serial.println(file_size);
5554
/* Test seek method */
5655
seek_val = MyFile.seek(100);
56+
Serial.print("TEXT.txt seek value: ");
57+
Serial.println(seek_val);
5758

5859
for(i = 0; i<10; i++)
5960
{
@@ -62,9 +63,11 @@ void setup()
6263
i = 0;
6364

6465
/* Test available() and read() methods */
66+
Serial.print("TEXT.txt content: ");
6567
while(MyFile.available())
6668
{
6769
rtext[i] = (uint8)MyFile.read();
70+
Serial.println(rtext[i]);
6871
i++;
6972
}
7073

@@ -107,7 +110,7 @@ void setup()
107110
MyFile = SD.open("ARDUINO/OTTO/WRITE.txt");
108111
file_size = MyFile.size();
109112
bytesread = MyFile.read(rtext, file_size);
110-
MyFile.close();
113+
MyFile.close();
111114
}
112115

113116
void loop()

libraries/SD/src/SD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
level (e.g. open).
5050
5151
*/
52+
5253
extern "C" {
5354
#include <stdlib.h>
5455
#include <string.h>
@@ -458,4 +459,3 @@ uint8_t File::isDirectory()
458459
return FALSE;
459460
}
460461
}
461-

libraries/SD/src/SD.h

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define __SD_H__
1717

1818
#include <Arduino.h>
19-
/* DISCOVERY includes component */
19+
/* otto includes component */
2020
#include "BSP/OTTO/otto_sd.h"
2121

2222
/* FatFs includes component */
@@ -31,40 +31,49 @@
3131

3232
class File {
3333
public:
34+
3435
virtual size_t write(uint8_t);
3536
virtual size_t write(const uint8_t *buf, size_t size);
36-
virtual size_t print(const char* data);
37-
virtual size_t println();
38-
virtual size_t println(const char* data);
3937
virtual int read();
40-
int read(void* buf, size_t len);
4138
virtual int peek();
4239
virtual int available();
4340
virtual void flush();
41+
int read(void* buf, size_t len);
4442
uint8_t seek(uint32_t pos);
4543
uint32_t position();
4644
uint32_t size();
4745
void close();
46+
// alfran ----- begin -----
47+
operator bool();
48+
// alfran ----- end -----
49+
char *name;
4850
uint8_t isDirectory();
4951

50-
FIL Fil;
51-
char *name;
52+
53+
virtual size_t print(const char* data);
54+
virtual size_t println();
55+
virtual size_t println(const char* data);
56+
57+
FIL Fil;
58+
5259
};
5360

5461
class SDClass {
62+
5563
public:
5664

5765
/* Initialize the SD peripheral */
5866
static uint8_t begin();
5967
static uint8_t begin(uint8_t cspin);
68+
static File open(const char *filepath, uint8_t mode);
69+
static File open(const char *filepath);
6070
static uint8_t exists(const char *filepath);
6171
static uint8_t mkdir(const char *filepath);
62-
static uint8_t rmdir(const char *filepath);
63-
static File open(const char *filepath);
64-
static File open(const char *filepath, uint8_t mode);
6572
static uint8_t remove(const char *filepath);
73+
static uint8_t rmdir(const char *filepath);
6674

6775
friend class File;
76+
6877
};
6978

7079
extern SDClass SD;

0 commit comments

Comments
 (0)