4 #include "elrs_eeprom.h"
8 #if defined(PLATFORM_ESP32)
13 // CONFIG_MAGIC is ORed with CONFIG_VERSION in the version field
14 #define CONFIG_MAGIC_MASK (0b11U << 30)
15 #define TX_CONFIG_MAGIC (0b01U << 30)
16 #define RX_CONFIG_MAGIC (0b10U << 30)
18 #define TX_CONFIG_VERSION 8U
19 #define RX_CONFIG_VERSION 10U
21 #if defined(TARGET_TX)
23 #define CONFIG_TX_BUTTON_ACTION_CNT 2
24 #define CONFIG_TX_MODEL_CNT 64
45 } headTrackingEnable_t
;
52 boostChannel
:3, // dynamic power boost AUX channel
55 txAntenna
:2, // FUTURE: Which TX antenna to use, 0=Auto
62 uint8_t pressType
:1, // 0 short, 1 long
63 count
:3, // 1-8 click count for short, .5sec hold count for long
64 action
:4; // action to execute
69 uint8_t color
; // RRRGGGBB
70 button_action_t actions
[CONFIG_TX_BUTTON_ACTION_CNT
];
77 BACKPACK_TELEM_MODE_OFF
,
78 BACKPACK_TELEM_MODE_ESPNOW
,
79 BACKPACK_TELEM_MODE_WIFI
,
80 BACKPACK_TELEM_MODE_BLUETOOTH
,
85 uint8_t vtxBand
; // 0=Off, else band number
86 uint8_t vtxChannel
; // 0=Ch1 -> 7=Ch8
87 uint8_t vtxPower
; // 0=Do not set, else power number
88 uint8_t vtxPitmode
; // Off/On/AUX1^/AUX1v/etc
89 uint8_t powerFanThreshold
:4; // Power level to enable fan if present
90 model_config_t model_config
[CONFIG_TX_MODEL_CNT
];
91 uint8_t fanMode
; // some value used by thermal?
92 uint8_t motionMode
:2, // bool, but space for 2 more modes
94 backpackDisable
:1, // bool, disable backpack via EN pin if available
95 backpackTlmMode
:2; // 0=Off, 1=Fwd tlm via espnow, 2=fwd tlm via wifi 3=(FUTURE) bluetooth
96 uint8_t dvrStartDelay
:3,
98 tx_button_color_t buttonColors
[2]; // FUTURE: TX RGB color / mode (sets color of TX, can be a static color or standard)
99 // FUTURE: Model RGB color / mode (sets LED color mode on the model, but can be second TX led color too)
100 // FUTURE: Custom button actions
111 uint8_t GetRate() const { return m_model
->rate
; }
112 uint8_t GetTlm() const { return m_model
->tlm
; }
113 uint8_t GetPower() const { return m_model
->power
; }
114 bool GetDynamicPower() const { return m_model
->dynamicPower
; }
115 uint8_t GetBoostChannel() const { return m_model
->boostChannel
; }
116 uint8_t GetSwitchMode() const { return m_model
->switchMode
; }
117 uint8_t GetAntennaMode() const { return m_model
->txAntenna
; }
118 uint8_t GetLinkMode() const { return m_model
->linkMode
; }
119 bool GetModelMatch() const { return m_model
->modelMatch
; }
120 bool IsModified() const { return m_modified
; }
121 uint8_t GetVtxBand() const { return m_config
.vtxBand
; }
122 uint8_t GetVtxChannel() const { return m_config
.vtxChannel
; }
123 uint8_t GetVtxPower() const { return m_config
.vtxPower
; }
124 uint8_t GetVtxPitmode() const { return m_config
.vtxPitmode
; }
125 uint8_t GetPowerFanThreshold() const { return m_config
.powerFanThreshold
; }
126 uint8_t GetFanMode() const { return m_config
.fanMode
; }
127 uint8_t GetMotionMode() const { return m_config
.motionMode
; }
128 uint8_t GetDvrAux() const { return m_config
.dvrAux
; }
129 uint8_t GetDvrStartDelay() const { return m_config
.dvrStartDelay
; }
130 uint8_t GetDvrStopDelay() const { return m_config
.dvrStopDelay
; }
131 bool GetBackpackDisable() const { return m_config
.backpackDisable
; }
132 uint8_t GetBackpackTlmMode() const { return m_config
.backpackTlmMode
; }
133 tx_button_color_t
const *GetButtonActions(uint8_t button
) const { return &m_config
.buttonColors
[button
]; }
134 model_config_t
const &GetModelConfig(uint8_t model
) const { return m_config
.model_config
[model
]; }
135 uint8_t GetPTRStartChannel() const { return m_model
->ptrStartChannel
; }
136 uint8_t GetPTREnableChannel() const { return m_model
->ptrEnableChannel
; }
139 void SetRate(uint8_t rate
);
140 void SetTlm(uint8_t tlm
);
141 void SetPower(uint8_t power
);
142 void SetDynamicPower(bool dynamicPower
);
143 void SetBoostChannel(uint8_t boostChannel
);
144 void SetSwitchMode(uint8_t switchMode
);
145 void SetAntennaMode(uint8_t txAntenna
);
146 void SetLinkMode(uint8_t linkMode
);
147 void SetModelMatch(bool modelMatch
);
148 void SetDefaults(bool commit
);
149 void SetStorageProvider(ELRS_EEPROM
*eeprom
);
150 void SetVtxBand(uint8_t vtxBand
);
151 void SetVtxChannel(uint8_t vtxChannel
);
152 void SetVtxPower(uint8_t vtxPower
);
153 void SetVtxPitmode(uint8_t vtxPitmode
);
154 void SetPowerFanThreshold(uint8_t powerFanThreshold
);
155 void SetFanMode(uint8_t fanMode
);
156 void SetMotionMode(uint8_t motionMode
);
157 void SetDvrAux(uint8_t dvrAux
);
158 void SetDvrStartDelay(uint8_t dvrStartDelay
);
159 void SetDvrStopDelay(uint8_t dvrStopDelay
);
160 void SetButtonActions(uint8_t button
, tx_button_color_t actions
[2]);
161 void SetBackpackDisable(bool backpackDisable
);
162 void SetBackpackTlmMode(uint8_t mode
);
163 void SetPTRStartChannel(uint8_t ptrStartChannel
);
164 void SetPTREnableChannel(uint8_t ptrEnableChannel
);
167 bool SetModelId(uint8_t modelId
);
170 #if !defined(PLATFORM_ESP32)
171 void UpgradeEepromV5ToV6();
172 void UpgradeEepromV6ToV7();
173 void UpgradeEepromV7ToV8();
176 tx_config_t m_config
;
177 ELRS_EEPROM
*m_eeprom
;
179 model_config_t
*m_model
;
181 #if defined(PLATFORM_ESP32)
186 extern TxConfig config
;
190 ///////////////////////////////////////////////////
192 #if defined(TARGET_RX)
193 constexpr uint8_t PWM_MAX_CHANNELS
= 16;
195 typedef enum : uint8_t {
196 BINDSTORAGE_PERSISTENT
= 0,
197 BINDSTORAGE_VOLATILE
= 1,
198 BINDSTORAGE_RETURNABLE
= 2,
199 } rx_config_bindstorage_t
;
203 uint32_t failsafe
:10, // us output during failsafe +988 (e.g. 512 here would be 1500us)
204 inputChannel
:4, // 0-based input channel
205 inverted
:1, // invert channel output
206 mode
:4, // Output mode (eServoOutputMode)
207 narrow
:1, // Narrow output mode (half pulse width)
208 failsafeMode
:2, // failsafe output mode (eServoOutputFailsafeMode)
209 unused
:10; // FUTURE: When someone complains "everyone" uses inverted polarity PWM or something :/
214 typedef struct __attribute__((packed
)) {
216 uint8_t uid
[UID_LEN
];
217 uint8_t unused_padding
;
218 uint8_t serial1Protocol
:4, // secondary serial protocol
219 serial1Protocol_unused
:4;
220 uint32_t flash_discriminator
;
221 struct __attribute__((packed
)) {
222 uint16_t scale
; // FUTURE: Override compiled vbat scale
223 int16_t offset
; // FUTURE: Override comiled vbat offset
225 uint8_t bindStorage
:2, // rx_config_bindstorage_t
227 antennaMode
:2; // 0=0, 1=1, 2=Diversity
228 uint8_t powerOnCounter
:2,
230 rateInitialIdx
:5; // Rate to start rateCycling at on boot
232 uint8_t serialProtocol
:4,
235 rx_config_pwm_t pwmChannels
[PWM_MAX_CHANNELS
] __attribute__((aligned(4)));
236 uint8_t teamraceChannel
:4,
238 teamracePitMode
:1; // FUTURE: Enable pit mode when disabling model
252 bool GetIsBound() const;
253 const uint8_t* GetUID() const { return m_config
.uid
; }
254 #if defined(PLATFORM_ESP8266)
255 uint8_t GetPowerOnCounter() const;
257 uint8_t GetPowerOnCounter() const { return m_config
.powerOnCounter
; }
259 uint8_t GetModelId() const { return m_config
.modelId
; }
260 uint8_t GetPower() const { return m_config
.power
; }
261 uint8_t GetAntennaMode() const { return m_config
.antennaMode
; }
262 bool IsModified() const { return m_modified
; }
263 #if defined(GPIO_PIN_PWM_OUTPUTS)
264 const rx_config_pwm_t
*GetPwmChannel(uint8_t ch
) const { return &m_config
.pwmChannels
[ch
]; }
266 bool GetForceTlmOff() const { return m_config
.forceTlmOff
; }
267 uint8_t GetRateInitialIdx() const { return m_config
.rateInitialIdx
; }
268 eSerialProtocol
GetSerialProtocol() const { return (eSerialProtocol
)m_config
.serialProtocol
; }
269 #if defined(PLATFORM_ESP32)
270 eSerial1Protocol
GetSerial1Protocol() const { return (eSerial1Protocol
)m_config
.serial1Protocol
; }
272 uint8_t GetTeamraceChannel() const { return m_config
.teamraceChannel
; }
273 uint8_t GetTeamracePosition() const { return m_config
.teamracePosition
; }
274 eFailsafeMode
GetFailsafeMode() const { return (eFailsafeMode
)m_config
.failsafeMode
; }
275 uint8_t GetTargetSysId() const { return m_config
.targetSysId
; }
276 uint8_t GetSourceSysId() const { return m_config
.sourceSysId
; }
277 rx_config_bindstorage_t
GetBindStorage() const { return (rx_config_bindstorage_t
)m_config
.bindStorage
; }
278 bool IsOnLoan() const;
281 void SetUID(uint8_t* uid
);
282 void SetPowerOnCounter(uint8_t powerOnCounter
);
283 void SetModelId(uint8_t modelId
);
284 void SetPower(uint8_t power
);
285 void SetAntennaMode(uint8_t antennaMode
);
286 void SetDefaults(bool commit
);
287 void SetStorageProvider(ELRS_EEPROM
*eeprom
);
288 #if defined(GPIO_PIN_PWM_OUTPUTS)
289 void SetPwmChannel(uint8_t ch
, uint16_t failsafe
, uint8_t inputCh
, bool inverted
, uint8_t mode
, bool narrow
);
290 void SetPwmChannelRaw(uint8_t ch
, uint32_t raw
);
292 void SetForceTlmOff(bool forceTlmOff
);
293 void SetRateInitialIdx(uint8_t rateInitialIdx
);
294 void SetSerialProtocol(eSerialProtocol serialProtocol
);
295 #if defined(PLATFORM_ESP32)
296 void SetSerial1Protocol(eSerial1Protocol serial1Protocol
);
298 void SetTeamraceChannel(uint8_t teamraceChannel
);
299 void SetTeamracePosition(uint8_t teamracePosition
);
300 void SetFailsafeMode(eFailsafeMode failsafeMode
);
301 void SetTargetSysId(uint8_t sysID
);
302 void SetSourceSysId(uint8_t sysID
);
303 void SetBindStorage(rx_config_bindstorage_t value
);
307 void CheckUpdateFlashedUid(bool skipDescrimCheck
);
308 void UpgradeUid(uint8_t *onLoanUid
, uint8_t *boundUid
);
309 void UpgradeEepromV4();
310 void UpgradeEepromV5();
311 void UpgradeEepromV6();
312 void UpgradeEepromV7V8();
313 void UpgradeEepromV9();
315 rx_config_t m_config
;
316 ELRS_EEPROM
*m_eeprom
;
320 extern RxConfig config
;