[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-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 | {
|
---|
[458] | 85 | gpio_set_pin(TADR_GPIO_BASE, hlcd->dcx_no, PORT_LOW);
|
---|
[453] | 86 | }
|
---|
| 87 |
|
---|
| 88 | static void set_dcx_data(LCD_Handler_t *hlcd)
|
---|
| 89 | {
|
---|
[458] | 90 | gpio_set_pin(TADR_GPIO_BASE, hlcd->dcx_no, PORT_HIGH);
|
---|
[453] | 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;
|
---|
[458] | 103 | set_dcx_control(hlcd);
|
---|
[453] | 104 | hspi->Init.DataSize = 8;
|
---|
| 105 | hspi->Init.InstLength = 8;
|
---|
| 106 | hspi->Init.AddrLength = 0;
|
---|
[458] | 107 | ercd = spi_core_transmit(hspi, hlcd->cs_sel, (uint8_t *)(aTxBuffer), 1);
|
---|
[453] | 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 |
|
---|
[458] | 130 | set_dcx_data(hlcd);
|
---|
[453] | 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 |
|
---|
[458] | 148 | set_dcx_data(hlcd);
|
---|
[453] | 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 |
|
---|
[458] | 169 | set_dcx_data(hlcd);
|
---|
[453] | 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 |
|
---|
[458] | 190 | set_dcx_data(hlcd);
|
---|
[453] | 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};
|
---|
[458] | 208 | uint8_t data[2] = {0};
|
---|
[453] | 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;
|
---|
[458] | 216 | gpio_setup(TADR_GPIO_BASE, &init, hlcd->dcx_no);
|
---|
| 217 | gpio_set_pin(TADR_GPIO_BASE, hlcd->dcx_no, PORT_HIGH);
|
---|
[453] | 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 |
|
---|
[458] | 229 | gpio_set_pin(TADR_GPIO_BASE, hlcd->rst_no, 0);
|
---|
| 230 | gpio_set_pin(TADR_GPIO_BASE, hlcd->rst_no, 1);
|
---|
[453] | 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);
|
---|
[458] | 247 | data[0] = 0x55;
|
---|
| 248 | lcd_writebyte(hlcd, &data, 1);
|
---|
[453] | 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);
|
---|
[458] | 261 | lcd_writebyte(hlcd, (uint8_t *)&hlcd->dir, 1);
|
---|
[453] | 262 |
|
---|
[458] | 263 | //lcd_writecommand(hlcd, RGB_IF_SIGNAL_CTL);
|
---|
| 264 | //data[0] = 0x00;
|
---|
| 265 | //data[1] = 0xF8;
|
---|
| 266 | //lcd_writebyte(hlcd, &data, 2);
|
---|
| 267 |
|
---|
[453] | 268 | /*
|
---|
| 269 | * display on
|
---|
| 270 | */
|
---|
| 271 | lcd_writecommand(hlcd, DISPALY_ON);
|
---|
| 272 | hlcd->mode = 1;
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | /*
|
---|
| 276 | * 表示ウィンドウ設定
|
---|
| 277 | */
|
---|
| 278 | void
|
---|
| 279 | lcd_setAddrWindow(LCD_Handler_t *hlcd, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
|
---|
| 280 | {
|
---|
[458] | 281 | uint8_t data[4] = {0};
|
---|
[453] | 282 |
|
---|
[458] | 283 | data[0] = (uint8_t)(x0 >> 8);
|
---|
| 284 | data[1] = (uint8_t)(x0);
|
---|
| 285 | data[2] = (uint8_t)(x1 >> 8);
|
---|
| 286 | data[3] = (uint8_t)(x1);
|
---|
[453] | 287 | lcd_writecommand(hlcd, HORIZONTAL_ADDRESS_SET);
|
---|
[458] | 288 | lcd_writebyte(hlcd, data, 4);
|
---|
[453] | 289 |
|
---|
[458] | 290 | data[0] = (uint8_t)(y0 >> 8);
|
---|
| 291 | data[1] = (uint8_t)(y0);
|
---|
| 292 | data[2] = (uint8_t)(y1 >> 8);
|
---|
| 293 | data[3] = (uint8_t)(y1);
|
---|
[453] | 294 | lcd_writecommand(hlcd, VERTICAL_ADDRESS_SET);
|
---|
[458] | 295 | lcd_writebyte(hlcd, data, 4);
|
---|
[453] | 296 |
|
---|
| 297 | SVC_PERROR(lcd_writecommand(hlcd, MEMORY_WRITE));
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | /*
|
---|
| 301 | * RECTANGLEのフィル描画
|
---|
| 302 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 303 | * param2 x: start X position
|
---|
| 304 | * param3 y: start Y position
|
---|
| 305 | * param4 w: width
|
---|
| 306 | * param5 h: height
|
---|
| 307 | * param6 color: color value
|
---|
| 308 | */
|
---|
| 309 | void
|
---|
| 310 | lcd_fillRect(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t w, int16_t h, color_t color)
|
---|
| 311 | {
|
---|
[458] | 312 | uint32_t data = ((uint32_t)color << 16) | (uint32_t)color;
|
---|
[453] | 313 | // rudimentary clipping (drawChar w/big text requires this)
|
---|
| 314 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
| 315 | if((x + w - 1) >= hlcd->_width) w = hlcd->_width - x;
|
---|
| 316 | if((y + h - 1) >= hlcd->_height) h = hlcd->_height - y;
|
---|
| 317 |
|
---|
| 318 | lcd_setAddrWindow(hlcd, x, y, x+w-1, y+h-1);
|
---|
[458] | 319 | SVC_PERROR(lcd_filldata(hlcd, &data, (h*w+1)/2));
|
---|
[453] | 320 | }
|
---|
| 321 |
|
---|
| 322 | /*
|
---|
| 323 | * PIXEL描画
|
---|
| 324 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 325 | * param2 x: X position
|
---|
| 326 | * param3 y: Y position
|
---|
| 327 | * param4 color: color value
|
---|
| 328 | */
|
---|
| 329 | void
|
---|
| 330 | lcd_drawPixel(LCD_Handler_t *hlcd, int16_t x, int16_t y, color_t color)
|
---|
| 331 | {
|
---|
| 332 | uint32_t data = color;
|
---|
[458] | 333 | lcd_setAddrWindow(hlcd, x, y, x, y);
|
---|
[453] | 334 | SVC_PERROR(lcd_writehalf(hlcd, &data, 1));
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 | /*
|
---|
| 338 | * 垂直方向LINEの高速描画
|
---|
| 339 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 340 | * param2 x: start X position
|
---|
| 341 | * param3 y: start Y position
|
---|
| 342 | * param4 h: height
|
---|
| 343 | * param5 color: color value
|
---|
| 344 | */
|
---|
| 345 | void
|
---|
| 346 | lcd_drawFastVLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t h, color_t color)
|
---|
| 347 | {
|
---|
[458] | 348 | uint32_t data = ((uint32_t)color << 16) | (uint32_t)color;
|
---|
[453] | 349 | // Rudimentary clipping
|
---|
| 350 | if(h == 0) return;
|
---|
| 351 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
| 352 | if((y+h-1) >= hlcd->_height) h = hlcd->_height-y;
|
---|
| 353 | lcd_setAddrWindow(hlcd, x, y, x, y+h-1);
|
---|
[458] | 354 | SVC_PERROR(lcd_filldata(hlcd, &data, (h+1)/2));
|
---|
[453] | 355 | }
|
---|
| 356 |
|
---|
| 357 | /*
|
---|
| 358 | * 水平方向LINEの高速描画
|
---|
| 359 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 360 | * param2 x: start X position
|
---|
| 361 | * param3 y: start Y position
|
---|
| 362 | * param4 w: width
|
---|
| 363 | * param5 color: color value
|
---|
| 364 | */
|
---|
| 365 | void lcd_drawFastHLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, int16_t w, color_t color)
|
---|
| 366 | {
|
---|
[458] | 367 | uint32_t data = ((uint32_t)color << 16) | (uint32_t)color;
|
---|
[453] | 368 | // Rudimentary clipping
|
---|
| 369 | if(w == 0) return;
|
---|
| 370 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
| 371 | if((x+w-1) >= hlcd->_width) w = hlcd->_width-x;
|
---|
| 372 | lcd_setAddrWindow(hlcd, x, y, x+w-1, y);
|
---|
[458] | 373 | SVC_PERROR(lcd_filldata(hlcd, &data, (w+1)/2));
|
---|
[453] | 374 | }
|
---|
| 375 |
|
---|
| 376 | /*
|
---|
| 377 | * DRAW IMAGE LINE描画
|
---|
| 378 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 379 | * param2 x: X position
|
---|
| 380 | * param3 y: Y position
|
---|
| 381 | * param4 w: width
|
---|
| 382 | * param5 pcolor: color value
|
---|
| 383 | */
|
---|
| 384 | void
|
---|
| 385 | lcd_drawImageHLine(LCD_Handler_t *hlcd, int16_t x, int16_t y, uint16_t w, uint32_t *pcolor)
|
---|
| 386 | {
|
---|
| 387 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
| 388 | if((x+w-1) >= hlcd->_width) w = hlcd->_width-x;
|
---|
| 389 | lcd_setAddrWindow(hlcd, x, y, x+w-1, y);
|
---|
| 390 | SVC_PERROR(lcd_writehalf(hlcd, pcolor, w));
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 | /*
|
---|
| 394 | * BITMAP描画
|
---|
| 395 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 396 | * param2 x0: Bmp X position in the LCD
|
---|
| 397 | * param3 y0: Bmp Y position in the LCD
|
---|
| 398 | * param4 pbmp: Pointer to Bmp picture address in the internal Flash
|
---|
| 399 | */
|
---|
| 400 | void
|
---|
| 401 | lcd_drawBitmap(LCD_Handler_t *hlcd, uint16_t x0, uint16_t y0, uint8_t *pbmp)
|
---|
| 402 | {
|
---|
| 403 | uint32_t index = 0, width = 0, height = 0, bit_pixel = 0;
|
---|
| 404 | uint32_t input_color_mode = 0;
|
---|
| 405 | uint32_t i;
|
---|
| 406 |
|
---|
| 407 | /* Get bitmap data address offset */
|
---|
| 408 | index = *(uint16_t *) (pbmp + 10);
|
---|
| 409 | index |= (*(uint16_t *) (pbmp + 12)) << 16;
|
---|
| 410 |
|
---|
| 411 | /* Read bitmap width */
|
---|
| 412 | width = *(uint16_t *) (pbmp + 18);
|
---|
| 413 | width |= (*(uint16_t *) (pbmp + 20)) << 16;
|
---|
| 414 |
|
---|
| 415 | /* Read bitmap height */
|
---|
| 416 | height = *(uint16_t *) (pbmp + 22);
|
---|
| 417 | height |= (*(uint16_t *) (pbmp + 24)) << 16;
|
---|
| 418 |
|
---|
| 419 | /* Read bit/pixel */
|
---|
| 420 | bit_pixel = *(uint16_t *) (pbmp + 28);
|
---|
| 421 |
|
---|
| 422 | /* Get the layer pixel format */
|
---|
| 423 | if ((bit_pixel/8) == 4){
|
---|
| 424 | input_color_mode = CM_ARGB8888;
|
---|
| 425 | }
|
---|
| 426 | else if ((bit_pixel/8) == 2){
|
---|
| 427 | input_color_mode = CM_RGB565;
|
---|
| 428 | }
|
---|
| 429 | else{
|
---|
| 430 | input_color_mode = CM_RGB888;
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | /* Bypass the bitmap header */
|
---|
| 434 | pbmp += (index + (width * (height - 1) * (bit_pixel/8)));
|
---|
| 435 | syslog_4(LOG_NOTICE, "## input_color_mode(%d) width(%d) height(%d) bit_pixel(%d) ##", input_color_mode, width, height, bit_pixel);
|
---|
| 436 | for(index=0; index < height; index++){
|
---|
| 437 | uint8_t *p = pbmp;
|
---|
| 438 | color_t color;
|
---|
| 439 | for (i = 0; i < width; i++){
|
---|
| 440 | color = ((p[0] & 0xf8) | (p[1] >> 5)) << 8;
|
---|
| 441 | color |= ((p[1] << 3) & 0xE0) | ((p[2] >> 3) & 0x1F);
|
---|
| 442 | lcd_drawPixel(hlcd, x0+i, y0+index, color);
|
---|
| 443 | p += 3;
|
---|
| 444 | }
|
---|
| 445 | pbmp -= width*3;
|
---|
| 446 | }
|
---|
| 447 | }
|
---|
| 448 |
|
---|
| 449 | /*
|
---|
| 450 | * PICTURE描画
|
---|
| 451 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 452 | * param2 x: Picture X position in the LCD
|
---|
| 453 | * param3 y: Picture Y position in the LCD
|
---|
| 454 | * param4 width: Picture width
|
---|
| 455 | * param5 height: Picture heigth
|
---|
| 456 | * param6 pbmp: Pointer to picture address in the internal Flash
|
---|
| 457 | */
|
---|
| 458 | void
|
---|
| 459 | lcd_drawPicture(LCD_Handler_t *hlcd, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t *pbmp)
|
---|
| 460 | {
|
---|
| 461 | SPI_Handle_t *hspi = hlcd->hspi;
|
---|
| 462 | ER ercd = E_OK;
|
---|
| 463 |
|
---|
| 464 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
| 465 | if((x+width-1) > hlcd->_width) return;
|
---|
| 466 | if((y+height-1) > hlcd->_height) return;
|
---|
| 467 |
|
---|
| 468 | lcd_setAddrWindow(hlcd, x, y, x+width-1, y+height-1);
|
---|
[458] | 469 | set_dcx_data(hlcd);
|
---|
[453] | 470 | hspi->Init.DataSize = 32;
|
---|
| 471 | hspi->Init.InstLength = 0;
|
---|
| 472 | hspi->Init.AddrLength = 32;
|
---|
| 473 | ercd = spi_core_transmit(hspi, hlcd->cs_sel, (uint8_t *)pbmp, width * height / 2);
|
---|
| 474 | #if SPI_WAIT_TIME == 0
|
---|
| 475 | if(ercd == E_OK)
|
---|
| 476 | spi_wait(hspi, SPI_CORE_WAIT_TIME);
|
---|
| 477 | #endif
|
---|
| 478 | (void)(ercd);
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 | /*
|
---|
| 482 | * INVERT DISPLAY
|
---|
| 483 | * param1 hlcd: Pointer to LCD Handler
|
---|
| 484 | * param2 i: invert value
|
---|
| 485 | */
|
---|
| 486 | void
|
---|
| 487 | lcd_invertDisplay(LCD_Handler_t *hlcd, bool_t i)
|
---|
| 488 | {
|
---|
| 489 | lcd_writecommand(hlcd, (i ? INVERSION_DISPALY_ON : INVERSION_DISPALY_OFF));
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 |
|
---|
| 493 | /*
|
---|
| 494 | * スクリーンフィル
|
---|
| 495 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
| 496 | */
|
---|
| 497 | void
|
---|
| 498 | lcd_fillScreen(LCD_DrawProp_t *pDrawProp)
|
---|
| 499 | {
|
---|
| 500 | lcd_fillRect(pDrawProp->hlcd, 0, 0, pDrawProp->hlcd->_width, pDrawProp->hlcd->_height, pDrawProp->BackColor);
|
---|
| 501 | }
|
---|
| 502 |
|
---|
| 503 | /*
|
---|
| 504 | * RECTANGLE描画
|
---|
| 505 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
| 506 | * param2 x: left X position
|
---|
| 507 | * param3 y: top Y position
|
---|
| 508 | * param4 w: width
|
---|
| 509 | * param5 h: height
|
---|
| 510 | */
|
---|
| 511 | void
|
---|
| 512 | lcd_drawRect(LCD_DrawProp_t *pDrawProp, int16_t x, int16_t y, int16_t w, int16_t h)
|
---|
| 513 | {
|
---|
| 514 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
| 515 | color_t color;
|
---|
| 516 |
|
---|
| 517 | // rudimentary clipping (drawChar w/big text requires this)
|
---|
| 518 | if((x >= hlcd->_width) || (y >= hlcd->_height)) return;
|
---|
| 519 | if((x + w - 1) >= hlcd->_width) w = hlcd->_width - x;
|
---|
| 520 | if((y + h - 1) >= hlcd->_height) h = hlcd->_height - y;
|
---|
| 521 |
|
---|
| 522 | color = pDrawProp->TextColor;
|
---|
| 523 | lcd_drawFastVLine(hlcd, x, y, h, color);
|
---|
| 524 | lcd_drawFastHLine(hlcd, x, y+h-1, w, color);
|
---|
| 525 | lcd_drawFastVLine(hlcd, x+w-1, y, h, color);
|
---|
| 526 | lcd_drawFastHLine(hlcd, x, y, w, color);
|
---|
| 527 | }
|
---|
| 528 |
|
---|
| 529 | /*
|
---|
| 530 | * 円描画
|
---|
| 531 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
| 532 | * param2 x0: X position
|
---|
| 533 | * param3 y0: Y position
|
---|
| 534 | * param4 Radius: Circle radius
|
---|
| 535 | */
|
---|
| 536 | void
|
---|
| 537 | lcd_DrawCircle(LCD_DrawProp_t *pDrawProp, uint16_t x0, uint16_t y0, uint16_t Radius)
|
---|
| 538 | {
|
---|
| 539 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
[458] | 540 | int32_t decision; /* Decision Variable */
|
---|
[453] | 541 | uint32_t current_x; /* Current X Value */
|
---|
| 542 | uint32_t current_y; /* Current Y Value */
|
---|
| 543 |
|
---|
| 544 | decision = 3 - (Radius << 1);
|
---|
| 545 | current_x = 0;
|
---|
| 546 | current_y = Radius;
|
---|
| 547 |
|
---|
| 548 | while(current_x <= current_y){
|
---|
| 549 | lcd_drawPixel(hlcd, (x0 + current_x), (y0 - current_y), pDrawProp->TextColor);
|
---|
| 550 | lcd_drawPixel(hlcd, (x0 - current_x), (y0 - current_y), pDrawProp->TextColor);
|
---|
| 551 | lcd_drawPixel(hlcd, (x0 + current_y), (y0 - current_x), pDrawProp->TextColor);
|
---|
| 552 | lcd_drawPixel(hlcd, (x0 - current_y), (y0 - current_x), pDrawProp->TextColor);
|
---|
| 553 | lcd_drawPixel(hlcd, (x0 + current_x), (y0 + current_y), pDrawProp->TextColor);
|
---|
| 554 | lcd_drawPixel(hlcd, (x0 - current_x), (y0 + current_y), pDrawProp->TextColor);
|
---|
| 555 | lcd_drawPixel(hlcd, (x0 + current_y), (y0 + current_x), pDrawProp->TextColor);
|
---|
| 556 | lcd_drawPixel(hlcd, (x0 - current_y), (y0 + current_x), pDrawProp->TextColor);
|
---|
| 557 |
|
---|
| 558 | if (decision < 0){
|
---|
| 559 | decision += (current_x << 2) + 6;
|
---|
| 560 | }
|
---|
| 561 | else{
|
---|
| 562 | decision += ((current_x - current_y) << 2) + 10;
|
---|
| 563 | current_y--;
|
---|
| 564 | }
|
---|
| 565 | current_x++;
|
---|
| 566 | }
|
---|
| 567 | }
|
---|
| 568 |
|
---|
| 569 | /*
|
---|
| 570 | * 線描画
|
---|
| 571 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
| 572 | * param2 x1: Point 1 X position
|
---|
| 573 | * param3 y1: Point 1 Y position
|
---|
| 574 | * param4 x2: Point 2 X position
|
---|
| 575 | * param5 y2: Point 2 Y position
|
---|
| 576 | */
|
---|
| 577 | void
|
---|
| 578 | lcd_drawLine(LCD_DrawProp_t *pDrawProp, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
|
---|
| 579 | {
|
---|
| 580 | LCD_Handler_t *hlcd = pDrawProp->hlcd;
|
---|
| 581 | int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
|
---|
| 582 | yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0,
|
---|
| 583 | curpixel = 0;
|
---|
| 584 |
|
---|
| 585 | deltax = ABS(x2 - x1); /* The difference between the x's */
|
---|
| 586 | deltay = ABS(y2 - y1); /* The difference between the y's */
|
---|
| 587 | x = x1; /* Start x off at the first pixel */
|
---|
| 588 | y = y1; /* Start y off at the first pixel */
|
---|
| 589 |
|
---|
| 590 | if(x2 >= x1){ /* The x-values are increasing */
|
---|
| 591 | xinc1 = 1;
|
---|
| 592 | xinc2 = 1;
|
---|
| 593 | }
|
---|
| 594 | else{ /* The x-values are decreasing */
|
---|
| 595 | xinc1 = -1;
|
---|
| 596 | xinc2 = -1;
|
---|
| 597 | }
|
---|
| 598 |
|
---|
| 599 | if(y2 >= y1){ /* The y-values are increasing */
|
---|
| 600 | yinc1 = 1;
|
---|
| 601 | yinc2 = 1;
|
---|
| 602 | }
|
---|
| 603 | else{ /* The y-values are decreasing */
|
---|
| 604 | yinc1 = -1;
|
---|
| 605 | yinc2 = -1;
|
---|
| 606 | }
|
---|
| 607 |
|
---|
| 608 | if(deltax >= deltay){ /* There is at least one x-value for every y-value */
|
---|
| 609 | xinc1 = 0; /* Don't change the x when numerator >= denominator */
|
---|
| 610 | yinc2 = 0; /* Don't change the y for every iteration */
|
---|
| 611 | den = deltax;
|
---|
| 612 | num = deltax / 2;
|
---|
| 613 | num_add = deltay;
|
---|
| 614 | num_pixels = deltax; /* There are more x-values than y-values */
|
---|
| 615 | }
|
---|
| 616 | else{ /* There is at least one y-value for every x-value */
|
---|
| 617 | xinc2 = 0; /* Don't change the x for every iteration */
|
---|
| 618 | yinc1 = 0; /* Don't change the y when numerator >= denominator */
|
---|
| 619 | den = deltay;
|
---|
| 620 | num = deltay / 2;
|
---|
| 621 | num_add = deltax;
|
---|
| 622 | num_pixels = deltay; /* There are more y-values than x-values */
|
---|
| 623 | }
|
---|
| 624 |
|
---|
| 625 | for (curpixel = 0; curpixel <= num_pixels; curpixel++){
|
---|
| 626 | lcd_drawPixel(hlcd, x, y, pDrawProp->TextColor); /* Draw the current pixel */
|
---|
| 627 | num += num_add; /* Increase the numerator by the top of the fraction */
|
---|
| 628 | if(num >= den){ /* Check if numerator >= denominator */
|
---|
| 629 | num -= den; /* Calculate the new numerator value */
|
---|
| 630 | x += xinc1; /* Change the x as appropriate */
|
---|
| 631 | y += yinc1; /* Change the y as appropriate */
|
---|
| 632 | }
|
---|
| 633 | x += xinc2; /* Change the x as appropriate */
|
---|
| 634 | y += yinc2; /* Change the y as appropriate */
|
---|
| 635 | }
|
---|
| 636 | }
|
---|
| 637 |
|
---|
| 638 | /*
|
---|
| 639 | * PLOY-LINE描画
|
---|
| 640 | * param1 pDrawProp: Pointer to Draw Prop
|
---|
| 641 | * param2 Points: Pointer to the points array
|
---|
| 642 | * param3 PointCount: Number of points
|
---|
| 643 | */
|
---|
| 644 | void
|
---|
| 645 | lcd_drawPolygon(LCD_DrawProp_t *pDrawProp, pPoint Points, uint16_t PointCount)
|
---|
| 646 | {
|
---|
| 647 | int16_t x = 0, y = 0;
|
---|
| 648 |
|
---|
| 649 | if(PointCount < 2){
|
---|
| 650 | return;
|
---|
| 651 | }
|
---|
| 652 |
|
---|
| 653 | lcd_drawLine(pDrawProp, Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
|
---|
| 654 | while(--PointCount){
|
---|
| 655 | x = Points->X;
|
---|
| 656 | y = Points->Y;
|
---|
| 657 | Points++;
|
---|
| 658 | lcd_drawLine(pDrawProp, x, y, Points->X, Points->Y);
|
---|
| 659 | }
|
---|
| 660 | }
|
---|
| 661 |
|
---|