From 2fcf93d1dd1bd1f3c202477a472ec7e05c98a8fc Mon Sep 17 00:00:00 2001 From: Max Regan Date: Thu, 29 Dec 2022 14:16:09 -0500 Subject: [PATCH] Initial commit --- platformio.ini | 4 ++-- src/native-plat.c | 3 +-- src/pico-plat.c | 21 ++++++++++++++++++--- src/pico-program.lsp | 23 +++++++++++++++++++---- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/platformio.ini b/platformio.ini index 6ba7d17..694a02f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -44,8 +44,8 @@ build_flags = build_src_filter = ${common.src_filter} + -upload_protocol = uf2 -upload_port = /run/media/max/RPI-RP2 +upload_protocol = picotool +;; upload_port = /run/media/max/RPI-RP2 lib_deps = /home/max/repos/uclisp/ extra_scripts = pre:extra_script.py diff --git a/src/native-plat.c b/src/native-plat.c index f2aeba7..dd8a423 100644 --- a/src/native-plat.c +++ b/src/native-plat.c @@ -19,11 +19,10 @@ const char *platform_get_text() { printf("> "); line = NULL; getline(&line, &line_len, stdin); - return line; } void platform_repl_complete() { free(line); - + line = NULL; } diff --git a/src/pico-plat.c b/src/pico-plat.c index fed3a96..a4d0a61 100644 --- a/src/pico-plat.c +++ b/src/pico-plat.c @@ -24,6 +24,10 @@ void pico_getline() { int chr; char *end = &buffer[0]; bool done = false; + + printf("> "); + fflush(stdout); + while (!done) { while((chr = getchar_timeout_us(0)) != PICO_ERROR_TIMEOUT) { @@ -33,10 +37,21 @@ void pico_getline() { } chr = chr & 0xFF; - *end = chr; - end++; - printf("%c", chr); + // Treat both backspace and DEL as backspace. It's unclear why to + // me, but they are appearing swapped for me in `screen` with the + // pico. + if (chr == '\b' || chr == '\x7f') { + if (end > buffer) { + end--; + printf("\b \b"); + } + } else { + *end = chr; + end++; + printf("%c", chr); + } + fflush(stdout); } } diff --git a/src/pico-program.lsp b/src/pico-program.lsp index 97a4188..0ac6e3f 100644 --- a/src/pico-program.lsp +++ b/src/pico-program.lsp @@ -1,4 +1,19 @@ -(gpio-write 0 1) -(sleep-millis 100) -(gpio-write 0 0) -(sleep-millis 100) +(setq led-pin 1) +(setq on 1) +(setq off 0) +(setq blink-delay 100) + +(defun blink () + (gpio-write led-pin on) + (sleep-millis blink-delay) + (gpio-write led-pin off) + (sleep-millis blink-delay)) + +(while (quote t) + (blink)) + +(setq n 0) + +(while 1 + (printl n) + (setq n (+ n 1)))