rg_input: use the unit parameter instead of RG_BATTERY_ADC_UNIT in the legacy ADC path#342
Open
koalaauto wants to merge 1 commit into
Open
rg_input: use the unit parameter instead of RG_BATTERY_ADC_UNIT in the legacy ADC path#342koalaauto wants to merge 1 commit into
unit parameter instead of RG_BATTERY_ADC_UNIT in the legacy ADC path#342koalaauto wants to merge 1 commit into
Conversation
_adc_setup_channel() takes an `adc_unit_t unit` parameter, but its legacy branch
tested the battery macro RG_BATTERY_ADC_UNIT instead. Any target that does not
define RG_BATTERY_ADC_UNIT therefore fails to compile:
rg_input.c:71:9: error: 'RG_BATTERY_ADC_UNIT' undeclared (first use in this
function); did you mean 'RG_BATTERY_CALC_VOLTAGE'?
Two things make this bite: USE_ADC_DRIVER_NG is commented out at the top of the
file, so the #else branch is the one actually compiled; and the function is
`static inline`, so its body is compiled even when nothing calls it.
The intent is clearly the parameter -- the RG_ASSERT above validates `unit`, and
the RG_LOGE just below already prints (int)unit. For targets that do define
RG_BATTERY_ADC_UNIT this is a no-op, since that is exactly what was passed in.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
_adc_setup_channel()takes anadc_unit_t unitparameter, but its legacy branch tests the battery macroRG_BATTERY_ADC_UNITinstead of that parameter. As a result any target that does not defineRG_BATTERY_ADC_UNITfails to compile.Details
components/retro-go/rg_input.c:Two things make this bite:
USE_ADC_DRIVER_NGis commented out at the top of the file (// #define USE_ADC_DRIVER_NG), so the#elsebranch is the one actually compiled.static inline, so its body is compiled even when nothing calls it.Consequently a target with, say,
RG_GAMEPAD_ADC_MAPbut no battery ADC — or simply noRG_BATTERY_*defines at all — dies with:The intent is clearly to use the parameter: the very next
RG_LOGE()already prints(int)unit, and theRG_ASSERTat the top validatesunit.Fix
Use
unitin the legacy branch, matching theUSE_ADC_DRIVER_NGbranch and the assert/log around it.Testing
Found while porting a new 160x128 ESP32 target that has no battery ADC. Before the change it would not compile on
dev; after it builds and runs (ESP-IDF v5.5.2, release build) with both the gamepad and battery paths behaving as before on targets that do defineRG_BATTERY_ADC_UNIT(for those,unitis exactly what was being passed in anyway).