From 8b4a21cd64c8199601629e6ae08c746f85fdd068 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 4 Mar 2024 12:11:27 +0100 Subject: [PATCH] extmod/network_ninaw10: Activate the NIC on demand. Activate the NIC on calls to connect() or config() if it's not already active. This change makes the NINA NIC more in line with CYW43 and other NICs, which allow configuring the NIC before or after it is activated. Signed-off-by: iabdalkader --- extmod/network_ninaw10.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/extmod/network_ninaw10.c b/extmod/network_ninaw10.c index e68a7a66e2..e53061557c 100644 --- a/extmod/network_ninaw10.c +++ b/extmod/network_ninaw10.c @@ -193,8 +193,7 @@ static mp_obj_t network_ninaw10_active(size_t n_args, const mp_obj_t *args) { nina_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 2) { bool active = mp_obj_is_true(args[1]); - network_ninaw10_deinit(); - if (active) { + if (active && !self->active) { int error = 0; if ((error = nina_init()) != 0) { mp_raise_msg_varg(&mp_type_OSError, @@ -223,7 +222,8 @@ static mp_obj_t network_ninaw10_active(size_t n_args, const mp_obj_t *args) { semver[NINA_FW_VER_MINOR_OFFS] - 48, semver[NINA_FW_VER_PATCH_OFFS] - 48); } soft_timer_static_init(&mp_wifi_poll_timer, SOFT_TIMER_MODE_ONE_SHOT, 0, network_ninaw10_timer_callback); - } else { + } else if (!active && self->active) { + network_ninaw10_deinit(); nina_deinit(); } self->active = active; @@ -289,6 +289,11 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Key can't be empty!")); } + // Activate the interface if not active. + if (!self->active) { + network_ninaw10_active(2, (mp_obj_t [2]) { pos_args[0], mp_const_true }); + } + // Disconnect active connections first. if (nina_isconnected()) { nina_disconnect();