ports: Provide mp_hal_stdio_poll for sys.stdio polling where needed.
This commit is contained in:
parent
964ae328cd
commit
c80614dfc8
|
@ -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())
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue