ZEReader 0.1.0
A Zephyr-based E-Book-Reader
Loading...
Searching...
No Matches
SD card file management

Functions

char * sd_build_full_path (const char *folder, const char *filename, int *error)
 Returns a char pointer on the fully built-up SD card path.
int sd_initialize (void)
 Initializes the SD card communication.
int sd_open (char const *const path, struct fs_file_t *f_obj)
 Open a file on a SD card.
int sd_close (struct fs_file_t *f_obj)
 Close a file on a SD card.
int sd_read (struct fs_file_t *f_obj, char *buffer, size_t *size)
 Read from a file on a SD card.
int sd_read_chunk (char const *const path, size_t *offset, char *const buffer, size_t *size)
 Open, read from a file on SD card and close it.
int sd_write_chunk (char const *const path, char const *const data, size_t *size)
 Open, write to a file on SD card and close it.
int sd_list_directories (char const *const path, char *buffer, size_t *size)
 List the directories on the SD card.
int sd_tell_end_offset (char const *const path, size_t *offset)
 Get the current location of the file pointer inside the file.

Detailed Description

Function Documentation

◆ sd_build_full_path()

char * sd_build_full_path ( const char * folder,
const char * filename,
int * error )

Returns a char pointer on the fully built-up SD card path.

Parameters
[in]folderThe folder's name
[in]filenameThe file's name
[in,out]errorAn int-typed error value
Return values
0on success.
-ENAMETOOLONGIf the path length is longer than CONFIG_FS_FATFS_MAX_LFN (255).
-ENOMEMIf there is not enough RAM left to allocate memory for the full path.

◆ sd_close()

int sd_close ( struct fs_file_t * f_obj)

Close a file on a SD card.

Parameters
[in]f_objA pointer to the file object representing the file.
Return values
0on success.

◆ sd_initialize()

int sd_initialize ( void )

Initializes the SD card communication.

Return values
-ENODEVIf the device was not found.
<0If getting the sector count or size failed or the card could not get mounted.

◆ sd_list_directories()

int sd_list_directories ( char const *const path,
char * buffer,
size_t * size )

List the directories on the SD card.

Parameters
[in]pathThe path on the SD card to be listed.
[in,out]bufferA pointer to the data buffer to be written.
[in,out]sizeThe maximum number of bytes to be written.
Return values
>=0the number of bytes written, on success.

◆ sd_open()

int sd_open ( char const *const path,
struct fs_file_t * f_obj )

Open a file on a SD card.

Parameters
[in]pathThe file's full path.
[in,out]f_objA pointer to the file object representing the file.
Return values
0on success.

◆ sd_read()

int sd_read ( struct fs_file_t * f_obj,
char * buffer,
size_t * size )

Read from a file on a SD card.

Parameters
[in,out]f_objA file object representing the file.
[in,out]bufferA pointer to the data buffer.
[in,out]sizeThe number of bytes to read.
Return values
>=0a number of bytes read, on success.

◆ sd_read_chunk()

int sd_read_chunk ( char const *const path,
size_t * offset,
char *const buffer,
size_t * size )

Open, read from a file on SD card and close it.

Parameters
[in]pathThe name of the file to read from.
[in,out]offsetRelative location to move the file pointer to.
[in,out]bufferA pointer to the data buffer.
[in,out]sizeThe number of bytes to read.
Return values
>=0a number of bytes read, on success.

◆ sd_tell_end_offset()

int sd_tell_end_offset ( char const *const path,
size_t * offset )

Get the current location of the file pointer inside the file.

Parameters
[in]pathThe name of the file.
[in,out]offsetThe offset within the file.
Return values
0on success.

◆ sd_write_chunk()

int sd_write_chunk ( char const *const path,
char const *const data,
size_t * size )

Open, write to a file on SD card and close it.

Parameters
[in]pathThe name of the file to write to.
[in]dataA pointer to the data buffer to be written.
[in,out]sizeThe number of bytes to be written.
Return values
0on success.