Implement crude but working REPL for board.
This commit is contained in:
parent
cbb8868f74
commit
f48cf67108
48
stm/main.c
48
stm/main.c
@ -184,32 +184,38 @@ static void board_info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *readline(const char *prompt) {
|
char *readline(const char *prompt) {
|
||||||
printf("a\n");
|
vstr_t vstr;
|
||||||
led_state(PYB_LED_R1, 1);
|
vstr_init(&vstr);
|
||||||
printf("b\n");
|
|
||||||
usb_vcp_send_str(prompt);
|
usb_vcp_send_str(prompt);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
printf("c\n");
|
//extern int rx_buf_in;
|
||||||
led_state(PYB_LED_R2, 1);
|
//extern int rx_buf_out;
|
||||||
|
while (usb_vcp_rx_any() == 0) {
|
||||||
|
//printf("nope %x %x\n", rx_buf_in, rx_buf_out);
|
||||||
|
sys_tick_delay_ms(10);
|
||||||
|
}
|
||||||
char c = usb_vcp_rx_get();
|
char c = usb_vcp_rx_get();
|
||||||
led_state(PYB_LED_R2, 0);
|
if (c == 4 && vstr_len(&vstr) == 0) {
|
||||||
usb_vcp_send_strn(&c, 1);
|
return NULL;
|
||||||
led_state(PYB_LED_G1, 1);
|
} else if (c == '\r') {
|
||||||
|
usb_vcp_send_str("\r\n");
|
||||||
|
return vstr_str(&vstr);
|
||||||
|
} else if (c == 127) {
|
||||||
|
if (vstr_len(&vstr) > 0) {
|
||||||
|
vstr_cut_tail(&vstr, 1);
|
||||||
|
usb_vcp_send_str("\b \b");
|
||||||
|
}
|
||||||
|
} else if (32 <= c && c <= 126) {
|
||||||
|
vstr_add_char(&vstr, c);
|
||||||
|
usb_vcp_send_strn(&c, 1);
|
||||||
|
}
|
||||||
sys_tick_delay_ms(100);
|
sys_tick_delay_ms(100);
|
||||||
led_state(PYB_LED_G1, 0);
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern char rx_buf[];
|
|
||||||
extern int rx_buf_out;
|
|
||||||
void do_repl() {
|
void do_repl() {
|
||||||
int i = 0;
|
|
||||||
for (;;) {
|
|
||||||
usb_vcp_send_str("Micro Python\r\n");
|
usb_vcp_send_str("Micro Python\r\n");
|
||||||
printf("%d %d %c\n", i++, usb_vcp_rx_any(), rx_buf[rx_buf_out]);
|
|
||||||
sys_tick_delay_ms(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char *line = readline(">>> ");
|
char *line = readline(">>> ");
|
||||||
@ -282,6 +288,11 @@ int main() {
|
|||||||
qstr_init();
|
qstr_init();
|
||||||
rt_init();
|
rt_init();
|
||||||
|
|
||||||
|
// add some functions to the python namespace
|
||||||
|
rt_store_name(qstr_from_str_static("pyb_delay"), rt_make_function_1(pyb_delay));
|
||||||
|
rt_store_name(qstr_from_str_static("pyb_led"), rt_make_function_1(pyb_led));
|
||||||
|
rt_store_name(qstr_from_str_static("pyb_sw"), rt_make_function_0(pyb_sw));
|
||||||
|
|
||||||
// print a message
|
// print a message
|
||||||
printf(" micro py board\n");
|
printf(" micro py board\n");
|
||||||
|
|
||||||
@ -478,11 +489,6 @@ int main() {
|
|||||||
} else {
|
} else {
|
||||||
// execute it!
|
// execute it!
|
||||||
|
|
||||||
// add some functions to the python namespace
|
|
||||||
rt_store_name(qstr_from_str_static("pyb_delay"), rt_make_function_1(pyb_delay));
|
|
||||||
rt_store_name(qstr_from_str_static("pyb_led"), rt_make_function_1(pyb_led));
|
|
||||||
rt_store_name(qstr_from_str_static("pyb_sw"), rt_make_function_0(pyb_sw));
|
|
||||||
|
|
||||||
py_obj_t module_fun = rt_make_function_from_id(1);
|
py_obj_t module_fun = rt_make_function_from_id(1);
|
||||||
|
|
||||||
// flash once
|
// flash once
|
||||||
|
@ -209,12 +209,12 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void lcd_print_strn(const char *str, unsigned int len);
|
void lcd_print_strn(const char *str, unsigned int len);
|
||||||
void usb_vcp_send(const char* str, int len);
|
void usb_vcp_send_strn(const char* str, int len);
|
||||||
|
|
||||||
void stdout_print_strn(void *data, const char *str, unsigned int len) {
|
void stdout_print_strn(void *data, const char *str, unsigned int len) {
|
||||||
// send stdout to LCD and USB CDC VCP
|
// send stdout to LCD and USB CDC VCP
|
||||||
lcd_print_strn(str, len);
|
lcd_print_strn(str, len);
|
||||||
//usb_vcp_send(str, len);
|
usb_vcp_send_strn(str, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const pfenv_t pfenv_stdout = {0, stdout_print_strn};
|
static const pfenv_t pfenv_stdout = {0, stdout_print_strn};
|
||||||
|
20
stm/usb.c
20
stm/usb.c
@ -26,15 +26,17 @@ void usb_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void usb_vcp_receive(const char *buf, uint32_t len) {
|
void usb_vcp_receive(const char *buf, uint32_t len) {
|
||||||
for (int i = 0; i < len; i++) {
|
if (is_enabled) {
|
||||||
rx_buf[rx_buf_in++] = buf[i];
|
for (int i = 0; i < len; i++) {
|
||||||
if (rx_buf_in >= sizeof(rx_buf)) {
|
rx_buf[rx_buf_in++] = buf[i];
|
||||||
rx_buf_in = 0;
|
if (rx_buf_in >= sizeof(rx_buf)) {
|
||||||
}
|
rx_buf_in = 0;
|
||||||
if (rx_buf_in == rx_buf_out) {
|
}
|
||||||
rx_buf_out = rx_buf_in + 1;
|
if (rx_buf_in == rx_buf_out) {
|
||||||
if (rx_buf_out >= sizeof(rx_buf)) {
|
rx_buf_out = rx_buf_in + 1;
|
||||||
rx_buf_out = 0;
|
if (rx_buf_out >= sizeof(rx_buf)) {
|
||||||
|
rx_buf_out = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user