diff options
| author | Andrew Leech <andrew.leech@planetinnovation.com.au> | 2025-06-04 12:13:46 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-06-10 11:20:38 +1000 |
| commit | fffaf8a41f094868590aab0506bba03f126a3f5d (patch) | |
| tree | 4d3b0ba530a60992ef6175043a3fddc4333f8287 | |
| parent | 95203ab88b50f5083c28afe6a39aae605b4df2da (diff) | |
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 <andrew.leech@planetinnovation.com.au>
| -rw-r--r-- | extmod/modnetwork.c | 39 | ||||
| -rw-r--r-- | extmod/modnetwork.h | 5 | ||||
| -rw-r--r-- | extmod/network_esp_hosted.c | 2 | ||||
| -rw-r--r-- | extmod/network_wiznet5k.c | 2 | ||||
| -rw-r--r-- | ports/alif/mpconfigport.h | 8 | ||||
| -rw-r--r-- | ports/mimxrt/mpconfigport.h | 8 | ||||
| -rw-r--r-- | ports/renesas-ra/mpconfigport.h | 8 | ||||
| -rw-r--r-- | ports/rp2/mpconfigport.h | 35 | ||||
| -rw-r--r-- | ports/stm32/mpconfigport.h | 16 |
9 files changed, 48 insertions, 75 deletions
diff --git a/extmod/modnetwork.c b/extmod/modnetwork.c index 336836b6b..b6855fcaa 100644 --- a/extmod/modnetwork.c +++ b/extmod/modnetwork.c @@ -40,6 +40,19 @@ #if MICROPY_PY_NETWORK_CYW43 // So that CYW43_LINK_xxx constants are available to MICROPY_PORT_NETWORK_INTERFACES. #include "lib/cyw43-driver/src/cyw43.h" +extern const struct _mp_obj_type_t mp_network_cyw43_type; +#endif + +#if MICROPY_PY_NETWORK_WIZNET5K +extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k; +#endif + +#if MICROPY_PY_NETWORK_NINAW10 +extern const struct _mp_obj_type_t mod_network_nic_type_nina; +#endif + +#if MICROPY_PY_NETWORK_ESP_HOSTED +extern const struct _mp_obj_type_t mod_network_esp_hosted_type; #endif #ifdef MICROPY_PY_NETWORK_INCLUDEFILE @@ -166,6 +179,32 @@ static const mp_rom_map_elem_t mp_module_network_globals_table[] = { MICROPY_PORT_NETWORK_INTERFACES #endif + #if MICROPY_PY_NETWORK_CYW43 + { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mp_network_cyw43_type) }, + // CYW43 status constants, currently for rp2 port only. + // TODO move these to WIFI module for all ports. + #if defined(PICO_PROGRAM_NAME) && defined(CYW43_LINK_DOWN) + { MP_ROM_QSTR(MP_QSTR_STAT_IDLE), MP_ROM_INT(CYW43_LINK_DOWN) }, + { MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING), MP_ROM_INT(CYW43_LINK_JOIN) }, + { MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(CYW43_LINK_BADAUTH) }, + { MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND), MP_ROM_INT(CYW43_LINK_NONET) }, + { MP_ROM_QSTR(MP_QSTR_STAT_CONNECT_FAIL), MP_ROM_INT(CYW43_LINK_FAIL) }, + { MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(CYW43_LINK_UP) }, + #endif + #endif + + #if MICROPY_PY_NETWORK_WIZNET5K + { MP_ROM_QSTR(MP_QSTR_WIZNET5K), MP_ROM_PTR(&mod_network_nic_type_wiznet5k) }, + #endif + + #if MICROPY_PY_NETWORK_NINAW10 + { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_nic_type_nina) }, + #endif + + #if MICROPY_PY_NETWORK_ESP_HOSTED + { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_esp_hosted_type) }, + #endif + // Allow a port to take mostly full control of the network module. #ifdef MICROPY_PY_NETWORK_MODULE_GLOBALS_INCLUDEFILE #include MICROPY_PY_NETWORK_MODULE_GLOBALS_INCLUDEFILE diff --git a/extmod/modnetwork.h b/extmod/modnetwork.h index 7e5a28335..d16329f07 100644 --- a/extmod/modnetwork.h +++ b/extmod/modnetwork.h @@ -60,6 +60,11 @@ extern char mod_network_country_code[2]; #define MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN (32) #endif +#if MICROPY_PY_NETWORK_NINAW10 +// This Network interface requires the extended socket state. +#define MICROPY_PY_SOCKET_EXTENDED_STATE (1) +#endif + // This is a null-terminated string. extern char mod_network_hostname_data[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN + 1]; diff --git a/extmod/network_esp_hosted.c b/extmod/network_esp_hosted.c index 04cfc36b3..6ed348450 100644 --- a/extmod/network_esp_hosted.c +++ b/extmod/network_esp_hosted.c @@ -48,6 +48,8 @@ #include "esp_hosted_wifi.h" #include "esp_hosted_hal.h" +extern const mp_obj_type_t mod_network_esp_hosted_type; + typedef struct _esp_hosted_obj_t { mp_obj_base_t base; uint32_t itf; diff --git a/extmod/network_wiznet5k.c b/extmod/network_wiznet5k.c index 533d39a18..e065c1486 100644 --- a/extmod/network_wiznet5k.c +++ b/extmod/network_wiznet5k.c @@ -78,6 +78,8 @@ #endif +extern const mp_obj_type_t mod_network_nic_type_wiznet5k; + #ifndef printf #define printf(...) mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__) #endif diff --git a/ports/alif/mpconfigport.h b/ports/alif/mpconfigport.h index 6c9e6af63..ddfc551bf 100644 --- a/ports/alif/mpconfigport.h +++ b/ports/alif/mpconfigport.h @@ -158,19 +158,11 @@ #define MICROPY_FATFS_MAX_SS (MICROPY_HW_FLASH_BLOCK_SIZE_BYTES) #endif -#if MICROPY_PY_NETWORK_CYW43 -extern const struct _mp_obj_type_t mp_network_cyw43_type; -#define MICROPY_HW_NIC_CYW43 { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mp_network_cyw43_type) }, -#else -#define MICROPY_HW_NIC_CYW43 -#endif - #ifndef MICROPY_BOARD_NETWORK_INTERFACES #define MICROPY_BOARD_NETWORK_INTERFACES #endif #define MICROPY_PORT_NETWORK_INTERFACES \ - MICROPY_HW_NIC_CYW43 \ MICROPY_BOARD_NETWORK_INTERFACES \ // Bluetooth code only runs in the scheduler, no locking/mutex required. diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index 9a7dfc630..e1c605f45 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -178,20 +178,12 @@ extern const struct _mp_obj_type_t network_lan_type; #define MICROPY_HW_NIC_ETH #endif -#if MICROPY_PY_NETWORK_CYW43 -extern const struct _mp_obj_type_t mp_network_cyw43_type; -#define MICROPY_HW_NIC_CYW43 { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mp_network_cyw43_type) }, -#else -#define MICROPY_HW_NIC_CYW43 -#endif - #ifndef MICROPY_BOARD_NETWORK_INTERFACES #define MICROPY_BOARD_NETWORK_INTERFACES #endif #define MICROPY_PORT_NETWORK_INTERFACES \ MICROPY_HW_NIC_ETH \ - MICROPY_HW_NIC_CYW43 \ MICROPY_BOARD_NETWORK_INTERFACES \ #ifndef MICROPY_BOARD_ROOT_POINTERS diff --git a/ports/renesas-ra/mpconfigport.h b/ports/renesas-ra/mpconfigport.h index bd936061f..c2b89f415 100644 --- a/ports/renesas-ra/mpconfigport.h +++ b/ports/renesas-ra/mpconfigport.h @@ -210,19 +210,11 @@ #define MP_STATE_PORT MP_STATE_VM -#if MICROPY_PY_NETWORK_ESP_HOSTED -extern const struct _mp_obj_type_t mod_network_esp_hosted_type; -#define MICROPY_HW_NIC_ESP_HOSTED { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_esp_hosted_type) }, -#else -#define MICROPY_HW_NIC_ESP_HOSTED -#endif - #ifndef MICROPY_BOARD_NETWORK_INTERFACES #define MICROPY_BOARD_NETWORK_INTERFACES #endif #define MICROPY_PORT_NETWORK_INTERFACES \ - MICROPY_HW_NIC_ESP_HOSTED \ MICROPY_BOARD_NETWORK_INTERFACES \ // Miscellaneous settings diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index 877cea087..35afea4fa 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -242,46 +242,11 @@ #endif #endif -#if MICROPY_PY_NETWORK_CYW43 -extern const struct _mp_obj_type_t mp_network_cyw43_type; -#define MICROPY_HW_NIC_CYW43 \ - { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mp_network_cyw43_type) }, \ - { MP_ROM_QSTR(MP_QSTR_STAT_IDLE), MP_ROM_INT(CYW43_LINK_DOWN) }, \ - { MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING), MP_ROM_INT(CYW43_LINK_JOIN) }, \ - { MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(CYW43_LINK_BADAUTH) }, \ - { MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND), MP_ROM_INT(CYW43_LINK_NONET) }, \ - { MP_ROM_QSTR(MP_QSTR_STAT_CONNECT_FAIL), MP_ROM_INT(CYW43_LINK_FAIL) }, \ - { MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(CYW43_LINK_UP) }, -#else -#define MICROPY_HW_NIC_CYW43 -#endif - -#if MICROPY_PY_NETWORK_NINAW10 -// This Network interface requires the extended socket state. -#ifndef MICROPY_PY_SOCKET_EXTENDED_STATE -#define MICROPY_PY_SOCKET_EXTENDED_STATE (1) -#endif -extern const struct _mp_obj_type_t mod_network_nic_type_nina; -#define MICROPY_HW_NIC_NINAW10 { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_nic_type_nina) }, -#else -#define MICROPY_HW_NIC_NINAW10 -#endif - -#if MICROPY_PY_NETWORK_WIZNET5K -extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k; -#define MICROPY_HW_NIC_WIZNET5K { MP_ROM_QSTR(MP_QSTR_WIZNET5K), MP_ROM_PTR(&mod_network_nic_type_wiznet5k) }, -#else -#define MICROPY_HW_NIC_WIZNET5K -#endif - #ifndef MICROPY_BOARD_NETWORK_INTERFACES #define MICROPY_BOARD_NETWORK_INTERFACES #endif #define MICROPY_PORT_NETWORK_INTERFACES \ - MICROPY_HW_NIC_CYW43 \ - MICROPY_HW_NIC_NINAW10 \ - MICROPY_HW_NIC_WIZNET5K \ MICROPY_BOARD_NETWORK_INTERFACES \ // Additional entries for use with pendsv_schedule_dispatch. diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h index d1d6fe249..bfaa3fb0b 100644 --- a/ports/stm32/mpconfigport.h +++ b/ports/stm32/mpconfigport.h @@ -205,20 +205,6 @@ extern const struct _mp_obj_type_t network_lan_type; #define MICROPY_HW_NIC_ETH #endif -#if MICROPY_PY_NETWORK_CYW43 -extern const struct _mp_obj_type_t mp_network_cyw43_type; -#define MICROPY_HW_NIC_CYW43 { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mp_network_cyw43_type) }, -#else -#define MICROPY_HW_NIC_CYW43 -#endif - -#if MICROPY_PY_NETWORK_WIZNET5K -extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k; -#define MICROPY_HW_NIC_WIZNET5K { MP_ROM_QSTR(MP_QSTR_WIZNET5K), MP_ROM_PTR(&mod_network_nic_type_wiznet5k) }, -#else -#define MICROPY_HW_NIC_WIZNET5K -#endif - // extra constants #define MICROPY_PORT_CONSTANTS \ MACHINE_BUILTIN_MODULE_CONSTANTS \ @@ -231,8 +217,6 @@ extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k; #define MICROPY_PORT_NETWORK_INTERFACES \ MICROPY_HW_NIC_ETH \ - MICROPY_HW_NIC_CYW43 \ - MICROPY_HW_NIC_WIZNET5K \ MICROPY_BOARD_NETWORK_INTERFACES \ #define MP_STATE_PORT MP_STATE_VM |
