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
,
99 OSD_ITEM_COUNT
// MUST BE LAST
103 // The order of the OSD stats enumeration *must* match the order they're displayed on-screen
104 // This is because the fields are presented in the configurator in the order of the enumeration
105 // and we want the configuration order to match the on-screen display order.
106 // Changes to the stats display order *must* be implemented in the configurator otherwise the
107 // stats selections will not be populated correctly and the settings will become corrupted.
109 // Also - if the stats are reordered then the PR version must be incremented. Otherwise there
110 // is no indication that the stored config must be reset and the bitmapped values will be incorrect.
112 OSD_STAT_RTC_DATE_TIME
,
116 OSD_STAT_MAX_DISTANCE
,
117 OSD_STAT_MIN_BATTERY
,
118 OSD_STAT_END_BATTERY
,
121 OSD_STAT_MAX_CURRENT
,
123 OSD_STAT_MAX_ALTITUDE
,
125 OSD_STAT_BLACKBOX_NUMBER
,
126 OSD_STAT_COUNT
// MUST BE LAST
129 // Make sure the number of stats do not exceed the available 32bit storage
130 STATIC_ASSERT(OSD_STAT_COUNT
<= 32, osdstats_overflow
);
145 OSD_TIMER_SRC_TOTAL_ARMED
,
146 OSD_TIMER_SRC_LAST_ARMED
,
148 } osd_timer_source_e
;
151 OSD_TIMER_PREC_SECOND
,
152 OSD_TIMER_PREC_HUNDREDTHS
,
154 } osd_timer_precision_e
;
157 OSD_WARNING_ARMING_DISABLE
,
158 OSD_WARNING_BATTERY_NOT_FULL
,
159 OSD_WARNING_BATTERY_WARNING
,
160 OSD_WARNING_BATTERY_CRITICAL
,
161 OSD_WARNING_VISUAL_BEEPER
,
162 OSD_WARNING_CRASH_FLIP
,
163 OSD_WARNING_ESC_FAIL
,
164 OSD_WARNING_CORE_TEMPERATURE
,
165 OSD_WARNING_RC_SMOOTHING
,
166 OSD_WARNING_COUNT
// MUST BE LAST
167 } osdWarningsFlags_e
;
169 // Make sure the number of warnings do not exceed the available 16bit storage
170 STATIC_ASSERT(OSD_WARNING_COUNT
<= 16, osdwarnings_overflow
);
172 #define ESC_RPM_ALARM_OFF -1
173 #define ESC_TEMP_ALARM_OFF INT8_MIN
174 #define ESC_CURRENT_ALARM_OFF -1
176 typedef struct osdConfig_s
{
177 uint16_t item_pos
[OSD_ITEM_COUNT
];
186 uint16_t timers
[OSD_TIMER_COUNT
];
187 uint16_t enabledWarnings
;
191 uint32_t enabled_stats
;
192 int8_t esc_temp_alarm
;
193 int16_t esc_rpm_alarm
;
194 int16_t esc_current_alarm
;
195 uint8_t core_temp_alarm
;
198 PG_DECLARE(osdConfig_t
, osdConfig
);
200 extern timeUs_t resumeRefreshAt
;
202 struct displayPort_s
;
203 void osdInit(struct displayPort_s
*osdDisplayPort
);
204 void osdResetAlarms(void);
205 void osdUpdate(timeUs_t currentTimeUs
);
206 void osdStatSetState(uint8_t statIndex
, bool enabled
);
207 bool osdStatGetState(uint8_t statIndex
);
208 void osdWarnSetState(uint8_t warningIndex
, bool enabled
);
209 bool osdWarnGetState(uint8_t warningIndex
);