source: azure_iot_hub_f767zi/trunk/asp_baseplatform/gdic/aqm1248_st7565/aqm1248_st7565.c@ 457

Last change on this file since 457 was 457, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 18.0 KB
Line 
1/*
2 * TOPPERS BASE PLATFORM MIDDLEWARE
3 *
4 * Copyright (C) 2017-2019 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 * AQM1248 ST7565 LCD制御プログラムの本体
41 */
42
43#include <kernel.h>
44#include <t_syslog.h>
45#include <t_stdlib.h>
46#include <stdio.h>
47#include <string.h>
48#include <target_syssvc.h>
49#include "syssvc/serial.h"
50#include "syssvc/syslog.h"
51#include "kernel_cfg.h"
52#include "device.h"
53#include "aqm1248_st7565.h"
54
55/*
56 * サービスコールのエラーのログ出力
57 */
58Inline void
59svc_perror(const char *file, int_t line, const char *expr, ER ercd)
60{
61 if (ercd < 0) {
62 t_perror(LOG_ERROR, file, line, expr, ercd);
63 }
64}
65
66#define SVC_PERROR(expr) svc_perror(__FILE__, __LINE__, #expr, (expr))
67#define ABS(X) ((X) > 0 ? (X) : -(X))
68
69#define PORT_HIGH 1
70#define PORT_LOW 0
71
72#define cs_set(sw) digitalWrite(hlcd->cs_pin, sw)
73#define rs_set(sw) digitalWrite(hlcd->rs_pin, sw)
74#define rst_set(sw) digitalWrite(hlcd->rst_pin, sw)
75
76static const uint8_t left_mask_table[8] = {
77 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01
78};
79
80static const uint8_t right_mask_table[8] = {
81 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF
82};
83
84static const uint8_t dither_table[8][8] = {
85 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* BLACK */
86 {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55}, /* BLUE */
87 {0xFA, 0x5F, 0xF5, 0xAF, 0xFA, 0x5F, 0xF5, 0xAF}, /* GREEN */
88 {0xFD, 0xDF, 0xFB, 0xBF, 0xFD, 0xDF, 0xFB, 0xBF}, /* CYAN */
89 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA}, /* RED */
90 {0xAF, 0xF5, 0x5F, 0xFA, 0xAF, 0xF5, 0x5F, 0xFA}, /* MAGENTA */
91 {0xDF, 0xFD, 0xBF, 0xFB, 0xDF, 0xFD, 0xBF, 0xFB}, /* YELLOW */
92 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} /* WHITE */
93};
94
95/* Buffer used for transmission */
96static uint8_t aTxBuffer[4];
97
98
99/*
100 * バッファデータをLCDに転送
101 */
102static void
103lcd_flush_buffer(LCD_Handler_t *hlcd)
104{
105 uint32_t l, col, i;
106 uint8_t page, val1, val2;
107
108 for(l = hlcd->_winy1 ; l <= hlcd->_winy2 ; l += AQM1248_PLINE){
109 page = l / AQM1248_PLINE;
110 col = hlcd->_winx1;
111 SVC_PERROR(lcd_writecommand(hlcd, ST7565_PAGEADR + page));
112 SVC_PERROR(lcd_writecommand(hlcd, ST7565_COLADR + (col >> 4)));
113 SVC_PERROR(lcd_writecommand(hlcd, (col & 0x0f)));
114 for(; col <= hlcd->_winx2 ; col++){
115 for(i = val1 = 0 ; i < 8 ; i++){
116 val2 = hlcd->buffer[(page * AQM1248_PLINE) + i][col/8] << (col & 7);
117 val1 |= (val2 & 0x80) >> (7 - i);
118 }
119 SVC_PERROR(lcd_writedata(hlcd, val1));
120 }
121 }
122}
123
124/*
125 * バッファ上にイメージを作る
126 */
127static void
128lcd_fill_buffer(LCD_Handler_t *hlcd, color_t color)
129{
130 uint32_t x, y;
131 uint8_t *p;
132
133 color &= 7;
134 for(y = hlcd->_winy1 ; y <= hlcd->_winy2 ; y++){
135 p = &hlcd->buffer[y][hlcd->_winx1/8];
136 for(x = 0 ; x < hlcd->stride ; x++, p++){
137 if(x == 0){
138 *p &= ~hlcd->lmask;
139 *p |= dither_table[color][y & 7] & hlcd->lmask;
140 }
141 else if(x == (hlcd->stride-1)){
142 *p &= ~hlcd->rmask;
143 *p |= dither_table[color][y & 7] & hlcd->rmask;
144 }
145 else
146 *p = dither_table[color][y & 7];
147 }
148 }
149}
150
151/*
152 * LCDへのコマンド送信関数
153 */
154ER
155lcd_writecommand(LCD_Handler_t *hlcd, uint8_t c)
156{
157 ER ercd = E_OK;
158
159 if(hlcd->spi_lock != 0){
160 if((ercd = wai_sem(hlcd->spi_lock)) != E_OK)
161 return ercd;
162 }
163 rs_set(PORT_LOW);
164 cs_set(PORT_LOW);
165
166 aTxBuffer[0] = c;
167#if SPI_WAIT_TIME != 0
168 ercd = spi_transmit(hlcd->hspi, (uint8_t*)aTxBuffer, 1);
169#else
170 if((ercd = spi_transmit(hlcd->hspi, (uint8_t*)aTxBuffer, 1)) == E_OK){
171 ercd = spi_wait(hlcd->hspi, 100);
172 }
173#endif
174
175 cs_set(PORT_HIGH);
176 if(hlcd->spi_lock != 0)
177 sig_sem(hlcd->spi_lock);
178 return ercd;
179}
180
181/*
182 * LCDへのデータ送信関数
183 */
184ER
185lcd_writedata(LCD_Handler_t *hlcd, uint8_t c)
186{
187 ER ercd = E_OK;
188
189 if(hlcd->spi_lock != 0){
190 if((ercd = wai_sem(hlcd->spi_lock)) != E_OK)
191 return ercd;
192 }
193 rs_set(PORT_HIGH);
194 cs_set(PORT_LOW);
195 sil_dly_nse(100);
196
197 aTxBuffer[0] = c;
198#if SPI_WAIT_TIME != 0
199 ercd = spi_transmit(hlcd->hspi, (uint8_t*)aTxBuffer, 1);
200#else
201 if((ercd = spi_transmit(hlcd->hspi, (uint8_t*)aTxBuffer, 1)) == E_OK){
202 ercd = spi_wait(hlcd->hspi, 100);
203 }
204#endif
205
206 sil_dly_nse(100);
207 cs_set(PORT_HIGH);
208 if(hlcd->spi_lock != 0)
209 sig_sem(hlcd->spi_lock);
210 return ercd;
211}
212
213
214/*
215 * ST7565 LCDの初期化関数
216 */
217void
218lcd_init(LCD_Handler_t *hlcd)
219{
220 uint32_t i;
221
222 rst_set(PORT_LOW);
223 dly_tsk(100);
224 rst_set(PORT_HIGH);
225 dly_tsk(100);
226
227 hlcd->_width = AQM1248_WIDTH;
228 hlcd->_height = AQM1248_HEIGHT;
229
230 SVC_PERROR(lcd_writecommand(hlcd, ST7565_DISPOFF)); /* 表示OFF */
231 SVC_PERROR(lcd_writecommand(hlcd, ST7565_ADCSELN)); /* ADC select normal */
232 SVC_PERROR(lcd_writecommand(hlcd, ST7565_COMOUTR)); /* comon output reverse */
233 SVC_PERROR(lcd_writecommand(hlcd, ST7565_BIAS17)); /* lcd bias 1/7 */
234
235 SVC_PERROR(lcd_writecommand(hlcd, ST7565_PWRSEL+4)); /* power select 1 */
236 dly_tsk(2);
237 SVC_PERROR(lcd_writecommand(hlcd, ST7565_PWRSEL+6)); /* power select 2 */
238 dly_tsk(2);
239 SVC_PERROR(lcd_writecommand(hlcd, ST7565_PWRSEL+7)); /* power select 3 */
240
241 SVC_PERROR(lcd_writecommand(hlcd, ST7565_RATSEL+3)); /* voltage resistor ratio 3 */
242 SVC_PERROR(lcd_writecommand(hlcd, ST7565_SETEVOL)); /* electronic volume set */
243 SVC_PERROR(lcd_writecommand(hlcd, 0x1C)); /* volume value */
244
245 SVC_PERROR(lcd_writecommand(hlcd, ST7565_ALLPNL)); /* all point normal */
246 SVC_PERROR(lcd_writecommand(hlcd, ST7565_STRLINE)); /* start line #0 */
247 SVC_PERROR(lcd_writecommand(hlcd, ST7565_DISPREV)); /* 表示reverse */
248 SVC_PERROR(lcd_writecommand(hlcd, ST7565_DISPON)); /* 表示ON */
249 for(i = 0 ; i < AQM1248_HEIGHT ; i++)
250 memset(&hlcd->buffer[i][0], 0xff, AQM1248_WIDTH/8);
251}
252
253/*
254 * 表示ウィンドウ設定
255 */
256void
257lcd_setAddrWindow(LCD_Handler_t *hlcd, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
258{
259 uint8_t hx = x0 & 7;
260
261 hlcd->_winx1 = x0;
262 hlcd->_winy1 = y0;
263 hlcd->_winx2 = x1;
264 hlcd->_winy2 = y1;
265 hlcd->lmask = left_mask_table[hx];
266 hlcd->rmask = right_mask_table[x1 & 7];
267 if(hx == 0)
268 hlcd->stride = (x1 - x0 + 8) / 8;
269 else
270 hlcd->stride = (x1 - x0 + hx) / 8 + 1;
271 if(hlcd->stride == 1)
272 hlcd->lmask &= hlcd->rmask;
273}
274
275/*
276 * RECTANGLEのフィル描画
277 * param1 hlcd: Pointer to LCD Handler
278 * param2 x: start X position
279 * param3 y: start Y position
280 * param4 w: width
281 * param5 h: height
282 * param6 color: color value
283 */
284void
285lcd_fillRect(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t w, int16_t h, color_t color)
286{
287 // rudimentary clipping (drawChar w/big text requires this)
288 if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
289 if((x + w - 1) >= hlcd->_width) w = hlcd->_width - x;
290 if((y + h - 1) >= hlcd->_height) h = hlcd->_height - y;
291
292 lcd_setAddrWindow(hlcd, x, y, x+w-1, y+h-1);
293 lcd_fill_buffer(hlcd, color);
294 lcd_flush_buffer(hlcd);
295}
296
297/*
298 * PIXEL描画
299 * param1 hlcd: Pointer to LCD Handler
300 * param2 x: X position
301 * param3 y: Y position
302 * param4 color: color value
303 */
304void
305lcd_drawPixel(LCD_Handler_t *hlcd, int16_t x, int16_t y, color_t color)
306{
307 if((x < 0) ||(x >= hlcd->_width) || (y < 0) || (y >= hlcd->_height)) return;
308
309 lcd_setAddrWindow(hlcd, x, y, x, y);
310 lcd_fill_buffer(hlcd, color);
311 lcd_flush_buffer(hlcd);
312}
313
314/*
315 * 垂直方向LINEの高速描画
316 * param1 hlcd: Pointer to LCD Handler
317 * param2 x: start X position
318 * param3 y: start Y position
319 * param4 h: height
320 * param5 color: color value
321 */
322void
323lcd_drawFastVLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t h, color_t color)
324{
325 // Rudimentary clipping
326 if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
327 if((y+h-1) >= hlcd->_height) h = hlcd->_height-y;
328 lcd_setAddrWindow(hlcd, x, y, x, y+h-1);
329 lcd_fill_buffer(hlcd, color);
330 lcd_flush_buffer(hlcd);
331}
332
333/*
334 * 水平方向LINEの高速描画
335 * param1 hlcd: Pointer to LCD Handler
336 * param2 x: start X position
337 * param3 y: start Y position
338 * param4 w: width
339 * param5 color: color value
340 */
341void lcd_drawFastHLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t w, color_t color)
342{
343 // Rudimentary clipping
344 if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
345 if((x+w-1) >= hlcd->_width) w = hlcd->_width-x;
346 lcd_setAddrWindow(hlcd, x, y, x+w-1, y);
347 lcd_fill_buffer(hlcd, color);
348 lcd_flush_buffer(hlcd);
349}
350
351/*
352 * DRAW IMAGE LINE描画
353 * param1 hlcd: Pointer to LCD Handler
354 * param2 x: X position
355 * param3 y: Y position
356 * param4 w: width
357 * param5 pcolor: color value
358 */
359void
360lcd_drawImageHLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, uint16_t w, color_t *pcolor)
361{
362 uint32_t i;
363
364 if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
365 if((x+w-1) >= hlcd->_width) w = hlcd->_width-x;
366
367 for(i = 0 ; i < w ; i++, pcolor++){
368 lcd_setAddrWindow(hlcd, x+i, y, x+i, y);
369 lcd_fill_buffer(hlcd, *pcolor);
370 lcd_flush_buffer(hlcd);
371 }
372}
373
374/*
375 * BITMAP描画
376 * param1 hlcd: Pointer to LCD Handler
377 * param2 x0: Bmp X position in the LCD
378 * param3 y0: Bmp Y position in the LCD
379 * param4 pbmp: Pointer to Bmp picture address in the internal Flash
380 */
381void
382lcd_drawBitmap(LCD_Handler_t *hlcd, uint16_t x0, uint16_t y0, uint8_t *pbmp)
383{
384 uint32_t index = 0, width = 0, height = 0, bit_pixel = 0;
385 uint32_t input_color_mode = 0;
386 uint16_t val, l, col;
387
388 /* Get bitmap data address offset */
389 index = *(uint16_t *) (pbmp + 10);
390 index |= (*(uint16_t *) (pbmp + 12)) << 16;
391
392 /* Read bitmap width */
393 width = *(uint16_t *) (pbmp + 18);
394 width |= (*(uint16_t *) (pbmp + 20)) << 16;
395
396 /* Read bitmap height */
397 height = *(uint16_t *) (pbmp + 22);
398 height |= (*(uint16_t *) (pbmp + 24)) << 16;
399
400 /* Read bit/pixel */
401 bit_pixel = *(uint16_t *) (pbmp + 28);
402
403 /* Get the layer pixel format */
404 if ((bit_pixel/8) == 4){
405 input_color_mode = CM_ARGB8888;
406 }
407 else if ((bit_pixel/8) == 2){
408 input_color_mode = CM_RGB565;
409 }
410 else{
411 input_color_mode = CM_RGB888;
412 }
413
414 /* Bypass the bitmap header */
415 pbmp += (index + (width * (height - 1) * (bit_pixel/8)));
416 syslog_4(LOG_NOTICE, "## input_color_mode(%d) width(%d) height(%d) bit_pixel(%d) ##", input_color_mode, width, height, bit_pixel);
417
418 for(l = 0 ; l < height ; l++){
419 uint8_t *p = pbmp;
420 for(col = 0 ; col < width ; col++){
421 switch(input_color_mode){
422 case CM_RGB565:
423 if((*p & 0xC0) == 0xC0)
424 val = 0x04;
425 else
426 val = 0x00;
427 if((*p++ & 0x06) == 0x06)
428 val |= 0x02;
429 if((*p++ & 0x18) == 0x18)
430 val |= 0x01;
431 break;
432 default:
433 if((*p++ & 0xE0) == 0xE0)
434 val = 0x04;
435 else
436 val = 0x00;
437 if((*p++ & 0xE0) == 0xE0)
438 val |= 0x02;
439 if((*p++ & 0xE0) == 0xE0)
440 val |= 0x01;
441 break;
442 }
443 if((l+y0) < hlcd->_height)
444 lcd_drawPixel(hlcd, col+x0, l+y0, val);
445 }
446 pbmp -= (bit_pixel/8) * width;
447 }
448}
449
450/*
451 * INVERT DISPLAY
452 * param1 hlcd: Pointer to LCD Handler
453 * param2 i: invert value
454 */
455void
456lcd_invertDisplay(LCD_Handler_t *hlcd, bool_t i)
457{
458 SVC_PERROR(lcd_writecommand(hlcd, i ? ST7565_DISPNOR : ST7565_DISPREV));
459}
460
461
462/*
463 * スクリーンフィル
464 * param1 pDrawProp: Pointer to Draw Prop
465 */
466void
467lcd_fillScreen(LCD_DrawProp_t *pDrawProp)
468{
469 lcd_fillRect(pDrawProp->hlcd, 0, 0, pDrawProp->hlcd->_width, pDrawProp->hlcd->_height, pDrawProp->BackColor);
470}
471
472/*
473 * RECTANGLE描画
474 * param1 pDrawProp: Pointer to Draw Prop
475 * param2 x: left X position
476 * param3 y: top Y position
477 * param4 w: width
478 * param5 h: height
479 */
480void
481lcd_drawRect(LCD_DrawProp_t *pDrawProp, int16_t x, int16_t y, int16_t w, int16_t h)
482{
483 LCD_Handler_t *hlcd = pDrawProp->hlcd;
484 color_t color;
485
486 // rudimentary clipping (drawChar w/big text requires this)
487 if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
488 if(y < 0) return;
489 if((x + w - 1) >= hlcd->_width) w = hlcd->_width - x;
490 if((y + h - 1) >= hlcd->_height) h = hlcd->_height - y;
491
492 color = pDrawProp->TextColor;
493 lcd_drawFastVLine(hlcd, x, y, h, color);
494 lcd_drawFastHLine(hlcd, x, y+h-1, w, color);
495 lcd_drawFastVLine(hlcd, x+w-1, y, h, color);
496 lcd_drawFastHLine(hlcd, x, y, w, color);
497}
498
499/*
500 * 円描画
501 * param1 pDrawProp: Pointer to Draw Prop
502 * param2 x0: X position
503 * param3 y0: Y position
504 * param4 Radius: Circle radius
505 */
506void
507lcd_DrawCircle(LCD_DrawProp_t *pDrawProp, uint16_t x0, uint16_t y0, uint16_t Radius)
508{
509 LCD_Handler_t *hlcd = pDrawProp->hlcd;
510 int32_t decision; /* Decision Variable */
511 uint32_t current_x; /* Current X Value */
512 uint32_t current_y; /* Current Y Value */
513
514 decision = 3 - (Radius << 1);
515 current_x = 0;
516 current_y = Radius;
517
518 while(current_x <= current_y){
519 lcd_drawPixel(hlcd, (x0 + current_x), (y0 - current_y), pDrawProp->TextColor);
520 lcd_drawPixel(hlcd, (x0 - current_x), (y0 - current_y), pDrawProp->TextColor);
521 lcd_drawPixel(hlcd, (x0 + current_y), (y0 - current_x), pDrawProp->TextColor);
522 lcd_drawPixel(hlcd, (x0 - current_y), (y0 - current_x), pDrawProp->TextColor);
523 lcd_drawPixel(hlcd, (x0 + current_x), (y0 + current_y), pDrawProp->TextColor);
524 lcd_drawPixel(hlcd, (x0 - current_x), (y0 + current_y), pDrawProp->TextColor);
525 lcd_drawPixel(hlcd, (x0 + current_y), (y0 + current_x), pDrawProp->TextColor);
526 lcd_drawPixel(hlcd, (x0 - current_y), (y0 + current_x), pDrawProp->TextColor);
527
528 if (decision < 0){
529 decision += (current_x << 2) + 6;
530 }
531 else{
532 decision += ((current_x - current_y) << 2) + 10;
533 current_y--;
534 }
535 current_x++;
536 }
537}
538
539/*
540 * 線描画
541 * param1 pDrawProp: Pointer to Draw Prop
542 * param2 x1: Point 1 X position
543 * param3 y1: Point 1 Y position
544 * param4 x2: Point 2 X position
545 * param5 y2: Point 2 Y position
546 */
547void
548lcd_drawLine(LCD_DrawProp_t *pDrawProp, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
549{
550 LCD_Handler_t *hlcd = pDrawProp->hlcd;
551 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
552 yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0,
553 curpixel = 0;
554
555 deltax = ABS(x2 - x1); /* The difference between the x's */
556 deltay = ABS(y2 - y1); /* The difference between the y's */
557 x = x1; /* Start x off at the first pixel */
558 y = y1; /* Start y off at the first pixel */
559
560 if(x2 >= x1){ /* The x-values are increasing */
561 xinc1 = 1;
562 xinc2 = 1;
563 }
564 else{ /* The x-values are decreasing */
565 xinc1 = -1;
566 xinc2 = -1;
567 }
568
569 if(y2 >= y1){ /* The y-values are increasing */
570 yinc1 = 1;
571 yinc2 = 1;
572 }
573 else{ /* The y-values are decreasing */
574 yinc1 = -1;
575 yinc2 = -1;
576 }
577
578 if(deltax >= deltay){ /* There is at least one x-value for every y-value */
579 xinc1 = 0; /* Don't change the x when numerator >= denominator */
580 yinc2 = 0; /* Don't change the y for every iteration */
581 den = deltax;
582 num = deltax / 2;
583 num_add = deltay;
584 num_pixels = deltax; /* There are more x-values than y-values */
585 }
586 else{ /* There is at least one y-value for every x-value */
587 xinc2 = 0; /* Don't change the x for every iteration */
588 yinc1 = 0; /* Don't change the y when numerator >= denominator */
589 den = deltay;
590 num = deltay / 2;
591 num_add = deltax;
592 num_pixels = deltay; /* There are more y-values than x-values */
593 }
594
595 for (curpixel = 0; curpixel <= num_pixels; curpixel++){
596 lcd_drawPixel(hlcd, x, y, pDrawProp->TextColor); /* Draw the current pixel */
597 num += num_add; /* Increase the numerator by the top of the fraction */
598 if(num >= den){ /* Check if numerator >= denominator */
599 num -= den; /* Calculate the new numerator value */
600 x += xinc1; /* Change the x as appropriate */
601 y += yinc1; /* Change the y as appropriate */
602 }
603 x += xinc2; /* Change the x as appropriate */
604 y += yinc2; /* Change the y as appropriate */
605 }
606}
607
608/*
609 * PLOY-LINE描画
610 * param1 pDrawProp: Pointer to Draw Prop
611 * param2 Points: Pointer to the points array
612 * param3 PointCount: Number of points
613 */
614void
615lcd_drawPolygon(LCD_DrawProp_t *pDrawProp, pPoint Points, uint16_t PointCount)
616{
617 int16_t x = 0, y = 0;
618
619 if(PointCount < 2){
620 return;
621 }
622
623 lcd_drawLine(pDrawProp, Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
624 while(--PointCount){
625 x = Points->X;
626 y = Points->Y;
627 Points++;
628 lcd_drawLine(pDrawProp, x, y, Points->X, Points->Y);
629 }
630}
631
Note: See TracBrowser for help on using the repository browser.