Skip to content

Commit 5dbddbb

Browse files
author
BiffoBear
committed
Moved _detect_and_reset_w5500 and _detect_and_reset_w5100s into _w5xxx_init.
1 parent 296d4ec commit 5dbddbb

File tree

1 file changed

+49
-48
lines changed

1 file changed

+49
-48
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -455,71 +455,72 @@ def _w5xxx_init(self) -> int:
455455
456456
:return int: 1 if the initialization succeeds, 0 if it fails.
457457
"""
458+
459+
def _detect_and_reset_w5500() -> bool:
460+
"""
461+
Detect and reset a W5500 chip. Called at startup to initialize the
462+
interface hardware.
463+
464+
:return bool: True if a W5500 chip is detected, False if not.
465+
"""
466+
self._chip_type = "w5500"
467+
# assert self.sw_reset() == 0, "Chip not reset properly!"
468+
self._write_mr(0x08)
469+
# assert self._read_mr()[0] == 0x08, "Expected 0x08."
470+
if self._read_mr()[0] != 0x08:
471+
return False
472+
473+
self._write_mr(0x10)
474+
# assert self._read_mr()[0] == 0x10, "Expected 0x10."
475+
if self._read_mr()[0] != 0x10:
476+
return False
477+
478+
self._write_mr(0x00)
479+
# assert self._read_mr()[0] == 0x00, "Expected 0x00."
480+
if self._read_mr()[0] != 0x00:
481+
return False
482+
483+
if self.read(REG_VERSIONR_W5500, 0x00)[0] != 0x04:
484+
return False
485+
# self._chip_type = "w5500"
486+
# self._ch_base_msb = 0x10
487+
return True
488+
489+
def _detect_and_reset_w5100s() -> bool:
490+
"""
491+
Detect and reset a W5100S chip. Called at startup to initialize the
492+
interface hardware.
493+
494+
:return bool: True if a W5100 chip is detected, False if not.
495+
"""
496+
self._chip_type = "w5100s"
497+
# sw reset
498+
assert self.sw_reset() == 0, "Chip not reset properly!"
499+
if self.read(REG_VERSIONR_W5100S, 0x00)[0] != 0x51:
500+
return False
501+
502+
self._ch_base_msb = 0x0400
503+
return True
504+
458505
time.sleep(1)
459506
self._cs.switch_to_output()
460507
self._cs.value = 1
461508

462509
# Detect if chip is Wiznet W5500
463-
if self._detect_and_reset_w5500() == 1:
510+
if _detect_and_reset_w5500():
464511
# perform w5500 initialization
465512
for i in range(0, W5200_W5500_MAX_SOCK_NUM):
466513
ctrl_byte = 0x0C + (i << 5)
467514
self.write(0x1E, ctrl_byte, 2)
468515
self.write(0x1F, ctrl_byte, 2)
469516
else:
470517
# Detect if chip is Wiznet W5100S
471-
if self._detect_and_reset_w5100s() == 1:
518+
if _detect_and_reset_w5100s():
472519
pass
473520
else:
474521
return 0
475522
return 1
476523

477-
def _detect_and_reset_w5500(self) -> int:
478-
"""
479-
Detect and reset a W5500 chip. Called at startup to initialize the
480-
interface hardware.
481-
482-
:return int: 1 if a W5500 chip is detected, -1 if not.
483-
"""
484-
self._chip_type = "w5500"
485-
# assert self.sw_reset() == 0, "Chip not reset properly!"
486-
self._write_mr(0x08)
487-
# assert self._read_mr()[0] == 0x08, "Expected 0x08."
488-
if self._read_mr()[0] != 0x08:
489-
return -1
490-
491-
self._write_mr(0x10)
492-
# assert self._read_mr()[0] == 0x10, "Expected 0x10."
493-
if self._read_mr()[0] != 0x10:
494-
return -1
495-
496-
self._write_mr(0x00)
497-
# assert self._read_mr()[0] == 0x00, "Expected 0x00."
498-
if self._read_mr()[0] != 0x00:
499-
return -1
500-
501-
if self.read(REG_VERSIONR_W5500, 0x00)[0] != 0x04:
502-
return -1
503-
# self._chip_type = "w5500"
504-
# self._ch_base_msb = 0x10
505-
return 1
506-
507-
def _detect_and_reset_w5100s(self) -> int:
508-
"""
509-
Detect and reset a W5100S chip. Called at startup to initialize the
510-
interface hardware.
511-
512-
:return int: 1 if a W5100 chip is detected, -1 if not.
513-
"""
514-
self._chip_type = "w5100s"
515-
# sw reset
516-
assert self.sw_reset() == 0, "Chip not reset properly!"
517-
if self.read(REG_VERSIONR_W5100S, 0x00)[0] != 0x51:
518-
return -1
519-
520-
self._ch_base_msb = 0x0400
521-
return 1
522-
523524
def sw_reset(self) -> int:
524525
"""Perform a soft-reset on the Wiznet chip.
525526

0 commit comments

Comments
 (0)