Skip to content

Fix espnow reinit, remove todos and improve docs #7809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions ports/espressif/bindings/espidf/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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 <https://docs.espressif.com/projects/esp-idf/en/release-v4.4/esp32/api-reference/error-codes.html>`_
//| """
//|
//| ...
//|
const mp_obj_type_t mp_type_espidf_IDFError = {
{ &mp_type_type },
.name = MP_QSTR_IDFError,
Expand All @@ -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."""
//|
//| ...
//|
Expand Down
10 changes: 7 additions & 3 deletions ports/espressif/bindings/espnow/ESPNow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://docs.espressif.com/projects/esp-idf/en/release-v4.4/esp32/api-reference/network/esp_wifi.html#_CPPv415wifi_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 };
Expand All @@ -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"));
}

Expand Down Expand Up @@ -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 <https://docs.espressif.com/projects/esp-idf/en/release-v4.4/esp32/api-reference/network/esp_wifi.html#_CPPv415wifi_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);
Expand Down
5 changes: 1 addition & 4 deletions ports/espressif/bindings/espnow/Peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
//|
Expand Down Expand Up @@ -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)];
Expand Down
2 changes: 0 additions & 2 deletions ports/espressif/bindings/espnow/Peers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
//|
Expand Down
5 changes: 2 additions & 3 deletions ports/espressif/bindings/espnow/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
//| """ESP-NOW Module
//|
//| The `espnow` module provides an interface to the
//| `ESP-NOW <https://www.espressif.com/en/products/software/esp-now/overview>`_
//| protocol provided by Espressif on its SoCs
//| (`API docs <https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/network/esp_now.html>`_).
//| `ESP-NOW <https://docs.espressif.com/projects/esp-idf/en/release-v4.4/esp32/api-reference/network/esp_now.html>`_
//| protocol provided by Espressif on its SoCs.
//|
//| **Sender**
//|
Expand Down