New SPI API supporting DMA
[betaflight.git] / src / main / fc / rc_modes.h
blob664df337cb1b59b7291d6f8203f8c8205b7b8c92
1 /*
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)
8 * any later version.
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/>.
21 #pragma once
23 #include <stdbool.h>
25 #include "pg/pg.h"
27 #define BOXID_NONE 255
29 typedef enum {
30 // ARM flag
31 BOXARM = 0,
32 // FLIGHT_MODE
33 BOXANGLE,
34 BOXHORIZON,
35 BOXMAG,
36 BOXHEADFREE,
37 BOXPASSTHRU,
38 BOXFAILSAFE,
39 BOXGPSRESCUE,
40 BOXID_FLIGHTMODE_LAST = BOXGPSRESCUE,
42 // When new flight modes are added, the parameter group version for 'modeActivationConditions' in src/main/fc/rc_modes.c has to be incremented to ensure that the RC modes configuration is reset.
44 // RCMODE flags
45 BOXANTIGRAVITY,
46 BOXHEADADJ,
47 BOXCAMSTAB,
48 BOXBEEPERON,
49 BOXLEDLOW,
50 BOXCALIB,
51 BOXOSD,
52 BOXTELEMETRY,
53 BOXSERVO1,
54 BOXSERVO2,
55 BOXSERVO3,
56 BOXBLACKBOX,
57 BOXAIRMODE,
58 BOX3D,
59 BOXFPVANGLEMIX,
60 BOXBLACKBOXERASE,
61 BOXCAMERA1,
62 BOXCAMERA2,
63 BOXCAMERA3,
64 BOXFLIPOVERAFTERCRASH,
65 BOXPREARM,
66 BOXBEEPGPSCOUNT,
67 BOXVTXPITMODE,
68 BOXPARALYZE,
69 BOXUSER1,
70 BOXUSER2,
71 BOXUSER3,
72 BOXUSER4,
73 BOXPIDAUDIO,
74 BOXACROTRAINER,
75 BOXVTXCONTROLDISABLE,
76 BOXLAUNCHCONTROL,
77 BOXMSPOVERRIDE,
78 BOXSTICKCOMMANDDISABLE,
79 BOXBEEPERMUTE,
80 CHECKBOX_ITEM_COUNT
81 } boxId_e;
83 typedef enum {
84 MODELOGIC_OR = 0,
85 MODELOGIC_AND
86 } modeLogic_e;
88 // type to hold enough bits for CHECKBOX_ITEM_COUNT. Struct used for value-like behavior
89 typedef struct boxBitmask_s { uint32_t bits[(CHECKBOX_ITEM_COUNT + 31) / 32]; } boxBitmask_t;
91 #define MAX_MODE_ACTIVATION_CONDITION_COUNT 20
93 #define CHANNEL_RANGE_MIN 900
94 #define CHANNEL_RANGE_MAX 2100
96 #define MODE_STEP_TO_CHANNEL_VALUE(step) (CHANNEL_RANGE_MIN + 25 * step)
97 #define CHANNEL_VALUE_TO_STEP(channelValue) ((constrain(channelValue, CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / 25)
99 #define MIN_MODE_RANGE_STEP 0
100 #define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25)
102 // steps are 25 apart
103 // a value of 0 corresponds to a channel value of 900 or less
104 // a value of 48 corresponds to a channel value of 2100 or more
105 // 48 steps between 900 and 2100
106 typedef struct channelRange_s {
107 uint8_t startStep;
108 uint8_t endStep;
109 } channelRange_t;
111 typedef struct modeActivationCondition_s {
112 boxId_e modeId;
113 uint8_t auxChannelIndex;
114 channelRange_t range;
115 modeLogic_e modeLogic;
116 boxId_e linkedTo;
117 } modeActivationCondition_t;
119 PG_DECLARE_ARRAY(modeActivationCondition_t, MAX_MODE_ACTIVATION_CONDITION_COUNT, modeActivationConditions);
121 #if defined(USE_CUSTOM_BOX_NAMES)
123 #define MAX_BOX_USER_NAME_LENGTH 16
125 typedef struct modeActivationConfig_s {
126 char box_user_1_name[MAX_BOX_USER_NAME_LENGTH];
127 char box_user_2_name[MAX_BOX_USER_NAME_LENGTH];
128 char box_user_3_name[MAX_BOX_USER_NAME_LENGTH];
129 char box_user_4_name[MAX_BOX_USER_NAME_LENGTH];
130 } modeActivationConfig_t;
132 PG_DECLARE(modeActivationConfig_t, modeActivationConfig);
133 #endif
135 typedef struct modeActivationProfile_s {
136 modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
137 } modeActivationProfile_t;
139 #define IS_RANGE_USABLE(range) ((range)->startStep < (range)->endStep)
141 bool IS_RC_MODE_ACTIVE(boxId_e boxId);
142 void rcModeUpdate(boxBitmask_t *newState);
144 bool airmodeIsEnabled(void);
146 bool isRangeActive(uint8_t auxChannelIndex, const channelRange_t *range);
147 void updateActivatedModes(void);
148 bool isModeActivationConditionPresent(boxId_e modeId);
149 bool isModeActivationConditionLinked(boxId_e modeId);
150 void removeModeActivationCondition(boxId_e modeId);
151 bool isModeActivationConditionConfigured(const modeActivationCondition_t *mac, const modeActivationCondition_t *emptyMac);
152 void analyzeModeActivationConditions(void);