Skip to content

Commit a1644f1

Browse files
committed
use esp error for espnow
1 parent cac90a6 commit a1644f1

File tree

6 files changed

+46
-138
lines changed

6 files changed

+46
-138
lines changed

locale/circuitpython.pot

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ msgstr ""
222222
msgid "%q=%q"
223223
msgstr ""
224224

225-
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
225+
#: ports/espressif/common-hal/espidf/__init__.c
226226
#, c-format
227227
msgid "%s error 0x%x"
228228
msgstr ""
@@ -680,7 +680,7 @@ msgstr ""
680680
msgid "CIRCUITPY drive could not be found or created."
681681
msgstr ""
682682

683-
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
683+
#: ports/espressif/common-hal/espidf/__init__.c
684684
msgid "CRC or checksum was invalid"
685685
msgstr ""
686686

@@ -1067,7 +1067,7 @@ msgstr ""
10671067
msgid "GNSS init"
10681068
msgstr ""
10691069

1070-
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
1070+
#: ports/espressif/common-hal/espidf/__init__.c
10711071
msgid "Generic Failure"
10721072
msgstr ""
10731073

@@ -1235,8 +1235,7 @@ msgstr ""
12351235
msgid "Invalid MAC address"
12361236
msgstr ""
12371237

1238-
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
1239-
#: py/moduerrno.c
1238+
#: ports/espressif/common-hal/espidf/__init__.c py/moduerrno.c
12401239
msgid "Invalid argument"
12411240
msgstr ""
12421241

@@ -1266,7 +1265,7 @@ msgstr ""
12661265
msgid "Invalid multicast MAC address"
12671266
msgstr ""
12681267

1269-
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
1268+
#: ports/espressif/common-hal/espidf/__init__.c
12701269
msgid "Invalid size"
12711270
msgstr ""
12721271

@@ -1275,7 +1274,7 @@ msgstr ""
12751274
msgid "Invalid socket for TLS"
12761275
msgstr ""
12771276

1278-
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
1277+
#: ports/espressif/common-hal/espidf/__init__.c
12791278
msgid "Invalid state"
12801279
msgstr ""
12811280

@@ -1307,7 +1306,7 @@ msgstr ""
13071306
msgid "Layer must be a Group or TileGrid subclass"
13081307
msgstr ""
13091308

1310-
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
1309+
#: ports/espressif/common-hal/espidf/__init__.c
13111310
msgid "MAC address was invalid"
13121311
msgstr ""
13131312

@@ -1667,19 +1666,19 @@ msgstr ""
16671666
msgid "Operation not permitted"
16681667
msgstr ""
16691668

1670-
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
1669+
#: ports/espressif/common-hal/espidf/__init__.c
16711670
msgid "Operation or feature not supported"
16721671
msgstr ""
16731672

1674-
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
1673+
#: ports/espressif/common-hal/espidf/__init__.c
16751674
msgid "Operation timed out"
16761675
msgstr ""
16771676

16781677
#: ports/raspberrypi/common-hal/mdns/Server.c
16791678
msgid "Out of MDNS service slots"
16801679
msgstr ""
16811680

1682-
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
1681+
#: ports/espressif/common-hal/espidf/__init__.c
16831682
msgid "Out of memory"
16841683
msgstr ""
16851684

@@ -1855,7 +1854,7 @@ msgstr ""
18551854
msgid "Read-only filesystem"
18561855
msgstr ""
18571856

1858-
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
1857+
#: ports/espressif/common-hal/espidf/__init__.c
18591858
msgid "Received response was invalid"
18601859
msgstr ""
18611860

@@ -1875,7 +1874,7 @@ msgstr ""
18751874
msgid "Requested AES mode is unsupported"
18761875
msgstr ""
18771876

1878-
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
1877+
#: ports/espressif/common-hal/espidf/__init__.c
18791878
msgid "Requested resource not found"
18801879
msgstr ""
18811880

@@ -2341,7 +2340,7 @@ msgstr ""
23412340
msgid "Value length > max_length"
23422341
msgstr ""
23432342

2344-
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
2343+
#: ports/espressif/common-hal/espidf/__init__.c
23452344
msgid "Version was invalid"
23462345
msgstr ""
23472346

@@ -2431,11 +2430,6 @@ msgstr ""
24312430
msgid "addresses is empty"
24322431
msgstr ""
24332432

2434-
#: ports/espressif/bindings/espnow/Peers.c
2435-
#: ports/espressif/common-hal/espnow/ESPNow.c
2436-
msgid "an error occured"
2437-
msgstr ""
2438-
24392433
#: py/compile.c
24402434
msgid "annotation must be an identifier"
24412435
msgstr ""

ports/espressif/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ endif
218218
SRC_C += \
219219
background.c \
220220
mphalport.c \
221-
bindings/espidf/__init__.c \
222221
boards/$(BOARD)/board.c \
223222
boards/$(BOARD)/pins.c \
224223
shared/netutils/netutils.c \
@@ -252,8 +251,6 @@ ifneq ($(CIRCUITPY_BLEIO),0)
252251
SRC_C += common-hal/_bleio/ble_events.c
253252
endif
254253

255-
SRC_C += $(wildcard common-hal/espidf/*.c)
256-
257254
ifneq ($(CIRCUITPY_ESPCAMERA),0)
258255
SRC_CAMERA := \
259256
$(wildcard common-hal/espcamera/*.c) \
@@ -263,6 +260,13 @@ CFLAGS += -isystem esp32-camera/driver/include
263260
CFLAGS += -isystem esp32-camera/conversions/include
264261
endif
265262

263+
ifneq ($(CIRCUITPY_ESPIDF),0)
264+
SRC_ESPIDF := \
265+
$(wildcard common-hal/espidf/*.c) \
266+
$(wildcard bindings/espidf/*.c)
267+
SRC_C += $(SRC_ESPIDF)
268+
endif
269+
266270
ifneq ($(CIRCUITPY_ESPNOW),0)
267271
SRC_ESPNOW := \
268272
$(wildcard common-hal/espnow/*.c) \

ports/espressif/bindings/espnow/Peers.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,13 @@
2828
#include "py/objlist.h"
2929
#include "py/runtime.h"
3030

31+
#include "bindings/espidf/__init__.h"
32+
3133
#include "bindings/espnow/Peer.h"
3234
#include "bindings/espnow/Peers.h"
3335

3436
#include "esp_now.h"
3537

36-
static void check_esp_err(esp_err_t status) {
37-
if (status != ESP_OK) {
38-
mp_raise_RuntimeError(translate("an error occured"));
39-
}
40-
}
41-
4238
//| class Peers:
4339
//| """A class that provides peer managment functions. Sequence[Peer]."""
4440
//|
@@ -51,7 +47,7 @@ static void check_esp_err(esp_err_t status) {
5147
//| ...
5248
STATIC mp_obj_t espnow_peers_append(mp_obj_t self_in, mp_obj_t arg) {
5349
espnow_peer_obj_t *peer = MP_OBJ_TO_PTR(mp_arg_validate_type(arg, &espnow_peer_type, MP_QSTR_Peer));
54-
check_esp_err(esp_now_add_peer(&peer->peer_info));
50+
CHECK_ESP_RESULT(esp_now_add_peer(&peer->peer_info));
5551
espnow_peers_obj_t *self = MP_OBJ_TO_PTR(self_in);
5652
return mp_obj_list_append(self->list, arg);
5753
}
@@ -66,7 +62,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_peers_append_obj, espnow_peers_append);
6662
//|
6763
STATIC mp_obj_t espnow_peers_remove(mp_obj_t self_in, mp_obj_t arg) {
6864
espnow_peer_obj_t *peer = MP_OBJ_TO_PTR(mp_arg_validate_type(arg, &espnow_peer_type, MP_QSTR_Peer));
69-
check_esp_err(esp_now_del_peer(peer->peer_info.peer_addr));
65+
CHECK_ESP_RESULT(esp_now_del_peer(peer->peer_info.peer_addr));
7066
espnow_peers_obj_t *self = MP_OBJ_TO_PTR(self_in);
7167
return mp_obj_list_remove(self->list, arg);
7268
}

ports/espressif/common-hal/espidf/__init__.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
#include "supervisor/memory.h"
3030
#include "py/runtime.h"
3131

32+
#include "esp_now.h"
3233
#include "esp_log.h"
34+
3335
#define TAG "espidf"
3436

3537
#ifdef CONFIG_SPIRAM
@@ -180,14 +182,19 @@ void raise_esp_error(esp_err_t err) {
180182

181183
// tests must be in descending order
182184
MP_STATIC_ASSERT(ESP_ERR_FLASH_BASE > ESP_ERR_MESH_BASE);
183-
MP_STATIC_ASSERT(ESP_ERR_MESH_BASE > ESP_ERR_WIFI_BASE);
185+
MP_STATIC_ASSERT(ESP_ERR_MESH_BASE > ESP_ERR_ESPNOW_BASE);
186+
MP_STATIC_ASSERT(ESP_ERR_ESPNOW_BASE > ESP_ERR_WIFI_BASE);
187+
184188
if (err >= ESP_ERR_FLASH_BASE) {
185189
group = "Flash";
186190
} else if (err >= ESP_ERR_MESH_BASE) {
187191
group = "Mesh";
192+
} else if (err >= ESP_ERR_ESPNOW_BASE) {
193+
group = "ESP-NOW";
188194
} else if (err >= ESP_ERR_WIFI_BASE) {
189195
group = "WiFi";
190196
}
197+
191198
mp_raise_msg_varg(exception_type, translate("%s error 0x%x"), group, err);
192199
}
193200

ports/espressif/common-hal/espnow/ESPNow.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
#include "py/mperrno.h"
3131
#include "py/runtime.h"
3232

33+
#include "bindings/espidf/__init__.h"
3334
#include "bindings/espnow/ESPNowPacket.h"
35+
3436
#include "shared-bindings/wifi/__init__.h"
3537

3638
#include "common-hal/espnow/ESPNow.h"
@@ -41,6 +43,8 @@
4143

4244
#define ESPNOW_MAGIC 0x99
4345

46+
// TODO: deinit wifi?
47+
4448
// The maximum length of an espnow packet (bytes)
4549
#define MAX_PACKET_LEN (sizeof(espnow_packet_t) + ESP_NOW_MAX_DATA_LEN)
4650

@@ -66,12 +70,6 @@ typedef struct {
6670
uint8_t msg[0]; // Message is up to 250 bytes
6771
} __attribute__((packed)) espnow_packet_t;
6872

69-
static void check_esp_err(esp_err_t status) {
70-
if (status != ESP_OK) {
71-
mp_raise_RuntimeError(translate("an error occured"));
72-
}
73-
}
74-
7573
// Return a pointer to the ESPNow module singleton
7674
static espnow_obj_t *_get_singleton(void) {
7775
return MP_STATE_PORT(espnow_singleton);
@@ -152,12 +150,12 @@ void common_hal_espnow_init(espnow_obj_t *self) {
152150
common_hal_wifi_radio_set_enabled(&common_hal_wifi_radio_obj, true);
153151
}
154152

155-
check_esp_err(esp_wifi_config_espnow_rate(ESP_IF_WIFI_STA, self->phy_rate));
156-
check_esp_err(esp_wifi_config_espnow_rate(ESP_IF_WIFI_AP, self->phy_rate));
153+
CHECK_ESP_RESULT(esp_wifi_config_espnow_rate(ESP_IF_WIFI_STA, self->phy_rate));
154+
CHECK_ESP_RESULT(esp_wifi_config_espnow_rate(ESP_IF_WIFI_AP, self->phy_rate));
157155

158-
check_esp_err(esp_now_init());
159-
check_esp_err(esp_now_register_send_cb(send_cb));
160-
check_esp_err(esp_now_register_recv_cb(recv_cb));
156+
CHECK_ESP_RESULT(esp_now_init());
157+
CHECK_ESP_RESULT(esp_now_register_send_cb(send_cb));
158+
CHECK_ESP_RESULT(esp_now_register_recv_cb(recv_cb));
161159
}
162160

163161
// De-initialize the ESP-NOW software stack,
@@ -167,9 +165,9 @@ void common_hal_espnow_deinit(espnow_obj_t *self) {
167165
return;
168166
}
169167

170-
check_esp_err(esp_now_unregister_send_cb());
171-
check_esp_err(esp_now_unregister_recv_cb());
172-
check_esp_err(esp_now_deinit());
168+
CHECK_ESP_RESULT(esp_now_unregister_send_cb());
169+
CHECK_ESP_RESULT(esp_now_unregister_recv_cb());
170+
CHECK_ESP_RESULT(esp_now_deinit());
173171

174172
self->recv_buffer->buf = NULL;
175173
self->recv_buffer = NULL;
@@ -191,7 +189,7 @@ void common_hal_espnow_set_phy_rate(espnow_obj_t *self, mp_int_t value) {
191189
};
192190

193191
void common_hal_espnow_set_pmk(espnow_obj_t *self, const uint8_t *key) {
194-
check_esp_err(esp_now_set_pmk(key));
192+
CHECK_ESP_RESULT(esp_now_set_pmk(key));
195193
}
196194

197195
// --- 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
206204
(mp_hal_ticks_ms() - start) <= DEFAULT_SEND_TIMEOUT_MS) {
207205
RUN_BACKGROUND_TASKS;
208206
}
209-
check_esp_err(err);
207+
CHECK_ESP_RESULT(err);
210208

211209
// Increment the sent packet count.
212210
// If mac == NULL msg will be sent to all peers EXCEPT any broadcast or multicast addresses.

ports/espressif/esp_error.c

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)