1 | /*
|
---|
2 | * TOPPERS BASE PLATFORM MIDDLEWARE
|
---|
3 | *
|
---|
4 | * Copyright (C) 2017-2018 by TOPPERS PROJECT
|
---|
5 | * Educational Working Group.
|
---|
6 | *
|
---|
7 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
8 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
9 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
10 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
11 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
12 | * スコード中に含まれていること.
|
---|
13 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
14 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
15 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
16 | * の無保証規定を掲載すること.
|
---|
17 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
18 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
19 | * と.
|
---|
20 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
21 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
22 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
23 | * 報告すること.
|
---|
24 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
25 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
26 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
27 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
28 | * 免責すること.
|
---|
29 | *
|
---|
30 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
31 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
32 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
33 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
34 | * の責任を負わない.
|
---|
35 | *
|
---|
36 | * @(#) $Id$
|
---|
37 | */
|
---|
38 | /**
|
---|
39 | ******************************************************************************
|
---|
40 | * @attention
|
---|
41 | *
|
---|
42 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
|
---|
43 | *
|
---|
44 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
45 | * are permitted provided that the following conditions are met:
|
---|
46 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
47 | * this list of conditions and the following disclaimer.
|
---|
48 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
49 | * this list of conditions and the following disclaimer in the documentation
|
---|
50 | * and/or other materials provided with the distribution.
|
---|
51 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
---|
52 | * may be used to endorse or promote products derived from this software
|
---|
53 | * without specific prior written permission.
|
---|
54 | *
|
---|
55 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
---|
56 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
57 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
58 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
---|
59 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
60 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
---|
61 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
---|
62 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
63 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
64 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
65 | *
|
---|
66 | ******************************************************************************
|
---|
67 | */
|
---|
68 |
|
---|
69 | #include "stlcd_rk043fn48h.h"
|
---|
70 | #include <sil.h>
|
---|
71 | #include <target_syssvc.h>
|
---|
72 |
|
---|
73 | #define sil_orw_mem(a, b) sil_wrw_mem((a), sil_rew_mem(a) | (b))
|
---|
74 | #define sil_andw_mem(a, b) sil_wrw_mem((a), sil_rew_mem(a) & ~(b))
|
---|
75 | #define sil_modw_mem(a, b, c) sil_wrw_mem((a), (sil_rew_mem(a) & (~b)) | (c))
|
---|
76 |
|
---|
77 | #define POLY_X(Z) ((int32_t)((Points + Z)->X))
|
---|
78 | #define POLY_Y(Z) ((int32_t)((Points + Z)->Y))
|
---|
79 | #define ABS(X) ((X) > 0 ? (X) : -(X))
|
---|
80 |
|
---|
81 | #ifndef ENABLE
|
---|
82 | #define ENABLE 1
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | static LTDC_Handle_t hLtdcHandler;
|
---|
86 | static DMA2D_Handle_t hDma2dHandler;
|
---|
87 |
|
---|
88 | static void FillTriangle(LCD_DrawProp_t *pDrawProp, uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3);
|
---|
89 | static void LL_FillBuffer(LCD_Handler_t *hlcd, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex);
|
---|
90 | static void LL_ConvertLineToARGB8888(void * pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode);
|
---|
91 |
|
---|
92 | /*
|
---|
93 | * LTDC/RK043FN48Hスクリーンの初期化関数
|
---|
94 | */
|
---|
95 | ER
|
---|
96 | lcd_init(LCD_Handler_t *hlcd, LCD_OrientationTypeDef orientation)
|
---|
97 | {
|
---|
98 | /* The RK043FN48H LCD 480x272 is selected */
|
---|
99 | /* Timing Configuration */
|
---|
100 | hLtdcHandler.Init.HorizontalSync = (RK043FN48H_HSYNC - 1);
|
---|
101 | hLtdcHandler.Init.VerticalSync = (RK043FN48H_VSYNC - 1);
|
---|
102 | hLtdcHandler.Init.AccumulatedHBP = (RK043FN48H_HSYNC + RK043FN48H_HBP - 1);
|
---|
103 | hLtdcHandler.Init.AccumulatedVBP = (RK043FN48H_VSYNC + RK043FN48H_VBP - 1);
|
---|
104 | hLtdcHandler.Init.AccumulatedActiveH = (RK043FN48H_HEIGHT + RK043FN48H_VSYNC + RK043FN48H_VBP - 1);
|
---|
105 | hLtdcHandler.Init.AccumulatedActiveW = (RK043FN48H_WIDTH + RK043FN48H_HSYNC + RK043FN48H_HBP - 1);
|
---|
106 | hLtdcHandler.Init.TotalHeigh = (RK043FN48H_HEIGHT + RK043FN48H_VSYNC + RK043FN48H_VBP + RK043FN48H_VFP - 1);
|
---|
107 | hLtdcHandler.Init.TotalWidth = (RK043FN48H_WIDTH + RK043FN48H_HSYNC + RK043FN48H_HBP + RK043FN48H_HFP - 1);
|
---|
108 | hLtdcHandler.Init.pllsain = 192;
|
---|
109 | hLtdcHandler.Init.pllsair = 5;
|
---|
110 | hLtdcHandler.Init.saidivr = RCC_DCKCFGR1_PLLSAIDIVR_0; /* DIV 4 */
|
---|
111 |
|
---|
112 | /* Initialize the LCD pixel width and pixel height */
|
---|
113 | hLtdcHandler.LayerCfg[0].ImageWidth = RK043FN48H_WIDTH;
|
---|
114 | hLtdcHandler.LayerCfg[0].ImageHeight = RK043FN48H_HEIGHT;
|
---|
115 | #if MAX_LAYER_NUMBER >= 2
|
---|
116 | hLtdcHandler.LayerCfg[1].ImageWidth = RK043FN48H_WIDTH;
|
---|
117 | hLtdcHandler.LayerCfg[1].ImageHeight = RK043FN48H_HEIGHT;
|
---|
118 | #endif
|
---|
119 |
|
---|
120 | /* Background value */
|
---|
121 | hLtdcHandler.Init.Backcolor.Blue = 0;
|
---|
122 | hLtdcHandler.Init.Backcolor.Green = 0;
|
---|
123 | hLtdcHandler.Init.Backcolor.Red = 0;
|
---|
124 |
|
---|
125 | /* Polarity */
|
---|
126 | hLtdcHandler.Init.HSPolarity = LTDC_HSPOLARITY_AL;
|
---|
127 | hLtdcHandler.Init.VSPolarity = LTDC_VSPOLARITY_AL;
|
---|
128 | hLtdcHandler.Init.DEPolarity = LTDC_DEPOLARITY_AL;
|
---|
129 | hLtdcHandler.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
|
---|
130 | hLtdcHandler.base = TADR_LTDC_BASE;
|
---|
131 | hlcd->_width = RK043FN48H_WIDTH;
|
---|
132 | hlcd->_height = RK043FN48H_HEIGHT;
|
---|
133 | ltdc_init(&hLtdcHandler);
|
---|
134 | hlcd->hltdc = &hLtdcHandler;
|
---|
135 | return E_OK;
|
---|
136 | }
|
---|
137 |
|
---|
138 | /*
|
---|
139 | * LTDC/RK043FN48Hスクリーンレイヤ初期化関数
|
---|
140 | */
|
---|
141 | ER
|
---|
142 | lcd_layerdefaultinit(LCD_Handler_t *hlcd, LCD_DrawProp_t *pDrawProp, uint16_t LayerIndex, uint32_t FB_Address)
|
---|
143 | {
|
---|
144 | LTDC_LayerCfg_t layer_cfg;
|
---|
145 |
|
---|
146 | if(LayerIndex >= MAX_LAYER_NUMBER)
|
---|
147 | return E_PAR;
|
---|
148 | /* Layer Init */
|
---|
149 | layer_cfg.WindowX0 = 0;
|
---|
150 | layer_cfg.WindowX1 = hlcd->hltdc->LayerCfg[LayerIndex].ImageWidth;
|
---|
151 | layer_cfg.WindowY0 = 0;
|
---|
152 | layer_cfg.WindowY1 = hlcd->hltdc->LayerCfg[LayerIndex].ImageHeight;
|
---|
153 | layer_cfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
|
---|
154 | layer_cfg.FBStartAdress = FB_Address;
|
---|
155 | layer_cfg.Alpha = 255;
|
---|
156 | layer_cfg.Alpha0 = 0;
|
---|
157 | layer_cfg.Backcolor.Blue = 0;
|
---|
158 | layer_cfg.Backcolor.Green = 0;
|
---|
159 | layer_cfg.Backcolor.Red = 0;
|
---|
160 | layer_cfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
|
---|
161 | layer_cfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
|
---|
162 | layer_cfg.ImageWidth = hlcd->hltdc->LayerCfg[LayerIndex].ImageWidth;
|
---|
163 | layer_cfg.ImageHeight = hlcd->hltdc->LayerCfg[LayerIndex].ImageHeight;
|
---|
164 |
|
---|
165 | ltdc_configlayer(&hLtdcHandler, &layer_cfg, LayerIndex);
|
---|
166 |
|
---|
167 | hlcd->layer = LayerIndex;
|
---|
168 | pDrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE;
|
---|
169 | pDrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK;
|
---|
170 | pDrawProp[LayerIndex].hlcd = hlcd;
|
---|
171 | return E_OK;
|
---|
172 | }
|
---|
173 |
|
---|
174 | /*
|
---|
175 | * LTDC/RK043FN48HスクリーンRGB565レイヤ初期化関数
|
---|
176 | */
|
---|
177 | ER
|
---|
178 | lcd_layerRgb565init(LCD_Handler_t *hlcd, LCD_DrawProp_t *pDrawProp, uint16_t LayerIndex, uint32_t FB_Address)
|
---|
179 | {
|
---|
180 | LTDC_LayerCfg_t layer_cfg;
|
---|
181 |
|
---|
182 | if(LayerIndex >= MAX_LAYER_NUMBER)
|
---|
183 | return E_PAR;
|
---|
184 | /* Layer Init */
|
---|
185 | layer_cfg.WindowX0 = 0;
|
---|
186 | layer_cfg.WindowX1 = hlcd->hltdc->LayerCfg[LayerIndex].ImageWidth;
|
---|
187 | layer_cfg.WindowY0 = 0;
|
---|
188 | layer_cfg.WindowY1 = hlcd->hltdc->LayerCfg[LayerIndex].ImageHeight;
|
---|
189 | layer_cfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
|
---|
190 | layer_cfg.FBStartAdress = FB_Address;
|
---|
191 | layer_cfg.Alpha = 255;
|
---|
192 | layer_cfg.Alpha0 = 0;
|
---|
193 | layer_cfg.Backcolor.Blue = 0;
|
---|
194 | layer_cfg.Backcolor.Green = 0;
|
---|
195 | layer_cfg.Backcolor.Red = 0;
|
---|
196 | layer_cfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
|
---|
197 | layer_cfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
|
---|
198 | layer_cfg.ImageWidth = hlcd->hltdc->LayerCfg[LayerIndex].ImageWidth;
|
---|
199 | layer_cfg.ImageHeight = hlcd->hltdc->LayerCfg[LayerIndex].ImageHeight;
|
---|
200 |
|
---|
201 | ltdc_configlayer(&hLtdcHandler, &layer_cfg, LayerIndex);
|
---|
202 |
|
---|
203 | hlcd->layer = LayerIndex;
|
---|
204 | pDrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE;
|
---|
205 | pDrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK;
|
---|
206 | pDrawProp[LayerIndex].hlcd = hlcd;
|
---|
207 | return E_OK;
|
---|
208 | }
|
---|
209 |
|
---|
210 | /*
|
---|
211 | * LTDC/RK043FN48Hスクリーンレイヤ表示設定関数
|
---|
212 | */
|
---|
213 | void
|
---|
214 | lcd_setlayervisible(LCD_Handler_t *hlcd, uint32_t LayerIndex, uint8_t State)
|
---|
215 | {
|
---|
216 | uint32_t layer_base = ((uint32_t)TADR_LTDC_BASE + 0x84 + (0x80 * LayerIndex));
|
---|
217 | if(State == ENABLE){
|
---|
218 | sil_orw_mem((uint32_t *)(layer_base+TOFF_LTDCW_CR), LTDC_CR_LEN);
|
---|
219 | }
|
---|
220 | else{
|
---|
221 | sil_andw_mem((uint32_t *)(layer_base+TOFF_LTDCW_CR), LTDC_CR_LEN);
|
---|
222 | }
|
---|
223 | sil_orw_mem((uint32_t *)(TADR_LTDC_BASE+TOFF_LTDC_SRCR), LTDC_SRCR_IMR);
|
---|
224 | }
|
---|
225 |
|
---|
226 | /*
|
---|
227 | * LTDC/RK043FN48Hスクリーンレイヤ透過設定関数
|
---|
228 | *
|
---|
229 | * @brief Configures the transparency.
|
---|
230 | * @param LayerIndex: Layer foreground or background.
|
---|
231 | * @param Transparency: Transparency
|
---|
232 | * This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF
|
---|
233 | * @retval None
|
---|
234 | */
|
---|
235 | void
|
---|
236 | lcd_settransparency(LCD_Handler_t *hlcd, uint32_t LayerIndex, uint8_t Transparency)
|
---|
237 | {
|
---|
238 | ltdc_setalpha(hlcd->hltdc, Transparency, LayerIndex);
|
---|
239 | }
|
---|
240 |
|
---|
241 | /*
|
---|
242 | * LTDC/RK043FN48HスクリーンレイヤRAMアドレス設定関数
|
---|
243 | */
|
---|
244 | void
|
---|
245 | lcd_setlayeraddress(LCD_Handler_t *hlcd, uint32_t LayerIndex, uint32_t Address)
|
---|
246 | {
|
---|
247 | ltdc_setaddress(hlcd->hltdc, Address, LayerIndex);
|
---|
248 | }
|
---|
249 |
|
---|
250 | /*
|
---|
251 | * LTDC/RK043FN48H表示ウィンドウ設定
|
---|
252 | */
|
---|
253 | void
|
---|
254 | lcd_setAddrWindow(LCD_Handler_t *hlcd, uint16_t LayerIndex, uint16_t x0, uint16_t y0, uint16_t Width, uint16_t Height)
|
---|
255 | {
|
---|
256 | /* Reconfigure the layer size */
|
---|
257 | ltdc_setwindowsize(hlcd->hltdc, Width, Height, LayerIndex);
|
---|
258 |
|
---|
259 | /* Reconfigure the layer position */
|
---|
260 | ltdc_setwindowposition(hlcd->hltdc, x0, y0, LayerIndex);
|
---|
261 | }
|
---|
262 |
|
---|
263 | /**
|
---|
264 | * @brief Configures and sets the color keying.
|
---|
265 | * @param LayerIndex: Layer foreground or background
|
---|
266 | * @param RGBValue: Color reference
|
---|
267 | * @retval None
|
---|
268 | */
|
---|
269 | void
|
---|
270 | lcd_setcolorkeying(LCD_Handler_t *hlcd, uint32_t LayerIndex, uint32_t RGBValue)
|
---|
271 | {
|
---|
272 | /* Configure and Enable the color Keying for LCD Layer */
|
---|
273 | ltdc_configcolorkeying(hlcd->hltdc, RGBValue, LayerIndex);
|
---|
274 | ltdc_enablecolorkeying(hlcd->hltdc, LayerIndex);
|
---|
275 | }
|
---|
276 |
|
---|
277 | /**
|
---|
278 | * @brief Disables the color keying.
|
---|
279 | * @param LayerIndex: Layer foreground or background
|
---|
280 | * @retval None
|
---|
281 | */
|
---|
282 | void
|
---|
283 | lcd_resetcolorkeying(LCD_Handler_t *hlcd, uint32_t LayerIndex)
|
---|
284 | {
|
---|
285 | /* Disable the color Keying for LCD Layer */
|
---|
286 | ltdc_disablecolorkeying(hlcd->hltdc, LayerIndex);
|
---|
287 | }
|
---|
288 |
|
---|
289 | /*
|
---|
290 | * LTDC/RK043FN48Hスクリーンクリア
|
---|
291 | */
|
---|
292 | void
|
---|
293 | lcd_clear(LCD_Handler_t *hlcd, uint32_t Color)
|
---|
294 | {
|
---|
295 | LTDC_Handle_t *hltdc = hlcd->hltdc;
|
---|
296 | uint32_t layer = hlcd->layer;
|
---|
297 | uint32_t width, height;
|
---|
298 |
|
---|
299 | width = hltdc->LayerCfg[layer].ImageWidth;
|
---|
300 | height = hltdc->LayerCfg[layer].ImageHeight;
|
---|
301 | /* Clear the LCD */
|
---|
302 | LL_FillBuffer(hlcd, (uint32_t *)(hltdc->LayerCfg[layer].FBStartAdress), width, height, 0, Color);
|
---|
303 | }
|
---|
304 |
|
---|
305 | /*
|
---|
306 | * PIXEL読み出し
|
---|
307 | * param1 hlcd: Pointer to LCD Handler
|
---|
308 | * param2 x: X position
|
---|
309 | * param3 y: Y position
|
---|
310 | */
|
---|
311 | uint32_t
|
---|
312 | lcd_readPixel(LCD_Handler_t *hlcd, uint16_t Xpos, uint16_t Ypos)
|
---|
313 | {
|
---|
314 | LTDC_Handle_t *hltdc = hlcd->hltdc;
|
---|
315 | uint32_t layer = hlcd->layer;
|
---|
316 | uint32_t ret = 0;
|
---|
317 | uint32_t width;
|
---|
318 |
|
---|
319 | width = hltdc->LayerCfg[layer].ImageWidth;
|
---|
320 | if(hltdc->LayerCfg[layer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888){
|
---|
321 | /* Read data value from SDRAM memory */
|
---|
322 | ret = *(volatile uint32_t*)(hltdc->LayerCfg[layer].FBStartAdress + (2*(Ypos * width + Xpos)));
|
---|
323 | }
|
---|
324 | else if(hltdc->LayerCfg[layer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888){
|
---|
325 | /* Read data value from SDRAM memory */
|
---|
326 | ret = (*(volatile uint32_t*)(hltdc->LayerCfg[layer].FBStartAdress + (2*(Ypos * width + Xpos))) & 0x00FFFFFF);
|
---|
327 | }
|
---|
328 | else if((hltdc->LayerCfg[layer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565)
|
---|
329 | || (hltdc->LayerCfg[layer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444)
|
---|
330 | || (hltdc->LayerCfg[layer].PixelFormat == LTDC_PIXEL_FORMAT_AL88)){
|
---|
331 | /* Read data value from SDRAM memory */
|
---|
332 | ret = *(volatile uint16_t*)(hltdc->LayerCfg[layer].FBStartAdress + (2*(Ypos * width + Xpos)));
|
---|
333 | }
|
---|
334 | else{
|
---|
335 | /* Read data value from SDRAM memory */
|
---|
336 | ret = *(volatile uint8_t*)(hltdc->LayerCfg[layer].FBStartAdress + (2*(Ypos * width + Xpos)));
|
---|
337 | }
|
---|
338 | return ret;
|
---|
339 | }
|
---|
340 |
|
---|
341 | /*
|
---|
342 | * PIXEL描画
|
---|
343 | * param1 hlcd: Pointer to LCD Handler
|
---|
344 | * param2 x: X position
|
---|
345 | * param3 y: Y position
|
---|
346 | * param4 color: color value
|
---|
347 | */
|
---|
348 | void
|
---|
349 | lcd_drawPixel(LCD_Handler_t *hlcd, uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
|
---|
350 | {
|
---|
351 | LTDC_Handle_t *hltdc = hlcd->hltdc;
|
---|
352 | uint32_t layer = hlcd->layer;
|
---|
353 |
|
---|
354 | /* Write data value to all SDRAM memory */
|
---|
355 | if(hltdc->LayerCfg[layer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565){ /* RGB565 format */
|
---|
356 | *(volatile uint16_t*)(hltdc->LayerCfg[layer].FBStartAdress + (2*(Ypos*hltdc->LayerCfg[layer].ImageWidth + Xpos))) = (uint16_t)RGB_Code;
|
---|
357 | }
|
---|
358 | else{ /* ARGB8888 format */
|
---|
359 | *(volatile uint32_t*)(hltdc->LayerCfg[layer].FBStartAdress + (4*(Ypos*hltdc->LayerCfg[layer].ImageWidth + Xpos))) = RGB_Code;
|
---|
360 | }
|
---|
361 | }
|
---|
362 |
|
---|
363 | /*
|
---|
364 | * 垂直方向LINEの高速描画
|
---|
365 | * param1 hlcd: Pointer to LCD Handler
|
---|
366 | * param2 x: start X position
|
---|
367 | * param3 y: start Y position
|
---|
368 | * param4 h: height
|
---|
369 | * param5 color: color value
|
---|
370 | */
|
---|
371 | void
|
---|
372 | lcd_drawFastHLine(LCD_Handler_t *hlcd, uint16_t Xpos, uint16_t Ypos, uint16_t Length, uint32_t color)
|
---|
373 | {
|
---|
374 | LTDC_Handle_t *hltdc = hlcd->hltdc;
|
---|
375 | uint32_t layer = hlcd->layer;
|
---|
376 | uint32_t Xaddress = 0, width;
|
---|
377 |
|
---|
378 | width = hltdc->LayerCfg[layer].ImageWidth;
|
---|
379 | /* Get the line address */
|
---|
380 | if(hltdc->LayerCfg[layer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565){ /* RGB565 format */
|
---|
381 | Xaddress = (hltdc->LayerCfg[layer].FBStartAdress) + 2*(width * Ypos + Xpos);
|
---|
382 | }
|
---|
383 | else{ /* ARGB8888 format */
|
---|
384 | Xaddress = (hltdc->LayerCfg[layer].FBStartAdress) + 4*(width * Ypos + Xpos);
|
---|
385 | }
|
---|
386 | /* Write line */
|
---|
387 | LL_FillBuffer(hlcd, (uint32_t *)Xaddress, Length, 1, 0, color);
|
---|
388 | }
|
---|
389 |
|
---|
390 | /*
|
---|
391 | * 水平方向LINEの高速描画
|
---|
392 | * param1 hlcd: Pointer to LCD Handler
|
---|
393 | * param2 x: start X position
|
---|
394 | * param3 y: start Y position
|
---|
395 | * param4 w: width
|
---|
396 | * param5 color: color value
|
---|
397 | */
|
---|
398 | void
|
---|
399 | lcd_drawFastVLine(LCD_Handler_t *hlcd, uint16_t Xpos, uint16_t Ypos, uint16_t Length, uint32_t color)
|
---|
400 | {
|
---|
401 | LTDC_Handle_t *hltdc = hlcd->hltdc;
|
---|
402 | uint32_t layer = hlcd->layer;
|
---|
403 | uint32_t Xaddress = 0, width;
|
---|
404 |
|
---|
405 | width = hltdc->LayerCfg[layer].ImageWidth;
|
---|
406 | /* Get the line address */
|
---|
407 | if(hltdc->LayerCfg[layer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565){ /* RGB565 format */
|
---|
408 | Xaddress = (hltdc->LayerCfg[layer].FBStartAdress) + 2*(width * Ypos + Xpos);
|
---|
409 | }
|
---|
410 | else{ /* ARGB8888 format */
|
---|
411 | Xaddress = (hltdc->LayerCfg[layer].FBStartAdress) + 4*(width*Ypos + Xpos);
|
---|
412 | }
|
---|
413 |
|
---|
414 | /* Write line */
|
---|
415 | LL_FillBuffer(hlcd, (uint32_t *)Xaddress, 1, Length, (width - 1), color);
|
---|
416 | }
|
---|
417 |
|
---|
418 | /*
|
---|
419 | * BITMAP描画
|
---|
420 | * param1 hlcd: Pointer to LCD Handler
|
---|
421 | * param2 x0: Bmp X position in the LCD
|
---|
422 | * param3 y0: Bmp Y position in the LCD
|
---|
423 | * param4 pbmp: Pointer to Bmp picture address in the internal Flash
|
---|
424 | */
|
---|
425 | void
|
---|
426 | lcd_drawBitmap(LCD_Handler_t *hlcd, uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp)
|
---|
427 | {
|
---|
428 | LTDC_Handle_t *hltdc = hlcd->hltdc;
|
---|
429 | uint32_t layer = hlcd->layer;
|
---|
430 | uint32_t index = 0, width = 0, height = 0, bit_pixel = 0;
|
---|
431 | uint32_t address, iwidth;
|
---|
432 | uint32_t input_color_mode = 0;
|
---|
433 |
|
---|
434 | iwidth = hltdc->LayerCfg[hlcd->layer].ImageWidth;
|
---|
435 | /* Get bitmap data address offset */
|
---|
436 | index = *(volatile uint16_t *) (pbmp + 10);
|
---|
437 | index |= (*(volatile uint16_t *) (pbmp + 12)) << 16;
|
---|
438 |
|
---|
439 | /* Read bitmap width */
|
---|
440 | width = *(volatile uint16_t *) (pbmp + 18);
|
---|
441 | width |= (*(volatile uint16_t *) (pbmp + 20)) << 16;
|
---|
442 |
|
---|
443 | /* Read bitmap height */
|
---|
444 | height = *(volatile uint16_t *) (pbmp + 22);
|
---|
445 | height |= (*(volatile uint16_t *) (pbmp + 24)) << 16;
|
---|
446 |
|
---|
447 | /* Read bit/pixel */
|
---|
448 | bit_pixel = *(uint16_t *) (pbmp + 28);
|
---|
449 |
|
---|
450 | /* Set the address */
|
---|
451 | address = hltdc->LayerCfg[layer].FBStartAdress + (((hltdc->LayerCfg[layer].ImageWidth*Ypos) + Xpos)*(4));
|
---|
452 |
|
---|
453 | /* Get the layer pixel format */
|
---|
454 | if((bit_pixel/8) == 4){
|
---|
455 | input_color_mode = CM_ARGB8888;
|
---|
456 | }
|
---|
457 | else if ((bit_pixel/8) == 2){
|
---|
458 | input_color_mode = CM_RGB565;
|
---|
459 | }
|
---|
460 | else{
|
---|
461 | input_color_mode = CM_RGB888;
|
---|
462 | }
|
---|
463 |
|
---|
464 | /* Bypass the bitmap header */
|
---|
465 | pbmp += (index + (width * (height - 1) * (bit_pixel/8)));
|
---|
466 |
|
---|
467 | /* Convert picture to ARGB8888 pixel format */
|
---|
468 | for(index=0; index < height; index++){
|
---|
469 | /* Pixel format conversion */
|
---|
470 | LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)address, width, input_color_mode);
|
---|
471 |
|
---|
472 | /* Increment the source and destination buffers */
|
---|
473 | address+= (iwidth*4);
|
---|
474 | pbmp -= width*(bit_pixel/8);
|
---|
475 | }
|
---|
476 | }
|
---|
477 |
|
---|
478 | /*
|
---|
479 | * RECTANGLE塗りつぶし描画
|
---|
480 | * param1 hlcd: Pointer to LCD Handler
|
---|
481 | * param2 x: left X position
|
---|
482 | * param3 y: top Y position
|
---|
483 | * param4 w: width
|
---|
484 | * param5 h: height
|
---|
485 | * param6 color: color value
|
---|
486 | */
|
---|
487 | void
|
---|
488 | lcd_fillRect(LCD_Handler_t *hlcd, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height, uint32_t color)
|
---|
489 | {
|
---|
490 | LTDC_Handle_t *hltdc = hlcd->hltdc;
|
---|
491 | uint32_t x_address = 0;
|
---|
492 | uint32_t width;
|
---|
493 |
|
---|
494 | width = hltdc->LayerCfg[hlcd->layer].ImageWidth;
|
---|
495 |
|
---|
496 | /* Get the rectangle start address */
|
---|
497 | if(hltdc->LayerCfg[hlcd->layer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565){ /* RGB565 format */
|
---|
498 | x_address = (hltdc->LayerCfg[hlcd->layer].FBStartAdress) + 2*(width * Ypos + Xpos);
|
---|
499 | }
|
---|
500 | else{ /* ARGB8888 format */
|
---|
501 | x_address = (hltdc->LayerCfg[hlcd->layer].FBStartAdress) + 4*(width * Ypos + Xpos);
|
---|
502 | }
|
---|
503 | /* Fill the rectangle */
|
---|
504 | LL_FillBuffer(hlcd, (uint32_t *)x_address, Width, Height, (width - Width), color);
|
---|
505 | }
|
---|
506 |
|
---|
507 |
|
---|
508 | /*
|
---|
509 | * 線描画
|
---|
510 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
511 | * param2 x1: Point 1 X position
|
---|
512 | * param3 y1: Point 1 Y position
|
---|
513 | * param4 x2: Point 2 X position
|
---|
514 | * param5 y2: Point 2 Y position
|
---|
515 | */
|
---|
516 | void
|
---|
517 | lcd_drawLine(LCD_DrawProp_t *pDrawProp, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
|
---|
518 | {
|
---|
519 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
520 | int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
|
---|
521 | yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0,
|
---|
522 | curpixel = 0;
|
---|
523 |
|
---|
524 | deltax = ABS(x2 - x1); /* The difference between the x's */
|
---|
525 | deltay = ABS(y2 - y1); /* The difference between the y's */
|
---|
526 | x = x1; /* Start x off at the first pixel */
|
---|
527 | y = y1; /* Start y off at the first pixel */
|
---|
528 |
|
---|
529 | if(x2 >= x1){ /* The x-values are increasing */
|
---|
530 | xinc1 = 1;
|
---|
531 | xinc2 = 1;
|
---|
532 | }
|
---|
533 | else{ /* The x-values are decreasing */
|
---|
534 | xinc1 = -1;
|
---|
535 | xinc2 = -1;
|
---|
536 | }
|
---|
537 |
|
---|
538 | if(y2 >= y1){ /* The y-values are increasing */
|
---|
539 | yinc1 = 1;
|
---|
540 | yinc2 = 1;
|
---|
541 | }
|
---|
542 | else{ /* The y-values are decreasing */
|
---|
543 | yinc1 = -1;
|
---|
544 | yinc2 = -1;
|
---|
545 | }
|
---|
546 |
|
---|
547 | if(deltax >= deltay){ /* There is at least one x-value for every y-value */
|
---|
548 | xinc1 = 0; /* Don't change the x when numerator >= denominator */
|
---|
549 | yinc2 = 0; /* Don't change the y for every iteration */
|
---|
550 | den = deltax;
|
---|
551 | num = deltax / 2;
|
---|
552 | num_add = deltay;
|
---|
553 | num_pixels = deltax; /* There are more x-values than y-values */
|
---|
554 | }
|
---|
555 | else{ /* There is at least one y-value for every x-value */
|
---|
556 | xinc2 = 0; /* Don't change the x for every iteration */
|
---|
557 | yinc1 = 0; /* Don't change the y when numerator >= denominator */
|
---|
558 | den = deltay;
|
---|
559 | num = deltay / 2;
|
---|
560 | num_add = deltax;
|
---|
561 | num_pixels = deltay; /* There are more y-values than x-values */
|
---|
562 | }
|
---|
563 |
|
---|
564 | for(curpixel = 0; curpixel <= num_pixels; curpixel++){
|
---|
565 | lcd_drawPixel(hlcd, x, y, pDrawProp[hlcd->layer].TextColor); /* Draw the current pixel */
|
---|
566 | num += num_add; /* Increase the numerator by the top of the fraction */
|
---|
567 | if(num >= den){ /* Check if numerator >= denominator */
|
---|
568 | num -= den; /* Calculate the new numerator value */
|
---|
569 | x += xinc1; /* Change the x as appropriate */
|
---|
570 | y += yinc1; /* Change the y as appropriate */
|
---|
571 | }
|
---|
572 | x += xinc2; /* Change the x as appropriate */
|
---|
573 | y += yinc2; /* Change the y as appropriate */
|
---|
574 | }
|
---|
575 | }
|
---|
576 |
|
---|
577 | /*
|
---|
578 | * RECTANGLE描画
|
---|
579 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
580 | * param2 x: left X position
|
---|
581 | * param3 y: top Y position
|
---|
582 | * param4 w: width
|
---|
583 | * param5 h: height
|
---|
584 | */
|
---|
585 | void
|
---|
586 | lcd_drawRect(LCD_DrawProp_t *pDrawProp, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
|
---|
587 | {
|
---|
588 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
589 | uint32_t color = pDrawProp[hlcd->layer].TextColor;
|
---|
590 | /* Draw horizontal lines */
|
---|
591 | lcd_drawFastHLine(hlcd, Xpos, Ypos, Width, color);
|
---|
592 | lcd_drawFastHLine(hlcd, Xpos, (Ypos+ Height), Width, color);
|
---|
593 |
|
---|
594 | /* Draw vertical lines */
|
---|
595 | lcd_drawFastVLine(hlcd, Xpos, Ypos, Height, color);
|
---|
596 | lcd_drawFastVLine(hlcd, (Xpos + Width), Ypos, Height, color);
|
---|
597 | }
|
---|
598 |
|
---|
599 | /*
|
---|
600 | * 円描画
|
---|
601 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
602 | * param2 x0: X position
|
---|
603 | * param3 y0: Y position
|
---|
604 | * param4 Radius: Circle radius
|
---|
605 | */
|
---|
606 | void
|
---|
607 | lcd_DrawCircle(LCD_DrawProp_t *pDrawProp, uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
|
---|
608 | {
|
---|
609 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
610 | uint32_t color = pDrawProp[hlcd->layer].TextColor;
|
---|
611 | int32_t decision; /* Decision Variable */
|
---|
612 | uint32_t current_x; /* Current X Value */
|
---|
613 | uint32_t current_y; /* Current Y Value */
|
---|
614 |
|
---|
615 | decision = 3 - (Radius << 1);
|
---|
616 | current_x = 0;
|
---|
617 | current_y = Radius;
|
---|
618 |
|
---|
619 | while (current_x <= current_y){
|
---|
620 | lcd_drawPixel(hlcd, (Xpos + current_x), (Ypos - current_y), color);
|
---|
621 | lcd_drawPixel(hlcd, (Xpos - current_x), (Ypos - current_y), color);
|
---|
622 | lcd_drawPixel(hlcd, (Xpos + current_y), (Ypos - current_x), color);
|
---|
623 | lcd_drawPixel(hlcd, (Xpos - current_y), (Ypos - current_x), color);
|
---|
624 | lcd_drawPixel(hlcd, (Xpos + current_x), (Ypos + current_y), color);
|
---|
625 | lcd_drawPixel(hlcd, (Xpos - current_x), (Ypos + current_y), color);
|
---|
626 | lcd_drawPixel(hlcd, (Xpos + current_y), (Ypos + current_x), color);
|
---|
627 | lcd_drawPixel(hlcd, (Xpos - current_y), (Ypos + current_x), color);
|
---|
628 |
|
---|
629 | if(decision < 0){
|
---|
630 | decision += (current_x << 2) + 6;
|
---|
631 | }
|
---|
632 | else{
|
---|
633 | decision += ((current_x - current_y) << 2) + 10;
|
---|
634 | current_y--;
|
---|
635 | }
|
---|
636 | current_x++;
|
---|
637 | }
|
---|
638 | }
|
---|
639 |
|
---|
640 | /*
|
---|
641 | * 楕円描画
|
---|
642 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
643 | * param2 x0: X position
|
---|
644 | * param3 y0: Y position
|
---|
645 | * param4 XRadius: Ellipse X radius
|
---|
646 | * param5 YRadius: Ellipse Y radius
|
---|
647 | */
|
---|
648 | void
|
---|
649 | lcd_DrawEllipse(LCD_DrawProp_t *pDrawProp, int Xpos, int Ypos, int XRadius, int YRadius)
|
---|
650 | {
|
---|
651 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
652 | uint32_t color = pDrawProp[hlcd->layer].TextColor;
|
---|
653 | int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
|
---|
654 | float k = 0, rad1 = 0, rad2 = 0;
|
---|
655 |
|
---|
656 | rad1 = XRadius;
|
---|
657 | rad2 = YRadius;
|
---|
658 | k = (float)(rad2/rad1);
|
---|
659 |
|
---|
660 | do{
|
---|
661 | lcd_drawPixel(hlcd, (Xpos-(uint16_t)(x/k)), (Ypos+y), color);
|
---|
662 | lcd_drawPixel(hlcd, (Xpos+(uint16_t)(x/k)), (Ypos+y), color);
|
---|
663 | lcd_drawPixel(hlcd, (Xpos+(uint16_t)(x/k)), (Ypos-y), color);
|
---|
664 | lcd_drawPixel(hlcd, (Xpos-(uint16_t)(x/k)), (Ypos-y), color);
|
---|
665 |
|
---|
666 | e2 = err;
|
---|
667 | if(e2 <= x){
|
---|
668 | err += ++x*2+1;
|
---|
669 | if(-y == x && e2 <= y)
|
---|
670 | e2 = 0;
|
---|
671 | }
|
---|
672 | if(e2 > y)
|
---|
673 | err += ++y*2+1;
|
---|
674 | }
|
---|
675 | while (y <= 0);
|
---|
676 | }
|
---|
677 |
|
---|
678 | /*
|
---|
679 | * PLOY-LINE描画
|
---|
680 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
681 | * param2 Points: Pointer to the points array
|
---|
682 | * param3 PointCount: Number of points
|
---|
683 | */
|
---|
684 | void
|
---|
685 | lcd_drawPolygon(LCD_DrawProp_t *pDrawProp, pPoint Points, uint16_t PointCount)
|
---|
686 | {
|
---|
687 | int16_t x = 0, y = 0;
|
---|
688 |
|
---|
689 | if(PointCount < 2){
|
---|
690 | return;
|
---|
691 | }
|
---|
692 |
|
---|
693 | lcd_drawLine(pDrawProp, Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
|
---|
694 | while(--PointCount){
|
---|
695 | x = Points->X;
|
---|
696 | y = Points->Y;
|
---|
697 | Points++;
|
---|
698 | lcd_drawLine(pDrawProp, x, y, Points->X, Points->Y);
|
---|
699 | }
|
---|
700 | }
|
---|
701 |
|
---|
702 | /*
|
---|
703 | * 円塗りつぶし描画
|
---|
704 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
705 | * param2 x0: X position
|
---|
706 | * param3 y0: Y position
|
---|
707 | * param4 Radius: Circle radius
|
---|
708 | */
|
---|
709 | void
|
---|
710 | lcd_fillCircle(LCD_DrawProp_t *pDrawProp, uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
|
---|
711 | {
|
---|
712 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
713 | uint32_t color = pDrawProp->TextColor;
|
---|
714 | int32_t decision; /* Decision Variable */
|
---|
715 | uint32_t current_x; /* Current X Value */
|
---|
716 | uint32_t current_y; /* Current Y Value */
|
---|
717 |
|
---|
718 | decision = 3 - (Radius << 1);
|
---|
719 | current_x = 0;
|
---|
720 | current_y = Radius;
|
---|
721 |
|
---|
722 | while (current_x <= current_y){
|
---|
723 | if(current_y > 0){
|
---|
724 | lcd_drawFastHLine(hlcd, Xpos - current_y, Ypos + current_x, 2*current_y, color);
|
---|
725 | lcd_drawFastHLine(hlcd, Xpos - current_y, Ypos - current_x, 2*current_y, color);
|
---|
726 | }
|
---|
727 | if(current_x > 0){
|
---|
728 | lcd_drawFastHLine(hlcd, Xpos - current_x, Ypos - current_y, 2*current_x, color);
|
---|
729 | lcd_drawFastHLine(hlcd, Xpos - current_x, Ypos + current_y, 2*current_x, color);
|
---|
730 | }
|
---|
731 | if(decision < 0){
|
---|
732 | decision += (current_x << 2) + 6;
|
---|
733 | }
|
---|
734 | else{
|
---|
735 | decision += ((current_x - current_y) << 2) + 10;
|
---|
736 | current_y--;
|
---|
737 | }
|
---|
738 | current_x++;
|
---|
739 | }
|
---|
740 | lcd_DrawCircle(pDrawProp, Xpos, Ypos, Radius);
|
---|
741 | }
|
---|
742 |
|
---|
743 | /*
|
---|
744 | * 楕円塗りつぶし描画
|
---|
745 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
746 | * param2 x0: X position
|
---|
747 | * param3 y0: Y position
|
---|
748 | * param4 XRadius: Ellipse X radius
|
---|
749 | * param5 YRadius: Ellipse Y radius
|
---|
750 | */
|
---|
751 | void
|
---|
752 | lcd_fillEllipse(LCD_DrawProp_t *pDrawProp, int Xpos, int Ypos, int XRadius, int YRadius)
|
---|
753 | {
|
---|
754 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
755 | uint32_t color = pDrawProp[hlcd->layer].TextColor;
|
---|
756 | int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
|
---|
757 | float k = 0, rad1 = 0, rad2 = 0;
|
---|
758 |
|
---|
759 | rad1 = XRadius;
|
---|
760 | rad2 = YRadius;
|
---|
761 | k = (float)(rad2/rad1);
|
---|
762 |
|
---|
763 | do{
|
---|
764 | lcd_drawFastHLine(hlcd, (Xpos-(uint16_t)(x/k)), (Ypos+y), (2*(uint16_t)(x/k) + 1), color);
|
---|
765 | lcd_drawFastHLine(hlcd, (Xpos-(uint16_t)(x/k)), (Ypos-y), (2*(uint16_t)(x/k) + 1), color);
|
---|
766 |
|
---|
767 | e2 = err;
|
---|
768 | if(e2 <= x){
|
---|
769 | err += ++x*2+1;
|
---|
770 | if(-y == x && e2 <= y)
|
---|
771 | e2 = 0;
|
---|
772 | }
|
---|
773 | if(e2 > y)
|
---|
774 | err += ++y*2+1;
|
---|
775 | }while(y <= 0);
|
---|
776 | }
|
---|
777 |
|
---|
778 | /*
|
---|
779 | * PLOY-LINE塗りつぶし描画
|
---|
780 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
781 | * param2 Points: Pointer to the points array
|
---|
782 | * param3 PointCount: Number of points
|
---|
783 | */
|
---|
784 | void
|
---|
785 | lcd_fillPolygon(LCD_DrawProp_t *pDrawProp, pPoint Points, uint16_t PointCount)
|
---|
786 | {
|
---|
787 | int16_t X = 0, Y = 0, X2 = 0, Y2 = 0, X_center = 0, Y_center = 0, X_first = 0, Y_first = 0, pixelX = 0, pixelY = 0, counter = 0;
|
---|
788 | uint16_t image_left = 0, image_right = 0, image_top = 0, image_bottom = 0;
|
---|
789 |
|
---|
790 | image_left = image_right = Points->X;
|
---|
791 | image_top= image_bottom = Points->Y;
|
---|
792 |
|
---|
793 | for(counter = 1; counter < PointCount; counter++){
|
---|
794 | pixelX = POLY_X(counter);
|
---|
795 | if(pixelX < image_left){
|
---|
796 | image_left = pixelX;
|
---|
797 | }
|
---|
798 | if(pixelX > image_right){
|
---|
799 | image_right = pixelX;
|
---|
800 | }
|
---|
801 |
|
---|
802 | pixelY = POLY_Y(counter);
|
---|
803 | if(pixelY < image_top){
|
---|
804 | image_top = pixelY;
|
---|
805 | }
|
---|
806 | if(pixelY > image_bottom){
|
---|
807 | image_bottom = pixelY;
|
---|
808 | }
|
---|
809 | }
|
---|
810 |
|
---|
811 | if(PointCount < 2){
|
---|
812 | return;
|
---|
813 | }
|
---|
814 |
|
---|
815 | X_center = (image_left + image_right)/2;
|
---|
816 | Y_center = (image_bottom + image_top)/2;
|
---|
817 | X_first = Points->X;
|
---|
818 | Y_first = Points->Y;
|
---|
819 |
|
---|
820 | while(--PointCount){
|
---|
821 | X = Points->X;
|
---|
822 | Y = Points->Y;
|
---|
823 | Points++;
|
---|
824 | X2 = Points->X;
|
---|
825 | Y2 = Points->Y;
|
---|
826 |
|
---|
827 | FillTriangle(pDrawProp, X, X2, X_center, Y, Y2, Y_center);
|
---|
828 | FillTriangle(pDrawProp, X, X_center, X2, Y, Y_center, Y2);
|
---|
829 | FillTriangle(pDrawProp, X_center, X2, X, Y_center, Y2, Y);
|
---|
830 | }
|
---|
831 |
|
---|
832 | FillTriangle(pDrawProp, X_first, X2, X_center, Y_first, Y2, Y_center);
|
---|
833 | FillTriangle(pDrawProp, X_first, X_center, X2, Y_first, Y_center, Y2);
|
---|
834 | FillTriangle(pDrawProp, X_center, X2, X_first, Y_center, Y2, Y_first);
|
---|
835 | }
|
---|
836 |
|
---|
837 |
|
---|
838 | /*******************************************************************************
|
---|
839 | Static Functions
|
---|
840 | *******************************************************************************/
|
---|
841 |
|
---|
842 | /*
|
---|
843 | * トライアングルフィル
|
---|
844 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
845 | * param2 x1: 点1 X座標始点
|
---|
846 | * param3 y1: 点1 Y座標始点
|
---|
847 | * param4 x2: 点2 X座標始点
|
---|
848 | * param5 y2: 点2 Y座標始点
|
---|
849 | * param6 x3: 点3 X座標始点
|
---|
850 | * param7 y3: 点3 Y座標始点
|
---|
851 | */
|
---|
852 | static void
|
---|
853 | FillTriangle(LCD_DrawProp_t *pDrawProp, uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3)
|
---|
854 | {
|
---|
855 | int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
|
---|
856 | yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0,
|
---|
857 | curpixel = 0;
|
---|
858 |
|
---|
859 | deltax = ABS(x2 - x1); /* The difference between the x's */
|
---|
860 | deltay = ABS(y2 - y1); /* The difference between the y's */
|
---|
861 | x = x1; /* Start x off at the first pixel */
|
---|
862 | y = y1; /* Start y off at the first pixel */
|
---|
863 |
|
---|
864 | if(x2 >= x1){ /* The x-values are increasing */
|
---|
865 | xinc1 = 1;
|
---|
866 | xinc2 = 1;
|
---|
867 | }
|
---|
868 | else{ /* The x-values are decreasing */
|
---|
869 | xinc1 = -1;
|
---|
870 | xinc2 = -1;
|
---|
871 | }
|
---|
872 |
|
---|
873 | if(y2 >= y1){ /* The y-values are increasing */
|
---|
874 | yinc1 = 1;
|
---|
875 | yinc2 = 1;
|
---|
876 | }
|
---|
877 | else{ /* The y-values are decreasing */
|
---|
878 | yinc1 = -1;
|
---|
879 | yinc2 = -1;
|
---|
880 | }
|
---|
881 |
|
---|
882 | if(deltax >= deltay){ /* There is at least one x-value for every y-value */
|
---|
883 | xinc1 = 0; /* Don't change the x when numerator >= denominator */
|
---|
884 | yinc2 = 0; /* Don't change the y for every iteration */
|
---|
885 | den = deltax;
|
---|
886 | num = deltax / 2;
|
---|
887 | num_add = deltay;
|
---|
888 | num_pixels = deltax; /* There are more x-values than y-values */
|
---|
889 | }
|
---|
890 | else{ /* There is at least one y-value for every x-value */
|
---|
891 | xinc2 = 0; /* Don't change the x for every iteration */
|
---|
892 | yinc1 = 0; /* Don't change the y when numerator >= denominator */
|
---|
893 | den = deltay;
|
---|
894 | num = deltay / 2;
|
---|
895 | num_add = deltax;
|
---|
896 | num_pixels = deltay; /* There are more y-values than x-values */
|
---|
897 | }
|
---|
898 |
|
---|
899 | for(curpixel = 0; curpixel <= num_pixels; curpixel++){
|
---|
900 | lcd_drawLine(pDrawProp, x, y, x3, y3);
|
---|
901 | num += num_add; /* Increase the numerator by the top of the fraction */
|
---|
902 | if(num >= den){ /* Check if numerator >= denominator */
|
---|
903 | num -= den; /* Calculate the new numerator value */
|
---|
904 | x += xinc1; /* Change the x as appropriate */
|
---|
905 | y += yinc1; /* Change the y as appropriate */
|
---|
906 | }
|
---|
907 | x += xinc2; /* Change the x as appropriate */
|
---|
908 | y += yinc2; /* Change the y as appropriate */
|
---|
909 | }
|
---|
910 | }
|
---|
911 |
|
---|
912 | /*
|
---|
913 | * バッファフィル
|
---|
914 | * param1 hlcd: Pointer to LCD Handler
|
---|
915 | * param2 pDst:バッファ先頭ポインタ
|
---|
916 | * param3 xSize: バッファ幅
|
---|
917 | * param3 ySize: バッファ高さ
|
---|
918 | * param4 OffLine: 出力オフセット
|
---|
919 | * param5 ColorIndex: フィルカラー
|
---|
920 | */
|
---|
921 | static void
|
---|
922 | LL_FillBuffer(LCD_Handler_t *hlcd, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex)
|
---|
923 | {
|
---|
924 | LTDC_Handle_t *hltdc = hlcd->hltdc;
|
---|
925 |
|
---|
926 | /* Register to memory mode with ARGB8888 as color Mode */
|
---|
927 | hDma2dHandler.Init.Mode = DMA2D_R2M;
|
---|
928 | if(hltdc->LayerCfg[hlcd->layer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565){ /* RGB565 format */
|
---|
929 | hDma2dHandler.Init.ColorMode = DMA2D_RGB565;
|
---|
930 | }
|
---|
931 | else{ /* ARGB8888 format */
|
---|
932 | hDma2dHandler.Init.ColorMode = DMA2D_ARGB8888;
|
---|
933 | }
|
---|
934 | hDma2dHandler.Init.OutputOffset = OffLine;
|
---|
935 |
|
---|
936 | hDma2dHandler.base = (uint32_t)TADR_DMA2D_BASE;
|
---|
937 |
|
---|
938 | /* DMA2D Initialization */
|
---|
939 | if(dma2d_init(&hDma2dHandler) == E_OK){
|
---|
940 | if(dma2d_configlayer(&hDma2dHandler, hlcd->layer) == E_OK){
|
---|
941 | if(dma2d_start(&hDma2dHandler, ColorIndex, (uint32_t)pDst, xSize, ySize) == E_OK){
|
---|
942 | /* Polling For DMA transfer */
|
---|
943 | dma2d_waittransfar(&hDma2dHandler, 10);
|
---|
944 | }
|
---|
945 | }
|
---|
946 | }
|
---|
947 | }
|
---|
948 |
|
---|
949 | /**
|
---|
950 | * @brief Converts a line to an ARGB8888 pixel format.
|
---|
951 | * @param pSrc: Pointer to source buffer
|
---|
952 | * @param pDst: Output color
|
---|
953 | * @param xSize: Buffer width
|
---|
954 | * @param ColorMode: Input color mode
|
---|
955 | * @retval None
|
---|
956 | */
|
---|
957 | static void
|
---|
958 | LL_ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode)
|
---|
959 | {
|
---|
960 | /* Configure the DMA2D Mode, Color Mode and output offset */
|
---|
961 | hDma2dHandler.Init.Mode = DMA2D_M2M_PFC;
|
---|
962 | hDma2dHandler.Init.ColorMode = DMA2D_ARGB8888;
|
---|
963 | hDma2dHandler.Init.OutputOffset = 0;
|
---|
964 |
|
---|
965 | /* Foreground Configuration */
|
---|
966 | hDma2dHandler.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
---|
967 | hDma2dHandler.LayerCfg[1].InputAlpha = 0xFF;
|
---|
968 | hDma2dHandler.LayerCfg[1].InputColorMode = ColorMode;
|
---|
969 | hDma2dHandler.LayerCfg[1].InputOffset = 0;
|
---|
970 | hDma2dHandler.base = (uint32_t)TADR_DMA2D_BASE;
|
---|
971 |
|
---|
972 | /* DMA2D Initialization */
|
---|
973 | if(dma2d_init(&hDma2dHandler) == E_OK){
|
---|
974 | if(dma2d_configlayer(&hDma2dHandler, 1) == E_OK){
|
---|
975 | if(dma2d_start(&hDma2dHandler, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == E_OK){
|
---|
976 | /* Polling For DMA transfer */
|
---|
977 | dma2d_waittransfar(&hDma2dHandler, 10);
|
---|
978 | }
|
---|
979 | }
|
---|
980 | }
|
---|
981 | }
|
---|
982 |
|
---|