From 3d026f4f31fd170f88d973d4574d2f9f6221ac7a Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Mon, 27 Dec 2021 00:19:13 -0800 Subject: [PATCH] Added support for SD, tweaked SD_MMC. --- ueforth/Makefile | 2 +- ueforth/esp32/bindings.fs | 12 ++++++++++++ ueforth/esp32/template.ino | 33 +++++++++++++++++++++++++++------ ueforth/site/ESP32forth.html | 24 ++++++++++++++++++++++-- 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/ueforth/Makefile b/ueforth/Makefile index 70a6228..d32f4b6 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -VERSION=7.0.6.7 +VERSION=7.0.6.8 STABLE_VERSION=7.0.5.4 REVISION=$(shell git rev-parse HEAD) REVSHORT=$(shell echo $(REVISION) | head -c 7) diff --git a/ueforth/esp32/bindings.fs b/ueforth/esp32/bindings.fs index 804ca29..8039228 100644 --- a/ueforth/esp32/bindings.fs +++ b/ueforth/esp32/bindings.fs @@ -56,10 +56,22 @@ transfer{ forth definitions +DEFINED? SD.begin [IF] +vocabulary SD SD definitions +transfer{ + SD.begin SD.end + SD.beginFull SD.beginDefaults + SD.totalBytes SD.usedBytes + SD.cardType +}transfer +forth definitions +[THEN] + DEFINED? SD_MMC.begin [IF] vocabulary SD_MMC SD_MMC definitions transfer{ SD_MMC.begin SD_MMC.end + SD_MMC.beginFull SD_MMC.beginDefaults SD_MMC.totalBytes SD_MMC.usedBytes SD_MMC.cardType }transfer diff --git a/ueforth/esp32/template.ino b/ueforth/esp32/template.ino index 404a50f..0985911 100644 --- a/ueforth/esp32/template.ino +++ b/ueforth/esp32/template.ino @@ -32,10 +32,11 @@ #define ENABLE_SOCKETS_SUPPORT #define ENABLE_FREERTOS_SUPPORT #define ENABLE_INTERRUPTS_SUPPORT +#define ENABLE_SD_SUPPORT // SD_MMC does not work on ESP32-S2 / ESP32-C3 #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) -# define ENABLE_SDCARD_SUPPORT +# define ENABLE_SD_MMC_SUPPORT #endif // ESP32-C3 has no DACs. @@ -170,7 +171,8 @@ OPTIONAL_WIFI_SUPPORT \ OPTIONAL_MDNS_SUPPORT \ OPTIONAL_WEBSERVER_SUPPORT \ - OPTIONAL_SDCARD_SUPPORT \ + OPTIONAL_SD_SUPPORT \ + OPTIONAL_SD_MMC_SUPPORT \ OPTIONAL_I2C_SUPPORT \ OPTIONAL_SERIAL_BLUETOOTH_SUPPORT \ OPTIONAL_CAMERA_SUPPORT \ @@ -344,12 +346,31 @@ Y(errno, PUSH errno) #endif -#ifndef ENABLE_SDCARD_SUPPORT -# define OPTIONAL_SDCARD_SUPPORT +#ifndef ENABLE_SD_SUPPORT +# define OPTIONAL_SD_SUPPORT +#else +# include "SD.h" +# define OPTIONAL_SD_SUPPORT \ + X("SD.begin", SD_BEGIN, PUSH SD.begin()) \ + X("SD.beginFull", SD_BEGIN_FULL, \ + tos = SD.begin(n5, *(SPIClass*)a4, n3, c2, n1, n0); NIPn(5)) \ + X("SD.beginDefaults", SD_BEGIN_DEFAULTS, \ + PUSH SS; PUSH &SPI; PUSH 4000000; PUSH "/sd"; PUSH 5; PUSH false) \ + X("SD.end", SD_END, SD.end()) \ + X("SD.cardType", SD_CARD_TYPE, PUSH SD.cardType()) \ + X("SD.totalBytes", SD_TOTAL_BYTES, PUSH SD.totalBytes()) \ + X("SD.usedBytes", SD_USED_BYTES, PUSH SD.usedBytes()) +#endif + +#ifndef ENABLE_SD_MMC_SUPPORT +# define OPTIONAL_SD_MMC_SUPPORT #else # include "SD_MMC.h" -# define OPTIONAL_SDCARD_SUPPORT \ - X("SD_MMC.begin", SD_MMC_BEGIN, tos = SD_MMC.begin(c1, n0); NIP) \ +# define OPTIONAL_SD_MMC_SUPPORT \ + X("SD_MMC.begin", SD_MMC_BEGIN, PUSH SD_MMC.begin()) \ + X("SD_MMC.beginFull", SD_MMC_BEGIN_FULL, tos = SD_MMC.begin(c2, n1, n0); NIPn(2)) \ + X("SD_MMC.beginDefaults", SD_MMC_BEGIN_DEFAULTS, \ + PUSH "/sdcard"; PUSH false; PUSH false) \ X("SD_MMC.end", SD_MMC_END, SD_MMC.end()) \ X("SD_MMC.cardType", SD_MMC_CARD_TYPE, PUSH SD_MMC.cardType()) \ X("SD_MMC.totalBytes", SD_MMC_TOTAL_BYTES, PUSH SD_MMC.totalBytes()) \ diff --git a/ueforth/site/ESP32forth.html b/ueforth/site/ESP32forth.html index 503f333..312127f 100644 --- a/ueforth/site/ESP32forth.html +++ b/ueforth/site/ESP32forth.html @@ -535,11 +535,31 @@ server ( port -- ) Start an image server at port, e.g. http://IP/image will produce an image +
SD
+These words are inside the SD vocabulary. +They allow use of an SDcard over SPI. +
+SD.begin ( -- ok )   uses all the defaults "/sd" etc.
+SD.beginDefaults ( -- sspin SPIClass frequency mountpointsz maxfiles format_if_empty )
+                 (    SS    SPI      4000000   "/sd"        5        false )
+SD.beginFull ( sspin SPIClass frequency mountpoint maxfiles format_if_empty -- ok )
+SD.end ( -- )
+SD.cardType ( -- n )
+SD.totalBytes ( -- n )
+SD.usedBytes ( -- n )
+
+
SD_MMC
-These words are inside the SD_MMC vocabulary.
+These words are inside the SD_MMC vocabulary. +They allow use of an SDcard over MMC internal interface. +
Note, SD_MMC is unavailable on ESP32-S2 and ESP32-C3.
-SD_MMC.begin ( mount mode1bit )   default mode1bit=false
+SD_MMC.begin ( -- ok )   uses all the defaults "/sdcard" etc.
+SD_MMC.beginDefaults ( -- mountsz   mode1bit format_if_fail )
+                     (    "/sdcard" false    false )
+                     (    sdmmc_freq not supported for generality )
+SD_MMC.beginFull ( mountsz mode1bit format_if_fail -- ok )
 SD_MMC.end ( -- )
 SD_MMC.cardType ( -- n )
 SD_MMC.totalBytes ( -- n )