1
- /* uLisp ESP Release 4.4c - www.ulisp.com
2
- David Johnson-Davies - www.technoblogy.com - 21st April 2023
1
+ /* uLisp ESP Release 4.4d - www.ulisp.com
2
+ David Johnson-Davies - www.technoblogy.com - 30th June 2023
3
3
4
4
Licensed under the MIT license: https://opensource.org/licenses/MIT
5
5
*/
@@ -26,7 +26,6 @@ const char LispLibrary[] PROGMEM = "";
26
26
#include < SPI.h>
27
27
#include < Wire.h>
28
28
#include < limits.h>
29
- #include < EEPROM.h>
30
29
#if defined (ESP8266)
31
30
#include < ESP8266WiFi.h>
32
31
#elif defined (ESP32)
@@ -60,38 +59,35 @@ Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST);
60
59
61
60
#if defined(ESP8266)
62
61
#define WORKSPACESIZE (3928 -SDSIZE) /* Cells (8*bytes) */
62
+ #include < EEPROM.h>
63
63
#define EEPROMSIZE 4096 /* Bytes available for EEPROM */
64
64
#define SDCARD_SS_PIN 10
65
65
#define LED_BUILTIN 13
66
66
67
67
#elif defined(ARDUINO_FEATHER_ESP32)
68
68
#define WORKSPACESIZE (9216 -SDSIZE) /* Cells (8*bytes) */
69
69
#define LITTLEFS
70
- #include " FS.h"
71
70
#include < LittleFS.h>
72
71
#define analogWrite (x,y ) dacWrite((x),(y))
73
72
#define SDCARD_SS_PIN 13
74
73
75
74
#elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2_TFT)
76
- #define WORKSPACESIZE (9216 -SDSIZE) /* Cells (8*bytes) */
75
+ #define WORKSPACESIZE (8160 -SDSIZE) /* Cells (8*bytes) */
77
76
#define LITTLEFS
78
- #include " FS.h"
79
77
#include < LittleFS.h>
80
78
#define analogWrite (x,y ) dacWrite((x),(y))
81
79
#define SDCARD_SS_PIN 13
82
80
83
81
#elif defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO)
84
82
#define WORKSPACESIZE (9216 -SDSIZE) /* Cells (8*bytes) */
85
83
#define LITTLEFS
86
- #include " FS.h"
87
84
#include < LittleFS.h>
88
85
#define SDCARD_SS_PIN 13
89
86
#define LED_BUILTIN 13
90
87
91
88
#elif defined(ARDUINO_ADAFRUIT_QTPY_ESP32S2)
92
- #define WORKSPACESIZE (9216 -SDSIZE) /* Cells (8*bytes) */
89
+ #define WORKSPACESIZE (8160 -SDSIZE) /* Cells (8*bytes) */
93
90
#define LITTLEFS
94
- #include " FS.h"
95
91
#include < LittleFS.h>
96
92
#define analogWrite (x,y ) dacWrite((x),(y))
97
93
#define SDCARD_SS_PIN 13
@@ -100,15 +96,13 @@ Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST);
100
96
#elif defined(ARDUINO_ADAFRUIT_QTPY_ESP32C3)
101
97
#define WORKSPACESIZE (9216 -SDSIZE) /* Cells (8*bytes) */
102
98
#define LITTLEFS
103
- #include " FS.h"
104
99
#include < LittleFS.h>
105
100
#define SDCARD_SS_PIN 13
106
101
#define LED_BUILTIN 13
107
102
108
103
#elif defined(ARDUINO_FEATHERS2) /* UM FeatherS2 */
109
- #define WORKSPACESIZE (9216 -SDSIZE) /* Cells (8*bytes) */
104
+ #define WORKSPACESIZE (8160 -SDSIZE) /* Cells (8*bytes) */
110
105
#define LITTLEFS
111
- #include " FS.h"
112
106
#include < LittleFS.h>
113
107
#define analogWrite (x,y ) dacWrite((x),(y))
114
108
#define SDCARD_SS_PIN 13
@@ -117,15 +111,14 @@ Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST);
117
111
#elif defined(ARDUINO_ESP32_DEV) /* For TTGO T-Display */
118
112
#define WORKSPACESIZE (9216 -SDSIZE) /* Cells (8*bytes) */
119
113
#define LITTLEFS
120
- #include " FS.h"
121
114
#include < LittleFS.h>
122
115
#define analogWrite (x,y ) dacWrite((x),(y))
123
116
#define SDCARD_SS_PIN 13
117
+ #define LED_BUILTIN 13
124
118
125
119
#elif defined(ARDUINO_ESP32S2_DEV)
126
120
#define WORKSPACESIZE (9216 -SDSIZE) /* Cells (8*bytes) */
127
121
#define LITTLEFS
128
- #include " FS.h"
129
122
#include < LittleFS.h>
130
123
#define analogWrite (x,y ) dacWrite((x),(y))
131
124
#define SDCARD_SS_PIN 13
@@ -134,23 +127,20 @@ Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST);
134
127
#elif defined(ARDUINO_ESP32C3_DEV)
135
128
#define WORKSPACESIZE (9216 -SDSIZE) /* Cells (8*bytes) */
136
129
#define LITTLEFS
137
- #include " FS.h"
138
130
#include < LittleFS.h>
139
131
#define SDCARD_SS_PIN 13
140
132
#define LED_BUILTIN 13
141
133
142
134
#elif defined(ARDUINO_ESP32S3_DEV)
143
135
#define WORKSPACESIZE (22000 -SDSIZE) /* Cells (8*bytes) */
144
136
#define LITTLEFS
145
- #include " FS.h"
146
137
#include < LittleFS.h>
147
138
#define SDCARD_SS_PIN 13
148
139
#define LED_BUILTIN 13
149
140
150
141
#elif defined(ESP32)
151
142
#define WORKSPACESIZE (9216 -SDSIZE) /* Cells (8*bytes) */
152
143
#define LITTLEFS
153
- #include " FS.h"
154
144
#include < LittleFS.h>
155
145
#define analogWrite (x,y ) dacWrite((x),(y))
156
146
#define SDCARD_SS_PIN 13
@@ -1069,10 +1059,6 @@ object *divide_floats (object *args, float fresult) {
1069
1059
return makefloat (fresult);
1070
1060
}
1071
1061
1072
- int myround (float number) {
1073
- return (number >= 0 ) ? (int )(number + 0.5 ) : (int )(number - 0.5 );
1074
- }
1075
-
1076
1062
object *compare (object *args, bool lt, bool gt, bool eq) {
1077
1063
object *arg1 = first (args);
1078
1064
args = cdr (args);
@@ -1348,13 +1334,13 @@ object *copystring (object *arg) {
1348
1334
return obj;
1349
1335
}
1350
1336
1351
- object *readstring (uint8_t delim, gfun_t gfun) {
1337
+ object *readstring (uint8_t delim, bool esc, gfun_t gfun) {
1352
1338
object *obj = newstring ();
1353
1339
object *tail = obj;
1354
1340
int ch = gfun ();
1355
1341
if (ch == -1 ) return nil;
1356
1342
while ((ch != delim) && (ch != -1 )) {
1357
- if (ch == ' \\ ' ) ch = gfun ();
1343
+ if (esc && ch == ' \\ ' ) ch = gfun ();
1358
1344
buildstring (ch, &tail);
1359
1345
ch = gfun ();
1360
1346
}
@@ -1402,6 +1388,17 @@ void pstr (char c) {
1402
1388
buildstring (c, &GlobalStringTail);
1403
1389
}
1404
1390
1391
+ object *iptostring (IPAddress ip) {
1392
+ union { uint32_t data2; uint8_t u8 [4 ]; };
1393
+ object *obj = startstring ();
1394
+ data2 = ip;
1395
+ for (int i=0 ; i<4 ; i++) {
1396
+ if (i) pstr (' .' );
1397
+ pintbase (u8 [i], 10 , pstr);
1398
+ }
1399
+ return obj;
1400
+ }
1401
+
1405
1402
object *lispstring (char *s) {
1406
1403
object *obj = newstring ();
1407
1404
object *tail = obj;
@@ -1824,6 +1821,7 @@ inline int WiFiread () {
1824
1821
LastChar = 0 ;
1825
1822
return temp;
1826
1823
}
1824
+ while (!client.available ()) testescape ();
1827
1825
return client.read ();
1828
1826
}
1829
1827
@@ -2487,12 +2485,15 @@ object *sp_withspi (object *args, object *env) {
2487
2485
}
2488
2486
2489
2487
object *sp_withsdcard (object *args, object *env) {
2490
- #if defined(sdcardsupport)
2488
+ #if defined(sdcardsupport)
2491
2489
object *params = checkarguments (args, 2 , 3 );
2492
2490
object *var = first (params);
2493
2491
params = cdr (params);
2494
2492
if (params == NULL ) error2 (PSTR (" no filename specified" ));
2493
+ builtin_t temp = Context;
2495
2494
object *filename = eval (first (params), env);
2495
+ Context = temp;
2496
+ if (!stringp (filename)) error (PSTR (" filename is not a string" ), filename);
2496
2497
params = cdr (params);
2497
2498
SD.begin ();
2498
2499
int mode = 0 ;
@@ -2514,11 +2515,11 @@ object *sp_withsdcard (object *args, object *env) {
2514
2515
object *result = eval (tf_progn (forms,env), env);
2515
2516
if (mode >= 1 ) SDpfile.close (); else SDgfile.close ();
2516
2517
return result;
2517
- #else
2518
+ #else
2518
2519
(void ) args, (void ) env;
2519
2520
error2 (PSTR (" not supported" ));
2520
2521
return nil;
2521
- #endif
2522
+ #endif
2522
2523
}
2523
2524
2524
2525
// Tail-recursive forms
@@ -3328,8 +3329,8 @@ object *fn_round (object *args, object *env) {
3328
3329
(void ) env;
3329
3330
object *arg = first (args);
3330
3331
args = cdr (args);
3331
- if (args != NULL ) return number (myround (checkintfloat (arg) / checkintfloat (first (args))));
3332
- else return number (myround (checkintfloat (arg)));
3332
+ if (args != NULL ) return number (round (checkintfloat (arg) / checkintfloat (first (args))));
3333
+ else return number (round (checkintfloat (arg)));
3333
3334
}
3334
3335
3335
3336
// Characters
@@ -3665,7 +3666,7 @@ object *fn_readbyte (object *args, object *env) {
3665
3666
object *fn_readline (object *args, object *env) {
3666
3667
(void ) env;
3667
3668
gfun_t gfun = gstreamfun (args);
3668
- return readstring (' \n ' , gfun);
3669
+ return readstring (' \n ' , false , gfun);
3669
3670
}
3670
3671
3671
3672
object *fn_writebyte (object *args, object *env) {
@@ -3701,7 +3702,7 @@ object *fn_writeline (object *args, object *env) {
3701
3702
3702
3703
object *fn_restarti2c (object *args, object *env) {
3703
3704
(void ) env;
3704
- int stream = first (args)-> integer ;
3705
+ int stream = isstream ( first (args)) ;
3705
3706
args = cdr (args);
3706
3707
int read = 0 ; // Write
3707
3708
I2Ccount = 0 ;
@@ -4209,7 +4210,7 @@ object *fn_wifisoftap (object *args, object *env) {
4209
4210
}
4210
4211
WiFi.softAP (cstring (first, ssid, 33 ), cstring (second, pass, 65 ), channel, hidden);
4211
4212
}
4212
- return lispstring (( char *) WiFi.softAPIP (). toString (). c_str ());
4213
+ return iptostring ( WiFi.softAPIP ());
4213
4214
}
4214
4215
4215
4216
object *fn_connected (object *args, object *env) {
@@ -4220,7 +4221,7 @@ object *fn_connected (object *args, object *env) {
4220
4221
4221
4222
object *fn_wifilocalip (object *args, object *env) {
4222
4223
(void ) args, (void ) env;
4223
- return lispstring (( char *) WiFi.localIP (). toString (). c_str ());
4224
+ return iptostring ( WiFi.localIP ());
4224
4225
}
4225
4226
4226
4227
object *fn_wificonnect (object *args, object *env) {
@@ -4230,7 +4231,7 @@ object *fn_wificonnect (object *args, object *env) {
4230
4231
if (cdr (args) == NULL ) WiFi.begin (cstring (first (args), ssid, 33 ));
4231
4232
else WiFi.begin (cstring (first (args), ssid, 33 ), cstring (second (args), pass, 65 ));
4232
4233
int result = WiFi.waitForConnectResult ();
4233
- if (result == WL_CONNECTED) return lispstring (( char *) WiFi.localIP (). toString (). c_str ());
4234
+ if (result == WL_CONNECTED) return iptostring ( WiFi.localIP ());
4234
4235
else if (result == WL_NO_SSID_AVAIL) error2 (PSTR (" network not found" ));
4235
4236
else if (result == WL_CONNECT_FAILED) error2 (PSTR (" connection failed" ));
4236
4237
else error2 (PSTR (" unable to connect" ));
@@ -5550,7 +5551,7 @@ bool findsubstring (char *part, builtin_t name) {
5550
5551
}
5551
5552
5552
5553
void testescape () {
5553
- if (Serial.available () && Serial.read () == ' ~' ) error2 (PSTR (" escape!" ));
5554
+ if (Serial.available () && Serial.read () == ' ~' ) { Context = NIL; error2 (PSTR (" escape!" )); }
5554
5555
}
5555
5556
5556
5557
bool keywordp (object *obj) {
@@ -6085,7 +6086,7 @@ object *nextitem (gfun_t gfun) {
6085
6086
if (ch == ' \' ' ) return (object *)QUO;
6086
6087
6087
6088
// Parse string
6088
- if (ch == ' "' ) return readstring (' "' , gfun);
6089
+ if (ch == ' "' ) return readstring (' "' , true , gfun);
6089
6090
6090
6091
// Parse symbol, character, or number
6091
6092
int index = 0 , base = 10 , sign = 1 ;
@@ -6261,7 +6262,7 @@ void setup () {
6261
6262
initenv ();
6262
6263
initsleep ();
6263
6264
initgfx ();
6264
- pfstring (PSTR (" uLisp 4.4c " ), pserial); pln (pserial);
6265
+ pfstring (PSTR (" uLisp 4.4d " ), pserial); pln (pserial);
6265
6266
}
6266
6267
6267
6268
// Read/Evaluate/Print loop
0 commit comments