fix WhatsNew for release
[librepilot.git] / flight / modules / Osd / osdgen / inc / osdgen.h
blob35d7c30204e10360e32a3e95967fdaaed8059c8a
1 /**
2 ******************************************************************************
3 * @addtogroup OpenPilotModules OpenPilot Modules
4 * @{
5 * @addtogroup OSDgenModule osdgen Module
6 * @brief Process OSD information
7 * @{
9 * @file osdgen.h
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
11 * @brief OSD gen module, handles OSD draw. Parts from CL-OSD and SUPEROSD projects
12 * @see The GNU Public License (GPL) Version 3
14 *****************************************************************************/
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * for more details.
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #ifndef OSDGEN_H_
32 #define OSDGEN_H_
34 #include "openpilot.h"
35 #include "pios.h"
37 int32_t osdgenInitialize(void);
39 // Size of an array (num items.)
40 #define SIZEOF_ARRAY(x) (sizeof(x) / sizeof((x)[0]))
42 #define HUD_VSCALE_FLAG_CLEAR 1
43 #define HUD_VSCALE_FLAG_NO_NEGATIVE 2
45 // Macros for computing addresses and bit positions.
46 // NOTE: /16 in y is because we are addressing by word not byte.
47 #define CALC_BUFF_ADDR(x, y) (((x) / 8) + ((y) * (GRAPHICS_WIDTH_REAL / 8)))
48 #define CALC_BIT_IN_WORD(x) ((x) & 7)
49 #define DEBUG_DELAY
50 // Macro for writing a word with a mode (NAND = clear, OR = set, XOR = toggle)
51 // at a given position
52 #define WRITE_WORD_MODE(buff, addr, mask, mode) \
53 switch (mode) { \
54 case 0: buff[addr] &= ~mask; break; \
55 case 1: buff[addr] |= mask; break; \
56 case 2: buff[addr] ^= mask; break; }
58 #define WRITE_WORD_NAND(buff, addr, mask) { buff[addr] &= ~mask; DEBUG_DELAY; }
59 #define WRITE_WORD_OR(buff, addr, mask) { buff[addr] |= mask; DEBUG_DELAY; }
60 #define WRITE_WORD_XOR(buff, addr, mask) { buff[addr] ^= mask; DEBUG_DELAY; }
62 // Horizontal line calculations.
63 // Edge cases.
64 #define COMPUTE_HLINE_EDGE_L_MASK(b) ((1 << (8 - (b))) - 1)
65 #define COMPUTE_HLINE_EDGE_R_MASK(b) (~((1 << (7 - (b))) - 1))
66 // This computes an island mask.
67 #define COMPUTE_HLINE_ISLAND_MASK(b0, b1) (COMPUTE_HLINE_EDGE_L_MASK(b0) ^ COMPUTE_HLINE_EDGE_L_MASK(b1));
69 // Macro for initializing stroke/fill modes. Add new modes here
70 // if necessary.
71 #define SETUP_STROKE_FILL(stroke, fill, mode) \
72 stroke = 0; fill = 0; \
73 if (mode == 0) { stroke = 0; fill = 1; } \
74 if (mode == 1) { stroke = 1; fill = 0; } \
76 // Line endcaps (for horizontal and vertical lines.)
77 #define ENDCAP_NONE 0
78 #define ENDCAP_ROUND 1
79 #define ENDCAP_FLAT 2
81 #define DRAW_ENDCAP_HLINE(e, x, y, s, f, l) \
82 if ((e) == ENDCAP_ROUND) /* single pixel endcap */ \
83 { write_pixel_lm(x, y, f, l); } \
84 else if ((e) == ENDCAP_FLAT) /* flat endcap: FIXME, quicker to draw a vertical line(?) */ \
85 { write_pixel_lm(x, y - 1, s, l); write_pixel_lm(x, y, s, l); write_pixel_lm(x, y + 1, s, l); }
87 #define DRAW_ENDCAP_VLINE(e, x, y, s, f, l) \
88 if ((e) == ENDCAP_ROUND) /* single pixel endcap */ \
89 { write_pixel_lm(x, y, f, l); } \
90 else if ((e) == ENDCAP_FLAT) /* flat endcap: FIXME, quicker to draw a horizontal line(?) */ \
91 { write_pixel_lm(x - 1, y, s, l); write_pixel_lm(x, y, s, l); write_pixel_lm(x + 1, y, s, l); }
93 // Macros for writing pixels in a midpoint circle algorithm.
94 #define CIRCLE_PLOT_8(buff, cx, cy, x, y, mode) \
95 CIRCLE_PLOT_4(buff, cx, cy, x, y, mode); \
96 if ((x) != (y)) { CIRCLE_PLOT_4(buff, cx, cy, y, x, mode); }
98 #define CIRCLE_PLOT_4(buff, cx, cy, x, y, mode) \
99 write_pixel(buff, (cx) + (x), (cy) + (y), mode); \
100 write_pixel(buff, (cx) - (x), (cy) + (y), mode); \
101 write_pixel(buff, (cx) + (x), (cy) - (y), mode); \
102 write_pixel(buff, (cx) - (x), (cy) - (y), mode);
104 // Font flags.
105 #define FONT_BOLD 1 // bold text (no outline)
106 #define FONT_INVERT 2 // invert: border white, inside black
107 // Text alignments.
108 #define TEXT_VA_TOP 0
109 #define TEXT_VA_MIDDLE 1
110 #define TEXT_VA_BOTTOM 2
111 #define TEXT_HA_LEFT 0
112 #define TEXT_HA_CENTER 1
113 #define TEXT_HA_RIGHT 2
115 // Text dimension structures.
116 struct FontDimensions {
117 int width, height;
120 // Max/Min macros.
121 #define MAX(a, b) ((a) > (b) ? (a) : (b))
122 #define MIN(a, b) ((a) < (b) ? (a) : (b))
123 #define MAX3(a, b, c) MAX(a, MAX(b, c))
124 #define MIN3(a, b, c) MIN(a, MIN(b, c))
126 // Apply DeadBand
127 #define APPLY_DEADBAND(x, y) { x = (x) + GRAPHICS_HDEADBAND; y = (y) + GRAPHICS_VDEADBAND; }
128 #define APPLY_VDEADBAND(y) ((y) + GRAPHICS_VDEADBAND)
129 #define APPLY_HDEADBAND(x) ((x) + GRAPHICS_HDEADBAND)
131 // Check if coordinates are valid. If not, return. Assumes unsigned coordinate
132 #define CHECK_COORDS(x, y) if (x >= GRAPHICS_WIDTH_REAL || y >= GRAPHICS_HEIGHT_REAL) { return; }
133 #define CHECK_COORD_X(x) if (x >= GRAPHICS_WIDTH_REAL) { return; }
134 #define CHECK_COORD_Y(y) if (y >= GRAPHICS_HEIGHT_REAL) { return; }
136 // Clip coordinates out of range - assumes unsigned coordinate
137 #define CLIP_COORD_X(x) { x = MIN(x, GRAPHICS_WIDTH_REAL); }
138 #define CLIP_COORD_Y(y) { y = MIN(y, GRAPHICS_HEIGHT_REAL); }
139 #define CLIP_COORDS(x, y) { CLIP_COORD_X(x); CLIP_COORD_Y(y); }
141 // Macro to swap two variables using XOR swap.
142 #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; }
144 // Line triggering
145 #define LAST_LINE 312 // 625/2 //PAL
146 // #define LAST_LINE 525/2 //NTSC
148 // Global vars
150 #define DELAY_1_NOP() asm ("nop\r\n")
151 #define DELAY_2_NOP() asm ("nop\r\nnop\r\n")
152 #define DELAY_3_NOP() asm ("nop\r\nnop\r\nnop\r\n")
153 #define DELAY_4_NOP() asm ("nop\r\nnop\r\nnop\r\nnop\r\n")
154 #define DELAY_5_NOP() asm ("nop\r\nnop\r\nnop\r\nnop\r\nnop\r\n")
155 #define DELAY_6_NOP() asm ("nop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\n")
156 #define DELAY_7_NOP() asm ("nop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\n")
157 #define DELAY_8_NOP() asm ("nop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\n")
158 #define DELAY_9_NOP() asm ("nop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\n")
159 #define DELAY_10_NOP() asm ("nop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\nnop\r\n")
161 uint8_t getCharData(uint16_t charPos);
162 void introText();
164 void clearGraphics();
165 uint8_t validPos(uint16_t x, uint16_t y);
166 void setPixel(uint16_t x, uint16_t y, uint8_t state);
167 void drawCircle(uint16_t x0, uint16_t y0, uint16_t radius);
168 void swap(uint16_t *a, uint16_t *b);
169 void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
170 void drawBox(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
171 void drawArrow(uint16_t x, uint16_t y, uint16_t angle, uint16_t size);
172 void drawAttitude(uint16_t x, uint16_t y, int16_t pitch, int16_t roll, uint16_t size);
173 void introGraphics();
174 void updateGraphics();
175 void drawGraphicsLine();
177 void write_char16(char ch, unsigned int x, unsigned int y, int font);
178 void write_pixel(uint8_t *buff, unsigned int x, unsigned int y, int mode);
179 void write_pixel_lm(unsigned int x, unsigned int y, int mmode, int lmode);
180 void write_hline(uint8_t *buff, unsigned int x0, unsigned int x1, unsigned int y, int mode);
181 void write_hline_lm(unsigned int x0, unsigned int x1, unsigned int y, int lmode, int mmode);
182 void write_hline_outlined(unsigned int x0, unsigned int x1, unsigned int y, int endcap0, int endcap1, int mode, int mmode);
183 void write_vline(uint8_t *buff, unsigned int x, unsigned int y0, unsigned int y1, int mode);
184 void write_vline_lm(unsigned int x, unsigned int y0, unsigned int y1, int lmode, int mmode);
185 void write_vline_outlined(unsigned int x, unsigned int y0, unsigned int y1, int endcap0, int endcap1, int mode, int mmode);
186 void write_filled_rectangle(uint8_t *buff, unsigned int x, unsigned int y, unsigned int width, unsigned int height, int mode);
187 void write_filled_rectangle_lm(unsigned int x, unsigned int y, unsigned int width, unsigned int height, int lmode, int mmode);
188 void write_rectangle_outlined(unsigned int x, unsigned int y, int width, int height, int mode, int mmode);
189 void write_circle(uint8_t *buff, unsigned int cx, unsigned int cy, unsigned int r, unsigned int dashp, int mode);
190 void write_circle_outlined(unsigned int cx, unsigned int cy, unsigned int r, unsigned int dashp, int bmode, int mode, int mmode);
191 void write_circle_filled(uint8_t *buff, unsigned int cx, unsigned int cy, unsigned int r, int mode);
192 void write_line(uint8_t *buff, unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, int mode);
193 void write_line_lm(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, int mmode, int lmode);
194 void write_line_outlined(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, int endcap0, int endcap1, int mode, int mmode);
195 void write_word_misaligned(uint8_t *buff, uint16_t word, unsigned int addr, unsigned int xoff, int mode);
196 void write_word_misaligned_NAND(uint8_t *buff, uint16_t word, unsigned int addr, unsigned int xoff);
197 void write_word_misaligned_OR(uint8_t *buff, uint16_t word, unsigned int addr, unsigned int xoff);
198 void write_word_misaligned_lm(uint16_t wordl, uint16_t wordm, unsigned int addr, unsigned int xoff, int lmode, int mmode);
199 // int fetch_font_info(char ch, int font, struct FontEntry *font_info, char *lookup);
200 void write_char(char ch, unsigned int x, unsigned int y, int flags, int font);
201 // void calc_text_dimensions(char *str, struct FontEntry font, int xs, int ys, struct FontDimensions *dim);
202 void write_string(char *str, unsigned int x, unsigned int y, unsigned int xs, unsigned int ys, int va, int ha, int flags, int font);
203 void write_string_formatted(char *str, unsigned int x, unsigned int y, unsigned int xs, unsigned int ys, int va, int ha, int flags);
205 void updateOnceEveryFrame();
207 #endif /* OSDGEN_H_ */