Emit AE/AGC callback skeleton + document ipctool sensor monitor#147
Merged
Emit AE/AGC callback skeleton + document ipctool sensor monitor#147
Conversation
Two changes that share a theme: making the AE/AGC layer of an extracted sensor driver navigable. The first (write-side) finishes a deferred item from #145; the second (read-side) documents an existing-but-undocumented ipctool feature. Write-side: trace_to_driver.py now emits a third function `<sensor>_ae_step` that writes each runtime hot register (top 8, above 25% of the max count) with its last-seen trace value, in trace order, each tagged `/* TODO: derive */`. Header documents that the values are placeholders and points at the vendor's cmos_inttime_update / cmos_gains_update equivalents for the math. Cross-checked against widgetii/smart_sc2315e on the SC2315E + Majestic capture from #145: skeleton emits exactly 0x3314, 0x5781, 0x5785 with values 0x14, 0x60, 0x30 - matching the else-branches of the reference's two AE callbacks. The trace was captured under steady ambient light, so only the low-gain / short-inttime branch values appear. Read-side: `ipctool sensor monitor` already supported SC2315E (added some time ago); the feature was never documented anywhere. It reads the same hot register set in a loop while the sensor runs, giving you value time-series under varying lighting - the natural complement to the static trace-extraction. New "Stage 4 - Live-reading the AE state" section in docs/sensor-driver-extraction.md walks through pairing the two: extract `_ae_step` for the register set, then `monitor` while varying lighting to capture the value distribution that derives the threshold conditionals. Renamed sc2315e's R3812 to HOLD (it is the group-hold trigger from cmos_gains_update) so the live-read output is self-explanatory. test_pipeline.sh asserts the new function is emitted and the file still passes gcc -Wall -Wextra. Docs updated to describe the third function and the inherent limitation (math not in trace). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
f6a5f52 to
0611528
Compare
This was referenced May 3, 2026
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.
Follow-up to #145 / #146. Two changes that share a theme: making the AE/AGC layer of an extracted sensor driver navigable.
Write-side: AE/AGC callback skeleton
trace_to_driver.pynow emits a third function<sensor>_ae_stepcontaining the per-frame AE/AGC writes captured during the runtime phase, tagged/* TODO: derive */. The original plan in #145 promised this; #145 shipped only a comment block.For SC2315E + Majestic from #145:
The reference's
cmos_gains_updatewrites0x5781=96 (0x60),0x5785=48 (0x30)in its else-branch andcmos_inttime_updatewrites0x3314=20 (0x14)in its low-inttime branch — the skeleton captures the right registers and the values that the running AE loop wrote during steady-state ambient light. A varying-light capture would surface the if-branches too.Selection heuristic: top 8 by frequency, each ≥25% of the max count. Conservative on noisy traces; permissive on clean ones.
Read-side: document
ipctool sensor monitoripctool sensor monitoris an existing feature: poll a fixed list of AE/exposure registers from the running sensor over I2C/SPI in a loop, decoded as labelled fields. SC2315E was already wired up but the feature itself was never documented.Same idea as
_ae_step, but read-side. The two pair naturally:_ae_stepviatrace→ register setsensor monitorwhile varying lighting (cover lens, switch IR cut) → value time-seriesThe new "Stage 4 — Live-reading the AE state" section in
docs/sensor-driver-extraction.mdwalks through this pairing and includes the recipe for adding a new sensor's reg list tosrc/snstool.c.Also renamed
R3812→HOLDin the sc2315e reg table — that register is the group-hold trigger fromcmos_gains_updateand self-documents the live output.Test plan
tools/test_pipeline.shextended to assert the new_ae_stepfunction is emitted; passesgcc -Wall -Wextra -fsyntax-onlyon real captured + generated scaffold passestest-extraction-pipelinejob catches regressions in segmenter / generatorwidgetii/smart_sc2315e/sc2315e_cmos.cconfirms register selectionipctool-upx sensor monitorruns on the SC2315E camera; output shows the renamedHOLDfield correctly🤖 Generated with Claude Code