Skip to content

Commit

Permalink
w60x: Make os.dupterm() run.
Browse files Browse the repository at this point in the history
And add a ioctl function to machine.UART, allowing to uss is as a
stream.

Signed-off-by: robert-hh <robert@hammelrath.com>
  • Loading branch information
robert-hh committed Jul 22, 2023
1 parent efe57f5 commit ed6dbd0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
22 changes: 18 additions & 4 deletions ports/w60x/hal/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "py/mpstate.h"
#include "py/mphal.h"
#include "py/stream.h"
#include "extmod/misc.h"

extern int sendchar(int ch);

Expand All @@ -48,6 +49,9 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
ret |= MP_STREAM_POLL_RD;
}
return ret;
#if MICROPY_PY_OS_DUPTERM
ret |= mp_os_dupterm_poll(poll_flags);
#endif
}

// Receive single character
Expand All @@ -57,18 +61,28 @@ int mp_hal_stdin_rx_chr(void) {
c = ringbuf_get(&stdin_ringbuf);
if (c != -1) {
return c;
} else {
MICROPY_EVENT_POLL_HOOK
}
#if MICROPY_PY_OS_DUPTERM
int dupterm_c = mp_os_dupterm_rx_chr();
if (dupterm_c >= 0) {
return dupterm_c;
}
#endif
MICROPY_EVENT_POLL_HOOK
}
}

// Send string of given length
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
while (len--) {

for (size_t i = 0; i < len; i++) {
// wait for TXE
sendchar(*str++);
sendchar(str[i]);
}

#if MICROPY_PY_OS_DUPTERM
mp_os_dupterm_tx_strn(str, len);
#endif
}

void mp_hal_stdout_tx_str(const char *str) {
Expand Down
21 changes: 21 additions & 0 deletions ports/w60x/machine/machine_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,31 @@ STATIC mp_uint_t machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uin
return size;
}

STATIC mp_uint_t machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
machine_uart_obj_t *self = self_in;
mp_uint_t ret;
if (request == MP_STREAM_POLL) {
uintptr_t flags = arg;
ret = 0;
if ((flags & MP_STREAM_POLL_RD) && tls_uart_read_avail(self->uart_num)) {
ret |= MP_STREAM_POLL_RD;
}
if (flags & MP_STREAM_POLL_WR) {
ret |= MP_STREAM_POLL_WR;
}
} else if (request == MP_STREAM_FLUSH) {
ret = 0;
} else {
*errcode = MP_EINVAL;
ret = MP_STREAM_ERROR;
}
return ret;
}

STATIC const mp_stream_p_t uart_stream_p = {
.read = machine_uart_read,
.write = machine_uart_write,
.ioctl = machine_uart_ioctl,
.is_text = false,
};

Expand Down
1 change: 0 additions & 1 deletion ports/w60x/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
#define MICROPY_WARNINGS (1)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#define MICROPY_STREAMS_POSIX_API (1)
#define MICROPY_USE_INTERNAL_ERRNO (1)
#define MICROPY_USE_INTERNAL_PRINTF (0)
#define MICROPY_SCHEDULER_DEPTH (8)
Expand Down

0 comments on commit ed6dbd0

Please sign in to comment.