Skip to content

Commit

Permalink
extmod/network_ninaw10: Activate the NIC on demand.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
iabdalkader authored and dpgeorge committed Mar 14, 2024
1 parent d712feb commit 8b4a21c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions extmod/network_ninaw10.c
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 8b4a21c

Please sign in to comment.