My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

u8g_dev_uc1701_mini12864_HAL.cpp 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Based on u8g_dev_uc1701_mini12864.c (dealextreme)
  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/MarlinConfigPre.h"
  55. #if HAS_GRAPHICAL_LCD
  56. #include <U8glib.h>
  57. #include "HAL_LCD_com_defines.h"
  58. #define WIDTH 128
  59. #define HEIGHT 64
  60. #define PAGE_HEIGHT 8
  61. #define UC1701_ADC_REVERSE(N) ((N) ? 0xA1 : 0xA0)
  62. #define UC1701_BIAS_MODE(N) ((N) ? 0xA3 : 0xA2)
  63. #define UC1701_ALL_PIX(N) ((N) ? 0xA5 : 0xA4)
  64. #define UC1701_INVERTED(N) ((N) ? 0xA7 : 0xA6)
  65. #define UC1701_ON(N) ((N) ? 0xAF : 0xAE)
  66. #define UC1701_OUT_MODE(N) ((N) ? 0xC8 : 0xC0)
  67. #define UC1701_POWER_CONTROL(N) (0x28 | (N))
  68. #define UC1701_V5_RATIO(N) (0x20 | ((N) & 0x7))
  69. #define UC1701_CONTRAST(N) (0x81), (N)
  70. #define UC1701_COLUMN_HI(N) (0x10 | (((N) >> 4) & 0xF))
  71. #define UC1701_COLUMN_ADR(N) UC1701_COLUMN_HI(N), ((N) & 0xF)
  72. #define UC1701_PAGE_ADR(N) (0xB0 | (N))
  73. #define UC1701_START_LINE(N) (0x40 | (N))
  74. #define UC1701_INDICATOR(N) (0xAC), (N)
  75. #define UC1701_RESET() (0xE2)
  76. #define UC1701_NOOP() (0xE3)
  77. #define UC1701_BOOST_RATIO(N) (0xF8), (N)
  78. static const uint8_t u8g_dev_uc1701_mini12864_HAL_init_seq[] PROGMEM = {
  79. U8G_ESC_CS(0), // disable chip
  80. U8G_ESC_ADR(0), // instruction mode
  81. U8G_ESC_RST(1), // do reset low pulse with (1*16)+2 milliseconds
  82. U8G_ESC_CS(1), // enable chip
  83. UC1701_RESET(), // soft reset
  84. UC1701_START_LINE(0), // set display start line to 0
  85. UC1701_ADC_REVERSE(0), // ADC set to reverse
  86. UC1701_OUT_MODE(1), // common output mode
  87. UC1701_INVERTED(0), // display normal, bit val 0: LCD pixel off
  88. UC1701_BIAS_MODE(0), // LCD bias 1/9
  89. UC1701_POWER_CONTROL(0x7), // all power control circuits on
  90. UC1701_BOOST_RATIO(0x0), // set booster ratio to 4x
  91. UC1701_V5_RATIO(3), // set V0 voltage resistor ratio to large
  92. UC1701_CONTRAST(0x27), // set contrast
  93. UC1701_INDICATOR(0), // indicator disable
  94. UC1701_ON(1), // display on
  95. U8G_ESC_CS(0), // disable chip
  96. U8G_ESC_DLY(100), // delay 100 ms
  97. U8G_ESC_CS(1), // enable chip
  98. UC1701_ALL_PIX(1), // display all points, ST7565
  99. U8G_ESC_CS(0), // disable chip
  100. U8G_ESC_DLY(100), // delay 100 ms
  101. U8G_ESC_DLY(100), // delay 100 ms
  102. U8G_ESC_CS(1), // enable chip
  103. UC1701_ALL_PIX(0), // normal display
  104. U8G_ESC_CS(0), // disable chip
  105. U8G_ESC_END // end of sequence
  106. };
  107. static const uint8_t u8g_dev_uc1701_mini12864_HAL_data_start[] PROGMEM = {
  108. U8G_ESC_ADR(0), // instruction mode
  109. U8G_ESC_CS(1), // enable chip
  110. #if ENABLED(MKS_MINI_12864)
  111. UC1701_START_LINE(0), // set display start line to 0
  112. UC1701_ADC_REVERSE(0), // ADC set to reverse
  113. UC1701_OUT_MODE(1), // common output mode
  114. UC1701_INVERTED(0), // display normal, bit val 0: LCD pixel off
  115. UC1701_BIAS_MODE(0), // LCD bias 1/9
  116. UC1701_POWER_CONTROL(0x7),// all power control circuits on
  117. UC1701_BOOST_RATIO(0x0), // set booster ratio to 4x
  118. UC1701_V5_RATIO(3), // set V0 voltage resistor ratio to large
  119. UC1701_INDICATOR(0), // indicator disable
  120. UC1701_ON(1), // display on
  121. UC1701_COLUMN_HI(0), // set upper 4 bit of the col adr to 0
  122. #else
  123. UC1701_COLUMN_ADR(0), // address 0
  124. #endif
  125. U8G_ESC_END // end of sequence
  126. };
  127. uint8_t u8g_dev_uc1701_mini12864_HAL_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
  128. switch (msg) {
  129. case U8G_DEV_MSG_INIT:
  130. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
  131. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1701_mini12864_HAL_init_seq);
  132. break;
  133. case U8G_DEV_MSG_STOP: break;
  134. case U8G_DEV_MSG_PAGE_NEXT: {
  135. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  136. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1701_mini12864_HAL_data_start);
  137. u8g_WriteByte(u8g, dev, 0x0B0 | pb->p.page); /* select current page */
  138. u8g_SetAddress(u8g, dev, 1); /* data mode */
  139. if (!u8g_pb_WriteBuffer(pb, u8g, dev)) return 0;
  140. u8g_SetChipSelect(u8g, dev, 0);
  141. } break;
  142. case U8G_DEV_MSG_CONTRAST:
  143. u8g_SetChipSelect(u8g, dev, 1);
  144. u8g_SetAddress(u8g, dev, 0); /* instruction mode */
  145. u8g_WriteByte(u8g, dev, 0x081);
  146. u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
  147. u8g_SetChipSelect(u8g, dev, 0);
  148. return 1;
  149. }
  150. return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
  151. }
  152. uint8_t u8g_dev_uc1701_mini12864_HAL_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
  153. switch (msg) {
  154. case U8G_DEV_MSG_INIT:
  155. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
  156. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1701_mini12864_HAL_init_seq);
  157. break;
  158. case U8G_DEV_MSG_STOP: break;
  159. case U8G_DEV_MSG_PAGE_NEXT: {
  160. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  161. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1701_mini12864_HAL_data_start);
  162. u8g_WriteByte(u8g, dev, 0x0B0 | (2*pb->p.page)); /* select current page */
  163. u8g_SetAddress(u8g, dev, 1); /* data mode */
  164. u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)pb->buf);
  165. u8g_SetChipSelect(u8g, dev, 0);
  166. u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1701_mini12864_HAL_data_start);
  167. u8g_WriteByte(u8g, dev, 0x0B0 | (2*pb->p.page+1)); /* select current page */
  168. u8g_SetAddress(u8g, dev, 1); /* data mode */
  169. u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
  170. u8g_SetChipSelect(u8g, dev, 0);
  171. } break;
  172. case U8G_DEV_MSG_CONTRAST:
  173. u8g_SetChipSelect(u8g, dev, 1);
  174. u8g_SetAddress(u8g, dev, 0); /* instruction mode */
  175. u8g_WriteByte(u8g, dev, 0x081);
  176. u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
  177. u8g_SetChipSelect(u8g, dev, 0);
  178. return 1;
  179. }
  180. return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
  181. }
  182. U8G_PB_DEV(u8g_dev_uc1701_mini12864_HAL_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1701_mini12864_HAL_fn, U8G_COM_HAL_SW_SPI_FN);
  183. U8G_PB_DEV(u8g_dev_uc1701_mini12864_HAL_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1701_mini12864_HAL_fn, U8G_COM_HAL_HW_SPI_FN);
  184. uint8_t u8g_dev_uc1701_mini12864_HAL_2x_buf[WIDTH*2] U8G_NOCOMMON ;
  185. u8g_pb_t u8g_dev_uc1701_mini12864_HAL_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_uc1701_mini12864_HAL_2x_buf};
  186. u8g_dev_t u8g_dev_uc1701_mini12864_HAL_2x_sw_spi = { u8g_dev_uc1701_mini12864_HAL_2x_fn, &u8g_dev_uc1701_mini12864_HAL_2x_pb, U8G_COM_HAL_SW_SPI_FN };
  187. u8g_dev_t u8g_dev_uc1701_mini12864_HAL_2x_hw_spi = { u8g_dev_uc1701_mini12864_HAL_2x_fn, &u8g_dev_uc1701_mini12864_HAL_2x_pb, U8G_COM_HAL_HW_SPI_FN };
  188. #endif // HAS_GRAPHICAL_LCD