123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #include "lcdDrv.h"
- #include "osi_api.h"
- #include "osi_log.h"
- #include "hal_gouda.h"
- #include "drv_lcd.h"
- #include "gui.h"
- #include "log.h"
- #define LCD_DRV_ID_ST7735 0x7c89f0
- static void _lcdDelayMs(int ms_delay)
- {
- osiDelayUS(ms_delay * 1000);
- }
- static void cmdDataSet(unsigned char cmd, unsigned char *data, int datalen){
- int i;
- LCD_CtrlWrite_ST7735(cmd);
- for(i=0;i<datalen;i++) LCD_DataWrite_ST7735(data[i]);
- }
- /**************************************************************************************/
- // Description: initialize all LCD with LCDC MCU MODE and LCDC mcu mode
- /**************************************************************************************/
- static void _st7735Init(void)
- {
- MSG_INFO(1, "lcd init start");
- _lcdDelayMs(10);
- #if 0
- LCD_CtrlWrite_ST7735(0xe2);
- LCD_CtrlWrite_ST7735(0xa3);
- LCD_CtrlWrite_ST7735(0xa0);
- LCD_CtrlWrite_ST7735(0xc8);
- LCD_CtrlWrite_ST7735(0x2c);
- LCD_CtrlWrite_ST7735(0x2e);
- LCD_CtrlWrite_ST7735(0x2f);
- LCD_CtrlWrite_ST7735(0x81);
- LCD_CtrlWrite_ST7735(0x12);
- LCD_CtrlWrite_ST7735(0x24);
- LCD_CtrlWrite_ST7735(0xaf);
- LCD_CtrlWrite_ST7735(0x40);
- #else
- LCD_CtrlWrite_ST7735(0xAE);
- LCD_CtrlWrite_ST7735(0x00); /*set lower column address*/
- LCD_CtrlWrite_ST7735(0x10); /*set higher column address*/
- LCD_CtrlWrite_ST7735(0x40); /*set display start line*/
- LCD_CtrlWrite_ST7735(0xB0); /*set page address*/
- LCD_CtrlWrite_ST7735(0x81); /*contract control*/
- LCD_CtrlWrite_ST7735(0x8f); /*128*/
- LCD_CtrlWrite_ST7735(0xA1); /*set segment remap*/
- LCD_CtrlWrite_ST7735(0xA4);
- LCD_CtrlWrite_ST7735(0xA6); /*normal / reverse*/
- LCD_CtrlWrite_ST7735(0xA8); /*multiplex ratio*/
- LCD_CtrlWrite_ST7735(0x3F); /*duty = 1/64*/
- LCD_CtrlWrite_ST7735(0xC8); /*Com scan direction*/
- LCD_CtrlWrite_ST7735(0xD3); /*set display offset*/
- LCD_CtrlWrite_ST7735(0x00);
- LCD_CtrlWrite_ST7735(0xD5); /*set osc division*/
- LCD_CtrlWrite_ST7735(0x80);
- LCD_CtrlWrite_ST7735(0xD9); /*set pre-charge period*/
- LCD_CtrlWrite_ST7735(0x22);
- LCD_CtrlWrite_ST7735(0xDA); /*set COM pins*/
- LCD_CtrlWrite_ST7735(0x12);
- LCD_CtrlWrite_ST7735(0xdb); /*set vcomh*/
- LCD_CtrlWrite_ST7735(0x30);
- LCD_CtrlWrite_ST7735(0x8d); /*set charge pump enable*/
- LCD_CtrlWrite_ST7735(0x10);
- _lcdDelayMs(10);
-
- LCD_CtrlWrite_ST7735(0xAF); /*display ON*/
- #endif
- }
- static const lcdOperations_t st7735sOperations =
- {
- _st7735Init,
- NULL,//_st7735SleepIn,
- NULL,//_st7735EsdCheck,
- NULL,//_st7735SetDisplayWindow,
- NULL,//_st7735InvalidateRect,
- NULL,//_st7735Invalidate,
- NULL,//_st7735Close,
- NULL,//_st7735RotationInvalidateRect,
- NULL,
- NULL,//_st7735ReadId,
- };
- const lcdSpec_t g_lcd_st7735s =
- {
- LCD_DRV_ID_ST7735,
- GLCD_WIDTH,
- GLCD_HEIGHT,
- HAL_GOUDA_SPI_LINE_4,
- LCD_CTRL_SPI,
- (lcdOperations_t *)&st7735sOperations,
- false,
- 0x2a000,
- 10000000,// 500000, //10000000, 10M
- };
- static lcdSpec_t *lcd_cfg_tab[] =
- {
- (lcdSpec_t *)&g_lcd_st7735s,
- };
- char lcdDrv_Init(char type){
- bool status;
- drvLcdInfoRegisterFromOpenCpu(lcd_cfg_tab, 0, 1, 0);
- LSAPI_PmuSetPowerLevel(OSI_MAKE_TAG('L', 'C', 'D', ' '), 1800);//3000
- //LSAPI_OSI_ThreadSleep(100);
- LSAPI_PmuSwitchPower(OSI_MAKE_TAG('L', 'C', 'D', ' '), true, true);
- //LSAPI_OSI_ThreadSleep(100);
- drvLcdClose();
- status=drvLcdInit();
-
- MSG_INFO(1, "Lcd status:%d", status);
- if(status==false) return 1;
- else return 0;
- }
- void showBusErrInfo(int i){
- static int errCnt=0;
- if(i>=0) return;
- if(++errCnt%20) MSG_WARN(1,"lcd bus errcnt:%d",errCnt);
- }
- void LCD_CtrlWrite_ST7735(unsigned char cmd){
- int i=100;
- do{
- if(HAL_ERR_NO==halGoudaWriteCmd(cmd)) break;
- }while(--i>0);
- showBusErrInfo(i);
- }
- void LCD_DataWrite_ST7735(unsigned char data){
- int i=100;
- do{
- if(HAL_ERR_NO==halGoudaWriteData(data)) break;
- }while(--i>0);
- showBusErrInfo(i);
- }
- void LCD_DataRead_ST7735(unsigned char *reg, unsigned char *data, unsigned int readLen){
- halGoudaReadData(reg, data, readLen);
- }
|