WIP: Functional pico REPL (broke native)
This commit is contained in:
2
include/pico/config_autogen.h
Normal file
2
include/pico/config_autogen.h
Normal file
@@ -0,0 +1,2 @@
|
||||
/* SELECT OTHER BOARD */
|
||||
#include "boards/pico.h"
|
||||
18
include/tusb_config.h
Normal file
18
include/tusb_config.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
default config for printf
|
||||
*/
|
||||
|
||||
#ifndef _PICO_STDIO_USB_TUSB_CONFIG_H
|
||||
#define _PICO_STDIO_USB_TUSB_CONFIG_H
|
||||
|
||||
#include "pico/stdio_usb.h"
|
||||
|
||||
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE)
|
||||
|
||||
#define CFG_TUD_CDC (1)
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE (256)
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE (256)
|
||||
|
||||
// We use a vendor specific interface but with our own driver
|
||||
#define CFG_TUD_VENDOR (0)
|
||||
#endif
|
||||
@@ -25,7 +25,8 @@ release_build_flags =
|
||||
debug_build_flags =
|
||||
-ggdb
|
||||
-O0
|
||||
|
||||
src_filter =
|
||||
+<main.c>
|
||||
|
||||
[env:pico-debug]
|
||||
platform = https://github.com/Wiz-IO/wizio-pico.git
|
||||
@@ -37,6 +38,9 @@ build_flags =
|
||||
-D PLATFORM_PICO_SDK
|
||||
-D LIB_PICO_STDIO_USB
|
||||
-D PICO_USB
|
||||
build_src_filter =
|
||||
${common.src_filter}
|
||||
+<pico-plat.c>
|
||||
|
||||
upload_protocol = uf2
|
||||
upload_port = /run/media/max/RPI-RP2
|
||||
@@ -48,6 +52,9 @@ build_flags =
|
||||
${common.build_flags}
|
||||
${common.debug_build_flags}
|
||||
-D PLATFORM_NATIVE
|
||||
build_src_filter =
|
||||
${common.src_filter}
|
||||
+<native-plat.c>
|
||||
|
||||
[env:native-release]
|
||||
platform = native
|
||||
@@ -55,7 +62,9 @@ build_flags =
|
||||
${common.build_flags}
|
||||
${common.release_build_flags}
|
||||
-D PLATFORM_NATIVE
|
||||
|
||||
build_src_filter =
|
||||
${common.src_filter}
|
||||
+<native-plat.c>
|
||||
|
||||
;monitor_port = SELECT SERIAL PORT
|
||||
;monitor_speed = 115200
|
||||
|
||||
88
src/main.c
88
src/main.c
@@ -3,11 +3,13 @@
|
||||
|
||||
#include "uclisp.h"
|
||||
#include "types.h"
|
||||
#include "plat.h"
|
||||
|
||||
#ifdef PLATFORM_PICO_SDK
|
||||
// TODO:remove
|
||||
#include "pico/stdio.h"
|
||||
#include "pico/stdlib.h"
|
||||
#endif
|
||||
|
||||
#define UNUSED __attribute__((unused))
|
||||
|
||||
struct ucl *ucl;
|
||||
|
||||
@@ -15,30 +17,48 @@ struct ucl *ucl;
|
||||
struct ucl_object *ucl_car(struct ucl*, struct ucl_object *);
|
||||
void ucl_print_obj(struct ucl_object *);
|
||||
|
||||
// TODO: remove
|
||||
char buffer[1024] = {0};
|
||||
|
||||
void pico_getline() {
|
||||
int chr;
|
||||
char *end = &buffer[0];
|
||||
bool done = false;
|
||||
while (!done) {
|
||||
while((chr = getchar_timeout_us(0)) != PICO_ERROR_TIMEOUT)
|
||||
{
|
||||
if (chr == '\n' || chr == '\r') {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
|
||||
chr = chr & 0xFF;
|
||||
*end = chr;
|
||||
end++;
|
||||
|
||||
printf("%c", chr);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
*end = '\0';
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
#ifdef PLATFORM_PICO_SDK
|
||||
stdio_usb_init();
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||
bool gpio_state = false;
|
||||
#endif
|
||||
|
||||
platform_init();
|
||||
ucl = ucl_create();
|
||||
|
||||
while(1) {
|
||||
#ifdef PLATFORM_PICO_SDK
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, gpio_state);
|
||||
gpio_state = !gpio_state;
|
||||
#endif
|
||||
platform_repl_complete();
|
||||
|
||||
// TODO: Work out input for pico
|
||||
size_t line_len = 512;
|
||||
char *line = NULL;
|
||||
printf("> ");
|
||||
getline(&line, &line_len, stdin);
|
||||
fflush(stdout);
|
||||
|
||||
struct ucl_object *sexp = ucl_parse(ucl, line);
|
||||
pico_getline();
|
||||
|
||||
struct ucl_object *sexp = ucl_parse(ucl, buffer);
|
||||
struct ucl_object *result = NULL;
|
||||
if (sexp->type == UCL_TYPE_ERROR) {
|
||||
result = sexp;
|
||||
@@ -46,10 +66,38 @@ int main() {
|
||||
result = ucl_evaluate(ucl, ucl_car(ucl, sexp));
|
||||
}
|
||||
ucl_print_obj(result);
|
||||
printf("\n");
|
||||
|
||||
ucl_gc(ucl);
|
||||
free(line);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* int main() { */
|
||||
|
||||
/* platform_init(); */
|
||||
/* ucl = ucl_create(); */
|
||||
|
||||
/* while(1) { */
|
||||
/* platform_repl_complete(); */
|
||||
|
||||
/* size_t line_len = 512; */
|
||||
/* char *line = NULL; */
|
||||
/* printf("> "); */
|
||||
/* getline(&line, &line_len, stdin); */
|
||||
|
||||
/* struct ucl_object *sexp = ucl_parse(ucl, line); */
|
||||
/* struct ucl_object *result = NULL; */
|
||||
/* if (sexp->type == UCL_TYPE_ERROR) { */
|
||||
/* result = sexp; */
|
||||
/* } else { */
|
||||
/* result = ucl_evaluate(ucl, ucl_car(ucl, sexp)); */
|
||||
/* } */
|
||||
/* ucl_print_obj(result); */
|
||||
/* printf("\n"); */
|
||||
/* ucl_gc(ucl); */
|
||||
/* } */
|
||||
|
||||
/* return 0; */
|
||||
/* } */
|
||||
|
||||
7
src/native-plat.c
Normal file
7
src/native-plat.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "plat.h"
|
||||
|
||||
void platform_init() {
|
||||
}
|
||||
|
||||
void platform_repl_complete() {
|
||||
}
|
||||
4
src/native-plat.h
Normal file
4
src/native-plat.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef _NATIVE_ENV_H_
|
||||
#define _NATIVE_ENV_H_
|
||||
|
||||
#endif
|
||||
18
src/pico-plat.c
Normal file
18
src/pico-plat.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "plat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "pico/stdio.h"
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
static bool gpio_state = false;
|
||||
|
||||
void platform_init() {
|
||||
stdio_init_all();
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||
}
|
||||
|
||||
void platform_repl_complete() {
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, gpio_state);
|
||||
gpio_state = !gpio_state;
|
||||
}
|
||||
7
src/pico-plat.h
Normal file
7
src/pico-plat.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef _PICO_PLAT_H_
|
||||
#define _PICO_PLAT_H_
|
||||
|
||||
// Not sure why this isn't defined on Wizio Pico-SDK (is it defined in the standard SDK?)
|
||||
#define getline __getline
|
||||
|
||||
#endif
|
||||
15
src/plat.h
Normal file
15
src/plat.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _PLAT_H_
|
||||
#define _PLAT_H_
|
||||
|
||||
#ifdef PLATFORM_PICO_SDK
|
||||
#include "pico-plat.h"
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_NATIVE
|
||||
#include "native-plat.h"
|
||||
#endif
|
||||
|
||||
void platform_init();
|
||||
void platform_repl_complete();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user