Added option to display RX SNR dB for CRSF instead of RSSI dBm.
[betaflight.git] / src / main / osd / osd.h
blobfd3b197fc960b067230beac154d9643246a98038
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 "common/time.h"
25 #include "drivers/display.h"
27 #include "pg/pg.h"
29 #include "sensors/esc_sensor.h"
31 #define OSD_NUM_TIMER_TYPES 4
32 extern const char * const osdTimerSourceNames[OSD_NUM_TIMER_TYPES];
34 #define OSD_ELEMENT_BUFFER_LENGTH 32
36 #define OSD_PROFILE_NAME_LENGTH 16
38 #ifdef USE_OSD_PROFILES
39 #define OSD_PROFILE_COUNT 3
40 #else
41 #define OSD_PROFILE_COUNT 1
42 #endif
44 #define OSD_RCCHANNELS_COUNT 4
46 #define OSD_CAMERA_FRAME_MIN_WIDTH 2
47 #define OSD_CAMERA_FRAME_MAX_WIDTH 30 // Characters per row supportes by MAX7456
48 #define OSD_CAMERA_FRAME_MIN_HEIGHT 2
49 #define OSD_CAMERA_FRAME_MAX_HEIGHT 16 // Rows supported by MAX7456 (PAL)
51 #define OSD_PROFILE_BITS_POS 11
52 #define OSD_PROFILE_MASK (((1 << OSD_PROFILE_COUNT) - 1) << OSD_PROFILE_BITS_POS)
53 #define OSD_POS_MAX 0x3FF
54 #define OSD_POSCFG_MAX (OSD_PROFILE_MASK | 0x3FF) // For CLI values
55 #define OSD_PROFILE_FLAG(x) (1 << ((x) - 1 + OSD_PROFILE_BITS_POS))
56 #define OSD_PROFILE_1_FLAG OSD_PROFILE_FLAG(1)
59 #ifdef USE_OSD_PROFILES
60 #define VISIBLE(x) osdElementVisible(x)
61 #define VISIBLE_IN_OSD_PROFILE(item, profile) ((item) & ((OSD_PROFILE_1_FLAG) << ((profile)-1)))
62 #else
63 #define VISIBLE(x) ((x) & OSD_PROFILE_MASK)
64 #define VISIBLE_IN_OSD_PROFILE(item, profile) VISIBLE(item)
65 #endif
68 // Character coordinate
69 #define OSD_POSITION_BITS 5 // 5 bits gives a range 0-31
70 #define OSD_POSITION_XY_MASK ((1 << OSD_POSITION_BITS) - 1)
71 #define OSD_POS(x,y) ((x & OSD_POSITION_XY_MASK) | ((y & OSD_POSITION_XY_MASK) << OSD_POSITION_BITS))
72 #define OSD_X(x) (x & OSD_POSITION_XY_MASK)
73 #define OSD_Y(x) ((x >> OSD_POSITION_BITS) & OSD_POSITION_XY_MASK)
75 // Timer configuration
76 // Stored as 15[alarm:8][precision:4][source:4]0
77 #define OSD_TIMER(src, prec, alarm) ((src & 0x0F) | ((prec & 0x0F) << 4) | ((alarm & 0xFF ) << 8))
78 #define OSD_TIMER_SRC(timer) (timer & 0x0F)
79 #define OSD_TIMER_PRECISION(timer) ((timer >> 4) & 0x0F)
80 #define OSD_TIMER_ALARM(timer) ((timer >> 8) & 0xFF)
82 // NB: to ensure backwards compatibility, new enum values must be appended at the end but before the OSD_XXXX_COUNT entry.
84 // *** IMPORTANT ***
85 // See the information at the top of osd/osd_elements.c for instructions
86 // on how to add OSD elements.
87 typedef enum {
88 OSD_RSSI_VALUE,
89 OSD_MAIN_BATT_VOLTAGE,
90 OSD_CROSSHAIRS,
91 OSD_ARTIFICIAL_HORIZON,
92 OSD_HORIZON_SIDEBARS,
93 OSD_ITEM_TIMER_1,
94 OSD_ITEM_TIMER_2,
95 OSD_FLYMODE,
96 OSD_CRAFT_NAME,
97 OSD_THROTTLE_POS,
98 OSD_VTX_CHANNEL,
99 OSD_CURRENT_DRAW,
100 OSD_MAH_DRAWN,
101 OSD_GPS_SPEED,
102 OSD_GPS_SATS,
103 OSD_ALTITUDE,
104 OSD_ROLL_PIDS,
105 OSD_PITCH_PIDS,
106 OSD_YAW_PIDS,
107 OSD_POWER,
108 OSD_PIDRATE_PROFILE,
109 OSD_WARNINGS,
110 OSD_AVG_CELL_VOLTAGE,
111 OSD_GPS_LON,
112 OSD_GPS_LAT,
113 OSD_DEBUG,
114 OSD_PITCH_ANGLE,
115 OSD_ROLL_ANGLE,
116 OSD_MAIN_BATT_USAGE,
117 OSD_DISARMED,
118 OSD_HOME_DIR,
119 OSD_HOME_DIST,
120 OSD_NUMERICAL_HEADING,
121 OSD_NUMERICAL_VARIO,
122 OSD_COMPASS_BAR,
123 OSD_ESC_TMP,
124 OSD_ESC_RPM,
125 OSD_REMAINING_TIME_ESTIMATE,
126 OSD_RTC_DATETIME,
127 OSD_ADJUSTMENT_RANGE,
128 OSD_CORE_TEMPERATURE,
129 OSD_ANTI_GRAVITY,
130 OSD_G_FORCE,
131 OSD_MOTOR_DIAG,
132 OSD_LOG_STATUS,
133 OSD_FLIP_ARROW,
134 OSD_LINK_QUALITY,
135 OSD_FLIGHT_DIST,
136 OSD_STICK_OVERLAY_LEFT,
137 OSD_STICK_OVERLAY_RIGHT,
138 OSD_DISPLAY_NAME,
139 OSD_ESC_RPM_FREQ,
140 OSD_RATE_PROFILE_NAME,
141 OSD_PID_PROFILE_NAME,
142 OSD_PROFILE_NAME,
143 OSD_RSSI_DBM_VALUE,
144 OSD_RC_CHANNELS,
145 OSD_CAMERA_FRAME,
146 OSD_ITEM_COUNT // MUST BE LAST
147 } osd_items_e;
149 // *** IMPORTANT ***
150 // Whenever new elements are added to 'osd_items_e', make sure to increment
151 // the parameter group version for 'osdConfig' in 'osd.c'
153 // *** IMPORTANT ***
154 // DO NOT REORDER THE STATS ENUMERATION. The order here cooresponds to the enabled flag bit position
155 // storage and changing the order will corrupt user settings. Any new stats MUST be added to the end
156 // just before the OSD_STAT_COUNT entry. YOU MUST ALSO add the new stat to the
157 // osdStatsDisplayOrder array in osd.c.
159 // IF YOU WANT TO REORDER THE STATS DISPLAY, then adjust the ordering of the osdStatsDisplayOrder array
160 typedef enum {
161 OSD_STAT_RTC_DATE_TIME,
162 OSD_STAT_TIMER_1,
163 OSD_STAT_TIMER_2,
164 OSD_STAT_MAX_SPEED,
165 OSD_STAT_MAX_DISTANCE,
166 OSD_STAT_MIN_BATTERY,
167 OSD_STAT_END_BATTERY,
168 OSD_STAT_BATTERY,
169 OSD_STAT_MIN_RSSI,
170 OSD_STAT_MAX_CURRENT,
171 OSD_STAT_USED_MAH,
172 OSD_STAT_MAX_ALTITUDE,
173 OSD_STAT_BLACKBOX,
174 OSD_STAT_BLACKBOX_NUMBER,
175 OSD_STAT_MAX_G_FORCE,
176 OSD_STAT_MAX_ESC_TEMP,
177 OSD_STAT_MAX_ESC_RPM,
178 OSD_STAT_MIN_LINK_QUALITY,
179 OSD_STAT_FLIGHT_DISTANCE,
180 OSD_STAT_MAX_FFT,
181 OSD_STAT_TOTAL_FLIGHTS,
182 OSD_STAT_TOTAL_TIME,
183 OSD_STAT_TOTAL_DIST,
184 OSD_STAT_MIN_RSSI_DBM,
185 OSD_STAT_COUNT // MUST BE LAST
186 } osd_stats_e;
188 // Make sure the number of stats do not exceed the available 32bit storage
189 STATIC_ASSERT(OSD_STAT_COUNT <= 32, osdstats_overflow);
191 typedef enum {
192 OSD_UNIT_IMPERIAL,
193 OSD_UNIT_METRIC
194 } osd_unit_e;
196 typedef enum {
197 OSD_TIMER_1,
198 OSD_TIMER_2,
199 OSD_TIMER_COUNT
200 } osd_timer_e;
202 typedef enum {
203 OSD_TIMER_SRC_ON,
204 OSD_TIMER_SRC_TOTAL_ARMED,
205 OSD_TIMER_SRC_LAST_ARMED,
206 OSD_TIMER_SRC_ON_OR_ARMED,
207 OSD_TIMER_SRC_COUNT
208 } osd_timer_source_e;
210 typedef enum {
211 OSD_TIMER_PREC_SECOND,
212 OSD_TIMER_PREC_HUNDREDTHS,
213 OSD_TIMER_PREC_TENTHS,
214 OSD_TIMER_PREC_COUNT
215 } osd_timer_precision_e;
217 typedef enum {
218 OSD_WARNING_ARMING_DISABLE,
219 OSD_WARNING_BATTERY_NOT_FULL,
220 OSD_WARNING_BATTERY_WARNING,
221 OSD_WARNING_BATTERY_CRITICAL,
222 OSD_WARNING_VISUAL_BEEPER,
223 OSD_WARNING_CRASH_FLIP,
224 OSD_WARNING_ESC_FAIL,
225 OSD_WARNING_CORE_TEMPERATURE,
226 OSD_WARNING_RC_SMOOTHING,
227 OSD_WARNING_FAIL_SAFE,
228 OSD_WARNING_LAUNCH_CONTROL,
229 OSD_WARNING_GPS_RESCUE_UNAVAILABLE,
230 OSD_WARNING_GPS_RESCUE_DISABLED,
231 OSD_WARNING_RSSI,
232 OSD_WARNING_LINK_QUALITY,
233 OSD_WARNING_RSSI_DBM,
234 OSD_WARNING_OVER_CAP,
235 OSD_WARNING_COUNT // MUST BE LAST
236 } osdWarningsFlags_e;
238 typedef enum {
239 OSD_DISPLAYPORT_DEVICE_NONE = 0,
240 OSD_DISPLAYPORT_DEVICE_AUTO,
241 OSD_DISPLAYPORT_DEVICE_MAX7456,
242 OSD_DISPLAYPORT_DEVICE_MSP,
243 OSD_DISPLAYPORT_DEVICE_FRSKYOSD,
244 } osdDisplayPortDevice_e;
246 // Make sure the number of warnings do not exceed the available 32bit storage
247 STATIC_ASSERT(OSD_WARNING_COUNT <= 32, osdwarnings_overflow);
249 #define ESC_RPM_ALARM_OFF -1
250 #define ESC_TEMP_ALARM_OFF INT8_MIN
251 #define ESC_CURRENT_ALARM_OFF -1
253 #define OSD_GPS_RESCUE_DISABLED_WARNING_DURATION_US 3000000 // 3 seconds
255 extern const uint16_t osdTimerDefault[OSD_TIMER_COUNT];
256 extern const osd_stats_e osdStatsDisplayOrder[OSD_STAT_COUNT];
258 typedef struct osdConfig_s {
259 // Alarms
260 uint16_t cap_alarm;
261 uint16_t alt_alarm;
262 uint8_t rssi_alarm;
264 osd_unit_e units;
266 uint16_t timers[OSD_TIMER_COUNT];
267 uint32_t enabledWarnings;
269 uint8_t ahMaxPitch;
270 uint8_t ahMaxRoll;
271 uint32_t enabled_stats;
272 int8_t esc_temp_alarm;
273 int16_t esc_rpm_alarm;
274 int16_t esc_current_alarm;
275 uint8_t core_temp_alarm;
276 uint8_t ahInvert; // invert the artificial horizon
277 uint8_t osdProfileIndex;
278 uint8_t overlay_radio_mode;
279 char profile[OSD_PROFILE_COUNT][OSD_PROFILE_NAME_LENGTH + 1];
280 uint16_t link_quality_alarm;
281 int16_t rssi_dbm_alarm;
282 uint8_t gps_sats_show_hdop;
283 int8_t rcChannels[OSD_RCCHANNELS_COUNT]; // RC channel values to display, -1 if none
284 uint8_t displayPortDevice; // osdDisplayPortDevice_e
285 uint16_t distance_alarm;
286 uint8_t logo_on_arming; // show the logo on arming
287 uint8_t logo_on_arming_duration; // display duration in 0.1s units
288 uint8_t camera_frame_width; // The width of the box for the camera frame element
289 uint8_t camera_frame_height; // The height of the box for the camera frame element
290 } osdConfig_t;
292 PG_DECLARE(osdConfig_t, osdConfig);
294 typedef struct osdElementConfig_s {
295 uint16_t item_pos[OSD_ITEM_COUNT];
296 } osdElementConfig_t;
298 PG_DECLARE(osdElementConfig_t, osdElementConfig);
300 typedef struct statistic_s {
301 timeUs_t armed_time;
302 int16_t max_speed;
303 int16_t min_voltage; // /100
304 uint16_t end_voltage;
305 int16_t max_current; // /10
306 uint8_t min_rssi;
307 int32_t max_altitude;
308 int16_t max_distance;
309 float max_g_force;
310 int16_t max_esc_temp;
311 int32_t max_esc_rpm;
312 uint16_t min_link_quality;
313 int16_t min_rssi_dbm;
314 } statistic_t;
316 extern timeUs_t resumeRefreshAt;
317 extern timeUs_t osdFlyTime;
318 #if defined(USE_ACC)
319 extern float osdGForce;
320 #endif
321 #ifdef USE_ESC_SENSOR
322 extern escSensorData_t *osdEscDataCombined;
323 #endif
325 void osdInit(displayPort_t *osdDisplayPort, osdDisplayPortDevice_e displayPortDevice);
326 bool osdInitialized(void);
327 void osdUpdate(timeUs_t currentTimeUs);
328 void osdStatSetState(uint8_t statIndex, bool enabled);
329 bool osdStatGetState(uint8_t statIndex);
330 void osdWarnSetState(uint8_t warningIndex, bool enabled);
331 bool osdWarnGetState(uint8_t warningIndex);
332 void osdSuppressStats(bool flag);
334 void osdAnalyzeActiveElements(void);
335 uint8_t getCurrentOsdProfileIndex(void);
336 void changeOsdProfileIndex(uint8_t profileIndex);
337 bool osdElementVisible(uint16_t value);
338 bool osdGetVisualBeeperState(void);
339 statistic_t *osdGetStats(void);
340 bool osdNeedsAccelerometer(void);
341 displayPort_t *osdGetDisplayPort(osdDisplayPortDevice_e *displayPortDevice);