Skip to content

Commit 58d3400

Browse files
author
BiffoBear
committed
Refactor read and write socket reg methods to chip specific section.
1 parent 2900ae1 commit 58d3400

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,27 +1120,6 @@ def _write(self, addr: int, callback: int, data: Union[int, bytes]) -> None:
11201120
pass
11211121
bus_device.write(data)
11221122

1123-
def _write_socket_register(self, sock: int, address: int, data: int) -> None:
1124-
"""Write to a WIZnet 5k socket register."""
1125-
if self._chip_type in ("w5500", "w6100"):
1126-
cntl_byte = (sock << 5) + 0x0C
1127-
self._write(address, cntl_byte, data)
1128-
elif self._chip_type == "w5100s":
1129-
cntl_byte = 0
1130-
self._write(self._ch_base_msb + sock * _CH_SIZE + address, cntl_byte, data)
1131-
1132-
def _read_socket_register(self, sock: int, address: int) -> int:
1133-
"""Read a WIZnet 5k socket register."""
1134-
if self._chip_type in ("w5500", "w6100"):
1135-
cntl_byte = (sock << 5) + 0x08
1136-
register = self._read(address, cntl_byte)
1137-
elif self._chip_type == "w5100s":
1138-
cntl_byte = 0
1139-
register = self._read(
1140-
self._ch_base_msb + sock * _CH_SIZE + address, cntl_byte
1141-
)
1142-
return int.from_bytes(register, "big")
1143-
11441123
def _read_two_byte_sock_reg(self, sock: int, reg_address: int) -> int:
11451124
"""Read a two byte socket register."""
11461125
register = self._read_socket_register(sock, reg_address) << 8
@@ -1353,3 +1332,24 @@ def _chip_parse_udp_header(self, socket_num) -> int:
13531332
self.udp_from_port[socket_num] = int.from_bytes(self._pbuff[6:], "big")
13541333
return int.from_bytes(self._pbuff[:2], "big") & 0x07FF
13551334
raise ValueError("Unsupported chip type.")
1335+
1336+
def _write_socket_register(self, sock: int, address: int, data: int) -> None:
1337+
"""Write to a WIZnet 5k socket register."""
1338+
if self._chip_type in ("w5500", "w6100"):
1339+
cntl_byte = (sock << 5) + 0x0C
1340+
self._write(address, cntl_byte, data)
1341+
elif self._chip_type == "w5100s":
1342+
cntl_byte = 0
1343+
self._write(self._ch_base_msb + sock * _CH_SIZE + address, cntl_byte, data)
1344+
1345+
def _read_socket_register(self, sock: int, address: int) -> int:
1346+
"""Read a WIZnet 5k socket register."""
1347+
if self._chip_type in ("w5500", "w6100"):
1348+
cntl_byte = (sock << 5) + 0x08
1349+
register = self._read(address, cntl_byte)
1350+
elif self._chip_type == "w5100s":
1351+
cntl_byte = 0
1352+
register = self._read(
1353+
self._ch_base_msb + sock * _CH_SIZE + address, cntl_byte
1354+
)
1355+
return int.from_bytes(register, "big")

0 commit comments

Comments
 (0)