summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorLoïc Guégan <manzerbredes@mailbox.org>2025-03-24 09:33:49 +0100
committerLoïc Guégan <manzerbredes@mailbox.org>2025-03-24 09:33:49 +0100
commit7741f014456df395b655b72d9ebb848af72cc37e (patch)
tree5ddae273929780ac7c0af2a26b64ba1a382e4b05 /src/main.c
parentd3ecfe3498d73d3ba924063bc1001cca3f333170 (diff)
Init repository
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..b26543d
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,60 @@
+#include "libs/tty.h"
+#include "libs/utils.h"
+#include "libs/gpio.h"
+#include "libs/interrupts.h"
+#include "libs/clock.h"
+
+#define MOTD "WELCOME TO RP2040 TTY\n\n\r"
+#define PROMPT "rp2040> "
+#define HELP "\tblink\t\tmake led blink for almost 1s\n\r"
+
+char cmd[64];
+char *cmdptr=cmd;
+
+// Execute command from cmd buffer
+void exec(){
+ if(!strncmp(cmd, "blink", strlen("exit")))
+ gpio_blink_led(1);
+ else if(!strncmp(cmd, "help", strlen("help")))
+ tty_putstr(HELP);
+ else if(cmdptr != cmd)
+ tty_putstr("Unknown command (see help)\n\r");
+}
+
+void main(){
+ // Finishing boot
+ interrupts_init();
+ xosc_init();
+ gpio_init();
+ tty_init();
+
+
+ // REPL
+ char c=tty_getchar();
+ tty_putstr(MOTD);
+ tty_putstr(PROMPT);
+ while(1){
+ c=tty_getchar();
+ if(c=='\r'){
+ tty_putstr("\n\r");
+ exec();
+ tty_putstr(PROMPT);
+ cmdptr=cmd;
+ }
+ else if (c ==0x8){
+ if(cmdptr-cmd){
+ tty_putstr("\b \b"); // Erase last character
+ cmdptr--;
+ }
+ }
+ else{
+ *cmdptr=c;
+ cmdptr++;
+ tty_putchar(c);
+ }
+ }
+
+
+
+ return;
+}