Fix up optionals, pull out oled.

This commit is contained in:
Brad Nelson
2023-07-05 21:41:21 -07:00
parent 6884898cb1
commit ea1217a162
10 changed files with 131 additions and 62 deletions

View File

@ -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 ----

View File

@ -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 <Adafruit_GFX.h>
# include <Adafruit_SSD1306.h>
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

View File

@ -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

View File

@ -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

53
esp32/optional/oled.h Normal file
View File

@ -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 <Adafruit_GFX.h>
# include <Adafruit_SSD1306.h>
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))

View File

@ -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

View File

@ -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,

View File

@ -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)