From fca3308cc376f2c1c66fa3cef82e30c55c9acca2 Mon Sep 17 00:00:00 2001 From: danicampora Date: Fri, 16 Oct 2015 10:12:54 +0200 Subject: [PATCH] cc3200: Improvements to terminal duplication. --- cc3200/hal/cc3200_hal.c | 18 +++++++++++------- cc3200/mods/modussl.c | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c index 7ea243d1b2..b29c0fee0b 100644 --- a/cc3200/hal/cc3200_hal.c +++ b/cc3200/hal/cc3200_hal.c @@ -31,13 +31,16 @@ #include #include #include + + +#include "py/mpstate.h" +#include MICROPY_HAL_H +#include "py/runtime.h" +#include "py/objstr.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_nvic.h" #include "hw_memmap.h" -#include "py/mpstate.h" -#include "py/runtime.h" -#include MICROPY_HAL_H #include "rom_map.h" #include "interrupt.h" #include "systick.h" @@ -142,7 +145,7 @@ void mp_hal_stdout_tx_strn(const char *str, uint32_t len) { if (MP_OBJ_IS_TYPE(MP_STATE_PORT(os_term_dup_obj)->stream_o, &pyb_uart_type)) { uart_tx_strn(MP_STATE_PORT(os_term_dup_obj)->stream_o, str, len); } else { - MP_STATE_PORT(os_term_dup_obj)->write[2] = mp_obj_new_bytes((const byte*)str, len); + MP_STATE_PORT(os_term_dup_obj)->write[2] = mp_obj_new_str_of_type(&mp_type_str, (const byte *)str, len); mp_call_method_n_kw(1, 0, MP_STATE_PORT(os_term_dup_obj)->write); } } @@ -181,10 +184,11 @@ int mp_hal_stdin_rx_chr(void) { } } else { MP_STATE_PORT(os_term_dup_obj)->read[2] = mp_obj_new_int(1); - mp_obj_t rbytes = mp_call_method_n_kw(1, 0, MP_STATE_PORT(os_term_dup_obj)->read); - if (rbytes != mp_const_none) { + mp_obj_t data = mp_call_method_n_kw(1, 0, MP_STATE_PORT(os_term_dup_obj)->read); + // data len is > 0 + if (mp_obj_is_true(data)) { mp_buffer_info_t bufinfo; - mp_get_buffer_raise(rbytes, &bufinfo, MP_BUFFER_READ); + mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); return ((int *)(bufinfo.buf))[0]; } } diff --git a/cc3200/mods/modussl.c b/cc3200/mods/modussl.c index 31005631ba..a11d2b2ef9 100644 --- a/cc3200/mods/modussl.c +++ b/cc3200/mods/modussl.c @@ -91,7 +91,7 @@ STATIC mp_obj_t mod_ssl_wrap_socket(mp_uint_t n_args, const mp_obj_t *pos_args, goto arg_error; } - // retrieve the file paths (with an 6 byte offset because to strip the '/flash' prefix) + // retrieve the file paths (with an 6 byte offset in order to strip it from the '/flash' prefix) const char *keyfile = (args[1].u_obj == mp_const_none) ? NULL : &(mp_obj_str_get_str(args[1].u_obj)[6]); const char *certfile = (args[2].u_obj == mp_const_none) ? NULL : &(mp_obj_str_get_str(args[2].u_obj)[6]); const char *cafile = (args[5].u_obj == mp_const_none || args[4].u_int != SSL_CERT_REQUIRED) ?