diff --git a/Makefile b/Makefile index f554428..0e4966e 100644 --- a/Makefile +++ b/Makefile @@ -285,13 +285,22 @@ ESP32_BOOT = $(COMMON_PHASE1) \ $(GEN)/esp32_boot.h: tools/source_to_string.js $(ESP32_BOOT) | $(GEN) $< boot $(VERSION) $(REVISION) $(ESP32_BOOT) >$@ -ESP32_ASSEMBLERS = common/assembler.fs \ - esp32/xtensa-assembler.fs \ - esp32/riscv-assembler.fs -$(GEN)/esp32_assemblers.h: tools/source_to_string.js $(ESP32_ASSEMBLERS) | $(GEN) - $< assemblers_source $(VERSION) $(REVISION) $(ESP32_ASSEMBLERS) >$@ +$(GEN)/esp32_assembler.h: tools/source_to_string.js common/assembler.fs | $(GEN) + $< assembler_source $(VERSION) $(REVISION) common/assembler.fs >$@ -OPTIONAL_MODULES = $(ESP32)/ESP32forth/assemblers.h +$(GEN)/esp32_xtensa-assembler.h: \ + tools/source_to_string.js esp32/optional/assemblers/xtensa-assembler.fs | $(GEN) + $< xtensa_assembler_source $(VERSION) $(REVISION) \ + esp32/optional/assemblers/xtensa-assembler.fs >$@ + +$(GEN)/esp32_riscv-assembler.h: \ + tools/source_to_string.js esp32/optional/assemblers/riscv-assembler.fs | $(GEN) + $< riscv_assembler_source $(VERSION) $(REVISION) \ + esp32/optional/assemblers/riscv-assembler.fs >$@ + +OPTIONAL_MODULES = \ + $(ESP32)/ESP32forth/oled.h \ + $(ESP32)/ESP32forth/assemblers.h add-optional: $(OPTIONAL_MODULES) @@ -301,6 +310,9 @@ drop-optional: $(ESP32)/ESP32forth/assemblers.h: $(ESP32)/ESP32forth/optional/assemblers.h cp $< $@ +$(ESP32)/ESP32forth/oled.h: $(ESP32)/ESP32forth/optional/oled.h + cp $< $@ + $(GEN)/dump_web_opcodes: \ web/dump_web_opcodes.c \ common/tier0_opcodes.h \ @@ -564,18 +576,30 @@ $(ESP32)/ESP32forth/README.txt: esp32/README.txt | $(ESP32)/ESP32forth >$@ $(ESP32)/ESP32forth/optional/README-optional.txt: \ - esp32/README-optional.txt | $(ESP32)/ESP32forth/optional - cat esp32/README-optional.txt | tools/replace.js \ + esp32/optional/README-optional.txt | $(ESP32)/ESP32forth/optional + cat esp32/optional/README-optional.txt | tools/replace.js \ VERSION=$(VERSION) \ REVISION=$(REVISION) \ >$@ $(ESP32)/ESP32forth/optional/assemblers.h: \ - esp32/assemblers.h $(GEN)/esp32_assemblers.h | $(ESP32)/ESP32forth/optional - cat esp32/assemblers.h | tools/replace.js \ + esp32/optional/assemblers/assemblers.h \ + $(GEN)/esp32_assembler.h \ + $(GEN)/esp32_xtensa-assembler.h \ + $(GEN)/esp32_riscv-assembler.h | $(ESP32)/ESP32forth/optional + cat esp32/optional/assemblers/assemblers.h | tools/replace.js \ + VERSION=$(VERSION) \ + REVISION=$(REVISION) \ + assembler=@$(GEN)/esp32_assembler.h \ + xtensa_assembler=@$(GEN)/esp32_xtensa-assembler.h \ + riscv_assembler=@$(GEN)/esp32_riscv-assembler.h \ + >$@ + +$(ESP32)/ESP32forth/optional/oled.h: \ + esp32/optional/oled.h | $(ESP32)/ESP32forth/optional + cat esp32/optional/oled.h | tools/replace.js \ VERSION=$(VERSION) \ REVISION=$(REVISION) \ - assemblers=@$(GEN)/esp32_assemblers.h \ >$@ # ---- ESP32 ARDUINO BUILD AND FLASH ---- @@ -672,7 +696,8 @@ $(ESP32)/ESP32forth.zip: \ $(ESP32)/ESP32forth/ESP32forth.ino \ $(ESP32)/ESP32forth/README.txt \ $(ESP32)/ESP32forth/optional/README-optional.txt \ - $(ESP32)/ESP32forth/optional/assemblers.h + $(ESP32)/ESP32forth/optional/assemblers.h \ + $(ESP32)/ESP32forth/optional/oled.h cd $(ESP32) && rm -f ESP32forth.zip && zip -r ESP32forth.zip ESP32forth # ---- Publish to Archive ---- diff --git a/esp32/builtins.h b/esp32/builtins.h index 8234713..8f88a89 100644 --- a/esp32/builtins.h +++ b/esp32/builtins.h @@ -36,6 +36,13 @@ # define OPTIONAL_ASSEMBLERS_SUPPORT # endif +// Hook to pull in words from optional oled.h +# if __has_include("oled.h") +# include "oled.h" +# else +# define OPTIONAL_OLED_SUPPORT +# endif + static cell_t ResizeFile(cell_t fd, cell_t size); #endif @@ -624,37 +631,3 @@ static cell_t FromIP(IPAddress ip) { /* mDNS */ \ X("MDNS.begin", MDNS_BEGIN, n0 = MDNS.begin(c0)) #endif - -#ifndef ENABLE_OLED_SUPPORT -# define OPTIONAL_OLED_SUPPORT -#else -# ifndef SIM_PRINT_ONLY -# include -# include -static Adafruit_SSD1306 *oled_display = 0; -# endif -# define OPTIONAL_OLED_SUPPORT \ - YV(oled, OledAddr, PUSH &oled_display) \ - YV(oled, OledNew, oled_display = new Adafruit_SSD1306(n2, n1, &Wire, n0); DROPn(3)) \ - YV(oled, OledDelete, delete oled_display) \ - YV(oled, OledBegin, n0 = oled_display->begin(n1, n0); NIP) \ - YV(oled, OledHOME, oled_display->setCursor(0,0); DROP) \ - YV(oled, OledCLS, oled_display->clearDisplay()) \ - YV(oled, OledTextc, oled_display->setTextColor(n0); DROP) \ - YV(oled, OledPrintln, oled_display->println(c0); DROP) \ - YV(oled, OledNumln, oled_display->println(n0); DROP) \ - YV(oled, OledNum, oled_display->print(n0); DROP) \ - YV(oled, OledDisplay, oled_display->display()) \ - YV(oled, OledPrint, oled_display->write(c0); DROP) \ - YV(oled, OledInvert, oled_display->invertDisplay(n0); DROP) \ - YV(oled, OledTextsize, oled_display->setTextSize(n0); DROP) \ - YV(oled, OledSetCursor, oled_display->setCursor(n1,n0); DROPn(2)) \ - YV(oled, OledPixel, oled_display->drawPixel(n2, n1, n0); DROPn(2)) \ - YV(oled, OledDrawL, oled_display->drawLine(n4, n3, n2, n1, n0); DROPn(4)) \ - YV(oled, OledCirc, oled_display->drawCircle(n3,n2, n1, n0); DROPn(3)) \ - YV(oled, OledCircF, oled_display->fillCircle(n3, n2, n1, n0); DROPn(3)) \ - YV(oled, OledRect, oled_display->drawRect(n4, n3, n2, n1, n0); DROPn(4)) \ - YV(oled, OledRectF, oled_display->fillRect(n4, n3, n2, n1, n0); DROPn(3)) \ - YV(oled, OledRectR, oled_display->drawRoundRect(n5, n4, n3, n2, n1, n0); DROPn(5)) \ - YV(oled, OledRectRF, oled_display->fillRoundRect(n5, n4, n3, n2, n1, n0 ); DROPn(5)) -#endif diff --git a/esp32/README-optional.txt b/esp32/optional/README-optional.txt similarity index 95% rename from esp32/README-optional.txt rename to esp32/optional/README-optional.txt index 8ef66e8..2d69e4e 100644 --- a/esp32/README-optional.txt +++ b/esp32/optional/README-optional.txt @@ -10,6 +10,7 @@ into the parent directory, next to the ESPforth.ino file. These are the current optional modules: * assemblers.h - Assemblers for ESP32 Xtensa and ESP32 RISC-V + * oled.h - Support for the SSD1306 Oled Initially ESP32forth focused on a minimal C kernel, with most functionality built in Forth code loaded at boot. Eventually, as support for more capabilities diff --git a/esp32/assemblers.h b/esp32/optional/assemblers/assemblers.h similarity index 53% rename from esp32/assemblers.h rename to esp32/optional/assemblers/assemblers.h index ae63305..6522e9a 100644 --- a/esp32/assemblers.h +++ b/esp32/optional/assemblers/assemblers.h @@ -19,8 +19,27 @@ * Revision: {{REVISION}} */ -{{assemblers}} - #define OPTIONAL_ASSEMBLERS_SUPPORT \ - XV(internals, "assemblers-source", ASSEMBLERS_SOURCE, \ - PUSH assemblers_source; PUSH sizeof(assemblers_source)) + XV(internals, "assembler-source", ASSEMBLER_SOURCE, \ + PUSH assembler_source; PUSH sizeof(assembler_source) - 1) \ + PLATFORM_ASSEMBLER_SUPPORT + +{{assembler}} + +#if defined(__riscv) + +# define PLATFORM_ASSEMBLER_SUPPORT \ + XV(internals, "riscv-assembler-source", RISCV_ASSEMBLER_SOURCE, \ + PUSH riscv_assembler_source; PUSH sizeof(riscv_assembler_source) - 1) + +{{riscv_assembler}} + +#else + +# define PLATFORM_ASSEMBLER_SUPPORT \ + XV(internals, "xtensa-assembler-source", XTENSA_ASSEMBLER_SOURCE, \ + PUSH xtensa_assembler_source; PUSH sizeof(xtensa_assembler_source) - 1) + +{{xtensa_assembler}} + +#endif diff --git a/esp32/riscv-assembler.fs b/esp32/optional/assemblers/riscv-assembler.fs similarity index 100% rename from esp32/riscv-assembler.fs rename to esp32/optional/assemblers/riscv-assembler.fs diff --git a/esp32/xtensa-assembler.fs b/esp32/optional/assemblers/xtensa-assembler.fs similarity index 100% rename from esp32/xtensa-assembler.fs rename to esp32/optional/assemblers/xtensa-assembler.fs diff --git a/esp32/optional/oled.h b/esp32/optional/oled.h new file mode 100644 index 0000000..05a21ec --- /dev/null +++ b/esp32/optional/oled.h @@ -0,0 +1,53 @@ +// Copyright 2023 Bradley D. Nelson +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/* + * ESP32forth Assemblers v{{VERSION}} + * Revision: {{REVISION}} + */ + +// You will need to install these libraries from the Library Manager: +// Adafruit SSD1306 +// Adafruit GFX Library +// Adafruit BusIO + +# ifndef SIM_PRINT_ONLY +# include +# include +static Adafruit_SSD1306 *oled_display = 0; +# endif +# define OPTIONAL_OLED_SUPPORT \ + YV(oled, OledAddr, PUSH &oled_display) \ + YV(oled, OledNew, oled_display = new Adafruit_SSD1306(n2, n1, &Wire, n0); DROPn(3)) \ + YV(oled, OledDelete, delete oled_display) \ + YV(oled, OledBegin, n0 = oled_display->begin(n1, n0); NIP) \ + YV(oled, OledHOME, oled_display->setCursor(0,0); DROP) \ + YV(oled, OledCLS, oled_display->clearDisplay()) \ + YV(oled, OledTextc, oled_display->setTextColor(n0); DROP) \ + YV(oled, OledPrintln, oled_display->println(c0); DROP) \ + YV(oled, OledNumln, oled_display->println(n0); DROP) \ + YV(oled, OledNum, oled_display->print(n0); DROP) \ + YV(oled, OledDisplay, oled_display->display()) \ + YV(oled, OledPrint, oled_display->write(c0); DROP) \ + YV(oled, OledInvert, oled_display->invertDisplay(n0); DROP) \ + YV(oled, OledTextsize, oled_display->setTextSize(n0); DROP) \ + YV(oled, OledSetCursor, oled_display->setCursor(n1,n0); DROPn(2)) \ + YV(oled, OledPixel, oled_display->drawPixel(n2, n1, n0); DROPn(2)) \ + YV(oled, OledDrawL, oled_display->drawLine(n4, n3, n2, n1, n0); DROPn(4)) \ + YV(oled, OledCirc, oled_display->drawCircle(n3,n2, n1, n0); DROPn(3)) \ + YV(oled, OledCircF, oled_display->fillCircle(n3, n2, n1, n0); DROPn(3)) \ + YV(oled, OledRect, oled_display->drawRect(n4, n3, n2, n1, n0); DROPn(4)) \ + YV(oled, OledRectF, oled_display->fillRect(n4, n3, n2, n1, n0); DROPn(3)) \ + YV(oled, OledRectR, oled_display->drawRoundRect(n5, n4, n3, n2, n1, n0); DROPn(5)) \ + YV(oled, OledRectRF, oled_display->fillRoundRect(n5, n4, n3, n2, n1, n0 ); DROPn(5)) diff --git a/esp32/optionals.fs b/esp32/optionals.fs index 1de43eb..e532e31 100644 --- a/esp32/optionals.fs +++ b/esp32/optionals.fs @@ -12,8 +12,12 @@ \ See the License for the specific language governing permissions and \ limitations under the License. -internals - -DEFINED? assemblers-source [IF] assemblers-source evaluate [THEN] - -forth +internals DEFINED? assembler-source [IF] + assembler-source evaluate +[THEN] forth +internals DEFINED? xtensa-assembler-source [IF] + xtensa-assembler-source evaluate +[THEN] forth +internals DEFINED? riscv-assembler-source [IF] + riscv-assembler-source evaluate +[THEN] forth diff --git a/esp32/options.h b/esp32/options.h index d54bc67..47d4bb7 100644 --- a/esp32/options.h +++ b/esp32/options.h @@ -57,13 +57,6 @@ #if !defined(CONFIG_IDF_TARGET_ESP32C3) #endif -// Uncomment this #define for OLED Support. -// You will need to install these libraries from the Library Manager: -// Adafruit SSD1306 -// Adafruit GFX Library -// Adafruit BusIO -//#define ENABLE_OLED_SUPPORT - // For now assume only boards with PSRAM should enable // camera support and BluetoothSerial. // ESP32-CAM always have PSRAM, but so do WROVER boards, diff --git a/esp32/print-builtins.cpp b/esp32/print-builtins.cpp index b8718cf..6292597 100644 --- a/esp32/print-builtins.cpp +++ b/esp32/print-builtins.cpp @@ -24,6 +24,7 @@ #define FLOATING_POINT_LIST #define USER_WORDS #define OPTIONAL_ASSEMBLERS_SUPPORT +#define OPTIONAL_OLED_SUPPORT #include "builtins.h" #define XV(flags, name, op, code) Z(flags, name, op, code)