lcdDrv.c 3.5 KB

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