Skip to content

Commit 9bdf6df

Browse files
committed
Use bool type instead of uint8_t
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 30afe43 commit 9bdf6df

File tree

12 files changed

+61
-64
lines changed

12 files changed

+61
-64
lines changed

examples/Datalogger/Datalogger.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void setup()
3030

3131
Serial.print("Initializing SD card...");
3232
// see if the card is present and can be initialized:
33-
while (SD.begin(SD_DETECT_PIN) != TRUE)
33+
while (!SD.begin(SD_DETECT_PIN))
3434
{
3535
delay(10);
3636
}

examples/DumpFile/DumpFile.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void setup()
3030

3131
Serial.print("Initializing SD card...");
3232
// see if the card is present and can be initialized:
33-
while (SD.begin(SD_DETECT_PIN) != TRUE)
33+
while (!SD.begin(SD_DETECT_PIN))
3434
{
3535
delay(10);
3636
}

examples/Files/Files.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void setup()
2929

3030
Serial.print("Initializing SD card...");
3131

32-
while (SD.begin(SD_DETECT_PIN) != TRUE)
32+
while (!SD.begin(SD_DETECT_PIN))
3333
{
3434
delay(10);
3535
}

examples/Full/Full.ino

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
#define COUNTOF(__BUFFER__) (sizeof(__BUFFER__) / sizeof(*(__BUFFER__)))
1010
#define BUFFERSIZE (COUNTOF(wtext) -1)
1111

12-
uint32_t file_size = 0, seek_val = FALSE, peek_val = 0;
12+
uint32_t file_size = 0, seek_val = false, peek_val = 0;
1313
uint32_t byteswritten, bytesread = 0;
1414
/* File write buffer */
1515
uint8_t wtext[] = "This is the Arduino SD Test working with FatFs.";
1616
/* File read buffer */
1717
uint8_t rtext[BUFFERSIZE];
1818
uint32_t i = 0;
19-
uint8_t isdir = FALSE;
19+
bool isdir = false;
2020
File MyFile;
2121

2222
void setup()
@@ -25,27 +25,27 @@ void setup()
2525
while (!Serial);
2626

2727
/* Test begin() method */
28-
while (SD.begin(SD_DETECT_PIN) != TRUE)
28+
while (!SD.begin(SD_DETECT_PIN))
2929
{
3030
delay(10);
3131
}
3232
delay(100);
3333

3434
/* Test mkdir() method */
3535
Serial.print("Creating 'STM32' directory...");
36-
if (SD.mkdir("STM32") == TRUE) {
36+
if (SD.mkdir("STM32")) {
3737
Serial.println("OK");
3838
} else {
3939
Serial.println("KO");
4040
}
4141
Serial.print("Creating 'ARDUINO' directory...");
42-
if (SD.mkdir("ARDUINO") == TRUE) {
42+
if (SD.mkdir("ARDUINO")) {
4343
Serial.println("OK");
4444
} else {
4545
Serial.println("KO");
4646
}
4747
Serial.print("Creating 'ARDUINO/SD' directory...");
48-
if (SD.mkdir("ARDUINO/SD") == TRUE) {
48+
if (SD.mkdir("ARDUINO/SD")) {
4949
Serial.println("OK");
5050
} else {
5151
Serial.println("KO");
@@ -224,14 +224,14 @@ void setup()
224224
}
225225
/* Test exists(), remove() and rmdir() methods */
226226
Serial.print("Removing 'STM32/Toremove.txt' file...");
227-
while (SD.exists("STM32/Toremove.txt") == TRUE)
227+
while (SD.exists("STM32/Toremove.txt") == true)
228228
{
229229
SD.remove("STM32/Toremove.txt");
230230
}
231231
Serial.println("OK");
232232

233233
Serial.print("Removing 'STM32' dir...");
234-
while (SD.exists("STM32") == TRUE)
234+
while (SD.exists("STM32") == true)
235235
{
236236
SD.rmdir("STM32");
237237
}

examples/ReadWrite/ReadWrite.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void setup()
2929

3030

3131
Serial.print("Initializing SD card...");
32-
while (SD.begin(SD_DETECT_PIN) != TRUE)
32+
while (!SD.begin(SD_DETECT_PIN))
3333
{
3434
delay(10);
3535
}

examples/listfiles/listfiles.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void setup()
2929
}
3030

3131
Serial.print("Initializing SD card...");
32-
while (SD.begin(SD_DETECT_PIN) != TRUE)
32+
while (!SD.begin(SD_DETECT_PIN))
3333
{
3434
delay(10);
3535
}

src/SD.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,59 +60,59 @@ SDClass SD;
6060
* @brief Link SD, register the file system object to the FatFs mode and configure
6161
* relatives SD IOs including SD Detect Pin if any
6262
* @param None
63-
* @retval TRUE or FALSE
63+
* @retval true or false
6464
*/
65-
uint8_t SDClass::begin(uint32_t detectpin)
65+
bool SDClass::begin(uint32_t detectpin)
6666
{
6767
/*##-1- Initializes SD IOs #############################################*/
6868
if (_card.init(detectpin)) {
6969
return _fatFs.init();
7070
}
71-
return FALSE;
71+
return false;
7272
}
7373

7474
/**
7575
* @brief Check if a file or folder exist on the SD disk
7676
* @param filename: File name
77-
* @retval TRUE or FALSE
77+
* @retval true or false
7878
*/
79-
uint8_t SDClass::exists(const char *filepath)
79+
bool SDClass::exists(const char *filepath)
8080
{
8181
FILINFO fno;
8282

8383
if (f_stat(filepath, &fno) != FR_OK) {
84-
return FALSE;
84+
return false;
8585
} else {
86-
return TRUE;
86+
return true;
8787
}
8888
}
8989

9090
/**
9191
* @brief Create directory on the SD disk
9292
* @param filename: File name
93-
* @retval TRUE if created or existing else FALSE
93+
* @retval true if created or existing else false
9494
*/
95-
uint8_t SDClass::mkdir(const char *filepath)
95+
bool SDClass::mkdir(const char *filepath)
9696
{
9797
FRESULT res = f_mkdir(filepath);
9898
if ((res != FR_OK) && (res != FR_EXIST)) {
99-
return FALSE;
99+
return false;
100100
} else {
101-
return TRUE;
101+
return true;
102102
}
103103
}
104104

105105
/**
106106
* @brief Remove directory on the SD disk
107107
* @param filename: File name
108-
* @retval TRUE or FALSE
108+
* @retval true or false
109109
*/
110-
uint8_t SDClass::rmdir(const char *filepath)
110+
bool SDClass::rmdir(const char *filepath)
111111
{
112112
if (f_unlink(filepath) != FR_OK) {
113-
return FALSE;
113+
return false;
114114
} else {
115-
return TRUE;
115+
return true;
116116
}
117117
}
118118

@@ -141,7 +141,7 @@ File SDClass::open(const char *filepath, uint8_t mode)
141141
{
142142
File file = File(filepath);
143143

144-
if ((mode == FILE_WRITE) && (SD.exists(filepath) != TRUE)) {
144+
if ((mode == FILE_WRITE) && (!SD.exists(filepath))) {
145145
mode = mode | FA_CREATE_ALWAYS;
146146
}
147147

@@ -154,14 +154,14 @@ File SDClass::open(const char *filepath, uint8_t mode)
154154
/**
155155
* @brief Remove a file on the SD disk
156156
* @param filename: File name
157-
* @retval TRUE or FALSE
157+
* @retval true or false
158158
*/
159-
uint8_t SDClass::remove(const char *filepath)
159+
bool SDClass::remove(const char *filepath)
160160
{
161161
if (f_unlink(filepath) != FR_OK) {
162-
return FALSE;
162+
return false;
163163
} else {
164-
return TRUE;
164+
return true;
165165
}
166166
}
167167

@@ -455,17 +455,17 @@ uint32_t File::position()
455455
/**
456456
* @brief Seek to a new position in the file
457457
* @param pos: The position to which to seek
458-
* @retval TRUE or FALSE
458+
* @retval true or false
459459
*/
460-
uint8_t File::seek(uint32_t pos)
460+
bool File::seek(uint32_t pos)
461461
{
462462
if (pos > size()) {
463-
return FALSE;
463+
return false;
464464
} else {
465465
if (f_lseek(_fil, pos) != FR_OK) {
466-
return FALSE;
466+
return false;
467467
} else {
468-
return TRUE;
468+
return true;
469469
}
470470
}
471471
}
@@ -486,9 +486,9 @@ uint32_t File::size()
486486
File::operator bool()
487487
{
488488
#if _FATFS == 68300
489-
return ((_name == NULL) || ((_fil == NULL) && (_dir.obj.fs == 0)) || ((_fil != NULL) && (_fil->obj.fs == 0) && (_dir.obj.fs == 0))) ? FALSE : TRUE;
489+
return !((_name == NULL) || ((_fil == NULL) && (_dir.obj.fs == 0)) || ((_fil != NULL) && (_fil->obj.fs == 0) && (_dir.obj.fs == 0)));
490490
#else
491-
return ((_name == NULL) || ((_fil == NULL) && (_dir.fs == 0)) || ((_fil != NULL) && (_fil->fs == 0) && (_dir.fs == 0))) ? FALSE : TRUE;
491+
return !((_name == NULL) || ((_fil == NULL) && (_dir.fs == 0)) || ((_fil != NULL) && (_fil->fs == 0) && (_dir.fs == 0)));
492492
#endif
493493
}
494494
/**
@@ -584,7 +584,7 @@ char *File::name()
584584
* @brief Check if the file is directory or normal file
585585
* @retval TRUE if directory else FALSE
586586
*/
587-
uint8_t File::isDirectory()
587+
bool File::isDirectory()
588588
{
589589
FILINFO fno;
590590
if (_name == NULL) {
@@ -595,21 +595,21 @@ uint8_t File::isDirectory()
595595
#else
596596
if (_dir.fs != 0)
597597
#endif
598-
return TRUE;
598+
return true;
599599
#if _FATFS == 68300
600600
else if (_fil->obj.fs != 0)
601601
#else
602602
else if (_fil->fs != 0)
603603
#endif
604-
return FALSE;
604+
return false;
605605
// if not init get info
606606
if (f_stat(_name, &fno) == FR_OK) {
607607
if (fno.fattrib & AM_DIR) {
608-
return TRUE;
608+
return true;
609609
}
610610
}
611611
// Assume not a directory
612-
return FALSE;
612+
return false;
613613
}
614614

615615
File File::openNextFile(uint8_t mode)

src/STM32SD.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class File {
4343
virtual int available();
4444
virtual void flush();
4545
int read(void *buf, size_t len);
46-
uint8_t seek(uint32_t pos);
46+
bool seek(uint32_t pos);
4747
uint32_t position();
4848
uint32_t size();
4949
void close();
@@ -54,7 +54,7 @@ class File {
5454
{
5555
return _name;
5656
};
57-
uint8_t isDirectory();
57+
bool isDirectory();
5858
File openNextFile(uint8_t mode = FILE_READ);
5959
void rewindDirectory(void);
6060

@@ -81,13 +81,13 @@ class SDClass {
8181
public:
8282

8383
/* Initialize the SD peripheral */
84-
uint8_t begin(uint32_t detectpin = SD_DETECT_NONE);
84+
bool begin(uint32_t detectpin = SD_DETECT_NONE);
8585
static File open(const char *filepath, uint8_t mode);
8686
static File open(const char *filepath);
87-
static uint8_t exists(const char *filepath);
88-
static uint8_t mkdir(const char *filepath);
89-
static uint8_t remove(const char *filepath);
90-
static uint8_t rmdir(const char *filepath);
87+
static bool exists(const char *filepath);
88+
static bool mkdir(const char *filepath);
89+
static bool remove(const char *filepath);
90+
static bool rmdir(const char *filepath);
9191

9292
File openRoot(void);
9393

src/Sd2Card.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@
3737
#include <Arduino.h>
3838
#include "Sd2Card.h"
3939

40-
uint8_t Sd2Card::init(uint32_t detectpin)
40+
bool Sd2Card::init(uint32_t detectpin)
4141
{
4242
if (detectpin != SD_DETECT_NONE) {
4343
PinName p = digitalPinToPinName(detectpin);
4444
if ((p == NC) || \
4545
BSP_SD_DetectPin(set_GPIO_Port_Clock(STM_PORT(p)),
4646
STM_LL_GPIO_PIN(p)) != MSD_OK) {
47-
return FALSE;
47+
return false;
4848
}
4949
}
5050
if (BSP_SD_Init() == MSD_OK) {
5151
BSP_SD_GetCardInfo(&_SdCardInfo);
52-
return TRUE;
52+
return true;
5353
}
54-
return FALSE;
54+
return false;
5555
}
5656

5757
uint8_t Sd2Card::type(void) const

src/Sd2Card.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939

4040
#include "bsp_sd.h"
4141

42-
#define FALSE ((uint8_t)0x00)
43-
#define TRUE ((uint8_t)0x01)
44-
4542
// card types to match Arduino definition
4643
#define SD_CARD_TYPE_UKN 0
4744
/** Standard capacity V1 SD card */
@@ -56,7 +53,7 @@
5653
class Sd2Card {
5754
public:
5855

59-
uint8_t init(uint32_t detectpin = SD_DETECT_NONE);
56+
bool init(uint32_t detectpin = SD_DETECT_NONE);
6057

6158
/** Return the card type: SD V1, SD V2 or SDHC */
6259
uint8_t type(void) const;

0 commit comments

Comments
 (0)