board_ILI9341.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * This file is subject to the terms of the GFX License. If a copy of
  3. * the license was not distributed with this file, you can obtain one at:
  4. *
  5. * http://ugfx.io/license.html
  6. */
  7. /**
  8. * @file boards/addons/gdisp/board_ILI9341_stm32f4xx.h
  9. * @brief GDISP Graphic Driver subsystem board SPI interface for the ILI9341 display.
  10. *
  11. * @note This file contains a mix of hardware specific and operating system specific
  12. * code. You will need to change it for your CPU and/or operating system.
  13. */
  14. #ifndef _GDISP_LLD_BOARD_H
  15. #define _GDISP_LLD_BOARD_H
  16. // For a multiple display configuration we would put all this in a structure and then
  17. // set g->board to that structure.
  18. // Use Bank1.sector4 of NOR/SRAM, address bit HADDR[27,26]=11
  19. // A6 as data command distinguishing line
  20. // Note that STM32 will be shifted to the right by one bit during setting! 111 1110=0x7E
  21. #define GDISP_REG (*((volatile uint16_t *) 0x6C000000)) /* RS = 0 */
  22. #define GDISP_RAM (*((volatile uint16_t *) 0x6C000080)) /* RS = 1 */
  23. #ifdef USE_BL_PWM
  24. /* PWM configuration structure. We use timer 12 channel 1 */
  25. static const PWMConfig pwmcfg = {
  26. 100000, /* 100 kHz PWM clock frequency. */
  27. 100, /* PWM period is 100 cycles. */
  28. 0,
  29. {
  30. {PWM_OUTPUT_ACTIVE_LOW, 0},
  31. {PWM_OUTPUT_DISABLED, 0},
  32. {PWM_OUTPUT_DISABLED, 0},
  33. {PWM_OUTPUT_DISABLED, 0}
  34. },
  35. 0,
  36. 0
  37. };
  38. #endif // USE_BL_PWM
  39. static GFXINLINE void init_board(GDisplay *g) {
  40. (void) g;
  41. // As we are not using multiple displays we set g->board to NULL as we don't use it.
  42. /* GPIO setup done by board.h */
  43. /* FSMC setup for F4 */
  44. rccEnableAHB3(RCC_AHB3ENR_FSMCEN, 0);
  45. /*** ADD DMA support!!!! */
  46. const unsigned char FSMC_Bank = 0x06; // FSMC_NE4
  47. /** From china driver */
  48. /* Bank1 NOR/SRAM control register configuration */
  49. // FSMC_MemoryDataWidth_16b | FSMC_WriteOperation_Enable | FSMC_ExtendedMode_Enable
  50. FSMC_Bank1->BTCR[FSMC_Bank] = (uint32_t)(0x10 | 0x1000 | 0x4000);
  51. /* Bank1 NOR/SRAM timing register configuration */
  52. // Address setup time (ADDSET) is 16 HCLK 1/168M=6ns*16=96ns
  53. // Data save time is 25 HCLK = 6*25 = 150ns
  54. FSMC_Bank1->BTCR[FSMC_Bank+1] = (uint32_t)(0x0F | (0x18 << 8));
  55. /* Bank1 NOR/SRAM timing register for write configuration, if extended mode is used */
  56. // Address setup time (ADDSET) is 8 HCLK = 48ns
  57. // Data save time is 6ns*9 HCLK = 54ns
  58. //FSMC_Bank1E->BWTR[FSMC_Bank] = (uint32_t)(0x08 | (0x08 << 8));
  59. /* ILI9341 can WR fastes: */
  60. //FSMC_Bank1E->BWTR[FSMC_Bank]&=~(0XF<<0); //Address setup time (ADDSET) is cleared
  61. //FSMC_Bank1E->BWTR[FSMC_Bank]&=~(0XF<<8); //Data storage time is cleared
  62. //FSMC_Bank1E->BWTR[FSMC_Bank] |=3<<0; //Address setup time (ADDSET) is 3 HCLK = 18ns
  63. //FSMC_Bank1E->BWTR[FSMC_Bank] |=2<<8; //Data storage time is 6ns*3 HCLK=18ns
  64. FSMC_Bank1E->BWTR[FSMC_Bank] = (uint32_t)((3 << 0) | (2 <<8 ));
  65. /* Enable the selected NOR/SRAM Bank by setting the PBKEN bit in the BCRx register */
  66. FSMC_Bank1->BTCR[FSMC_Bank] |= 0x01;
  67. #ifdef USE_BL_PWM
  68. /* Display backlight control */
  69. /* TIM12 is an alternate function 9 (AF9) */
  70. pwmStart(&PWMD12, &pwmcfg);
  71. palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(9));
  72. pwmEnableChannel(&PWMD12, 0, 100);
  73. #endif // USE_BL_PWM
  74. }
  75. static GFXINLINE void post_init_board(GDisplay *g) {
  76. (void) g;
  77. }
  78. static GFXINLINE void setpin_reset(GDisplay *g, gBool state) {
  79. (void) g;
  80. (void) state;
  81. }
  82. static GFXINLINE void set_backlight(GDisplay *g, gU8 percent) {
  83. (void) g;
  84. #ifdef USE_BL_PWM
  85. pwmEnableChannel(&PWMD12, 0, percent);
  86. #else
  87. if (percent) {
  88. palClearLine(LINE_LCD_BL); // PNP transistor
  89. } else {
  90. palSetLine(LINE_LCD_BL);
  91. }
  92. #endif // USE_BL_PWM
  93. }
  94. static GFXINLINE void acquire_bus(GDisplay *g) {
  95. (void) g;
  96. }
  97. static GFXINLINE void release_bus(GDisplay *g) {
  98. (void) g;
  99. }
  100. static GFXINLINE void write_index(GDisplay *g, gU16 index) {
  101. (void) g;
  102. GDISP_REG = index;
  103. }
  104. static GFXINLINE void write_data(GDisplay *g, gU16 data) {
  105. (void) g;
  106. //GDISP_RAM = (data | (data<<8));
  107. GDISP_RAM = data;
  108. }
  109. static GFXINLINE void setreadmode(GDisplay *g) {
  110. (void) g;
  111. }
  112. static GFXINLINE void setwritemode(GDisplay *g) {
  113. (void) g;
  114. }
  115. static GFXINLINE gU16 read_data(GDisplay *g) {
  116. (void) g;
  117. return GDISP_RAM;
  118. }
  119. #endif /* _GDISP_LLD_BOARD_H */