summaryrefslogtreecommitdiff
path: root/ports/esp32/mpconfigport.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-04-27 23:53:45 +1000
committerDamien George <damien.p.george@gmail.com>2018-04-27 23:57:26 +1000
commit999c8b9711bf31ac375c09f35672e59b21d0aed4 (patch)
treee4ebd19862f4876105a5a47f9adee2f821b9c2ba /ports/esp32/mpconfigport.h
parent98b05e36148655ac53383f4ccea37e15445a5c54 (diff)
esp32/modsocket: Add support for registering socket event callbacks.
The esp8266 uses modlwip.c for its usocket implementation, which allows to easily support callbacks on socket events (like when a socket becomes ready for reading). This is not as easy to do for the esp32 which uses the ESP-IDF-provided lwIP POSIX socket API. Socket events are needed to get WebREPL working, and this patch provides a way for such events to work by explicitly polling registered sockets for readability, and then calling the associated callback if the socket is readable.
Diffstat (limited to 'ports/esp32/mpconfigport.h')
-rw-r--r--ports/esp32/mpconfigport.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h
index 2f4acaf12..0239de408 100644
--- a/ports/esp32/mpconfigport.h
+++ b/ports/esp32/mpconfigport.h
@@ -221,11 +221,18 @@ extern const struct _mp_obj_module_t mp_module_onewire;
#define MICROPY_BEGIN_ATOMIC_SECTION() portENTER_CRITICAL_NESTED()
#define MICROPY_END_ATOMIC_SECTION(state) portEXIT_CRITICAL_NESTED(state)
+#if MICROPY_PY_USOCKET_EVENTS
+#define MICROPY_PY_USOCKET_EVENTS_HANDLER extern void usocket_events_handler(void); usocket_events_handler();
+#else
+#define MICROPY_PY_USOCKET_EVENTS_HANDLER
+#endif
+
#if MICROPY_PY_THREAD
#define MICROPY_EVENT_POLL_HOOK \
do { \
extern void mp_handle_pending(void); \
mp_handle_pending(); \
+ MICROPY_PY_USOCKET_EVENTS_HANDLER \
MP_THREAD_GIL_EXIT(); \
MP_THREAD_GIL_ENTER(); \
} while (0);
@@ -234,6 +241,7 @@ extern const struct _mp_obj_module_t mp_module_onewire;
do { \
extern void mp_handle_pending(void); \
mp_handle_pending(); \
+ MICROPY_PY_USOCKET_EVENTS_HANDLER \
asm("waiti 0"); \
} while (0);
#endif