kopia lustrzana https://github.com/micropython/micropython
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>pull/14023/head
rodzic
d712feb68a
commit
8b4a21cd64
|
@ -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();
|
||||
|
|
Ładowanie…
Reference in New Issue