Skip to content

Commit fffaf8a

Browse files
pi-anldpgeorge
authored andcommitted
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. This commit has been verified to be a no-op in terms of firmware change. Signed-off-by: Andrew Leech <[email protected]>
1 parent 95203ab commit fffaf8a

File tree

9 files changed

+48
-75
lines changed

9 files changed

+48
-75
lines changed

extmod/modnetwork.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@
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+
extern const struct _mp_obj_type_t mod_network_nic_type_nina;
52+
#endif
53+
54+
#if MICROPY_PY_NETWORK_ESP_HOSTED
55+
extern const struct _mp_obj_type_t mod_network_esp_hosted_type;
4356
#endif
4457

4558
#ifdef MICROPY_PY_NETWORK_INCLUDEFILE
@@ -166,6 +179,32 @@ static const mp_rom_map_elem_t mp_module_network_globals_table[] = {
166179
MICROPY_PORT_NETWORK_INTERFACES
167180
#endif
168181

182+
#if MICROPY_PY_NETWORK_CYW43
183+
{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mp_network_cyw43_type) },
184+
// CYW43 status constants, currently for rp2 port only.
185+
// TODO move these to WIFI module for all ports.
186+
#if defined(PICO_PROGRAM_NAME) && defined(CYW43_LINK_DOWN)
187+
{ MP_ROM_QSTR(MP_QSTR_STAT_IDLE), MP_ROM_INT(CYW43_LINK_DOWN) },
188+
{ MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING), MP_ROM_INT(CYW43_LINK_JOIN) },
189+
{ MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(CYW43_LINK_BADAUTH) },
190+
{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND), MP_ROM_INT(CYW43_LINK_NONET) },
191+
{ MP_ROM_QSTR(MP_QSTR_STAT_CONNECT_FAIL), MP_ROM_INT(CYW43_LINK_FAIL) },
192+
{ MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(CYW43_LINK_UP) },
193+
#endif
194+
#endif
195+
196+
#if MICROPY_PY_NETWORK_WIZNET5K
197+
{ MP_ROM_QSTR(MP_QSTR_WIZNET5K), MP_ROM_PTR(&mod_network_nic_type_wiznet5k) },
198+
#endif
199+
200+
#if MICROPY_PY_NETWORK_NINAW10
201+
{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_nic_type_nina) },
202+
#endif
203+
204+
#if MICROPY_PY_NETWORK_ESP_HOSTED
205+
{ MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_esp_hosted_type) },
206+
#endif
207+
169208
// Allow a port to take mostly full control of the network module.
170209
#ifdef MICROPY_PY_NETWORK_MODULE_GLOBALS_INCLUDEFILE
171210
#include MICROPY_PY_NETWORK_MODULE_GLOBALS_INCLUDEFILE

extmod/modnetwork.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ extern char mod_network_country_code[2];
6060
#define MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN (32)
6161
#endif
6262

63+
#if MICROPY_PY_NETWORK_NINAW10
64+
// This Network interface requires the extended socket state.
65+
#define MICROPY_PY_SOCKET_EXTENDED_STATE (1)
66+
#endif
67+
6368
// This is a null-terminated string.
6469
extern char mod_network_hostname_data[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN + 1];
6570

extmod/network_esp_hosted.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#include "esp_hosted_wifi.h"
4949
#include "esp_hosted_hal.h"
5050

51+
extern const mp_obj_type_t mod_network_esp_hosted_type;
52+
5153
typedef struct _esp_hosted_obj_t {
5254
mp_obj_base_t base;
5355
uint32_t itf;

extmod/network_wiznet5k.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878

7979
#endif
8080

81+
extern const mp_obj_type_t mod_network_nic_type_wiznet5k;
82+
8183
#ifndef printf
8284
#define printf(...) mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__)
8385
#endif

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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +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-
188181
#ifndef MICROPY_BOARD_NETWORK_INTERFACES
189182
#define MICROPY_BOARD_NETWORK_INTERFACES
190183
#endif
191184

192185
#define MICROPY_PORT_NETWORK_INTERFACES \
193186
MICROPY_HW_NIC_ETH \
194-
MICROPY_HW_NIC_CYW43 \
195187
MICROPY_BOARD_NETWORK_INTERFACES \
196188

197189
#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 & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -242,46 +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-
277245
#ifndef MICROPY_BOARD_NETWORK_INTERFACES
278246
#define MICROPY_BOARD_NETWORK_INTERFACES
279247
#endif
280248

281249
#define MICROPY_PORT_NETWORK_INTERFACES \
282-
MICROPY_HW_NIC_CYW43 \
283-
MICROPY_HW_NIC_NINAW10 \
284-
MICROPY_HW_NIC_WIZNET5K \
285250
MICROPY_BOARD_NETWORK_INTERFACES \
286251

287252
// Additional entries for use with pendsv_schedule_dispatch.

ports/stm32/mpconfigport.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +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-
222208
// extra constants
223209
#define MICROPY_PORT_CONSTANTS \
224210
MACHINE_BUILTIN_MODULE_CONSTANTS \
@@ -231,8 +217,6 @@ extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k;
231217

232218
#define MICROPY_PORT_NETWORK_INTERFACES \
233219
MICROPY_HW_NIC_ETH \
234-
MICROPY_HW_NIC_CYW43 \
235-
MICROPY_HW_NIC_WIZNET5K \
236220
MICROPY_BOARD_NETWORK_INTERFACES \
237221

238222
#define MP_STATE_PORT MP_STATE_VM

0 commit comments

Comments
 (0)