Skip to content

Commit 0ca481e

Browse files
authored
Merge branch 'main' into main
2 parents 00cab19 + 17c9ed8 commit 0ca481e

File tree

1 file changed

+50
-49
lines changed

1 file changed

+50
-49
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

+50-49
Original file line numberDiff line numberDiff line change
@@ -452,77 +452,78 @@ def ifconfig(
452452

453453
self._dns = dns_server
454454

455-
def _w5100_init(self) -> int:
455+
def _w5xxx_init(self) -> int:
456456
"""
457457
Detect and initialize a Wiznet5k ethernet module.
458458
459459
:return int: 1 if the initialization succeeds, 0 if it fails.
460460
"""
461+
462+
def _detect_and_reset_w5500() -> bool:
463+
"""
464+
Detect and reset a W5500 chip. Called at startup to initialize the
465+
interface hardware.
466+
467+
:return bool: True if a W5500 chip is detected, False if not.
468+
"""
469+
self._chip_type = "w5500"
470+
# assert self.sw_reset() == 0, "Chip not reset properly!"
471+
self._write_mr(0x08)
472+
# assert self._read_mr()[0] == 0x08, "Expected 0x08."
473+
if self._read_mr()[0] != 0x08:
474+
return False
475+
476+
self._write_mr(0x10)
477+
# assert self._read_mr()[0] == 0x10, "Expected 0x10."
478+
if self._read_mr()[0] != 0x10:
479+
return False
480+
481+
self._write_mr(0x00)
482+
# assert self._read_mr()[0] == 0x00, "Expected 0x00."
483+
if self._read_mr()[0] != 0x00:
484+
return False
485+
486+
if self.read(REG_VERSIONR_W5500, 0x00)[0] != 0x04:
487+
return False
488+
# self._chip_type = "w5500"
489+
# self._ch_base_msb = 0x10
490+
return True
491+
492+
def _detect_and_reset_w5100s() -> bool:
493+
"""
494+
Detect and reset a W5100S chip. Called at startup to initialize the
495+
interface hardware.
496+
497+
:return bool: True if a W5100 chip is detected, False if not.
498+
"""
499+
self._chip_type = "w5100s"
500+
# sw reset
501+
assert self.sw_reset() == 0, "Chip not reset properly!"
502+
if self.read(REG_VERSIONR_W5100S, 0x00)[0] != 0x51:
503+
return False
504+
505+
self._ch_base_msb = 0x0400
506+
return True
507+
461508
time.sleep(1)
462509
self._cs.switch_to_output()
463510
self._cs.value = 1
464511

465512
# Detect if chip is Wiznet W5500
466-
if self.detect_w5500() == 1:
513+
if _detect_and_reset_w5500():
467514
# perform w5500 initialization
468515
for i in range(0, W5200_W5500_MAX_SOCK_NUM):
469516
ctrl_byte = 0x0C + (i << 5)
470517
self.write(0x1E, ctrl_byte, 2)
471518
self.write(0x1F, ctrl_byte, 2)
472519
else:
473520
# Detect if chip is Wiznet W5100S
474-
if self.detect_w5100s() == 1:
521+
if _detect_and_reset_w5100s():
475522
pass
476523
else:
477524
return 0
478525
return 1
479526

480-
def detect_w5500(self) -> int:
481-
"""
482-
Detect W5500 chip.
483-
484-
:return int: 1 if a W5500 chip is detected, -1 if not.
485-
"""
486-
self._chip_type = "w5500"
487-
if self.sw_reset() != 0:
488-
raise RuntimeError("Chip not reset properly!")
489-
self._write_mr(0x08)
490-
# assert self._read_mr()[0] == 0x08, "Expected 0x08."
491-
if self._read_mr()[0] != 0x08:
492-
return -1
493-
494-
self._write_mr(0x10)
495-
# assert self._read_mr()[0] == 0x10, "Expected 0x10."
496-
if self._read_mr()[0] != 0x10:
497-
return -1
498-
499-
self._write_mr(0x00)
500-
# assert self._read_mr()[0] == 0x00, "Expected 0x00."
501-
if self._read_mr()[0] != 0x00:
502-
return -1
503-
504-
if self.read(REG_VERSIONR_W5500, 0x00)[0] != 0x04:
505-
return -1
506-
# self._chip_type = "w5500"
507-
# self._ch_base_msb = 0x10
508-
return 1
509-
510-
def detect_w5100s(self) -> int:
511-
"""
512-
Detect W5100S chip.
513-
514-
:return int: 1 if a W5100 chip is detected, -1 if not.
515-
"""
516-
self._chip_type = "w5100s"
517-
# sw reset
518-
if self.sw_reset() != 0:
519-
raise RuntimeError("Chip not reset properly!")
520-
if self.read(REG_VERSIONR_W5100S, 0x00)[0] != 0x51:
521-
return -1
522-
523-
self._ch_base_msb = 0x0400
524-
return 1
525-
526527
def sw_reset(self) -> int:
527528
"""Perform a soft-reset on the Wiznet chip.
528529

0 commit comments

Comments
 (0)