PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
|
#include <libpropeller/libpropeller/sd/sd.h>
Public Member Functions | |
~SD () | |
void | Mount (const int basepin) |
void | Mount (const int pin_do, const int pin_clk, const int pin_di, const int pin_cs) |
void | Unmount (void) |
void | Open (const char *filename, const char file_mode) |
void | Close (void) |
int | Get (void) |
int | Get (char *read_buffer, int bytes_to_read_count) |
int | Put (const char C) |
int | Put (const char *B) |
int | Put (const char *buffer, int byte_count) |
int | PutFormatted (const char *formatString,...) |
void | OpenRootDirectory (void) |
bool | NextFile (char *filename) |
bool | NextFile (char *filename, int &filesize) |
bool | NextFile (char *filename, int &filesize, int &year, int &month, int &day, int &hour, int &minute, int &second) |
int | Seek (const int position) |
int | SetDate (const int year, const int month, const int day, const int hour, const int minute, const int second) |
bool | HasError (void) const |
void | ClearError (void) |
int | GetError (void) const |
int | GetClusterSize (void) const |
int | GetClusterCount (void) const |
int | GetFilesize (void) const |
FAT16/32 SD card interface.
This class is based on the Spin version of FSRW 2.6 by Rokicki and Lonesock. Thanks!
This object provides FAT16/32 file read/write access on a block device. Only one file can be open at a time. Open modes are 'r' (read), 'a' (append), 'w' (write), and 'd' (delete). Only the root directory is supported. No long filenames are supported. This object also supports traversing the root directory.
This object requires pullup resistors on the four SD card I/O lines. The pullup resistors should be approximately 10kOhms each.
The SPI DO, DI, and CLK lines can be shared with other SPI devices, as long as the Release() command is called after doing SD card activities and before doing other SPI activities. Note: this has not been tested at all.
Cluster size: If it's not 32768, it should be (32K clusters). To format a drive with FAT32 with 32K clusters, use the following command under linux: sudo fdisk -l sudo mkdosfs /dev/sdX -s 64 -F 32 -I
To check the filesystem under linux: sudo dosfsck -v /dev/sdX
Note: the mkdosfs command will format the entire disk, and erase all information on it.
If an exceptional error occurs then the HasError() function will return true. To see what went wrong, query the GetError() function. After you fix the error, clear it with ClearError(); Every function may set the error, although you're generally OK with just checking after Mount() and Open()
Possible improvements: Write a function that gets a string: int Get(char * Ubuf, char EndOfStringChar);
libpropeller::SD::~SD | ( | ) |
void libpropeller::SD::ClearError | ( | void | ) |
void libpropeller::SD::Close | ( | void | ) |
int libpropeller::SD::Get | ( | char * | read_buffer, |
int | bytes_to_read_count | ||
) |
Read bytes into a buffer from currently open file.
Note that this function does not null terminate a string.
read_buffer | The buffer to store the data. The buffer may be as large as you want. |
bytes_to_read_count | The number of bytes to read. |
int libpropeller::SD::Get | ( | void | ) |
int libpropeller::SD::GetClusterCount | ( | void | ) | const |
int libpropeller::SD::GetClusterSize | ( | void | ) | const |
int libpropeller::SD::GetError | ( | void | ) | const |
int libpropeller::SD::GetFilesize | ( | void | ) | const |
bool libpropeller::SD::HasError | ( | void | ) | const |
void libpropeller::SD::Mount | ( | const int | basepin | ) |
void libpropeller::SD::Mount | ( | const int | pin_do, |
const int | pin_clk, | ||
const int | pin_di, | ||
const int | pin_cs | ||
) |
Mount a volume with explicit pin numbers. Does not require adjacent pins.
pin_do | The SPI Data Out pin (ouput relative to Propeller). |
pin_clk | The SPI Clock pin. |
pin_di | The SPI Data In pin (input relative to Propeller). |
pin_cs | The Chip Select pin. |
Definition at line 125 of file sd.h.
bool libpropeller::SD::NextFile | ( | char * | filename | ) |
Close any currently open file, and open a new one with the given file name and mode.
The filename should be in 8.3 format (up to eight characters, a period, and up to three characters. The filename will be converted to uppercase. Valid characters include A through Z, digits 0 through 9, space, and '$', '', '-', '_', '@', '~', '‘’, '!', '(', ')', '{', '}', '^', '#', '&' and a single '.'. Filenames can be shorter than 8.3. The behavior for invalid filenames is undefined.
Modes:
filename | Filename in 8.3 format. |
file_mode | one of the modes described above |
Definition at line 232 of file sd.h.
void libpropeller::SD::OpenRootDirectory | ( | void | ) |
int libpropeller::SD::Put | ( | const char * | B | ) |
Write a null-terminated string to the file.
B | The null-terminated string to write. No size limitations. Does not write the null terminator. |
Definition at line 461 of file sd.h.
int libpropeller::SD::Put | ( | const char * | buffer, |
int | byte_count | ||
) |
Write bytes from buffer into the currently open file.
buffer | The buffer to pull the data from. The buffer may be as large as you want. |
byte_count | the number of bytes to write. |
int libpropeller::SD::Put | ( | const char | C | ) |
int libpropeller::SD::Seek | ( | const int | position | ) |
Change the read pointer to a different position in the file.
Seek() works only in 'r' (read) mode.
position | The position to seek to, relative to the beginning of the file. Units? |
int libpropeller::SD::SetDate | ( | const int | year, |
const int | month, | ||
const int | day, | ||
const int | hour, | ||
const int | minute, | ||
const int | second | ||
) |
Set the current date and time for file creation and last modified.
This date and time will remain constant until the next time SetDate() is called.
year | The year (range 1980 - 2106, all 4 digits!) |
month | The month (range 1-12) |
day | The day (range 1-31) |
hour | The hour (range 0-23) |
minute | The minute (range 0-59) |
second | The second (range 0-59) |
Definition at line 648 of file sd.h.
void libpropeller::SD::Unmount | ( | void | ) |