blob: 42b2fa46165c4eaae27d30e8738f9f0581bd7c69 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/***********************************************************************
2 * Copyright (C) 2014, ZTE Corporation.
3 *
4 * File Name: hal_lcd.c
5 * File Mark:
6 * Description: Lcd function implementation. Adapted to LCM MODEL - LEAD T15DS26.
7 * Others: this file is in BOOTLOADER procedure.
8 * This LCM MODEL uses SPI-4.
9 * NOTE: 4-lines-spi uses CS, CLK, D/CX and SDI. Do not using SDO instead of D/CX.
10 * Version: V1.0
11 * Author: YinWenguan
12 * Date: 2014-12-19
13 *
14 * History 1:
15 * Date: 2015-1-16
16 * Version:
17 * Author: YinWenguan
18 * Modification: Add brightness setting.
19 * History 2:
20 * Date: 2015-2-10
21 * Version:
22 * Author: YinWenguan
23 * Modification: Add "Low Battery" logo.
24 *
25***********************************************************************/
26
27/*************************************************************************
28 * Include files
29 *************************************************************************/
30#include "../include/board.h"
31
32#include <common.h>
33#include <malloc.h>
34#include <asm/io.h>
35#include "../include/spi.h"
36#include "../include/ssp.h"
37#include <lcd.h>
38#include <drvs_gpio.h>
39#include <peripheral.h>
40
41/*************************************************************************
42 * Macro
43 *************************************************************************/
44 /* debug switch */
45#define LCD_DEBUG
46
47#ifdef LCD_DEBUG
48#define LCD_PRINTF(format, args...) printf(format, ##args)
49#define LCD_ASSERT(condition, ret, format, args...) { if (!(condition)) { printf(format, ##args); while(1){}; } }
50#else
51#define LCD_PRINTF(format, args...)
52#define LCD_ASSERT(condition, ret, format, args...)
53#endif
54/* read/write register's value */
55#define REG_READ(REG) *((volatile unsigned int*)(REG))
56#define REG_WRITE(REG,value) *((volatile unsigned int*)(REG)) = value
57
58#define ZSP_LOGO_PATH "/LOGO.bin"
59#define ZSP_LOGOBAK_PATH "/LOGOBAK.bin"
60#define ZSP_UPDATING_PATH "/UPDATING.bin"
61#define ZSP_UPDATESUCC_PATH "/UPDATESUCC.bin"
62#define ZSP_UPDATEFAIL_PATH "/UPDATEFAIL.bin"
63#define ZSP_LOWBAT_PATH "/LOWBAT.bin"
64#define ZSP_NOBAT_PATH "/NOBAT.bin"
65#define ZSP_CHARGING_PATH "/CHARGING.bin"
66
67/*R-5BIT,G-6BIT,B-5BIT:
68 * 1st byte: R4 R3 R2 R1 R0 G5 G4 G3
69 * 2nd byte: G2 G1 G0 B4 B3 B2 B1 B0
70 * picture width: 240,picture height: 240
71*/
72unsigned char bmp_logo[153600] = {};
73unsigned char bmp_updating[153600]= {};
74unsigned char bmp_updatesuccess[]= {};
75unsigned char bmp_updatefailed[] = {};
76unsigned char bmp_lowbattery[153600] = {};
77unsigned char bmp_nobattery[153600] = {};
78unsigned char bmp_charging[153600]={};
79
80
81/**************************************************************************
82 * Types *
83 **************************************************************************/
84
85/**************************************************************************
86 * Global Variable
87 **************************************************************************/
88static void * g_sLcd_SpiHandle = NULL; // SPI device handle
89volatile T_ZDrvLcd_Info s_lcd_info = {0};
90
91static int __def_lcd_prj(void)
92{
93 LCD_PRINTF("lcd_prj undefine\n");
94 return -1;
95}
96
97void lcd_gpio_define(struct T_ZDrvLcd_gpio_define * config) __attribute__((weak, alias("__def_lcd_prj")));
98int update_rect(unsigned char *pBuf, unsigned short uiLeft, unsigned short uiTop,\
99 unsigned short uiWidth, unsigned short uiHeight) __attribute__((weak, alias("__def_lcd_prj")));
100int prj_lcm_init(void) __attribute__((weak, alias("__def_lcd_prj")));
101int prj_lcd_get_info(T_ZDrvLcd_Info * pInfo) __attribute__((weak, alias("__def_lcd_prj")));
102
103/**************************************************************************
104 * Function Implementation
105 **************************************************************************/
106
107/*******************************************************************************
108 *
109 * Keep reserved.
110 * Simulating SPI r/w via GPIO.
111 *
112 ********************************************************************************/
113/* 4ÏßSPIµçƽ¼°Êý¾Ý´«Êä·½Ïò */
114#define CS_L zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.spi_cs_gpio, GPIO_LOW)
115#define CS_H zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.spi_cs_gpio, GPIO_HIGH)
116
117#define RS_L zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.spi_dcx_gpio, GPIO_LOW)
118#define RS_H zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.spi_dcx_gpio, GPIO_HIGH)
119
120#define SDA_L zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.spi_sda_gpio, GPIO_LOW)
121#define SDA_H zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.spi_sda_gpio, GPIO_HIGH)
122
123#define SCL_L zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.spi_scl_gpio, GPIO_LOW)
124#define SCL_H zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.spi_scl_gpio, GPIO_HIGH)
125
126#define SDA_OUT zDrvGpio_SetDirection(s_lcd_info.gpio_def.spi_sda_gpio, GPIO_OUT)
127#define SDA_IN zDrvGpio_SetDirection(s_lcd_info.gpio_def.spi_sda_gpio, GPIO_IN)
128
129/* SPIÅäÖÃ״̬--> ÆÕͨGPIO¿Ú */
130void change_spi_to_gpio()
131{
132 zDrvGpio_SetFunc(s_lcd_info.gpio_def.spi_cs_gpio, s_lcd_info.gpio_def.spi_cs_gpio_sel);
133 zDrvGpio_SetFunc(s_lcd_info.gpio_def.spi_scl_gpio, s_lcd_info.gpio_def.spi_scl_gpio_sel);
134 zDrvGpio_SetFunc(s_lcd_info.gpio_def.spi_sda_gpio, s_lcd_info.gpio_def.spi_sda_gpio_sel);
135
136 zDrvGpio_SetDirection(s_lcd_info.gpio_def.spi_cs_gpio, GPIO_OUT);
137 zDrvGpio_SetDirection(s_lcd_info.gpio_def.spi_scl_gpio, GPIO_OUT);
138 zDrvGpio_SetDirection(s_lcd_info.gpio_def.spi_sda_gpio, GPIO_OUT);
139
140 CS_H;
141 SCL_L;
142}
143
144/* »Ö¸´³ÉÔ­À´µÄSPIÅäÖÃ״̬ */
145void recover_gpio_to_spi()
146{
147 zDrvGpio_SetFunc(s_lcd_info.gpio_def.spi_cs_gpio, s_lcd_info.gpio_def.spi_cs_func_sel);
148 zDrvGpio_SetFunc(s_lcd_info.gpio_def.spi_scl_gpio, s_lcd_info.gpio_def.spi_scl_func_sel);
149 zDrvGpio_SetFunc(s_lcd_info.gpio_def.spi_sda_gpio, s_lcd_info.gpio_def.spi_sda_func_sel);
150 SDA_IN;
151}
152
153void delay_gpio(unsigned int tt)
154{
155 volatile unsigned int tmp = tt;
156 while(tmp > 0){tmp--;}
157}
158
159void write_st(unsigned short rs, unsigned short para)
160{
161 unsigned char i;
162
163 change_spi_to_gpio();
164
165 if (rs){RS_H;}else{RS_L;}
166 CS_L;
167 delay_gpio(50);
168 for (i = 0; i < 8; i++)
169 {
170 SCL_L;
171 delay_gpio(50);
172 if ((para & 0x80)==0x80)
173 {
174 SDA_H;
175 }
176 else
177 {
178 SDA_L;
179 }
180 delay_gpio(50);
181 SCL_H;
182 delay_gpio(50);
183 para <<= 1;
184 }
185 CS_H;
186 SCL_L;
187 delay_gpio(50);
188 recover_gpio_to_spi();
189}
190
191unsigned short read_st(unsigned short reg)
192{
193 unsigned char i;
194 volatile unsigned char tmp;
195
196 change_spi_to_gpio();
197
198 RS_L;
199 CS_L;
200 delay_gpio(50);
201 for (i = 0; i < 8; i++)
202 {
203 SCL_L;
204 delay_gpio(50);
205 if ((reg & 0x80)==0x80)
206 {
207 SDA_H;
208 }
209 else
210 {
211 SDA_L;
212 }
213 delay_gpio(50);
214 SCL_H;
215 delay_gpio(50);
216 reg <<= 1;
217 }
218 delay_gpio(50);
219 RS_H;
220 SDA_IN;
221 delay_gpio(150);
222 tmp = 0;
223 for (i = 0; i < 8; i++)
224 {
225 tmp <<= 1;
226 SCL_L;
227 delay_gpio(250);
228 if (GPIO_HIGH == zDrvGpio_GetInputValue(s_lcd_info.gpio_def.spi_sda_gpio))
229 {
230 tmp |= 0x01;
231 }
232 SCL_H;
233 delay_gpio(250);
234 }
235 CS_H;
236 SDA_OUT;
237
238 recover_gpio_to_spi();
239 return tmp;
240}
241
242#if 1
243/*******************************************************************************
244 * Function: zDrvLcd_DelayMs
245 * Description: used to delay.
246 * Parameters:
247 * (IN)
248 * ms: millisecond
249 * (OUT):
250 * None.
251 * Returns:
252 *
253 *
254 * Others:
255 ********************************************************************************/
256void zDrvLcd_DelayMs(unsigned long ms)
257{
258 volatile int i = 0;
259 while (i < (50000 * ms)) {i++;}
260}
261
262void zDrvLcd_DelayUs(unsigned long us)
263{
264 volatile int i = 0;
265 while (i < (50 * us)) {i++;}
266}
267/**************************************************************************
268* Function: zDrvLcd_Blg_Init
269* Description: used to initialize backlight usage.
270* Parameters:
271* (IN)
272*
273* (OUT)
274*
275* Returns:
276* DRV_SUCCESS: successed.
277* DRV_ERROR: others error code. For more details, please refer to the source code.
278* Others:
279**************************************************************************/
280int zDrvLcd_Blg_Init(VOID)
281{
282 int ret = DRV_SUCCESS;
283
284 if(INVLID_GPIO == s_lcd_info.gpio_def.lcd_blg_gpio)
285 return ret;
286
287 zDrvGpio_SetFunc(s_lcd_info.gpio_def.lcd_blg_gpio, s_lcd_info.gpio_def.lcd_blg_gpio_sel); /* function selection: gpio225 */
288 zDrvGpio_PullUpDown(s_lcd_info.gpio_def.lcd_blg_gpio, 0);
289 zDrvGpio_SetDirection(s_lcd_info.gpio_def.lcd_blg_gpio, GPIO_OUT);
290
291 return ret;
292}
293
294/**************************************************************************
295* Function: zDrvLcd_Gpio_Init
296* Description: used to initialize GPIO usage.
297* Parameters:
298* (IN)
299*
300* (OUT)
301*
302* Returns:
303* DRV_SUCCESS: successed.
304* DRV_ERROR: others error code. For more details, please refer to the source code.
305* Others:
306**************************************************************************/
307int zDrvLcd_Gpio_Init(void)
308{
309 int ret = DRV_SUCCESS;
310
311 lcd_gpio_define(&(s_lcd_info.gpio_def));
312
313 // RS, ¼´D/CX
314 zDrvGpio_SetFunc(s_lcd_info.gpio_def.spi_dcx_gpio, s_lcd_info.gpio_def.spi_dcx_gpio_sel); /* function selection: gpio192 */
315 zDrvGpio_SetDirection(s_lcd_info.gpio_def.spi_dcx_gpio, GPIO_OUT);
316
317 // ¸´Î»
318 zDrvGpio_SetFunc(s_lcd_info.gpio_def.lcd_reset_gpio, s_lcd_info.gpio_def.lcd_reset_gpio_sel); /* function selection: gpio225 */
319 zDrvGpio_SetDirection(s_lcd_info.gpio_def.lcd_reset_gpio, GPIO_OUT);
320
321 return ret;
322}
323
324/**************************************************************************
325* Function: zDrvLcd_Spi_Init
326* Description: used to initialize SPI usage.
327* Parameters:
328* (IN)
329*
330* (OUT)
331*
332* Returns:
333* DRV_SUCCESS: successed.
334* DRV_ERROR: others error code. For more details, please refer to the source code.
335* Others:
336**************************************************************************/
337int zDrvLcd_Spi_Init(void)
338{
339 int ret = DRV_SUCCESS;
340
341 g_sLcd_SpiHandle = ssp_open(SSP_DEV_0);
342 LCD_ASSERT(NULL != g_sLcd_SpiHandle, DRV_ERROR, "[LCD] Can not open SPI device to get handle!");
343
344 return ret;
345}
346
347/**************************************************************************
348* Function: zDrvLcd_Spi_ConfigDcx
349* Description: used to configure D/CX pin. thus, this interface is just for SPI-4.
350* Parameters:
351* (IN)
352* type command or parameter/data
353* (OUT)
354* None.
355* Returns:
356* DRV_SUCCESS: successed.
357* DRV_ERROR: others error code. For more details, please refer to the source code.
358* Others:
359* - SPI-3's data packet contains a control bit D/CX and a transmission byte.
360* - SPI-4's data packet contains just transmission byte and
361* control bit D/CX is transferred by the D/CX pin.
362**************************************************************************/
363int zDrvLcd_Spi_ConfigDcx(T_ZDrvLcd_DcxType type)
364{
365 s_lcd_info.instance.eDcxType = type;
366 zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.spi_dcx_gpio, (type == LCD_DCX_DATA) ? GPIO_HIGH : GPIO_LOW);
367
368 return DRV_SUCCESS;
369}
370
371/**************************************************************************
372* Function: zDrvLcd_Spi_WriteCmd
373* Description: used to send command-code to the LCD device IC.
374* Parameters:
375* (IN)
376* cmd command
377* (OUT)
378* None.
379* Returns:
380* DRV_SUCCESS: successed.
381* DRV_ERROR: others error code. For more details, please refer to the source code.
382* Others:
383* - SPI-3's data packet contains a control bit D/CX and a transmission byte.
384* - SPI-4's data packet contains just transmission byte and
385* control bit D/CX is transferred by the D/CX pin.
386**************************************************************************/
387int zDrvLcd_Spi_WriteCmd(unsigned char cmd)
388{
389 unsigned char buf[1] = {cmd};
390 int cnt = 0;
391
392 zDrvLcd_Spi_ConfigDcx(LCD_DCX_CMD); // µ÷Õû´«ÊäÊý¾ÝÀàÐÍ: ÃüÁî
393 cnt = ssp_transfer(g_sLcd_SpiHandle, buf, 1); // ÏòSPI¿Ú·¢ËÍ8bits cmd; ubootÀïµÄspiÖ»ÓÐCPU´«Êäģʽ
394
395 return (1 == cnt ? DRV_SUCCESS : DRV_ERROR);
396}
397
398/**************************************************************************
399* Function: zDrvLcd_Spi_WriteData
400* Description: used to send parameter/data to the LCD device IC.
401* Parameters:
402* (IN)
403* data parameter or RAM data.
404* (OUT)
405* None.
406* Returns:
407* DRV_SUCCESS: successed.
408* DRV_ERROR: others error code. For more details, please refer to the source code.
409* Others:
410* - SPI-3's data packet contains a control bit D/CX and a transmission byte.
411* - SPI-4's data packet contains just transmission byte and
412* control bit D/CX is transferred by the D/CX pin.
413**************************************************************************/
414int zDrvLcd_Spi_WriteData(unsigned char data)
415{
416 int cnt = 0;
417
418 // µ÷ÕûºóÃæµÄ´«ÊäÀàÐÍ:¸Ã½Ó¿Ú¿ÉÄܱ»Á¬Ðøµ÷Óô«Êä´óÁ¿Êý¾Ý£¬
419 // Ó¦¼õÉÙÅäÖôÎÊý
420 if (LCD_DCX_CMD == s_lcd_info.instance.eDcxType)
421 {
422 zDrvLcd_Spi_ConfigDcx(LCD_DCX_DATA);
423 }
424
425 // cnt = ssp_transfer(g_sLcd_SpiHandle, buf, 1);
426 cnt = ssp_transfer(g_sLcd_SpiHandle, &data, 1);
427
428 return (1 == cnt ? DRV_SUCCESS : DRV_ERROR);
429}
430
431int zDrvLcd_Spi_WriteDataBlock(unsigned char* pData, unsigned long size)
432{
433 int cnt = 0;
434
435 if (LCD_DCX_CMD == s_lcd_info.instance.eDcxType)
436 {
437 zDrvLcd_Spi_ConfigDcx(LCD_DCX_DATA);
438 }
439
440 cnt = ssp_transfer(g_sLcd_SpiHandle, pData, size);
441
442 return (size == cnt ? DRV_SUCCESS : DRV_ERROR);
443}
444
445/**************************************************************************
446* Function: zDrvLcd_InitLcm
447* Description: used to initialize lead(ST7735S)
448* Parameters:
449* (IN)
450* None.
451* (OUT)
452* None.
453* Returns:
454* DRV_SUCCESS: successed.
455* DRV_ERROR: others error code. For more details, please refer to the source code.
456* Others:
457* None.
458**************************************************************************/
459int zDrvLcd_Lcm_Init(void)
460{
461 int ret = DRV_SUCCESS;
462
463 ret = prj_lcm_init();
464
465 return ret;
466}
467#endif
468
469/**************************************************************************
470* Function: zDrvLcd_Open
471* Description: used to open the LCD device.
472* Parameters:
473* (IN)
474* None.
475* (OUT)
476* None.
477* Returns:
478* DRV_SUCCESS: successed.
479* DRV_ERR_OPEN_TIMES: has been opened already.
480* DRV_ERROR: others error code. For more details, please refer to the source code.
481* Others:
482* None.
483**************************************************************************/
484int zDrvLcd_Initiate(void)
485{
486 int ret = DRV_SUCCESS;
487
488 ret = zDrvLcd_Spi_Init(); // SPI³õʼ»¯
489 ret |= zDrvLcd_Gpio_Init(); // LCDÓÐÈý¸öÒý½ÅÓÃGPIO¿ØÖÆ : rest, backlight, rs(D/CX)
490
491 ret |= zDrvLcd_Reset();
492 LCD_ASSERT(DRV_SUCCESS == ret, DRV_ERROR, "[LCD] Failed to reset LCM!");
493
494 zDrvLcd_GetInfo(&s_lcd_info);
495 ret |= zDrvLcd_BootPicFromRes();
496 ret |= zDrvLcd_Lcm_Init(); // ³õʼ»¯Ä£×é
497 ret |= zDrvLcd_Blg_Init();
498 return ret;
499}
500
501int lcd_init(void)
502{
503#ifdef CONFIG_ZX297520V3E_MIFI_MINI
504#ifdef CONFIG_ZX297520V3_AIC8800
505 return zDrvLcd_Initiate();
506#endif
507#endif
508 return zDrvLcd_Initiate();
509}
510
511/**************************************************************************
512* Function: zDrvLcd_Open
513* Description: used to open the LCD device.
514* Parameters:
515* (IN)
516* devData LCD device name
517* flags don't care
518* (OUT)
519* None.
520* Returns:
521* DRV_SUCCESS: successed.
522* DRV_ERR_OPEN_TIMES: has been opened already.
523* DRV_ERROR: others error code. For more details, please refer to the source code.
524* Others:
525* None.
526**************************************************************************/
527int zDrvLcd_Open(void)
528{
529 if (s_lcd_info.instance.bOpen)
530 {
531 return DRV_ERR_OPEN_TIMES;
532 }
533
534 // Öôò¿ª±êÖ¾ºÍµ±Ç°Ä£Ê½
535 s_lcd_info.instance.bOpen= true;
536 s_lcd_info.instance.eMode = LCD_NORMAL;
537
538 return DRV_SUCCESS;
539}
540
541/**************************************************************************
542* Function: zDrvLcd_Close
543* Description: used to close the LCD device opened previously.
544* Parameters:
545* (IN)
546* None.
547* (OUT)
548* None.
549* Returns:
550* DRV_SUCCESS: successed.
551* DRV_ERR_NOT_OPENED: has not been opend yet.
552* DRV_ERROR: others error code. For more details, please refer to the source code.
553* Others:
554* None.
555**************************************************************************/
556int zDrvLcd_Close()
557{
558 if (false == s_lcd_info.instance.bOpen)
559 {
560 return DRV_ERR_NOT_OPENED;
561 }
562
563 s_lcd_info.instance.bOpen = false;
564 return DRV_SUCCESS;
565}
566
567/**************************************************************************
568* Function: zDrvLcd_GetInfo
569* Description: used to get the LCD device information.
570* Parameters:
571* (IN)
572* pInfo the pointer of LCD device information to store into
573* (OUT)
574* pInfo the pointer of LCD device information allready stored into
575* Returns:
576* DRV_SUCCESS: succeeded.
577* Others:
578* None.
579**************************************************************************/
580int zDrvLcd_GetInfo(T_ZDrvLcd_Info* pInfo)
581{
582 int ret = DRV_SUCCESS;
583
584 ret = prj_lcd_get_info(pInfo);
585
586 return ret;
587}
588
589/**************************************************************************
590* Function: zDrvLcd_Reset
591* Description: used to reset the LCD device opened previously.
592* Parameters:
593* (IN)
594* None.
595* (OUT)
596* None.
597* Returns:
598* None.
599* Others:
600* None.
601**************************************************************************/
602int zDrvLcd_Reset(void)
603{
604 int ret = DRV_SUCCESS;
605
606 // Ó²¼þ¸´Î»
607 zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.lcd_reset_gpio, GPIO_HIGH);
608 zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.lcd_reset_gpio, GPIO_LOW);
609 zDrvLcd_DelayMs(100);
610 zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.lcd_reset_gpio, GPIO_HIGH);
611 zDrvLcd_DelayMs(120);
612
613 return ret;
614}
615
616/**************************************************************************
617* Function: zDrvLcd_UpdateRect
618* Description: used to update a specified rectangle area of the LCD device opened previously.
619* Parameters:
620* (IN)
621* pBuf data buffer
622* uiLeft left postion
623* uiTop top postion
624* uiWidth rectangle width
625* uiHeight rectangle height
626* (OUT)
627* None.
628* Returns:
629* DRV_SUCCESS: successed.
630* DRV_ERROR: others error code. For more details, please refer to the source code.
631* Others:
632* None.
633**************************************************************************/
634int zDrvLcd_UpdateRect(unsigned char *pBuf, unsigned short uiLeft, unsigned short uiTop, unsigned short uiWidth, unsigned short uiHeight)
635{
636 int ret = DRV_SUCCESS;
637 unsigned short uiRight = uiLeft + uiWidth - 1;
638 unsigned short uiBottom = uiTop + uiHeight - 1;
639
640 if(pBuf != NULL)
641 {
642 if ((s_lcd_info.width <= uiLeft) ||
643 (s_lcd_info.height <= uiTop) ||
644 (s_lcd_info.width <= uiRight) ||
645 (s_lcd_info.height <= uiBottom))
646 {
647 LCD_PRINTF("[LCD]Invalid input parameter on calling zDrvLcd_UpdateRect!!!!");
648 }
649 }
650 else
651 {
652 LCD_PRINTF("[LCD]fsload resource BIN failed!!!!\n");
653 }
654 update_rect(pBuf, uiLeft, uiTop, uiWidth, uiHeight);
655
656 return ret;
657}
658
659/**************************************************************************
660* Function: Lcd_EnterSleepMode
661* Description: used to let the LCD device into sleep mode.
662* Parameters:
663* (IN)
664* bIn enter or exit sleep mode
665* (OUT)
666* None.
667* Returns:
668* DRV_SUCCESS: successed.
669* DRV_ERROR: others error code. For more details, please refer to the source code.
670* Others:
671* None.
672**************************************************************************/
673int zDrvLcd_SleepInOut( bool bIn )
674{
675 int ret = DRV_SUCCESS;
676
677 ret = zDrvLcd_Spi_WriteCmd(bIn ? 0x10 : 0x11); // enter/exit the spleep mode
678 zDrvLcd_DelayMs(120); // leave 120ms
679
680 if (false == bIn)
681 {
682 s_lcd_info.instance.eMode = LCD_NORMAL;
683 ret |= zDrvLcd_Spi_WriteCmd(0x2c); // Í˳ösleepʱ£¬²¹Ò»ÌõÖ¸Áî
684 }
685 else
686 {
687 s_lcd_info.instance.eMode = LCD_SLEEP;
688 }
689
690 return ret;
691}
692
693/**************************************************************************
694* Function: zDrvLcd_TurnBacklightOnOff
695* Description: used to turn on/off the LCD device's backlight.
696* Parameters:
697* (IN)
698* None.
699* (OUT)
700* None.
701* Returns:
702* DRV_SUCCESS: successed.
703* DRV_ERROR: others error code. For more details, please refer to the source code.
704* Others:
705* None.
706**************************************************************************/
707int zDrvLcd_TurnBacklightOnOff(unsigned int enable)
708{
709 if (enable)
710 {
711 /* turn on backlight */
712 zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.lcd_blg_gpio, GPIO_HIGH);
713 s_lcd_info.backlight = LCD_BACKLIGHT_ON;
714 }
715 else
716 {
717 /* turn off backlight */
718 zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.lcd_blg_gpio, GPIO_LOW);
719 s_lcd_info.backlight = LCD_BACKLIGHT_OFF;
720 }
721
722 return DRV_SUCCESS;
723}
724
725int zDrvLcd_SetPulseLevel(int level)
726{
727 unsigned int i = 0;
728 int ret = DRV_SUCCESS;
729
730 if (level > 16 || level < 11)
731 {
732 return -1;
733 }
734
735 for (i = 0; i < level; i++)
736 {
737 zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.lcd_blg_gpio, GPIO_LOW);
738 zDrvLcd_DelayUs(15);
739 zDrvGpio_SetOutputValue(s_lcd_info.gpio_def.lcd_blg_gpio, GPIO_HIGH);
740 zDrvLcd_DelayUs(15);
741 }
742
743 LCD_PRINTF("[lcd]:zDrvLcd_SetPulseLevel %d\n", level);
744
745 return ret;
746}
747/**************************************************************************
748* Function: zDrvLcd_PowerOnLogo, zDrvLcd_ShowXxx
749* Description:
750* Parameters:
751* (IN)
752* None.
753* (OUT)
754* None.
755* Returns:
756* DRV_SUCCESS: successed.
757* DRV_ERROR: others error code. For more details, please refer to the source code.
758* Others:
759* None.
760**************************************************************************/
761int zDrvLcd_BootPicFromRes(void)
762{
763 unsigned char *bmp;
764 char cmd[64] = {0};
765
766 sprintf(cmd, "fsload resource 0x%x %s", (ulong)(&bmp_logo), ZSP_LOGO_PATH);
767 run_command(cmd, 0);
768
769 sprintf(cmd, "fsload resource 0x%x %s", (ulong)(&bmp_updating), ZSP_UPDATING_PATH);
770 run_command(cmd, 0);
771
772 sprintf(cmd, "fsload resource 0x%x %s", (ulong)(&bmp_lowbattery), ZSP_LOWBAT_PATH);
773 run_command(cmd, 0);
774
775 sprintf(cmd, "fsload resource 0x%x %s", (ulong)(&bmp_nobattery), ZSP_NOBAT_PATH);
776 run_command(cmd, 0);
777
778 sprintf(cmd, "fsload resource 0x%x %s", (ulong)(&bmp_charging), ZSP_CHARGING_PATH);
779 run_command(cmd, 0);
780
781 return DRV_SUCCESS;
782}
783
784int zDrvLcd_PowerOnLogo(void)
785{
786 unsigned char *bmp;
787 bmp = bmp_logo;
788 return zDrvLcd_UpdateRect(bmp, 0, 0, s_lcd_info.width, s_lcd_info.height);
789}
790
791int zDrvLcd_ShowUpdateWait(void)
792{
793 unsigned char *bmp;
794 bmp = bmp_updating;
795
796 return zDrvLcd_UpdateRect(bmp, 0, 0, s_lcd_info.width, s_lcd_info.height);
797}
798
799int zDrvLcd_ShowUpdateSucc(void)
800{
801 unsigned char *bmp;
802 char cmd[64] = {0};
803 extern unsigned char bmp_updatesuccess[];
804
805 sprintf(cmd, "fsload resource 0x%x %s", (ulong)(&bmp_updatesuccess), ZSP_UPDATESUCC_PATH);
806 run_command(cmd, 0);
807 bmp = bmp_updatesuccess;
808
809 return zDrvLcd_UpdateRect(bmp, 0, 0, s_lcd_info.width, s_lcd_info.height);
810}
811
812int zDrvLcd_ShowUpdateFail(void)
813{
814 unsigned char *bmp;
815 char cmd[64] = {0};
816 extern unsigned char bmp_updatefailed[];
817
818 sprintf(cmd, "fsload resource 0x%x %s", (ulong)(&bmp_updatefailed), ZSP_UPDATEFAIL_PATH);
819 run_command(cmd, 0);
820 bmp = bmp_updatefailed;
821
822 return zDrvLcd_UpdateRect(bmp, 0, 0, s_lcd_info.width, s_lcd_info.height);
823}
824
825int zDrvLcd_ShowLowBattery(void)
826{
827 unsigned char *bmp;
828 bmp = bmp_lowbattery;
829
830 return zDrvLcd_UpdateRect(bmp, 0, 0, s_lcd_info.width, s_lcd_info.height);
831}
832
833int zDrvLcd_ShowNoBattery(void)
834{
835 unsigned char *bmp;
836 bmp = bmp_nobattery;
837
838 return zDrvLcd_UpdateRect(bmp, 0, 0, s_lcd_info.width, s_lcd_info.height);
839}
840
841int zDrvLcd_ShowCharging(void)
842{
843 unsigned char *bmp;
844 bmp = bmp_charging;
845
846 return zDrvLcd_UpdateRect(bmp, 0, 0, s_lcd_info.width, s_lcd_info.height);
847}
848