ports: Use common mp_hal_stdout_tx_strn_cooked instead of custom one.
To reduce code duplication. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
20a6044952
commit
132d93886f
|
@ -147,6 +147,7 @@ APP_LIB_SRC_C = $(addprefix lib/,\
|
|||
utils/gchelper_native.c \
|
||||
utils/pyexec.c \
|
||||
utils/interrupt_char.c \
|
||||
utils/stdout_helpers.c \
|
||||
utils/sys_stdio_mphal.c \
|
||||
)
|
||||
|
||||
|
|
|
@ -141,10 +141,6 @@ void mp_hal_delay_ms(mp_uint_t delay) {
|
|||
}
|
||||
}
|
||||
|
||||
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, size_t len) {
|
||||
if (MP_STATE_PORT(os_term_dup_obj)) {
|
||||
if (mp_obj_is_type(MP_STATE_PORT(os_term_dup_obj)->stream_o, &pyb_uart_type)) {
|
||||
|
@ -158,25 +154,6 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
|||
telnet_tx_strn(str, len);
|
||||
}
|
||||
|
||||
void mp_hal_stdout_tx_strn_cooked (const char *str, size_t len) {
|
||||
int32_t nslen = 0;
|
||||
const char *_str = str;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (str[i] == '\n') {
|
||||
mp_hal_stdout_tx_strn(_str, nslen);
|
||||
mp_hal_stdout_tx_strn("\r\n", 2);
|
||||
_str += nslen + 1;
|
||||
nslen = 0;
|
||||
} else {
|
||||
nslen++;
|
||||
}
|
||||
}
|
||||
if (_str < str + len) {
|
||||
mp_hal_stdout_tx_strn(_str, nslen);
|
||||
}
|
||||
}
|
||||
|
||||
int mp_hal_stdin_rx_chr(void) {
|
||||
for ( ;; ) {
|
||||
// read telnet first
|
||||
|
|
|
@ -27,6 +27,7 @@ set(MICROPY_SOURCE_LIB
|
|||
${MICROPY_DIR}/lib/oofatfs/ffunicode.c
|
||||
${MICROPY_DIR}/lib/timeutils/timeutils.c
|
||||
${MICROPY_DIR}/lib/utils/interrupt_char.c
|
||||
${MICROPY_DIR}/lib/utils/stdout_helpers.c
|
||||
${MICROPY_DIR}/lib/utils/sys_stdio_mphal.c
|
||||
${MICROPY_DIR}/lib/utils/pyexec.c
|
||||
)
|
||||
|
|
|
@ -108,10 +108,6 @@ int mp_hal_stdin_rx_chr(void) {
|
|||
}
|
||||
}
|
||||
|
||||
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, uint32_t len) {
|
||||
// Only release the GIL if many characters are being sent
|
||||
bool release_gil = len > 20;
|
||||
|
@ -131,26 +127,6 @@ void mp_hal_stdout_tx_strn(const char *str, uint32_t len) {
|
|||
mp_uos_dupterm_tx_strn(str, len);
|
||||
}
|
||||
|
||||
// Efficiently convert "\n" to "\r\n"
|
||||
void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
|
||||
const char *last = str;
|
||||
while (len--) {
|
||||
if (*str == '\n') {
|
||||
if (str > last) {
|
||||
mp_hal_stdout_tx_strn(last, str - last);
|
||||
}
|
||||
mp_hal_stdout_tx_strn("\r\n", 2);
|
||||
++str;
|
||||
last = str;
|
||||
} else {
|
||||
++str;
|
||||
}
|
||||
}
|
||||
if (str > last) {
|
||||
mp_hal_stdout_tx_strn(last, str - last);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t mp_hal_ticks_ms(void) {
|
||||
return esp_timer_get_time() / 1000;
|
||||
}
|
||||
|
|
|
@ -145,6 +145,7 @@ LIB_SRC_C = $(addprefix lib/,\
|
|||
timeutils/timeutils.c \
|
||||
utils/pyexec.c \
|
||||
utils/interrupt_char.c \
|
||||
utils/stdout_helpers.c \
|
||||
utils/sys_stdio_mphal.c \
|
||||
)
|
||||
|
||||
|
|
|
@ -91,33 +91,10 @@ void mp_hal_debug_str(const char *str) {
|
|||
}
|
||||
#endif
|
||||
|
||||
void mp_hal_stdout_tx_str(const char *str) {
|
||||
mp_uos_dupterm_tx_strn(str, strlen(str));
|
||||
}
|
||||
|
||||
void mp_hal_stdout_tx_strn(const char *str, uint32_t len) {
|
||||
mp_uos_dupterm_tx_strn(str, len);
|
||||
}
|
||||
|
||||
void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len) {
|
||||
const char *last = str;
|
||||
while (len--) {
|
||||
if (*str == '\n') {
|
||||
if (str > last) {
|
||||
mp_uos_dupterm_tx_strn(last, str - last);
|
||||
}
|
||||
mp_uos_dupterm_tx_strn("\r\n", 2);
|
||||
++str;
|
||||
last = str;
|
||||
} else {
|
||||
++str;
|
||||
}
|
||||
}
|
||||
if (str > last) {
|
||||
mp_uos_dupterm_tx_strn(last, str - last);
|
||||
}
|
||||
}
|
||||
|
||||
void mp_hal_debug_tx_strn_cooked(void *env, const char *str, uint32_t len) {
|
||||
(void)env;
|
||||
while (len--) {
|
||||
|
|
|
@ -167,6 +167,7 @@ LIB_SRC_C += $(addprefix lib/,\
|
|||
utils/gchelper_native.c \
|
||||
utils/pyexec.c \
|
||||
utils/interrupt_char.c \
|
||||
utils/stdout_helpers.c \
|
||||
utils/sys_stdio_mphal.c \
|
||||
utils/mpirq.c \
|
||||
)
|
||||
|
|
|
@ -53,10 +53,6 @@ MP_WEAK int mp_hal_stdin_rx_chr(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void mp_hal_stdout_tx_str(const char *str) {
|
||||
mp_hal_stdout_tx_strn(str, strlen(str));
|
||||
}
|
||||
|
||||
MP_WEAK void mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
||||
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
|
||||
uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len);
|
||||
|
@ -67,26 +63,6 @@ MP_WEAK void mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
|||
mp_uos_dupterm_tx_strn(str, len);
|
||||
}
|
||||
|
||||
// Efficiently convert "\n" to "\r\n"
|
||||
void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
|
||||
const char *last = str;
|
||||
while (len--) {
|
||||
if (*str == '\n') {
|
||||
if (str > last) {
|
||||
mp_hal_stdout_tx_strn(last, str - last);
|
||||
}
|
||||
mp_hal_stdout_tx_strn("\r\n", 2);
|
||||
++str;
|
||||
last = str;
|
||||
} else {
|
||||
++str;
|
||||
}
|
||||
}
|
||||
if (str > last) {
|
||||
mp_hal_stdout_tx_strn(last, str - last);
|
||||
}
|
||||
}
|
||||
|
||||
#if __CORTEX_M >= 0x03
|
||||
void mp_hal_ticks_cpu_enable(void) {
|
||||
if (!(DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk)) {
|
||||
|
|
Loading…
Reference in New Issue