[453] | 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-2018 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 | /*
|
---|
| 45 | * Written by Limor Fried/Ladyada for Adafruit Industries.
|
---|
| 46 | * MIT license, all text above must be included in any redistribution
|
---|
| 47 | * http://opensource.org/licenses/mit-license.php
|
---|
| 48 | */
|
---|
| 49 |
|
---|
| 50 | /*
|
---|
| 51 | * ADAFRUIT ST7735 1.8",1.44"LCD制御プログラムの本体
|
---|
| 52 | */
|
---|
| 53 |
|
---|
| 54 | #include <kernel.h>
|
---|
| 55 | #include <t_syslog.h>
|
---|
| 56 | #include <t_stdlib.h>
|
---|
| 57 | #include <stdio.h>
|
---|
| 58 | #include <string.h>
|
---|
| 59 | #include <target_syssvc.h>
|
---|
| 60 | #include "syssvc/serial.h"
|
---|
| 61 | #include "syssvc/syslog.h"
|
---|
| 62 | #include "device.h"
|
---|
| 63 | #include "adafruit_st7735.h"
|
---|
| 64 |
|
---|
| 65 | /*
|
---|
| 66 | * サービスコールのエラーのログ出力
|
---|
| 67 | */
|
---|
| 68 | Inline void
|
---|
| 69 | svc_perror(const char *file, int_t line, const char *expr, ER ercd)
|
---|
| 70 | {
|
---|
| 71 | if (ercd < 0) {
|
---|
| 72 | t_perror(LOG_ERROR, file, line, expr, ercd);
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | #define SVC_PERROR(expr) svc_perror(__FILE__, __LINE__, #expr, (expr))
|
---|
| 77 | #define ABS(X) ((X) > 0 ? (X) : -(X))
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | // Rather than a bazillion writecommand() and writedata() calls, screen
|
---|
| 81 | // initialization commands and arguments are organized in these tables
|
---|
| 82 | // stored in PROGMEM. The table may look bulky, but that's mostly the
|
---|
| 83 | // formatting -- storage-wise this is hundreds of bytes more compact
|
---|
| 84 | // than the equivalent code. Companion function follows.
|
---|
| 85 | #define DELAY 0x80
|
---|
| 86 | static const uint8_t
|
---|
| 87 | Bcmd[] = { // Initialization commands for 7735B screens
|
---|
| 88 | 18, // 18 commands in list:
|
---|
| 89 | ST7735_SWRESET, DELAY, // 1: Software reset, no args, w/delay
|
---|
| 90 | 50, // 50 ms delay
|
---|
| 91 | ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, no args, w/delay
|
---|
| 92 | 255, // 255 = 500 ms delay
|
---|
| 93 | ST7735_COLMOD , 1+DELAY, // 3: Set color mode, 1 arg + delay:
|
---|
| 94 | 0x05, // 16-bit color
|
---|
| 95 | 10, // 10 ms delay
|
---|
| 96 | ST7735_FRMCTR1, 3+DELAY, // 4: Frame rate control, 3 args + delay:
|
---|
| 97 | 0x00, // fastest refresh
|
---|
| 98 | 0x06, // 6 lines front porch
|
---|
| 99 | 0x03, // 3 lines back porch
|
---|
| 100 | 10, // 10 ms delay
|
---|
| 101 | ST7735_MADCTL , 1 , // 5: Memory access ctrl (directions), 1 arg:
|
---|
| 102 | 0x08, // Row addr/col addr, bottom to top refresh
|
---|
| 103 | ST7735_DISSET5, 2 , // 6: Display settings #5, 2 args, no delay:
|
---|
| 104 | 0x15, // 1 clk cycle nonoverlap, 2 cycle gate
|
---|
| 105 | // rise, 3 cycle osc equalize
|
---|
| 106 | 0x02, // Fix on VTL
|
---|
| 107 | ST7735_INVCTR , 1 , // 7: Display inversion control, 1 arg:
|
---|
| 108 | 0x0, // Line inversion
|
---|
| 109 | ST7735_PWCTR1 , 2+DELAY, // 8: Power control, 2 args + delay:
|
---|
| 110 | 0x02, // GVDD = 4.7V
|
---|
| 111 | 0x70, // 1.0uA
|
---|
| 112 | 10, // 10 ms delay
|
---|
| 113 | ST7735_PWCTR2 , 1 , // 9: Power control, 1 arg, no delay:
|
---|
| 114 | 0x05, // VGH = 14.7V, VGL = -7.35V
|
---|
| 115 | ST7735_PWCTR3 , 2 , // 10: Power control, 2 args, no delay:
|
---|
| 116 | 0x01, // Opamp current small
|
---|
| 117 | 0x02, // Boost frequency
|
---|
| 118 | ST7735_VMCTR1 , 2+DELAY, // 11: Power control, 2 args + delay:
|
---|
| 119 | 0x3C, // VCOMH = 4V
|
---|
| 120 | 0x38, // VCOML = -1.1V
|
---|
| 121 | 10, // 10 ms delay
|
---|
| 122 | ST7735_PWCTR6 , 2 , // 12: Power control, 2 args, no delay:
|
---|
| 123 | 0x11, 0x15,
|
---|
| 124 | ST7735_GMCTRP1,16 , // 13: Magical unicorn dust, 16 args, no delay:
|
---|
| 125 | 0x09, 0x16, 0x09, 0x20, // (seriously though, not sure what
|
---|
| 126 | 0x21, 0x1B, 0x13, 0x19, // these config values represent)
|
---|
| 127 | 0x17, 0x15, 0x1E, 0x2B,
|
---|
| 128 | 0x04, 0x05, 0x02, 0x0E,
|
---|
| 129 | ST7735_GMCTRN1,16+DELAY, // 14: Sparkles and rainbows, 16 args + delay:
|
---|
| 130 | 0x0B, 0x14, 0x08, 0x1E, // (ditto)
|
---|
| 131 | 0x22, 0x1D, 0x18, 0x1E,
|
---|
| 132 | 0x1B, 0x1A, 0x24, 0x2B,
|
---|
| 133 | 0x06, 0x06, 0x02, 0x0F,
|
---|
| 134 | 10, // 10 ms delay
|
---|
| 135 | ST7735_CASET , 4 , // 15: Column addr set, 4 args, no delay:
|
---|
| 136 | 0x00, 0x02, // XSTART = 2
|
---|
| 137 | 0x00, 0x81, // XEND = 129
|
---|
| 138 | ST7735_RASET , 4 , // 16: Row addr set, 4 args, no delay:
|
---|
| 139 | 0x00, 0x02, // XSTART = 1
|
---|
| 140 | 0x00, 0x81, // XEND = 160
|
---|
| 141 | ST7735_NORON , DELAY, // 17: Normal display on, no args, w/delay
|
---|
| 142 | 10, // 10 ms delay
|
---|
| 143 | ST7735_DISPON , DELAY, // 18: Main screen turn on, no args, w/delay
|
---|
| 144 | 255}; // 255 = 500 ms delay
|
---|
| 145 |
|
---|
| 146 | static const uint8_t
|
---|
| 147 | Rcmd1[] = { // Init for 7735R, part 1 (red or green tab)
|
---|
| 148 | 15, // 15 commands in list:
|
---|
| 149 | ST7735_SWRESET, DELAY, // 1: Software reset, 0 args, w/delay
|
---|
| 150 | 150, // 150 ms delay
|
---|
| 151 | ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, 0 args, w/delay
|
---|
| 152 | 255, // 500 ms delay
|
---|
| 153 | ST7735_FRMCTR1, 3 , // 3: Frame rate ctrl - normal mode, 3 args:
|
---|
| 154 | 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
|
---|
| 155 | ST7735_FRMCTR2, 3 , // 4: Frame rate control - idle mode, 3 args:
|
---|
| 156 | 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
|
---|
| 157 | ST7735_FRMCTR3, 6 , // 5: Frame rate ctrl - partial mode, 6 args:
|
---|
| 158 | 0x01, 0x2C, 0x2D, // Dot inversion mode
|
---|
| 159 | 0x01, 0x2C, 0x2D, // Line inversion mode
|
---|
| 160 | ST7735_INVCTR , 1 , // 6: Display inversion ctrl, 1 arg, no delay:
|
---|
| 161 | 0x07, // No inversion
|
---|
| 162 | ST7735_PWCTR1 , 3 , // 7: Power control, 3 args, no delay:
|
---|
| 163 | 0xA2,
|
---|
| 164 | 0x02, // -4.6V
|
---|
| 165 | 0x84, // AUTO mode
|
---|
| 166 | ST7735_PWCTR2 , 1 , // 8: Power control, 1 arg, no delay:
|
---|
| 167 | 0xC5, // VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD
|
---|
| 168 | ST7735_PWCTR3 , 2 , // 9: Power control, 2 args, no delay:
|
---|
| 169 | 0x0A, // Opamp current small
|
---|
| 170 | 0x00, // Boost frequency
|
---|
| 171 | ST7735_PWCTR4 , 2 , // 10: Power control, 2 args, no delay:
|
---|
| 172 | 0x8A, // BCLK/2, Opamp current small & Medium low
|
---|
| 173 | 0x2A,
|
---|
| 174 | ST7735_PWCTR5 , 2 , // 11: Power control, 2 args, no delay:
|
---|
| 175 | 0x8A, 0xEE,
|
---|
| 176 | ST7735_VMCTR1 , 1 , // 12: Power control, 1 arg, no delay:
|
---|
| 177 | 0x0E,
|
---|
| 178 | ST7735_INVOFF , 0 , // 13: Don't invert display, no args, no delay
|
---|
| 179 | ST7735_MADCTL , 1 , // 14: Memory access control (directions), 1 arg:
|
---|
| 180 | 0xC8, // row addr/col addr, bottom to top refresh
|
---|
| 181 | ST7735_COLMOD , 1 , // 15: set color mode, 1 arg, no delay:
|
---|
| 182 | 0x05 }; // 16-bit color
|
---|
| 183 |
|
---|
| 184 | static const uint8_t
|
---|
| 185 | Rcmd2green[] = { // Init for 7735R, part 2 (green tab only)
|
---|
| 186 | 2, // 2 commands in list:
|
---|
| 187 | ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay:
|
---|
| 188 | 0x00, 0x02, // XSTART = 0
|
---|
| 189 | 0x00, 0x7F+0x02, // XEND = 127
|
---|
| 190 | ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay:
|
---|
| 191 | 0x00, 0x01, // XSTART = 0
|
---|
| 192 | 0x00, 0x9F+0x01 }; // XEND = 159
|
---|
| 193 |
|
---|
| 194 | static const uint8_t
|
---|
| 195 | Rcmd2red[] = { // Init for 7735R, part 2 (red tab only)
|
---|
| 196 | 2, // 2 commands in list:
|
---|
| 197 | ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay:
|
---|
| 198 | 0x00, 0x00, // XSTART = 0
|
---|
| 199 | 0x00, 0x7F, // XEND = 127
|
---|
| 200 | ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay:
|
---|
| 201 | 0x00, 0x00, // XSTART = 0
|
---|
| 202 | 0x00, 0x9F }; // XEND = 159
|
---|
| 203 |
|
---|
| 204 | static const uint8_t
|
---|
| 205 | Rcmd2green144[] = { // Init for 7735R, part 2 (green 1.44 tab)
|
---|
| 206 | 2, // 2 commands in list:
|
---|
| 207 | ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay:
|
---|
| 208 | 0x00, 0x00, // XSTART = 0
|
---|
| 209 | 0x00, 0x7F, // XEND = 127
|
---|
| 210 | ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay:
|
---|
| 211 | 0x00, 0x00, // XSTART = 0
|
---|
| 212 | 0x00, 0x7F }; // XEND = 127
|
---|
| 213 |
|
---|
| 214 | static const uint8_t
|
---|
| 215 | Rcmd3[] = { // Init for 7735R, part 3 (red or green tab)
|
---|
| 216 | 4, // 4 commands in list:
|
---|
| 217 | ST7735_GMCTRP1, 16 , // 1: Magical unicorn dust, 16 args, no delay:
|
---|
| 218 | 0x02, 0x1c, 0x07, 0x12,
|
---|
| 219 | 0x37, 0x32, 0x29, 0x2d,
|
---|
| 220 | 0x29, 0x25, 0x2B, 0x39,
|
---|
| 221 | 0x00, 0x01, 0x03, 0x10,
|
---|
| 222 | ST7735_GMCTRN1, 16 , // 2: Sparkles and rainbows, 16 args, no delay:
|
---|
| 223 | 0x03, 0x1d, 0x07, 0x06,
|
---|
| 224 | 0x2E, 0x2C, 0x29, 0x2D,
|
---|
| 225 | 0x2E, 0x2E, 0x37, 0x3F,
|
---|
| 226 | 0x00, 0x00, 0x02, 0x10,
|
---|
| 227 | ST7735_NORON , DELAY, // 3: Normal display on, no args, w/delay
|
---|
| 228 | 10, // 10 ms delay
|
---|
| 229 | ST7735_DISPON , DELAY, // 4: Main screen turn on, no args w/delay
|
---|
| 230 | 100 }; // 100 ms delay
|
---|
| 231 |
|
---|
| 232 |
|
---|
| 233 |
|
---|
| 234 |
|
---|
| 235 | /* Buffer used for transmission */
|
---|
| 236 | static uint8_t aTxBuffer[4];
|
---|
| 237 |
|
---|
| 238 | #define PORT_HIGH 1
|
---|
| 239 | #define PORT_LOW 0
|
---|
| 240 |
|
---|
| 241 | #define cs_set(sw) digitalWrite(hlcd->cs_pin, sw)
|
---|
| 242 | #define rs_set(sw) digitalWrite(hlcd->rs_pin, sw)
|
---|
| 243 | #define rst_set(sw) digitalWrite(hlcd->rst_pin, sw)
|
---|
| 244 | #define cs2_set(sw) digitalWrite(hlcd->cs2_pin, sw)
|
---|
| 245 |
|
---|
| 246 | /*
|
---|
| 247 | * LCDへのコマンド送信関数
|
---|
| 248 | */
|
---|
| 249 | ER
|
---|
| 250 | lcd_writecommand(LCD_Handler_t *hlcd, uint8_t c)
|
---|
| 251 | {
|
---|
| 252 | ER ercd = E_OK;
|
---|
| 253 |
|
---|
| 254 | if(hlcd->spi_lock != 0){
|
---|
| 255 | if((ercd = wai_sem(hlcd->spi_lock)) != E_OK)
|
---|
| 256 | return ercd;
|
---|
| 257 | }
|
---|
| 258 | rs_set(PORT_LOW);
|
---|
| 259 | cs_set(PORT_LOW);
|
---|
| 260 |
|
---|
| 261 | aTxBuffer[0] = c;
|
---|
| 262 | #if SPI_WAIT_TIME != 0
|
---|
| 263 | ercd = spi_transmit(hlcd->hspi, (uint8_t*)aTxBuffer, 1);
|
---|
| 264 | #else
|
---|
| 265 | if((ercd = spi_transmit(hlcd->hspi, (uint8_t*)aTxBuffer, 1)) == E_OK){
|
---|
| 266 | ercd = spi_wait(hlcd->hspi, 100);
|
---|
| 267 | }
|
---|
| 268 | #endif
|
---|
| 269 |
|
---|
| 270 | cs_set(PORT_HIGH);
|
---|
| 271 | if(hlcd->spi_lock != 0)
|
---|
| 272 | sig_sem(hlcd->spi_lock);
|
---|
| 273 | return ercd;
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | /*
|
---|
| 277 | * LCDへのデータ送信関数
|
---|
| 278 | */
|
---|
| 279 | ER
|
---|
| 280 | lcd_writedata(LCD_Handler_t *hlcd, uint8_t *p, uint32_t len)
|
---|
| 281 | {
|
---|
| 282 | ER ercd = E_OK;
|
---|
| 283 |
|
---|
| 284 | if(hlcd->spi_lock != 0){
|
---|
| 285 | if((ercd = wai_sem(hlcd->spi_lock)) != E_OK)
|
---|
| 286 | return ercd;
|
---|
| 287 | }
|
---|
| 288 | rs_set(PORT_HIGH);
|
---|
| 289 | cs_set(PORT_LOW);
|
---|
| 290 | sil_dly_nse(100);
|
---|
| 291 |
|
---|
| 292 | #if SPI_WAIT_TIME != 0
|
---|
| 293 | ercd = spi_transmit(hlcd->hspi, (uint8_t*)p, len);
|
---|
| 294 | #else
|
---|
| 295 | if((ercd = spi_transmit(hlcd->hspi, (uint8_t*)p, len)) == E_OK){
|
---|
| 296 | ercd = spi_wait(hlcd->hspi, 100);
|
---|
| 297 | }
|
---|
| 298 | #endif
|
---|
| 299 |
|
---|
| 300 | sil_dly_nse(100);
|
---|
| 301 | cs_set(PORT_HIGH);
|
---|
| 302 | if(hlcd->spi_lock != 0)
|
---|
| 303 | sig_sem(hlcd->spi_lock);
|
---|
| 304 | return ercd;
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | /*
|
---|
| 308 | * LCDへの2バイトデータ送信関数
|
---|
| 309 | */
|
---|
| 310 | ER
|
---|
| 311 | lcd_writedata2(LCD_Handler_t *hlcd, uint16_t c, int cnt)
|
---|
| 312 | {
|
---|
| 313 | ER ercd = E_OK;
|
---|
| 314 | int i;
|
---|
| 315 |
|
---|
| 316 | if(cnt == 0)
|
---|
| 317 | return ercd;
|
---|
| 318 | if(hlcd->spi_lock != 0){
|
---|
| 319 | if((ercd = wai_sem(hlcd->spi_lock)) != E_OK)
|
---|
| 320 | return ercd;
|
---|
| 321 | }
|
---|
| 322 | rs_set(PORT_HIGH);
|
---|
| 323 | cs_set(PORT_LOW);
|
---|
| 324 | sil_dly_nse(100);
|
---|
| 325 | aTxBuffer[0] = c>>8;
|
---|
| 326 | aTxBuffer[1] = (uint8_t)c;
|
---|
| 327 | for(i = 0 ; i < cnt ; i++){
|
---|
| 328 | if((ercd = spi_transmit(hlcd->hspi, (uint8_t*)aTxBuffer, 2)) != E_OK){
|
---|
| 329 | break;
|
---|
| 330 | }
|
---|
| 331 | #if SPI_WAIT_TIME == 0
|
---|
| 332 | if((ercd = spi_wait(hlcd->hspi, 100)) != E_OK){
|
---|
| 333 | break;
|
---|
| 334 | }
|
---|
| 335 | #endif
|
---|
| 336 | }
|
---|
| 337 | sil_dly_nse(100);
|
---|
| 338 | cs_set(PORT_HIGH);
|
---|
| 339 | if(hlcd->spi_lock != 0)
|
---|
| 340 | sig_sem(hlcd->spi_lock);
|
---|
| 341 | return ercd;
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 | /*
|
---|
| 345 | * LCDへのRGBデータ送信関数
|
---|
| 346 | */
|
---|
| 347 | ER
|
---|
| 348 | lcd_writedata3(LCD_Handler_t *hlcd, uint8_t *pbmp, uint16_t width, uint16_t height)
|
---|
| 349 | {
|
---|
| 350 | ER ercd = E_OK;
|
---|
| 351 | int index, i;
|
---|
| 352 |
|
---|
| 353 | if(width == 0 || height == 0)
|
---|
| 354 | return ercd;
|
---|
| 355 | if(hlcd->spi_lock != 0){
|
---|
| 356 | if((ercd = wai_sem(hlcd->spi_lock)) != E_OK)
|
---|
| 357 | return ercd;
|
---|
| 358 | }
|
---|
| 359 | rs_set(PORT_HIGH);
|
---|
| 360 | cs_set(PORT_LOW);
|
---|
| 361 | sil_dly_nse(100);
|
---|
| 362 | for(index=0; index < height; index++){
|
---|
| 363 | uint8_t *p = pbmp;
|
---|
| 364 | for (i = 0; i < width; i++){
|
---|
| 365 | aTxBuffer[0] = (*p++) & 0xf8;
|
---|
| 366 | aTxBuffer[0] |= *p >> 5;
|
---|
| 367 | aTxBuffer[1] = (*p++ << 3) & 0xE0;
|
---|
| 368 | aTxBuffer[1] |= (*p++ >> 3) & 0x1F;
|
---|
| 369 | if((ercd = spi_transmit(hlcd->hspi, (uint8_t*)aTxBuffer, 2)) != E_OK){
|
---|
| 370 | break;
|
---|
| 371 | }
|
---|
| 372 | #if SPI_WAIT_TIME == 0
|
---|
| 373 | if((ercd = spi_wait(hlcd->hspi, 100)) != E_OK){
|
---|
| 374 | break;
|
---|
| 375 | }
|
---|
| 376 | #endif
|
---|
| 377 | }
|
---|
| 378 | pbmp -= width*3;
|
---|
| 379 | }
|
---|
| 380 | sil_dly_nse(100);
|
---|
| 381 | cs_set(PORT_HIGH);
|
---|
| 382 | if(hlcd->spi_lock != 0)
|
---|
| 383 | sig_sem(hlcd->spi_lock);
|
---|
| 384 | return ercd;
|
---|
| 385 | }
|
---|
| 386 |
|
---|
| 387 | /*
|
---|
| 388 | * ST7735へのコマンドリスト送信
|
---|
| 389 | */
|
---|
| 390 | static void
|
---|
| 391 | Adafruit_ST7735_commandList(LCD_Handler_t *hlcd, const uint8_t *addr)
|
---|
| 392 | {
|
---|
| 393 | uint8_t numCommands, numArgs;
|
---|
| 394 | uint8_t data[4];
|
---|
| 395 | uint16_t ms;
|
---|
| 396 |
|
---|
| 397 | numCommands = *addr++; // Number of commands to follow
|
---|
| 398 | while(numCommands--) { // For each command...
|
---|
| 399 | SVC_PERROR(lcd_writecommand(hlcd, *addr++)); // Read, issue command
|
---|
| 400 | numArgs = *addr++; // Number of args to follow
|
---|
| 401 | ms = numArgs & DELAY; // If hibit set, delay follows args
|
---|
| 402 | numArgs &= ~DELAY; // Mask out delay bit
|
---|
| 403 | while(numArgs--) { // For each argument...
|
---|
| 404 | data[0] = *addr++;
|
---|
| 405 | SVC_PERROR(lcd_writedata(hlcd, data, 1)); // Read, issue argument
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | if(ms) {
|
---|
| 409 | ms = *addr++; // Read post-command delay time (ms)
|
---|
| 410 | if(ms == 255) ms = 500; // If 255, delay for 500 ms
|
---|
| 411 | dly_tsk(ms);
|
---|
| 412 | }
|
---|
| 413 | }
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 |
|
---|
| 417 | /*
|
---|
| 418 | * ST7735B または ST7735RタイプのLEDの共通初期化関数
|
---|
| 419 | */
|
---|
| 420 | static void
|
---|
| 421 | Adafruit_ST7735_commonInit(LCD_Handler_t *hlcd, const uint8_t *cmdList)
|
---|
| 422 | {
|
---|
| 423 | hlcd->colstart = hlcd->rowstart = 0; // May be overridden in init func
|
---|
| 424 | hlcd->_width = ST7735_TFTWIDTH;
|
---|
| 425 | hlcd->_height = ST7735_TFTHEIGHT_18;
|
---|
| 426 |
|
---|
| 427 | // toggle RST low to reset; CS low so it'll listen to us
|
---|
| 428 | cs_set(PORT_LOW);
|
---|
| 429 | rst_set(PORT_HIGH);
|
---|
| 430 | dly_tsk(500);
|
---|
| 431 | rst_set(PORT_LOW);
|
---|
| 432 | dly_tsk(500);
|
---|
| 433 | rst_set(PORT_HIGH);
|
---|
| 434 |
|
---|
| 435 | if(cmdList) Adafruit_ST7735_commandList(hlcd, cmdList);
|
---|
| 436 | }
|
---|
| 437 |
|
---|
| 438 |
|
---|
| 439 | /*
|
---|
| 440 | * 表示ウィンドウ設定
|
---|
| 441 | */
|
---|
| 442 | void
|
---|
| 443 | lcd_setAddrWindow(LCD_Handler_t *hlcd, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
|
---|
| 444 | {
|
---|
| 445 | uint8_t data[4];
|
---|
| 446 |
|
---|
| 447 | SVC_PERROR(lcd_writecommand(hlcd, ST7735_CASET)); // Column addr set
|
---|
| 448 | data[0] = (uint8_t)((x0 + hlcd->colstart) >> 8);
|
---|
| 449 | data[1] = (uint8_t)(x0 + hlcd->colstart); // XSTART
|
---|
| 450 | data[2] = (uint8_t)((x1 + hlcd->colstart) >> 8);
|
---|
| 451 | data[3] = (uint8_t)(x1 + hlcd->colstart); // XEND
|
---|
| 452 | SVC_PERROR(lcd_writedata(hlcd, data, 4));
|
---|
| 453 |
|
---|
| 454 | SVC_PERROR(lcd_writecommand(hlcd, ST7735_RASET)); // Row addr set
|
---|
| 455 | data[0] = (uint8_t)((y0 + hlcd->rowstart) >> 8);
|
---|
| 456 | data[1] = (uint8_t)(y0 + hlcd->rowstart); // YSTART
|
---|
| 457 | data[2] = (uint8_t)((y1 + hlcd->rowstart) >> 8);
|
---|
| 458 | data[3] = (uint8_t)(y1 + hlcd->rowstart); // YEND
|
---|
| 459 | SVC_PERROR(lcd_writedata(hlcd, data, 4));
|
---|
| 460 |
|
---|
| 461 | SVC_PERROR(lcd_writecommand(hlcd, ST7735_RAMWR)); // write to RAM
|
---|
| 462 | }
|
---|
| 463 |
|
---|
| 464 | /*
|
---|
| 465 | * ST7735B screensの初期化関数
|
---|
| 466 | */
|
---|
| 467 | void
|
---|
| 468 | lcd_initB(LCD_Handler_t *hlcd)
|
---|
| 469 | {
|
---|
| 470 | Adafruit_ST7735_commonInit(hlcd, Bcmd);
|
---|
| 471 | }
|
---|
| 472 |
|
---|
| 473 | /*
|
---|
| 474 | * ST7735R screens (green or red tabs)の初期化関数
|
---|
| 475 | */
|
---|
| 476 | void
|
---|
| 477 | lcd_initR(LCD_Handler_t *hlcd, uint8_t options)
|
---|
| 478 | {
|
---|
| 479 | uint8_t data[4];
|
---|
| 480 |
|
---|
| 481 | Adafruit_ST7735_commonInit(hlcd, Rcmd1);
|
---|
| 482 |
|
---|
| 483 | if(options == INITR_GREENTAB){
|
---|
| 484 | Adafruit_ST7735_commandList(hlcd, Rcmd2green);
|
---|
| 485 | hlcd->colstart = 2;
|
---|
| 486 | hlcd->rowstart = 1;
|
---|
| 487 | }
|
---|
| 488 | else if(options == INITR_144GREENTAB){
|
---|
| 489 | hlcd->_height = ST7735_TFTHEIGHT_144;
|
---|
| 490 | Adafruit_ST7735_commandList(hlcd, Rcmd2green144);
|
---|
| 491 | hlcd->colstart = 2;
|
---|
| 492 | hlcd->rowstart = 3;
|
---|
| 493 | }
|
---|
| 494 | else{
|
---|
| 495 | // colstart, rowstart left at default '0' values
|
---|
| 496 | Adafruit_ST7735_commandList(hlcd, Rcmd2red);
|
---|
| 497 | }
|
---|
| 498 | Adafruit_ST7735_commandList(hlcd, Rcmd3);
|
---|
| 499 |
|
---|
| 500 | // if black, change MADCTL color filter
|
---|
| 501 | if(options == INITR_BLACKTAB){
|
---|
| 502 | SVC_PERROR(lcd_writecommand(hlcd, ST7735_MADCTL));
|
---|
| 503 | data[0] = 0xC0;
|
---|
| 504 | SVC_PERROR(lcd_writedata(hlcd, data, 1));
|
---|
| 505 | }
|
---|
| 506 | syslog_2(LOG_NOTICE, "## width(%d) height(%d) ##", hlcd->_width, hlcd->_height);
|
---|
| 507 | hlcd->tabcolor = options;
|
---|
| 508 | }
|
---|
| 509 |
|
---|
| 510 | /*
|
---|
| 511 | * RECTANGLEのフィル描画
|
---|
| 512 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 513 | * param2 x: start X position
|
---|
| 514 | * param3 y: start Y position
|
---|
| 515 | * param4 w: width
|
---|
| 516 | * param5 h: height
|
---|
| 517 | * param6 color: color value
|
---|
| 518 | */
|
---|
| 519 | void
|
---|
| 520 | lcd_fillRect(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t w, int16_t h, color_t color)
|
---|
| 521 | {
|
---|
| 522 | // rudimentary clipping (drawChar w/big text requires this)
|
---|
| 523 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
| 524 | if((x + w - 1) >= hlcd->_width) w = hlcd->_width - x;
|
---|
| 525 | if((y + h - 1) >= hlcd->_height) h = hlcd->_height - y;
|
---|
| 526 |
|
---|
| 527 | lcd_setAddrWindow(hlcd, x, y, x+w-1, y+h-1);
|
---|
| 528 | SVC_PERROR(lcd_writedata2(hlcd, color, h*w));
|
---|
| 529 | }
|
---|
| 530 |
|
---|
| 531 | void
|
---|
| 532 | lcd_pushColor(LCD_Handler_t *hlcd, color_t color)
|
---|
| 533 | {
|
---|
| 534 | SVC_PERROR(lcd_writedata2(hlcd, color, 1));
|
---|
| 535 | }
|
---|
| 536 |
|
---|
| 537 | /*
|
---|
| 538 | * PIXEL描画
|
---|
| 539 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 540 | * param2 x: X position
|
---|
| 541 | * param3 y: Y position
|
---|
| 542 | * param4 color: color value
|
---|
| 543 | */
|
---|
| 544 | void
|
---|
| 545 | lcd_drawPixel(LCD_Handler_t *hlcd, int16_t x, int16_t y, color_t color)
|
---|
| 546 | {
|
---|
| 547 | if((x < 0) ||(x >= hlcd->_width) || (y < 0) || (y >= hlcd->_height)) return;
|
---|
| 548 |
|
---|
| 549 | lcd_setAddrWindow(hlcd, x, y, x, y);
|
---|
| 550 | SVC_PERROR(lcd_writedata2(hlcd, color, 1));
|
---|
| 551 | }
|
---|
| 552 |
|
---|
| 553 | /*
|
---|
| 554 | * 垂直方向LINEの高速描画
|
---|
| 555 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 556 | * param2 x: start X position
|
---|
| 557 | * param3 y: start Y position
|
---|
| 558 | * param4 h: height
|
---|
| 559 | * param5 color: color value
|
---|
| 560 | */
|
---|
| 561 | void
|
---|
| 562 | lcd_drawFastVLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t h, color_t color)
|
---|
| 563 | {
|
---|
| 564 | // Rudimentary clipping
|
---|
| 565 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
| 566 | if((y+h-1) >= hlcd->_height) h = hlcd->_height-y;
|
---|
| 567 | lcd_setAddrWindow(hlcd, x, y, x, y+h-1);
|
---|
| 568 | SVC_PERROR(lcd_writedata2(hlcd, color, h));
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 | /*
|
---|
| 572 | * 水平方向LINEの高速描画
|
---|
| 573 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 574 | * param2 x: start X position
|
---|
| 575 | * param3 y: start Y position
|
---|
| 576 | * param4 w: width
|
---|
| 577 | * param5 color: color value
|
---|
| 578 | */
|
---|
| 579 | void lcd_drawFastHLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t w, color_t color)
|
---|
| 580 | {
|
---|
| 581 | // Rudimentary clipping
|
---|
| 582 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
| 583 | if((x+w-1) >= hlcd->_width) w = hlcd->_width-x;
|
---|
| 584 | lcd_setAddrWindow(hlcd, x, y, x+w-1, y);
|
---|
| 585 | SVC_PERROR(lcd_writedata2(hlcd, color, w));
|
---|
| 586 | }
|
---|
| 587 |
|
---|
| 588 | /*
|
---|
| 589 | * DRAW IMAGE LINE描画
|
---|
| 590 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 591 | * param2 x: X position
|
---|
| 592 | * param3 y: Y position
|
---|
| 593 | * param4 w: width
|
---|
| 594 | * param5 pcolor: color value
|
---|
| 595 | */
|
---|
| 596 | void
|
---|
| 597 | lcd_drawImageHLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, uint16_t w, color_t *pcolor)
|
---|
| 598 | {
|
---|
| 599 | uint32_t i;
|
---|
| 600 |
|
---|
| 601 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
| 602 | if((x+w-1) >= hlcd->_width) w = hlcd->_width-x;
|
---|
| 603 |
|
---|
| 604 | lcd_setAddrWindow(hlcd, x, y, x+w-1, y);
|
---|
| 605 | for(i = 0 ; i < w ; i++, pcolor++)
|
---|
| 606 | SVC_PERROR(lcd_writedata2(hlcd, *pcolor, 1));
|
---|
| 607 | }
|
---|
| 608 |
|
---|
| 609 | /*
|
---|
| 610 | * BITMAP描画
|
---|
| 611 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 612 | * param2 x0: Bmp X position in the LCD
|
---|
| 613 | * param3 y0: Bmp Y position in the LCD
|
---|
| 614 | * param4 pbmp: Pointer to Bmp picture address in the internal Flash
|
---|
| 615 | */
|
---|
| 616 | void
|
---|
| 617 | lcd_drawBitmap(LCD_Handler_t *hlcd, uint16_t x0, uint16_t y0, uint8_t *pbmp)
|
---|
| 618 | {
|
---|
| 619 | uint32_t index = 0, width = 0, height = 0, bit_pixel = 0;
|
---|
| 620 | uint32_t input_color_mode = 0;
|
---|
| 621 |
|
---|
| 622 | /* Get bitmap data address offset */
|
---|
| 623 | index = *(uint16_t *) (pbmp + 10);
|
---|
| 624 | index |= (*(uint16_t *) (pbmp + 12)) << 16;
|
---|
| 625 |
|
---|
| 626 | /* Read bitmap width */
|
---|
| 627 | width = *(uint16_t *) (pbmp + 18);
|
---|
| 628 | width |= (*(uint16_t *) (pbmp + 20)) << 16;
|
---|
| 629 |
|
---|
| 630 | /* Read bitmap height */
|
---|
| 631 | height = *(uint16_t *) (pbmp + 22);
|
---|
| 632 | height |= (*(uint16_t *) (pbmp + 24)) << 16;
|
---|
| 633 |
|
---|
| 634 | /* Read bit/pixel */
|
---|
| 635 | bit_pixel = *(uint16_t *) (pbmp + 28);
|
---|
| 636 |
|
---|
| 637 | /* Get the layer pixel format */
|
---|
| 638 | if ((bit_pixel/8) == 4){
|
---|
| 639 | input_color_mode = CM_ARGB8888;
|
---|
| 640 | }
|
---|
| 641 | else if ((bit_pixel/8) == 2){
|
---|
| 642 | input_color_mode = CM_RGB565;
|
---|
| 643 | }
|
---|
| 644 | else{
|
---|
| 645 | input_color_mode = CM_RGB888;
|
---|
| 646 | }
|
---|
| 647 |
|
---|
| 648 | /* Bypass the bitmap header */
|
---|
| 649 | pbmp += (index + (width * (height - 1) * (bit_pixel/8)));
|
---|
| 650 | syslog_4(LOG_NOTICE, "## input_color_mode(%d) width(%d) height(%d) bit_pixel(%d) ##", input_color_mode, width, height, bit_pixel);
|
---|
| 651 |
|
---|
| 652 | lcd_setAddrWindow(hlcd, x0, y0, x0+width-1, y0+height-1);
|
---|
| 653 | lcd_writedata3(hlcd, pbmp, width, height);
|
---|
| 654 | }
|
---|
| 655 |
|
---|
| 656 | /*
|
---|
| 657 | * INVERT DISPLAY
|
---|
| 658 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 659 | * param2 i: invert value
|
---|
| 660 | */
|
---|
| 661 | void
|
---|
| 662 | lcd_invertDisplay(LCD_Handler_t *hlcd, bool_t i)
|
---|
| 663 | {
|
---|
| 664 | SVC_PERROR(lcd_writecommand(hlcd, i ? ST7735_INVON : ST7735_INVOFF));
|
---|
| 665 | }
|
---|
| 666 |
|
---|
| 667 |
|
---|
| 668 | /*
|
---|
| 669 | * スクリーンフィル
|
---|
| 670 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
| 671 | */
|
---|
| 672 | void
|
---|
| 673 | lcd_fillScreen(LCD_DrawProp_t *pDrawProp)
|
---|
| 674 | {
|
---|
| 675 | lcd_fillRect(pDrawProp->hlcd, 0, 0, pDrawProp->hlcd->_width, pDrawProp->hlcd->_height, pDrawProp->BackColor);
|
---|
| 676 | }
|
---|
| 677 |
|
---|
| 678 | /*
|
---|
| 679 | * RECTANGLE描画
|
---|
| 680 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
| 681 | * param2 x: left X position
|
---|
| 682 | * param3 y: top Y position
|
---|
| 683 | * param4 w: width
|
---|
| 684 | * param5 h: height
|
---|
| 685 | */
|
---|
| 686 | void
|
---|
| 687 | lcd_drawRect(LCD_DrawProp_t *pDrawProp, int16_t x, int16_t y, int16_t w, int16_t h)
|
---|
| 688 | {
|
---|
| 689 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
| 690 | color_t color;
|
---|
| 691 |
|
---|
| 692 | // rudimentary clipping (drawChar w/big text requires this)
|
---|
| 693 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
| 694 | if((x + w - 1) >= hlcd->_width) w = hlcd->_width - x;
|
---|
| 695 | if((y + h - 1) >= hlcd->_height) h = hlcd->_height - y;
|
---|
| 696 |
|
---|
| 697 | color = pDrawProp->TextColor;
|
---|
| 698 | lcd_drawFastVLine(hlcd, x, y, h, color);
|
---|
| 699 | lcd_drawFastHLine(hlcd, x, y+h-1, w, color);
|
---|
| 700 | lcd_drawFastVLine(hlcd, x+w-1, y, h, color);
|
---|
| 701 | lcd_drawFastHLine(hlcd, x, y, w, color);
|
---|
| 702 | }
|
---|
| 703 |
|
---|
| 704 | /*
|
---|
| 705 | * 円描画
|
---|
| 706 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
| 707 | * param2 x0: X position
|
---|
| 708 | * param3 y0: Y position
|
---|
| 709 | * param4 Radius: Circle radius
|
---|
| 710 | */
|
---|
| 711 | void
|
---|
| 712 | lcd_DrawCircle(LCD_DrawProp_t *pDrawProp, uint16_t x0, uint16_t y0, uint16_t Radius)
|
---|
| 713 | {
|
---|
| 714 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
| 715 | int32_t decision; /* Decision Variable */
|
---|
| 716 | uint32_t current_x; /* Current X Value */
|
---|
| 717 | uint32_t current_y; /* Current Y Value */
|
---|
| 718 |
|
---|
| 719 | decision = 3 - (Radius << 1);
|
---|
| 720 | current_x = 0;
|
---|
| 721 | current_y = Radius;
|
---|
| 722 |
|
---|
| 723 | while(current_x <= current_y){
|
---|
| 724 | lcd_drawPixel(hlcd, (x0 + current_x), (y0 - current_y), pDrawProp->TextColor);
|
---|
| 725 | lcd_drawPixel(hlcd, (x0 - current_x), (y0 - current_y), pDrawProp->TextColor);
|
---|
| 726 | lcd_drawPixel(hlcd, (x0 + current_y), (y0 - current_x), pDrawProp->TextColor);
|
---|
| 727 | lcd_drawPixel(hlcd, (x0 - current_y), (y0 - current_x), pDrawProp->TextColor);
|
---|
| 728 | lcd_drawPixel(hlcd, (x0 + current_x), (y0 + current_y), pDrawProp->TextColor);
|
---|
| 729 | lcd_drawPixel(hlcd, (x0 - current_x), (y0 + current_y), pDrawProp->TextColor);
|
---|
| 730 | lcd_drawPixel(hlcd, (x0 + current_y), (y0 + current_x), pDrawProp->TextColor);
|
---|
| 731 | lcd_drawPixel(hlcd, (x0 - current_y), (y0 + current_x), pDrawProp->TextColor);
|
---|
| 732 |
|
---|
| 733 | if (decision < 0){
|
---|
| 734 | decision += (current_x << 2) + 6;
|
---|
| 735 | }
|
---|
| 736 | else{
|
---|
| 737 | decision += ((current_x - current_y) << 2) + 10;
|
---|
| 738 | current_y--;
|
---|
| 739 | }
|
---|
| 740 | current_x++;
|
---|
| 741 | }
|
---|
| 742 | }
|
---|
| 743 |
|
---|
| 744 | /*
|
---|
| 745 | * 線描画
|
---|
| 746 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
| 747 | * param2 x1: Point 1 X position
|
---|
| 748 | * param3 y1: Point 1 Y position
|
---|
| 749 | * param4 x2: Point 2 X position
|
---|
| 750 | * param5 y2: Point 2 Y position
|
---|
| 751 | */
|
---|
| 752 | void
|
---|
| 753 | lcd_drawLine(LCD_DrawProp_t *pDrawProp, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
|
---|
| 754 | {
|
---|
| 755 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
| 756 | int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
|
---|
| 757 | yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0,
|
---|
| 758 | curpixel = 0;
|
---|
| 759 |
|
---|
| 760 | deltax = ABS(x2 - x1); /* The difference between the x's */
|
---|
| 761 | deltay = ABS(y2 - y1); /* The difference between the y's */
|
---|
| 762 | x = x1; /* Start x off at the first pixel */
|
---|
| 763 | y = y1; /* Start y off at the first pixel */
|
---|
| 764 |
|
---|
| 765 | if(x2 >= x1){ /* The x-values are increasing */
|
---|
| 766 | xinc1 = 1;
|
---|
| 767 | xinc2 = 1;
|
---|
| 768 | }
|
---|
| 769 | else{ /* The x-values are decreasing */
|
---|
| 770 | xinc1 = -1;
|
---|
| 771 | xinc2 = -1;
|
---|
| 772 | }
|
---|
| 773 |
|
---|
| 774 | if(y2 >= y1){ /* The y-values are increasing */
|
---|
| 775 | yinc1 = 1;
|
---|
| 776 | yinc2 = 1;
|
---|
| 777 | }
|
---|
| 778 | else{ /* The y-values are decreasing */
|
---|
| 779 | yinc1 = -1;
|
---|
| 780 | yinc2 = -1;
|
---|
| 781 | }
|
---|
| 782 |
|
---|
| 783 | if(deltax >= deltay){ /* There is at least one x-value for every y-value */
|
---|
| 784 | xinc1 = 0; /* Don't change the x when numerator >= denominator */
|
---|
| 785 | yinc2 = 0; /* Don't change the y for every iteration */
|
---|
| 786 | den = deltax;
|
---|
| 787 | num = deltax / 2;
|
---|
| 788 | num_add = deltay;
|
---|
| 789 | num_pixels = deltax; /* There are more x-values than y-values */
|
---|
| 790 | }
|
---|
| 791 | else{ /* There is at least one y-value for every x-value */
|
---|
| 792 | xinc2 = 0; /* Don't change the x for every iteration */
|
---|
| 793 | yinc1 = 0; /* Don't change the y when numerator >= denominator */
|
---|
| 794 | den = deltay;
|
---|
| 795 | num = deltay / 2;
|
---|
| 796 | num_add = deltax;
|
---|
| 797 | num_pixels = deltay; /* There are more y-values than x-values */
|
---|
| 798 | }
|
---|
| 799 |
|
---|
| 800 | for (curpixel = 0; curpixel <= num_pixels; curpixel++){
|
---|
| 801 | lcd_drawPixel(hlcd, x, y, pDrawProp->TextColor); /* Draw the current pixel */
|
---|
| 802 | num += num_add; /* Increase the numerator by the top of the fraction */
|
---|
| 803 | if(num >= den){ /* Check if numerator >= denominator */
|
---|
| 804 | num -= den; /* Calculate the new numerator value */
|
---|
| 805 | x += xinc1; /* Change the x as appropriate */
|
---|
| 806 | y += yinc1; /* Change the y as appropriate */
|
---|
| 807 | }
|
---|
| 808 | x += xinc2; /* Change the x as appropriate */
|
---|
| 809 | y += yinc2; /* Change the y as appropriate */
|
---|
| 810 | }
|
---|
| 811 | }
|
---|
| 812 |
|
---|
| 813 | /*
|
---|
| 814 | * PLOY-LINE描画
|
---|
| 815 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
| 816 | * param2 Points: Pointer to the points array
|
---|
| 817 | * param3 PointCount: Number of points
|
---|
| 818 | */
|
---|
| 819 | void
|
---|
| 820 | lcd_drawPolygon(LCD_DrawProp_t *pDrawProp, pPoint Points, uint16_t PointCount)
|
---|
| 821 | {
|
---|
| 822 | int16_t x = 0, y = 0;
|
---|
| 823 |
|
---|
| 824 | if(PointCount < 2){
|
---|
| 825 | return;
|
---|
| 826 | }
|
---|
| 827 |
|
---|
| 828 | lcd_drawLine(pDrawProp, Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
|
---|
| 829 | while(--PointCount){
|
---|
| 830 | x = Points->X;
|
---|
| 831 | y = Points->Y;
|
---|
| 832 | Points++;
|
---|
| 833 | lcd_drawLine(pDrawProp, x, y, Points->X, Points->Y);
|
---|
| 834 | }
|
---|
| 835 | }
|
---|
| 836 |
|
---|