lcdDrv(7778).c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. static void cmdDataSet(unsigned char cmd, unsigned char *data, int datalen){
  14. int i;
  15. LCD_CtrlWrite_ST7735(cmd);
  16. for(i=0;i<datalen;i++) LCD_DataWrite_ST7735(data[i]);
  17. }
  18. /**************************************************************************************/
  19. // Description: initialize all LCD with LCDC MCU MODE and LCDC mcu mode
  20. /**************************************************************************************/
  21. static void _st7735Init(void)
  22. {
  23. MSG_INFO(1, "lcd init start");
  24. _lcdDelayMs(10);
  25. #if 0
  26. LCD_CtrlWrite_ST7735(0xe2);
  27. LCD_CtrlWrite_ST7735(0xa3);
  28. LCD_CtrlWrite_ST7735(0xa0);
  29. LCD_CtrlWrite_ST7735(0xc8);
  30. LCD_CtrlWrite_ST7735(0x2c);
  31. LCD_CtrlWrite_ST7735(0x2e);
  32. LCD_CtrlWrite_ST7735(0x2f);
  33. LCD_CtrlWrite_ST7735(0x81);
  34. LCD_CtrlWrite_ST7735(0x12);
  35. LCD_CtrlWrite_ST7735(0x24);
  36. LCD_CtrlWrite_ST7735(0xaf);
  37. LCD_CtrlWrite_ST7735(0x40);
  38. #else
  39. LCD_CtrlWrite_ST7735(0xAE);
  40. LCD_CtrlWrite_ST7735(0x00); /*set lower column address*/
  41. LCD_CtrlWrite_ST7735(0x10); /*set higher column address*/
  42. LCD_CtrlWrite_ST7735(0x40); /*set display start line*/
  43. LCD_CtrlWrite_ST7735(0xB0); /*set page address*/
  44. LCD_CtrlWrite_ST7735(0x81); /*contract control*/
  45. LCD_CtrlWrite_ST7735(0x8f); /*128*/
  46. LCD_CtrlWrite_ST7735(0xA1); /*set segment remap*/
  47. LCD_CtrlWrite_ST7735(0xA4);
  48. LCD_CtrlWrite_ST7735(0xA6); /*normal / reverse*/
  49. LCD_CtrlWrite_ST7735(0xA8); /*multiplex ratio*/
  50. LCD_CtrlWrite_ST7735(0x3F); /*duty = 1/64*/
  51. LCD_CtrlWrite_ST7735(0xC8); /*Com scan direction*/
  52. LCD_CtrlWrite_ST7735(0xD3); /*set display offset*/
  53. LCD_CtrlWrite_ST7735(0x00);
  54. LCD_CtrlWrite_ST7735(0xD5); /*set osc division*/
  55. LCD_CtrlWrite_ST7735(0x80);
  56. LCD_CtrlWrite_ST7735(0xD9); /*set pre-charge period*/
  57. LCD_CtrlWrite_ST7735(0x22);
  58. LCD_CtrlWrite_ST7735(0xDA); /*set COM pins*/
  59. LCD_CtrlWrite_ST7735(0x12);
  60. LCD_CtrlWrite_ST7735(0xdb); /*set vcomh*/
  61. LCD_CtrlWrite_ST7735(0x30);
  62. LCD_CtrlWrite_ST7735(0x8d); /*set charge pump enable*/
  63. LCD_CtrlWrite_ST7735(0x10);
  64. _lcdDelayMs(10);
  65. LCD_CtrlWrite_ST7735(0xAF); /*display ON*/
  66. #endif
  67. }
  68. static const lcdOperations_t st7735sOperations =
  69. {
  70. _st7735Init,
  71. NULL,//_st7735SleepIn,
  72. NULL,//_st7735EsdCheck,
  73. NULL,//_st7735SetDisplayWindow,
  74. NULL,//_st7735InvalidateRect,
  75. NULL,//_st7735Invalidate,
  76. NULL,//_st7735Close,
  77. NULL,//_st7735RotationInvalidateRect,
  78. NULL,
  79. NULL,//_st7735ReadId,
  80. };
  81. const lcdSpec_t g_lcd_st7735s =
  82. {
  83. LCD_DRV_ID_ST7735,
  84. GLCD_WIDTH,
  85. GLCD_HEIGHT,
  86. HAL_GOUDA_SPI_LINE_4,
  87. LCD_CTRL_SPI,
  88. (lcdOperations_t *)&st7735sOperations,
  89. false,
  90. 0x2a000,
  91. 10000000,// 500000, //10000000, 10M
  92. };
  93. static lcdSpec_t *lcd_cfg_tab[] =
  94. {
  95. (lcdSpec_t *)&g_lcd_st7735s,
  96. };
  97. char lcdDrv_Init(char type){
  98. bool status;
  99. drvLcdInfoRegisterFromOpenCpu(lcd_cfg_tab, 0, 1, 0);
  100. LSAPI_PmuSetPowerLevel(OSI_MAKE_TAG('L', 'C', 'D', ' '), 1800);//3000
  101. //LSAPI_OSI_ThreadSleep(100);
  102. LSAPI_PmuSwitchPower(OSI_MAKE_TAG('L', 'C', 'D', ' '), true, true);
  103. //LSAPI_OSI_ThreadSleep(100);
  104. drvLcdClose();
  105. status=drvLcdInit();
  106. MSG_INFO(1, "Lcd status:%d", status);
  107. if(status==false) return 1;
  108. else return 0;
  109. }
  110. void showBusErrInfo(int i){
  111. static int errCnt=0;
  112. if(i>=0) return;
  113. if(++errCnt%20) MSG_WARN(1,"lcd bus errcnt:%d",errCnt);
  114. }
  115. void LCD_CtrlWrite_ST7735(unsigned char cmd){
  116. int i=100;
  117. do{
  118. if(HAL_ERR_NO==halGoudaWriteCmd(cmd)) break;
  119. }while(--i>0);
  120. showBusErrInfo(i);
  121. }
  122. void LCD_DataWrite_ST7735(unsigned char data){
  123. int i=100;
  124. do{
  125. if(HAL_ERR_NO==halGoudaWriteData(data)) break;
  126. }while(--i>0);
  127. showBusErrInfo(i);
  128. }
  129. void LCD_DataRead_ST7735(unsigned char *reg, unsigned char *data, unsigned int readLen){
  130. halGoudaReadData(reg, data, readLen);
  131. }