|
29 | 29 |
|
30 | 30 | #include "stm32f4xx_hal.h" |
31 | 31 |
|
32 | | -#include "misc.h" |
33 | 32 | #include "mpconfig.h" |
| 33 | +#include "misc.h" |
| 34 | +#include "nlr.h" |
34 | 35 | #include "qstr.h" |
35 | 36 | #include "obj.h" |
36 | 37 | #include "gc.h" |
@@ -302,6 +303,28 @@ STATIC mp_obj_t pyb_have_cdc(void ) { |
302 | 303 | } |
303 | 304 | STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_have_cdc_obj, pyb_have_cdc); |
304 | 305 |
|
| 306 | +/// \function repl_uart(uart) |
| 307 | +/// Get or set the UART object that the REPL is repeated on. |
| 308 | +STATIC mp_obj_t pyb_repl_uart(uint n_args, const mp_obj_t *args) { |
| 309 | + if (n_args == 0) { |
| 310 | + if (pyb_uart_global_debug == NULL) { |
| 311 | + return mp_const_none; |
| 312 | + } else { |
| 313 | + return pyb_uart_global_debug; |
| 314 | + } |
| 315 | + } else { |
| 316 | + if (args[0] == mp_const_none) { |
| 317 | + pyb_uart_global_debug = NULL; |
| 318 | + } else if (mp_obj_get_type(args[0]) == &pyb_uart_type) { |
| 319 | + pyb_uart_global_debug = args[0]; |
| 320 | + } else { |
| 321 | + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "need a UART object")); |
| 322 | + } |
| 323 | + return mp_const_none; |
| 324 | + } |
| 325 | +} |
| 326 | +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_repl_uart_obj, 0, 1, pyb_repl_uart); |
| 327 | + |
305 | 328 | /// \function hid((buttons, x, y, z)) |
306 | 329 | /// Takes a 4-tuple (or list) and sends it to the USB host (the PC) to |
307 | 330 | /// signal a HID mouse-motion event. |
@@ -342,6 +365,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = { |
342 | 365 | { MP_OBJ_NEW_QSTR(MP_QSTR_usb_mode), (mp_obj_t)&pyb_usb_mode_obj }, |
343 | 366 |
|
344 | 367 | { MP_OBJ_NEW_QSTR(MP_QSTR_have_cdc), (mp_obj_t)&pyb_have_cdc_obj }, |
| 368 | + { MP_OBJ_NEW_QSTR(MP_QSTR_repl_uart), (mp_obj_t)&pyb_repl_uart_obj }, |
345 | 369 | { MP_OBJ_NEW_QSTR(MP_QSTR_hid), (mp_obj_t)&pyb_hid_send_report_obj }, |
346 | 370 |
|
347 | 371 | { MP_OBJ_NEW_QSTR(MP_QSTR_millis), (mp_obj_t)&pyb_millis_obj }, |
|
0 commit comments