Skip to content

Commit 5558411

Browse files
committed
extmod/network_cyw43.c: Make new overrideable.
Signed-off-by: Peter Harper <[email protected]>
1 parent b550134 commit 5558411

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

extmod/network_cyw43.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,29 @@ static void network_cyw43_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
8989
);
9090
}
9191

92+
93+
mp_obj_t network_cyw43_get_interface(mp_int_t type) {
94+
if (type == MOD_NETWORK_STA_IF) {
95+
return MP_OBJ_FROM_PTR(&network_cyw43_wl_sta);
96+
} else {
97+
return MP_OBJ_FROM_PTR(&network_cyw43_wl_ap);
98+
}
99+
}
100+
101+
// Allow network_cyw43_make_new to be overridden
102+
#ifndef MICROPY_PY_NETWORK_CYW43_MAKE_NEW
103+
#define MICROPY_PY_NETWORK_CYW43_MAKE_NEW network_cyw43_make_new
92104
static mp_obj_t network_cyw43_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
93105
mp_arg_check_num(n_args, n_kw, 0, 1, false);
94106
if (n_args == 0 || mp_obj_get_int(args[0]) == MOD_NETWORK_STA_IF) {
95-
return MP_OBJ_FROM_PTR(&network_cyw43_wl_sta);
107+
return network_cyw43_get_interface(MOD_NETWORK_STA_IF);
96108
} else {
97-
return MP_OBJ_FROM_PTR(&network_cyw43_wl_ap);
109+
return network_cyw43_get_interface(MOD_NETWORK_AP_IF);
98110
}
99111
}
112+
#else
113+
mp_obj_t MICROPY_PY_NETWORK_CYW43_MAKE_NEW(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
114+
#endif
100115

101116
static mp_obj_t network_cyw43_send_ethernet(mp_obj_t self_in, mp_obj_t buf_in) {
102117
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -558,7 +573,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
558573
mp_network_cyw43_type,
559574
MP_QSTR_CYW43,
560575
MP_TYPE_FLAG_NONE,
561-
make_new, network_cyw43_make_new,
576+
make_new, MICROPY_PY_NETWORK_CYW43_MAKE_NEW,
562577
print, network_cyw43_print,
563578
locals_dict, &network_cyw43_locals_dict
564579
);

extmod/network_cyw43.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@
2828

2929
extern const mp_obj_type_t mp_network_cyw43_type;
3030

31+
// Get the interface, where type is either MOD_NETWORK_STA_IF or MOD_NETWORK_AP_IF
32+
mp_obj_t network_cyw43_get_interface(mp_int_t type);
33+
3134
#endif // MICROPY_INCLUDED_EXTMOD_NETWORK_CYW43_H

0 commit comments

Comments
 (0)