Repository navigation
chore: use settings from radio JSON files instead of hal.h - #7411
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds JSON schema/models and Jinja template to generate hal_settings.h from board JSON. Refactors CMake to centralize generation and dependencies. Migrates numerous board JSONs to new lcd/backlight/leds/timers schema. Updates companion parsing, headers, IRQ macro names, drivers, Lua/YAML/Simu wiring, and GUI gating. ChangesHardware definition generation and integration
Sequence Diagram(s)sequenceDiagram
autonumber
participant Dev as Developer/CMake
participant Schema as hwdef_schema.json
participant Gen as generator.py
participant Tmpl as hal_settings.jinja
participant Build as CMake Targets
participant Code as Firmware/Headers
Dev->>Schema: Validate board JSON
Dev->>Build: Configure AddHWGenTarget(${FLAVOUR}.json → hal_settings.h)
Build->>Gen: Run generator with validated JSON
Gen->>Tmpl: Render with display/leds/backlight/timers
Tmpl-->>Build: hal_settings.h generated
Build->>Build: add_dependencies(... hal_settings)
Build->>Code: Compile with new macros/IRQ names
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 9
🧹 Nitpick comments (1)
radio/util/hw_defs/hal_settings.jinja (1)
10-45: 🏗️ Heavy liftBoolean HAL feature macros expand to
True/False, but current usage isdefined(...)-gated
hal_settings.jinjaemits#define OLED_SCREEN True/False-style values for boolean HAL fields, and the current codebase referencesOLED_SCREEN,HAS_BACKLIGHT_COLOR,STATUS_LEDS,LCD_HORIZONTAL_INVERT, andLCD_VERTICAL_INVERTvia#if defined(...)/#if !defined(...)(so theTrue/Falsenumeric-expression risk doesn’t show up in current consumers).
For extra robustness/future-proofing, consider switching to value-less#definefortrue(skipfalse) or emit1/0instead of PythonTrue/False.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@radio/util/hw_defs/hal_settings.jinja` around lines 10 - 45, The template currently emits Python True/False text for boolean HAL fields which can break consumers using `#if` defined(...) checks; update the hal_settings.jinja generation so booleans are robust: either (preferred) emit value-less defines only when true (e.g., if val is True then output "`#define` OLED_SCREEN" and skip when False) or consistently emit "1"/"0" integers (e.g., "`#define` OLED_SCREEN 1" or "0"); apply this change to the boolean symbols referenced in the codebase such as OLED_SCREEN, HAS_BACKLIGHT_COLOR, STATUS_LEDS, LCD_HORIZONTAL_INVERT, and LCD_VERTICAL_INVERT by testing val's truthiness and emitting the appropriate form.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@companion/src/firmwares/boardjson.cpp`:
- Around line 1229-1235: The loader currently populates display fields but omits
the new lcd_vertical_invert flag; add parsing for
o.value("lcd_vertical_invert").toBool() and assign it to the display struct
(e.g. set display.vertical_invert or display.lcd_vertical_invert depending on
the existing field name in the Display struct) alongside the other assignments
(display.w, display.h, display.phys_w, display.phys_h, display.depth,
display.color, display.oled) so the companion stays in sync with the migrated
board schema.
- Around line 1247-1250: The assignment to cfs_led_strip_length is wrong: it's
storing a boolean (toInt() > 0) instead of the actual length, causing cfs.groups
to be computed as 0; change the line that defines cfs_led_strip_length to
capture the integer length (int cfs_led_strip_length =
o.value("cfs_led_strip_length").toInt();) and keep the existing logic that
computes cfs.groups using cfs_led_strip_length and cfs_leds_per_switch, ensuring
cfs.rgb_led is set from cfs.groups as before.
In `@radio/src/boards/hw_defs/pa01.json`:
- Line 306: The led_strip_gpio value uses an octal-style integer literal; change
the pin argument in the JSON from "GPIO_PIN(GPIOF, 06)" to use a decimal literal
(e.g., "GPIO_PIN(GPIOF, 6)") so GPIO_PIN/ GPIOF evaluation is consistent with
other entries and avoids octal parsing issues; update the entry named
led_strip_gpio accordingly.
In `@radio/src/boards/hw_defs/tx15.json`:
- Around line 337-340: The backlight timer is TIM1 so the backlight_timer_freq
must use the APB2 timer domain instead of the APB1 expression; update the value
of backlight_timer_freq (currently "(PERI1_FREQUENCY * TIMER_MULT_APB1)") to use
the APB2 clock symbols (e.g. "PERI2_FREQUENCY * TIMER_MULT_APB2") so TIM1
references the correct APB2 timer frequency.
In `@radio/src/boards/hw_defs/tx16smk3.json`:
- Around line 451-454: The backlight timer TIM1 is an APB2 peripheral but the
JSON uses the APB1 clock expression; update the backlight_timer_freq value to
use the APB2 timer clock expression instead of "(PERI1_FREQUENCY *
TIMER_MULT_APB1)". Replace that string with the equivalent APB2 expression (e.g.
use PERI2_FREQUENCY and TIMER_MULT_APB2) so backlight_timer = "TIM1" has
backlight_timer_freq matching APB2.
In `@radio/src/boards/hw_defs/x9d.json`:
- Around line 353-358: The hardware definition for X9D is missing the
has_int_module_support flag which causes generated settings to omit built-in RF
module support; add "has_int_module_support": true to the "hardware" object in
x9d.json (alongside has_ext_module_support, sport_max_baudrate, cpu, cpu_type)
so the target correctly recognizes internal-module support.
In `@radio/src/boards/hw_defs/x9d`+.json:
- Around line 367-372: The hardware block for X9D+ removed the internal-module
flag which alters generated capabilities; restore the internal module support by
adding "has_int_module_support": true back into the same "hardware" object (next
to "has_ext_module_support") so X9D+ retains its built-in RF/internal module
paths.
In `@radio/src/boards/hw_defs/x9d`+2019.json:
- Around line 361-366: The hardware definition for the X9D+ 2019 JSON removed
the internal module flag; restore the "has_int_module_support" property in the
"hardware" object of x9d+2019.json (add "has_int_module_support": true) so the
generated capabilities include internal RF support for the X9D+ 2019 target.
In `@radio/src/boards/hw_defs/x9e.json`:
- Around line 559-564: The hardware block for X9E omitted the internal-module
flag, which breaks generated capabilities; update the "hardware" object in
x9e.json (where "has_ext_module_support", "sport_max_baudrate", "cpu", and
"cpu_type" are defined) to include "has_int_module_support": true so the target
correctly advertises its built-in RF hardware and internal-module functionality
is preserved.
---
Nitpick comments:
In `@radio/util/hw_defs/hal_settings.jinja`:
- Around line 10-45: The template currently emits Python True/False text for
boolean HAL fields which can break consumers using `#if` defined(...) checks;
update the hal_settings.jinja generation so booleans are robust: either
(preferred) emit value-less defines only when true (e.g., if val is True then
output "`#define` OLED_SCREEN" and skip when False) or consistently emit "1"/"0"
integers (e.g., "`#define` OLED_SCREEN 1" or "0"); apply this change to the
boolean symbols referenced in the codebase such as OLED_SCREEN,
HAS_BACKLIGHT_COLOR, STATUS_LEDS, LCD_HORIZONTAL_INVERT, and LCD_VERTICAL_INVERT
by testing val's truthiness and emitting the appropriate form.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f8c01218-433e-443b-a2e7-e38db07e594c
📒 Files selected for processing (82)
cmake/Macros.cmakecompanion/src/firmwares/boardjson.cppradio/src/CMakeLists.txtradio/src/boards/generic_stm32/CMakeLists.txtradio/src/boards/generic_stm32/rgb_leds.cppradio/src/boards/hw_defs/boxer.jsonradio/src/boards/hw_defs/bumblebee.jsonradio/src/boards/hw_defs/commando8.jsonradio/src/boards/hw_defs/el18.jsonradio/src/boards/hw_defs/f16.jsonradio/src/boards/hw_defs/gx12.jsonradio/src/boards/hw_defs/lr3pro.jsonradio/src/boards/hw_defs/mt12.jsonradio/src/boards/hw_defs/nb4p.jsonradio/src/boards/hw_defs/nv14.jsonradio/src/boards/hw_defs/pa01.jsonradio/src/boards/hw_defs/pl18.jsonradio/src/boards/hw_defs/pl18ev.jsonradio/src/boards/hw_defs/pl18u.jsonradio/src/boards/hw_defs/pocket.jsonradio/src/boards/hw_defs/st16.jsonradio/src/boards/hw_defs/t12.jsonradio/src/boards/hw_defs/t12max.jsonradio/src/boards/hw_defs/t14.jsonradio/src/boards/hw_defs/t15.jsonradio/src/boards/hw_defs/t15pro.jsonradio/src/boards/hw_defs/t16.jsonradio/src/boards/hw_defs/t18.jsonradio/src/boards/hw_defs/t20.jsonradio/src/boards/hw_defs/t20v2.jsonradio/src/boards/hw_defs/t8.jsonradio/src/boards/hw_defs/tlite.jsonradio/src/boards/hw_defs/tpro.jsonradio/src/boards/hw_defs/tpros.jsonradio/src/boards/hw_defs/tprov2.jsonradio/src/boards/hw_defs/tx12.jsonradio/src/boards/hw_defs/tx12mk2.jsonradio/src/boards/hw_defs/tx15.jsonradio/src/boards/hw_defs/tx16s.jsonradio/src/boards/hw_defs/tx16smk3.jsonradio/src/boards/hw_defs/v12.jsonradio/src/boards/hw_defs/v14.jsonradio/src/boards/hw_defs/v16.jsonradio/src/boards/hw_defs/x10.jsonradio/src/boards/hw_defs/x10express.jsonradio/src/boards/hw_defs/x12s.jsonradio/src/boards/hw_defs/x7.jsonradio/src/boards/hw_defs/x7access.jsonradio/src/boards/hw_defs/x9d+.jsonradio/src/boards/hw_defs/x9d+2019.jsonradio/src/boards/hw_defs/x9d.jsonradio/src/boards/hw_defs/x9e.jsonradio/src/boards/hw_defs/x9lite.jsonradio/src/boards/hw_defs/x9lites.jsonradio/src/boards/hw_defs/xlite.jsonradio/src/boards/hw_defs/xlites.jsonradio/src/boards/hw_defs/zorro.jsonradio/src/bootloader/CMakeLists.txtradio/src/gui/212x64/radio_setup.cppradio/src/gui/common/stdlcd/feature_control.hradio/src/hal/CMakeLists.txtradio/src/lua/CMakeLists.txtradio/src/lua/api_general.cppradio/src/storage/yaml/CMakeLists.txtradio/src/targets/common/arm/stm32/CMakeLists.txtradio/src/targets/common/arm/stm32/mixer_scheduler_driver.cppradio/src/targets/common/arm/stm32/timers_driver.cppradio/src/targets/horus/hal.hradio/src/targets/pa01/hal.hradio/src/targets/pl18/CMakeLists.txtradio/src/targets/pl18/hal.hradio/src/targets/simu/CMakeLists.txtradio/src/targets/st16/hal.hradio/src/targets/stm32h7s78-dk/hal.hradio/src/targets/t15pro/hal.hradio/src/targets/taranis/CMakeLists.txtradio/src/targets/taranis/hal.hradio/src/targets/tx15/hal.hradio/src/targets/tx16smk3/hal.hradio/util/hw_defs/generator.pyradio/util/hw_defs/hal_settings.jinjaradio/util/hw_defs/models.py
💤 Files with no reviewable changes (7)
- radio/src/hal/CMakeLists.txt
- radio/src/targets/pl18/CMakeLists.txt
- radio/src/gui/common/stdlcd/feature_control.h
- radio/src/targets/taranis/CMakeLists.txt
- radio/src/lua/CMakeLists.txt
- radio/src/storage/yaml/CMakeLists.txt
- radio/src/bootloader/CMakeLists.txt
3djc
left a comment
There was a problem hiding this comment.
Overall I'm for it. The only drawback is that it starts to make the addition of new radio very complex, since we have no heleprs or validation of those .json. Before I could add it to 2.12, and use the generated json as a reference point, few additions where needed. This starts to make the task very complex
e3f7b78 to
d4fc3ef
Compare
|
Right now in This works today only because every false flag is omitted from the JSON. But all consumers test these with I'd suggest skipping false and rendering true as 1, so the generated header is correct regardless of how the JSON is authored: --- a/radio/util/hw_defs/hal_settings.jinja
+++ b/radio/util/hw_defs/hal_settings.jinja
@@ -8,9 +8,9 @@
// Timers
{% for name, val in timers %}
-{% if val is not none %}
-#define {{ name | upper }} {{ val }}
+{% if val is not none and val is not false %}
+#define {{ name | upper }} {{ 1 if val is true else val }}
{% endif %}
{% endfor %}
{% endif -%}
@@ -18,9 +18,9 @@
// Display
{% for name, val in display %}
-{% if val is not none %}
-#define {{ name | upper }} {{ val }}
+{% if val is not none and val is not false %}
+#define {{ name | upper }} {{ 1 if val is true else val }}
{% endif %}
{% endfor %}
{% endif -%}
@@ -28,9 +28,9 @@
// Backlight
{% for name, val in backlight %}
-{% if val is not none %}
-#define {{ name | upper }} {{ val }}
+{% if val is not none and val is not false %}
+#define {{ name | upper }} {{ 1 if val is true else val }}
{% endif %}
{% endfor %}
{% endif -%}
@@ -38,9 +38,9 @@
// LEDS
{% for name, val in leds %}
-{% if val is not none %}
-#define {{ name | upper }} {{ val }}
+{% if val is not none and val is not false %}
+#define {{ name | upper }} {{ 1 if val is true else val }}
{% endif %}
{% endfor %}
{% endif -%}Result: |
|
Another minor thing: |
There was a problem hiding this comment.
Apart from the 2 nits / potential for hardening (#7411 (comment) and #7411 (comment)) I mentioned earlier, this looks pretty solid to me, thx @philmoz!
d4fc3ef to
3069408
Compare
Silently dropping things could cause other problems in future. Instead I have fixed the output for booleans to be true/false instead of True/False and changed the usage to remove the 'defined' test. #if defined(OLED_SCREEN)
becomes #if OLED_SCREEN
Undefined names are treated as 0 by the preprocessor so this works as expected, and is more readable IMO. |
265f31b to
3abc09a
Compare
Isn't the "normal" convention to use |
I updated the generator to always output these #defines so it does not need to fall back to undefined behaviour. |
|
Since
to
this means it and hardware_defs are now dead code, and should be removed, no? |
dc9db43 to
08b0d5c
Compare
2f207e8 to
976413f
Compare
976413f to
b398957
Compare
|
We need to a think around PCBREV with those json based declarations; Will talk to Raph about it |
9b17a45 to
4e7d432
Compare
4e7d432 to
d2d3e11
Compare
…n, disable IMU Ports the real HelloRadioSky V12 (STM32H750, 320x240 16bpp color LCD) board bring-up from the 2.12 branch (where PR #7113 landed) onto main's JSON-driven hardware description pattern (PR #7411 "chore: use settings from radio JSON files instead of hal.h"), replacing the stale monochrome F407 placeholder removed in the previous commit. - Author boards/hw_defs/v12.json (real 320x240 16bpp STM32H750 color board), modeled on t22.json (closest sibling HRS H750 board) with V12's actual pin/DMA facts from 2.12's targets/v12/hal.h and the helloradiosky reference branch. - Trim targets/v12/hal.h down to facts not covered by the generated hal_settings.h (USB, telemetry, LCD SPI+DMA, QSPI, I2C, touch, intmodule/extmodule, trainer port), following the pl18/t22 pattern. - Add targets/v12/CMakeLists.txt (stm32_rgbleds.cpp, pca95xx.cpp, HARDWARE_TOUCH) and targets/v12/usb_descriptor.h, and set IMU OFF: 2.12's own v12/CMakeLists.txt marks IMU "not populated in final" and ships the icm42670 driver unused; this port follows that and drops the old-PR-branch icm42627.cpp wiring, which collided with main's unrelated V16 icm42627 driver (#7482). - Add the full boards/helloradio-h750/ driver set (LCD, touch, backlight, haptic, key, SDRAM, system clock, USB charger, ext flash), ported off the retired stm32_ws2812 API onto the current boards/generic_stm32/ rgb_leds.h API (rgbSetLedColor/rgbLedClearAll/rgbLedColorApply). - sixPosUpdateFromAdc(): 2.12 replaced the old getSixPosAnalogValue() mechanism with a weak-symbol hook in rgb_6pos.cpp overridden by board.cpp, driving the sticky 6POS-to-function-switch RGB mapping ("Fixed function switch" in 2.12's history) - ported verbatim. - v12.json: reclassify the third ADC input (6POS raw analog reading) as RAW instead of FLEX/MULTIPOS, hiding it from the pot UI (V12 only has 2 real pots), and correct switch defaults to match 2.12's final tuning (SA 2POS, SD TOGGLE, SE-SJ 2POS as custom switches). - legacy_names.py: split V12 out of the shared {v12, v14, v14lcd} group into its own entry (2 pots, not 3), matching the pot-count correction. - Wire I2C_B4 (V12's touch/IMU bus) into the shared i2c_bus.cpp and stm32_i2c_driver, restore INTMODULE_ANTSEL_GPIO/USB_GPIO_SEL init in pwr_driver.cpp/usb_driver.cpp, and the RADIO_V12 dual-switch pwrPressed() branch. - Guard MIXSRC_TILT_X/Y in yaml_datastructs_v12.cpp behind defined(IMU), and add CHKSIZE(ModelData, 7640) for V12's actual struct layout. - Register the v12 flavour in radio/src/CMakeLists.txt, tools/boards.py, radio/util/build-firmware.py, tools/build-common.sh, tools/generate-yaml.sh, and radio/src/storage/yaml/CMakeLists.txt so yaml_datastructs_v12.cpp is actually compiled in. - Remove leftover duplicate antenna-selection code the stale PR branch had bolted on next to the generalized paths in several more places (edgetx.cpp double-calling checkExternalAntenna(), a third hand-rolled antenna Choice widget in crossfire_settings.cpp, duplicate icon guards in bitmaps.cpp/.h), and restore two unrelated main improvements the stale branch had silently reverted by predating them (rgb_6pos.cpp weak-symbol pattern already covered above; keysPollingCycle()'s KEY_ACTIVITY_KEYS/KEY_ACTIVITY_TRIMS bitmask API had regressed to a plain bool). Firmware now builds cleanly for -DPCB=V12 and produces a real 320x240/16bpp color firmware.bin/uf2 (STM32H750), not the old monochrome image. Co-authored-by: radiosky <839034809@qq.com> Co-authored-by: helloradiosky <839034809@qq.com> Co-authored-by: Richard Li <richard.li@ces.hk>
…n, disable IMU Ports the real HelloRadioSky V12 (STM32H750, 320x240 16bpp color LCD) board bring-up from the 2.12 branch (where PR #7113 landed) onto main's JSON-driven hardware description pattern (PR #7411 "chore: use settings from radio JSON files instead of hal.h"), replacing the stale monochrome F407 placeholder removed in the previous commit. - Author boards/hw_defs/v12.json (real 320x240 16bpp STM32H750 color board), modeled on t22.json (closest sibling HRS H750 board) with V12's actual pin/DMA facts from 2.12's targets/v12/hal.h and the helloradiosky reference branch. - Trim targets/v12/hal.h down to facts not covered by the generated hal_settings.h (USB, telemetry, LCD SPI+DMA, QSPI, I2C, touch, intmodule/extmodule, trainer port), following the pl18/t22 pattern. - Add targets/v12/CMakeLists.txt (stm32_rgbleds.cpp, pca95xx.cpp, HARDWARE_TOUCH) and targets/v12/usb_descriptor.h, and set IMU OFF: 2.12's own v12/CMakeLists.txt marks IMU "not populated in final" and ships the icm42670 driver unused; this port follows that and drops the old-PR-branch icm42627.cpp wiring, which collided with main's unrelated V16 icm42627 driver (#7482). - Add the full boards/helloradio-h750/ driver set (LCD, touch, backlight, haptic, key, SDRAM, system clock, USB charger, ext flash), ported off the retired stm32_ws2812 API onto the current boards/generic_stm32/ rgb_leds.h API (rgbSetLedColor/rgbLedClearAll/rgbLedColorApply). - sixPosUpdateFromAdc(): 2.12 replaced the old getSixPosAnalogValue() mechanism with a weak-symbol hook in rgb_6pos.cpp overridden by board.cpp, driving the sticky 6POS-to-function-switch RGB mapping ("Fixed function switch" in 2.12's history) - ported verbatim. - v12.json: reclassify the third ADC input (6POS raw analog reading) as RAW instead of FLEX/MULTIPOS, hiding it from the pot UI (V12 only has 2 real pots), and correct switch defaults to match 2.12's final tuning (SA 2POS, SD TOGGLE, SE-SJ 2POS as custom switches). - legacy_names.py: split V12 out of the shared {v12, v14, v14lcd} group into its own entry (2 pots, not 3), matching the pot-count correction. - Wire I2C_B4 (V12's touch/IMU bus) into the shared i2c_bus.cpp and stm32_i2c_driver, restore INTMODULE_ANTSEL_GPIO/USB_GPIO_SEL init in pwr_driver.cpp/usb_driver.cpp, and the RADIO_V12 dual-switch pwrPressed() branch. - Guard MIXSRC_TILT_X/Y in yaml_datastructs_v12.cpp behind defined(IMU), and add CHKSIZE(ModelData, 7640) for V12's actual struct layout. - Register the v12 flavour in radio/src/CMakeLists.txt, tools/boards.py, radio/util/build-firmware.py, tools/build-common.sh, tools/generate-yaml.sh, and radio/src/storage/yaml/CMakeLists.txt so yaml_datastructs_v12.cpp is actually compiled in. - Remove leftover duplicate antenna-selection code the stale PR branch had bolted on next to the generalized paths in several more places (edgetx.cpp double-calling checkExternalAntenna(), a third hand-rolled antenna Choice widget in crossfire_settings.cpp, duplicate icon guards in bitmaps.cpp/.h), and restore two unrelated main improvements the stale branch had silently reverted by predating them (rgb_6pos.cpp weak-symbol pattern already covered above; keysPollingCycle()'s KEY_ACTIVITY_KEYS/KEY_ACTIVITY_TRIMS bitmask API had regressed to a plain bool). Firmware now builds cleanly for -DPCB=V12 and produces a real 320x240/16bpp color firmware.bin/uf2 (STM32H750), not the old monochrome image. Co-authored-by: radiosky <839034809@qq.com> Co-authored-by: helloradiosky <839034809@qq.com> Co-authored-by: Richard Li <richard.li@ces.hk>
Both are top-level sections in every board JSON (EdgeTX#7411, EdgeTX#7383), but the schema did not list them, so every file failed validation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Start to move away from hal.h files and use the radio JSON files for build settings.
Changes:
Known concerns:
Summary by CodeRabbit