#include "nwy_osi_api.h" #include "nwy_lcd_bus.h" #include "nwy_pm.h" #include "log.h" #include "board.h" #include "lcdDrv.h" static void _st7735Init(char type); static bool lcdInitYet=false; void lcdDrvPowerCtl(bool on_off){ nwy_subpower_switch(NWY_POWER_LCD, on_off, on_off); } void lcdDrv_Init(char type){ nwy_lcd_bus_config_t lcd_bus_config = { .cs = NWY_LCD_BUS_CS_0, .cs0Polarity = false, .cs1Polarity = false, .resetb = true, .rsPolarity = false, .wrPolarity = false, .rdPolarity = false, .highByte = false, .clk = 15000000,//总线时钟 }; if(type==0){//第一次初始化 CTL_LCD_BL(0); nwy_subpower_switch(NWY_POWER_LCD, true, true); nwy_subpower_switch(NWY_POWER_BACK_LIGHT, true, true); nwy_subpower_switch(NWY_POWER_RGB_IB0, true, true); nwy_sleep(200); nwy_lcd_bus_init(&lcd_bus_config); nwy_sleep(32); _st7735Init(type); nwy_sleep(32); lcdInitYet=true; }else{//唤醒后重新初始化 nwy_subpower_switch(NWY_POWER_LCD, true, true); nwy_lcd_bus_init(&lcd_bus_config); _st7735Init(type); } } void lcdDrv_DeInit(void){ if(false==lcdInitYet) return; lcdInitYet = false; nwy_lcd_bus_deinit(); nwy_subpower_switch(NWY_POWER_BACK_LIGHT, false, false); nwy_subpower_switch(NWY_POWER_RGB_IB0, false, false); nwy_subpower_switch(NWY_POWER_LCD, false, false); } const unsigned char Cmd_xB1[3]={0x05,0x3c,0x3c}; const unsigned char Cmd_xB2[3]={0x05,0x3c,0x3c}; const unsigned char Cmd_xB3[6]={0x05,0x3c,0x3c,0x05,0x3c,0x3c}; const unsigned char Cmd_xB4[1]={0x03}; const unsigned char Cmd_xC0[3]={0x28,0x08,0x04}; const unsigned char Cmd_xC1[1]={0xC0}; const unsigned char Cmd_xC2[2]={0x0D,0x00}; const unsigned char Cmd_xC3[2]={0x8D,0x2A}; const unsigned char Cmd_xC4[2]={0x8D,0xEE}; const unsigned char Cmd_xC5[1]={0x1A}; const unsigned char Cmd_x36[1]={0x68};//低4位,如果是0b 0000-->RGB 0b 1000-->BGR const unsigned char Cmd_xE0[16]={0x04,0x22,0x07,0x0A,0x2E,0x30,0x25,0x2A,0x28,0x26,0x2E,0x3A,0x00,0x01,0x03,0x13}; const unsigned char Cmd_xE1[16]={0x04,0x16,0x06,0x0D,0x2D,0x26,0x23,0x27,0x27,0x25,0x2D,0x3B,0x00,0x01,0x04,0x13}; const unsigned char Cmd_x3A[1]={0x05}; static void cmdDataSet(unsigned char cmd, unsigned char *data, int datalen){ int i; LCD_CtrlWrite_ST7735(cmd); for(i=0;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(true==nwy_lcd_bus_write_cmd(cmd)) break; }while(--i>0); showBusErrInfo(i); } void LCD_DataWrite_ST7735(unsigned char data){ int i=100; do{ if(true==nwy_lcd_bus_write_data(data)) break; }while(--i>0); showBusErrInfo(i); }