whiskers 0.2.0
RP2350 BadUSB Tool
Loading...
Searching...
No Matches
disk.h File Reference

Detailed Description

HAL disk functions.

Author
zane

This file contains all the functions required to initialize and manage the disk (SD card).

Note as per usual with HAL functions, the proper structs and underlying memory is set by the functions.

Example mounting and formatting the disk

Here is an example snippet of code that initializes the disk, mounts it, and if no filesystem is found creates one.

#include "hal/shared.h"
#include "hal/disk.h"
_DISK_INFO di;
// Initialize the SD card
disk_init(&di);
// Try to mount the drive
if(!disk_mount(&di))
{
if(di.errno == HAL_FS_NO_FS)
{
// If no filesystem found make one!
if(!disk_format_ff(&di))
{
printf("Disk unable to be formatted: %s\n",HAL_ERROR_to_str(di.errno));
} else {
printf("Disk formatted with FatFS succesfully!\n");
}
} else {
printf("Disk unable to be mounted: %s\n",HAL_ERROR_to_str(di.errno));
}
} else {
printf("Disk mounted with FatFS succesfully!\n");
}
... // Have the rest of your program's code here
// When we're done with the drive unmount it
if(!disk_umount(&di))
{
printf("Disk unabled to be un-mounted: %s\n",HAL_ERROR_to_str(di.errno));
} else {
printf("Disk un-mounted!\n");
}
HAL disk functions.
bool disk_mount(_DISK_INFO *di)
Mounts the disk and checks for a FatFS.
bool disk_umount(_DISK_INFO *di)
Unmounts the disk regardless of filesystem status.
bool disk_format_ff(_DISK_INFO *di)
Creates a FatFS on the disk.
void disk_init(_DISK_INFO *di)
Sets all the variables required for the disk and then initializes the SD library.
Shared structs, error codes, and functions for all HAL files.
#define HAL_FS_NO_FS
Disk mounted but not FatFS found.
Definition shared.h:87
HAL_ERROR errno
Definition shared.h:265
See also
shared.h
#include "shared.h"

Go to the source code of this file.

Functions

void disk_init (_DISK_INFO *di)
 Sets all the variables required for the disk and then initializes the SD library.
bool disk_mount (_DISK_INFO *di)
 Mounts the disk and checks for a FatFS.
bool disk_umount (_DISK_INFO *di)
 Unmounts the disk regardless of filesystem status.
bool disk_format_ff (_DISK_INFO *di)
 Creates a FatFS on the disk.
bool disk_is_physically_mounted ()
 Checks if a SD card is currently present in the device.

Function Documentation

◆ disk_format_ff()

bool disk_format_ff ( _DISK_INFO * di)

Creates a FatFS on the disk.

Parameters
*di_DISK_INFO pointer to manage the FatFS and to set errno

Creates a FatFS (Fat version determined by the library internally) spanning the entire working space of the disk. This will erase all of the data already on the disk.

Returns
True on success/False on failure. di.errno is set on failure

◆ disk_init()

void disk_init ( _DISK_INFO * di)

Sets all the variables required for the disk and then initializes the SD library.

Parameters
*di_DISK_INFO pointer to store the resulting SD pointers.

Note that this function only sets hardware configuration values and doesn't actually mount the drive or do any FatFS related operations. This must be called first before any of the other functions.

◆ disk_is_physically_mounted()

bool disk_is_physically_mounted ( )

Checks if a SD card is currently present in the device.

Note: the lower level implementation of this either uses the underlying SD library to check for a connection, or the physical chip select switch on the SD card slot. This is configured in shared.h under the HAL_SD_USE_HW_CD definition. Either way, it is reliable enough to use.

See also
HAL_SD_USE_HW_CD
Returns
True on card inserted/False on card not inserted.

◆ disk_mount()

bool disk_mount ( _DISK_INFO * di)

Mounts the disk and checks for a FatFS.

Parameters
*di_DISK_INFO pointer to store the internal filesytem information and to set errno and the mounted status

This function mounts the device and checks for a valid filesystem. If none is found then HAL_FS_NO_FS is set as the errno for no filesystem. Any other error that occurs is set as well. If no fileystem is found then one must be created.

See also
disk_format_ff()
Returns
True on success/False on failure. di.errno is set on failure

◆ disk_umount()

bool disk_umount ( _DISK_INFO * di)

Unmounts the disk regardless of filesystem status.

Parameters
*di_DISK_INFO pointer to manage the FatFS and to set errno and mounted status.
Returns
True on success/False on failure. di.errno is set on failure