Skip to content

Commit 946400a

Browse files
author
BiffoBear
committed
Add w6100 detection.
1 parent d1fa3a1 commit 946400a

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def __init__(
236236
# attempt to initialize the module
237237
self._ch_base_msb = 0
238238
self._src_ports_in_use = []
239-
self._w5xxx_init()
239+
self._wiznet_chip_init()
240240

241241
# Set MAC address
242242
self.mac_address = mac
@@ -951,13 +951,39 @@ def sw_reset(self) -> None:
951951
if result != expected_result:
952952
raise RuntimeError("WIZnet chip reset failed.")
953953

954-
def _w5xxx_init(self) -> None:
954+
def _wiznet_chip_init(self) -> None:
955955
"""
956956
Detect and initialize a WIZnet 5k Ethernet module.
957957
958958
:raises RuntimeError: If no WIZnet chip is detected.
959959
"""
960960

961+
def _detect_and_reset_w6100() -> bool:
962+
"""
963+
Detect and reset a W6100 chip. Called at startup to initialize the
964+
interface hardware.
965+
966+
:return bool: True if a W6100 chip is detected, False if not.
967+
"""
968+
self._chip_type = "w6100"
969+
try:
970+
self.sw_reset()
971+
except RuntimeError:
972+
return False
973+
974+
if self._read(_REG_VERSIONR[self._chip_type], 0x00)[0] != 0x61:
975+
return False
976+
# Initialize w6100.
977+
self._write(0x41F5, 0x04, 0x3A) # Unlock network settings.
978+
for i in range(_MAX_SOCK_NUM[self._chip_type]):
979+
ctrl_byte = 0x0C + (i << 5)
980+
self._write(0x1E, ctrl_byte, 2)
981+
self._write(0x1F, ctrl_byte, 2)
982+
self._ch_base_msb = 0x00
983+
WIZNET5K._sockets_reserved = [False] * (_MAX_SOCK_NUM[self._chip_type] - 1)
984+
self._src_ports_in_use = [0] * _MAX_SOCK_NUM[self._chip_type]
985+
return True
986+
961987
def _detect_and_reset_w5500() -> bool:
962988
"""
963989
Detect and reset a W5500 chip. Called at startup to initialize the
@@ -1015,7 +1041,11 @@ def _detect_and_reset_w5100s() -> bool:
10151041
self._src_ports_in_use = [0] * _MAX_SOCK_NUM[self._chip_type]
10161042
return True
10171043

1018-
for func in [_detect_and_reset_w5100s, _detect_and_reset_w5500]:
1044+
for func in [
1045+
_detect_and_reset_w5100s,
1046+
_detect_and_reset_w5500,
1047+
_detect_and_reset_w6100,
1048+
]:
10191049
if func():
10201050
return
10211051
self._chip_type = None

0 commit comments

Comments
 (0)