|
31 | 31 | #include <stdio.h> |
32 | 32 | #include <stdint.h> |
33 | 33 | #include <string.h> |
| 34 | + |
| 35 | + |
| 36 | +#include "py/mpstate.h" |
| 37 | +#include MICROPY_HAL_H |
| 38 | +#include "py/runtime.h" |
| 39 | +#include "py/objstr.h" |
34 | 40 | #include "inc/hw_types.h" |
35 | 41 | #include "inc/hw_ints.h" |
36 | 42 | #include "inc/hw_nvic.h" |
37 | 43 | #include "hw_memmap.h" |
38 | | -#include "py/mpstate.h" |
39 | | -#include "py/runtime.h" |
40 | | -#include MICROPY_HAL_H |
41 | 44 | #include "rom_map.h" |
42 | 45 | #include "interrupt.h" |
43 | 46 | #include "systick.h" |
@@ -142,7 +145,7 @@ void mp_hal_stdout_tx_strn(const char *str, uint32_t len) { |
142 | 145 | if (MP_OBJ_IS_TYPE(MP_STATE_PORT(os_term_dup_obj)->stream_o, &pyb_uart_type)) { |
143 | 146 | uart_tx_strn(MP_STATE_PORT(os_term_dup_obj)->stream_o, str, len); |
144 | 147 | } else { |
145 | | - MP_STATE_PORT(os_term_dup_obj)->write[2] = mp_obj_new_bytes((const byte*)str, len); |
| 148 | + MP_STATE_PORT(os_term_dup_obj)->write[2] = mp_obj_new_str_of_type(&mp_type_str, (const byte *)str, len); |
146 | 149 | mp_call_method_n_kw(1, 0, MP_STATE_PORT(os_term_dup_obj)->write); |
147 | 150 | } |
148 | 151 | } |
@@ -181,10 +184,11 @@ int mp_hal_stdin_rx_chr(void) { |
181 | 184 | } |
182 | 185 | } else { |
183 | 186 | MP_STATE_PORT(os_term_dup_obj)->read[2] = mp_obj_new_int(1); |
184 | | - mp_obj_t rbytes = mp_call_method_n_kw(1, 0, MP_STATE_PORT(os_term_dup_obj)->read); |
185 | | - if (rbytes != mp_const_none) { |
| 187 | + mp_obj_t data = mp_call_method_n_kw(1, 0, MP_STATE_PORT(os_term_dup_obj)->read); |
| 188 | + // data len is > 0 |
| 189 | + if (mp_obj_is_true(data)) { |
186 | 190 | mp_buffer_info_t bufinfo; |
187 | | - mp_get_buffer_raise(rbytes, &bufinfo, MP_BUFFER_READ); |
| 191 | + mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); |
188 | 192 | return ((int *)(bufinfo.buf))[0]; |
189 | 193 | } |
190 | 194 | } |
|
0 commit comments