|
30 | 30 | ******************************************************************************/ |
31 | 31 | #include <stdio.h> |
32 | 32 | #include <stdint.h> |
| 33 | +#include <string.h> |
33 | 34 | #include "inc/hw_types.h" |
34 | 35 | #include "inc/hw_ints.h" |
35 | 36 | #include "inc/hw_nvic.h" |
36 | 37 | #include "hw_memmap.h" |
37 | | -#include "mpconfig.h" |
| 38 | +#include "py/mpstate.h" |
38 | 39 | #include MICROPY_HAL_H |
39 | 40 | #include "rom_map.h" |
40 | 41 | #include "interrupt.h" |
|
43 | 44 | #include "sdhost.h" |
44 | 45 | #include "pin.h" |
45 | 46 | #include "mpexception.h" |
| 47 | +#include "telnet.h" |
| 48 | +#include "pybuart.h" |
46 | 49 |
|
47 | 50 | #ifdef USE_FREERTOS |
48 | 51 | #include "FreeRTOS.h" |
@@ -126,6 +129,43 @@ void mp_hal_set_interrupt_char (int c) { |
126 | 129 | mpexception_set_interrupt_char (c); |
127 | 130 | } |
128 | 131 |
|
| 132 | +void mp_hal_stdout_tx_str(const char *str) { |
| 133 | + mp_hal_stdout_tx_strn(str, strlen(str)); |
| 134 | +} |
| 135 | + |
| 136 | +void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { |
| 137 | + if (MP_STATE_PORT(pyb_stdio_uart) != NULL) { |
| 138 | + uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len); |
| 139 | + } |
| 140 | + // and also to telnet |
| 141 | + if (telnet_is_active()) { |
| 142 | + telnet_tx_strn(str, len); |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) { |
| 147 | + // send stdout to UART |
| 148 | + if (MP_STATE_PORT(pyb_stdio_uart) != NULL) { |
| 149 | + uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len); |
| 150 | + } |
| 151 | + // and also to telnet |
| 152 | + if (telnet_is_active()) { |
| 153 | + telnet_tx_strn_cooked(str, len); |
| 154 | + } |
| 155 | +} |
| 156 | + |
| 157 | +int mp_hal_stdin_rx_chr(void) { |
| 158 | + for ( ;; ) { |
| 159 | + if (telnet_rx_any()) { |
| 160 | + return telnet_rx_char(); |
| 161 | + } |
| 162 | + else if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) { |
| 163 | + return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart)); |
| 164 | + } |
| 165 | + HAL_Delay(1); |
| 166 | + } |
| 167 | +} |
| 168 | + |
129 | 169 | /****************************************************************************** |
130 | 170 | DEFINE PRIVATE FUNCTIONS |
131 | 171 | ******************************************************************************/ |
|
0 commit comments