@@ -184,32 +184,38 @@ static void board_info() {
184184}
185185
186186char * readline (const char * prompt ) {
187- printf ("a\n" );
188- led_state (PYB_LED_R1 , 1 );
189- printf ("b\n" );
187+ vstr_t vstr ;
188+ vstr_init (& vstr );
190189 usb_vcp_send_str (prompt );
191190 for (;;) {
192- printf ("c\n" );
193- led_state (PYB_LED_R2 , 1 );
191+ //extern int rx_buf_in;
192+ //extern int rx_buf_out;
193+ while (usb_vcp_rx_any () == 0 ) {
194+ //printf("nope %x %x\n", rx_buf_in, rx_buf_out);
195+ sys_tick_delay_ms (10 );
196+ }
194197 char c = usb_vcp_rx_get ();
195- led_state (PYB_LED_R2 , 0 );
196- usb_vcp_send_strn (& c , 1 );
197- led_state (PYB_LED_G1 , 1 );
198+ if (c == 4 && vstr_len (& vstr ) == 0 ) {
199+ return NULL ;
200+ } else if (c == '\r' ) {
201+ usb_vcp_send_str ("\r\n" );
202+ return vstr_str (& vstr );
203+ } else if (c == 127 ) {
204+ if (vstr_len (& vstr ) > 0 ) {
205+ vstr_cut_tail (& vstr , 1 );
206+ usb_vcp_send_str ("\b \b" );
207+ }
208+ } else if (32 <= c && c <= 126 ) {
209+ vstr_add_char (& vstr , c );
210+ usb_vcp_send_strn (& c , 1 );
211+ }
198212 sys_tick_delay_ms (100 );
199- led_state (PYB_LED_G1 , 0 );
200213 }
201214 return NULL ;
202215}
203216
204- extern char rx_buf [];
205- extern int rx_buf_out ;
206217void do_repl () {
207- int i = 0 ;
208- for (;;) {
209218 usb_vcp_send_str ("Micro Python\r\n" );
210- printf ("%d %d %c\n" , i ++ , usb_vcp_rx_any (), rx_buf [rx_buf_out ]);
211- sys_tick_delay_ms (1000 );
212- }
213219
214220 for (;;) {
215221 char * line = readline (">>> " );
@@ -282,6 +288,11 @@ int main() {
282288 qstr_init ();
283289 rt_init ();
284290
291+ // add some functions to the python namespace
292+ rt_store_name (qstr_from_str_static ("pyb_delay" ), rt_make_function_1 (pyb_delay ));
293+ rt_store_name (qstr_from_str_static ("pyb_led" ), rt_make_function_1 (pyb_led ));
294+ rt_store_name (qstr_from_str_static ("pyb_sw" ), rt_make_function_0 (pyb_sw ));
295+
285296 // print a message
286297 printf (" micro py board\n" );
287298
@@ -478,11 +489,6 @@ int main() {
478489 } else {
479490 // execute it!
480491
481- // add some functions to the python namespace
482- rt_store_name (qstr_from_str_static ("pyb_delay" ), rt_make_function_1 (pyb_delay ));
483- rt_store_name (qstr_from_str_static ("pyb_led" ), rt_make_function_1 (pyb_led ));
484- rt_store_name (qstr_from_str_static ("pyb_sw" ), rt_make_function_0 (pyb_sw ));
485-
486492 py_obj_t module_fun = rt_make_function_from_id (1 );
487493
488494 // flash once
0 commit comments