Skip to content

rewrite(phase3): port adc/gpio from c-RCP, fix a critical ADC averaging regression - #137

Merged
SoundMatt merged 1 commit into
rewrite/v3-from-c-rcpfrom
phase3/adc-gpio
Aug 21, 2026
Merged

SoundMatt merged 1 commit into
rewrite/v3-from-c-rcpfrom
phase3/adc-gpio

Conversation

@SoundMatt

Copy link
Copy Markdown
Owner

Part of the v3.0.0 ground-up rewrite (#129, ROADMAP.md Phase 17). Third of Phase 3's Wave 1 batches, alongside iseled/i2c and can/lin (separate PRs).

adc.hpp (55 requirements) — was substantially wrong, not just incomplete

Critical bug: the pre-rewrite pilot-era code averaged adc_combine_avg_values interval-means down to one output value. c-RCP's own file header records this exact mistake was already made and fixed once in c-RCP's own history — adc_combine_avg_values is a packing count, not a second reduction; a response carries N values, never one. Fixed against c-RCP's current ep_adc.c 1:1. Also a field-naming bug (a config field was doing double duty for two distinct layer-1/layer-2 meanings). Missing entirely, now ported: wall-clock sample-spacing validation, cadence classification, Table 53 threshold triggers, the full EP_func register block + apply_reconfig (closing an evt[2:0]=111b gap the old header just stubbed out), real ACF-level wire codec.

gpio.hpp (46 requirements) — core was correct, extended

Bug found and fixed: apply_gpio_write's Subtract semantics computed the operands in the wrong order — c-RCP defines the row normatively as request-minus-current, not current-minus-request. Fixed locally in gpio.hpp (not in the shared endpoint.hpp helper, to avoid silently changing pwm.hpp's semantics before that module gets its own Phase 3 pass). Missing entirely, now ported: Table 43 trigger-signal numbering, per-pin debounce filtering, response-timing classification, the full EP_func register block + apply_reconfig.

test_adc.cpp: 18→62 cases. test_gpio.cpp: 20→62 cases.

Call sites touched

mock.hpp's dispatch_adc() rewritten against the new API, now routes reconfig through the real apply_reconfig instead of rejecting it; 2 test_mock.cpp cases updated to match.

Verified

Full tree rebuilds clean (223/223 targets), 56/56 ctest suites pass (100%) — independently re-verified from a fresh build.

Tracked at #129 — completes Phase 3 Wave 1.

…ng regression

Part of the v3.0.0 ground-up rewrite (cpp-RCP #129, ROADMAP.md Phase 17),
branch rewrite/v3-from-c-rcp. Third of Phase 3's Wave 1 batches,
alongside iseled/i2c and can/lin (separate PRs).

adc.hpp (55 requirements) was substantially wrong, not just incomplete:

- Critical bug: the pre-rewrite pilot-era AdcEndpoint::request_reading
  averaged adc_combine_avg_values interval-means down to *one* output
  value. c-RCP's own file header records this exact mistake was already
  made and fixed once in c-RCP's history -- adc_combine_avg_values is a
  packing count, not a second reduction; a response carries N values,
  never one (Sec13.7.9.2/.3). Fixed: average_interval/
  collect_response_values now port rcp_ep_adc_average_interval()/
  rcp_ep_adc_collect_response_values() 1:1; AdcEndpoint redesigned
  around execute_measurement_cycle()/response_ready()/
  collect_response().
- Field-naming bug: AdcAveragingConfig::adc_avg_intervals_per_request
  was actually being used for a layer-1 samples-per-interval count --
  c-RCP's adc_samples_per_avg_interval's role, not layer 2's meaning.
- Missing entirely, now ported: wall-clock inter-sample spacing
  validation (REQ-ADC-033), cadence classification (REQ-ADC-037/053),
  Table 53 threshold/measurement-finished triggers (REQ-ADC-031/
  048-052), the full EP_func register block + apply_reconfig
  (REQ-ADC-035/036/038-040, closing the evt[2:0]=111b gap the old
  header stubbed as config_write_not_supported), lifecycle-authorized
  functional-config setters, real ACF-level read-request/response/
  reconfig wire codec.

gpio.hpp (46 requirements) core was already correct; extended:

- Bug found and fixed: apply_gpio_write's Subtract semantics computed
  current-operand; c-RCP's rcp_ep_gpio_apply_write() (REQ-GPIO-011)
  defines the row normatively as request minus current. Fixed locally
  in gpio.hpp, not in the shared endpoint.hpp helper, to avoid silently
  changing pwm.hpp's PWM_OUT semantics (out of this phase's scope, not
  yet re-verified).
- Missing entirely, now ported: Table 43 wire trigger-signal numbering
  (REQ-GPIO-034), per-pin debounce filtering (REQ-GPIO-035/044),
  response-timing classification (REQ-GPIO-036), reserved evt[2:0]=
  100b wire rejection (REQ-GPIO-012/045/046), the full EP_func register
  block + apply_reconfig (REQ-GPIO-013/038-042, with c-RCP's own
  resolved gpio_debounce_IO31 editorial-defect offset at 0x0028),
  functional-config setters, real ACF-level wire codec.
- rcp_ep_gpio_toggle_pin_direction() (no longer a real TC18 mechanism
  per c-RCP's own comment) deliberately not ported -- low-value,
  non-wire caller convenience.

Fixed-capacity: AdcEndpoint's pending-averaged-value accumulator is a
std::array<AdcAvgValue, 255>-backed BoundedVector (255 = Table 54's own
8-bit adc_combine_avg_values register width). GPIO's existing
std::array<uint8_t, kMaxPins> pattern extended to
GpioFunctionalConfig::pins/debounce.

test_adc.cpp: 18 -> 62 TEST_CASEs. test_gpio.cpp: 20 -> 62 TEST_CASEs.

Call sites touched: mock.hpp's dispatch_adc() rewritten against the new
AdcEndpoint API and to route evt[2:0]=111b through the now-real
adc::apply_reconfig instead of rejecting it; wire_error_code_for()
updated (removed config_write_not_supported, added reconfig_short/
reconfig_out_of_range mappings). tests/test_mock.cpp: two ADC
config-write tests updated for the now-real reconfig behavior.

Left as // TODO(phase3-followup): rcp_ep_gpio_toggle_pin_direction()
not ported (noted in gpio.hpp's header, no stub added). Full
dispatch-level wiring (response-shape composition, RxSequenceGuard,
fragmentation) for both endpoints' new EP_func/reconfig paths remains
mock.hpp's own Phase 4 scope -- this pass's minimal dispatch_adc
wiring is enough to exercise apply_reconfig and keep the tree green,
not a full Phase 4 implementation.

Verified: full tree rebuilds clean (223/223 targets), 56/56 ctest
suites pass (100%) -- independently re-verified from a fresh build, not
just the porting agent's own report.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Matt <47545907+SoundMatt@users.noreply.github.com>
@SoundMatt
SoundMatt merged commit 7c24c41 into rewrite/v3-from-c-rcp Aug 21, 2026
22 checks passed
@SoundMatt
SoundMatt deleted the phase3/adc-gpio branch August 21, 2026 20:45
SoundMatt added a commit that referenced this pull request Aug 21, 2026
… operand order

Part of the v3.0.0 ground-up rewrite (cpp-RCP #129, ROADMAP.md Phase 17),
branch rewrite/v3-from-c-rcp. Third of Phase 3 Wave 2's three batches,
alongside mdio and spi/uart (separate PRs).

## pwm.hpp

- Fixed the same operand-order bug class found and fixed in gpio.hpp
  during PR #137: PWM_OUT's Subtract conditional-request handling used
  current - operand instead of c-RCP's normative request - current.
  This is deliberately fixed per-endpoint (not centralized into
  endpoint.hpp), matching the same caution documented in #137 that this
  bug needed independent re-verification at every endpoint using
  Subtract semantics, not an assumption that one fix covers all of
  them -- confirmed here to be a real, independent instance of the same
  class, not a duplicate report.
- Ported against c-RCP's current RC5-conformant ep_pwm.h/.c.

## wakeup.hpp

- Prior cpp-RCP wakeup.hpp content was a wholesale invention with no
  real relationship to c-RCP's actual ep_wakeup.h/.c -- re-derived from
  scratch against c-RCP's current implementation.
- REQ-WAKEUP-020/026's regmap.c-scoped behavior intentionally NOT
  ported here (out of scope for the endpoint module itself; deferred to
  Phase 4's regmap port, noted in-file).

## Call sites

None touched -- mock.hpp and powerstate.hpp (and their tests) confirmed
compatible with the new pwm.hpp/wakeup.hpp APIs without modification.

## Verification

Full tree rebuilds clean (223/223 targets), 56/56 ctest suites pass
(100%) -- independently re-verified from a fresh build in the worktree,
not just the porting agent's own report.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Matt <47545907+SoundMatt@users.noreply.github.com>
SoundMatt added a commit that referenced this pull request Aug 21, 2026
… operand order (#140)

Part of the v3.0.0 ground-up rewrite (cpp-RCP #129, ROADMAP.md Phase 17),
branch rewrite/v3-from-c-rcp. Third of Phase 3 Wave 2's three batches,
alongside mdio and spi/uart (separate PRs).

## pwm.hpp

- Fixed the same operand-order bug class found and fixed in gpio.hpp
  during PR #137: PWM_OUT's Subtract conditional-request handling used
  current - operand instead of c-RCP's normative request - current.
  This is deliberately fixed per-endpoint (not centralized into
  endpoint.hpp), matching the same caution documented in #137 that this
  bug needed independent re-verification at every endpoint using
  Subtract semantics, not an assumption that one fix covers all of
  them -- confirmed here to be a real, independent instance of the same
  class, not a duplicate report.
- Ported against c-RCP's current RC5-conformant ep_pwm.h/.c.

## wakeup.hpp

- Prior cpp-RCP wakeup.hpp content was a wholesale invention with no
  real relationship to c-RCP's actual ep_wakeup.h/.c -- re-derived from
  scratch against c-RCP's current implementation.
- REQ-WAKEUP-020/026's regmap.c-scoped behavior intentionally NOT
  ported here (out of scope for the endpoint module itself; deferred to
  Phase 4's regmap port, noted in-file).

## Call sites

None touched -- mock.hpp and powerstate.hpp (and their tests) confirmed
compatible with the new pwm.hpp/wakeup.hpp APIs without modification.

## Verification

Full tree rebuilds clean (223/223 targets), 56/56 ctest suites pass
(100%) -- independently re-verified from a fresh build in the worktree,
not just the porting agent's own report.

Signed-off-by: Matt <47545907+SoundMatt@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
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.

1 participant