diff options
| author | Damien George | 2015-02-13 15:04:53 +0000 |
|---|---|---|
| committer | Damien George | 2015-02-13 15:04:53 +0000 |
| commit | 0b32e50365b6e36474e183a7240ccfc8fa56830a (patch) | |
| tree | 101cf35f6844c50672af4f15b5866e226bcb47d9 /cc3200/hal | |
| parent | c385a639e6316cba4ff0e7a859325807857d8f00 (diff) | |
stmhal: Make pybstdio usable by other ports, and use it.
Now all ports can use pybstdio.c to provide sys.stdin/stdout/stderr, so
long as they implement mp_hal_stdin_* and mp_hal_stdout_* functions.
Diffstat (limited to 'cc3200/hal')
| -rw-r--r-- | cc3200/hal/cc3200_hal.c | 42 | ||||
| -rw-r--r-- | cc3200/hal/cc3200_hal.h | 5 |
2 files changed, 46 insertions, 1 deletions
diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c index 8424065c5..cae936776 100644 --- a/cc3200/hal/cc3200_hal.c +++ b/cc3200/hal/cc3200_hal.c @@ -30,11 +30,12 @@ ******************************************************************************/ #include <stdio.h> #include <stdint.h> +#include <string.h> #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_nvic.h" #include "hw_memmap.h" -#include "mpconfig.h" +#include "py/mpstate.h" #include MICROPY_HAL_H #include "rom_map.h" #include "interrupt.h" @@ -43,6 +44,8 @@ #include "sdhost.h" #include "pin.h" #include "mpexception.h" +#include "telnet.h" +#include "pybuart.h" #ifdef USE_FREERTOS #include "FreeRTOS.h" @@ -126,6 +129,43 @@ void mp_hal_set_interrupt_char (int c) { mpexception_set_interrupt_char (c); } +void mp_hal_stdout_tx_str(const char *str) { + mp_hal_stdout_tx_strn(str, strlen(str)); +} + +void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { + if (MP_STATE_PORT(pyb_stdio_uart) != NULL) { + uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len); + } + // and also to telnet + if (telnet_is_active()) { + telnet_tx_strn(str, len); + } +} + +void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len) { + // send stdout to UART + if (MP_STATE_PORT(pyb_stdio_uart) != NULL) { + uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len); + } + // and also to telnet + if (telnet_is_active()) { + telnet_tx_strn_cooked(str, len); + } +} + +int mp_hal_stdin_rx_chr(void) { + for ( ;; ) { + if (telnet_rx_any()) { + return telnet_rx_char(); + } + else if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) { + return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart)); + } + HAL_Delay(1); + } +} + /****************************************************************************** DEFINE PRIVATE FUNCTIONS ******************************************************************************/ diff --git a/cc3200/hal/cc3200_hal.h b/cc3200/hal/cc3200_hal.h index 9562c827e..b738ff669 100644 --- a/cc3200/hal/cc3200_hal.h +++ b/cc3200/hal/cc3200_hal.h @@ -63,4 +63,9 @@ extern uint32_t HAL_GetTick(void); extern void HAL_Delay(uint32_t delay); extern void mp_hal_set_interrupt_char (int c); +int mp_hal_stdin_rx_chr(void); +void mp_hal_stdout_tx_str(const char *str); +void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len); +void mp_hal_stdout_tx_strn_cooked(const char *str, mp_uint_t len); + #endif /* CC3200_LAUNCHXL_HAL_CC3200_HAL_H_ */ |
