You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.3 KiB

  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.org/license.html
  6. */
  7. #ifndef _GDISP_LLD_BOARD_H
  8. #define _GDISP_LLD_BOARD_H
  9. #define ST7565_LCD_BIAS ST7565_LCD_BIAS_9 // actually 6
  10. #define ST7565_ADC ST7565_ADC_NORMAL
  11. #define ST7565_COM_SCAN ST7565_COM_SCAN_DEC
  12. #define ST7565_PAGE_ORDER 0,1,2,3
  13. /*
  14. * Custom page order for several LCD boards, e.g. HEM12864-99
  15. * #define ST7565_PAGE_ORDER 4,5,6,7,0,1,2,3
  16. */
  17. #define ST7565_GPIOPORT GPIOC
  18. #define ST7565_PORT PORTC
  19. #define ST7565_A0_PIN 7
  20. #define ST7565_RST_PIN 8
  21. #define ST7565_MOSI_PIN 6
  22. #define ST7565_SLCK_PIN 5
  23. #define ST7565_SS_PIN 4
  24. #define palSetPadModeRaw(portname, bits) \
  25. ST7565_PORT->PCR[ST7565_##portname##_PIN] = bits
  26. #define palSetPadModeNamed(portname, portmode) \
  27. palSetPadMode(ST7565_GPIOPORT, ST7565_##portname##_PIN, portmode)
  28. #define ST7565_SPI_MODE PORTx_PCRn_DSE | PORTx_PCRn_MUX(2)
  29. // DSPI Clock and Transfer Attributes
  30. // Frame Size: 8 bits
  31. // MSB First
  32. // CLK Low by default
  33. static const SPIConfig spi1config = {
  34. // Operation complete callback or @p NULL.
  35. .end_cb = NULL,
  36. //The chip select line port - when not using pcs.
  37. .ssport = ST7565_GPIOPORT,
  38. // brief The chip select line pad number - when not using pcs.
  39. .sspad=ST7565_SS_PIN,
  40. // SPI initialization data.
  41. .tar0 =
  42. SPIx_CTARn_FMSZ(7) // Frame size = 8 bytes
  43. | SPIx_CTARn_ASC(1) // After SCK Delay Scaler (min 50 ns) = 55.56ns
  44. | SPIx_CTARn_DT(0) // Delay After Transfer Scaler (no minimum)= 27.78ns
  45. | SPIx_CTARn_CSSCK(0) // PCS to SCK Delay Scaler (min 20 ns) = 27.78ns
  46. | SPIx_CTARn_PBR(0) // Baud Rate Prescaler = 2
  47. | SPIx_CTARn_BR(0) // Baud rate (min 50ns) = 55.56ns
  48. };
  49. static GFXINLINE void acquire_bus(GDisplay *g) {
  50. (void) g;
  51. // Only the LCD is using the SPI bus, so no need to acquire
  52. // spiAcquireBus(&SPID1);
  53. spiSelect(&SPID1);
  54. }
  55. static GFXINLINE void release_bus(GDisplay *g) {
  56. (void) g;
  57. // Only the LCD is using the SPI bus, so no need to release
  58. //spiReleaseBus(&SPID1);
  59. spiUnselect(&SPID1);
  60. }
  61. static GFXINLINE void init_board(GDisplay *g) {
  62. (void) g;
  63. palSetPadModeNamed(A0, PAL_MODE_OUTPUT_PUSHPULL);
  64. palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN);
  65. palSetPadModeNamed(RST, PAL_MODE_OUTPUT_PUSHPULL);
  66. palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN);
  67. palSetPadModeRaw(MOSI, ST7565_SPI_MODE);
  68. palSetPadModeRaw(SLCK, ST7565_SPI_MODE);
  69. palSetPadModeNamed(SS, PAL_MODE_OUTPUT_PUSHPULL);
  70. spiInit();
  71. spiStart(&SPID1, &spi1config);
  72. release_bus(g);
  73. }
  74. static GFXINLINE void post_init_board(GDisplay *g) {
  75. (void) g;
  76. }
  77. static GFXINLINE void setpin_reset(GDisplay *g, bool_t state) {
  78. (void) g;
  79. if (state) {
  80. palClearPad(ST7565_GPIOPORT, ST7565_RST_PIN);
  81. }
  82. else {
  83. palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN);
  84. }
  85. }
  86. static GFXINLINE void enter_data_mode(GDisplay *g) {
  87. palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN);
  88. }
  89. static GFXINLINE void enter_cmd_mode(GDisplay *g) {
  90. palClearPad(ST7565_GPIOPORT, ST7565_A0_PIN);
  91. }
  92. static GFXINLINE void write_data(GDisplay *g, uint8_t* data, uint16_t length) {
  93. (void) g;
  94. spiSend(&SPID1, length, data);
  95. }
  96. #endif /* _GDISP_LLD_BOARD_H */