ESP32 SPI SD Card library.
This commit adds ESP32's SPI SD Host Controller support for mruby/c.
You can use stdio.h
and driver/sdspi_host.h
APIs from mruby/c with this commit.
This program doesn't check arguments.
So if you use wrongly(e.g. you passed wrong typed values or not enough count of arguments), it segfaults.
(C) Matsue College of Technology.
このプログラムは松江高専の授業中に作成されました.
This class have methods about SPI initialization and FileSystem mounting.
This class only have one SD card and first partition.
You want to extend to be able to use multiple SD card, you should create instancing-able class about SD card.
That class must hold sdmmc_host_t
and sdmmc_card_t
.
mruby/c seems to have special method to create instance with additional space to remember C structures, but it is not documented and cannot guarantee the class have additional space DEFINITELY.
If you want to see second and later partitions, you may create vfs program yourself because I can't find any API to look other partitions.
Pass SPI pin numbers, MOSI(Master out slave in), MISO(Master in slave out), SCLK(SPI Clock).
This method initializes SPI Bus.
If success, return true
, otherwise false
.
Pass CS(Chip Select, also called Slave Select).
2nd argument is a path where to mount on. e.g. "/sdcard"
.
This method initializes vfs module and mount file system.
If success, return true
, otherwise false
.
This method unmounts file system.
If success, return true
, otherwise false
.
This method frees the SPI Bus.
This returns nothing.
This class provides stdio.h
functions.
You can open up to 8 files.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html
This returns file id
instead of FILE
pointer. If fails, return -1
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fclose.html
This need file id
instead of FILE
pointer.
If success, return true
, otherwise false
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fputs.html
This need file id
instead of FILE
pointer and String
instead of char
pointer.
If success, return true
, otherwise false
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fputc.html
This need file id
instead of FILE
pointer and String
instead of char
.
If success, return true
, otherwise false
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fwrite.html
This need file id
instead of FILE
pointer and String
instead of char
.
If success, return true
, otherwise false
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fputc.html
This need file id
instead of FILE
pointer and String
instead of char
.
If success, return true
, otherwise false
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fgets.html
This need file id
instead of FILE
pointer.
If success, return content typed String
, otherwise nil
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fread.html
This need file id
instead of FILE
pointer.
If success, return content typed String
, otherwise nil
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fgetc.html
This need file id
instead of FILE
pointer.
If success, return content typed String
, otherwise nil
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html
This need file id
instead of FILE
pointer.
If success, return true
, otherwise false
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fgetpos.html
This need file id
instead of FILE
pointer.
If success, return true
, otherwise false
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsetpos.html
This need file id
instead of FILE
pointer.
If success, return true
, otherwise false
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fseek.html
This need file id
instead of FILE
pointer.
SEEK_SET
is 0
, SEEK_CUR
is 1
, SEEK_END
is 2
.
If success, return true
, otherwise false
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/remove.html
If success, return true
, otherwise false
.
See https://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html
If success, return true
, otherwise false
.
This class provides directory information and file time stamp API.
Enumerated files contained selected directory(argument directory
).
If succeeded, return array of String, name of files contained, otherwise nil
.
Enumerated directories contained selected directory(argument directory
).
If succeeded, return array of String, name of directories contained, otherwise nil
.
Enumerated both files and directories contained selected directory(argument directory
).
If succeeded, return array of String, name of entries contained, otherwise nil
.
Get created date of given file.
If succeeded, return ESP32_FILETIME
, otherwise nil
.
ESP32_FILETIME
have these members, all return values are Integer
.
getYear()
, getMonth()
, getDay()
, getDayOfWeek()
, getHour()
, getMinute()
, getSecond()
.