Skip to content

Commit 8c1abbd

Browse files
committed
Improve HM01B0 PIO sync
Have to disable DMA to reset write address Also, restarting PIO SM doesn't clear RX buffer, have to read out manually Still not perfect. Start of frame seems consistently good, but DMA seems to loose sync or something part way through with a lot of frames
1 parent 79fd3a1 commit 8c1abbd

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/camera/hm01b0_pio.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ def __init__(
200200
self.sm_id = sm_id
201201
self.i2c_address = i2c_address
202202
self.buffer = np.zeros((244, 324), dtype=np.uint8)
203-
# self.buffer = bytearray(244 * 324)
204203

205204
Pin(pin_d0, Pin.IN)
206205
Pin(pin_vsync, Pin.IN)
@@ -286,7 +285,6 @@ def start_pio_dma(self):
286285
)
287286
self.dma.config(
288287
read = self.sm,
289-
write = self.buffer,
290288
count = 244 * 324,
291289
ctrl = dma_ctrl
292290
)
@@ -297,10 +295,18 @@ def start_pio_dma(self):
297295
)
298296

299297
def _vsync_handler(self):
300-
self.sm.restart()
298+
# Disable DMA before reconfiguring it
299+
self.dma.active(False)
300+
301+
# Ensure PIO RX FIFO is empty
302+
while self.sm.rx_fifo() > 0:
303+
self.sm.get()
304+
305+
# Reset the DMA write address
301306
self.dma.write = self.buffer
307+
308+
# Start the DMA
302309
self.dma.active(True)
303-
# print("new frame:", time.ticks_ms())
304310

305311
@rp2.asm_pio(
306312
in_shiftdir = rp2.PIO.SHIFT_LEFT,

0 commit comments

Comments
 (0)