APM:Libraries
SdFatFs.h
Go to the documentation of this file.
1 /*
2 
3  intermediate layer for FatFs
4 
5  */
6 #ifndef SdFatFs_h
7 #define SdFatFs_h
8 
9 #include "Sd2Card.h"
10 #include "stdio.h"
11 
12 #if defined(BOARD_SDCARD_CS_PIN) || defined(BOARD_DATAFLASH_FATFS)
13 
14 /* FatFs includes component */
15 #include "FatFs/drivers/sd.h"
16 #include "FatFs/ff.h"
17 
18 
19 // To match Arduino definition
20 #define FILE_WRITE FA_WRITE
21 #define FILE_READ FA_READ
22 
24 static inline uint16_t FAT_YEAR(uint16_t fatDate) {
25  return 1980 + (fatDate >> 9);
26 }
28 static inline uint8_t FAT_MONTH(uint16_t fatDate) {
29  return (fatDate >> 5) & 0XF;
30 }
32 static inline uint8_t FAT_DAY(uint16_t fatDate) {
33  return fatDate & 0X1F;
34 }
35 
37 static inline uint8_t FAT_HOUR(uint16_t fatTime) {
38  return fatTime >> 11;
39 }
41 static inline uint8_t FAT_MINUTE(uint16_t fatTime) {
42  return(fatTime >> 5) & 0X3F;
43 }
45 static inline uint8_t FAT_SECOND(uint16_t fatTime) {
46  return 2*(fatTime & 0X1F);
47 }
48 
49 class SdFatFs {
50  public:
51 
52  SdFatFs(){}
53 
54  FRESULT init(Sd2Card *card);
55 
57  uint8_t fatType(void);
58 
59  // inline functions that return volume info
61  uint8_t blocksPerCluster(void) const {return _SDFatFs.csize ? _SDFatFs.csize : blockSize();}
63  inline uint32_t clusterCount(void) const {return _SDFatFs.n_fatent? _SDFatFs.n_fatent -2:0;}
64 
65  // returns raw volume size
66  inline uint32_t sectorCount(void) const { return _card->sectorCount(); }
67  inline uint32_t sectorSize(void) const { return _card->sectorSize(); }
68  inline uint32_t blockSize(void) const { return _card->blockSize(); }
69 
70  inline char* getRoot(void) { return _SDPath; };
71  FRESULT format(const char *filepath, Sd2Card *card);
72 
73  static const char *strError(FRESULT err);
74 
75 private:
76  FATFS _SDFatFs; /* File system object for SD disk logical drive */
77  char _SDPath[4]; /* SD disk logical drive path */
78  Sd2Card *_card;
79 };
80 #endif
81 #endif // sdFatFs_h
82 
Definition: ff.h:99
FRESULT
Definition: ff.h:243
void init()
Generic board initialization function.
Definition: system.cpp:136