summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriabdalkader <i.abdalkader@gmail.com>2024-03-04 12:11:27 +0100
committerDamien George <damien@micropython.org>2024-03-14 17:40:18 +1100
commit8b4a21cd64c8199601629e6ae08c746f85fdd068 (patch)
tree1bfbd40981450713895f1f82008121d13f3911e4
parentd712feb68a3ac8ec181ff75a4ac55997141ad075 (diff)
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 <i.abdalkader@gmail.com>
-rw-r--r--extmod/network_ninaw10.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/extmod/network_ninaw10.c b/extmod/network_ninaw10.c
index e68a7a66e..e53061557 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();