Open
Conversation
Member
|
Please take a look at this comment: openmv/openmv#2970 (comment) |
552a20f to
55bd352
Compare
55bd352 to
e710072
Compare
kwagyeman
reviewed
Feb 16, 2026
Comment on lines
+31
to
+73
| # Prime DMA system before reading raw events. | ||
| # Prime on first size or poll request. | ||
| primed = False | ||
|
|
||
| # Only grab next frame when current FIFO buffer has been fully streamed. | ||
| frame_available = False | ||
|
|
||
| class EventChannel: | ||
| def size(self): | ||
| global primed | ||
| if not primed: | ||
| primed = True | ||
|
|
||
| return event_length | ||
|
|
||
| def shape(self): | ||
| return (event_length, 1) | ||
|
|
||
| def read(self, offset, size): | ||
| global frame_available | ||
|
|
||
| if frame_available: | ||
| end = offset + size | ||
| mv = events_mv[offset:end] | ||
| if end == event_length: | ||
| frame_available = False | ||
| return mv | ||
| return bytes(size) | ||
|
|
||
| def poll(self): | ||
| global primed | ||
| if not primed: | ||
| primed = True | ||
|
|
||
| return frame_available | ||
|
|
||
|
|
||
| protocol.register(name='events', backend=EventChannel()) | ||
|
|
||
| while True: | ||
| if not frame_available and primed: | ||
| csi0.ioctl(csi.IOCTL_GENX320_READ_EVENTS_RAW) | ||
| frame_available = True No newline at end of file |
Member
There was a problem hiding this comment.
Suggested change
| # Prime DMA system before reading raw events. | |
| # Prime on first size or poll request. | |
| primed = False | |
| # Only grab next frame when current FIFO buffer has been fully streamed. | |
| frame_available = False | |
| class EventChannel: | |
| def size(self): | |
| global primed | |
| if not primed: | |
| primed = True | |
| return event_length | |
| def shape(self): | |
| return (event_length, 1) | |
| def read(self, offset, size): | |
| global frame_available | |
| if frame_available: | |
| end = offset + size | |
| mv = events_mv[offset:end] | |
| if end == event_length: | |
| frame_available = False | |
| return mv | |
| return bytes(size) | |
| def poll(self): | |
| global primed | |
| if not primed: | |
| primed = True | |
| return frame_available | |
| protocol.register(name='events', backend=EventChannel()) | |
| while True: | |
| if not frame_available and primed: | |
| csi0.ioctl(csi.IOCTL_GENX320_READ_EVENTS_RAW) | |
| frame_available = True | |
| # Only grab next frame when current FIFO buffer has been fully streamed. | |
| frame_available = True | |
| class EventChannel: | |
| def size(self): | |
| return len(events_mv) | |
| def shape(self): | |
| return (len(events_mv), 1) | |
| def read(self, offset, size): | |
| global frame_available | |
| if frame_available: | |
| end = offset + size | |
| mv = events_mv[offset:end] | |
| if end == len(events_mv): | |
| frame_available = False | |
| return mv | |
| return bytes(size) | |
| def poll(self): | |
| return frame_available | |
| protocol.register(name='events', backend=EventChannel()) | |
| while True: | |
| if not frame_available: | |
| events = csi0.ioctl(csi.IOCTL_GENX320_READ_EVENTS_RAW) | |
| events_mv = memoryview(events.bytearray()) | |
| frame_available = True |
Member
There was a problem hiding this comment.
Since you have the fifo enabled, you have to treat each events object returned as a new image which you have to get the byte array to.
What's happening above is that the frames accumulate in the fifo onboard. When a USB access happens it's going to suck out whatever the latest frame is, unlock the main loop to pop another off the head of the fifo, and then lock it again for USB to suck out another frame.
As long as the rate at which frames are removed from the fifo is faster than the fifo filling up, then you shouldn't drop any data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds MicroPython scripts for streaming raw 32-bit words from the GENX320 to the user's PC.