Refactoring: modularize main.c into per-subsystem source files#169
Conversation
…PI data size register
Remove RGB_to_BRG() calls, fix spi data size bug
* feat: update dependencies + CI file * ci: test * ci: wrong branch name * ci: remove old file
CI: cleanup & updating dependencies
- Root .gitignore for editor configs and source archives - Extend AxxSolder_firmware/.gitignore with build/, .vscode/, .clangd
main.c was 2898 lines mixing peripheral init, ISR dispatchers, sensor
handling, state machine, PID control, display, buttons/encoder,
USB-PD negotiation, and persistent settings. This commit extracts
each subsystem into its own .c/.h pair while preserving the
byte-equivalent runtime behavior of the original.
New modules (Core/Src + Core/Inc):
sensors thermocouple, bus voltage, MCU temp, heater current
ADC sampling and moving-average filters
heater TIM1 PWM, ADC2 current measurement, duty cycle math
handle JBC handle detection (T210/T245/NT115), cartridge
presence, per-handle power limits and PID gains
state_machine RUN/STANDBY/SLEEP/HALTED transitions, emergency
shutdown checks, delta-temperature fault detection
encoder TIM2 quadrature decoding, setpoint write
buttons EXTI press handlers, TIM16 debounce, long/short press
stand stand-sense GPIO debounce and state transitions
settings flash storage of Flash_values struct
telemetry rate-limited UART debug packet transmission
power_source STUSB4500 USB-PD negotiation
display_app main screen render, popups, graph view, uGUI glue
controller PID instance, setpoint update, PID_TUNING hooks
util clamp()
version firmware and hardware version queries
Modified modules:
buzzer extended with beep_at_set_temp and ISR entry points
main.c now contains only the CubeMX-generated peripheral inits, the
USER CODE BEGIN 2 / BEGIN WHILE init sequences (byte-exact firing
order with the original), and thin one-line ISR dispatchers that
route HAL callbacks to the owning modules.
Dead code removed in this pass (verified unused in upstream):
UART_buffer, timer_cleaned, time_to_standby_ms, time_to_sleep_ms,
and the min()/min3() helpers (only call site was inlined).
No behavior changes, no new features. Code organization only.
RAM and FLASH footprint match upstream within rounding.
Added warnings about power supply usage and USB-C chargers to ensure safe operation of AxxSolder.
|
First thing, it looks like Fix LCD color handling: compile-time BRG565 definitions and STM32G4 S… broke the color rendering. It is working as "intended" now. But we do not have the correct colors anymore. I think we have to fix that. As an exemple: Now C_ORANGE is orange (as it should be) but that means it is not the RED is should be. So how do we fix this? Should we back-calculate colors And use? |
|
ping @pashamray |
just replace C_ORANGE to C_RED in code It's best to use aliases for colors, for example (in gui.h) #define C_ACCENT C_RED and replce C_ORANGE to C_ACCENT #define C_ACCENT C_RED
#define C_ALERT C_REDIt's better to make many defines of the same color for different tasks, anyway it will turn into a value substitution during compilation and doesn't take up space |
Summary
main.cinto subsystems with its own.cand.hpair while preserving byte-equivalent runtime behavior of the original firmware.Why
A monolithic
main.chas accumulated friction over time:By extracting subsystems into modules the code becomes self-contained and isolated. Therefore, beneficial for new developers to hop on and maintain the project.
Scope
Refactor only. No new features, no PID tuning changes, no UI changes, no protocol changes.
New modules
sensors.c/hheater.c/hhandle.c/hstate_machine.c/hencoder.c/hbuttons.c/hstand.c/hsettings.c/hFlash_valuesstructtelemetry.c/hpower_source.c/hdisplay_app.c/hcontroller.c/hutil.c/hclamp()helperversion.c/hModified modules
buzzer.c/hbeep_at_set_temp()and ISR entry points for setpoint-reached audio feedback (logic was previously inline inmain.c)debug.cgraph.c/graph.hmenu_profiles.c/menu_profiles.h#includeadjustmentmenu_settings.c#includeadjustmenttip_profile.hcontroller.hboundaryDead code removed
Verified unused in upstream and dropped:
UART_buffer: buffer that was never readtimer_cleaned: flag that no code path checkedtime_to_standby_ms,time_to_sleep_ms: overridden by the values in Flash_valuesmin()/min3(): only call site was inlined; standard<comparison used insteadWhat stayed in
main.cMX_GPIO_Init,MX_ADC1_Init, etc.). Left verbatim to preserve regen-ability if anyone re-runs CubeMX from the.ioc.The USER CODE BEGIN 2 / BEGIN WHILE init sequences. Kept in byte-exact firing order with upstream. Reordering startup is its own PR.
Thin one-line ISR dispatchers that route HAL callbacks (
HAL_TIM_PeriodElapsedCallback,HAL_GPIO_EXTI_Callback,HAL_ADC_ConvCpltCallback, etc.) to the owning modules.Result
main.cwent from 2898 → 1203 linesVerification status
Done (software-only):
main.cNot done: hardware functional verification still needed:
Bench testing on real hardware (T245/T210/NT115 cartridges, USB-PD source, 24 V brick) has not been run yet. The refactor is structurally equivalent to upstream per static checks, but behavior on hardware must be confirmed before merge.