Skip to content

Commit 9f835df

Browse files
glenn20dpgeorge
authored andcommitted
esp32,esp8266: Rename MICROPY_ESPNOW to MICROPY_PY_ESPNOW.
For consistency with other Python-level modules. Also add the corresponding missing preprocessor guard to esp32/modespnow.c, so that this port compiles if MICROPY_PY_ESPNOW and MICROPY_PY_NETWORK_WLAN are set to 0. Fixes micropython#12622. Signed-off-by: Glenn Moloney <[email protected]>
1 parent a06f4c8 commit 9f835df

File tree

7 files changed

+43
-38
lines changed

7 files changed

+43
-38
lines changed

ports/esp32/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#include "extmod/modbluetooth.h"
6161
#endif
6262

63-
#if MICROPY_ESPNOW
63+
#if MICROPY_PY_ESPNOW
6464
#include "modespnow.h"
6565
#endif
6666

@@ -152,7 +152,7 @@ void mp_task(void *pvParameter) {
152152
mp_bluetooth_deinit();
153153
#endif
154154

155-
#if MICROPY_ESPNOW
155+
#if MICROPY_PY_ESPNOW
156156
espnow_deinit(mp_const_none);
157157
MP_STATE_PORT(espnow_singleton) = NULL;
158158
#endif

ports/esp32/modespnow.c

+30-25
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,20 @@
4747
#include "py/ringbuf.h"
4848

4949
#include "mpconfigport.h"
50+
51+
#if MICROPY_PY_ESPNOW
52+
5053
#include "mphalport.h"
5154
#include "modnetwork.h"
5255
#include "modespnow.h"
5356

54-
#ifndef MICROPY_ESPNOW_RSSI
57+
#ifndef MICROPY_PY_ESPNOW_RSSI
5558
// Include code to track rssi of peers
56-
#define MICROPY_ESPNOW_RSSI 1
59+
#define MICROPY_PY_ESPNOW_RSSI 1
5760
#endif
58-
#ifndef MICROPY_ESPNOW_EXTRA_PEER_METHODS
61+
#ifndef MICROPY_PY_ESPNOW_EXTRA_PEER_METHODS
5962
// Include mod_peer(),get_peer(),peer_count()
60-
#define MICROPY_ESPNOW_EXTRA_PEER_METHODS 1
63+
#define MICROPY_PY_ESPNOW_EXTRA_PEER_METHODS 1
6164
#endif
6265

6366
// Relies on gcc Variadic Macros and Statement Expressions
@@ -71,10 +74,10 @@ static const uint8_t ESPNOW_MAGIC = 0x99;
7174
typedef struct {
7275
uint8_t magic; // = ESPNOW_MAGIC
7376
uint8_t msg_len; // Length of the message
74-
#if MICROPY_ESPNOW_RSSI
77+
#if MICROPY_PY_ESPNOW_RSSI
7578
uint32_t time_ms; // Timestamp (ms) when packet is received
7679
int8_t rssi; // RSSI value (dBm) (-127 to 0)
77-
#endif // MICROPY_ESPNOW_RSSI
80+
#endif // MICROPY_PY_ESPNOW_RSSI
7881
} __attribute__((packed)) espnow_hdr_t;
7982

8083
typedef struct {
@@ -117,9 +120,9 @@ typedef struct _esp_espnow_obj_t {
117120
size_t peer_count; // Cache the # of peers for send(sync=True)
118121
mp_obj_t recv_cb; // Callback when a packet is received
119122
mp_obj_t recv_cb_arg; // Argument passed to callback
120-
#if MICROPY_ESPNOW_RSSI
123+
#if MICROPY_PY_ESPNOW_RSSI
121124
mp_obj_t peers_table; // A dictionary of discovered peers
122-
#endif // MICROPY_ESPNOW_RSSI
125+
#endif // MICROPY_PY_ESPNOW_RSSI
123126
} esp_espnow_obj_t;
124127

125128
const mp_obj_type_t esp_espnow_type;
@@ -164,11 +167,11 @@ STATIC mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args,
164167
self->recv_timeout_ms = DEFAULT_RECV_TIMEOUT_MS;
165168
self->recv_buffer = NULL; // Buffer is allocated in espnow_init()
166169
self->recv_cb = mp_const_none;
167-
#if MICROPY_ESPNOW_RSSI
170+
#if MICROPY_PY_ESPNOW_RSSI
168171
self->peers_table = mp_obj_new_dict(0);
169172
// Prevent user code modifying the dict
170173
mp_obj_dict_get_map(self->peers_table)->is_fixed = 1;
171-
#endif // MICROPY_ESPNOW_RSSI
174+
#endif // MICROPY_PY_ESPNOW_RSSI
172175

173176
// Set the global singleton pointer for the espnow protocol.
174177
MP_STATE_PORT(espnow_singleton) = self;
@@ -305,7 +308,7 @@ STATIC mp_obj_t espnow_stats(mp_obj_t _) {
305308
}
306309
STATIC MP_DEFINE_CONST_FUN_OBJ_1(espnow_stats_obj, espnow_stats);
307310

308-
#if MICROPY_ESPNOW_RSSI
311+
#if MICROPY_PY_ESPNOW_RSSI
309312
// ### Maintaining the peer table and reading RSSI values
310313
//
311314
// We maintain a peers table for several reasons, to:
@@ -345,7 +348,7 @@ static mp_map_elem_t *_update_rssi(const uint8_t *peer, int8_t rssi, uint32_t ti
345348
list->items[1] = mp_obj_new_int(time_ms);
346349
return item;
347350
}
348-
#endif // MICROPY_ESPNOW_RSSI
351+
#endif // MICROPY_PY_ESPNOW_RSSI
349352

350353
// Return C pointer to byte memory string/bytes/bytearray in obj.
351354
// Raise ValueError if the length does not match expected len.
@@ -413,11 +416,11 @@ STATIC mp_obj_t espnow_recvinto(size_t n_args, const mp_obj_t *args) {
413416
msg->len += msg->free; // Make all the space in msg array available
414417
msg->free = 0;
415418
}
416-
#if MICROPY_ESPNOW_RSSI
419+
#if MICROPY_PY_ESPNOW_RSSI
417420
uint8_t peer_buf[ESP_NOW_ETH_ALEN];
418421
#else
419422
uint8_t *peer_buf = _get_bytes_len_w(list->items[0], ESP_NOW_ETH_ALEN);
420-
#endif // MICROPY_ESPNOW_RSSI
423+
#endif // MICROPY_PY_ESPNOW_RSSI
421424
uint8_t *msg_buf = _get_bytes_len_w(msg, ESP_NOW_MAX_DATA_LEN);
422425

423426
// Read the packet header from the incoming buffer
@@ -441,15 +444,15 @@ STATIC mp_obj_t espnow_recvinto(size_t n_args, const mp_obj_t *args) {
441444
msg->free = size - msg_len;
442445
}
443446

444-
#if MICROPY_ESPNOW_RSSI
447+
#if MICROPY_PY_ESPNOW_RSSI
445448
// Update rssi value in the peer device table
446449
mp_map_elem_t *entry = _update_rssi(peer_buf, hdr.rssi, hdr.time_ms);
447450
list->items[0] = entry->key; // Set first element of list to peer
448451
if (list->len >= 4) {
449452
list->items[2] = MP_OBJ_NEW_SMALL_INT(hdr.rssi);
450453
list->items[3] = mp_obj_new_int(hdr.time_ms);
451454
}
452-
#endif // MICROPY_ESPNOW_RSSI
455+
#endif // MICROPY_PY_ESPNOW_RSSI
453456

454457
return MP_OBJ_NEW_SMALL_INT(msg_len);
455458
}
@@ -561,10 +564,10 @@ STATIC void recv_cb(const esp_now_recv_info_t *recv_info, const uint8_t *msg, in
561564
espnow_hdr_t header;
562565
header.magic = ESPNOW_MAGIC;
563566
header.msg_len = msg_len;
564-
#if MICROPY_ESPNOW_RSSI
567+
#if MICROPY_PY_ESPNOW_RSSI
565568
header.rssi = recv_info->rx_ctrl->rssi;
566569
header.time_ms = mp_hal_ticks_ms();
567-
#endif // MICROPY_ESPNOW_RSSI
570+
#endif // MICROPY_PY_ESPNOW_RSSI
568571

569572
ringbuf_put_bytes(buf, (uint8_t *)&header, sizeof(header));
570573
ringbuf_put_bytes(buf, recv_info->src_addr, ESP_NOW_ETH_ALEN);
@@ -710,7 +713,7 @@ STATIC mp_obj_t espnow_get_peers(mp_obj_t _) {
710713
}
711714
STATIC MP_DEFINE_CONST_FUN_OBJ_1(espnow_get_peers_obj, espnow_get_peers);
712715

713-
#if MICROPY_ESPNOW_EXTRA_PEER_METHODS
716+
#if MICROPY_PY_ESPNOW_EXTRA_PEER_METHODS
714717
// ESPNow.get_peer(peer_mac): Get the peer info for peer_mac as a tuple.
715718
// Raise OSError if ESPNow.init() has not been called.
716719
// Raise ValueError if mac or LMK are not bytes-like objects or wrong length.
@@ -777,11 +780,11 @@ STATIC const mp_rom_map_elem_t esp_espnow_locals_dict_table[] = {
777780
{ MP_ROM_QSTR(MP_QSTR_add_peer), MP_ROM_PTR(&espnow_add_peer_obj) },
778781
{ MP_ROM_QSTR(MP_QSTR_del_peer), MP_ROM_PTR(&espnow_del_peer_obj) },
779782
{ MP_ROM_QSTR(MP_QSTR_get_peers), MP_ROM_PTR(&espnow_get_peers_obj) },
780-
#if MICROPY_ESPNOW_EXTRA_PEER_METHODS
783+
#if MICROPY_PY_ESPNOW_EXTRA_PEER_METHODS
781784
{ MP_ROM_QSTR(MP_QSTR_mod_peer), MP_ROM_PTR(&espnow_mod_peer_obj) },
782785
{ MP_ROM_QSTR(MP_QSTR_get_peer), MP_ROM_PTR(&espnow_get_peer_obj) },
783786
{ MP_ROM_QSTR(MP_QSTR_peer_count), MP_ROM_PTR(&espnow_peer_count_obj) },
784-
#endif // MICROPY_ESPNOW_EXTRA_PEER_METHODS
787+
#endif // MICROPY_PY_ESPNOW_EXTRA_PEER_METHODS
785788
};
786789
STATIC MP_DEFINE_CONST_DICT(esp_espnow_locals_dict, esp_espnow_locals_dict_table);
787790

@@ -819,7 +822,7 @@ STATIC const mp_stream_p_t espnow_stream_p = {
819822
.ioctl = espnow_stream_ioctl,
820823
};
821824

822-
#if MICROPY_ESPNOW_RSSI
825+
#if MICROPY_PY_ESPNOW_RSSI
823826
// Return reference to the dictionary of peers we have seen:
824827
// {peer1: (rssi, time_sec), peer2: (rssi, time_msec), ...}
825828
// where:
@@ -838,16 +841,16 @@ STATIC void espnow_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
838841
}
839842
dest[1] = MP_OBJ_SENTINEL; // Attribute not found
840843
}
841-
#endif // MICROPY_ESPNOW_RSSI
844+
#endif // MICROPY_PY_ESPNOW_RSSI
842845

843846
MP_DEFINE_CONST_OBJ_TYPE(
844847
esp_espnow_type,
845848
MP_QSTR_ESPNowBase,
846849
MP_TYPE_FLAG_NONE,
847850
make_new, espnow_make_new,
848-
#if MICROPY_ESPNOW_RSSI
851+
#if MICROPY_PY_ESPNOW_RSSI
849852
attr, espnow_attr,
850-
#endif // MICROPY_ESPNOW_RSSI
853+
#endif // MICROPY_PY_ESPNOW_RSSI
851854
protocol, &espnow_stream_p,
852855
locals_dict, &esp_espnow_locals_dict
853856
);
@@ -859,3 +862,5 @@ const mp_obj_module_t mp_module_espnow = {
859862

860863
MP_REGISTER_MODULE(MP_QSTR__espnow, mp_module_espnow);
861864
MP_REGISTER_ROOT_POINTER(struct _esp_espnow_obj_t *espnow_singleton);
865+
866+
#endif // MICROPY_PY_ESPNOW

ports/esp32/mpconfigport.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
#define MICROPY_GC_SPLIT_HEAP_AUTO (1)
7373

7474
// extended modules
75-
#ifndef MICROPY_ESPNOW
76-
#define MICROPY_ESPNOW (1)
75+
#ifndef MICROPY_PY_ESPNOW
76+
#define MICROPY_PY_ESPNOW (1)
7777
#endif
7878
#ifndef MICROPY_PY_BLUETOOTH
7979
#define MICROPY_PY_BLUETOOTH (1)

ports/esp8266/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ LD_FILES ?= boards/esp8266_2m.ld
7878
LDFLAGS += -nostdlib -T $(LD_FILES) -Map=$(@:.elf=.map) --cref
7979
LIBS += -L$(ESP_SDK)/lib -lmain -ljson -llwip_open -lpp -lnet80211 -lwpa -lphy -lnet80211
8080

81-
ifeq ($(MICROPY_ESPNOW),1)
82-
CFLAGS += -DMICROPY_ESPNOW=1
81+
ifeq ($(MICROPY_PY_ESPNOW),1)
82+
CFLAGS += -DMICROPY_PY_ESPNOW=1
8383
LIBS += -lespnow
8484
endif
8585

@@ -126,7 +126,7 @@ SRC_C = \
126126
hspi.c \
127127
$(wildcard $(BOARD_DIR)/*.c) \
128128

129-
ifeq ($(MICROPY_ESPNOW),1)
129+
ifeq ($(MICROPY_PY_ESPNOW),1)
130130
SRC_C += \
131131
modespnow.c
132132
endif

ports/esp8266/boards/ESP8266_GENERIC/mpconfigboard.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ifeq ($(BOARD_VARIANT),)
22
LD_FILES = boards/esp8266_2MiB.ld
33

4-
MICROPY_ESPNOW ?= 1
4+
MICROPY_PY_ESPNOW ?= 1
55
MICROPY_PY_BTREE ?= 1
66
MICROPY_VFS_FAT ?= 1
77
MICROPY_VFS_LFS2 ?= 1
@@ -16,7 +16,7 @@ endif
1616
ifeq ($(BOARD_VARIANT),FLASH_1M)
1717
LD_FILES = boards/esp8266_1MiB.ld
1818

19-
MICROPY_ESPNOW ?= 1
19+
MICROPY_PY_ESPNOW ?= 1
2020
MICROPY_PY_BTREE ?= 1
2121
MICROPY_VFS_LFS2 ?= 1
2222

@@ -29,7 +29,7 @@ endif
2929
ifeq ($(BOARD_VARIANT),OTA)
3030
LD_FILES = boards/esp8266_ota.ld
3131

32-
MICROPY_ESPNOW ?= 1
32+
MICROPY_PY_ESPNOW ?= 1
3333
MICROPY_PY_BTREE ?= 1
3434
MICROPY_VFS_LFS2 ?= 1
3535

ports/esp8266/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#include "gccollect.h"
4646
#include "user_interface.h"
4747

48-
#if MICROPY_ESPNOW
48+
#if MICROPY_PY_ESPNOW
4949
#include "modespnow.h"
5050
#endif
5151

@@ -77,7 +77,7 @@ STATIC void mp_reset(void) {
7777
mp_os_dupterm_obj.fun.var(2, args);
7878
}
7979

80-
#if MICROPY_ESPNOW
80+
#if MICROPY_PY_ESPNOW
8181
espnow_deinit(mp_const_none);
8282
#endif
8383

ports/esp8266/modespnow.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#include "py/runtime.h"
3535

36-
#if MICROPY_ESPNOW
36+
#if MICROPY_PY_ESPNOW
3737

3838
#include "c_types.h"
3939
#include "espnow.h"

0 commit comments

Comments
 (0)