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 0x3FF
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_XY_MASK ((1 << OSD_POSITION_BITS) - 1)
76 #define OSD_TYPE_MASK 0xC000 // bits 14-15
77 #define OSD_POS(x,y) ((x & OSD_POSITION_XY_MASK) | ((y & OSD_POSITION_XY_MASK) << OSD_POSITION_BITS))
78 #define OSD_X(x) (x & OSD_POSITION_XY_MASK)
79 #define OSD_Y(x) ((x >> OSD_POSITION_BITS) & OSD_POSITION_XY_MASK)
80 #define OSD_TYPE(x) ((x & OSD_TYPE_MASK) >> 14)
82 // Timer configuration
83 // Stored as 15[alarm:8][precision:4][source:4]0
84 #define OSD_TIMER(src, prec, alarm) ((src & 0x0F) | ((prec & 0x0F) << 4) | ((alarm & 0xFF ) << 8))
85 #define OSD_TIMER_SRC(timer) (timer & 0x0F)
86 #define OSD_TIMER_PRECISION(timer) ((timer >> 4) & 0x0F)
87 #define OSD_TIMER_ALARM(timer) ((timer >> 8) & 0xFF)
90 #define OSD_DRAW_FREQ_DENOM 5
92 // MWOSD @ 115200 baud
93 #define OSD_DRAW_FREQ_DENOM 10
96 // NB: to ensure backwards compatibility, new enum values must be appended at the end but before the OSD_XXXX_COUNT entry.
99 // See the information at the top of osd/osd_elements.c for instructions
100 // on how to add OSD elements.
103 OSD_MAIN_BATT_VOLTAGE
,
105 OSD_ARTIFICIAL_HORIZON
,
106 OSD_HORIZON_SIDEBARS
,
124 OSD_AVG_CELL_VOLTAGE
,
134 OSD_NUMERICAL_HEADING
,
139 OSD_REMAINING_TIME_ESTIMATE
,
141 OSD_ADJUSTMENT_RANGE
,
142 OSD_CORE_TEMPERATURE
,
150 OSD_STICK_OVERLAY_LEFT
,
151 OSD_STICK_OVERLAY_RIGHT
,
154 OSD_RATE_PROFILE_NAME
,
155 OSD_PID_PROFILE_NAME
,
162 OSD_UP_DOWN_REFERENCE
,
164 OSD_ITEM_COUNT
// MUST BE LAST
168 // Whenever new elements are added to 'osd_items_e', make sure to increment
169 // the parameter group version for 'osdConfig' in 'osd.c'
172 // DO NOT REORDER THE STATS ENUMERATION. The order here cooresponds to the enabled flag bit position
173 // storage and changing the order will corrupt user settings. Any new stats MUST be added to the end
174 // just before the OSD_STAT_COUNT entry. YOU MUST ALSO add the new stat to the
175 // osdStatsDisplayOrder array in osd.c.
177 // IF YOU WANT TO REORDER THE STATS DISPLAY, then adjust the ordering of the osdStatsDisplayOrder array
179 OSD_STAT_RTC_DATE_TIME
,
183 OSD_STAT_MAX_DISTANCE
,
184 OSD_STAT_MIN_BATTERY
,
185 OSD_STAT_END_BATTERY
,
188 OSD_STAT_MAX_CURRENT
,
190 OSD_STAT_MAX_ALTITUDE
,
192 OSD_STAT_BLACKBOX_NUMBER
,
193 OSD_STAT_MAX_G_FORCE
,
194 OSD_STAT_MAX_ESC_TEMP
,
195 OSD_STAT_MAX_ESC_RPM
,
196 OSD_STAT_MIN_LINK_QUALITY
,
197 OSD_STAT_FLIGHT_DISTANCE
,
199 OSD_STAT_TOTAL_FLIGHTS
,
202 OSD_STAT_MIN_RSSI_DBM
,
203 OSD_STAT_COUNT
// MUST BE LAST
206 // Make sure the number of stats do not exceed the available 32bit storage
207 STATIC_ASSERT(OSD_STAT_COUNT
<= 32, osdstats_overflow
);
217 OSD_TIMER_SRC_TOTAL_ARMED
,
218 OSD_TIMER_SRC_LAST_ARMED
,
219 OSD_TIMER_SRC_ON_OR_ARMED
,
221 } osd_timer_source_e
;
224 OSD_TIMER_PREC_SECOND
,
225 OSD_TIMER_PREC_HUNDREDTHS
,
226 OSD_TIMER_PREC_TENTHS
,
228 } osd_timer_precision_e
;
231 OSD_WARNING_ARMING_DISABLE
,
232 OSD_WARNING_BATTERY_NOT_FULL
,
233 OSD_WARNING_BATTERY_WARNING
,
234 OSD_WARNING_BATTERY_CRITICAL
,
235 OSD_WARNING_VISUAL_BEEPER
,
236 OSD_WARNING_CRASH_FLIP
,
237 OSD_WARNING_ESC_FAIL
,
238 OSD_WARNING_CORE_TEMPERATURE
,
239 OSD_WARNING_RC_SMOOTHING
,
240 OSD_WARNING_FAIL_SAFE
,
241 OSD_WARNING_LAUNCH_CONTROL
,
242 OSD_WARNING_GPS_RESCUE_UNAVAILABLE
,
243 OSD_WARNING_GPS_RESCUE_DISABLED
,
245 OSD_WARNING_LINK_QUALITY
,
246 OSD_WARNING_RSSI_DBM
,
247 OSD_WARNING_OVER_CAP
,
248 OSD_WARNING_COUNT
// MUST BE LAST
249 } osdWarningsFlags_e
;
252 OSD_DISPLAYPORT_DEVICE_NONE
= 0,
253 OSD_DISPLAYPORT_DEVICE_AUTO
,
254 OSD_DISPLAYPORT_DEVICE_MAX7456
,
255 OSD_DISPLAYPORT_DEVICE_MSP
,
256 OSD_DISPLAYPORT_DEVICE_FRSKYOSD
,
257 } osdDisplayPortDevice_e
;
259 // Make sure the number of warnings do not exceed the available 32bit storage
260 STATIC_ASSERT(OSD_WARNING_COUNT
<= 32, osdwarnings_overflow
);
262 #define ESC_RPM_ALARM_OFF -1
263 #define ESC_TEMP_ALARM_OFF INT8_MIN
264 #define ESC_CURRENT_ALARM_OFF -1
266 #define OSD_GPS_RESCUE_DISABLED_WARNING_DURATION_US 3000000 // 3 seconds
268 extern const uint16_t osdTimerDefault
[OSD_TIMER_COUNT
];
269 extern const osd_stats_e osdStatsDisplayOrder
[OSD_STAT_COUNT
];
271 typedef struct osdConfig_s
{
279 uint16_t timers
[OSD_TIMER_COUNT
];
280 uint32_t enabledWarnings
;
284 uint32_t enabled_stats
;
285 int8_t esc_temp_alarm
;
286 int16_t esc_rpm_alarm
;
287 int16_t esc_current_alarm
;
288 uint8_t core_temp_alarm
;
289 uint8_t ahInvert
; // invert the artificial horizon
290 uint8_t osdProfileIndex
;
291 uint8_t overlay_radio_mode
;
292 char profile
[OSD_PROFILE_COUNT
][OSD_PROFILE_NAME_LENGTH
+ 1];
293 uint16_t link_quality_alarm
;
294 int16_t rssi_dbm_alarm
;
295 uint8_t gps_sats_show_hdop
;
296 int8_t rcChannels
[OSD_RCCHANNELS_COUNT
]; // RC channel values to display, -1 if none
297 uint8_t displayPortDevice
; // osdDisplayPortDevice_e
298 uint16_t distance_alarm
;
299 uint8_t logo_on_arming
; // show the logo on arming
300 uint8_t logo_on_arming_duration
; // display duration in 0.1s units
301 uint8_t camera_frame_width
; // The width of the box for the camera frame element
302 uint8_t camera_frame_height
; // The height of the box for the camera frame element
303 uint16_t framerate_hz
;
304 uint8_t cms_background_type
; // For supporting devices, determines whether the CMS background is transparent or opaque
305 uint8_t stat_show_cell_value
;
308 PG_DECLARE(osdConfig_t
, osdConfig
);
310 typedef struct osdElementConfig_s
{
311 uint16_t item_pos
[OSD_ITEM_COUNT
];
312 } osdElementConfig_t
;
314 PG_DECLARE(osdElementConfig_t
, osdElementConfig
);
316 typedef struct statistic_s
{
319 int16_t min_voltage
; // /100
320 uint16_t end_voltage
;
321 int16_t max_current
; // /10
323 int32_t max_altitude
;
324 int16_t max_distance
;
326 int16_t max_esc_temp
;
328 uint16_t min_link_quality
;
329 int16_t min_rssi_dbm
;
332 extern timeUs_t resumeRefreshAt
;
333 extern timeUs_t osdFlyTime
;
335 extern float osdGForce
;
337 #ifdef USE_ESC_SENSOR
338 extern escSensorData_t
*osdEscDataCombined
;
341 void osdInit(displayPort_t
*osdDisplayPort
, osdDisplayPortDevice_e displayPortDevice
);
342 bool osdUpdateCheck(timeUs_t currentTimeUs
, timeDelta_t currentDeltaTimeUs
);
343 void osdUpdate(timeUs_t currentTimeUs
);
345 void osdStatSetState(uint8_t statIndex
, bool enabled
);
346 bool osdStatGetState(uint8_t statIndex
);
347 void osdSuppressStats(bool flag
);
348 void osdAnalyzeActiveElements(void);
349 void changeOsdProfileIndex(uint8_t profileIndex
);
350 uint8_t getCurrentOsdProfileIndex(void);
351 displayPort_t
*osdGetDisplayPort(osdDisplayPortDevice_e
*displayPortDevice
);
353 void osdWarnSetState(uint8_t warningIndex
, bool enabled
);
354 bool osdWarnGetState(uint8_t warningIndex
);
355 bool osdElementVisible(uint16_t value
);
356 bool osdGetVisualBeeperState(void);
357 statistic_t
*osdGetStats(void);
358 bool osdNeedsAccelerometer(void);
359 int osdPrintFloat(char *buffer
, char leadingSymbol
, float value
, char *formatString
, unsigned decimalPlaces
, bool round
, char trailingSymbol
);