Skip to content

Commit 5df2376

Browse files
author
BiffoBear
committed
Renamed _chip_type to chip_type so that users can check which hardware is present.
1 parent 5dbddbb commit 5df2376

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def __init__(
169169
:param bool debug: Enable debugging output, defaults to False.
170170
"""
171171
self._debug = debug
172-
self._chip_type = None
172+
self.chip_type = None
173173
self._device = SPIDevice(spi_bus, cs, baudrate=8000000, polarity=0, phase=0)
174174
# init c.s.
175175
self._cs = cs
@@ -282,9 +282,9 @@ def max_sockets(self) -> int:
282282
283283
:return int: Maximum supported sockets.
284284
"""
285-
if self._chip_type == "w5500":
285+
if self.chip_type == "w5500":
286286
return W5200_W5500_MAX_SOCK_NUM
287-
if self._chip_type == "w5100s":
287+
if self.chip_type == "w5100s":
288288
return W5100_MAX_SOCK_NUM
289289
return -1
290290

@@ -295,7 +295,7 @@ def chip(self) -> str:
295295
296296
:return str: The chip type.
297297
"""
298-
return self._chip_type
298+
return self.chip_type
299299

300300
@property
301301
def ip_address(self) -> bytearray:
@@ -393,10 +393,10 @@ def link_status(self) -> int:
393393
394394
:return int: 1 if the link is up, 0 if the link is down.
395395
"""
396-
if self._chip_type == "w5500":
396+
if self.chip_type == "w5500":
397397
data = self.read(REG_PHYCFGR, 0x00)
398398
return data[0] & 0x01
399-
if self._chip_type == "w5100s":
399+
if self.chip_type == "w5100s":
400400
data = self.read(REG_PHYCFGR_W5100S, 0x00)
401401
return data[0] & 0x01
402402
return 0
@@ -463,7 +463,7 @@ def _detect_and_reset_w5500() -> bool:
463463
464464
:return bool: True if a W5500 chip is detected, False if not.
465465
"""
466-
self._chip_type = "w5500"
466+
self.chip_type = "w5500"
467467
# assert self.sw_reset() == 0, "Chip not reset properly!"
468468
self._write_mr(0x08)
469469
# assert self._read_mr()[0] == 0x08, "Expected 0x08."
@@ -493,7 +493,7 @@ def _detect_and_reset_w5100s() -> bool:
493493
494494
:return bool: True if a W5100 chip is detected, False if not.
495495
"""
496-
self._chip_type = "w5100s"
496+
self.chip_type = "w5100s"
497497
# sw reset
498498
assert self.sw_reset() == 0, "Chip not reset properly!"
499499
if self.read(REG_VERSIONR_W5100S, 0x00)[0] != 0x51:
@@ -564,7 +564,7 @@ def read(
564564
:return Union[WriteableBuffer, bytearray]: Data read from the chip.
565565
"""
566566
with self._device as bus_device:
567-
if self._chip_type == "w5500":
567+
if self.chip_type == "w5500":
568568
bus_device.write(bytes([addr >> 8])) # pylint: disable=no-member
569569
bus_device.write(bytes([addr & 0xFF])) # pylint: disable=no-member
570570
bus_device.write(bytes([callback])) # pylint: disable=no-member
@@ -592,7 +592,7 @@ def write(
592592
:param Union[int, Sequence[Union[int, bytes]]] data: Data to write to the register address.
593593
"""
594594
with self._device as bus_device:
595-
if self._chip_type == "w5500":
595+
if self.chip_type == "w5500":
596596
bus_device.write(bytes([addr >> 8])) # pylint: disable=no-member
597597
bus_device.write(bytes([addr & 0xFF])) # pylint: disable=no-member
598598
bus_device.write(bytes([callback])) # pylint: disable=no-member
@@ -910,7 +910,7 @@ def socket_read(
910910
# Read the starting save address of the received data
911911
ptr = self._read_snrx_rd(socket_num)
912912

913-
if self._chip_type == "w5500":
913+
if self.chip_type == "w5500":
914914
# Read data from the starting address of snrx_rd
915915
ctrl_byte = 0x18 + (socket_num << 5)
916916

@@ -1001,7 +1001,7 @@ def socket_write(
10011001
# Read the starting address for saving the transmitting data.
10021002
ptr = self._read_sntx_wr(socket_num)
10031003
offset = ptr & SOCK_MASK
1004-
if self._chip_type == "w5500":
1004+
if self.chip_type == "w5500":
10051005
dst_addr = offset + (socket_num * SOCK_SIZE + 0x8000)
10061006

10071007
txbuf = buffer[:ret]
@@ -1136,10 +1136,10 @@ def _read_snmr(self, sock: int) -> Optional[bytearray]:
11361136

11371137
def _write_socket(self, sock: int, address: int, data: int) -> None:
11381138
"""Write to a W5k socket register."""
1139-
if self._chip_type == "w5500":
1139+
if self.chip_type == "w5500":
11401140
cntl_byte = (sock << 5) + 0x0C
11411141
return self.write(address, cntl_byte, data)
1142-
if self._chip_type == "w5100s":
1142+
if self.chip_type == "w5100s":
11431143
cntl_byte = 0
11441144
return self.write(
11451145
self._ch_base_msb + sock * CH_SIZE + address, cntl_byte, data
@@ -1148,10 +1148,10 @@ def _write_socket(self, sock: int, address: int, data: int) -> None:
11481148

11491149
def _read_socket(self, sock: int, address: int) -> Optional[bytearray]:
11501150
"""Read a W5k socket register."""
1151-
if self._chip_type == "w5500":
1151+
if self.chip_type == "w5500":
11521152
cntl_byte = (sock << 5) + 0x08
11531153
return self.read(address, cntl_byte)
1154-
if self._chip_type == "w5100s":
1154+
if self.chip_type == "w5100s":
11551155
cntl_byte = 0
11561156
return self.read(self._ch_base_msb + sock * CH_SIZE + address, cntl_byte)
11571157
return None

0 commit comments

Comments
 (0)