rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
board_overrides.h
Go to the documentation of this file.
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>
29
30// function with no parameters and returning void
32using setup_custom_board_config_type = void (*)(engine_configuration_s * /*previousConfiguration*/);
34
35using setup_custom_board_ts_command_override_type = void (*)(uint16_t /*subsystem*/, uint16_t /*index*/);
36extern std::optional<setup_custom_board_ts_command_override_type> custom_board_ts_command;
37
38#if EFI_CAN_SUPPORT
39#include "can_msg_tx.h"
40using board_can_rx_type = void (*)(const size_t, const CANRxFrame &, efitick_t);
41extern std::optional<board_can_rx_type> custom_board_can_rx;
42
43using board_can_update_dash_type = void (*)(CanCycle cycle);
44extern std::optional<board_can_update_dash_type> custom_board_update_dash;
45#endif // EFI_CAN_SUPPORT
46
47/**
48 * @brief Pre-HAL initialization override point
49 * Allows boards to perform custom initialization before HAL is initialized
50 */
51extern std::optional<setup_custom_board_overrides_type> custom_board_preHalInit;
52
53extern std::optional<setup_custom_board_overrides_type> custom_board_boardSayHello;
54
55// Called before configuration is loaded
56extern std::optional<setup_custom_board_overrides_type> custom_board_InitHardwareEarly;
57extern std::optional<setup_custom_board_overrides_type> custom_board_InitHardware;
58extern std::optional<setup_custom_board_overrides_type> custom_board_InitHardwareExtra;
59extern std::optional<setup_custom_board_config_type> custom_board_OnConfigurationChange;
60
61// Board hardware related:
62extern std::optional<setup_custom_board_output_type> custom_board_getMetaOutputsCount;
63extern std::optional<setup_custom_board_output_type> custom_board_getMetaLowSideOutputs;
64
65// LTFT to VE table custom apply algo
66extern std::optional<setup_custom_board_overrides_type> custom_board_LtftTrimToVeApply;
67
68// specific firmware builds are meant for specific hardware. In order to provide best user experience on well-known boards sometimes we reduce user flexibility.
69extern std::optional<setup_custom_board_overrides_type> custom_board_DefaultConfiguration;
70extern std::optional<setup_custom_board_overrides_type> custom_board_ConfigOverrides;
71
72/**
73 * This function checks if an override is present and calls it if available.
74 * Return true if override is present and was called
75 */
76template<typename FuncType, typename... Args>
77static inline bool call_board_override(std::optional<FuncType> board_override, Args&&... args){
78 if (board_override.has_value()) {
79 std::invoke(board_override.value(), std::forward<Args>(args)...);
80 return true;
81 }
82 return false;
83}
std::optional< board_can_rx_type > custom_board_can_rx
Definition can_rx.cpp:201
void(*)(const size_t, const CANRxFrame &, efitick_t) board_can_rx_type
std::optional< board_can_update_dash_type > custom_board_update_dash
Definition can_dash.cpp:612
void(*)(uint16_t, uint16_t) setup_custom_board_ts_command_override_type
std::optional< setup_custom_board_overrides_type > custom_board_InitHardware
Definition hardware.cpp:77
std::optional< setup_custom_board_overrides_type > custom_board_ConfigOverrides
void(*)() setup_custom_board_overrides_type
std::optional< setup_custom_board_ts_command_override_type > custom_board_ts_command
static bool call_board_override(std::optional< FuncType > board_override, Args &&... args)
std::optional< setup_custom_board_overrides_type > custom_board_boardSayHello
void(*)(CanCycle cycle) board_can_update_dash_type
std::optional< setup_custom_board_overrides_type > custom_board_preHalInit
Pre-HAL initialization override point Allows boards to perform custom initialization before HAL is in...
Definition main.cpp:22
std::optional< setup_custom_board_overrides_type > custom_board_LtftTrimToVeApply
std::optional< setup_custom_board_overrides_type > custom_board_DefaultConfiguration
int(*)() setup_custom_board_output_type
std::optional< setup_custom_board_config_type > custom_board_OnConfigurationChange
void(*)(engine_configuration_s *) setup_custom_board_config_type
std::optional< setup_custom_board_overrides_type > custom_board_InitHardwareExtra
Definition hardware.cpp:78
std::optional< setup_custom_board_output_type > custom_board_getMetaLowSideOutputs
std::optional< setup_custom_board_overrides_type > custom_board_InitHardwareEarly
Definition hardware.cpp:76
std::optional< setup_custom_board_output_type > custom_board_getMetaOutputsCount
Definition can.h:83
Main engine configuration data structure.