diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-29 14:20:05 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-29 14:20:05 +0000 |
commit | c9fd6645b0a1af73f3854ddc2745596070985a18 (patch) | |
tree | 24440350973d243c8f5522d9e1c7862b14b54767 /stmhal/pybstdio.c | |
parent | c689c194710f4acf4cabd193795b57e5a101420e (diff) |
stmhal: Factor out stdio and readline to separate files.
Adds readline_init() to clear readline history on soft reset. Addresses
issue #387.
Diffstat (limited to 'stmhal/pybstdio.c')
-rw-r--r-- | stmhal/pybstdio.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/stmhal/pybstdio.c b/stmhal/pybstdio.c new file mode 100644 index 000000000..95582d330 --- /dev/null +++ b/stmhal/pybstdio.c @@ -0,0 +1,54 @@ +#include <stm32f4xx_hal.h> + +#include "misc.h" +#include "mpconfig.h" +#include "qstr.h" +#include "misc.h" +#include "obj.h" +#include "pybstdio.h" +#include "storage.h" +#include "usb.h" +#include "usart.h" + +void stdout_tx_str(const char *str) { + if (pyb_usart_global_debug != PYB_USART_NONE) { + usart_tx_str(pyb_usart_global_debug, str); + } +#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD + lcd_print_str(str); +#endif + usb_vcp_send_str(str); +} + +void stdout_tx_strn(const char *str, uint len) { + if (pyb_usart_global_debug != PYB_USART_NONE) { + usart_tx_strn(pyb_usart_global_debug, str, len); + } +#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD + lcd_print_strn(str, len); +#endif + usb_vcp_send_strn(str, len); +} + +int stdin_rx_chr(void) { + for (;;) { +#if 0 +#ifdef USE_HOST_MODE + pyb_usb_host_process(); + int c = pyb_usb_host_get_keyboard(); + if (c != 0) { + return c; + } +#endif +#endif + if (usb_vcp_rx_num() != 0) { + return usb_vcp_rx_get(); + } else if (pyb_usart_global_debug != PYB_USART_NONE && usart_rx_any(pyb_usart_global_debug)) { + return usart_rx_char(pyb_usart_global_debug); + } + HAL_Delay(1); + if (storage_needs_flush()) { + storage_flush(); + } + } +} |