aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George2019-06-19 14:02:38 +1000
committerDamien George2019-07-01 17:10:12 +1000
commitc80614dfc8b6454819380e4886d49dfd93193691 (patch)
treecdeec4bafad4cf8ed74efd8d2a6a39f44186143b
parent964ae328cd00260d9a017a4e67909694fded9902 (diff)
ports: Provide mp_hal_stdio_poll for sys.stdio polling where needed.
-rw-r--r--ports/cc3200/hal/cc3200_hal.h1
-rw-r--r--ports/esp32/mphalport.c9
-rw-r--r--ports/esp8266/esp_mphal.c9
-rw-r--r--ports/pic16bit/pic16bit_mphal.c9
-rw-r--r--ports/stm32/mphalport.c11
-rw-r--r--ports/teensy/teensy_hal.c14
6 files changed, 53 insertions, 0 deletions
diff --git a/ports/cc3200/hal/cc3200_hal.h b/ports/cc3200/hal/cc3200_hal.h
index 71e245eeb..3d0d632d5 100644
--- a/ports/cc3200/hal/cc3200_hal.h
+++ b/ports/cc3200/hal/cc3200_hal.h
@@ -64,5 +64,6 @@ extern void HAL_SystemDeInit (void);
extern void HAL_IncrementTick(void);
extern void mp_hal_set_interrupt_char (int c);
+#define mp_hal_stdio_poll(poll_flags) (0) // not implemented
#define mp_hal_delay_us(usec) UtilsDelay(UTILS_DELAY_US_TO_COUNT(usec))
#define mp_hal_ticks_cpu() (SysTickPeriodGet() - SysTickValueGet())
diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c
index 804c71986..0d1ea74d6 100644
--- a/ports/esp32/mphalport.c
+++ b/ports/esp32/mphalport.c
@@ -34,6 +34,7 @@
#include "rom/uart.h"
#include "py/obj.h"
+#include "py/stream.h"
#include "py/mpstate.h"
#include "py/mphal.h"
#include "extmod/misc.h"
@@ -45,6 +46,14 @@ TaskHandle_t mp_main_task_handle;
STATIC uint8_t stdin_ringbuf_array[256];
ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array)};
+uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
+ uintptr_t ret = 0;
+ if ((poll_flags & MP_STREAM_POLL_RD) && stdin_ringbuf.iget != stdin_ringbuf.iput) {
+ ret |= MP_STREAM_POLL_RD;
+ }
+ return ret;
+}
+
int mp_hal_stdin_rx_chr(void) {
for (;;) {
int c = ringbuf_get(&stdin_ringbuf);
diff --git a/ports/esp8266/esp_mphal.c b/ports/esp8266/esp_mphal.c
index 351bf522c..2ce288ea3 100644
--- a/ports/esp8266/esp_mphal.c
+++ b/ports/esp8266/esp_mphal.c
@@ -32,6 +32,7 @@
#include "user_interface.h"
#include "ets_alt_task.h"
#include "py/runtime.h"
+#include "py/stream.h"
#include "extmod/misc.h"
#include "lib/utils/pyexec.h"
@@ -56,6 +57,14 @@ void mp_hal_delay_us(uint32_t us) {
}
}
+uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
+ uintptr_t ret = 0;
+ if ((poll_flags & MP_STREAM_POLL_RD) && stdin_ringbuf.iget != stdin_ringbuf.iput) {
+ ret |= MP_STREAM_POLL_RD;
+ }
+ return ret;
+}
+
int mp_hal_stdin_rx_chr(void) {
for (;;) {
int c = ringbuf_get(&stdin_ringbuf);
diff --git a/ports/pic16bit/pic16bit_mphal.c b/ports/pic16bit/pic16bit_mphal.c
index 35955f2d3..adab38193 100644
--- a/ports/pic16bit/pic16bit_mphal.c
+++ b/ports/pic16bit/pic16bit_mphal.c
@@ -25,6 +25,7 @@
*/
#include <string.h>
+#include "py/stream.h"
#include "py/mphal.h"
#include "board.h"
@@ -51,6 +52,14 @@ void mp_hal_set_interrupt_char(int c) {
interrupt_char = c;
}
+uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
+ uintptr_t ret = 0;
+ if ((poll_flags & MP_STREAM_POLL_RD) && uart_rx_any()) {
+ ret |= MP_STREAM_POLL_RD;
+ }
+ return ret;
+}
+
int mp_hal_stdin_rx_chr(void) {
for (;;) {
if (uart_rx_any()) {
diff --git a/ports/stm32/mphalport.c b/ports/stm32/mphalport.c
index f4ae7293c..79b28bd3d 100644
--- a/ports/stm32/mphalport.c
+++ b/ports/stm32/mphalport.c
@@ -1,6 +1,7 @@
#include <string.h>
#include "py/runtime.h"
+#include "py/stream.h"
#include "py/mperrno.h"
#include "py/mphal.h"
#include "extmod/misc.h"
@@ -19,6 +20,16 @@ NORETURN void mp_hal_raise(HAL_StatusTypeDef status) {
mp_raise_OSError(mp_hal_status_to_errno_table[status]);
}
+MP_WEAK uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
+ uintptr_t ret = 0;
+ if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
+ int errcode;
+ const mp_stream_p_t *stream_p = mp_get_stream(MP_STATE_PORT(pyb_stdio_uart));
+ ret = stream_p->ioctl(MP_STATE_PORT(pyb_stdio_uart), MP_STREAM_POLL, poll_flags, &errcode);
+ }
+ return ret | mp_uos_dupterm_poll(poll_flags);
+}
+
MP_WEAK int mp_hal_stdin_rx_chr(void) {
for (;;) {
#if 0
diff --git a/ports/teensy/teensy_hal.c b/ports/teensy/teensy_hal.c
index 7ce82f1d2..e9cc6778d 100644
--- a/ports/teensy/teensy_hal.c
+++ b/ports/teensy/teensy_hal.c
@@ -2,6 +2,7 @@
#include <string.h>
#include "py/runtime.h"
+#include "py/stream.h"
#include "py/mphal.h"
#include "usb.h"
#include "uart.h"
@@ -21,6 +22,19 @@ void mp_hal_set_interrupt_char(int c) {
// you can't press Control-C and get your python script to stop.
}
+uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
+ uintptr_t ret = 0;
+ if (poll_flags & MP_STREAM_POLL_RD) {
+ if (usb_vcp_rx_num()) {
+ ret |= MP_STREAM_POLL_RD;
+ }
+ if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
+ ret |= MP_STREAM_POLL_RD;
+ }
+ }
+ return ret;
+}
+
int mp_hal_stdin_rx_chr(void) {
for (;;) {
byte c;