Skip to content

Commit 65ba481

Browse files
committed
stm32/modnwwiznet5k: Implement WIZNET5K.isconnected() method.
1 parent 829c329 commit 65ba481

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

docs/library/network.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ parameter should be `id`.
268268
Methods
269269
-------
270270

271+
.. method:: wiznet5k.isconnected()
272+
273+
Returns ``True`` if the physical Ethernet link is connected and up.
274+
Returns ``False`` otherwise.
275+
271276
.. method:: wiznet5k.ifconfig([(ip, subnet, gateway, dns)])
272277

273278
Get/set IP address, subnet mask, gateway and DNS.

ports/stm32/modnwwiznet5k.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@ STATIC mp_obj_t wiznet5k_regs(mp_obj_t self_in) {
414414
}
415415
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wiznet5k_regs_obj, wiznet5k_regs);
416416

417+
STATIC mp_obj_t wiznet5k_isconnected(mp_obj_t self_in) {
418+
(void)self_in;
419+
return mp_obj_new_bool(wizphy_getphylink() == PHY_LINK_ON);
420+
}
421+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wiznet5k_isconnected_obj, wiznet5k_isconnected);
422+
417423
/// \method ifconfig([(ip, subnet, gateway, dns)])
418424
/// Get/set IP address, subnet mask, gateway and DNS.
419425
STATIC mp_obj_t wiznet5k_ifconfig(size_t n_args, const mp_obj_t *args) {
@@ -445,6 +451,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wiznet5k_ifconfig_obj, 1, 2, wiznet5k
445451
STATIC const mp_rom_map_elem_t wiznet5k_locals_dict_table[] = {
446452
{ MP_ROM_QSTR(MP_QSTR_regs), MP_ROM_PTR(&wiznet5k_regs_obj) },
447453
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&wiznet5k_ifconfig_obj) },
454+
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&wiznet5k_isconnected_obj) },
448455
};
449456

450457
STATIC MP_DEFINE_CONST_DICT(wiznet5k_locals_dict, wiznet5k_locals_dict_table);

0 commit comments

Comments
 (0)