My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

u8g_dev_st7565_64128n_HAL.cpp 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Based on u8g_dev_st7565_64128n_HAL.c (Displaytech)
  24. *
  25. * Universal 8bit Graphics Library
  26. *
  27. * Copyright (c) 2011, olikraus@gmail.com
  28. * All rights reserved.
  29. *
  30. * Redistribution and use in source and binary forms, with or without modification,
  31. * are permitted provided that the following conditions are met:
  32. *
  33. * * Redistributions of source code must retain the above copyright notice, this list
  34. * of conditions and the following disclaimer.
  35. *
  36. * * Redistributions in binary form must reproduce the above copyright notice, this
  37. * list of conditions and the following disclaimer in the documentation and/or other
  38. * materials provided with the distribution.
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  41. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  42. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  43. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  44. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  45. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  46. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  47. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  48. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  49. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  50. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  51. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  52. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  53. */
  54. #include "../../inc/MarlinConfig.h"
  55. #if HAS_MARLINUI_U8GLIB
  56. #include <U8glib-HAL.h>
  57. #include "HAL_LCD_com_defines.h"
  58. #define WIDTH 128
  59. #define HEIGHT 64
  60. #define PAGE_HEIGHT 8
  61. #ifndef ST7565_XOFFSET
  62. #define ST7565_XOFFSET 0x00
  63. #endif
  64. #define ST7565_ADC_REVERSE(N) ((N) ? 0xA1 : 0xA0)
  65. #define ST7565_BIAS_MODE(N) ((N) ? 0xA3 : 0xA2)
  66. #define ST7565_ALL_PIX(N) ((N) ? 0xA5 : 0xA4)
  67. #define ST7565_INVERTED(N) ((N) ? 0xA7 : 0xA6)
  68. #define ST7565_ON(N) ((N) ? 0xAF : 0xAE)
  69. #define ST7565_OUT_MODE(N) ((N) ? 0xC8 : 0xC0)
  70. #define ST7565_POWER_CONTROL(N) (0x28 | (N))
  71. #define ST7565_V5_RATIO(N) (0x20 | ((N) & 0x7))
  72. #define ST7565_CONTRAST(N) (0x81), (N)
  73. #define ST7565_COLUMN_ADR(N) (0x10 | (((N) >> 4) & 0xF)), ((N) & 0xF)
  74. #define ST7565_PAGE_ADR(N) (0xB0 | (N))
  75. #define ST7565_START_LINE(N) (0x40 | (N))
  76. #define ST7565_SLEEP_MODE() (0xAC) // ,(N) needed?
  77. #define ST7565_NOOP() (0xE3)
  78. /* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */
  79. static const uint8_t u8g_dev_st7565_64128n_HAL_init_seq[] PROGMEM = {
  80. U8G_ESC_CS(0), // disable chip
  81. U8G_ESC_ADR(0), // instruction mode
  82. U8G_ESC_CS(1), // enable chip
  83. U8G_ESC_RST(15), // do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
  84. ST7565_BIAS_MODE(0), // 0xA2: LCD bias 1/9 (according to Displaytech 64128N datasheet)
  85. ST7565_ADC_REVERSE(0), // Normal ADC Select (according to Displaytech 64128N datasheet)
  86. ST7565_OUT_MODE(1), // common output mode: set scan direction
  87. ST7565_START_LINE(0), // Display start line for Displaytech 64128N
  88. ST7565_POWER_CONTROL(0x4), // power control: turn on voltage converter
  89. U8G_ESC_DLY(50), // delay 50 ms
  90. ST7565_POWER_CONTROL(0x6), // power control: turn on voltage regulator
  91. U8G_ESC_DLY(50), // delay 50 ms
  92. ST7565_POWER_CONTROL(0x7), // power control: turn on voltage follower
  93. U8G_ESC_DLY(50), // delay 50 ms
  94. #ifdef ST7565_VOLTAGE_DIVIDER_VALUE
  95. // Set V5 voltage resistor ratio. Affects brightness of Displaytech 64128N
  96. ST7565_V5_RATIO(ST7565_VOLTAGE_DIVIDER_VALUE),
  97. #endif
  98. ST7565_INVERTED(0), // display normal, bit val 0: LCD pixel off.
  99. ST7565_CONTRAST(0x1E), // Contrast value for Displaytech 64128N
  100. ST7565_ON(1), // display on
  101. U8G_ESC_DLY(100), // delay 100 ms
  102. ST7565_ALL_PIX(1), // display all points, ST7565
  103. U8G_ESC_DLY(100), // delay 100 ms
  104. U8G_ESC_DLY(100), // delay 100 ms
  105. ST7565_ALL_PIX(0), // normal display
  106. U8G_ESC_CS(0), // disable chip
  107. U8G_ESC_END // end of sequence
  108. };
  109. static const uint8_t u8g_dev_st7565_64128n_HAL_data_start[] PROGMEM = {
  110. U8G_ESC_ADR(0), // instruction mode
  111. U8G_ESC_CS(1), // enable chip
  112. ST7565_COLUMN_ADR(ST7565_XOFFSET), // high 4 bits to 0, low 4 bits to 0. Changed for DisplayTech 64128N
  113. U8G_ESC_END // end of sequence
  114. };
  115. static const uint8_t u8g_dev_st7565_64128n_HAL_sleep_on[] PROGMEM = {
  116. U8G_ESC_ADR(0), // instruction mode
  117. U8G_ESC_CS(1), // enable chip
  118. ST7565_SLEEP_MODE(), // static indicator off
  119. //0x00, // indicator register set (not sure if this is required)
  120. ST7565_ON(0), // display off
  121. ST7565_ALL_PIX(1), // all points on
  122. U8G_ESC_CS(0), // disable chip, bugfix 12 nov 2014
  123. U8G_ESC_END // end of sequence
  124. };
  125. static const uint8_t u8g_dev_st7565_64128n_HAL_sleep_off[] PROGMEM = {
  126. U8G_ESC_ADR(0), // instruction mode
  127. U8G_ESC_CS(1), // enable chip
  128. ST7565_ALL_PIX(0), // all points off
  129. ST7565_ON(1), // display on
  130. U8G_ESC_DLY(50), // delay 50 ms
  131. U8G_ESC_CS(0), // disable chip, bugfix 12 nov 2014
  132. U8G_ESC_END // end of sequence
  133. };
  134. uint8_t u8g_dev_st7565_64128n_HAL_fn(u8g_t *u8g, u8g_dev_t *dev, const uint8_t msg, void *arg) {
  135. switch (msg) {
  136. case U8G_DEV_MSG_INIT:
  137. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
  138. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_init_seq);
  139. break;
  140. case U8G_DEV_MSG_STOP:
  141. break;
  142. case U8G_DEV_MSG_PAGE_NEXT: {
  143. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  144. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_data_start);
  145. u8g_WriteByte(u8g, dev, ST7565_PAGE_ADR(pb->p.page)); /* select current page (ST7565R) */
  146. u8g_SetAddress(u8g, dev, 1); /* data mode */
  147. if (!u8g_pb_WriteBuffer(pb, u8g, dev)) return 0;
  148. u8g_SetChipSelect(u8g, dev, 0);
  149. }
  150. break;
  151. case U8G_DEV_MSG_CONTRAST:
  152. u8g_SetChipSelect(u8g, dev, 1);
  153. u8g_SetAddress(u8g, dev, 0); /* instruction mode */
  154. u8g_WriteByte(u8g, dev, 0x81);
  155. u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
  156. u8g_SetChipSelect(u8g, dev, 0);
  157. return 1;
  158. case U8G_DEV_MSG_SLEEP_ON:
  159. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_sleep_on);
  160. return 1;
  161. case U8G_DEV_MSG_SLEEP_OFF:
  162. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_sleep_off);
  163. return 1;
  164. }
  165. return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
  166. }
  167. uint8_t u8g_dev_st7565_64128n_HAL_2x_fn(u8g_t *u8g, u8g_dev_t *dev, const uint8_t msg, void *arg) {
  168. switch (msg) {
  169. case U8G_DEV_MSG_INIT:
  170. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
  171. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_init_seq);
  172. break;
  173. case U8G_DEV_MSG_STOP:
  174. break;
  175. case U8G_DEV_MSG_PAGE_NEXT: {
  176. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  177. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_data_start);
  178. u8g_WriteByte(u8g, dev, ST7565_PAGE_ADR(2 * pb->p.page)); /* select current page (ST7565R) */
  179. u8g_SetAddress(u8g, dev, 1); /* data mode */
  180. u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)pb->buf);
  181. u8g_SetChipSelect(u8g, dev, 0);
  182. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_data_start);
  183. u8g_WriteByte(u8g, dev, ST7565_PAGE_ADR(2 * pb->p.page + 1)); /* select current page (ST7565R) */
  184. u8g_SetAddress(u8g, dev, 1); /* data mode */
  185. u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
  186. u8g_SetChipSelect(u8g, dev, 0);
  187. }
  188. break;
  189. case U8G_DEV_MSG_CONTRAST:
  190. u8g_SetChipSelect(u8g, dev, 1);
  191. u8g_SetAddress(u8g, dev, 0); /* instruction mode */
  192. u8g_WriteByte(u8g, dev, 0x81);
  193. u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
  194. u8g_SetChipSelect(u8g, dev, 0);
  195. return 1;
  196. case U8G_DEV_MSG_SLEEP_ON:
  197. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_sleep_on);
  198. return 1;
  199. case U8G_DEV_MSG_SLEEP_OFF:
  200. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_HAL_sleep_off);
  201. return 1;
  202. }
  203. return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
  204. }
  205. U8G_PB_DEV(u8g_dev_st7565_64128n_HAL_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_64128n_HAL_fn, U8G_COM_HAL_SW_SPI_FN);
  206. uint8_t u8g_dev_st7565_64128n_HAL_2x_buf[WIDTH*2] U8G_NOCOMMON ;
  207. u8g_pb_t u8g_dev_st7565_64128n_HAL_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_64128n_HAL_2x_buf};
  208. u8g_dev_t u8g_dev_st7565_64128n_HAL_2x_sw_spi = { u8g_dev_st7565_64128n_HAL_2x_fn, &u8g_dev_st7565_64128n_HAL_2x_pb, U8G_COM_HAL_SW_SPI_FN };
  209. U8G_PB_DEV(u8g_dev_st7565_64128n_HAL_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_64128n_HAL_fn, U8G_COM_HAL_HW_SPI_FN);
  210. u8g_dev_t u8g_dev_st7565_64128n_HAL_2x_hw_spi = { u8g_dev_st7565_64128n_HAL_2x_fn, &u8g_dev_st7565_64128n_HAL_2x_pb, U8G_COM_HAL_HW_SPI_FN };
  211. #endif // HAS_MARLINUI_U8GLIB