More updates
[inav.git] / src / main / fc / config.h
blobe32a705e1a1b934d30425f6b16348bccb40e23f0
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #pragma once
20 #include <stdint.h>
21 #include <stdbool.h>
22 #include "common/axis.h"
23 #include "common/time.h"
24 #include "config/parameter_group.h"
25 #include "drivers/adc.h"
26 #include "fc/stats.h"
28 #define MAX_PROFILE_COUNT 3
29 #define ONESHOT_FEATURE_CHANGED_DELAY_ON_BOOT_MS 1500
30 #define MAX_NAME_LENGTH 16
32 #define TASK_GYRO_LOOPTIME 250 // Task gyro always runs at 4kHz
34 typedef enum {
35 FEATURE_THR_VBAT_COMP = 1 << 0,
36 FEATURE_VBAT = 1 << 1,
37 FEATURE_TX_PROF_SEL = 1 << 2, // Profile selection by TX stick command
38 FEATURE_BAT_PROFILE_AUTOSWITCH = 1 << 3,
39 FEATURE_MOTOR_STOP = 1 << 4,
40 FEATURE_UNUSED_1 = 1 << 5, // was FEATURE_SERVO_TILT was FEATURE_DYNAMIC_FILTERS
41 FEATURE_SOFTSERIAL = 1 << 6,
42 FEATURE_GPS = 1 << 7,
43 FEATURE_UNUSED_3 = 1 << 8, // was FEATURE_FAILSAFE
44 FEATURE_UNUSED_4 = 1 << 9, // was FEATURE_SONAR
45 FEATURE_TELEMETRY = 1 << 10,
46 FEATURE_CURRENT_METER = 1 << 11,
47 FEATURE_REVERSIBLE_MOTORS = 1 << 12,
48 FEATURE_UNUSED_5 = 1 << 13, // RX_PARALLEL_PWM
49 FEATURE_UNUSED_6 = 1 << 14, // RX_MSP
50 FEATURE_RSSI_ADC = 1 << 15,
51 FEATURE_LED_STRIP = 1 << 16,
52 FEATURE_DASHBOARD = 1 << 17,
53 FEATURE_UNUSED_7 = 1 << 18, // Unused in INAV
54 FEATURE_BLACKBOX = 1 << 19,
55 FEATURE_UNUSED_10 = 1 << 20, // was FEATURE_CHANNEL_FORWARDING
56 FEATURE_TRANSPONDER = 1 << 21,
57 FEATURE_AIRMODE = 1 << 22,
58 FEATURE_SUPEREXPO_RATES = 1 << 23,
59 FEATURE_VTX = 1 << 24,
60 FEATURE_UNUSED_8 = 1 << 25, // RX_SPI
61 FEATURE_UNUSED_9 = 1 << 26, // SOFTSPI
62 FEATURE_UNUSED_11 = 1 << 27, // FEATURE_PWM_SERVO_DRIVER
63 FEATURE_PWM_OUTPUT_ENABLE = 1 << 28,
64 FEATURE_OSD = 1 << 29,
65 FEATURE_FW_LAUNCH = 1 << 30,
66 FEATURE_FW_AUTOTRIM = 1 << 31,
67 } features_e;
69 typedef struct systemConfig_s {
70 uint8_t current_profile_index;
71 uint8_t current_battery_profile_index;
72 uint8_t debug_mode;
73 #ifdef USE_DEV_TOOLS
74 bool groundTestMode; // Disables motor ouput, sets heading trusted on FW (for dev use)
75 #endif
76 #ifdef USE_I2C
77 uint8_t i2c_speed;
78 #endif
79 #ifdef USE_UNDERCLOCK
80 uint8_t cpuUnderclock;
81 #endif
82 uint8_t throttle_tilt_compensation_strength; // the correction that will be applied at throttle_correction_angle.
83 char craftName[MAX_NAME_LENGTH + 1];
84 char pilotName[MAX_NAME_LENGTH + 1];
85 } systemConfig_t;
87 PG_DECLARE(systemConfig_t, systemConfig);
89 typedef struct beeperConfig_s {
90 uint32_t beeper_off_flags;
91 uint32_t preferred_beeper_off_flags;
92 bool dshot_beeper_enabled;
93 uint8_t dshot_beeper_tone;
94 bool pwmMode;
95 } beeperConfig_t;
97 PG_DECLARE(beeperConfig_t, beeperConfig);
99 typedef struct adcChannelConfig_s {
100 uint8_t adcFunctionChannel[ADC_FUNCTION_COUNT];
101 } adcChannelConfig_t;
103 PG_DECLARE(adcChannelConfig_t, adcChannelConfig);
106 #ifdef USE_STATS
107 PG_DECLARE(statsConfig_t, statsConfig);
108 #endif
110 void beeperOffSet(uint32_t mask);
111 void beeperOffSetAll(uint8_t beeperCount);
112 void beeperOffClear(uint32_t mask);
113 void beeperOffClearAll(void);
114 uint32_t getBeeperOffMask(void);
115 void setBeeperOffMask(uint32_t mask);
116 uint32_t getPreferredBeeperOffMask(void);
117 void setPreferredBeeperOffMask(uint32_t mask);
119 void copyCurrentProfileToProfileSlot(uint8_t profileSlotIndex);
121 void initEEPROM(void);
122 void resetEEPROM(void);
123 void readEEPROM(void);
124 void writeEEPROM(void);
125 void ensureEEPROMContainsValidData(void);
126 void processDelayedSave(void);
128 void saveConfig(void);
129 void saveConfigAndNotify(void);
130 void validateAndFixConfig(void);
131 void validateAndFixTargetConfig(void);
133 uint8_t getConfigProfile(void);
134 bool setConfigProfile(uint8_t profileIndex);
135 void setConfigProfileAndWriteEEPROM(uint8_t profileIndex);
137 uint8_t getConfigBatteryProfile(void);
138 bool setConfigBatteryProfile(uint8_t profileIndex);
139 void setConfigBatteryProfileAndWriteEEPROM(uint8_t profileIndex);
141 void setGyroCalibration(float getGyroZero[XYZ_AXIS_COUNT]);
142 void setGravityCalibration(float getGravity);
144 bool canSoftwareSerialBeUsed(void);
145 void applyAndSaveBoardAlignmentDelta(int16_t roll, int16_t pitch);
147 void createDefaultConfig(void);
148 void resetConfigs(void);
149 void targetConfiguration(void);
151 uint32_t getLooptime(void);
152 uint32_t getGyroLooptime(void);