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"
26 #define OSD_NUM_TIMER_TYPES 3
27 extern const char * const osdTimerSourceNames
[OSD_NUM_TIMER_TYPES
];
29 #define OSD_ELEMENT_BUFFER_LENGTH 32
31 #define VISIBLE_FLAG 0x0800
32 #define VISIBLE(x) (x & VISIBLE_FLAG)
33 #define OSD_POS_MAX 0x3FF
34 #define OSD_POSCFG_MAX (VISIBLE_FLAG|0x3FF) // For CLI values
36 // Character coordinate
37 #define OSD_POSITION_BITS 5 // 5 bits gives a range 0-31
38 #define OSD_POSITION_XY_MASK ((1 << OSD_POSITION_BITS) - 1)
39 #define OSD_POS(x,y) ((x & OSD_POSITION_XY_MASK) | ((y & OSD_POSITION_XY_MASK) << OSD_POSITION_BITS))
40 #define OSD_X(x) (x & OSD_POSITION_XY_MASK)
41 #define OSD_Y(x) ((x >> OSD_POSITION_BITS) & OSD_POSITION_XY_MASK)
43 // Timer configuration
44 // Stored as 15[alarm:8][precision:4][source:4]0
45 #define OSD_TIMER(src, prec, alarm) ((src & 0x0F) | ((prec & 0x0F) << 4) | ((alarm & 0xFF ) << 8))
46 #define OSD_TIMER_SRC(timer) (timer & 0x0F)
47 #define OSD_TIMER_PRECISION(timer) ((timer >> 4) & 0x0F)
48 #define OSD_TIMER_ALARM(timer) ((timer >> 8) & 0xFF)
50 // NB: to ensure backwards compatibility, new enum values must be appended at the end but before the OSD_XXXX_COUNT entry.
53 // If you are adding additional elements that do not require any conditional display logic,
54 // you must add the elements to the osdElementDisplayOrder[] array in src/main/io/osd.c
57 OSD_MAIN_BATT_VOLTAGE
,
59 OSD_ARTIFICIAL_HORIZON
,
88 OSD_NUMERICAL_HEADING
,
93 OSD_REMAINING_TIME_ESTIMATE
,
98 OSD_ITEM_COUNT
// MUST BE LAST
102 // The order of the OSD stats enumeration *must* match the order they're displayed on-screen
103 // This is because the fields are presented in the configurator in the order of the enumeration
104 // and we want the configuration order to match the on-screen display order.
105 // Changes to the stats display order *must* be implemented in the configurator otherwise the
106 // stats selections will not be populated correctly and the settings will become corrupted.
108 // Also - if the stats are reordered then the PR version must be incremented. Otherwise there
109 // is no indication that the stored config must be reset and the bitmapped values will be incorrect.
111 OSD_STAT_RTC_DATE_TIME
,
115 OSD_STAT_MAX_DISTANCE
,
116 OSD_STAT_MIN_BATTERY
,
117 OSD_STAT_END_BATTERY
,
120 OSD_STAT_MAX_CURRENT
,
122 OSD_STAT_MAX_ALTITUDE
,
124 OSD_STAT_BLACKBOX_NUMBER
,
125 OSD_STAT_COUNT
// MUST BE LAST
128 // Make sure the number of stats do not exceed the available 32bit storage
129 STATIC_ASSERT(OSD_STAT_COUNT
<= 32, osdstats_overflow
);
144 OSD_TIMER_SRC_TOTAL_ARMED
,
145 OSD_TIMER_SRC_LAST_ARMED
,
147 } osd_timer_source_e
;
150 OSD_TIMER_PREC_SECOND
,
151 OSD_TIMER_PREC_HUNDREDTHS
,
153 } osd_timer_precision_e
;
156 OSD_WARNING_ARMING_DISABLE
,
157 OSD_WARNING_BATTERY_NOT_FULL
,
158 OSD_WARNING_BATTERY_WARNING
,
159 OSD_WARNING_BATTERY_CRITICAL
,
160 OSD_WARNING_VISUAL_BEEPER
,
161 OSD_WARNING_CRASH_FLIP
,
162 OSD_WARNING_ESC_FAIL
,
163 OSD_WARNING_CORE_TEMPERATURE
,
164 OSD_WARNING_RC_SMOOTHING
,
165 OSD_WARNING_COUNT
// MUST BE LAST
166 } osdWarningsFlags_e
;
168 // Make sure the number of warnings do not exceed the available 16bit storage
169 STATIC_ASSERT(OSD_WARNING_COUNT
<= 16, osdwarnings_overflow
);
171 #define ESC_RPM_ALARM_OFF -1
172 #define ESC_TEMP_ALARM_OFF INT8_MIN
173 #define ESC_CURRENT_ALARM_OFF -1
175 typedef struct osdConfig_s
{
176 uint16_t item_pos
[OSD_ITEM_COUNT
];
185 uint16_t timers
[OSD_TIMER_COUNT
];
186 uint16_t enabledWarnings
;
190 uint32_t enabled_stats
;
191 int8_t esc_temp_alarm
;
192 int16_t esc_rpm_alarm
;
193 int16_t esc_current_alarm
;
194 uint8_t core_temp_alarm
;
197 PG_DECLARE(osdConfig_t
, osdConfig
);
199 extern timeUs_t resumeRefreshAt
;
201 struct displayPort_s
;
202 void osdInit(struct displayPort_s
*osdDisplayPort
);
203 void osdResetAlarms(void);
204 void osdUpdate(timeUs_t currentTimeUs
);
205 void osdStatSetState(uint8_t statIndex
, bool enabled
);
206 bool osdStatGetState(uint8_t statIndex
);
207 void osdWarnSetState(uint8_t warningIndex
, bool enabled
);
208 bool osdWarnGetState(uint8_t warningIndex
);