Skip to content

Passing the sensor to FHAdv_Isp_SensorInit and calling it before FHAdv_Isp_Init - #105

Merged
wberube merged 1 commit into
OpenIPC:masterfrom
erkin-io:fix/fhan-advapi-sensor-init
Nov 21, 2026
Merged

wberube merged 1 commit into
OpenIPC:masterfrom
erkin-io:fix/fhan-advapi-sensor-init

Conversation

@erkin-io

Copy link
Copy Markdown
Contributor

What was wrong

On Fullhan V200, every start prints Error: sensor if is NULL, check if FHAdv_Isp_SensorInit was called from the vendor's libadvapi_isp.so. FHAdv_Isp_Init() then returns early, so the advapi ISP layer never reads the sensor's exposure defaults.

Why

FHAdv_Isp_SensorInit() takes the sensor's struct isp_sensor_if * and stores it for the rest of the library. FHAdv_Isp_Init() reads the ISP's current contrast, saturation and sharpness settings, then the sensor's AE defaults through that stored pointer. It stops with the message above if the pointer is not there.

src/hal/fhan/f2_isp.h declares fnAdvSensorInit as int (*)(void), and f2_pipeline_create() calls FHAdv_Isp_Init() first and FHAdv_Isp_SensorInit() second, without an argument. So Init always finds no sensor. SensorInit then receives whatever is in the first argument register.

What this changes

  • f2_isp.h: fnAdvSensorInit takes f2_isp_snrops *, the sensor table Divinus already passes to API_ISP_SensorRegCb().
  • f2_pipeline_create(): fnAdvSensorInit(f2_snr.ops) first, then fnAdvInit(). The unused result variables go.

How it was checked

  • Built with ./build.sh fhan-v2, no new warnings. ./test.sh -a passes.
  • On a Ruision F8 board (FH8856V200, GC4653), inside our firmware: the message is gone, and the picture and the day/night (colour/grey) switching are unchanged.
  • The order and the argument follow the library's disassembly. FHAdv_Isp_Init() only reads settings; it writes nothing to the ISP.

Effect on other platforms

Fullhan V200 only (fhan-v2). Upstream does not call any other advapi ISP function today, so the visible effect is the missing error message. Any later use of the advapi ISP functions (brightness, contrast, AE mode and so on) needs Init to have completed, which it does now.

🤖 Generated with Claude Code

…v_Isp_Init

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Initialize Fullhan V200 advapi with the sensor callback table

🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Pass the V200 sensor callback table to advapi sensor initialization, correcting its function
 signature.
• Initialize the sensor before advapi ISP initialization so it can read exposure defaults.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed advapi calls occur on the single F2 pipeline-creation path that is called by media startup.
  • Sensor setup, ISP initialization, and subsequent video output are one bounded camera integration behavior rather than separate capabilities; no independent functional scope is established by the dynamic-library boundary.
Sources

src/hal/fhan/f2_hal.c[364-371]

    /* advapi: hand it the sensor table first (FHAdv_Isp_SensorInit takes the
     * struct isp_sensor_if *), then FHAdv_Isp_Init, which reads the sensor's AE
     * defaults through it. Called the other way round and without the argument,
     * Init printed "sensor if is NULL" at every start and stopped early. */
    if (f2_isp.fnAdvSensorInit)
        f2_isp.fnAdvSensorInit(f2_snr.ops);
    if (f2_isp.fnAdvInit)
        f2_isp.fnAdvInit();
Behavioral complexity 🟡 Medium 🧩 Compatibility cases, Interacting branches

  • Before: FHAdv_Isp_SensorInit was loaded and called as a no-argument function after FHAdv_Isp_Init; the sensor table was not supplied to that advapi call.
  • After: the function pointer and dynamic-load cast require a sensor-table argument, and the call precedes FHAdv_Isp_Init.
  • New correctness condition: the deployed advapi ABI must accept the f2_snr.ops table, and FHAdv_Isp_SensorInit must complete before FHAdv_Isp_Init reads sensor-dependent AE defaults.
  • These are materially new compatibility and ordering conditions across the application and vendor-library boundary.
  • The later ISP registration still uses the same sensor table, so routine reuse of that existing mapping is not itself treated as additional complexity.
Sources

src/hal/fhan/f2_hal.c[364-371]

    /* advapi: hand it the sensor table first (FHAdv_Isp_SensorInit takes the
     * struct isp_sensor_if *), then FHAdv_Isp_Init, which reads the sensor's AE
     * defaults through it. Called the other way round and without the argument,
     * Init printed "sensor if is NULL" at every start and stopped early. */
    if (f2_isp.fnAdvSensorInit)
        f2_isp.fnAdvSensorInit(f2_snr.ops);
    if (f2_isp.fnAdvInit)
        f2_isp.fnAdvInit();

src/hal/fhan/f2_isp.h[110-111]

    int (*fnAdvInit)(void);
    int (*fnAdvSensorInit)(f2_isp_snrops *ops);   /* FHAdv_Isp_SensorInit(struct isp_sensor_if *) */
Potential damage 🟡 Medium 🩹 Temporary loss

  • The plausible concrete consequence is loss of the F2 camera/video capability during startup.
  • The media layer directly invokes f2_pipeline_create, and the remaining pipeline setup follows the changed calls.
  • Recovery is expected to require restarting the service or device with a compatible vendor library and corrected initialization state; reverting the code restores the prior call contract but does not repair an already-running process that has crashed.
  • No persistent application data or external financial/security effect is introduced by this change.
  • Recoverable by process/device restart and use of a compatible libadvapi_isp.so.
  • A code rollback can restore the prior ABI/order, but no automatic state-repair or external compensation mechanism is shown.
Sources

src/hal/fhan/f2_hal.c[364-371]

    /* advapi: hand it the sensor table first (FHAdv_Isp_SensorInit takes the
     * struct isp_sensor_if *), then FHAdv_Isp_Init, which reads the sensor's AE
     * defaults through it. Called the other way round and without the argument,
     * Init printed "sensor if is NULL" at every start and stopped early. */
    if (f2_isp.fnAdvSensorInit)
        f2_isp.fnAdvSensorInit(f2_snr.ops);
    if (f2_isp.fnAdvInit)
        f2_isp.fnAdvInit();
Assessed commit 4f164f7
Diagram

graph TD
  S["Sensor library"] --> T["Sensor callbacks"] --> SI["Adv sensor init"] --> AI["Adv ISP init"] --> P["ISP startup"]
Loading
High-Level Assessment

Using the callback table already supplied to API_ISP_SensorRegCb is the direct fix for the vendor API's required argument. Passing it before advapi initialization addresses the reported early exit without adding an adapter or changing other platforms.

Files changed (2) +10 / -8

Bug fix (2) +10 / -8
f2_hal.cPass sensor callbacks before initializing advapi ISP +8/-6

Pass sensor callbacks before initializing advapi ISP

• Reorders V200 advapi startup to call sensor initialization with f2_snr.ops before ISP initialization. Removes unused variables that previously captured the two call results.

src/hal/fhan/f2_hal.c

f2_isp.hCorrect the advapi sensor initialization signature +2/-2

Correct the advapi sensor initialization signature

• Changes the function pointer and dynamically loaded symbol cast to accept a pointer to f2_isp_snrops, matching the sensor table passed by the pipeline.

src/hal/fhan/f2_isp.h

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can add REVIEW.md to your repo root and Qodo follows it on every PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@wberube
wberube merged commit c516fdc into OpenIPC:master Nov 21, 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