2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
27 #include "config/feature.h"
29 #include "pg/pg_ids.h"
32 PG_REGISTER_WITH_RESET_TEMPLATE(featureConfig_t
, featureConfig
, PG_FEATURE_CONFIG
, 1);
34 PG_RESET_TEMPLATE(featureConfig_t
, featureConfig
,
35 .enabledFeatures
= DEFAULT_FEATURES
| DEFAULT_RX_FEATURE
| FEATURE_ANTI_GRAVITY
| FEATURE_AIRMODE
,
38 static uint32_t runtimeFeatureMask
;
40 void featureInit(void)
42 runtimeFeatureMask
= featureConfig()->enabledFeatures
;
45 static void featureSet(const uint32_t mask
, uint32_t *features
)
50 static void featureClear(const uint32_t mask
, uint32_t *features
)
55 // Determines if the feature is enabled (active) in the runtime state.
56 // This is the primary funciton used by code that wants to know if a
57 // feature is available.
58 bool featureIsEnabled(const uint32_t mask
)
60 return runtimeFeatureMask
& mask
;
63 // Determines if the feature is configured (set in the configuration). Doesn't mean the
64 // feature is active in the runtime. This function *SHOULD ONLY* be used in the config check
65 // performed at startup and when writing to EEPROM.
66 bool featureIsConfigured(const uint32_t mask
)
68 return featureConfig()->enabledFeatures
& mask
;
71 // Updates the configuration *AND* runtime state of a feature.
72 // Used *ONLY* by the config check process that runs at startup and EEPROM save.
73 void featureEnableImmediate(const uint32_t mask
)
75 featureSet(mask
, &featureConfigMutable()->enabledFeatures
);
76 featureSet(mask
, &runtimeFeatureMask
);
79 // Updates the configuration *AND* runtime state of a feature.
80 // Used *ONLY* by the config check process that runs at startup and EEPROM save.
81 void featureDisableImmediate(const uint32_t mask
)
83 featureClear(mask
, &featureConfigMutable()->enabledFeatures
);
84 featureClear(mask
, &runtimeFeatureMask
);
87 // Sets the configuration state of the feature and *DOES NOT* change the runtime state.
88 // For example, used by the CLI "feature" command. Use this function if you want to
89 // enable a feature that will be active after save/reboot.
90 void featureConfigSet(const uint32_t mask
)
92 featureSet(mask
, &featureConfigMutable()->enabledFeatures
);
95 // Sets the configuration state of the feature and *DOES NOT* change the runtime state.
96 // For example, used by the CLI "feature" command. Use this function if you want to
97 // disable a feature after a save/reboot.
98 void featureConfigClear(const uint32_t mask
)
100 featureClear(mask
, &featureConfigMutable()->enabledFeatures
);
103 // Sets the configuration state of all features and *DOES NOT* change the runtime state.
104 // For example, used by MSP to update all the configured features in one go.
105 void featureConfigReplace(const uint32_t mask
)
107 featureConfigMutable()->enabledFeatures
= mask
;