From 7869aa3859f8dacf6b700a551c8d6ff93af7659e Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sun, 21 Feb 2021 00:35:48 -0800 Subject: [PATCH] Adding sockets bindings for esp32 --- ueforth/Makefile | 2 +- ueforth/arduino/arduino.template.ino | 28 +++++++++++++++++++++++----- ueforth/arduino/bindings.fs | 9 +++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/ueforth/Makefile b/ueforth/Makefile index 9999d7a..4fd1dd1 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -1,4 +1,4 @@ -VERSION=7.0 +VERSION=7.0.1 REVISION=$(shell git rev-parse HEAD) OUT = out diff --git a/ueforth/arduino/arduino.template.ino b/ueforth/arduino/arduino.template.ino index d4cb1be..ae31201 100644 --- a/ueforth/arduino/arduino.template.ino +++ b/ueforth/arduino/arduino.template.ino @@ -13,6 +13,7 @@ #define ENABLE_WEBSERVER_SUPPORT #define ENABLE_SDCARD_SUPPORT #define ENABLE_I2C_SUPPORT +#define ENABLE_SOCKETS_SUPPORT // For now assume only boards with PSRAM (ESP32-CAM) // will want SerialBluetooth (very large) and camera support. @@ -115,6 +116,7 @@ OPTIONAL_I2C_SUPPORT \ OPTIONAL_SERIAL_BLUETOOTH_SUPPORT \ OPTIONAL_CAMERA_SUPPORT \ + OPTIONAL_SOCKETS_SUPPORT \ #ifndef ENABLE_SPIFFS_SUPPORT // Provide a default failing SPIFFS.begin @@ -123,7 +125,6 @@ #else # include "SPIFFS.h" # define OPTIONAL_SPIFFS_SUPPORT \ - /* SPIFFS */ \ X("SPIFFS.begin", SPIFFS_BEGIN, \ tos = SPIFFS.begin(n2, c1, n0); NIPn(2)) \ X("SPIFFS.end", SPIFFS_END, SPIFFS.end()) \ @@ -137,7 +138,6 @@ #else # include "esp_camera.h" # define OPTIONAL_CAMERA_SUPPORT \ - /* Camera */ \ Y(esp_camera_init, n0 = esp_camera_init((camera_config_t *) a0)) \ Y(esp_camera_deinit, PUSH esp_camera_deinit()) \ Y(esp_camera_fb_get, PUSH esp_camera_fb_get()) \ @@ -145,12 +145,32 @@ Y(esp_camera_sensor_get, PUSH esp_camera_sensor_get()) #endif +#ifndef ENABLE_SOCKETS_SUPPORT +# define OPTIONAL_SOCKETS_SUPPORT +#else +# include +# include +# include +# include +# include +# include +# include +# define OPTIONAL_SOCKETS_SUPPORT \ + Y(socket, n0 = socket(n2, n1, n0); NIPn(2)) \ + Y(bind, n0 = bind(n2, (struct sockaddr *) a1, n0); NIPn(2)) \ + Y(listen, n0 = listen(n1, n0); NIP) \ + Y(connect, n0 = connect(n2, (struct sockaddr *) a1, n0); NIPn(2)) \ + Y(accept, n0 = accept(n2, (struct sockaddr *) a1, (socklen_t *) a0); NIPn(2)) \ + Y(select, n0 = select(n4, (fd_set *) a3, (fd_set *) a2, (fd_set *) a1, (struct timeval *) a0); NIPn(4)) \ + Y(poll, n0 = poll((struct pollfd *) a2, (nfds_t) n1, n0); NIPn(2)) \ + Y(errno, PUSH errno) +#endif + #ifndef ENABLE_SDCARD_SUPPORT # define OPTIONAL_SDCARD_SUPPORT #else # include "SD_MMC.h" # define OPTIONAL_SDCARD_SUPPORT \ - /* SD_MMC */ \ X("SD_MMC.begin", SD_MMC_BEGIN, tos = SD_MMC.begin(c1, n0); NIP) \ X("SD_MMC.end", SD_MMC_END, SD_MMC.end()) \ X("SD_MMC.cardType", SD_MMC_CARD_TYPE, PUSH SD_MMC.cardType()) \ @@ -163,7 +183,6 @@ #else # include # define OPTIONAL_I2C_SUPPORT \ - /* Wire */ \ X("Wire.begin", WIRE_BEGIN, n0 = Wire.begin(n1, n0); NIP) \ X("Wire.setClock", WIRE_SET_CLOCK, Wire.setClock(n0); DROP) \ X("Wire.getClock", WIRE_GET_CLOCK, PUSH Wire.getClock()) \ @@ -193,7 +212,6 @@ # include "BluetoothSerial.h" # define bt0 ((BluetoothSerial *) a0) # define OPTIONAL_SERIAL_BLUETOOTH_SUPPORT \ - /* SerialBT */ \ X("SerialBT.new", SERIALBT_NEW, PUSH new BluetoothSerial()) \ X("SerialBT.delete", SERIALBT_DELETE, delete bt0; DROP) \ X("SerialBT.begin", SERIALBT_BEGIN, n0 = bt0->begin(c2, n1); NIPn(2)) \ diff --git a/ueforth/arduino/bindings.fs b/ueforth/arduino/bindings.fs index ce7d23c..a96580c 100644 --- a/ueforth/arduino/bindings.fs +++ b/ueforth/arduino/bindings.fs @@ -77,6 +77,15 @@ transfer{ }transfer forth definitions +vocabulary sockets sockets definitions +transfer{ + socket bind listen connect accept select poll errno +}transfer +1 constant SOCK_STREAM +2 constant AF_INET +16 constant sizeof(sockaddr_in) +forth definitions + vocabulary bluetooth bluetooth definitions ?transfer SerialBT.new ?transfer SerialBT.delete