1 | /*
|
---|
2 | * TOPPERS/ASP Kernel
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
4 | * Advanced Standard Profile Kernel
|
---|
5 | *
|
---|
6 | * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
|
---|
7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
8 | * Copyright (C) 2004-2012 by Embedded and Real-Time Systems Laboratory
|
---|
9 | * Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
10 | * Copyright (C) 2015-2019 by TOPPERS PROJECT Educational Working Group.
|
---|
11 | *
|
---|
12 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
13 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
14 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
15 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
16 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
17 | * スコード中に含まれていること.
|
---|
18 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
19 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
20 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
21 | * の無保証規定を掲載すること.
|
---|
22 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
23 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
24 | * と.
|
---|
25 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
26 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
27 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
28 | * 報告すること.
|
---|
29 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
30 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
31 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
32 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
33 | * 免責すること.
|
---|
34 | *
|
---|
35 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
36 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
37 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
38 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
39 | * の責任を負わない.
|
---|
40 | *
|
---|
41 | * $Id$
|
---|
42 | */
|
---|
43 | /*
|
---|
44 | * SIPEED ST7789 2.4"LCD制御プログラムの本体
|
---|
45 | */
|
---|
46 |
|
---|
47 | #include <kernel.h>
|
---|
48 | #include <t_syslog.h>
|
---|
49 | #include <t_stdlib.h>
|
---|
50 | #include <stdio.h>
|
---|
51 | #include <string.h>
|
---|
52 | #include <target_syssvc.h>
|
---|
53 | #include "syssvc/serial.h"
|
---|
54 | #include "syssvc/syslog.h"
|
---|
55 | #include "sipeed_st7789.h"
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * サービスコールのエラーのログ出力
|
---|
59 | */
|
---|
60 | Inline void
|
---|
61 | svc_perror(const char *file, int_t line, const char *expr, ER ercd)
|
---|
62 | {
|
---|
63 | if (ercd < 0) {
|
---|
64 | t_perror(LOG_ERROR, file, line, expr, ercd);
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | #define SVC_PERROR(expr) svc_perror(__FILE__, __LINE__, #expr, (expr))
|
---|
69 | #define ABS(X) ((X) > 0 ? (X) : -(X))
|
---|
70 |
|
---|
71 | #ifndef SPI_CORE_WAIT_TIME
|
---|
72 | #define SPI_CORE_WAIT_TIME 500
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | #define PORT_HIGH 1
|
---|
76 | #define PORT_LOW 0
|
---|
77 |
|
---|
78 | #define MAX_BUFFER 8
|
---|
79 |
|
---|
80 | static uint32_t aTxBuffer[MAX_BUFFER];
|
---|
81 |
|
---|
82 |
|
---|
83 | static void set_dcx_control(LCD_Handler_t *hlcd)
|
---|
84 | {
|
---|
85 | gpio_set_pin(TADR_GPIO_BASE, hlcd->dcx_no, PORT_LOW);
|
---|
86 | }
|
---|
87 |
|
---|
88 | static void set_dcx_data(LCD_Handler_t *hlcd)
|
---|
89 | {
|
---|
90 | gpio_set_pin(TADR_GPIO_BASE, hlcd->dcx_no, PORT_HIGH);
|
---|
91 | }
|
---|
92 |
|
---|
93 | /*
|
---|
94 | * LCDへのコマンド送信関数
|
---|
95 | */
|
---|
96 | ER
|
---|
97 | lcd_writecommand(LCD_Handler_t *hlcd, uint8_t c)
|
---|
98 | {
|
---|
99 | SPI_Handle_t *hspi = hlcd->hspi;
|
---|
100 | ER ercd = E_OK;
|
---|
101 |
|
---|
102 | aTxBuffer[0] = c;
|
---|
103 | set_dcx_control(hlcd);
|
---|
104 | hspi->Init.DataSize = 8;
|
---|
105 | hspi->Init.InstLength = 8;
|
---|
106 | hspi->Init.AddrLength = 0;
|
---|
107 | ercd = spi_core_transmit(hspi, hlcd->cs_sel, (uint8_t *)(aTxBuffer), 1);
|
---|
108 | #if SPI_WAIT_TIME == 0
|
---|
109 | if(ercd == E_OK)
|
---|
110 | ercd = spi_wait(hspi, SPI_CORE_WAIT_TIME);
|
---|
111 | #endif
|
---|
112 | return ercd;
|
---|
113 | }
|
---|
114 |
|
---|
115 | /*
|
---|
116 | * LCDへのデータ送信関数
|
---|
117 | */
|
---|
118 | ER
|
---|
119 | lcd_writebyte(LCD_Handler_t *hlcd, uint8_t *buf, uint8_t len)
|
---|
120 | {
|
---|
121 | SPI_Handle_t *hspi = hlcd->hspi;
|
---|
122 | uint32_t i;
|
---|
123 | ER ercd = E_OK;
|
---|
124 |
|
---|
125 | if(len >= MAX_BUFFER)
|
---|
126 | return E_PAR;
|
---|
127 | for(i = 0 ; i < len ; i++)
|
---|
128 | aTxBuffer[i] = buf[i];
|
---|
129 |
|
---|
130 | set_dcx_data(hlcd);
|
---|
131 | hspi->Init.DataSize = 8;
|
---|
132 | hspi->Init.InstLength = 8;
|
---|
133 | hspi->Init.AddrLength = 0;
|
---|
134 | ercd = spi_core_transmit(hspi, hlcd->cs_sel, (uint8_t *)aTxBuffer, len);
|
---|
135 | #if SPI_WAIT_TIME == 0
|
---|
136 | if(ercd == E_OK)
|
---|
137 | ercd = spi_wait(hspi, SPI_CORE_WAIT_TIME);
|
---|
138 | #endif
|
---|
139 | return ercd;
|
---|
140 | }
|
---|
141 |
|
---|
142 | ER
|
---|
143 | lcd_writebyte2(LCD_Handler_t *hlcd, uint8_t *buf, uint8_t len)
|
---|
144 | {
|
---|
145 | SPI_Handle_t *hspi = hlcd->hspi;
|
---|
146 | ER ercd = E_OK;
|
---|
147 |
|
---|
148 | set_dcx_data(hlcd);
|
---|
149 | hspi->Init.DataSize = 8;
|
---|
150 | hspi->Init.InstLength = 8;
|
---|
151 | hspi->Init.AddrLength = 0;
|
---|
152 | ercd = spi_core_transmit(hspi, hlcd->cs_sel, buf, len);
|
---|
153 | #if SPI_WAIT_TIME == 0
|
---|
154 | if(ercd == E_OK)
|
---|
155 | ercd = spi_wait(hspi, SPI_CORE_WAIT_TIME);
|
---|
156 | #endif
|
---|
157 | return ercd;
|
---|
158 | }
|
---|
159 |
|
---|
160 | /*
|
---|
161 | * LCDへの16ビットデータ転送
|
---|
162 | */
|
---|
163 | ER
|
---|
164 | lcd_writehalf(LCD_Handler_t *hlcd, uint32_t *buf, int cnt)
|
---|
165 | {
|
---|
166 | SPI_Handle_t *hspi = hlcd->hspi;
|
---|
167 | ER ercd = E_OK;
|
---|
168 |
|
---|
169 | set_dcx_data(hlcd);
|
---|
170 | hspi->Init.DataSize = 16;
|
---|
171 | hspi->Init.InstLength = 16;
|
---|
172 | hspi->Init.AddrLength = 0;
|
---|
173 | ercd = spi_core_transmit(hspi, hlcd->cs_sel, (uint8_t *)buf, cnt);
|
---|
174 | #if SPI_WAIT_TIME == 0
|
---|
175 | if(ercd == E_OK)
|
---|
176 | ercd = spi_wait(hspi, SPI_CORE_WAIT_TIME);
|
---|
177 | #endif
|
---|
178 | return ercd;
|
---|
179 | }
|
---|
180 |
|
---|
181 | /*
|
---|
182 | * LCD32ビットフィル
|
---|
183 | */
|
---|
184 | ER
|
---|
185 | lcd_filldata(LCD_Handler_t *hlcd, uint32_t *data_buf, uint32_t len)
|
---|
186 | {
|
---|
187 | SPI_Handle_t *hspi = hlcd->hspi;
|
---|
188 | ER ercd = E_OK;
|
---|
189 |
|
---|
190 | set_dcx_data(hlcd);
|
---|
191 | hspi->Init.DataSize = 32;
|
---|
192 | hspi->Init.InstLength = 0;
|
---|
193 | hspi->Init.AddrLength = 32;
|
---|
194 | ercd = spi_core_transmit_fill(hspi, hlcd->cs_sel, data_buf, len);
|
---|
195 | #if SPI_WAIT_TIME == 0
|
---|
196 | if(ercd == E_OK)
|
---|
197 | spi_wait(hspi, SPI_CORE_WAIT_TIME);
|
---|
198 | #endif
|
---|
199 | return ercd;
|
---|
200 | }
|
---|
201 |
|
---|
202 | /*
|
---|
203 | * SIPEED LCD初期化
|
---|
204 | */
|
---|
205 | void lcd_init(LCD_Handler_t *hlcd)
|
---|
206 | {
|
---|
207 | GPIO_Init_t init = {0};
|
---|
208 | uint8_t data = 0;
|
---|
209 |
|
---|
210 | /*
|
---|
211 | * DCXピン初期化
|
---|
212 | */
|
---|
213 | fpioa_set_function(hlcd->dcx_pin , FUNC_GPIO0 + hlcd->dcx_no);
|
---|
214 | init.mode = GPIO_MODE_OUTPUT;
|
---|
215 | init.pull = GPIO_PULLDOWN;
|
---|
216 | gpio_setup(TADR_GPIO_BASE, &init, hlcd->dcx_no);
|
---|
217 | gpio_set_pin(TADR_GPIO_BASE, hlcd->dcx_no, PORT_HIGH);
|
---|
218 |
|
---|
219 | /*
|
---|
220 | * LCDリセット
|
---|
221 | */
|
---|
222 | if(hlcd->rst_pin >= 0){
|
---|
223 | fpioa_set_function(hlcd->rst_pin , FUNC_GPIO0 + hlcd->rst_no);
|
---|
224 | init.mode = GPIO_MODE_OUTPUT;
|
---|
225 | init.pull = GPIO_PULLDOWN;
|
---|
226 | gpio_setup(TADR_GPIO_BASE, &init, hlcd->rst_no);
|
---|
227 | gpio_set_pin(TADR_GPIO_BASE, hlcd->rst_no, PORT_HIGH);
|
---|
228 |
|
---|
229 | gpio_set_pin(TADR_GPIO_BASE, hlcd->rst_no, 0);
|
---|
230 | gpio_set_pin(TADR_GPIO_BASE, hlcd->rst_no, 1);
|
---|
231 | }
|
---|
232 |
|
---|
233 | /*
|
---|
234 | * soft reset
|
---|
235 | */
|
---|
236 | lcd_writecommand(hlcd, SOFTWARE_RESET);
|
---|
237 | dly_tsk(100);
|
---|
238 | /*
|
---|
239 | * exit sleep
|
---|
240 | */
|
---|
241 | lcd_writecommand(hlcd, SLEEP_OFF);
|
---|
242 | dly_tsk(100);
|
---|
243 | /*
|
---|
244 | * pixel format
|
---|
245 | */
|
---|
246 | lcd_writecommand(hlcd, PIXEL_FORMAT_SET);
|
---|
247 | data = 0x55;
|
---|
248 | lcd_writebyte(hlcd, &data, 1);
|
---|
249 | if(hlcd->dir & DIR_XY_MASK){
|
---|
250 | hlcd->_width = ST7789_TFTHEIGHT;
|
---|
251 | hlcd->_height = ST7789_TFTWIDTH;
|
---|
252 | }
|
---|
253 | else{
|
---|
254 | hlcd->_width = ST7789_TFTWIDTH;
|
---|
255 | hlcd->_height = ST7789_TFTHEIGHT;
|
---|
256 | }
|
---|
257 | hlcd->colstart = 0;
|
---|
258 | hlcd->rowstart = 0;
|
---|
259 |
|
---|
260 | lcd_writecommand(hlcd, MEMORY_ACCESS_CTL);
|
---|
261 | lcd_writebyte(hlcd, (uint8_t *)&hlcd->dir, 1);
|
---|
262 |
|
---|
263 | /*
|
---|
264 | * display on
|
---|
265 | */
|
---|
266 | lcd_writecommand(hlcd, DISPALY_ON);
|
---|
267 | hlcd->mode = 1;
|
---|
268 | }
|
---|
269 |
|
---|
270 | /*
|
---|
271 | * 表示ウィンドウ設定
|
---|
272 | */
|
---|
273 | void
|
---|
274 | lcd_setAddrWindow(LCD_Handler_t *hlcd, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
|
---|
275 | {
|
---|
276 | uint8_t data[4] = {0};
|
---|
277 |
|
---|
278 | data[0] = (uint8_t)(x0 >> 8);
|
---|
279 | data[1] = (uint8_t)(x0);
|
---|
280 | data[2] = (uint8_t)(x1 >> 8);
|
---|
281 | data[3] = (uint8_t)(x1);
|
---|
282 | lcd_writecommand(hlcd, HORIZONTAL_ADDRESS_SET);
|
---|
283 | lcd_writebyte(hlcd, data, 4);
|
---|
284 |
|
---|
285 | data[0] = (uint8_t)(y0 >> 8);
|
---|
286 | data[1] = (uint8_t)(y0);
|
---|
287 | data[2] = (uint8_t)(y1 >> 8);
|
---|
288 | data[3] = (uint8_t)(y1);
|
---|
289 | lcd_writecommand(hlcd, VERTICAL_ADDRESS_SET);
|
---|
290 | lcd_writebyte(hlcd, data, 4);
|
---|
291 |
|
---|
292 | SVC_PERROR(lcd_writecommand(hlcd, MEMORY_WRITE));
|
---|
293 | }
|
---|
294 |
|
---|
295 | /*
|
---|
296 | * RECTANGLEのフィル描画
|
---|
297 | * param1 hlcd: Pointer to LCD Handler
|
---|
298 | * param2 x: start X position
|
---|
299 | * param3 y: start Y position
|
---|
300 | * param4 w: width
|
---|
301 | * param5 h: height
|
---|
302 | * param6 color: color value
|
---|
303 | */
|
---|
304 | void
|
---|
305 | lcd_fillRect(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t w, int16_t h, color_t color)
|
---|
306 | {
|
---|
307 | uint32_t data = ((uint32_t)color << 16) | (uint32_t)color;
|
---|
308 | // rudimentary clipping (drawChar w/big text requires this)
|
---|
309 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
310 | if((x + w - 1) >= hlcd->_width) w = hlcd->_width - x;
|
---|
311 | if((y + h - 1) >= hlcd->_height) h = hlcd->_height - y;
|
---|
312 |
|
---|
313 | lcd_setAddrWindow(hlcd, x, y, x+w-1, y+h-1);
|
---|
314 | SVC_PERROR(lcd_filldata(hlcd, &data, (h*w+1)/2));
|
---|
315 | }
|
---|
316 |
|
---|
317 | /*
|
---|
318 | * PIXEL描画
|
---|
319 | * param1 hlcd: Pointer to LCD Handler
|
---|
320 | * param2 x: X position
|
---|
321 | * param3 y: Y position
|
---|
322 | * param4 color: color value
|
---|
323 | */
|
---|
324 | void
|
---|
325 | lcd_drawPixel(LCD_Handler_t *hlcd, int16_t x, int16_t y, color_t color)
|
---|
326 | {
|
---|
327 | uint32_t data = color;
|
---|
328 | lcd_setAddrWindow(hlcd, x, y, x, y);
|
---|
329 | SVC_PERROR(lcd_writehalf(hlcd, &data, 1));
|
---|
330 | }
|
---|
331 |
|
---|
332 | /*
|
---|
333 | * 垂直方向LINEの高速描画
|
---|
334 | * param1 hlcd: Pointer to LCD Handler
|
---|
335 | * param2 x: start X position
|
---|
336 | * param3 y: start Y position
|
---|
337 | * param4 h: height
|
---|
338 | * param5 color: color value
|
---|
339 | */
|
---|
340 | void
|
---|
341 | lcd_drawFastVLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t h, color_t color)
|
---|
342 | {
|
---|
343 | uint32_t data = ((uint32_t)color << 16) | (uint32_t)color;
|
---|
344 | // Rudimentary clipping
|
---|
345 | if(h == 0) return;
|
---|
346 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
347 | if((y+h-1) >= hlcd->_height) h = hlcd->_height-y;
|
---|
348 | lcd_setAddrWindow(hlcd, x, y, x, y+h-1);
|
---|
349 | SVC_PERROR(lcd_filldata(hlcd, &data, (h+1)/2));
|
---|
350 | }
|
---|
351 |
|
---|
352 | /*
|
---|
353 | * 水平方向LINEの高速描画
|
---|
354 | * param1 hlcd: Pointer to LCD Handler
|
---|
355 | * param2 x: start X position
|
---|
356 | * param3 y: start Y position
|
---|
357 | * param4 w: width
|
---|
358 | * param5 color: color value
|
---|
359 | */
|
---|
360 | void lcd_drawFastHLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t w, color_t color)
|
---|
361 | {
|
---|
362 | uint32_t data = ((uint32_t)color << 16) | (uint32_t)color;
|
---|
363 | // Rudimentary clipping
|
---|
364 | if(w == 0) return;
|
---|
365 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
366 | if((x+w-1) >= hlcd->_width) w = hlcd->_width-x;
|
---|
367 | lcd_setAddrWindow(hlcd, x, y, x+w-1, y);
|
---|
368 | SVC_PERROR(lcd_filldata(hlcd, &data, (w+1)/2));
|
---|
369 | }
|
---|
370 |
|
---|
371 | /*
|
---|
372 | * DRAW IMAGE LINE描画
|
---|
373 | * param1 hlcd: Pointer to LCD Handler
|
---|
374 | * param2 x: X position
|
---|
375 | * param3 y: Y position
|
---|
376 | * param4 w: width
|
---|
377 | * param5 pcolor: color value
|
---|
378 | */
|
---|
379 | void
|
---|
380 | lcd_drawImageHLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, uint16_t w, uint32_t *pcolor)
|
---|
381 | {
|
---|
382 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
383 | if((x+w-1) >= hlcd->_width) w = hlcd->_width-x;
|
---|
384 | lcd_setAddrWindow(hlcd, x, y, x+w-1, y);
|
---|
385 | SVC_PERROR(lcd_writehalf(hlcd, pcolor, w));
|
---|
386 | }
|
---|
387 |
|
---|
388 | /*
|
---|
389 | * BITMAP描画
|
---|
390 | * param1 hlcd: Pointer to LCD Handler
|
---|
391 | * param2 x0: Bmp X position in the LCD
|
---|
392 | * param3 y0: Bmp Y position in the LCD
|
---|
393 | * param4 pbmp: Pointer to Bmp picture address in the internal Flash
|
---|
394 | */
|
---|
395 | void
|
---|
396 | lcd_drawBitmap(LCD_Handler_t *hlcd, uint16_t x0, uint16_t y0, uint8_t *pbmp)
|
---|
397 | {
|
---|
398 | uint32_t index = 0, width = 0, height = 0, bit_pixel = 0;
|
---|
399 | uint32_t input_color_mode = 0;
|
---|
400 | uint32_t i;
|
---|
401 |
|
---|
402 | /* Get bitmap data address offset */
|
---|
403 | index = *(uint16_t *) (pbmp + 10);
|
---|
404 | index |= (*(uint16_t *) (pbmp + 12)) << 16;
|
---|
405 |
|
---|
406 | /* Read bitmap width */
|
---|
407 | width = *(uint16_t *) (pbmp + 18);
|
---|
408 | width |= (*(uint16_t *) (pbmp + 20)) << 16;
|
---|
409 |
|
---|
410 | /* Read bitmap height */
|
---|
411 | height = *(uint16_t *) (pbmp + 22);
|
---|
412 | height |= (*(uint16_t *) (pbmp + 24)) << 16;
|
---|
413 |
|
---|
414 | /* Read bit/pixel */
|
---|
415 | bit_pixel = *(uint16_t *) (pbmp + 28);
|
---|
416 |
|
---|
417 | /* Get the layer pixel format */
|
---|
418 | if ((bit_pixel/8) == 4){
|
---|
419 | input_color_mode = CM_ARGB8888;
|
---|
420 | }
|
---|
421 | else if ((bit_pixel/8) == 2){
|
---|
422 | input_color_mode = CM_RGB565;
|
---|
423 | }
|
---|
424 | else{
|
---|
425 | input_color_mode = CM_RGB888;
|
---|
426 | }
|
---|
427 |
|
---|
428 | /* Bypass the bitmap header */
|
---|
429 | pbmp += (index + (width * (height - 1) * (bit_pixel/8)));
|
---|
430 | syslog_4(LOG_NOTICE, "## input_color_mode(%d) width(%d) height(%d) bit_pixel(%d) ##", input_color_mode, width, height, bit_pixel);
|
---|
431 | for(index=0; index < height; index++){
|
---|
432 | uint8_t *p = pbmp;
|
---|
433 | color_t color;
|
---|
434 | for (i = 0; i < width; i++){
|
---|
435 | color = ((p[0] & 0xf8) | (p[1] >> 5)) << 8;
|
---|
436 | color |= ((p[1] << 3) & 0xE0) | ((p[2] >> 3) & 0x1F);
|
---|
437 | lcd_drawPixel(hlcd, x0+i, y0+index, color);
|
---|
438 | p += 3;
|
---|
439 | }
|
---|
440 | pbmp -= width*3;
|
---|
441 | }
|
---|
442 | }
|
---|
443 |
|
---|
444 | /*
|
---|
445 | * PICTURE描画
|
---|
446 | * param1 hlcd: Pointer to LCD Handler
|
---|
447 | * param2 x: Picture X position in the LCD
|
---|
448 | * param3 y: Picture Y position in the LCD
|
---|
449 | * param4 width: Picture width
|
---|
450 | * param5 height: Picture heigth
|
---|
451 | * param6 pbmp: Pointer to picture address in the internal Flash
|
---|
452 | */
|
---|
453 | void
|
---|
454 | lcd_drawPicture(LCD_Handler_t *hlcd, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t *pbmp)
|
---|
455 | {
|
---|
456 | SPI_Handle_t *hspi = hlcd->hspi;
|
---|
457 | ER ercd = E_OK;
|
---|
458 |
|
---|
459 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
460 | if((x+width-1) > hlcd->_width) return;
|
---|
461 | if((y+height-1) > hlcd->_height) return;
|
---|
462 |
|
---|
463 | lcd_setAddrWindow(hlcd, x, y, x+width-1, y+height-1);
|
---|
464 | set_dcx_data(hlcd);
|
---|
465 | hspi->Init.DataSize = 32;
|
---|
466 | hspi->Init.InstLength = 0;
|
---|
467 | hspi->Init.AddrLength = 32;
|
---|
468 | ercd = spi_core_transmit(hspi, hlcd->cs_sel, (uint8_t *)pbmp, width * height / 2);
|
---|
469 | #if SPI_WAIT_TIME == 0
|
---|
470 | if(ercd == E_OK)
|
---|
471 | spi_wait(hspi, SPI_CORE_WAIT_TIME);
|
---|
472 | #endif
|
---|
473 | (void)(ercd);
|
---|
474 | }
|
---|
475 |
|
---|
476 | /*
|
---|
477 | * INVERT DISPLAY
|
---|
478 | * param1 hlcd: Pointer to LCD Handler
|
---|
479 | * param2 i: invert value
|
---|
480 | */
|
---|
481 | void
|
---|
482 | lcd_invertDisplay(LCD_Handler_t *hlcd, bool_t i)
|
---|
483 | {
|
---|
484 | lcd_writecommand(hlcd, (i ? INVERSION_DISPALY_ON : INVERSION_DISPALY_OFF));
|
---|
485 | }
|
---|
486 |
|
---|
487 |
|
---|
488 | /*
|
---|
489 | * スクリーンフィル
|
---|
490 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
491 | */
|
---|
492 | void
|
---|
493 | lcd_fillScreen(LCD_DrawProp_t *pDrawProp)
|
---|
494 | {
|
---|
495 | lcd_fillRect(pDrawProp->hlcd, 0, 0, pDrawProp->hlcd->_width, pDrawProp->hlcd->_height, pDrawProp->BackColor);
|
---|
496 | }
|
---|
497 |
|
---|
498 | /*
|
---|
499 | * RECTANGLE描画
|
---|
500 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
501 | * param2 x: left X position
|
---|
502 | * param3 y: top Y position
|
---|
503 | * param4 w: width
|
---|
504 | * param5 h: height
|
---|
505 | */
|
---|
506 | void
|
---|
507 | lcd_drawRect(LCD_DrawProp_t *pDrawProp, int16_t x, int16_t y, int16_t w, int16_t h)
|
---|
508 | {
|
---|
509 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
510 | color_t color;
|
---|
511 |
|
---|
512 | // rudimentary clipping (drawChar w/big text requires this)
|
---|
513 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
514 | if((x + w - 1) >= hlcd->_width) w = hlcd->_width - x;
|
---|
515 | if((y + h - 1) >= hlcd->_height) h = hlcd->_height - y;
|
---|
516 |
|
---|
517 | color = pDrawProp->TextColor;
|
---|
518 | lcd_drawFastVLine(hlcd, x, y, h, color);
|
---|
519 | lcd_drawFastHLine(hlcd, x, y+h-1, w, color);
|
---|
520 | lcd_drawFastVLine(hlcd, x+w-1, y, h, color);
|
---|
521 | lcd_drawFastHLine(hlcd, x, y, w, color);
|
---|
522 | }
|
---|
523 |
|
---|
524 | /*
|
---|
525 | * 円描画
|
---|
526 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
527 | * param2 x0: X position
|
---|
528 | * param3 y0: Y position
|
---|
529 | * param4 Radius: Circle radius
|
---|
530 | */
|
---|
531 | void
|
---|
532 | lcd_DrawCircle(LCD_DrawProp_t *pDrawProp, uint16_t x0, uint16_t y0, uint16_t Radius)
|
---|
533 | {
|
---|
534 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
535 | int32_t decision; /* Decision Variable */
|
---|
536 | uint32_t current_x; /* Current X Value */
|
---|
537 | uint32_t current_y; /* Current Y Value */
|
---|
538 |
|
---|
539 | decision = 3 - (Radius << 1);
|
---|
540 | current_x = 0;
|
---|
541 | current_y = Radius;
|
---|
542 |
|
---|
543 | while(current_x <= current_y){
|
---|
544 | lcd_drawPixel(hlcd, (x0 + current_x), (y0 - current_y), pDrawProp->TextColor);
|
---|
545 | lcd_drawPixel(hlcd, (x0 - current_x), (y0 - current_y), pDrawProp->TextColor);
|
---|
546 | lcd_drawPixel(hlcd, (x0 + current_y), (y0 - current_x), pDrawProp->TextColor);
|
---|
547 | lcd_drawPixel(hlcd, (x0 - current_y), (y0 - current_x), pDrawProp->TextColor);
|
---|
548 | lcd_drawPixel(hlcd, (x0 + current_x), (y0 + current_y), pDrawProp->TextColor);
|
---|
549 | lcd_drawPixel(hlcd, (x0 - current_x), (y0 + current_y), pDrawProp->TextColor);
|
---|
550 | lcd_drawPixel(hlcd, (x0 + current_y), (y0 + current_x), pDrawProp->TextColor);
|
---|
551 | lcd_drawPixel(hlcd, (x0 - current_y), (y0 + current_x), pDrawProp->TextColor);
|
---|
552 |
|
---|
553 | if (decision < 0){
|
---|
554 | decision += (current_x << 2) + 6;
|
---|
555 | }
|
---|
556 | else{
|
---|
557 | decision += ((current_x - current_y) << 2) + 10;
|
---|
558 | current_y--;
|
---|
559 | }
|
---|
560 | current_x++;
|
---|
561 | }
|
---|
562 | }
|
---|
563 |
|
---|
564 | /*
|
---|
565 | * 線描画
|
---|
566 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
567 | * param2 x1: Point 1 X position
|
---|
568 | * param3 y1: Point 1 Y position
|
---|
569 | * param4 x2: Point 2 X position
|
---|
570 | * param5 y2: Point 2 Y position
|
---|
571 | */
|
---|
572 | void
|
---|
573 | lcd_drawLine(LCD_DrawProp_t *pDrawProp, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
|
---|
574 | {
|
---|
575 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
576 | int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
|
---|
577 | yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0,
|
---|
578 | curpixel = 0;
|
---|
579 |
|
---|
580 | deltax = ABS(x2 - x1); /* The difference between the x's */
|
---|
581 | deltay = ABS(y2 - y1); /* The difference between the y's */
|
---|
582 | x = x1; /* Start x off at the first pixel */
|
---|
583 | y = y1; /* Start y off at the first pixel */
|
---|
584 |
|
---|
585 | if(x2 >= x1){ /* The x-values are increasing */
|
---|
586 | xinc1 = 1;
|
---|
587 | xinc2 = 1;
|
---|
588 | }
|
---|
589 | else{ /* The x-values are decreasing */
|
---|
590 | xinc1 = -1;
|
---|
591 | xinc2 = -1;
|
---|
592 | }
|
---|
593 |
|
---|
594 | if(y2 >= y1){ /* The y-values are increasing */
|
---|
595 | yinc1 = 1;
|
---|
596 | yinc2 = 1;
|
---|
597 | }
|
---|
598 | else{ /* The y-values are decreasing */
|
---|
599 | yinc1 = -1;
|
---|
600 | yinc2 = -1;
|
---|
601 | }
|
---|
602 |
|
---|
603 | if(deltax >= deltay){ /* There is at least one x-value for every y-value */
|
---|
604 | xinc1 = 0; /* Don't change the x when numerator >= denominator */
|
---|
605 | yinc2 = 0; /* Don't change the y for every iteration */
|
---|
606 | den = deltax;
|
---|
607 | num = deltax / 2;
|
---|
608 | num_add = deltay;
|
---|
609 | num_pixels = deltax; /* There are more x-values than y-values */
|
---|
610 | }
|
---|
611 | else{ /* There is at least one y-value for every x-value */
|
---|
612 | xinc2 = 0; /* Don't change the x for every iteration */
|
---|
613 | yinc1 = 0; /* Don't change the y when numerator >= denominator */
|
---|
614 | den = deltay;
|
---|
615 | num = deltay / 2;
|
---|
616 | num_add = deltax;
|
---|
617 | num_pixels = deltay; /* There are more y-values than x-values */
|
---|
618 | }
|
---|
619 |
|
---|
620 | for (curpixel = 0; curpixel <= num_pixels; curpixel++){
|
---|
621 | lcd_drawPixel(hlcd, x, y, pDrawProp->TextColor); /* Draw the current pixel */
|
---|
622 | num += num_add; /* Increase the numerator by the top of the fraction */
|
---|
623 | if(num >= den){ /* Check if numerator >= denominator */
|
---|
624 | num -= den; /* Calculate the new numerator value */
|
---|
625 | x += xinc1; /* Change the x as appropriate */
|
---|
626 | y += yinc1; /* Change the y as appropriate */
|
---|
627 | }
|
---|
628 | x += xinc2; /* Change the x as appropriate */
|
---|
629 | y += yinc2; /* Change the y as appropriate */
|
---|
630 | }
|
---|
631 | }
|
---|
632 |
|
---|
633 | /*
|
---|
634 | * PLOY-LINE描画
|
---|
635 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
636 | * param2 Points: Pointer to the points array
|
---|
637 | * param3 PointCount: Number of points
|
---|
638 | */
|
---|
639 | void
|
---|
640 | lcd_drawPolygon(LCD_DrawProp_t *pDrawProp, pPoint Points, uint16_t PointCount)
|
---|
641 | {
|
---|
642 | int16_t x = 0, y = 0;
|
---|
643 |
|
---|
644 | if(PointCount < 2){
|
---|
645 | return;
|
---|
646 | }
|
---|
647 |
|
---|
648 | lcd_drawLine(pDrawProp, Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
|
---|
649 | while(--PointCount){
|
---|
650 | x = Points->X;
|
---|
651 | y = Points->Y;
|
---|
652 | Points++;
|
---|
653 | lcd_drawLine(pDrawProp, x, y, Points->X, Points->Y);
|
---|
654 | }
|
---|
655 | }
|
---|
656 |
|
---|