Skip to content

Commit 4e45758

Browse files
Tinyu-Zhaolbuque
authored andcommitted
lib/unit: Fix pahub bug in read/write registers.
Signed-off-by: Tinyu-Zhao <[email protected]>
1 parent 10da470 commit 4e45758

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

m5stack/libs/unit/pahub.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: MIT
44
from machine import I2C
55
from micropython import const
6+
import time
67

78
try:
89
from typing import overload, Sequence
@@ -87,6 +88,7 @@ def readfrom_into(self, addr: int, buf: AnyWritableBuf, stop: bool = True) -> No
8788
def writeto(self, addr: int, buf: AnyReadableBuf, stop: bool = True) -> int:
8889
self.select_channel(self._chn)
8990
result = self._i2c.writeto(addr, buf, stop)
91+
time.sleep_ms(100)
9092
self.release_channel(self._chn)
9193
return result
9294

@@ -96,18 +98,20 @@ def writevto(self, addr: int, vector: Sequence[AnyReadableBuf], stop: bool = Tru
9698
self.release_channel(self._chn)
9799
return result
98100

99-
def readfrom_mem(self, addr: int, memaddr: int, nbytes: int) -> bytes:
101+
def readfrom_mem(self, addr: int, memaddr: int, nbytes: int, addrsize: int = 8) -> bytes:
100102
self.select_channel(self._chn)
101-
result = self._i2c.readfrom_mem(addr, memaddr, nbytes)
103+
result = self._i2c.readfrom_mem(addr, memaddr, nbytes, addrsize=addrsize)
102104
self.release_channel(self._chn)
103105
return result
104106

105-
def readfrom_mem_into(self, addr: int, memaddr: int, buf: AnyWritableBuf) -> None:
107+
def readfrom_mem_into(
108+
self, addr: int, memaddr: int, buf: AnyWritableBuf, addrsize: int = 8
109+
) -> None:
106110
self.select_channel(self._chn)
107-
self._i2c.readfrom_mem_into(addr, memaddr, buf)
111+
self._i2c.readfrom_mem_into(addr, memaddr, buf, addrsize=addrsize)
108112
self.release_channel(self._chn)
109113

110-
def writeto_mem(self, addr: int, memaddr: int, buf: AnyReadableBuf) -> None:
114+
def writeto_mem(self, addr: int, memaddr: int, buf: AnyReadableBuf, addrsize: int = 8) -> None:
111115
self.select_channel(self._chn)
112-
self._i2c.writeto_mem(addr, memaddr, buf)
116+
self._i2c.writeto_mem(addr, memaddr, buf, addrsize=addrsize)
113117
self.release_channel(self._chn)

0 commit comments

Comments
 (0)