Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c76c6e9

Browse files
Version 4.4c - 21st April 2023
Add support for Adafruit QT Py ESP32 Pico
1 parent 012006f commit c76c6e9

File tree

1 file changed

+77
-32
lines changed

1 file changed

+77
-32
lines changed

‎ulisp-esp.ino

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* uLisp ESP Release 4.4b - www.ulisp.com
2-
David Johnson-Davies - www.technoblogy.com - 31st March 2023
1+
/* uLisp ESP Release 4.4c - www.ulisp.com
2+
David Johnson-Davies - www.technoblogy.com - 21st April 2023
33
44
Licensed under the MIT license: https://opensource.org/licenses/MIT
55
*/
@@ -80,6 +80,14 @@ Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST);
8080
#define analogWrite(x,y) dacWrite((x),(y))
8181
#define SDCARD_SS_PIN 13
8282

83+
#elif defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO)
84+
#define WORKSPACESIZE (9216-SDSIZE) /* Cells (8*bytes) */
85+
#define LITTLEFS
86+
#include "FS.h"
87+
#include <LittleFS.h>
88+
#define SDCARD_SS_PIN 13
89+
#define LED_BUILTIN 13
90+
8391
#elif defined(ARDUINO_ADAFRUIT_QTPY_ESP32S2)
8492
#define WORKSPACESIZE (9216-SDSIZE) /* Cells (8*bytes) */
8593
#define LITTLEFS
@@ -1745,46 +1753,55 @@ object *mapcarcan (object *args, object *env, mapfun_t fun) {
17451753
}
17461754
}
17471755

1748-
// I2C interface for one port, using Arduino Wire
1756+
// I2C interface for up to two ports, using Arduino Wire
17491757

1750-
void I2Cinit (bool enablePullup) {
1758+
void I2Cinit (TwoWire *port, bool enablePullup) {
17511759
(void) enablePullup;
1752-
Wire.begin();
1760+
port->begin();
17531761
}
17541762

1755-
int I2Cread () {
1756-
return Wire.read();
1763+
int I2Cread (TwoWire *port) {
1764+
return port->read();
17571765
}
17581766

1759-
void I2Cwrite (uint8_t data) {
1760-
Wire.write(data);
1767+
void I2Cwrite (TwoWire *port, uint8_t data) {
1768+
port->write(data);
17611769
}
17621770

1763-
bool I2Cstart (uint8_t address, uint8_t read) {
1771+
bool I2Cstart (TwoWire *port, uint8_t address, uint8_t read) {
17641772
int ok = true;
17651773
if (read == 0) {
1766-
Wire.beginTransmission(address);
1767-
ok = (Wire.endTransmission(true) == 0);
1768-
Wire.beginTransmission(address);
1774+
port->beginTransmission(address);
1775+
ok = (port->endTransmission(true) == 0);
1776+
port->beginTransmission(address);
17691777
}
1770-
else Wire.requestFrom(address, I2Ccount);
1778+
else port->requestFrom(address, I2Ccount);
17711779
return ok;
17721780
}
17731781

1774-
bool I2Crestart (uint8_t address, uint8_t read) {
1775-
int error = (Wire.endTransmission(false) != 0);
1776-
if (read == 0) Wire.beginTransmission(address);
1777-
else Wire.requestFrom(address, I2Ccount);
1782+
bool I2Crestart (TwoWire *port, uint8_t address, uint8_t read) {
1783+
int error = (port->endTransmission(false) != 0);
1784+
if (read == 0) port->beginTransmission(address);
1785+
else port->requestFrom(address, I2Ccount);
17781786
return error ? false : true;
17791787
}
17801788

1781-
void I2Cstop (uint8_t read) {
1782-
if (read == 0) Wire.endTransmission(); // Check for error?
1789+
void I2Cstop (TwoWire *port, uint8_t read) {
1790+
if (read == 0) port->endTransmission(); // Check for error?
17831791
}
17841792

17851793
// Streams
17861794

1795+
// Simplify board differences
1796+
#if defined(ARDUINO_ADAFRUIT_QTPY_ESP32S2)
1797+
#define ULISP_I2C1
1798+
#endif
1799+
17871800
inline int spiread () { return SPI.transfer(0); }
1801+
inline int i2cread () { return I2Cread(&Wire); }
1802+
#if defined(ULISP_I2C1)
1803+
inline int i2c1read () { return I2Cread(&Wire1); }
1804+
#endif
17881805
inline int serial1read () { while (!Serial1.available()) testescape(); return Serial1.read(); }
17891806
#if defined(sdcardsupport)
17901807
File SDpfile, SDgfile;
@@ -1817,6 +1834,7 @@ void serialbegin (int address, int baud) {
18171834

18181835
void serialend (int address) {
18191836
if (address == 1) {Serial1.flush(); Serial1.end(); }
1837+
else error(PSTR("port not supported"), number(address));
18201838
}
18211839

18221840
gfun_t gstreamfun (object *args) {
@@ -1827,8 +1845,12 @@ gfun_t gstreamfun (object *args) {
18271845
int stream = isstream(first(args));
18281846
streamtype = stream>>8; address = stream & 0xFF;
18291847
}
1830-
if (streamtype == I2CSTREAM) gfun = (gfun_t)I2Cread;
1831-
else if (streamtype == SPISTREAM) gfun = spiread;
1848+
if (streamtype == I2CSTREAM) {
1849+
if (address < 128) gfun = i2cread;
1850+
#if defined(ULISP_I2C1)
1851+
else gfun = i2c1read;
1852+
#endif
1853+
} else if (streamtype == SPISTREAM) gfun = spiread;
18321854
else if (streamtype == SERIALSTREAM) {
18331855
if (address == 0) gfun = gserial;
18341856
else if (address == 1) gfun = serial1read;
@@ -1842,6 +1864,10 @@ gfun_t gstreamfun (object *args) {
18421864
}
18431865

18441866
inline void spiwrite (char c) { SPI.transfer(c); }
1867+
inline void i2cwrite (char c) { I2Cwrite(&Wire, c); }
1868+
#if defined(ULISP_I2C1)
1869+
inline void i2c1write (char c) { I2Cwrite(&Wire1, c); }
1870+
#endif
18451871
inline void serial1write (char c) { Serial1.write(c); }
18461872
inline void WiFiwrite (char c) { client.write(c); }
18471873
#if defined(sdcardsupport)
@@ -1859,8 +1885,12 @@ pfun_t pstreamfun (object *args) {
18591885
int stream = isstream(first(args));
18601886
streamtype = stream>>8; address = stream & 0xFF;
18611887
}
1862-
if (streamtype == I2CSTREAM) pfun = (pfun_t)I2Cwrite;
1863-
else if (streamtype == SPISTREAM) pfun = spiwrite;
1888+
if (streamtype == I2CSTREAM) {
1889+
if (address < 128) pfun = i2cwrite;
1890+
#if defined(ULISP_I2C1)
1891+
else pfun = i2c1write;
1892+
#endif
1893+
} else if (streamtype == SPISTREAM) pfun = spiwrite;
18641894
else if (streamtype == SERIALSTREAM) {
18651895
if (address == 0) pfun = pserial;
18661896
else if (address == 1) pfun = serial1write;
@@ -1892,6 +1922,8 @@ void checkanalogread (int pin) {
18921922
error(PSTR("invalid pin"), number(pin));
18931923
#elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2_TFT)
18941924
if (!(pin==8 || (pin>=14 && pin<=18))) error(PSTR("invalid pin"), number(pin));
1925+
#elif defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO)
1926+
if (!(pin==4 || pin==7 || (pin>=12 && pin<=15) || (pin>=25 && pin<=27) || (pin>=32 && pin<=33))) error(PSTR("invalid pin"), number(pin));
18951927
#elif defined(ARDUINO_ADAFRUIT_QTPY_ESP32S2)
18961928
if (!((pin>=5 && pin<=9) || (pin>=16 && pin<=18))) error(PSTR("invalid pin"), number(pin));
18971929
#elif defined(ARDUINO_ADAFRUIT_QTPY_ESP32C3)
@@ -1908,7 +1940,7 @@ void checkanalogread (int pin) {
19081940
void checkanalogwrite (int pin) {
19091941
#if defined(ESP8266)
19101942
if (!(pin>=0 && pin<=16)) error(PSTR("invalid pin"), number(pin));
1911-
#elif defined(ESP32) || defined(ARDUINO_FEATHER_ESP32) || defined(ARDUINO_ESP32_DEV)
1943+
#elif defined(ESP32) || defined(ARDUINO_FEATHER_ESP32) || defined(ARDUINO_ESP32_DEV) || defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO)
19121944
if (!(pin>=25 && pin<=26)) error(PSTR("invalid pin"), number(pin));
19131945
#elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2_TFT) || defined(ARDUINO_ADAFRUIT_QTPY_ESP32S2) || defined(ARDUINO_FEATHERS2) || defined(ARDUINO_ESP32S2_DEV)
19141946
if (!(pin>=17 && pin<=18)) error(PSTR("invalid pin"), number(pin));
@@ -2394,20 +2426,28 @@ object *sp_withi2c (object *args, object *env) {
23942426
object *var = first(params);
23952427
int address = checkinteger(eval(second(params), env));
23962428
params = cddr(params);
2397-
if (address == 0 && params != NULL) params = cdr(params); // Ignore port
2429+
if ((address == 0 || address == 1) && params != NULL) {
2430+
address = address * 128 + checkinteger(eval(first(params), env));
2431+
params = cdr(params);
2432+
}
23982433
int read = 0; // Write
23992434
I2Ccount = 0;
24002435
if (params != NULL) {
24012436
object *rw = eval(first(params), env);
24022437
if (integerp(rw)) I2Ccount = rw->integer;
24032438
read = (rw != NULL);
24042439
}
2405-
I2Cinit(1); // Pullups
2406-
object *pair = cons(var, (I2Cstart(address, read)) ? stream(I2CSTREAM, address) : nil);
2440+
// Top bit of address is I2C port
2441+
TwoWire *port = &Wire;
2442+
#if defined(ULISP_I2C1)
2443+
if (address > 127) port = &Wire1;
2444+
#endif
2445+
I2Cinit(port, 1); // Pullups
2446+
object *pair = cons(var, (I2Cstart(port, address & 0x7F, read)) ? stream(I2CSTREAM, address) : nil);
24072447
push(pair,env);
24082448
object *forms = cdr(args);
24092449
object *result = eval(tf_progn(forms,env), env);
2410-
I2Cstop(read);
2450+
I2Cstop(port, read);
24112451
return result;
24122452
}
24132453

@@ -3672,7 +3712,12 @@ object *fn_restarti2c (object *args, object *env) {
36723712
}
36733713
int address = stream & 0xFF;
36743714
if (stream>>8 != I2CSTREAM) error2(PSTR("not an i2c stream"));
3675-
return I2Crestart(address, read) ? tee : nil;
3715+
TwoWire *port;
3716+
if (address < 128) port = &Wire;
3717+
#if defined(ULISP_I2C1)
3718+
else port = &Wire1;
3719+
#endif
3720+
return I2Crestart(port, address & 0x7F, read) ? tee : nil;
36763721
}
36773722

36783723
object *fn_gc (object *obj, object *env) {
@@ -5505,7 +5550,7 @@ bool findsubstring (char *part, builtin_t name) {
55055550
}
55065551

55075552
void testescape () {
5508-
if (Serial.read() == '~') error2(PSTR("escape!"));
5553+
if (Serial.available() && Serial.read() == '~') error2(PSTR("escape!"));
55095554
}
55105555

55115556
bool keywordp (object *obj) {
@@ -6216,7 +6261,7 @@ void setup () {
62166261
initenv();
62176262
initsleep();
62186263
initgfx();
6219-
pfstring(PSTR("uLisp 4.4b "), pserial); pln(pserial);
6264+
pfstring(PSTR("uLisp 4.4c "), pserial); pln(pserial);
62206265
}
62216266

62226267
// Read/Evaluate/Print loop

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /