5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
29 #define CENTER_OFS (7*FW-FW/2)
31 #define lcdint_t int32_t
37 #define LCD_LINES (LCD_H/FH)
38 #define LCD_COLS (LCD_W/FW)
40 #define BITMAP_BUFFER_SIZE(w, h) (2 + (w) * (((h)+7)/8)*4)
42 /* lcdDrawText flags */
48 #define FIXEDWIDTH 0x10
49 /* no 0x80 here because of "GV"1 which is aligned LEFT */
50 /* no 0x10 here because of "MODEL"01 which uses LEADING0 */
53 /* lcdDrawNumber additional flags */
57 #define MODE(flags) ((((int8_t)(flags) & 0x30) - 0x10) >> 4)
59 /* line, rect, square flags */
63 #define FILL_WHITE 0x10
68 #define FONTSIZE_MASK 0x0700
69 #define FONTSIZE(x) ((x) & FONTSIZE_MASK)
70 #define TINSIZE 0x0100
71 #define SMLSIZE 0x0200
72 #define MIDSIZE 0x0300
73 #define DBLSIZE 0x0400
74 #define XXLSIZE 0x0500
75 #define ERASEBG 0x8000
76 #define VERTICAL 0x0800
78 #define TIMEBLINK 0x1000
79 #define TIMEHOUR 0x2000
80 #define STREXPANDED 0x4000
82 #define GREY(x) ((x) * 0x010000)
83 #define WHITE GREY(0xf)
84 #define GREY_DEFAULT GREY(11)
85 #define COLOUR_MASK(x) ((x) & 0x0F0000)
87 #define LcdFlags uint32_t
89 #define display_t uint8_t
90 #define DISPLAY_BUFFER_SIZE (LCD_W*LCD_H*4/8)
92 #if (defined(PCBX9E) || defined(PCBX9DP)) && defined(LCD_DUAL_BUFFER)
93 extern display_t displayBuf1
[DISPLAY_BUFFER_SIZE
];
94 extern display_t displayBuf2
[DISPLAY_BUFFER_SIZE
];
95 extern display_t
* displayBuf
;
97 extern display_t displayBuf
[DISPLAY_BUFFER_SIZE
];
100 extern coord_t lcdLastRightPos
;
101 extern coord_t lcdLastLeftPos
;
102 extern coord_t lcdNextPos
;
104 #define DISPLAY_END (displayBuf + DISPLAY_BUFFER_SIZE)
105 #define ASSERT_IN_DISPLAY(p) assert((p) >= displayBuf && (p) < DISPLAY_END)
108 // TODO quick & dirty :(
109 typedef const unsigned char pm_uchar
;
110 typedef const char pm_char
;
113 void lcdDrawChar(coord_t x
, coord_t y
, const unsigned char c
);
114 void lcdDrawChar(coord_t x
, coord_t y
, const unsigned char c
, LcdFlags mode
);
115 void lcdDrawText(coord_t x
, coord_t y
, const pm_char
* s
, LcdFlags mode
);
116 void lcdDrawTextAtIndex(coord_t x
, coord_t y
, const pm_char
* s
,uint8_t idx
, LcdFlags mode
);
117 void lcdDrawSizedText(coord_t x
, coord_t y
, const pm_char
* s
,unsigned char len
, LcdFlags mode
);
118 void lcdDrawText(coord_t x
, coord_t y
, const pm_char
* s
);
119 void lcdDrawSizedText(coord_t x
, coord_t y
, const pm_char
* s
, unsigned char len
);
120 void lcdDrawTextAlignedLeft(coord_t y
, const pm_char
* s
);
122 #define lcdDrawTextAlignedCenter(y, s) lcdDrawText((LCD_W-sizeof(TR_##s)*FW+FW+1)/2, y, STR_##s)
124 void lcdDrawHexNumber(coord_t x
, coord_t y
, uint32_t val
, LcdFlags mode
=0);
125 void lcdDrawNumber(coord_t x
, coord_t y
, int32_t val
, LcdFlags mode
, uint8_t len
);
126 void lcdDrawNumber(coord_t x
, coord_t y
, int32_t val
, LcdFlags mode
=0);
128 void drawStringWithIndex(coord_t x
, coord_t y
, const pm_char
*str
, uint8_t idx
, LcdFlags att
=0);
129 void putsModelName(coord_t x
, coord_t y
, char *name
, uint8_t id
, LcdFlags att
);
130 void drawSwitch(coord_t x
, coord_t y
, int32_t swtch
, LcdFlags att
=0);
131 void putsStickName(coord_t x
, coord_t y
, uint8_t idx
, LcdFlags att
=0);
132 void drawSource(coord_t x
, coord_t y
, uint32_t idx
, LcdFlags att
=0);
133 void drawCurveName(coord_t x
, coord_t y
, int8_t idx
, LcdFlags att
=0);
134 void drawTimerMode(coord_t x
, coord_t y
, int32_t mode
, LcdFlags att
=0);
135 void drawTrimMode(coord_t x
, coord_t y
, uint8_t phase
, uint8_t idx
, LcdFlags att
);
137 #define putsChn(x, y, idx, att) drawSource(x, y, MIXSRC_CH1+idx-1, att)
138 void putsChnLetter(coord_t x
, coord_t y
, uint8_t idx
, LcdFlags attr
);
140 void putsVolts(coord_t x
, coord_t y
, uint16_t volts
, LcdFlags att
);
141 void putsVBat(coord_t x
, coord_t y
, LcdFlags att
);
143 #define putstime_t int32_t
145 void drawRtcTime(coord_t x
, coord_t y
, LcdFlags att
);
146 void drawTimer(coord_t x
, coord_t y
, putstime_t tme
, LcdFlags att
, LcdFlags att2
);
147 inline void drawTimer(coord_t x
, coord_t y
, putstime_t tme
, LcdFlags att
)
149 drawTimer(x
, y
, tme
, att
, att
);
155 void lcdDrawPoint(coord_t x
, coord_t y
, LcdFlags att
=0);
156 void lcdMaskPoint(uint8_t *p
, uint8_t mask
, LcdFlags att
=0);
157 void lcdDrawSolidHorizontalLine(coord_t x
, coord_t y
, coord_t w
, LcdFlags att
=0);
158 void lcdDrawHorizontalLine(coord_t x
, coord_t y
, coord_t w
, uint8_t pat
, LcdFlags att
=0);
159 void lcdDrawSolidVerticalLine(coord_t x
, scoord_t y
, scoord_t h
, LcdFlags att
=0);
160 void lcdDrawVerticalLine(coord_t x
, scoord_t y
, scoord_t h
, uint8_t pat
, LcdFlags att
=0);
161 void lcdDrawLine(coord_t x1
, coord_t y1
, coord_t x2
, coord_t y2
, uint8_t pat
=SOLID
, LcdFlags att
=0);
162 void lcdDrawFilledRect(coord_t x
, scoord_t y
, coord_t w
, coord_t h
, uint8_t pat
=SOLID
, LcdFlags att
=0);
163 inline void lcdDrawSolidFilledRect(coord_t x
, scoord_t y
, coord_t w
, coord_t h
, LcdFlags att
=0)
165 lcdDrawFilledRect(x
, y
, w
, h
, SOLID
, att
);
167 void lcdDrawRect(coord_t x
, coord_t y
, coord_t w
, coord_t h
, uint8_t pat
=SOLID
, LcdFlags att
=0);
168 inline void lcdDrawSquare(coord_t x
, coord_t y
, coord_t w
, LcdFlags att
=0)
170 lcdDrawRect(x
, y
, w
, w
, SOLID
, att
);
173 void lcdInvertLine(int8_t line
);
174 #define lcdInvertLastLine() lcdInvertLine(LCD_LINES-1)
176 void drawShutdownAnimation(uint32_t index
, const char * message
);
177 void drawSleepBitmap();
178 void drawTelemetryTopBar();
180 #define V_BAR(xx, yy, ll) \
181 lcdDrawSolidVerticalLine(xx-1,yy-ll,ll); \
182 lcdDrawSolidVerticalLine(xx ,yy-ll,ll); \
183 lcdDrawSolidVerticalLine(xx+1,yy-ll,ll)
185 void lcdDraw1bitBitmap(coord_t x
, coord_t y
, const pm_uchar
* img
, uint8_t idx
, LcdFlags att
=0);
187 void lcdDrawBitmap(coord_t x
, coord_t y
, const uint8_t * img
, coord_t offset
=0, coord_t width
=0);
188 #define LCD_ICON(x, y, icon) lcdDrawBitmap(x, y, icons, icon)
192 uint8_t * lcdLoadBitmap(uint8_t * dest
, const char * filename
, uint16_t width
, uint16_t height
);
193 const char * writeScreenshot();
196 #define BLINK_ON_PHASE (0)
198 #define BLINK_ON_PHASE (g_blinkTmr10ms & (1<<6))
201 inline display_t
getPixel(unsigned int x
, unsigned int y
)
203 if (x
>=LCD_W
|| y
>=LCD_H
) {
207 display_t
* p
= &displayBuf
[y
/ 2 * LCD_W
+ x
];
208 return (y
& 1) ? (*p
>> 4) : (*p
& 0x0F);
212 uint8_t getTextWidth(const char * s
, uint8_t len
=0, LcdFlags flags
=0);