spi_lcd_st7565r.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) 2013 Ole Reinhardt <ole.reinhardt@embedded-it.de>
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. */
  35. #ifndef _SPI_LCD_ST7565_H_
  36. #define _SPI_LCD_ST7565_H_
  37. #include <toolchain.h>
  38. #include <dev/spibus.h>
  39. /* ST7565R clock settings */
  40. #define ST7565R_CLK_MAX 20000000
  41. #define ST7565R_CONTRAST_MAX 40
  42. #define ST7565R_CONTRAST_MIN 30
  43. /* Framebuffer settings */
  44. #define ST7565R_BPP 1
  45. #define ST7565R_MAX_WIDTH 132
  46. #define ST7565R_MAX_HEIGHT 65
  47. /* LCD controller commands*/
  48. #define ST7565R_CMD_DISPLAY_ON 0xAF
  49. #define ST7565R_CMD_DISPLAY_OFF 0xAE
  50. #define ST7565R_CMD_START_LINE_SET(line) (0x40 | (line))
  51. #define ST7565R_CMD_PAGE_ADDRESS_SET(page) (0xB0 | (page))
  52. #define ST7565R_CMD_COLUMN_ADDRESS_SET_MSB(col) (0x10 | (col))
  53. #define ST7565R_CMD_COLUMN_ADDRESS_SET_LSB(col) (0x00 | (col))
  54. #define ST7565R_CMD_ADC_NORMAL 0xA0
  55. #define ST7565R_CMD_ADC_REVERSE 0xA1
  56. #define ST7565R_CMD_DISPLAY_NORMAL 0xA6
  57. #define ST7565R_CMD_DISPLAY_REVERSE 0xA7
  58. #define ST7565R_CMD_DISPLAY_ALL_POINTS_OFF 0xA4
  59. #define ST7565R_CMD_DISPLAY_ALL_POINTS_ON 0xA5
  60. #define ST7565R_CMD_LCD_BIAS_1_DIV_6_DUTY33 0xA2
  61. #define ST7565R_CMD_LCD_BIAS_1_DIV_5_DUTY33 0xA3
  62. #define ST7565R_CMD_NORMAL_SCAN_DIRECTION 0xC0
  63. #define ST7565R_CMD_REVERSE_SCAN_DIRECTION 0xC8
  64. #define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_0 0x20
  65. #define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_1 0x21
  66. #define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_2 0x22
  67. #define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_3 0x23
  68. #define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_4 0x24
  69. #define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_5 0x25
  70. #define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_6 0x26
  71. #define ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_7 0x27
  72. #define ST7565R_CMD_POWER_CTRL_ALL_ON 0x2F
  73. #define ST7565R_CMD_SLEEP_MODE 0xAC
  74. #define ST7565R_CMD_NORMAL_MODE 0xAD
  75. #define ST7565R_CMD_RESET 0xE2
  76. #define ST7565R_CMD_NOP 0xE3
  77. #define ST7565R_CMD_END 0xEE
  78. #define ST7565R_CMD_READ_MODIFY_WRITE 0xE0
  79. #define ST7565R_CMD_ELECTRONIC_VOLUME_MODE_SET 0x81
  80. #define ST7565R_CMD_ELECTRONIC_VOLUME(volume) (0x3F & (~volume))
  81. #define ST7565R_CMD_BOOSTER_RATIO_SET 0xF8
  82. #define ST7565R_CMD_BOOSTER_RATIO_2X_3X_4X 0x00
  83. #define ST7565R_CMD_BOOSTER_RATIO_5X 0x01
  84. #define ST7565R_CMD_BOOSTER_RATIO_6X 0x03
  85. #define ST7565R_CMD_STATUS_READ 0x00
  86. typedef struct _ST7565R_DCB {
  87. HANDLE dcb_lock;
  88. int a0_port;
  89. int a0_pin;
  90. int reset_port;
  91. int reset_pin;
  92. } ST7565R_DCB;
  93. extern NUTSPINODE nodeAt45d0;
  94. extern NUTDEVICE devSt7565rFb0;
  95. extern int St7565rNodeLock(NUTDEVICE * dev);
  96. extern void St7565rNodeUnlock(NUTDEVICE * dev);
  97. extern int St7565rSetMode(NUTDEVICE * dev, int sleep);
  98. extern int St7565rSetPageAddress(NUTDEVICE * dev, uint8_t address);
  99. extern int St7565rSetColAddress(NUTDEVICE * dev, uint8_t address);
  100. extern int St7565rSetDisplayStartLineAddress(NUTDEVICE * dev, uint8_t address);
  101. extern int St7565rDisplayEnable(NUTDEVICE * dev, int enable);
  102. extern int St7565rSetContrast(NUTDEVICE * dev, uint8_t contrast);
  103. extern int St7565rDisplayInvert(NUTDEVICE * dev, int invert);
  104. extern int St7565rDebugPixelsAllOn(NUTDEVICE * dev, int all_on);
  105. extern int St7565rUpdateFb(NUTDEVICE * dev);
  106. #endif