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/time.h"
24 #include "common/unit.h"
26 #include "drivers/display.h"
30 #include "sensors/esc_sensor.h"
32 #define OSD_NUM_TIMER_TYPES 4
33 extern const char * const osdTimerSourceNames
[OSD_NUM_TIMER_TYPES
];
35 #define OSD_ELEMENT_BUFFER_LENGTH 32
37 #define OSD_PROFILE_NAME_LENGTH 16
39 #ifdef USE_OSD_PROFILES
40 #define OSD_PROFILE_COUNT 3
42 #define OSD_PROFILE_COUNT 1
45 #define OSD_RCCHANNELS_COUNT 4
47 #define OSD_CAMERA_FRAME_MIN_WIDTH 2
48 #define OSD_CAMERA_FRAME_MAX_WIDTH 30 // Characters per row supportes by MAX7456
49 #define OSD_CAMERA_FRAME_MIN_HEIGHT 2
50 #define OSD_CAMERA_FRAME_MAX_HEIGHT 16 // Rows supported by MAX7456 (PAL)
52 #define OSD_FRAMERATE_MIN_HZ 1
53 #define OSD_FRAMERATE_MAX_HZ 60
54 #define OSD_FRAMERATE_DEFAULT_HZ 12
56 #define OSD_PROFILE_BITS_POS 11
57 #define OSD_PROFILE_MASK (((1 << OSD_PROFILE_COUNT) - 1) << OSD_PROFILE_BITS_POS)
58 #define OSD_POS_MAX 0x7FF
59 #define OSD_POSCFG_MAX UINT16_MAX // element positions now use all 16 bits
60 #define OSD_PROFILE_FLAG(x) (1 << ((x) - 1 + OSD_PROFILE_BITS_POS))
61 #define OSD_PROFILE_1_FLAG OSD_PROFILE_FLAG(1)
64 #ifdef USE_OSD_PROFILES
65 #define VISIBLE(x) osdElementVisible(x)
66 #define VISIBLE_IN_OSD_PROFILE(item, profile) ((item) & ((OSD_PROFILE_1_FLAG) << ((profile)-1)))
68 #define VISIBLE(x) ((x) & OSD_PROFILE_MASK)
69 #define VISIBLE_IN_OSD_PROFILE(item, profile) VISIBLE(item)
73 // Character coordinate
74 #define OSD_POSITION_BITS 5 // 5 bits gives a range 0-31
75 #define OSD_POSITION_BIT_XHD 10 // extra bit used to extend X range in a backward compatible manner for HD displays
76 #define OSD_POSITION_XHD_MASK (1 << OSD_POSITION_BIT_XHD)
77 #define OSD_POSITION_XY_MASK ((1 << OSD_POSITION_BITS) - 1)
78 #define OSD_TYPE_MASK 0xC000 // bits 14-15
79 #define OSD_POS(x,y) ((x & OSD_POSITION_XY_MASK) | ((x << (OSD_POSITION_BIT_XHD - OSD_POSITION_BITS)) & OSD_POSITION_XHD_MASK) | \
80 ((y & OSD_POSITION_XY_MASK) << OSD_POSITION_BITS))
81 #define OSD_X(x) ((x & OSD_POSITION_XY_MASK) | ((x & OSD_POSITION_XHD_MASK) >> (OSD_POSITION_BIT_XHD - OSD_POSITION_BITS)))
82 #define OSD_Y(x) ((x >> OSD_POSITION_BITS) & OSD_POSITION_XY_MASK)
83 #define OSD_TYPE(x) ((x & OSD_TYPE_MASK) >> 14)
85 #define OSD_SD_COLS VIDEO_COLUMNS_SD
86 #define OSD_SD_ROWS VIDEO_LINES_PAL
88 // Default HD OSD canvas size to be applied unless the goggles announce otherwise
89 #define OSD_HD_COLS 53
90 #define OSD_HD_ROWS 20
92 // Timer configuration
93 // Stored as 15[alarm:8][precision:4][source:4]0
94 #define OSD_TIMER(src, prec, alarm) ((src & 0x0F) | ((prec & 0x0F) << 4) | ((alarm & 0xFF ) << 8))
95 #define OSD_TIMER_SRC(timer) (timer & 0x0F)
96 #define OSD_TIMER_PRECISION(timer) ((timer >> 4) & 0x0F)
97 #define OSD_TIMER_ALARM(timer) ((timer >> 8) & 0xFF)
100 #define OSD_DRAW_FREQ_DENOM 5
102 // MWOSD @ 115200 baud
103 #define OSD_DRAW_FREQ_DENOM 10
106 // NB: to ensure backwards compatibility, new enum values must be appended at the end but before the OSD_XXXX_COUNT entry.
109 // See the information at the top of osd/osd_elements.c for instructions
110 // on how to add OSD elements.
113 OSD_MAIN_BATT_VOLTAGE
,
115 OSD_ARTIFICIAL_HORIZON
,
116 OSD_HORIZON_SIDEBARS
,
134 OSD_AVG_CELL_VOLTAGE
,
144 OSD_NUMERICAL_HEADING
,
149 OSD_REMAINING_TIME_ESTIMATE
,
151 OSD_ADJUSTMENT_RANGE
,
152 OSD_CORE_TEMPERATURE
,
160 OSD_STICK_OVERLAY_LEFT
,
161 OSD_STICK_OVERLAY_RIGHT
,
164 OSD_RATE_PROFILE_NAME
,
165 OSD_PID_PROFILE_NAME
,
172 OSD_UP_DOWN_REFERENCE
,
174 OSD_WATT_HOURS_DRAWN
,
178 OSD_SYS_GOGGLE_VOLTAGE
,
189 OSD_ITEM_COUNT
// MUST BE LAST
193 // Whenever new elements are added to 'osd_items_e', make sure to increment
194 // the parameter group version for 'osdConfig' in 'osd.c'
197 // DO NOT REORDER THE STATS ENUMERATION. The order here cooresponds to the enabled flag bit position
198 // storage and changing the order will corrupt user settings. Any new stats MUST be added to the end
199 // just before the OSD_STAT_COUNT entry. YOU MUST ALSO add the new stat to the
200 // osdStatsDisplayOrder array in osd.c.
202 // IF YOU WANT TO REORDER THE STATS DISPLAY, then adjust the ordering of the osdStatsDisplayOrder array
204 OSD_STAT_RTC_DATE_TIME
,
208 OSD_STAT_MAX_DISTANCE
,
209 OSD_STAT_MIN_BATTERY
,
210 OSD_STAT_END_BATTERY
,
213 OSD_STAT_MAX_CURRENT
,
215 OSD_STAT_MAX_ALTITUDE
,
217 OSD_STAT_BLACKBOX_NUMBER
,
218 OSD_STAT_MAX_G_FORCE
,
219 OSD_STAT_MAX_ESC_TEMP
,
220 OSD_STAT_MAX_ESC_RPM
,
221 OSD_STAT_MIN_LINK_QUALITY
,
222 OSD_STAT_FLIGHT_DISTANCE
,
224 OSD_STAT_TOTAL_FLIGHTS
,
227 OSD_STAT_MIN_RSSI_DBM
,
228 OSD_STAT_WATT_HOURS_DRAWN
,
230 OSD_STAT_COUNT
// MUST BE LAST
233 // Make sure the number of stats do not exceed the available 32bit storage
234 STATIC_ASSERT(OSD_STAT_COUNT
<= 32, osdstats_overflow
);
244 OSD_TIMER_SRC_TOTAL_ARMED
,
245 OSD_TIMER_SRC_LAST_ARMED
,
246 OSD_TIMER_SRC_ON_OR_ARMED
,
248 } osd_timer_source_e
;
251 OSD_TIMER_PREC_SECOND
,
252 OSD_TIMER_PREC_HUNDREDTHS
,
253 OSD_TIMER_PREC_TENTHS
,
255 } osd_timer_precision_e
;
258 OSD_WARNING_ARMING_DISABLE
,
259 OSD_WARNING_BATTERY_NOT_FULL
,
260 OSD_WARNING_BATTERY_WARNING
,
261 OSD_WARNING_BATTERY_CRITICAL
,
262 OSD_WARNING_VISUAL_BEEPER
,
263 OSD_WARNING_CRASH_FLIP
,
264 OSD_WARNING_ESC_FAIL
,
265 OSD_WARNING_CORE_TEMPERATURE
,
266 OSD_WARNING_RC_SMOOTHING
,
267 OSD_WARNING_FAIL_SAFE
,
268 OSD_WARNING_LAUNCH_CONTROL
,
269 OSD_WARNING_GPS_RESCUE_UNAVAILABLE
,
270 OSD_WARNING_GPS_RESCUE_DISABLED
,
272 OSD_WARNING_LINK_QUALITY
,
273 OSD_WARNING_RSSI_DBM
,
274 OSD_WARNING_OVER_CAP
,
276 OSD_WARNING_COUNT
// MUST BE LAST
277 } osdWarningsFlags_e
;
280 OSD_DISPLAYPORT_DEVICE_NONE
= 0,
281 OSD_DISPLAYPORT_DEVICE_AUTO
,
282 OSD_DISPLAYPORT_DEVICE_MAX7456
,
283 OSD_DISPLAYPORT_DEVICE_MSP
,
284 OSD_DISPLAYPORT_DEVICE_FRSKYOSD
,
285 } osdDisplayPortDevice_e
;
287 // Make sure the number of warnings do not exceed the available 32bit storage
288 STATIC_ASSERT(OSD_WARNING_COUNT
<= 32, osdwarnings_overflow
);
290 #define ESC_RPM_ALARM_OFF -1
291 #define ESC_TEMP_ALARM_OFF 0
292 #define ESC_CURRENT_ALARM_OFF -1
294 #define OSD_GPS_RESCUE_DISABLED_WARNING_DURATION_US 3000000 // 3 seconds
296 extern const uint16_t osdTimerDefault
[OSD_TIMER_COUNT
];
297 extern const osd_stats_e osdStatsDisplayOrder
[OSD_STAT_COUNT
];
299 typedef struct osdConfig_s
{
307 uint16_t timers
[OSD_TIMER_COUNT
];
308 uint32_t enabledWarnings
;
312 uint32_t enabled_stats
;
313 uint8_t esc_temp_alarm
;
314 int16_t esc_rpm_alarm
;
315 int16_t esc_current_alarm
;
316 uint8_t core_temp_alarm
;
317 uint8_t ahInvert
; // invert the artificial horizon
318 uint8_t osdProfileIndex
;
319 uint8_t overlay_radio_mode
;
320 char profile
[OSD_PROFILE_COUNT
][OSD_PROFILE_NAME_LENGTH
+ 1];
321 uint16_t link_quality_alarm
;
322 int16_t rssi_dbm_alarm
;
324 uint8_t gps_sats_show_hdop
;
325 int8_t rcChannels
[OSD_RCCHANNELS_COUNT
]; // RC channel values to display, -1 if none
326 uint8_t displayPortDevice
; // osdDisplayPortDevice_e
327 uint16_t distance_alarm
;
328 uint8_t logo_on_arming
; // show the logo on arming
329 uint8_t logo_on_arming_duration
; // display duration in 0.1s units
330 uint8_t camera_frame_width
; // The width of the box for the camera frame element
331 uint8_t camera_frame_height
; // The height of the box for the camera frame element
332 uint16_t framerate_hz
;
333 uint8_t cms_background_type
; // For supporting devices, determines whether the CMS background is transparent or opaque
334 uint8_t stat_show_cell_value
;
335 #ifdef USE_CRAFTNAME_MSGS
336 uint8_t osd_craftname_msgs
; // Insert LQ/RSSI-dBm and warnings into CraftName
337 #endif //USE_CRAFTNAME_MSGS
341 uint8_t canvas_cols
; // Canvas dimensions for HD display
345 PG_DECLARE(osdConfig_t
, osdConfig
);
347 typedef struct osdElementConfig_s
{
348 uint16_t item_pos
[OSD_ITEM_COUNT
];
349 } osdElementConfig_t
;
351 PG_DECLARE(osdElementConfig_t
, osdElementConfig
);
353 typedef struct statistic_s
{
356 int16_t min_voltage
; // /100
357 uint16_t end_voltage
;
358 int16_t max_current
; // /10
360 int32_t max_altitude
;
361 int16_t max_distance
;
363 int16_t max_esc_temp_ix
;
364 int16_t max_esc_temp
;
366 uint16_t min_link_quality
;
367 int16_t min_rssi_dbm
;
371 extern timeUs_t resumeRefreshAt
;
372 extern timeUs_t osdFlyTime
;
374 extern float osdGForce
;
376 #ifdef USE_ESC_SENSOR
377 extern escSensorData_t
*osdEscDataCombined
;
379 extern uint16_t osdAuxValue
;
381 void osdInit(displayPort_t
*osdDisplayPort
, osdDisplayPortDevice_e displayPortDevice
);
382 bool osdUpdateCheck(timeUs_t currentTimeUs
, timeDelta_t currentDeltaTimeUs
);
383 void osdUpdate(timeUs_t currentTimeUs
);
385 void osdStatSetState(uint8_t statIndex
, bool enabled
);
386 bool osdStatGetState(uint8_t statIndex
);
387 void osdSuppressStats(bool flag
);
388 void osdAnalyzeActiveElements(void);
389 void changeOsdProfileIndex(uint8_t profileIndex
);
390 uint8_t getCurrentOsdProfileIndex(void);
391 displayPort_t
*osdGetDisplayPort(osdDisplayPortDevice_e
*displayPortDevice
);
393 void osdWarnSetState(uint8_t warningIndex
, bool enabled
);
394 bool osdWarnGetState(uint8_t warningIndex
);
395 bool osdElementVisible(uint16_t value
);
396 bool osdGetVisualBeeperState(void);
397 void osdSetVisualBeeperState(bool state
);
398 statistic_t
*osdGetStats(void);
399 bool osdNeedsAccelerometer(void);
400 int osdPrintFloat(char *buffer
, char leadingSymbol
, float value
, char *formatString
, unsigned decimalPlaces
, bool round
, char trailingSymbol
);