From f14861c2457f3f9d3c8610ca48c080f63c787b66 Mon Sep 17 00:00:00 2001 From: MicroDev <70126934+MicroDev1@users.noreply.github.com> Date: Wed, 29 Mar 2023 09:49:35 +0530 Subject: [PATCH] fix espnow reinit, remove todos and improve docs --- ports/espressif/bindings/espidf/__init__.c | 14 ++++++++++---- ports/espressif/bindings/espnow/ESPNow.c | 10 +++++++--- ports/espressif/bindings/espnow/Peer.c | 5 +---- ports/espressif/bindings/espnow/Peers.c | 2 -- ports/espressif/bindings/espnow/__init__.c | 5 ++--- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/ports/espressif/bindings/espidf/__init__.c b/ports/espressif/bindings/espidf/__init__.c index c1ef9da1e0..65b7f12a18 100644 --- a/ports/espressif/bindings/espidf/__init__.c +++ b/ports/espressif/bindings/espidf/__init__.c @@ -34,6 +34,8 @@ #include "nvs_flash.h" #include "components/heap/include/esp_heap_caps.h" +//| import builtins +//| //| """Direct access to a few ESP-IDF details. This module *should not* include any functionality //| that could be implemented by other frameworks. It should only include ESP-IDF specific //| things.""" @@ -95,6 +97,13 @@ STATIC void espidf_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_pr mp_obj_exception_print(print, o_in, kind); } +//| class IDFError(builtins.OSError): +//| """Raised when an ``ESP-IDF`` function returns an error code. +//| `esp_err_t `_ +//| """ +//| +//| ... +//| const mp_obj_type_t mp_type_espidf_IDFError = { { &mp_type_type }, .name = MP_QSTR_IDFError, @@ -104,11 +113,8 @@ const mp_obj_type_t mp_type_espidf_IDFError = { .parent = &mp_type_OSError, }; - -//| import builtins -//| //| class MemoryError(builtins.MemoryError): -//| """Raised when an ESP IDF memory allocation fails.""" +//| """Raised when an ``ESP-IDF`` memory allocation fails.""" //| //| ... //| diff --git a/ports/espressif/bindings/espnow/ESPNow.c b/ports/espressif/bindings/espnow/ESPNow.c index 32676bc9be..78d80924fd 100644 --- a/ports/espressif/bindings/espnow/ESPNow.c +++ b/ports/espressif/bindings/espnow/ESPNow.c @@ -57,7 +57,9 @@ static void espnow_check_for_deinit(espnow_obj_t *self) { //| """Allocate and initialize `ESPNow` instance as a singleton. //| //| :param int buffer_size: The size of the internal ring buffer. Default: 526 bytes. -//| :param int phy_rate: The ESP-NOW physical layer rate. Default: 1 Mbps.""" +//| :param int phy_rate: The ESP-NOW physical layer rate. Default: 1 Mbps. +//| `wifi_phy_rate_t `_ +//| """ //| ... STATIC mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_buffer_size, ARG_phy_rate }; @@ -71,7 +73,7 @@ STATIC mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, size_t espnow_obj_t *self = MP_STATE_PORT(espnow_singleton); - if (self != NULL) { + if (!common_hal_espnow_deinited(self)) { mp_raise_RuntimeError(translate("Already running")); } @@ -244,7 +246,9 @@ MP_PROPERTY_GETTER(espnow_buffer_size_obj, (mp_obj_t)&espnow_get_buffer_size_obj); //| phy_rate: int -//| """The ESP-NOW physical layer rate.""" +//| """The ESP-NOW physical layer rate. +//| `wifi_phy_rate_t `_ +//| """ //| STATIC mp_obj_t espnow_get_phy_rate(const mp_obj_t self_in) { espnow_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/ports/espressif/bindings/espnow/Peer.c b/ports/espressif/bindings/espnow/Peer.c index 5c21dafc4c..f69bec01e6 100644 --- a/ports/espressif/bindings/espnow/Peer.c +++ b/ports/espressif/bindings/espnow/Peer.c @@ -31,9 +31,6 @@ #include "bindings/espnow/Peer.h" #include "common-hal/espnow/__init__.h" -// TODO: check peer already exist -// TODO: check peer doesn't exist - //| class Peer: //| """A data class to store parameters specific to a peer.""" //| @@ -62,7 +59,7 @@ STATIC mp_obj_t espnow_peer_make_new(const mp_obj_type_t *type, size_t n_args, s { MP_QSTR_lmk, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } }, { MP_QSTR_channel, MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 0 } }, { MP_QSTR_interface,MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 0 } }, - { MP_QSTR_encrypted,MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } }, + { MP_QSTR_encrypted,MP_ARG_BOOL | MP_ARG_KW_ONLY,{ .u_bool = false } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; diff --git a/ports/espressif/bindings/espnow/Peers.c b/ports/espressif/bindings/espnow/Peers.c index 15d07c09d0..6fda9aed7a 100644 --- a/ports/espressif/bindings/espnow/Peers.c +++ b/ports/espressif/bindings/espnow/Peers.c @@ -35,8 +35,6 @@ #include "esp_now.h" -// TODO: Check for deinit - //| class Peers: //| """Maintains a `list` of `Peer` internally and only exposes a subset of `list` methods.""" //| diff --git a/ports/espressif/bindings/espnow/__init__.c b/ports/espressif/bindings/espnow/__init__.c index da15be49ea..3135858601 100644 --- a/ports/espressif/bindings/espnow/__init__.c +++ b/ports/espressif/bindings/espnow/__init__.c @@ -33,9 +33,8 @@ //| """ESP-NOW Module //| //| The `espnow` module provides an interface to the -//| `ESP-NOW `_ -//| protocol provided by Espressif on its SoCs -//| (`API docs `_). +//| `ESP-NOW `_ +//| protocol provided by Espressif on its SoCs. //| //| **Sender** //|