mas - olikraus/m2tklib GitHub Wiki
The mass stroage API will be available with M2tklib v1.08. It is intended to be used with file selection dialogs.
The mass storage subsystem will support several libraries to access SD cards (see below).
The following section include code patterns to setup the mass storage system. Within the Arduino environment, the code is typically executed in the setup()
procedure.
#include <SD.h>
#include "mas.h"
...
pinMode(SS, OUTPUT); // force the hardware chip select to output
if (SD.begin(23)) // use the global SD object
mas_Init(mas_device_sd, NULL);
Arduino SD library description: http://arduino.cc/en/Reference/SD
#include "mas.h"
#include <SdFat.h>
...
SdFat sdfat;
...
pinMode(SS, OUTPUT); // force the hardware chip select to output
if ( sdfat.init(SPI_HALF_SPEED, 23) )
mas_Init(mas_device_sdfat, (void *)&sdfat);
SdFat
project: http://code.google.com/p/sdfatlib/
#include "mas.h"
#include "pff.h"
...
FATFS pff_fs;
...
if ( pf_mount(&pff_fs) == FR_OK )
mas_Init(mas_device_pff, &pff_fs);
PFF reference: Petit FAT File System
-
Include
mas.h
-
C Prototype
uint8_t mas_ChDir(const char *subdir);
- Description:
Change current directory to the specified folder (
subdir
).
-
Arguments:
-
subdir
: Name of the folder.
-
-
Returns: 0, if not successful.
-
Available: M2tklib v1.08
-
Note:
-
Example:
-
See also: mas_ChDirUp, mas_ChDirRoot
-
Include
mas.h
-
C Prototype
void mas_ChDirRoot(void);
- Description:
Change current directory to the root directory.
-
Arguments:
-
Returns: 0, if not successful.
-
Available: M2tklib v1.08
-
Note:
-
Example:
-
See also: mas_ChDir, mas_ChDirUp
-
Include
mas.h
-
C Prototype
uint8_t mas_ChDirUp(void);
- Description:
Change current directory to the parent folder.
-
Arguments:
-
subdir
: Name of the folder.
-
-
Returns: 0, if not successful.
-
Available: M2tklib v1.08
-
Note:
-
Example:
-
See also: mas_ChDir, mas_ChDirRoot
-
Include
mas.h
-
C Prototype
uint8_t mas_Init(mas_device_fn *device, void *arg);
- Description:
Setup a mass storage. The following devices are avilable: | Name | Arg | Description | |:-------------------|:---------|:----------------| |
mas_device_sim
|NULL
| A virtual device for testing and debugging | |mas_device_sd
|NULL
| Connect to the global SD object of Arduino SD library | |mas_device_sdfat
|SdFat *
| Connect to ArduinoSdFat
library | |mas_device_pff
|FATFS *
| Connect to Petit FAT File System |
-
Arguments:
-
device
: A mass storage device (see description) -
arg
: Argument for the mass storage device (see description)
-
-
Returns: 0, if not successful.
-
Available: M2tklib v1.08
-
Note:
-
Example:
-
See also: mas_GetDirEntry, mas_GetFilename
-
Include
mas.h
-
C Prototype
uint8_t mas_IsDir(void);
- Description:
Returns
!= 0
if the current entry is a directory name. The current entry is updated by mas_GetDirEntry. The name of the sub-directory is returned by mas_GetFilename.
-
Arguments:
-
Returns: 0, if the current directory entry is a normal file.
-
Available: M2tklib v1.08
-
Note:
-
Example:
-
See also: mas_GetDirEntry, mas_GetFilename
-
Include
mas.h
-
C Prototype
uint8_t mas_GetDirEntry(uint16_t n);
- Description:
Load the directory entry at the specified position into the internal buffer.
-
Arguments:
-
n
: Directory entry at the specified positionn
(0
...mas_GetDirEntryCnt()-1
)
-
-
Returns: 0, if not successful.
-
Available: M2tklib v1.08
-
Note: When used together with
M2_STRLIST
: Maximum number of entries forM2_STRLIST
is limited to 254. -
Example:
-
See also: mas_GetDirEntryCnt
-
Include
mas.h
-
C Prototype
uint16_t mas_GetDirEntryCnt(void);
- Description:
Returns the number of directory entries in the current directory.
-
Arguments:
-
Returns: Number of directory entries in the current directory.
-
Available: M2tklib v1.08
-
Note: When used together with
M2_STRLIST
: Maximum number of entries forM2_STRLIST
must be limited to 254. -
Example:
-
See also: mas_GetDirEntry
-
Include
mas.h
-
C Prototype
const char *mas_GetFilename(void);
- Description:
Returns the current file name. The current filename is updated by mas_GetDirEntry.
-
Arguments:
-
Returns: Pointer to an internal buffer with the name of the current file entry.
-
Available: M2tklib v1.08
-
Note:
-
Example:
-
See also: mas_GetDirEntry
-
Include
mas.h
-
C Prototype
const char *mas_GetPath(void);
- Description:
Returns the current directory. The current directory is modified by mas_ChDir, mas_ChDirUp and mas_ChDirRoot
-
Arguments:
-
Returns: Pointer to an internal buffer with the current working directory.
-
Available: M2tklib v1.08
-
Note:
-
Example:
-
See also: mas_ChDir, mas_ChDirUp
-
Include
mas.h
-
C Prototype
const char *mas_GetPathFilename(void);
- Description:
Returns the current directory together with the current filename. The current directory is modified by mas_ChDir, mas_ChDirUp and mas_ChDirRoot. The current filename is updated by mas_GetDirEntry.
-
Arguments:
-
Returns: Pointer to an internal buffer with the full path of the current file entry.
-
Available: M2tklib v1.08
-
Note:
-
Example:
-
See also: mas_ChDir, mas_ChDirUp, mas_GetDirEntry