Skip to content

fix: sensor image flip and mirror orientation#82

Closed
henkwiedig wants to merge 2 commits into
OpenIPC:masterfrom
henkwiedig:flip-mirror
Closed

fix: sensor image flip and mirror orientation#82
henkwiedig wants to merge 2 commits into
OpenIPC:masterfrom
henkwiedig:flip-mirror

Conversation

@henkwiedig

Copy link
Copy Markdown

Fixes image.flip and image.mirror config options on star6e (Infinity6E) and maruko (SSC338Q/Infinity6C) platforms. Previously, orientation either had no effect or reverted to the default within ~1 second of stream start.
This is 100% vibe coded, i have no idea what i am doing here.

Root cause

Two separate bugs:

  1. VPE digital flip (MI_VPE_SetChannelParam with flip=1) caused a delayed/broken stream start on the IMX415 and possibly other sensors. It has been disabled; MI_SNR_SetOrien (sensor-level) is the only path now.

  2. ISP AE first-tick resets sensor timing registers at ~1s after stream start, and on the IMX415 this incidentally clears the sensor's orientation bits. The reset is triggered asynchronously by MI_ISP_CUS3A_Enable({0,0,0}) in the CUS3A handoff, so a single re-apply immediately after the handoff does not stick.

Fix

Multi-layer re-apply targeting every point where sensor registers can be clobbered:

  • Before MI_SNR_Enable in sensor_select.c — correct ordering matching the reference majestic streamer (SetRes→SetFps→SetOrien→Enable)
  • After VPE init in start_vpe / maruko_start_vpe
  • After ISP channel init (wait_isp_channel) and after ISP bin load in bind_and_finalize_pipeline
  • After the CUS3A handoff in cus3a_tick
  • After any MI_SNR_SetFps call (legacy_ae branch, live ISP bin reload, CUS3A fps_kick cold-boot fix) — SetFps resets sensor timing registers as a side effect
  • Frame loop (star6e_runtime.c, maruko_pipeline.c): re-apply at frames 1, fps, 2×fps…5×fps — catches the async AE first-tick reset regardless of when it fires

Changes

File Change
include/sensor_select.h Add image_mirror/image_flip to SensorSelectConfig
include/star6e_cus3a.h Add mirror/flip to Star6eCus3aConfig
include/maruko_config.h Add image_mirror/image_flip to MarukoBackendConfig
src/sensor_select.c Call MI_SNR_SetOrien before MI_SNR_Enable
src/star6e_pipeline.c Disable VPE digital flip; store orientation in globals; re-apply at all ISP init milestones
src/star6e_cus3a.c Load MI_SNR_SetOrien via dlsym; re-apply after fps_kick
src/star6e_runtime.c Propagate mirror/flip to CUS3A config; frame-loop re-apply
src/maruko_config.c Copy mirror/flip from vcfg
src/maruko_pipeline.c Full parity with star6e: SetOrien in start_vpe, after fps kicks, frame-loop

Tested on star6e with IMX415. Maruko changes follow the same pattern; no maruko hardware available for direct test.

@snokvist

Copy link
Copy Markdown
Collaborator

Hello,

You need to test the code on maruko as well if your fixes include it. Otherwise exclude maruko and document as follow-up.
IMX335 has a bug/feature afaik which doesnt allow flip to be done, been meaning to soft disable flip there, but also needs tests/confirmation before merge.

@snokvist

snokvist commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

PR #84 will merge this functionality, check it out!

@snokvist snokvist closed this Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants