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/>.
23 #include "common/utils.h"
25 // FIXME some of these are flight modes, some of these are general status indicators
28 WAS_EVER_ARMED
= (1 << 1),
29 WAS_ARMED_WITH_PREARM
= (1 << 2)
32 extern uint8_t armingFlags
;
34 #define DISABLE_ARMING_FLAG(mask) (armingFlags &= ~(mask))
35 #define ENABLE_ARMING_FLAG(mask) (armingFlags |= (mask))
36 #define ARMING_FLAG(mask) (armingFlags & (mask))
39 * Arming disable flags are listed in the order of criticalness.
40 * (Beeper code can notify the most critical reason.)
43 ARMING_DISABLED_NO_GYRO
= (1 << 0),
44 ARMING_DISABLED_FAILSAFE
= (1 << 1),
45 ARMING_DISABLED_RX_FAILSAFE
= (1 << 2),
46 ARMING_DISABLED_BAD_RX_RECOVERY
= (1 << 3),
47 ARMING_DISABLED_BOXFAILSAFE
= (1 << 4),
48 ARMING_DISABLED_RUNAWAY_TAKEOFF
= (1 << 5),
49 ARMING_DISABLED_CRASH_DETECTED
= (1 << 6),
50 ARMING_DISABLED_THROTTLE
= (1 << 7),
51 ARMING_DISABLED_ANGLE
= (1 << 8),
52 ARMING_DISABLED_BOOT_GRACE_TIME
= (1 << 9),
53 ARMING_DISABLED_NOPREARM
= (1 << 10),
54 ARMING_DISABLED_LOAD
= (1 << 11),
55 ARMING_DISABLED_CALIBRATING
= (1 << 12),
56 ARMING_DISABLED_CLI
= (1 << 13),
57 ARMING_DISABLED_CMS_MENU
= (1 << 14),
58 ARMING_DISABLED_BST
= (1 << 15),
59 ARMING_DISABLED_MSP
= (1 << 16),
60 ARMING_DISABLED_PARALYZE
= (1 << 17),
61 ARMING_DISABLED_GPS
= (1 << 18),
62 ARMING_DISABLED_RESC
= (1 << 19),
63 ARMING_DISABLED_RPMFILTER
= (1 << 20),
64 ARMING_DISABLED_REBOOT_REQUIRED
= (1 << 21),
65 ARMING_DISABLED_DSHOT_BITBANG
= (1 << 22),
66 ARMING_DISABLED_ACC_CALIBRATION
= (1 << 23),
67 ARMING_DISABLED_MOTOR_PROTOCOL
= (1 << 24),
68 ARMING_DISABLED_ARM_SWITCH
= (1 << 25), // Needs to be the last element, since it's always activated if one of the others is active when arming
69 } armingDisableFlags_e
;
71 #define ARMING_DISABLE_FLAGS_COUNT (LOG2(ARMING_DISABLED_ARM_SWITCH) + 1)
73 extern const char *armingDisableFlagNames
[ARMING_DISABLE_FLAGS_COUNT
];
75 void setArmingDisabled(armingDisableFlags_e flag
);
76 void unsetArmingDisabled(armingDisableFlags_e flag
);
77 bool isArmingDisabled(void);
78 armingDisableFlags_e
getArmingDisableFlags(void);
81 ANGLE_MODE
= (1 << 0),
82 HORIZON_MODE
= (1 << 1),
84 // BARO_MODE = (1 << 3),
85 // GPS_HOME_MODE = (1 << 4),
86 // GPS_HOLD_MODE = (1 << 5),
87 HEADFREE_MODE
= (1 << 6),
88 // UNUSED_MODE = (1 << 7), // old autotune
89 PASSTHRU_MODE
= (1 << 8),
90 // RANGEFINDER_MODE= (1 << 9),
91 FAILSAFE_MODE
= (1 << 10),
92 GPS_RESCUE_MODE
= (1 << 11)
95 extern uint16_t flightModeFlags
;
97 #define DISABLE_FLIGHT_MODE(mask) disableFlightMode(mask)
98 #define ENABLE_FLIGHT_MODE(mask) enableFlightMode(mask)
99 #define FLIGHT_MODE(mask) (flightModeFlags & (mask))
101 // macro to initialize map from boxId_e to log2(flightModeFlags). Keep it in sync with flightModeFlags_e enum.
102 // [BOXARM] is left unpopulated
103 #define BOXID_TO_FLIGHT_MODE_MAP_INITIALIZER { \
104 [BOXANGLE] = LOG2(ANGLE_MODE), \
105 [BOXHORIZON] = LOG2(HORIZON_MODE), \
106 [BOXMAG] = LOG2(MAG_MODE), \
107 [BOXHEADFREE] = LOG2(HEADFREE_MODE), \
108 [BOXPASSTHRU] = LOG2(PASSTHRU_MODE), \
109 [BOXFAILSAFE] = LOG2(FAILSAFE_MODE), \
110 [BOXGPSRESCUE] = LOG2(GPS_RESCUE_MODE), \
115 GPS_FIX_HOME
= (1 << 0),
117 GPS_FIX_EVER
= (1 << 2),
120 #define DISABLE_STATE(mask) (stateFlags &= ~(mask))
121 #define ENABLE_STATE(mask) (stateFlags |= (mask))
122 #define STATE(mask) (stateFlags & (mask))
124 extern uint8_t stateFlags
;
126 uint16_t enableFlightMode(flightModeFlags_e mask
);
127 uint16_t disableFlightMode(flightModeFlags_e mask
);
129 bool sensors(uint32_t mask
);
130 void sensorsSet(uint32_t mask
);
131 void sensorsClear(uint32_t mask
);
132 uint32_t sensorsMask(void);