blob: b26543d101cf8bb7f573ac84bc26cbc85f51b3f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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;
}
|