lcdDrv.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include "lcdDrv.h"
  2. #include "osi_api.h"
  3. #include "osi_log.h"
  4. #include "hal_gouda.h"
  5. #include "drv_lcd.h"
  6. #include "gui.h"
  7. #include "log.h"
  8. #define LCD_DRV_ID_ST7735 0x7c89f0
  9. static void _lcdDelayMs(int ms_delay)
  10. {
  11. osiDelayUS(ms_delay * 1000);
  12. }
  13. const unsigned char Cmd_xB1[3]={0x05,0x3c,0x3c};
  14. const unsigned char Cmd_xB2[3]={0x05,0x3c,0x3c};
  15. const unsigned char Cmd_xB3[6]={0x05,0x3c,0x3c,0x05,0x3c,0x3c};
  16. const unsigned char Cmd_xB4[1]={0x03};
  17. const unsigned char Cmd_xC0[3]={0x28,0x08,0x04};
  18. const unsigned char Cmd_xC1[1]={0xC0};
  19. const unsigned char Cmd_xC2[2]={0x0D,0x00};
  20. const unsigned char Cmd_xC3[2]={0x8D,0x2A};
  21. const unsigned char Cmd_xC4[2]={0x8D,0xEE};
  22. const unsigned char Cmd_xC5[1]={0x1A};
  23. const unsigned char Cmd_x36[1]={0xC0};//��如果�b 0000-->RGB 0b 1000-->BGR
  24. const unsigned char Cmd_xE0[16]={0x04,0x22,0x07,0x0A,0x2E,0x30,0x25,0x2A,0x28,0x26,0x2E,0x3A,0x00,0x01,0x03,0x13};
  25. const unsigned char Cmd_xE1[16]={0x04,0x16,0x06,0x0D,0x2D,0x26,0x23,0x27,0x27,0x25,0x2D,0x3B,0x00,0x01,0x04,0x13};
  26. const unsigned char Cmd_x3A[1]={0x05};
  27. static void cmdDataSet(unsigned char cmd, unsigned char *data, int datalen){
  28. int i;
  29. LCD_CtrlWrite_ST7735(cmd);
  30. for(i=0;i<datalen;i++) LCD_DataWrite_ST7735(data[i]);
  31. }
  32. /**************************************************************************************/
  33. // Description: initialize all LCD with LCDC MCU MODE and LCDC mcu mode
  34. /**************************************************************************************/
  35. static void _st7735Init(void)
  36. {
  37. MSG_INFO(1, "lcd: _st7735Init ");
  38. LCD_CtrlWrite_ST7735(0x11); //Sleep out
  39. _lcdDelayMs(10); //Delay 120ms
  40. cmdDataSet(0xB1,Cmd_xB1, sizeof(Cmd_xB1));
  41. cmdDataSet(0xB2,Cmd_xB2, sizeof(Cmd_xB2));
  42. cmdDataSet(0xB3,Cmd_xB3, sizeof(Cmd_xB3));
  43. cmdDataSet(0xB4,Cmd_xB4, sizeof(Cmd_xB4));
  44. cmdDataSet(0xC0,Cmd_xC0, sizeof(Cmd_xC0));
  45. cmdDataSet(0xC1,Cmd_xC1, sizeof(Cmd_xC1));
  46. cmdDataSet(0xC2,Cmd_xC2, sizeof(Cmd_xC2));
  47. cmdDataSet(0xC3,Cmd_xC3, sizeof(Cmd_xC3));
  48. cmdDataSet(0xC4,Cmd_xC4, sizeof(Cmd_xC4));
  49. cmdDataSet(0xC5,Cmd_xC5, sizeof(Cmd_xC5));
  50. cmdDataSet(0x36,Cmd_x36, sizeof(Cmd_x36));
  51. cmdDataSet(0xE0,Cmd_xE0, sizeof(Cmd_xE0));
  52. cmdDataSet(0xE1,Cmd_xE1, sizeof(Cmd_xE1));
  53. cmdDataSet(0x3A,Cmd_x3A, sizeof(Cmd_x3A));
  54. LCD_CtrlWrite_ST7735(0x29); //Display on
  55. _lcdDelayMs(2);
  56. LCD_CtrlWrite_ST7735(0x2c);
  57. }
  58. static const lcdOperations_t st7735sOperations =
  59. {
  60. _st7735Init,
  61. NULL,//_st7735SleepIn,
  62. NULL,//_st7735EsdCheck,
  63. NULL,//_st7735SetDisplayWindow,
  64. NULL,//_st7735InvalidateRect,
  65. NULL,//_st7735Invalidate,
  66. NULL,//_st7735Close,
  67. NULL,//_st7735RotationInvalidateRect,
  68. NULL,
  69. NULL,//_st7735ReadId,
  70. };
  71. const lcdSpec_t g_lcd_st7735s =
  72. {
  73. LCD_DRV_ID_ST7735,
  74. GLCD_WIDTH,
  75. GLCD_HEIGHT,
  76. HAL_GOUDA_SPI_LINE_4,
  77. LCD_CTRL_SPI,
  78. (lcdOperations_t *)&st7735sOperations,
  79. false,
  80. 0x2a000,
  81. 10000000,// 500000, //10000000, 10M
  82. };
  83. static lcdSpec_t *lcd_cfg_tab[] =
  84. {
  85. (lcdSpec_t *)&g_lcd_st7735s,
  86. };
  87. char lcdDrv_Init(char type){
  88. bool status;
  89. drvLcdInfoRegisterFromOpenCpu(lcd_cfg_tab, 0, 1, 0);
  90. LSAPI_PmuSetPowerLevel(OSI_MAKE_TAG('L', 'C', 'D', ' '), 1800);//2800
  91. //LSAPI_OSI_ThreadSleep(100);
  92. LSAPI_PmuSwitchPower(OSI_MAKE_TAG('L', 'C', 'D', ' '), true, true);
  93. //LSAPI_OSI_ThreadSleep(100);
  94. drvLcdClose();
  95. status=drvLcdInit();
  96. MSG_INFO(1, "Lcd status:%d", status);
  97. if(status==false) return 1;
  98. else return 0;
  99. }
  100. void showBusErrInfo(int i){
  101. static int errCnt=0;
  102. if(i>=0) return;
  103. if(++errCnt%20) MSG_WARN(1,"lcd bus errcnt:%d",errCnt);
  104. }
  105. void LCD_CtrlWrite_ST7735(unsigned char cmd){
  106. int i=100;
  107. do{
  108. if(HAL_ERR_NO==halGoudaWriteCmd(cmd)) break;
  109. }while(--i>0);
  110. showBusErrInfo(i);
  111. }
  112. void LCD_DataWrite_ST7735(unsigned char data){
  113. int i=100;
  114. do{
  115. if(HAL_ERR_NO==halGoudaWriteData(data)) break;
  116. }while(--i>0);
  117. showBusErrInfo(i);
  118. }