examples/embedding-full: Enable mphal-backed sys.stdin/out/err.

Signed-off-by: Christian Walther <cwalther@gmx.ch>
pull/11430/head
Christian Walther 2024-03-30 23:26:51 +01:00
rodzic e03158d2b9
commit 972938c721
4 zmienionych plików z 44 dodań i 2 usunięć

Wyświetl plik

@ -28,6 +28,12 @@ static const char *example_2 =
"help('modules')\n"
"import sys\n"
"help(sys)\n"
"print('sys.stdin.read(3):', repr(sys.stdin.read(3)))\n"
"print('sys.stdin.buffer.read(3):', repr(sys.stdin.buffer.read(3)))\n"
"sys.stdout.write('hello stdout text\\n')\n"
"sys.stdout.buffer.write(b'hello stdout binary\\n')\n"
"sys.stdout.write('hello stderr text\\n')\n"
"sys.stdout.buffer.write(b'hello stderr binary\\n')\n"
"import os\n"
"help(os)\n"
"print('os.uname():', os.uname())\n"
@ -51,7 +57,7 @@ static const char *example_2 =
;
// This array is the MicroPython GC heap.
static char heap[8 * 1024];
static char heap[10 * 1024];
int main() {
#if MICROPY_STACK_CHECK

Wyświetl plik

@ -14,6 +14,11 @@ EMBED_EXTRA += \
shared/timeutils/timeutils.h \
shared/timeutils/modtime_mphal.h
# Include source for mphal-backed stdio in the output.
# Disable when using POSIX-backed stdio (MICROPY_VFS_POSIX).
EMBED_EXTRA += \
shared/runtime/sys_stdio_mphal.c
# Freeze Python modules.
FROZEN_MANIFEST ?= manifest.py

Wyświetl plik

@ -40,7 +40,7 @@
// Can be enabled once either shared/runtime/sys_stdio_mphal.c or
// extmod/vfs_posix_file.c is included in the build.
#define MICROPY_PY_SYS_STDFILES (0)
//#define MICROPY_PY_SYS_STDFILES (0)
// Can be enabled if you provide an implementation of
// mp_hal_set_interrupt_char() in mphal.c or include

Wyświetl plik

@ -7,6 +7,9 @@
#include "py/builtin.h"
#include "py/compile.h"
#include "py/mperrno.h"
#if MICROPY_PY_SYS_STDFILES
#include "py/stream.h"
#endif
#if !MICROPY_VFS
@ -71,3 +74,31 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
printf("%.*s", (int)len, str);
start_of_line = (len > 0 && (str[len-1] == '\n' || str[len-1] == '\r'));
}
#if MICROPY_PY_SYS_STDFILES
// Binary-mode standard input
// Receive single character, blocking until one is available.
int mp_hal_stdin_rx_chr(void) {
return 'X';
}
// Binary-mode standard output
// Send the string of given length.
mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
printf("tx: %.*s", (int)len, str);
return len;
}
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
uintptr_t ret = 0;
if ((poll_flags & MP_STREAM_POLL_RD) /* && can_read */) {
ret |= MP_STREAM_POLL_RD;
}
if ((poll_flags & MP_STREAM_POLL_WR) /* && can_write */) {
ret |= MP_STREAM_POLL_WR;
}
return ret;
}
#endif