Skip to content

Commit b7da67c

Browse files
committed
lib/utils/sys_stdio_mphal: Add support to poll sys.stdin and sys.stdout.
A port must provide the following function for this to work: uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags);
1 parent 3786592 commit b7da67c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/utils/sys_stdio_mphal.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2013-2017 Damien P. George
6+
* Copyright (c) 2013-2019 Damien P. George
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal
@@ -85,6 +85,16 @@ STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size,
8585
}
8686
}
8787

88+
STATIC mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
89+
(void)self_in;
90+
if (request == MP_STREAM_POLL) {
91+
return mp_hal_stdio_poll(arg);
92+
} else {
93+
*errcode = MP_EINVAL;
94+
return MP_STREAM_ERROR;
95+
}
96+
}
97+
8898
STATIC mp_obj_t stdio_obj___exit__(size_t n_args, const mp_obj_t *args) {
8999
return mp_const_none;
90100
}
@@ -112,6 +122,7 @@ STATIC MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table);
112122
STATIC const mp_stream_p_t stdio_obj_stream_p = {
113123
.read = stdio_read,
114124
.write = stdio_write,
125+
.ioctl = stdio_ioctl,
115126
.is_text = true,
116127
};
117128

@@ -146,6 +157,7 @@ STATIC mp_uint_t stdio_buffer_write(mp_obj_t self_in, const void *buf, mp_uint_t
146157
STATIC const mp_stream_p_t stdio_buffer_obj_stream_p = {
147158
.read = stdio_buffer_read,
148159
.write = stdio_buffer_write,
160+
.ioctl = stdio_ioctl,
149161
.is_text = false,
150162
};
151163

py/mphal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
#include <mphalport.h>
3535
#endif
3636

37+
#ifndef mp_hal_stdio_poll
38+
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags);
39+
#endif
40+
3741
#ifndef mp_hal_stdin_rx_chr
3842
int mp_hal_stdin_rx_chr(void);
3943
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy