use esp error for espnow
This commit is contained in:
parent
cac90a6969
commit
a1644f15ea
@ -222,7 +222,7 @@ msgstr ""
|
||||
msgid "%q=%q"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
|
||||
#: ports/espressif/common-hal/espidf/__init__.c
|
||||
#, c-format
|
||||
msgid "%s error 0x%x"
|
||||
msgstr ""
|
||||
@ -680,7 +680,7 @@ msgstr ""
|
||||
msgid "CIRCUITPY drive could not be found or created."
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
|
||||
#: ports/espressif/common-hal/espidf/__init__.c
|
||||
msgid "CRC or checksum was invalid"
|
||||
msgstr ""
|
||||
|
||||
@ -1067,7 +1067,7 @@ msgstr ""
|
||||
msgid "GNSS init"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
|
||||
#: ports/espressif/common-hal/espidf/__init__.c
|
||||
msgid "Generic Failure"
|
||||
msgstr ""
|
||||
|
||||
@ -1235,8 +1235,7 @@ msgstr ""
|
||||
msgid "Invalid MAC address"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
|
||||
#: py/moduerrno.c
|
||||
#: ports/espressif/common-hal/espidf/__init__.c py/moduerrno.c
|
||||
msgid "Invalid argument"
|
||||
msgstr ""
|
||||
|
||||
@ -1266,7 +1265,7 @@ msgstr ""
|
||||
msgid "Invalid multicast MAC address"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
|
||||
#: ports/espressif/common-hal/espidf/__init__.c
|
||||
msgid "Invalid size"
|
||||
msgstr ""
|
||||
|
||||
@ -1275,7 +1274,7 @@ msgstr ""
|
||||
msgid "Invalid socket for TLS"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
|
||||
#: ports/espressif/common-hal/espidf/__init__.c
|
||||
msgid "Invalid state"
|
||||
msgstr ""
|
||||
|
||||
@ -1307,7 +1306,7 @@ msgstr ""
|
||||
msgid "Layer must be a Group or TileGrid subclass"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
|
||||
#: ports/espressif/common-hal/espidf/__init__.c
|
||||
msgid "MAC address was invalid"
|
||||
msgstr ""
|
||||
|
||||
@ -1667,11 +1666,11 @@ msgstr ""
|
||||
msgid "Operation not permitted"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
|
||||
#: ports/espressif/common-hal/espidf/__init__.c
|
||||
msgid "Operation or feature not supported"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
|
||||
#: ports/espressif/common-hal/espidf/__init__.c
|
||||
msgid "Operation timed out"
|
||||
msgstr ""
|
||||
|
||||
@ -1679,7 +1678,7 @@ msgstr ""
|
||||
msgid "Out of MDNS service slots"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
|
||||
#: ports/espressif/common-hal/espidf/__init__.c
|
||||
msgid "Out of memory"
|
||||
msgstr ""
|
||||
|
||||
@ -1855,7 +1854,7 @@ msgstr ""
|
||||
msgid "Read-only filesystem"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
|
||||
#: ports/espressif/common-hal/espidf/__init__.c
|
||||
msgid "Received response was invalid"
|
||||
msgstr ""
|
||||
|
||||
@ -1875,7 +1874,7 @@ msgstr ""
|
||||
msgid "Requested AES mode is unsupported"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
|
||||
#: ports/espressif/common-hal/espidf/__init__.c
|
||||
msgid "Requested resource not found"
|
||||
msgstr ""
|
||||
|
||||
@ -2341,7 +2340,7 @@ msgstr ""
|
||||
msgid "Value length > max_length"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
|
||||
#: ports/espressif/common-hal/espidf/__init__.c
|
||||
msgid "Version was invalid"
|
||||
msgstr ""
|
||||
|
||||
@ -2431,11 +2430,6 @@ msgstr ""
|
||||
msgid "addresses is empty"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/bindings/espnow/Peers.c
|
||||
#: ports/espressif/common-hal/espnow/ESPNow.c
|
||||
msgid "an error occured"
|
||||
msgstr ""
|
||||
|
||||
#: py/compile.c
|
||||
msgid "annotation must be an identifier"
|
||||
msgstr ""
|
||||
|
@ -218,7 +218,6 @@ endif
|
||||
SRC_C += \
|
||||
background.c \
|
||||
mphalport.c \
|
||||
bindings/espidf/__init__.c \
|
||||
boards/$(BOARD)/board.c \
|
||||
boards/$(BOARD)/pins.c \
|
||||
shared/netutils/netutils.c \
|
||||
@ -252,8 +251,6 @@ ifneq ($(CIRCUITPY_BLEIO),0)
|
||||
SRC_C += common-hal/_bleio/ble_events.c
|
||||
endif
|
||||
|
||||
SRC_C += $(wildcard common-hal/espidf/*.c)
|
||||
|
||||
ifneq ($(CIRCUITPY_ESPCAMERA),0)
|
||||
SRC_CAMERA := \
|
||||
$(wildcard common-hal/espcamera/*.c) \
|
||||
@ -263,6 +260,13 @@ CFLAGS += -isystem esp32-camera/driver/include
|
||||
CFLAGS += -isystem esp32-camera/conversions/include
|
||||
endif
|
||||
|
||||
ifneq ($(CIRCUITPY_ESPIDF),0)
|
||||
SRC_ESPIDF := \
|
||||
$(wildcard common-hal/espidf/*.c) \
|
||||
$(wildcard bindings/espidf/*.c)
|
||||
SRC_C += $(SRC_ESPIDF)
|
||||
endif
|
||||
|
||||
ifneq ($(CIRCUITPY_ESPNOW),0)
|
||||
SRC_ESPNOW := \
|
||||
$(wildcard common-hal/espnow/*.c) \
|
||||
|
@ -28,17 +28,13 @@
|
||||
#include "py/objlist.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "bindings/espidf/__init__.h"
|
||||
|
||||
#include "bindings/espnow/Peer.h"
|
||||
#include "bindings/espnow/Peers.h"
|
||||
|
||||
#include "esp_now.h"
|
||||
|
||||
static void check_esp_err(esp_err_t status) {
|
||||
if (status != ESP_OK) {
|
||||
mp_raise_RuntimeError(translate("an error occured"));
|
||||
}
|
||||
}
|
||||
|
||||
//| class Peers:
|
||||
//| """A class that provides peer managment functions. Sequence[Peer]."""
|
||||
//|
|
||||
@ -51,7 +47,7 @@ static void check_esp_err(esp_err_t status) {
|
||||
//| ...
|
||||
STATIC mp_obj_t espnow_peers_append(mp_obj_t self_in, mp_obj_t arg) {
|
||||
espnow_peer_obj_t *peer = MP_OBJ_TO_PTR(mp_arg_validate_type(arg, &espnow_peer_type, MP_QSTR_Peer));
|
||||
check_esp_err(esp_now_add_peer(&peer->peer_info));
|
||||
CHECK_ESP_RESULT(esp_now_add_peer(&peer->peer_info));
|
||||
espnow_peers_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return mp_obj_list_append(self->list, arg);
|
||||
}
|
||||
@ -66,7 +62,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_peers_append_obj, espnow_peers_append);
|
||||
//|
|
||||
STATIC mp_obj_t espnow_peers_remove(mp_obj_t self_in, mp_obj_t arg) {
|
||||
espnow_peer_obj_t *peer = MP_OBJ_TO_PTR(mp_arg_validate_type(arg, &espnow_peer_type, MP_QSTR_Peer));
|
||||
check_esp_err(esp_now_del_peer(peer->peer_info.peer_addr));
|
||||
CHECK_ESP_RESULT(esp_now_del_peer(peer->peer_info.peer_addr));
|
||||
espnow_peers_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return mp_obj_list_remove(self->list, arg);
|
||||
}
|
||||
|
@ -29,7 +29,9 @@
|
||||
#include "supervisor/memory.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "esp_now.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#define TAG "espidf"
|
||||
|
||||
#ifdef CONFIG_SPIRAM
|
||||
@ -180,14 +182,19 @@ void raise_esp_error(esp_err_t err) {
|
||||
|
||||
// tests must be in descending order
|
||||
MP_STATIC_ASSERT(ESP_ERR_FLASH_BASE > ESP_ERR_MESH_BASE);
|
||||
MP_STATIC_ASSERT(ESP_ERR_MESH_BASE > ESP_ERR_WIFI_BASE);
|
||||
MP_STATIC_ASSERT(ESP_ERR_MESH_BASE > ESP_ERR_ESPNOW_BASE);
|
||||
MP_STATIC_ASSERT(ESP_ERR_ESPNOW_BASE > ESP_ERR_WIFI_BASE);
|
||||
|
||||
if (err >= ESP_ERR_FLASH_BASE) {
|
||||
group = "Flash";
|
||||
} else if (err >= ESP_ERR_MESH_BASE) {
|
||||
group = "Mesh";
|
||||
} else if (err >= ESP_ERR_ESPNOW_BASE) {
|
||||
group = "ESP-NOW";
|
||||
} else if (err >= ESP_ERR_WIFI_BASE) {
|
||||
group = "WiFi";
|
||||
}
|
||||
|
||||
mp_raise_msg_varg(exception_type, translate("%s error 0x%x"), group, err);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,9 @@
|
||||
#include "py/mperrno.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "bindings/espidf/__init__.h"
|
||||
#include "bindings/espnow/ESPNowPacket.h"
|
||||
|
||||
#include "shared-bindings/wifi/__init__.h"
|
||||
|
||||
#include "common-hal/espnow/ESPNow.h"
|
||||
@ -41,6 +43,8 @@
|
||||
|
||||
#define ESPNOW_MAGIC 0x99
|
||||
|
||||
// TODO: deinit wifi?
|
||||
|
||||
// The maximum length of an espnow packet (bytes)
|
||||
#define MAX_PACKET_LEN (sizeof(espnow_packet_t) + ESP_NOW_MAX_DATA_LEN)
|
||||
|
||||
@ -66,12 +70,6 @@ typedef struct {
|
||||
uint8_t msg[0]; // Message is up to 250 bytes
|
||||
} __attribute__((packed)) espnow_packet_t;
|
||||
|
||||
static void check_esp_err(esp_err_t status) {
|
||||
if (status != ESP_OK) {
|
||||
mp_raise_RuntimeError(translate("an error occured"));
|
||||
}
|
||||
}
|
||||
|
||||
// Return a pointer to the ESPNow module singleton
|
||||
static espnow_obj_t *_get_singleton(void) {
|
||||
return MP_STATE_PORT(espnow_singleton);
|
||||
@ -152,12 +150,12 @@ void common_hal_espnow_init(espnow_obj_t *self) {
|
||||
common_hal_wifi_radio_set_enabled(&common_hal_wifi_radio_obj, true);
|
||||
}
|
||||
|
||||
check_esp_err(esp_wifi_config_espnow_rate(ESP_IF_WIFI_STA, self->phy_rate));
|
||||
check_esp_err(esp_wifi_config_espnow_rate(ESP_IF_WIFI_AP, self->phy_rate));
|
||||
CHECK_ESP_RESULT(esp_wifi_config_espnow_rate(ESP_IF_WIFI_STA, self->phy_rate));
|
||||
CHECK_ESP_RESULT(esp_wifi_config_espnow_rate(ESP_IF_WIFI_AP, self->phy_rate));
|
||||
|
||||
check_esp_err(esp_now_init());
|
||||
check_esp_err(esp_now_register_send_cb(send_cb));
|
||||
check_esp_err(esp_now_register_recv_cb(recv_cb));
|
||||
CHECK_ESP_RESULT(esp_now_init());
|
||||
CHECK_ESP_RESULT(esp_now_register_send_cb(send_cb));
|
||||
CHECK_ESP_RESULT(esp_now_register_recv_cb(recv_cb));
|
||||
}
|
||||
|
||||
// De-initialize the ESP-NOW software stack,
|
||||
@ -167,9 +165,9 @@ void common_hal_espnow_deinit(espnow_obj_t *self) {
|
||||
return;
|
||||
}
|
||||
|
||||
check_esp_err(esp_now_unregister_send_cb());
|
||||
check_esp_err(esp_now_unregister_recv_cb());
|
||||
check_esp_err(esp_now_deinit());
|
||||
CHECK_ESP_RESULT(esp_now_unregister_send_cb());
|
||||
CHECK_ESP_RESULT(esp_now_unregister_recv_cb());
|
||||
CHECK_ESP_RESULT(esp_now_deinit());
|
||||
|
||||
self->recv_buffer->buf = NULL;
|
||||
self->recv_buffer = NULL;
|
||||
@ -191,7 +189,7 @@ void common_hal_espnow_set_phy_rate(espnow_obj_t *self, mp_int_t value) {
|
||||
};
|
||||
|
||||
void common_hal_espnow_set_pmk(espnow_obj_t *self, const uint8_t *key) {
|
||||
check_esp_err(esp_now_set_pmk(key));
|
||||
CHECK_ESP_RESULT(esp_now_set_pmk(key));
|
||||
}
|
||||
|
||||
// --- Send and Receive ESP-NOW data ---
|
||||
@ -206,7 +204,7 @@ mp_obj_t common_hal_espnow_send(espnow_obj_t *self, const uint8_t *mac, const mp
|
||||
(mp_hal_ticks_ms() - start) <= DEFAULT_SEND_TIMEOUT_MS) {
|
||||
RUN_BACKGROUND_TASKS;
|
||||
}
|
||||
check_esp_err(err);
|
||||
CHECK_ESP_RESULT(err);
|
||||
|
||||
// Increment the sent packet count.
|
||||
// If mac == NULL msg will be sent to all peers EXCEPT any broadcast or multicast addresses.
|
||||
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "esp_error.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "bindings/espidf/__init__.h"
|
||||
|
||||
void raise_esp_error(esp_err_t err) {
|
||||
const compressed_string_t *msg = NULL;
|
||||
const mp_obj_type_t *exception_type = &mp_type_espidf_IDFError;
|
||||
switch (err) {
|
||||
case ESP_FAIL:
|
||||
msg = translate("Generic Failure");
|
||||
break;
|
||||
case ESP_ERR_NO_MEM:
|
||||
exception_type = &mp_type_espidf_MemoryError;
|
||||
msg = translate("Out of memory");
|
||||
break;
|
||||
case ESP_ERR_INVALID_ARG:
|
||||
msg = translate("Invalid argument");
|
||||
break;
|
||||
case ESP_ERR_INVALID_STATE:
|
||||
msg = translate("Invalid state");
|
||||
break;
|
||||
case ESP_ERR_INVALID_SIZE:
|
||||
msg = translate("Invalid size");
|
||||
break;
|
||||
case ESP_ERR_NOT_FOUND:
|
||||
msg = translate("Requested resource not found");
|
||||
break;
|
||||
case ESP_ERR_NOT_SUPPORTED:
|
||||
msg = translate("Operation or feature not supported");
|
||||
break;
|
||||
case ESP_ERR_TIMEOUT:
|
||||
msg = translate("Operation timed out");
|
||||
break;
|
||||
case ESP_ERR_INVALID_RESPONSE:
|
||||
msg = translate("Received response was invalid");
|
||||
break;
|
||||
case ESP_ERR_INVALID_CRC:
|
||||
msg = translate("CRC or checksum was invalid");
|
||||
break;
|
||||
case ESP_ERR_INVALID_VERSION:
|
||||
msg = translate("Version was invalid");
|
||||
break;
|
||||
case ESP_ERR_INVALID_MAC:
|
||||
msg = translate("MAC address was invalid");
|
||||
break;
|
||||
}
|
||||
if (msg) {
|
||||
mp_raise_msg(exception_type, msg);
|
||||
}
|
||||
|
||||
const char *group = "ESP-IDF";
|
||||
|
||||
// tests must be in descending order
|
||||
MP_STATIC_ASSERT(ESP_ERR_FLASH_BASE > ESP_ERR_MESH_BASE);
|
||||
MP_STATIC_ASSERT(ESP_ERR_MESH_BASE > ESP_ERR_WIFI_BASE);
|
||||
if (err >= ESP_ERR_FLASH_BASE) {
|
||||
group = "Flash";
|
||||
} else if (err >= ESP_ERR_MESH_BASE) {
|
||||
group = "Mesh";
|
||||
} else if (err >= ESP_ERR_WIFI_BASE) {
|
||||
group = "WiFi";
|
||||
}
|
||||
mp_raise_msg_varg(exception_type, translate("%s error 0x%x"), group, err);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user