Skip to content

Commit e59d8f2

Browse files
committed
extmod/modnetwork: Consolidate definition of common drivers.
Most extmod network drivers were being defined on a per-port basis, duplicating code and making enabling a driver on a new port harder. This consolidates extmod driver declarations and removes the existing per-port definitions of them. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent af8b06b commit e59d8f2

File tree

6 files changed

+50
-99
lines changed

6 files changed

+50
-99
lines changed

extmod/modnetwork.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@
4040
#if MICROPY_PY_NETWORK_CYW43
4141
// So that CYW43_LINK_xxx constants are available to MICROPY_PORT_NETWORK_INTERFACES.
4242
#include "lib/cyw43-driver/src/cyw43.h"
43+
extern const struct _mp_obj_type_t mp_network_cyw43_type;
44+
#endif
45+
46+
#if MICROPY_PY_NETWORK_WIZNET5K
47+
extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k;
48+
#endif
49+
50+
#if MICROPY_PY_NETWORK_NINAW10
51+
// This Network interface requires the extended socket state.
52+
#ifndef MICROPY_PY_SOCKET_EXTENDED_STATE
53+
#define MICROPY_PY_SOCKET_EXTENDED_STATE (1)
54+
#endif
55+
extern const struct _mp_obj_type_t mod_network_nic_type_nina;
56+
#endif
57+
58+
#if MICROPY_HW_NETWORK_USBNET
59+
extern const struct _mp_obj_type_t mod_network_nic_type_usbnet;
60+
#endif
61+
62+
#if MICROPY_PY_NETWORK_ESP_HOSTED
63+
extern const struct _mp_obj_type_t mod_network_esp_hosted_type;
4364
#endif
4465

4566
#ifdef MICROPY_PY_NETWORK_INCLUDEFILE
@@ -160,6 +181,35 @@ static const mp_rom_map_elem_t mp_module_network_globals_table[] = {
160181
{ MP_ROM_QSTR(MP_QSTR_PPP), MP_ROM_PTR(&mp_network_ppp_lwip_type) },
161182
#endif
162183

184+
#if MICROPY_PY_NETWORK_CYW43
185+
{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mp_network_cyw43_type) },
186+
// CYW43 status constants (used by rp2 port)
187+
#if defined(CYW43_LINK_DOWN)
188+
{ MP_ROM_QSTR(MP_QSTR_STAT_IDLE), MP_ROM_INT(CYW43_LINK_DOWN) },
189+
{ MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING), MP_ROM_INT(CYW43_LINK_JOIN) },
190+
{ MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(CYW43_LINK_BADAUTH) },
191+
{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND), MP_ROM_INT(CYW43_LINK_NONET) },
192+
{ MP_ROM_QSTR(MP_QSTR_STAT_CONNECT_FAIL), MP_ROM_INT(CYW43_LINK_FAIL) },
193+
{ MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(CYW43_LINK_UP) },
194+
#endif
195+
#endif
196+
197+
#if MICROPY_PY_NETWORK_WIZNET5K
198+
{ MP_ROM_QSTR(MP_QSTR_WIZNET5K), MP_ROM_PTR(&mod_network_nic_type_wiznet5k) },
199+
#endif
200+
201+
#if MICROPY_PY_NETWORK_NINAW10
202+
{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_nic_type_nina) },
203+
#endif
204+
205+
#if MICROPY_HW_NETWORK_USBNET
206+
{ MP_ROM_QSTR(MP_QSTR_USB_NET), MP_ROM_PTR(&mod_network_nic_type_usbnet) },
207+
#endif
208+
209+
#if MICROPY_PY_NETWORK_ESP_HOSTED
210+
{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_esp_hosted_type) },
211+
#endif
212+
163213
// Defined per port in mpconfigport.h
164214
#ifdef MICROPY_PORT_NETWORK_INTERFACES
165215
{ MP_ROM_QSTR(MP_QSTR_route), MP_ROM_PTR(&network_route_obj) },

ports/alif/mpconfigport.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,11 @@
158158
#define MICROPY_FATFS_MAX_SS (MICROPY_HW_FLASH_BLOCK_SIZE_BYTES)
159159
#endif
160160

161-
#if MICROPY_PY_NETWORK_CYW43
162-
extern const struct _mp_obj_type_t mp_network_cyw43_type;
163-
#define MICROPY_HW_NIC_CYW43 { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mp_network_cyw43_type) },
164-
#else
165-
#define MICROPY_HW_NIC_CYW43
166-
#endif
167-
168161
#ifndef MICROPY_BOARD_NETWORK_INTERFACES
169162
#define MICROPY_BOARD_NETWORK_INTERFACES
170163
#endif
171164

172165
#define MICROPY_PORT_NETWORK_INTERFACES \
173-
MICROPY_HW_NIC_CYW43 \
174166
MICROPY_BOARD_NETWORK_INTERFACES \
175167

176168
// Bluetooth code only runs in the scheduler, no locking/mutex required.

ports/mimxrt/mpconfigport.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,28 +178,12 @@ extern const struct _mp_obj_type_t network_lan_type;
178178
#define MICROPY_HW_NIC_ETH
179179
#endif
180180

181-
#if MICROPY_PY_NETWORK_CYW43
182-
extern const struct _mp_obj_type_t mp_network_cyw43_type;
183-
#define MICROPY_HW_NIC_CYW43 { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mp_network_cyw43_type) },
184-
#else
185-
#define MICROPY_HW_NIC_CYW43
186-
#endif
187-
188-
#if MICROPY_HW_NETWORK_USBNET
189-
extern const struct _mp_obj_type_t mod_network_nic_type_usbnet;
190-
#define MICROPY_HW_NIC_USBNET { MP_ROM_QSTR(MP_QSTR_USB_NET), MP_ROM_PTR(&mod_network_nic_type_usbnet) },
191-
#else
192-
#define MICROPY_HW_NIC_USBNET
193-
#endif
194-
195181
#ifndef MICROPY_BOARD_NETWORK_INTERFACES
196182
#define MICROPY_BOARD_NETWORK_INTERFACES
197183
#endif
198184

199185
#define MICROPY_PORT_NETWORK_INTERFACES \
200186
MICROPY_HW_NIC_ETH \
201-
MICROPY_HW_NIC_CYW43 \
202-
MICROPY_HW_NIC_USBNET \
203187
MICROPY_BOARD_NETWORK_INTERFACES \
204188

205189
#ifndef MICROPY_BOARD_ROOT_POINTERS

ports/renesas-ra/mpconfigport.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,11 @@
210210

211211
#define MP_STATE_PORT MP_STATE_VM
212212

213-
#if MICROPY_PY_NETWORK_ESP_HOSTED
214-
extern const struct _mp_obj_type_t mod_network_esp_hosted_type;
215-
#define MICROPY_HW_NIC_ESP_HOSTED { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_esp_hosted_type) },
216-
#else
217-
#define MICROPY_HW_NIC_ESP_HOSTED
218-
#endif
219-
220213
#ifndef MICROPY_BOARD_NETWORK_INTERFACES
221214
#define MICROPY_BOARD_NETWORK_INTERFACES
222215
#endif
223216

224217
#define MICROPY_PORT_NETWORK_INTERFACES \
225-
MICROPY_HW_NIC_ESP_HOSTED \
226218
MICROPY_BOARD_NETWORK_INTERFACES \
227219

228220
// Miscellaneous settings

ports/rp2/mpconfigport.h

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -242,54 +242,11 @@
242242
#endif
243243
#endif
244244

245-
#if MICROPY_PY_NETWORK_CYW43
246-
extern const struct _mp_obj_type_t mp_network_cyw43_type;
247-
#define MICROPY_HW_NIC_CYW43 \
248-
{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mp_network_cyw43_type) }, \
249-
{ MP_ROM_QSTR(MP_QSTR_STAT_IDLE), MP_ROM_INT(CYW43_LINK_DOWN) }, \
250-
{ MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING), MP_ROM_INT(CYW43_LINK_JOIN) }, \
251-
{ MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(CYW43_LINK_BADAUTH) }, \
252-
{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND), MP_ROM_INT(CYW43_LINK_NONET) }, \
253-
{ MP_ROM_QSTR(MP_QSTR_STAT_CONNECT_FAIL), MP_ROM_INT(CYW43_LINK_FAIL) }, \
254-
{ MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(CYW43_LINK_UP) },
255-
#else
256-
#define MICROPY_HW_NIC_CYW43
257-
#endif
258-
259-
#if MICROPY_PY_NETWORK_NINAW10
260-
// This Network interface requires the extended socket state.
261-
#ifndef MICROPY_PY_SOCKET_EXTENDED_STATE
262-
#define MICROPY_PY_SOCKET_EXTENDED_STATE (1)
263-
#endif
264-
extern const struct _mp_obj_type_t mod_network_nic_type_nina;
265-
#define MICROPY_HW_NIC_NINAW10 { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_nic_type_nina) },
266-
#else
267-
#define MICROPY_HW_NIC_NINAW10
268-
#endif
269-
270-
#if MICROPY_PY_NETWORK_WIZNET5K
271-
extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k;
272-
#define MICROPY_HW_NIC_WIZNET5K { MP_ROM_QSTR(MP_QSTR_WIZNET5K), MP_ROM_PTR(&mod_network_nic_type_wiznet5k) },
273-
#else
274-
#define MICROPY_HW_NIC_WIZNET5K
275-
#endif
276-
277-
#if MICROPY_HW_NETWORK_USBNET
278-
extern const struct _mp_obj_type_t mod_network_nic_type_usbnet;
279-
#define MICROPY_HW_NIC_USBNET { MP_ROM_QSTR(MP_QSTR_USB_NET), MP_ROM_PTR(&mod_network_nic_type_usbnet) },
280-
#else
281-
#define MICROPY_HW_NIC_USBNET
282-
#endif
283-
284245
#ifndef MICROPY_BOARD_NETWORK_INTERFACES
285246
#define MICROPY_BOARD_NETWORK_INTERFACES
286247
#endif
287248

288249
#define MICROPY_PORT_NETWORK_INTERFACES \
289-
MICROPY_HW_NIC_CYW43 \
290-
MICROPY_HW_NIC_NINAW10 \
291-
MICROPY_HW_NIC_WIZNET5K \
292-
MICROPY_HW_NIC_USBNET \
293250
MICROPY_BOARD_NETWORK_INTERFACES \
294251

295252
// Additional entries for use with pendsv_schedule_dispatch.

ports/stm32/mpconfigport.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -205,27 +205,6 @@ extern const struct _mp_obj_type_t network_lan_type;
205205
#define MICROPY_HW_NIC_ETH
206206
#endif
207207

208-
#if MICROPY_PY_NETWORK_CYW43
209-
extern const struct _mp_obj_type_t mp_network_cyw43_type;
210-
#define MICROPY_HW_NIC_CYW43 { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mp_network_cyw43_type) },
211-
#else
212-
#define MICROPY_HW_NIC_CYW43
213-
#endif
214-
215-
#if MICROPY_PY_NETWORK_WIZNET5K
216-
extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k;
217-
#define MICROPY_HW_NIC_WIZNET5K { MP_ROM_QSTR(MP_QSTR_WIZNET5K), MP_ROM_PTR(&mod_network_nic_type_wiznet5k) },
218-
#else
219-
#define MICROPY_HW_NIC_WIZNET5K
220-
#endif
221-
222-
#if MICROPY_HW_NETWORK_USBNET
223-
extern const struct _mp_obj_type_t mod_network_nic_type_usbnet;
224-
#define MICROPY_HW_NIC_USBNET { MP_ROM_QSTR(MP_QSTR_USB_NET), MP_ROM_PTR(&mod_network_nic_type_usbnet) },
225-
#else
226-
#define MICROPY_HW_NIC_USBNET
227-
#endif
228-
229208
// extra constants
230209
#define MICROPY_PORT_CONSTANTS \
231210
MACHINE_BUILTIN_MODULE_CONSTANTS \
@@ -238,9 +217,6 @@ extern const struct _mp_obj_type_t mod_network_nic_type_usbnet;
238217

239218
#define MICROPY_PORT_NETWORK_INTERFACES \
240219
MICROPY_HW_NIC_ETH \
241-
MICROPY_HW_NIC_CYW43 \
242-
MICROPY_HW_NIC_WIZNET5K \
243-
MICROPY_HW_NIC_USBNET \
244220
MICROPY_BOARD_NETWORK_INTERFACES \
245221

246222
#define MP_STATE_PORT MP_STATE_VM

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy