Fix WS2812 led definition
[inav.git] / src / main / cms / cms_types.h
blobd56ff80e55d24f1f1284a332936390fb9254621e
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
19 // Menu element types
20 // XXX Upon separation, all OME would be renamed to CME_ or similar.
23 #pragma once
25 #include <stdint.h>
27 //type of elements
29 typedef enum
31 OME_Label,
32 OME_LabelFunc, // bool func(char *buf, unsigned bufsize) - returns wether buf should be printed
33 OME_Back,
34 OME_OSD_Exit,
35 OME_Submenu,
36 OME_Funcall,
37 OME_Bool,
38 OME_BoolFunc, // bool func(bool*):
39 OME_INT8,
40 OME_UINT8,
41 OME_UINT16,
42 OME_INT16,
43 OME_String,
44 OME_FLOAT, //only up to 255 value and cant be 2.55 or 25.5, just for PID's
45 OME_Setting,
46 //wlasciwosci elementow
47 OME_TAB,
48 OME_END,
49 OME_BACK_AND_END,
51 // Debug aid
52 OME_MENU,
54 OME_MAX = OME_MENU
55 } OSD_MenuElement;
57 typedef long (*CMSEntryFuncPtr)(displayPort_t *displayPort, const void *ptr);
58 // This is a function used in the func member if the type is OME_Submenu.
59 typedef char * (*CMSMenuOptFuncPtr)(void);
61 typedef struct
63 const char * const text;
64 union
66 const CMSEntryFuncPtr func;
67 const CMSMenuOptFuncPtr menufunc;
68 int itemId;
70 const void * const data;
71 const uint8_t type; // from OSD_MenuElement
72 uint8_t flags;
73 } __attribute__((packed)) OSD_Entry;
75 // Bits in flags
76 #define PRINT_VALUE (1 << 0) // Value has been changed, need to redraw
77 #define PRINT_LABEL (1 << 1) // Text label should be printed
78 #define DYNAMIC (1 << 2) // Value should be updated dynamically
79 #define OPTSTRING (1 << 3) // (Temporary) Flag for OME_Submenu, indicating func should be called to get a string to display.
80 #define READONLY (1 << 4) // Indicates that the value is read-only and p->data points directly to it - applies to [U]INT(8|16)
82 #define OSD_LABEL_ENTRY(label) ((OSD_Entry){ label, {.func = NULL}, NULL, OME_Label, 0 })
83 #define OSD_LABEL_DATA_ENTRY(label, data) ((OSD_Entry){ label, {.func = NULL}, data, OME_Label, 0 })
84 #define OSD_LABEL_DATA_DYN_ENTRY(label, data) ((OSD_Entry){ label, {.func = NULL}, data, OME_Label, DYNAMIC })
85 #define OSD_LABEL_FUNC_DYN_ENTRY(label, fn) ((OSD_Entry){ label, {.func = NULL}, fn, OME_LabelFunc, DYNAMIC })
86 #define OSD_BACK_ENTRY ((OSD_Entry){ "BACK", {.func = NULL}, NULL, OME_Back, 0 })
87 #define OSD_BACK_AND_END_ENTRY ((OSD_Entry){ "BACK", {.func = NULL}, NULL, OME_BACK_AND_END, 0 })
88 #define OSD_SUBMENU_ENTRY(label, menu) ((OSD_Entry){ label, {.func = NULL}, menu, OME_Submenu, 0 })
89 #define OSD_FUNC_CALL_ENTRY(label, fn) ((OSD_Entry){ label, {.func = fn}, NULL, OME_Funcall, 0 })
90 #define OSD_BOOL_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_Bool, 0 })
91 #define OSD_BOOL_CALLBACK_ENTRY(label, cb, val) ((OSD_Entry){ label, {.func = cb}, val, OME_Bool, 0 })
92 #define OSD_BOOL_FUNC_ENTRY(label, fn) ((OSD_Entry){ label, {.func = NULL}, fn, OME_BoolFunc, 0 })
93 #define OSD_INT8_DYN_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_INT8, DYNAMIC })
94 #define OSD_UINT8_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_UINT8, 0 })
95 #define OSD_UINT8_DYN_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_UINT8, DYNAMIC })
96 #define OSD_UINT8_CALLBACK_ENTRY(label, cb, val)((OSD_Entry){ label, {.func = cb}, val, OME_UINT8, 0 })
97 #define OSD_UINT16_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_UINT16, 0 })
98 #define OSD_UINT16_DYN_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_UINT16, DYNAMIC })
99 #define OSD_UINT16_RO_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_UINT16, DYNAMIC | READONLY })
100 #define OSD_INT16_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_INT16, 0 })
101 #define OSD_INT16_DYN_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_INT16, DYNAMIC })
102 #define OSD_INT16_RO_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_INT16, DYNAMIC | READONLY })
103 #define OSD_STRING_ENTRY(label, str) ((OSD_Entry){ label, {.func = NULL}, str, OME_String, 0 })
104 #define OSD_TAB_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_TAB, 0 })
105 #define OSD_TAB_DYN_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_TAB, DYNAMIC })
106 #define OSD_TAB_CALLBACK_ENTRY(label, cb, val) ((OSD_Entry){ label, {.func = cb}, val, OME_TAB, 0 })
108 #define OSD_END_ENTRY ((OSD_Entry){ NULL, {.func = NULL}, NULL, OME_END, 0 })
110 // Data type for OME_Setting. Uses upper 4 bits
111 // of flags, leaving 16 data types.
112 #define CMS_DATA_TYPE_OFFSET (4)
113 typedef enum {
114 CMS_DATA_TYPE_ANGULAR_RATE = (1 << CMS_DATA_TYPE_OFFSET),
115 } CMSDataType_e;
117 // Use a function and data type to make sure switches are exhaustive
118 static inline CMSDataType_e CMS_DATA_TYPE(const OSD_Entry *entry) { return entry->flags & 0xF0; }
120 typedef long (*CMSMenuFuncPtr)(const OSD_Entry *from);
122 // Special return value(s) for function chaining by CMSMenuFuncPtr
123 #define MENU_CHAIN_BACK (-1) // Causes automatic cmsMenuBack
126 onExit function is called with self:
127 (1) Pointer to an OSD_Entry when cmsMenuBack() was called.
128 Point to an OSD_Entry with type == OME_Back if BACK was selected.
129 (2) NULL if called from menu exit (forced exit at top level).
132 typedef long (*CMSMenuOnExitPtr)(const OSD_Entry *self);
134 typedef struct
136 #ifdef CMS_MENU_DEBUG
137 // These two are debug aids for menu content creators.
138 const char *GUARD_text;
139 const OSD_MenuElement GUARD_type;
140 #endif
141 const CMSMenuFuncPtr onEnter;
142 const CMSMenuOnExitPtr onExit;
143 const CMSMenuFuncPtr onGlobalExit;
144 const OSD_Entry *entries;
145 } CMS_Menu;
147 typedef struct
149 uint8_t *val;
150 uint8_t min;
151 uint8_t max;
152 uint8_t step;
153 } OSD_UINT8_t;
155 typedef struct
157 int8_t *val;
158 int8_t min;
159 int8_t max;
160 int8_t step;
161 } OSD_INT8_t;
163 typedef struct
165 int16_t *val;
166 int16_t min;
167 int16_t max;
168 int16_t step;
169 } OSD_INT16_t;
171 typedef struct
173 uint16_t *val;
174 uint16_t min;
175 uint16_t max;
176 uint16_t step;
177 } OSD_UINT16_t;
179 typedef struct
181 uint8_t *val;
182 uint8_t min;
183 uint8_t max;
184 uint8_t step;
185 uint16_t multipler;
186 } OSD_FLOAT_t;
188 typedef struct OSD_SETTING_s {
189 const uint16_t val; // setting number, from the constants in settings_generated.h
190 const uint8_t step;
191 } __attribute__((packed)) OSD_SETTING_t;
193 #define OSD_SETTING_ENTRY_STEP_TYPE(name, setting, step, type) { name, NULL, &(const OSD_SETTING_t){ setting, step }, OME_Setting, type }
194 #define OSD_SETTING_ENTRY_TYPE(name, setting, type) OSD_SETTING_ENTRY_STEP_TYPE(name, setting, 0, type)
195 #define OSD_SETTING_ENTRY_STEP(name, setting, step) OSD_SETTING_ENTRY_STEP_TYPE(name, setting, step, 0)
196 #define OSD_SETTING_ENTRY(name, setting) OSD_SETTING_ENTRY_STEP(name, setting, 0)
198 typedef struct
200 uint8_t *val;
201 uint8_t max;
202 const char * const *names;
203 } OSD_TAB_t;
205 typedef struct
207 char *val;
208 } OSD_String_t;