@@ -187,7 +187,7 @@ def __init__(
187
187
188
188
# attempt to initialize the module
189
189
self ._ch_base_msb = 0
190
- assert self ._w5100_init () == 1 , "Failed to initialize WIZnet module."
190
+ assert self ._w5xxx_init () == 1 , "Failed to initialize WIZnet module."
191
191
# Set MAC address
192
192
self .mac_address = mac
193
193
self .src_port = 0
@@ -449,75 +449,78 @@ def ifconfig(
449
449
450
450
self ._dns = dns_server
451
451
452
- def _w5100_init (self ) -> int :
452
+ def _w5xxx_init (self ) -> int :
453
453
"""
454
454
Detect and initialize a Wiznet5k ethernet module.
455
455
456
456
:return int: 1 if the initialization succeeds, 0 if it fails.
457
457
"""
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
+
458
505
time .sleep (1 )
459
506
self ._cs .switch_to_output ()
460
507
self ._cs .value = 1
461
508
462
509
# Detect if chip is Wiznet W5500
463
- if self . detect_w5500 () == 1 :
510
+ if _detect_and_reset_w5500 () :
464
511
# perform w5500 initialization
465
512
for i in range (0 , W5200_W5500_MAX_SOCK_NUM ):
466
513
ctrl_byte = 0x0C + (i << 5 )
467
514
self .write (0x1E , ctrl_byte , 2 )
468
515
self .write (0x1F , ctrl_byte , 2 )
469
516
else :
470
517
# Detect if chip is Wiznet W5100S
471
- if self . detect_w5100s () == 1 :
518
+ if _detect_and_reset_w5100s () :
472
519
pass
473
520
else :
474
521
return 0
475
522
return 1
476
523
477
- def detect_w5500 (self ) -> int :
478
- """
479
- Detect W5500 chip.
480
-
481
- :return int: 1 if a W5500 chip is detected, -1 if not.
482
- """
483
- self ._chip_type = "w5500"
484
- assert self .sw_reset () == 0 , "Chip not reset properly!"
485
- self ._write_mr (0x08 )
486
- # assert self._read_mr()[0] == 0x08, "Expected 0x08."
487
- if self ._read_mr ()[0 ] != 0x08 :
488
- return - 1
489
-
490
- self ._write_mr (0x10 )
491
- # assert self._read_mr()[0] == 0x10, "Expected 0x10."
492
- if self ._read_mr ()[0 ] != 0x10 :
493
- return - 1
494
-
495
- self ._write_mr (0x00 )
496
- # assert self._read_mr()[0] == 0x00, "Expected 0x00."
497
- if self ._read_mr ()[0 ] != 0x00 :
498
- return - 1
499
-
500
- if self .read (REG_VERSIONR_W5500 , 0x00 )[0 ] != 0x04 :
501
- return - 1
502
- # self._chip_type = "w5500"
503
- # self._ch_base_msb = 0x10
504
- return 1
505
-
506
- def detect_w5100s (self ) -> int :
507
- """
508
- Detect W5100S chip.
509
-
510
- :return int: 1 if a W5100 chip is detected, -1 if not.
511
- """
512
- self ._chip_type = "w5100s"
513
- # sw reset
514
- assert self .sw_reset () == 0 , "Chip not reset properly!"
515
- if self .read (REG_VERSIONR_W5100S , 0x00 )[0 ] != 0x51 :
516
- return - 1
517
-
518
- self ._ch_base_msb = 0x0400
519
- return 1
520
-
521
524
def sw_reset (self ) -> int :
522
525
"""Perform a soft-reset on the Wiznet chip.
523
526
0 commit comments