123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- #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);
- }
- const unsigned char Cmd_xC8[3]={0xff,0x93,0x42};
- const unsigned char Cmd_xB6[2]={0x0A,0Xe0};
- const unsigned char Cmd_x36[1]={0x00};//d0
- const unsigned char Cmd_x3A[1]={0x06};
- const unsigned char Cmd_xC0[1]={0x2c};
- const unsigned char Cmd_xC1[1]={0x02};
- const unsigned char Cmd_xC2[1]={0x01};
- const unsigned char Cmd_xC3[1]={0x1a};
- const unsigned char Cmd_xC4[1]={0x20};
- const unsigned char Cmd_xC5[1]={0xca};
- const unsigned char Cmd_xC6[1]={0x0f};
- const unsigned char Cmd_xD0[2]={0xA4,0xa1};
- const unsigned char Cmd_xB1[2]={0x00,0x1b};
- const unsigned char Cmd_xB2[5]={0x0c,0x0c,0x00,0x33,0x33};
- const unsigned char Cmd_xB4[1]={0x02};
- const unsigned char Cmd_xB7[1]={0x35};
- const unsigned char Cmd_xBB[1]={0x38};
- const unsigned char Cmd_xE0[15]={0x00,0x01,0x04,0x00,0x11,0x08,0x35,0x79,0x45,0x07,0x0D,0x09,0x16,0x17,0x0F};
- const unsigned char Cmd_xE1[15]={0x00,0x28,0x29,0x02,0x0F,0x06,0x3F,0x25,0x55,0x06,0x15,0x0F,0x38,0x38,0x0F};
- 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]);
- }
- static void cmdDataSetOne(unsigned char cmd, unsigned char data){
- LCD_CtrlWrite_ST7735(cmd);
- LCD_DataWrite_ST7735(data);
- }
- /**************************************************************************************/
- // Description: initialize all LCD with LCDC MCU MODE and LCDC mcu mode
- /**************************************************************************************/
- static void _st7735Init(void)
- {
- char infoo[50];
- char lcdtype=0;
- unsigned char id[4];
- MSG_INFO(1, "lcd: _st7735Init ");
- LCD_DataRead_ST7735(0x04, id, 4);
- if(id[1]==0xf0 && id[2]==0x89 && id[3]==0x7c) lcdtype=0;//st7735
- else if(id[1]==0x06 && id[2]==0x91 && id[3]==0x00) lcdtype=1;//gc9106
- MSG_INFO(1, "id:%02x%02x%02x", id[1],id[2],id[3]);
-
- lcdtype=0;//test
-
- if(lcdtype==0){
-
- LCD_CtrlWrite_ST7735(0x11); //Sleep out
- _lcdDelayMs(10); //Delay 120ms
- #if 0
- //--------------------------------------Display Setting---------------------------------------//
- LCD_CtrlWrite_ST7735 (0x36);
- LCD_DataWrite_ST7735 (0xc8);
- LCD_CtrlWrite_ST7735 (0x3a);
- LCD_DataWrite_ST7735 (0x05);
- //--------------------------------ST7789S Frame rate setting----------------------------------//
- LCD_CtrlWrite_ST7735 (0xb2);
- LCD_DataWrite_ST7735 (0x0c);
- LCD_DataWrite_ST7735 (0x0c);
- LCD_DataWrite_ST7735 (0x00);
- LCD_DataWrite_ST7735 (0x33);
- LCD_DataWrite_ST7735 (0x33);
- LCD_CtrlWrite_ST7735 (0xb7);
- LCD_DataWrite_ST7735 (0x35);
- //---------------------------------ST7789S Power setting--------------------------------------//
- LCD_CtrlWrite_ST7735 (0xbb);
- LCD_DataWrite_ST7735 (0x35);
- LCD_CtrlWrite_ST7735 (0xc0);
- LCD_DataWrite_ST7735 (0x2c);
- LCD_CtrlWrite_ST7735 (0xc2);
- LCD_DataWrite_ST7735 (0x01);
- LCD_CtrlWrite_ST7735 (0xc3);
- LCD_DataWrite_ST7735 (0x11);
- LCD_CtrlWrite_ST7735 (0xc4);
- LCD_DataWrite_ST7735 (0x20);
- LCD_CtrlWrite_ST7735 (0xc6);
- LCD_DataWrite_ST7735 (0x0f);
- LCD_CtrlWrite_ST7735 (0xd0);
- LCD_DataWrite_ST7735 (0xa4);
- LCD_DataWrite_ST7735 (0xa1);
- //--------------------------------ST7789S gamma setting---------------------------------------//
- LCD_CtrlWrite_ST7735 (0xe0);
- LCD_DataWrite_ST7735 (0xd0);
- LCD_DataWrite_ST7735 (0x00);
- LCD_DataWrite_ST7735 (0x05);
- LCD_DataWrite_ST7735 (0x0e);
- LCD_DataWrite_ST7735 (0x15);
- LCD_DataWrite_ST7735 (0x0d);
- LCD_DataWrite_ST7735 (0x37);
- LCD_DataWrite_ST7735 (0x43);
- LCD_DataWrite_ST7735 (0x47);
- LCD_DataWrite_ST7735 (0x09);
- LCD_DataWrite_ST7735 (0x15);
- LCD_DataWrite_ST7735 (0x12);
- LCD_DataWrite_ST7735 (0x16);
- LCD_DataWrite_ST7735 (0x19);
- LCD_CtrlWrite_ST7735 (0xe1);
- LCD_DataWrite_ST7735 (0xd0);
- LCD_DataWrite_ST7735 (0x00);
- LCD_DataWrite_ST7735 (0x05);
- LCD_DataWrite_ST7735 (0x0d);
- LCD_DataWrite_ST7735 (0x0c);
- LCD_DataWrite_ST7735 (0x06);
- LCD_DataWrite_ST7735 (0x2d);
- LCD_DataWrite_ST7735 (0x44);
- LCD_DataWrite_ST7735 (0x40);
- LCD_DataWrite_ST7735 (0x0e);
- LCD_DataWrite_ST7735 (0x1c);
- LCD_DataWrite_ST7735 (0x18);
- LCD_DataWrite_ST7735 (0x16);
- LCD_DataWrite_ST7735 (0x19);
- LCD_CtrlWrite_ST7735 (0x29);
- #else
-
- LCD_CtrlWrite_ST7735(0x36);
- LCD_DataWrite_ST7735(0xc8);
- LCD_CtrlWrite_ST7735(0x3A);
- LCD_DataWrite_ST7735(0x05);
- LCD_CtrlWrite_ST7735(0x35);
- LCD_DataWrite_ST7735(0x00);
- LCD_CtrlWrite_ST7735(0x44);
- LCD_DataWrite_ST7735(0x00);
- LCD_DataWrite_ST7735(0x20);
- LCD_CtrlWrite_ST7735(0xB2);
- LCD_DataWrite_ST7735(0x0C);
- LCD_DataWrite_ST7735(0x0C);
- LCD_DataWrite_ST7735(0x00);
- LCD_DataWrite_ST7735(0x33);
- LCD_DataWrite_ST7735(0x33);
- LCD_CtrlWrite_ST7735(0xB7);
- LCD_DataWrite_ST7735(0x75);
- LCD_CtrlWrite_ST7735(0xBB);
- LCD_DataWrite_ST7735(0x1F);
- LCD_CtrlWrite_ST7735(0xC0);
- LCD_DataWrite_ST7735(0x2C);
- LCD_CtrlWrite_ST7735(0xC2);
- LCD_DataWrite_ST7735(0x01);
- LCD_CtrlWrite_ST7735(0xC3);
- LCD_DataWrite_ST7735(0x13);
- LCD_CtrlWrite_ST7735(0xC4);
- LCD_DataWrite_ST7735(0x20);
- LCD_CtrlWrite_ST7735(0xC6);
- LCD_DataWrite_ST7735(0x0F);
- LCD_CtrlWrite_ST7735(0xD0);
- LCD_DataWrite_ST7735(0xA4);
- LCD_DataWrite_ST7735(0xA1);
- LCD_CtrlWrite_ST7735(0xD6);
- LCD_DataWrite_ST7735(0xA1);
- LCD_CtrlWrite_ST7735(0x21);
- LCD_CtrlWrite_ST7735(0xE0);
- LCD_DataWrite_ST7735(0xD0);
- LCD_DataWrite_ST7735(0x08);
- LCD_DataWrite_ST7735(0x10);
- LCD_DataWrite_ST7735(0x0D);
- LCD_DataWrite_ST7735(0x0C);
- LCD_DataWrite_ST7735(0x07);
- LCD_DataWrite_ST7735(0x37);
- LCD_DataWrite_ST7735(0x53);
- LCD_DataWrite_ST7735(0x4C);
- LCD_DataWrite_ST7735(0x39);
- LCD_DataWrite_ST7735(0x15);
- LCD_DataWrite_ST7735(0x15);
- LCD_DataWrite_ST7735(0x2A);
- LCD_DataWrite_ST7735(0x2D);
- LCD_CtrlWrite_ST7735(0xE1);
- LCD_DataWrite_ST7735(0xD0);
- LCD_DataWrite_ST7735(0x0D);
- LCD_DataWrite_ST7735(0x12);
- LCD_DataWrite_ST7735(0x08);
- LCD_DataWrite_ST7735(0x08);
- LCD_DataWrite_ST7735(0x15);
- LCD_DataWrite_ST7735(0x34);
- LCD_DataWrite_ST7735(0x34);
- LCD_DataWrite_ST7735(0x4A);
- LCD_DataWrite_ST7735(0x36);
- LCD_DataWrite_ST7735(0x12);
- LCD_DataWrite_ST7735(0x13);
- LCD_DataWrite_ST7735(0x2B);
- LCD_DataWrite_ST7735(0x2F);
- LCD_CtrlWrite_ST7735(0x29);
-
- #endif
-
- _lcdDelayMs(2);
- //LCD_CtrlWrite_ST7735(0x2c);
-
- }else if(lcdtype==1){
- LCD_CtrlWrite_ST7735(0x01);
- LCD_CtrlWrite_ST7735(0xfe);
- LCD_CtrlWrite_ST7735(0xef);
-
- cmdDataSet(0xC8,Cmd_xC8, sizeof(Cmd_xC8));
- cmdDataSet(0xB6,Cmd_xB6, sizeof(Cmd_xB6));
- cmdDataSet(0x36,Cmd_x36, sizeof(Cmd_x36));
- cmdDataSet(0X3A,Cmd_x3A, sizeof(Cmd_x3A));
- cmdDataSet(0xc0,Cmd_xC0, sizeof(Cmd_xC0));
- cmdDataSet(0xC1,Cmd_xC1, sizeof(Cmd_xC1));
- cmdDataSet(0xC5,Cmd_xC5, sizeof(Cmd_xC5));
- cmdDataSet(0XB1,Cmd_xB1, sizeof(Cmd_xB1));
- cmdDataSet(0xB4,Cmd_xB4, sizeof(Cmd_xB4));
- cmdDataSet(0xE0,Cmd_xE0, sizeof(Cmd_xE0));
- cmdDataSet(0XE1,Cmd_xE1, sizeof(Cmd_xE1));
-
- LCD_CtrlWrite_ST7735(0xfe);
- LCD_CtrlWrite_ST7735(0xef);
-
- LCD_CtrlWrite_ST7735(0x11);
- _lcdDelayMs(120); //Delay 120ms
- LCD_CtrlWrite_ST7735(0x29); //Display on
- }
- }
- 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,
- 20000000,// 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', ' '), 2800);
- //LSAPI_OSI_ThreadSleep(100);
- LSAPI_PmuSwitchPower(OSI_MAKE_TAG('L', 'C', 'D', ' '), true, true);
- //LSAPI_OSI_ThreadSleep(100);
- LSAPI_PmuSetPowerLevel(OSI_MAKE_TAG('C', 'A', 'M', 'A'), 3200);//2800
- LSAPI_OSI_ThreadSleep(100);
- /*
- LSAPI_PmuSwitchPower(OSI_MAKE_TAG('C', 'A', 'M', 'A'), true, true);
- LSAPI_OSI_ThreadSleep(100);
- */
- drvLcdClose();
- status=drvLcdInit();
- lcdBackLightApi(0);
- 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);
- }
- void lcdBackList(char onoff){
- bool write_value = onoff;
-
- if(onoff)LSAPI_PmuSwitchPower(OSI_MAKE_TAG('C', 'A', 'M', 'A'), onoff, true);
- else LSAPI_PmuSwitchPower(OSI_MAKE_TAG('C', 'A', 'M', 'A'), onoff, false);
-
-
- }
|