56
56
import adafruit_wiznet5k .adafruit_wiznet5k_dns as dns
57
57
from adafruit_wiznet5k .adafruit_wiznet5k_debug import debug_msg
58
58
59
- # Wiznet5k Registers
60
- _REG_MR = const (0x0000 ) # Mode
61
- _REG_GAR = const (0x0001 ) # Gateway IP Address
62
- _REG_SUBR = const (0x0005 ) # Subnet Mask Address
63
- _REG_VERSIONR = {"w5100s" : const (0x0080 ), "w5500" : const (0x0039 )}
64
- _REG_SHAR = const (0x0009 ) # Source Hardware Address
65
- _REG_SIPR = const (0x000F ) # Source IP Address
66
- _REG_PHYCFGR = {"w5100s" : const (0x003C ), "w5500" : const (0x002E )}
67
- _REG_RCR = {"w5100s" : const (0x0019 ), "w5500" : const (0x001B )}
68
- _REG_RTR = {"w5100s" : const (0x0017 ), "w5500" : const (0x0019 )}
69
-
70
- # Wiznet5k Socket Registers
59
+ # *** Wiznet Common Registers ***
60
+ # Mode (used only for initialization and soft reset).
61
+ _REG_MR = {"w5100s" : const (0x0000 ), "w5500" : const (0x0000 ), "w6100" : const (0x4000 )}
62
+ # Gateway IPv4 Address.
63
+ _REG_GAR = {"w5100s" : const (0x0001 ), "w5500" : const (0x0001 ), "w6100" : const (0x4130 )}
64
+ # Subnet Mask Address
65
+ _REG_SUBR = {"w5100s" : const (0x0005 ), "w5500" : const (0x0005 ), "w6100" : const (0x4134 )}
66
+ # Chip version.
67
+ _REG_VERSIONR = {
68
+ "w5100s" : const (0x0080 ),
69
+ "w5500" : const (0x0039 ),
70
+ "w6100" : const (0x0000 ),
71
+ }
72
+ # Source Hardware Address
73
+ _REG_SHAR = {"w5100s" : const (0x0009 ), "w5500" : const (0x0009 ), "w6100" : const (0x4120 )}
74
+ # Source IP Address
75
+ _REG_SIPR = {"w5100s" : const (0x000F ), "w5500" : const (0x000F ), "w6100" : const (0x4138 )}
76
+ # Register with link status flag (PHYCFGR for 5xxxx, PHYSR for 6100).
77
+ _REG_LINK_FLAG = {
78
+ "w5100s" : const (0x003C ),
79
+ "w5500" : const (0x002E ),
80
+ "w6100" : const (0x3000 ),
81
+ }
82
+ _REG_RCR = {"w5100s" : const (0x0019 ), "w5500" : const (0x001B ), "w6100" : const (0x4204 )}
83
+ _REG_RTR = {"w5100s" : const (0x0017 ), "w5500" : const (0x0019 ), "w6100" : const (0x4200 )}
84
+
85
+ # Wiznet Socket Registers.
71
86
_REG_SNMR = const (0x0000 ) # Socket n Mode
72
87
_REG_SNCR = const (0x0001 ) # Socket n Command
73
88
_REG_SNIR = const (0x0002 ) # Socket n Interrupt
@@ -301,7 +316,7 @@ def ip_address(self) -> bytes:
301
316
302
317
:return bytes: IP address as four bytes.
303
318
"""
304
- return self ._read (_REG_SIPR , 0x00 , 4 )
319
+ return self ._read (_REG_SIPR [ self . _chip_type ] , 0x00 , 4 )
305
320
306
321
@staticmethod
307
322
def pretty_ip (ipv4 : bytes ) -> str :
@@ -338,7 +353,7 @@ def mac_address(self) -> bytes:
338
353
339
354
:return bytes: Six byte MAC address.
340
355
"""
341
- return self ._read (_REG_SHAR , 0x00 , 6 )
356
+ return self ._read (_REG_SHAR [ self . _chip_type ] , 0x00 , 6 )
342
357
343
358
@mac_address .setter
344
359
def mac_address (self , address : Union [MacAddressRaw , str ]) -> None :
@@ -357,7 +372,7 @@ def mac_address(self, address: Union[MacAddressRaw, str]) -> None:
357
372
if len (address ) != 6 :
358
373
raise ValueError ()
359
374
# Bytes conversion will raise ValueError if values are not 0-255
360
- self ._write (_REG_SHAR , 0x04 , bytes (address ))
375
+ self ._write (_REG_SHAR [ self . _chip_type ] , 0x04 , bytes (address ))
361
376
except ValueError :
362
377
# pylint: disable=raise-missing-from
363
378
raise ValueError ("Invalid MAC address." )
@@ -417,7 +432,7 @@ def link_status(self) -> bool:
417
432
:return bool: True if the link is up, False if the link is down.
418
433
"""
419
434
return bool (
420
- int .from_bytes (self ._read (_REG_PHYCFGR [self ._chip_type ], 0x00 ), "big" )
435
+ int .from_bytes (self ._read (_REG_LINK_FLAG [self ._chip_type ], 0x00 ), "big" )
421
436
& 0x01
422
437
)
423
438
@@ -431,8 +446,8 @@ def ifconfig(self) -> Tuple[bytes, bytes, bytes, bytes]:
431
446
"""
432
447
return (
433
448
self .ip_address ,
434
- self ._read (_REG_SUBR , 0x00 , 4 ),
435
- self ._read (_REG_GAR , 0x00 , 4 ),
449
+ self ._read (_REG_SUBR [ self . _chip_type ] , 0x00 , 4 ),
450
+ self ._read (_REG_GAR [ self . _chip_type ] , 0x00 , 4 ),
436
451
self ._dns ,
437
452
)
438
453
@@ -451,9 +466,9 @@ def ifconfig(
451
466
raise ValueError ("IPv4 address must be 4 bytes." )
452
467
ip_address , subnet_mask , gateway_address , dns_server = params
453
468
454
- self ._write (_REG_SIPR , 0x04 , bytes (ip_address ))
455
- self ._write (_REG_SUBR , 0x04 , bytes (subnet_mask ))
456
- self ._write (_REG_GAR , 0x04 , bytes (gateway_address ))
469
+ self ._write (_REG_SIPR [ self . _chip_type ] , 0x04 , bytes (ip_address ))
470
+ self ._write (_REG_SUBR [ self . _chip_type ] , 0x04 , bytes (subnet_mask ))
471
+ self ._write (_REG_GAR [ self . _chip_type ] , 0x04 , bytes (gateway_address ))
457
472
458
473
self ._dns = bytes (dns_server )
459
474
@@ -999,11 +1014,11 @@ def _check_link_status(self):
999
1014
1000
1015
def _read_mr (self ) -> int :
1001
1016
"""Read from the Mode Register (MR)."""
1002
- return int .from_bytes (self ._read (_REG_MR , 0x00 ), "big" )
1017
+ return int .from_bytes (self ._read (_REG_MR [ self . _chip_type ] , 0x00 ), "big" )
1003
1018
1004
1019
def _write_mr (self , data : int ) -> None :
1005
1020
"""Write to the mode register (MR)."""
1006
- self ._write (_REG_MR , 0x04 , data )
1021
+ self ._write (_REG_MR [ self . _chip_type ] , 0x04 , data )
1007
1022
1008
1023
# *** Low Level Methods ***
1009
1024
@@ -1131,7 +1146,9 @@ def _read_sndipr(self, sock) -> bytes:
1131
1146
"""Read socket destination IP address."""
1132
1147
data = []
1133
1148
for offset in range (4 ):
1134
- data .append (self ._read_socket_register (sock , _REG_SIPR + offset ))
1149
+ data .append (
1150
+ self ._read_socket_register (sock , _REG_SIPR [self ._chip_type ] + offset )
1151
+ )
1135
1152
return bytes (data )
1136
1153
1137
1154
def write_sndipr (self , sock : int , ip_addr : bytes ) -> None :
0 commit comments