| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | /* | |||
| 2 | * @file board_overrides.h | |||
| 3 | * @brief Board-specific override mechanism | |||
| 4 | * | |||
| 5 | * This header provides a centralized way to define and manage board-specific overrides. | |||
| 6 | * Custom boards can implement their own specialized behavior by overriding these function pointers. | |||
| 7 | * | |||
| 8 | * Usage Example: | |||
| 9 | * | |||
| 10 | * 1. Define your custom function: | |||
| 11 | * void myBoardCustomHello() { | |||
| 12 | * // Your custom implementation | |||
| 13 | * } | |||
| 14 | * | |||
| 15 | * 2. Set up the override in your board_configuration.cpp: | |||
| 16 | * void setup_custom_board_overrides() { | |||
| 17 | * custom_board_boardSayHello = myBoardCustomHello; | |||
| 18 | * } | |||
| 19 | * | |||
| 20 | * | |||
| 21 | * @date: jul 09, 2025 | |||
| 22 | * @author FDSoftware | |||
| 23 | */ | |||
| 24 | ||||
| 25 | #pragma once | |||
| 26 | #include <functional> | |||
| 27 | #include <optional> | |||
| 28 | #include "engine_configuration.h" | |||
| 29 | ||||
| 30 | // function with no parameters and returning void | |||
| 31 | using setup_custom_board_overrides_type = void (*)(); | |||
| 32 | using setup_custom_board_config_type = void (*)(engine_configuration_s * /*previousConfiguration*/); | |||
| 33 | using setup_custom_board_output_type = int (*)(); | |||
| 34 | using setup_custom_board_engine_type_type = void (*)(engine_type_e); | |||
| 35 | ||||
| 36 | using setup_custom_board_ts_command_override_type = void (*)(uint16_t /*subsystem*/, uint16_t /*index*/); | |||
| 37 | extern std::optional<setup_custom_board_ts_command_override_type> custom_board_ts_command; | |||
| 38 | ||||
| 39 | #if EFI_CAN_SUPPORT | |||
| 40 | #include "can_msg_tx.h" | |||
| 41 | using board_can_rx_type = void (*)(const size_t, const CANRxFrame &, efitick_t); | |||
| 42 | extern std::optional<board_can_rx_type> custom_board_can_rx; | |||
| 43 | ||||
| 44 | using board_can_update_dash_type = void (*)(CanCycle cycle); | |||
| 45 | extern std::optional<board_can_update_dash_type> custom_board_update_dash; | |||
| 46 | #endif // EFI_CAN_SUPPORT | |||
| 47 | ||||
| 48 | /** | |||
| 49 | * @brief Pre-HAL initialization override point | |||
| 50 | * Allows boards to perform custom initialization before HAL is initialized | |||
| 51 | */ | |||
| 52 | extern std::optional<setup_custom_board_overrides_type> custom_board_preHalInit; | |||
| 53 | ||||
| 54 | extern std::optional<setup_custom_board_overrides_type> custom_board_boardSayHello; | |||
| 55 | ||||
| 56 | // Called before configuration is loaded | |||
| 57 | extern std::optional<setup_custom_board_overrides_type> custom_board_InitHardwareEarly; | |||
| 58 | extern std::optional<setup_custom_board_overrides_type> custom_board_InitHardware; | |||
| 59 | extern std::optional<setup_custom_board_overrides_type> custom_board_InitHardwareExtra; | |||
| 60 | extern std::optional<setup_custom_board_config_type> custom_board_OnConfigurationChange; | |||
| 61 | ||||
| 62 | extern std::optional<setup_custom_board_overrides_type> custom_board_BeforeTuneDefaults; | |||
| 63 | extern std::optional<setup_custom_board_engine_type_type> custom_board_AfterTuneDefaults; | |||
| 64 | extern std::optional<setup_custom_board_engine_type_type> custom_board_applyUnknownType; | |||
| 65 | ||||
| 66 | extern std::optional<setup_custom_board_overrides_type> custom_board_periodicSlowCallback; | |||
| 67 | extern std::optional<setup_custom_board_overrides_type> custom_board_periodicFastCallback; | |||
| 68 | ||||
| 69 | // Board hardware related: | |||
| 70 | extern std::optional<setup_custom_board_output_type> custom_board_getMetaOutputsCount; | |||
| 71 | extern std::optional<setup_custom_board_output_type> custom_board_getMetaLowSideOutputs; | |||
| 72 | ||||
| 73 | // LTFT to VE table custom apply algo | |||
| 74 | extern std::optional<setup_custom_board_overrides_type> custom_board_LtftTrimToVeApply; | |||
| 75 | ||||
| 76 | // specific firmware builds are meant for specific hardware. In order to provide best user experience on well-known boards sometimes we reduce user flexibility. | |||
| 77 | extern std::optional<setup_custom_board_overrides_type> custom_board_DefaultConfiguration; | |||
| 78 | extern std::optional<setup_custom_board_overrides_type> custom_board_ConfigOverrides; | |||
| 79 | ||||
| 80 | /** | |||
| 81 | * This function checks if an override is present and calls it if available. | |||
| 82 | * Return true if override is present and was called | |||
| 83 | */ | |||
| 84 | template<typename FuncType, typename... Args> | |||
| 85 | 3943 | static inline bool call_board_override(std::optional<FuncType> board_override, Args&&... args){ | ||
| 86 |
2/4bool call_board_override<void (*)(engine_type_e), engine_type_e&>(std::optional<void (*)(engine_type_e)>, engine_type_e&):
✗ Branch 1 not taken.
✓ Branch 2 taken 587 times.
bool call_board_override<void (*)()>(std::optional<void (*)()>):
✗ Branch 1 not taken.
✓ Branch 2 taken 3356 times.
|
2/4bool call_board_override<void (*)(engine_type_e), engine_type_e&>(std::optional<void (*)(engine_type_e)>, engine_type_e&):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 587 times.
bool call_board_override<void (*)()>(std::optional<void (*)()>):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 3356 times.
|
3943 | if (board_override.has_value()) { |
| 87 | ✗ | std::invoke(board_override.value(), std::forward<Args>(args)...); | ||
| 88 | ✗ | return true; | ||
| 89 | } | |||
| 90 | 3943 | return false; | ||
| 91 | } | |||
| 92 |