/* * TOPPERS/ASP Kernel * Toyohashi Open Platform for Embedded Real-Time Systems/ * Advanced Standard Profile Kernel * * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory * Toyohashi Univ. of Technology, JAPAN * Copyright (C) 2004-2012 by Embedded and Real-Time Systems Laboratory * Graduate School of Information Science, Nagoya Univ., JAPAN * Copyright (C) 2015-2020 by TOPPERS PROJECT Educational Working Group. * * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改 * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する. * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー * スコード中に含まれていること. * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記 * の無保証規定を掲載すること. * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ * と. * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著 * 作権表示,この利用条件および下記の無保証規定を掲載すること. * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに * 報告すること. * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること. * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを * 免責すること. * * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ * の責任を負わない. * * $Id$ */ /* * Written by Limor Fried/Ladyada for Adafruit Industries. * MIT license, all text above must be included in any redistribution * http://opensource.org/licenses/mit-license.php */ /* * ADAFRUIT ST7789 LCD制御プログラムの本体 */ #include #include #include #include #include #include #include "syssvc/serial.h" #include "syssvc/syslog.h" #include "device.h" #include "adafruit_st7789.h" /* * サービスコールのエラーのログ出力 */ Inline void svc_perror(const char *file, int_t line, const char *expr, ER ercd) { if (ercd < 0) { t_perror(LOG_ERROR, file, line, expr, ercd); } } #define SVC_PERROR(expr) svc_perror(__FILE__, __LINE__, #expr, (expr)) #define ABS(X) ((X) > 0 ? (X) : -(X)) // Rather than a bazillion writecommand() and writedata() calls, screen // initialization commands and arguments are organized in these tables // stored in PROGMEM. The table may look bulky, but that's mostly the // formatting -- storage-wise this is hundreds of bytes more compact // than the equivalent code. Companion function follows. #define DELAY 0x80 static const uint8_t Gcmd[] = { // Initialization commands for 7789 screens 9, // 9 commands in list: ST7789_SWRESET, DELAY, // 1: Software reset, no args, w/delay 150, // 150 ms delay ST7789_SLPOUT , DELAY, // 2: Out of sleep mode, no args, w/delay 10, // 10 ms delay ST7789_COLMOD , 1+DELAY, // 3: Set color mode, 1 arg + delay: 0x55, // 16-bit color 10, // 10 ms delay ST7789_MADCTL , 1, // 4: Mem access ctrl (directions), 1 arg: 0x08, // Row/col addr, bottom-top refresh ST7789_CASET , 4, // 5: Column addr set, 4 args, no delay: 0x00, // 0, // XSTART = 0 0, // 240, // XEND = 240 ST7789_RASET , 4, // 6: Row addr set, 4 args, no delay: 0x00, 0, // YSTART = 0 320>>8, 320&0xFF, // YEND = 320 ST7789_INVON , DELAY, // 7: hack 10, // 10 ms delay ST7789_NORON , DELAY, // 8: Normal display on, no args, w/delay 10, // 10 ms delay ST7789_DISPON , DELAY, // 9: Main screen turn on, no args, delay 10 }; // 10 ms delay /* Buffer used for transmission */ static uint8_t aTxBuffer[4]; #define PORT_HIGH 1 #define PORT_LOW 0 #define cs_set(sw) digitalWrite(hlcd->cs_pin, sw) #define rs_set(sw) digitalWrite(hlcd->rs_pin, sw) #define rst_set(sw) digitalWrite(hlcd->rst_pin, sw) #define cs2_set(sw) digitalWrite(hlcd->cs2_pin, sw) /* * LCDへのコマンド送信関数 */ ER lcd_writecommand(LCD_Handler_t *hlcd, uint8_t c) { ER ercd = E_OK; if(hlcd->spi_lock != 0){ if((ercd = wai_sem(hlcd->spi_lock)) != E_OK) return ercd; } rs_set(PORT_LOW); cs_set(PORT_LOW); aTxBuffer[0] = c; #if SPI_WAIT_TIME != 0 ercd = spi_transmit(hlcd->hspi, (uint8_t*)aTxBuffer, 1); #else if((ercd = spi_transmit(hlcd->hspi, (uint8_t*)aTxBuffer, 1)) == E_OK){ ercd = spi_wait(hlcd->hspi, 100); } #endif cs_set(PORT_HIGH); if(hlcd->spi_lock != 0) sig_sem(hlcd->spi_lock); return ercd; } /* * LCDへのデータ送信関数 */ ER lcd_writedata(LCD_Handler_t *hlcd, uint8_t *p, uint32_t len) { ER ercd = E_OK; if(hlcd->spi_lock != 0){ if((ercd = wai_sem(hlcd->spi_lock)) != E_OK) return ercd; } rs_set(PORT_HIGH); cs_set(PORT_LOW); sil_dly_nse(100); #if SPI_WAIT_TIME != 0 ercd = spi_transmit(hlcd->hspi, (uint8_t*)p, len); #else if((ercd = spi_transmit(hlcd->hspi, (uint8_t*)p, len)) == E_OK){ ercd = spi_wait(hlcd->hspi, 100); } #endif sil_dly_nse(100); cs_set(PORT_HIGH); if(hlcd->spi_lock != 0) sig_sem(hlcd->spi_lock); return ercd; } /* * LCDへの2バイトデータ送信関数 */ ER lcd_writedata2(LCD_Handler_t *hlcd, uint16_t c, int cnt) { ER ercd = E_OK; int i; if(cnt == 0) return ercd; if(hlcd->spi_lock != 0){ if((ercd = wai_sem(hlcd->spi_lock)) != E_OK) return ercd; } rs_set(PORT_HIGH); cs_set(PORT_LOW); sil_dly_nse(100); aTxBuffer[0] = c>>8; aTxBuffer[1] = (uint8_t)c; for(i = 0 ; i < cnt ; i++){ if((ercd = spi_transmit(hlcd->hspi, (uint8_t*)aTxBuffer, 2)) != E_OK){ break; } #if SPI_WAIT_TIME == 0 if((ercd = spi_wait(hlcd->hspi, 100)) != E_OK){ break; } #endif } sil_dly_nse(100); cs_set(PORT_HIGH); if(hlcd->spi_lock != 0) sig_sem(hlcd->spi_lock); return ercd; } /* * LCDへのRGBデータ送信関数 */ ER lcd_writedata3(LCD_Handler_t *hlcd, uint8_t *pbmp, uint16_t width, uint16_t height) { ER ercd = E_OK; int index, i; if(width == 0 || height == 0) return ercd; if(hlcd->spi_lock != 0){ if((ercd = wai_sem(hlcd->spi_lock)) != E_OK) return ercd; } rs_set(PORT_HIGH); cs_set(PORT_LOW); sil_dly_nse(100); for(index=0; index < height; index++){ uint8_t *p = pbmp; for (i = 0; i < width; i++){ aTxBuffer[0] = (*p++) & 0xf8; aTxBuffer[0] |= *p >> 5; aTxBuffer[1] = (*p++ << 3) & 0xE0; aTxBuffer[1] |= (*p++ >> 3) & 0x1F; if((ercd = spi_transmit(hlcd->hspi, (uint8_t*)aTxBuffer, 2)) != E_OK){ break; } #if SPI_WAIT_TIME == 0 if((ercd = spi_wait(hlcd->hspi, 100)) != E_OK){ break; } #endif } pbmp -= width*3; } sil_dly_nse(100); cs_set(PORT_HIGH); if(hlcd->spi_lock != 0) sig_sem(hlcd->spi_lock); return ercd; } /* * ST7789へのコマンドリスト送信 */ static void displayInit(LCD_Handler_t *hlcd, const uint8_t *addr) { uint8_t numCommands, numArgs; uint8_t data[4]; uint16_t ms; numCommands = *addr++; // Number of commands to follow while(numCommands--) { // For each command... SVC_PERROR(lcd_writecommand(hlcd, *addr++)); // Read, issue command numArgs = *addr++; // Number of args to follow ms = numArgs & DELAY; // If hibit set, delay follows args numArgs &= ~DELAY; // Mask out delay bit while(numArgs--) { // For each argument... data[0] = *addr++; SVC_PERROR(lcd_writedata(hlcd, data, 1)); // Read, issue argument } if(ms) { ms = *addr++; // Read post-command delay time (ms) if(ms == 255) ms = 500; // If 255, delay for 500 ms dly_tsk(ms); } } } /* * ST7735B または ST7735RタイプのLEDの共通初期化関数 */ static void commonInit(LCD_Handler_t *hlcd, uint16_t width, uint16_t height) { hlcd->colstart = hlcd->rowstart = 0; // May be overridden in init func hlcd->lcd_width = width; hlcd->lcd_height = height; if(width == 240 && height == 240){ /* 1.3" and 1.54 displays */ hlcd->lcd_colstart = 0; hlcd->lcd_rowstart = 80; } else if(width == 135 && height == 240){ /*1.13" display */ hlcd->lcd_colstart = 53; hlcd->lcd_rowstart = 40; } else{ hlcd->lcd_colstart = 0; hlcd->lcd_rowstart = 0; } // toggle RST low to reset; CS low so it'll listen to us cs_set(PORT_LOW); rst_set(PORT_HIGH); dly_tsk(500); rst_set(PORT_LOW); dly_tsk(500); rst_set(PORT_HIGH); } /* * 表示ウィンドウ設定 */ void lcd_setAddrWindow(LCD_Handler_t *hlcd, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) { uint8_t data[4]; SVC_PERROR(lcd_writecommand(hlcd, ST7789_CASET)); // Column addr set data[0] = (uint8_t)((x0 + hlcd->colstart) >> 8); data[1] = (uint8_t)(x0 + hlcd->colstart); // XSTART data[2] = (uint8_t)((x1 + hlcd->colstart) >> 8); data[3] = (uint8_t)(x1 + hlcd->colstart); // XEND SVC_PERROR(lcd_writedata(hlcd, data, 4)); SVC_PERROR(lcd_writecommand(hlcd, ST7789_RASET)); // Row addr set data[0] = (uint8_t)((y0 + hlcd->rowstart) >> 8); data[1] = (uint8_t)(y0 + hlcd->rowstart); // YSTART data[2] = (uint8_t)((y1 + hlcd->rowstart) >> 8); data[3] = (uint8_t)(y1 + hlcd->rowstart); // YEND SVC_PERROR(lcd_writedata(hlcd, data, 4)); SVC_PERROR(lcd_writecommand(hlcd, ST7789_RAMWR)); // write to RAM } /* * オリエンテーション設定 * param1 hlcd: Pointer to LCD Handler * param2 m: orientation value(0-3) */ void lcd_setRotation(LCD_Handler_t *hlcd, uint8_t m) { uint8_t madctl[4]; hlcd->rotation = m & 3; // can't be higher than 3 madctl[0] = 0; switch(hlcd->rotation){ case 0: madctl[0] = ST7789_MADCTL_MX | ST7789_MADCTL_MY | ST7789_MADCTL_RGB; hlcd->colstart = hlcd->lcd_colstart; hlcd->rowstart = hlcd->lcd_rowstart; hlcd->_width = hlcd->lcd_width; hlcd->_height = hlcd->lcd_height; break; case 1: madctl[0] = ST7789_MADCTL_MY | ST7789_MADCTL_MV | ST7789_MADCTL_RGB; hlcd->colstart = hlcd->lcd_rowstart; hlcd->rowstart = hlcd->lcd_colstart; hlcd->_height = hlcd->lcd_width; hlcd->_width = hlcd->lcd_height; break; case 2: madctl[0] = ST7789_MADCTL_RGB; if(hlcd->lcd_width == 135 && hlcd->lcd_height == 240){ hlcd->colstart = hlcd->lcd_colstart-1; hlcd->rowstart = hlcd->lcd_rowstart; } else{ hlcd->colstart = 0; hlcd->rowstart = 0; } hlcd->_width = hlcd->lcd_width; hlcd->_height = hlcd->lcd_height; break; case 3: madctl[0] = ST7789_MADCTL_MX | ST7789_MADCTL_MV | ST7789_MADCTL_RGB; if(hlcd->lcd_width == 135 && hlcd->lcd_height == 240){ hlcd->colstart = hlcd->lcd_rowstart; hlcd->rowstart = hlcd->lcd_colstart; } else{ hlcd->colstart = 0; hlcd->rowstart = 0; } hlcd->_height = hlcd->lcd_width; hlcd->_width = hlcd->lcd_height; break; } SVC_PERROR(lcd_writecommand(hlcd, ST7789_MADCTL)); SVC_PERROR(lcd_writedata(hlcd, madctl, 1)); } /* * ST7789 screensの初期化関数 */ void lcd_init(LCD_Handler_t *hlcd, uint16_t width, uint16_t height) { commonInit(hlcd, width, height); displayInit(hlcd, Gcmd); lcd_setRotation(hlcd, hlcd->rotation); syslog_2(LOG_NOTICE, "## width(%d) height(%d) ##", hlcd->_width, hlcd->_height); } /* * RECTANGLEのフィル描画 * param1 hlcd: Pointer to LCD Handler * param2 x: start X position * param3 y: start Y position * param4 w: width * param5 h: height * param6 color: color value */ void lcd_fillRect(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t w, int16_t h, color_t color) { // rudimentary clipping (drawChar w/big text requires this) if((x >= hlcd->_width) || (y >= hlcd->_height)) return; if((x + w - 1) >= hlcd->_width) w = hlcd->_width - x; if((y + h - 1) >= hlcd->_height) h = hlcd->_height - y; lcd_setAddrWindow(hlcd, x, y, x+w-1, y+h-1); SVC_PERROR(lcd_writedata2(hlcd, color, h*w)); } void lcd_pushColor(LCD_Handler_t *hlcd, color_t color) { SVC_PERROR(lcd_writedata2(hlcd, color, 1)); } /* * PIXEL描画 * param1 hlcd: Pointer to LCD Handler * param2 x: X position * param3 y: Y position * param4 color: color value */ void lcd_drawPixel(LCD_Handler_t *hlcd, int16_t x, int16_t y, color_t color) { if((x < 0) ||(x >= hlcd->_width) || (y < 0) || (y >= hlcd->_height)) return; lcd_setAddrWindow(hlcd, x, y, x, y); SVC_PERROR(lcd_writedata2(hlcd, color, 1)); } /* * 垂直方向LINEの高速描画 * param1 hlcd: Pointer to LCD Handler * param2 x: start X position * param3 y: start Y position * param4 h: height * param5 color: color value */ void lcd_drawFastVLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t h, color_t color) { // Rudimentary clipping if((x >= hlcd->_width) || (y >= hlcd->_height)) return; if((y+h-1) >= hlcd->_height) h = hlcd->_height-y; lcd_setAddrWindow(hlcd, x, y, x, y+h-1); SVC_PERROR(lcd_writedata2(hlcd, color, h)); } /* * 水平方向LINEの高速描画 * param1 hlcd: Pointer to LCD Handler * param2 x: start X position * param3 y: start Y position * param4 w: width * param5 color: color value */ void lcd_drawFastHLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t w, color_t color) { // Rudimentary clipping if((x >= hlcd->_width) || (y >= hlcd->_height)) return; if((x+w-1) >= hlcd->_width) w = hlcd->_width-x; lcd_setAddrWindow(hlcd, x, y, x+w-1, y); SVC_PERROR(lcd_writedata2(hlcd, color, w)); } /* * DRAW IMAGE LINE描画 * param1 hlcd: Pointer to LCD Handler * param2 x: X position * param3 y: Y position * param4 w: width * param5 pcolor: color value */ void lcd_drawImageHLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, uint16_t w, color_t *pcolor) { uint32_t i; if((x >= hlcd->_width) || (y >= hlcd->_height)) return; if((x+w-1) >= hlcd->_width) w = hlcd->_width-x; lcd_setAddrWindow(hlcd, x, y, x+w-1, y); for(i = 0 ; i < w ; i++, pcolor++) SVC_PERROR(lcd_writedata2(hlcd, *pcolor, 1)); } /* * BITMAP描画 * param1 hlcd: Pointer to LCD Handler * param2 x0: Bmp X position in the LCD * param3 y0: Bmp Y position in the LCD * param4 pbmp: Pointer to Bmp picture address in the internal Flash */ void lcd_drawBitmap(LCD_Handler_t *hlcd, uint16_t x0, uint16_t y0, uint8_t *pbmp) { uint32_t index = 0, width = 0, height = 0, bit_pixel = 0; uint32_t input_color_mode = 0; /* Get bitmap data address offset */ index = *(uint16_t *) (pbmp + 10); index |= (*(uint16_t *) (pbmp + 12)) << 16; /* Read bitmap width */ width = *(uint16_t *) (pbmp + 18); width |= (*(uint16_t *) (pbmp + 20)) << 16; /* Read bitmap height */ height = *(uint16_t *) (pbmp + 22); height |= (*(uint16_t *) (pbmp + 24)) << 16; /* Read bit/pixel */ bit_pixel = *(uint16_t *) (pbmp + 28); /* Get the layer pixel format */ if ((bit_pixel/8) == 4){ input_color_mode = CM_ARGB8888; } else if ((bit_pixel/8) == 2){ input_color_mode = CM_RGB565; } else{ input_color_mode = CM_RGB888; } /* Bypass the bitmap header */ pbmp += (index + (width * (height - 1) * (bit_pixel/8))); syslog_4(LOG_NOTICE, "## input_color_mode(%d) width(%d) height(%d) bit_pixel(%d) ##", input_color_mode, width, height, bit_pixel); lcd_setAddrWindow(hlcd, x0, y0, x0+width-1, y0+height-1); lcd_writedata3(hlcd, pbmp, width, height); } /* * INVERT DISPLAY * param1 hlcd: Pointer to LCD Handler * param2 i: invert value */ void lcd_invertDisplay(LCD_Handler_t *hlcd, bool_t i) { SVC_PERROR(lcd_writecommand(hlcd, i ? ST7789_INVOFF : ST7789_INVON)); } /* * スクリーンフィル * param1 pDrawProp: Pointer to Draw Prop */ void lcd_fillScreen(LCD_DrawProp_t *pDrawProp) { lcd_fillRect(pDrawProp->hlcd, 0, 0, pDrawProp->hlcd->_width, pDrawProp->hlcd->_height, pDrawProp->BackColor); } /* * RECTANGLE描画 * param1 pDrawProp: Pointer to Draw Prop * param2 x: left X position * param3 y: top Y position * param4 w: width * param5 h: height */ void lcd_drawRect(LCD_DrawProp_t *pDrawProp, int16_t x, int16_t y, int16_t w, int16_t h) { LCD_Handler_t *hlcd = pDrawProp->hlcd; color_t color; // rudimentary clipping (drawChar w/big text requires this) if((x >= hlcd->_width) || (y >= hlcd->_height)) return; if((x + w - 1) >= hlcd->_width) w = hlcd->_width - x; if((y + h - 1) >= hlcd->_height) h = hlcd->_height - y; color = pDrawProp->TextColor; lcd_drawFastVLine(hlcd, x, y, h, color); lcd_drawFastHLine(hlcd, x, y+h-1, w, color); lcd_drawFastVLine(hlcd, x+w-1, y, h, color); lcd_drawFastHLine(hlcd, x, y, w, color); } /* * 円描画 * param1 pDrawProp: Pointer to Draw Prop * param2 x0: X position * param3 y0: Y position * param4 Radius: Circle radius */ void lcd_DrawCircle(LCD_DrawProp_t *pDrawProp, uint16_t x0, uint16_t y0, uint16_t Radius) { LCD_Handler_t *hlcd = pDrawProp->hlcd; int32_t decision; /* Decision Variable */ uint32_t current_x; /* Current X Value */ uint32_t current_y; /* Current Y Value */ decision = 3 - (Radius << 1); current_x = 0; current_y = Radius; while(current_x <= current_y){ lcd_drawPixel(hlcd, (x0 + current_x), (y0 - current_y), pDrawProp->TextColor); lcd_drawPixel(hlcd, (x0 - current_x), (y0 - current_y), pDrawProp->TextColor); lcd_drawPixel(hlcd, (x0 + current_y), (y0 - current_x), pDrawProp->TextColor); lcd_drawPixel(hlcd, (x0 - current_y), (y0 - current_x), pDrawProp->TextColor); lcd_drawPixel(hlcd, (x0 + current_x), (y0 + current_y), pDrawProp->TextColor); lcd_drawPixel(hlcd, (x0 - current_x), (y0 + current_y), pDrawProp->TextColor); lcd_drawPixel(hlcd, (x0 + current_y), (y0 + current_x), pDrawProp->TextColor); lcd_drawPixel(hlcd, (x0 - current_y), (y0 + current_x), pDrawProp->TextColor); if (decision < 0){ decision += (current_x << 2) + 6; } else{ decision += ((current_x - current_y) << 2) + 10; current_y--; } current_x++; } } /* * 線描画 * param1 pDrawProp: Pointer to Draw Prop * param2 x1: Point 1 X position * param3 y1: Point 1 Y position * param4 x2: Point 2 X position * param5 y2: Point 2 Y position */ void lcd_drawLine(LCD_DrawProp_t *pDrawProp, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) { LCD_Handler_t *hlcd = pDrawProp->hlcd; int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0, curpixel = 0; deltax = ABS(x2 - x1); /* The difference between the x's */ deltay = ABS(y2 - y1); /* The difference between the y's */ x = x1; /* Start x off at the first pixel */ y = y1; /* Start y off at the first pixel */ if(x2 >= x1){ /* The x-values are increasing */ xinc1 = 1; xinc2 = 1; } else{ /* The x-values are decreasing */ xinc1 = -1; xinc2 = -1; } if(y2 >= y1){ /* The y-values are increasing */ yinc1 = 1; yinc2 = 1; } else{ /* The y-values are decreasing */ yinc1 = -1; yinc2 = -1; } if(deltax >= deltay){ /* There is at least one x-value for every y-value */ xinc1 = 0; /* Don't change the x when numerator >= denominator */ yinc2 = 0; /* Don't change the y for every iteration */ den = deltax; num = deltax / 2; num_add = deltay; num_pixels = deltax; /* There are more x-values than y-values */ } else{ /* There is at least one y-value for every x-value */ xinc2 = 0; /* Don't change the x for every iteration */ yinc1 = 0; /* Don't change the y when numerator >= denominator */ den = deltay; num = deltay / 2; num_add = deltax; num_pixels = deltay; /* There are more y-values than x-values */ } for (curpixel = 0; curpixel <= num_pixels; curpixel++){ lcd_drawPixel(hlcd, x, y, pDrawProp->TextColor); /* Draw the current pixel */ num += num_add; /* Increase the numerator by the top of the fraction */ if(num >= den){ /* Check if numerator >= denominator */ num -= den; /* Calculate the new numerator value */ x += xinc1; /* Change the x as appropriate */ y += yinc1; /* Change the y as appropriate */ } x += xinc2; /* Change the x as appropriate */ y += yinc2; /* Change the y as appropriate */ } } /* * PLOY-LINE描画 * param1 pDrawProp: Pointer to Draw Prop * param2 Points: Pointer to the points array * param3 PointCount: Number of points */ void lcd_drawPolygon(LCD_DrawProp_t *pDrawProp, pPoint Points, uint16_t PointCount) { int16_t x = 0, y = 0; if(PointCount < 2){ return; } lcd_drawLine(pDrawProp, Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y); while(--PointCount){ x = Points->X; y = Points->Y; Points++; lcd_drawLine(pDrawProp, x, y, Points->X, Points->Y); } }