Skip to content

Commit 45e983a

Browse files
committed
ports: Provide mp_hal_stdio_poll for sys.stdio polling where needed.
1 parent c80a484 commit 45e983a

File tree

6 files changed

+53
-0
lines changed

6 files changed

+53
-0
lines changed

ports/cc3200/hal/cc3200_hal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ extern void HAL_SystemDeInit (void);
6464
extern void HAL_IncrementTick(void);
6565
extern void mp_hal_set_interrupt_char (int c);
6666

67+
#define mp_hal_stdio_poll(poll_flags) (0) // not implemented
6768
#define mp_hal_delay_us(usec) UtilsDelay(UTILS_DELAY_US_TO_COUNT(usec))
6869
#define mp_hal_ticks_cpu() (SysTickPeriodGet() - SysTickValueGet())

ports/esp32/mphalport.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "rom/uart.h"
3535

3636
#include "py/obj.h"
37+
#include "py/stream.h"
3738
#include "py/mpstate.h"
3839
#include "py/mphal.h"
3940
#include "extmod/misc.h"
@@ -45,6 +46,14 @@ TaskHandle_t mp_main_task_handle;
4546
STATIC uint8_t stdin_ringbuf_array[256];
4647
ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array)};
4748

49+
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
50+
uintptr_t ret = 0;
51+
if ((poll_flags & MP_STREAM_POLL_RD) && stdin_ringbuf.iget != stdin_ringbuf.iput) {
52+
ret |= MP_STREAM_POLL_RD;
53+
}
54+
return ret;
55+
}
56+
4857
int mp_hal_stdin_rx_chr(void) {
4958
for (;;) {
5059
int c = ringbuf_get(&stdin_ringbuf);

ports/esp8266/esp_mphal.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "user_interface.h"
3333
#include "ets_alt_task.h"
3434
#include "py/runtime.h"
35+
#include "py/stream.h"
3536
#include "extmod/misc.h"
3637
#include "lib/utils/pyexec.h"
3738

@@ -56,6 +57,14 @@ void mp_hal_delay_us(uint32_t us) {
5657
}
5758
}
5859

60+
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
61+
uintptr_t ret = 0;
62+
if ((poll_flags & MP_STREAM_POLL_RD) && stdin_ringbuf.iget != stdin_ringbuf.iput) {
63+
ret |= MP_STREAM_POLL_RD;
64+
}
65+
return ret;
66+
}
67+
5968
int mp_hal_stdin_rx_chr(void) {
6069
for (;;) {
6170
int c = ringbuf_get(&stdin_ringbuf);

ports/pic16bit/pic16bit_mphal.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
#include <string.h>
28+
#include "py/stream.h"
2829
#include "py/mphal.h"
2930
#include "board.h"
3031

@@ -51,6 +52,14 @@ void mp_hal_set_interrupt_char(int c) {
5152
interrupt_char = c;
5253
}
5354

55+
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
56+
uintptr_t ret = 0;
57+
if ((poll_flags & MP_STREAM_POLL_RD) && uart_rx_any()) {
58+
ret |= MP_STREAM_POLL_RD;
59+
}
60+
return ret;
61+
}
62+
5463
int mp_hal_stdin_rx_chr(void) {
5564
for (;;) {
5665
if (uart_rx_any()) {

ports/stm32/mphalport.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <string.h>
22

33
#include "py/runtime.h"
4+
#include "py/stream.h"
45
#include "py/mperrno.h"
56
#include "py/mphal.h"
67
#include "extmod/misc.h"
@@ -19,6 +20,16 @@ NORETURN void mp_hal_raise(HAL_StatusTypeDef status) {
1920
mp_raise_OSError(mp_hal_status_to_errno_table[status]);
2021
}
2122

23+
MP_WEAK uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
24+
uintptr_t ret = 0;
25+
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
26+
int errcode;
27+
const mp_stream_p_t *stream_p = mp_get_stream(MP_STATE_PORT(pyb_stdio_uart));
28+
ret = stream_p->ioctl(MP_STATE_PORT(pyb_stdio_uart), MP_STREAM_POLL, poll_flags, &errcode);
29+
}
30+
return ret | mp_uos_dupterm_poll(poll_flags);
31+
}
32+
2233
MP_WEAK int mp_hal_stdin_rx_chr(void) {
2334
for (;;) {
2435
#if 0

ports/teensy/teensy_hal.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <string.h>
33

44
#include "py/runtime.h"
5+
#include "py/stream.h"
56
#include "py/mphal.h"
67
#include "usb.h"
78
#include "uart.h"
@@ -21,6 +22,19 @@ void mp_hal_set_interrupt_char(int c) {
2122
// you can't press Control-C and get your python script to stop.
2223
}
2324

25+
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
26+
uintptr_t ret = 0;
27+
if (poll_flags & MP_STREAM_POLL_RD) {
28+
if (usb_vcp_rx_num()) {
29+
ret |= MP_STREAM_POLL_RD;
30+
}
31+
if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
32+
ret |= MP_STREAM_POLL_RD;
33+
}
34+
}
35+
return ret;
36+
}
37+
2438
int mp_hal_stdin_rx_chr(void) {
2539
for (;;) {
2640
byte c;

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