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"
25 #include "drivers/display.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
41 #define OSD_PROFILE_COUNT 1
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)))
63 #define VISIBLE(x) ((x) & OSD_PROFILE_MASK)
64 #define VISIBLE_IN_OSD_PROFILE(item, profile) VISIBLE(item)
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.
85 // See the information at the top of osd/osd_elements.c for instructions
86 // on how to add OSD elements.
89 OSD_MAIN_BATT_VOLTAGE
,
91 OSD_ARTIFICIAL_HORIZON
,
110 OSD_AVG_CELL_VOLTAGE
,
120 OSD_NUMERICAL_HEADING
,
125 OSD_REMAINING_TIME_ESTIMATE
,
127 OSD_ADJUSTMENT_RANGE
,
128 OSD_CORE_TEMPERATURE
,
136 OSD_STICK_OVERLAY_LEFT
,
137 OSD_STICK_OVERLAY_RIGHT
,
140 OSD_RATE_PROFILE_NAME
,
141 OSD_PID_PROFILE_NAME
,
146 OSD_ITEM_COUNT
// MUST BE LAST
150 // Whenever new elements are added to 'osd_items_e', make sure to increment
151 // the parameter group version for 'osdConfig' in 'osd.c'
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
161 OSD_STAT_RTC_DATE_TIME
,
165 OSD_STAT_MAX_DISTANCE
,
166 OSD_STAT_MIN_BATTERY
,
167 OSD_STAT_END_BATTERY
,
170 OSD_STAT_MAX_CURRENT
,
172 OSD_STAT_MAX_ALTITUDE
,
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
,
181 OSD_STAT_TOTAL_FLIGHTS
,
184 OSD_STAT_MIN_RSSI_DBM
,
185 OSD_STAT_COUNT
// MUST BE LAST
188 // Make sure the number of stats do not exceed the available 32bit storage
189 STATIC_ASSERT(OSD_STAT_COUNT
<= 32, osdstats_overflow
);
204 OSD_TIMER_SRC_TOTAL_ARMED
,
205 OSD_TIMER_SRC_LAST_ARMED
,
206 OSD_TIMER_SRC_ON_OR_ARMED
,
208 } osd_timer_source_e
;
211 OSD_TIMER_PREC_SECOND
,
212 OSD_TIMER_PREC_HUNDREDTHS
,
213 OSD_TIMER_PREC_TENTHS
,
215 } osd_timer_precision_e
;
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
,
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
;
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
{
266 uint16_t timers
[OSD_TIMER_COUNT
];
267 uint32_t enabledWarnings
;
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
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
{
303 int16_t min_voltage
; // /100
304 uint16_t end_voltage
;
305 int16_t max_current
; // /10
307 int32_t max_altitude
;
308 int16_t max_distance
;
310 int16_t max_esc_temp
;
312 uint16_t min_link_quality
;
313 int16_t min_rssi_dbm
;
316 extern timeUs_t resumeRefreshAt
;
317 extern timeUs_t osdFlyTime
;
319 extern float osdGForce
;
321 #ifdef USE_ESC_SENSOR
322 extern escSensorData_t
*osdEscDataCombined
;
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
);