My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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_com_arduino_ssd_i2c.c
  24. *
  25. * COM interface for Arduino (AND ATmega) and the SSDxxxx chip (SOLOMON) variant
  26. * I2C protocol
  27. *
  28. * ToDo: Rename this to u8g_com_avr_ssd_i2c.c
  29. *
  30. * Universal 8bit Graphics Library
  31. *
  32. * Copyright (c) 2011, olikraus@gmail.com
  33. * All rights reserved.
  34. *
  35. * Redistribution and use in source and binary forms, with or without modification,
  36. * are permitted provided that the following conditions are met:
  37. *
  38. * * Redistributions of source code must retain the above copyright notice, this list
  39. * of conditions and the following disclaimer.
  40. *
  41. * * Redistributions in binary form must reproduce the above copyright notice, this
  42. * list of conditions and the following disclaimer in the documentation and/or other
  43. * materials provided with the distribution.
  44. *
  45. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  46. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  47. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  48. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  49. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  50. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  51. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  52. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  53. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  54. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  55. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  56. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  57. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  58. */
  59. /**
  60. * Special pin usage:
  61. * U8G_PI_I2C_OPTION additional options
  62. * U8G_PI_A0_STATE used to store the last value of the command/data register selection
  63. * U8G_PI_SET_A0 1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device
  64. * U8G_PI_SCL clock line (NOT USED)
  65. * U8G_PI_SDA data line (NOT USED)
  66. *
  67. * U8G_PI_RESET reset line (currently disabled, see below)
  68. *
  69. * Protocol:
  70. * SLA, Cmd/Data Selection, Arguments
  71. * The command/data register is selected by a special instruction byte, which is sent after SLA
  72. *
  73. * The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode
  74. */
  75. #ifdef TARGET_LPC1768
  76. #include "../../../inc/MarlinConfigPre.h"
  77. #if HAS_GRAPHICAL_LCD
  78. #include <U8glib.h>
  79. #define I2C_SLA (0x3C*2)
  80. //#define I2C_CMD_MODE 0x080
  81. #define I2C_CMD_MODE 0x000
  82. #define I2C_DATA_MODE 0x040
  83. //#define U8G_I2C_OPT_FAST 16
  84. uint8_t u8g_com_ssd_I2C_start_sequence(u8g_t *u8g) {
  85. /* are we requested to set the a0 state? */
  86. if (u8g->pin_list[U8G_PI_SET_A0] == 0) return 1;
  87. /* setup bus, might be a repeated start */
  88. if (u8g_i2c_start(I2C_SLA) == 0)
  89. return 0;
  90. if (u8g->pin_list[U8G_PI_A0_STATE] == 0 ) {
  91. if (u8g_i2c_send_byte(I2C_CMD_MODE) == 0) return 0;
  92. }
  93. else if (u8g_i2c_send_byte(I2C_DATA_MODE) == 0)
  94. return 0;
  95. u8g->pin_list[U8G_PI_SET_A0] = 0;
  96. return 1;
  97. }
  98. uint8_t u8g_com_HAL_LPC1768_ssd_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
  99. switch(msg) {
  100. case U8G_COM_MSG_INIT:
  101. //u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
  102. //u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
  103. //u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: unknown mode */
  104. u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]);
  105. u8g_com_ssd_I2C_start_sequence(u8g);
  106. break;
  107. case U8G_COM_MSG_STOP:
  108. break;
  109. case U8G_COM_MSG_RESET:
  110. /* Currently disabled, but it could be enable. Previous restrictions have been removed */
  111. /* u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); */
  112. break;
  113. case U8G_COM_MSG_CHIP_SELECT:
  114. u8g->pin_list[U8G_PI_A0_STATE] = 0;
  115. u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */
  116. if (arg_val == 0 ) {
  117. /* disable chip, send stop condition */
  118. u8g_i2c_stop();
  119. }
  120. else {
  121. /* enable, do nothing: any byte writing will trigger the i2c start */
  122. }
  123. break;
  124. case U8G_COM_MSG_WRITE_BYTE:
  125. //u8g->pin_list[U8G_PI_SET_A0] = 1;
  126. //if (u8g_com_arduino_ssd_start_sequence(u8g) == 0)
  127. // return u8g_i2c_stop(), 0;
  128. if (u8g_i2c_send_byte(arg_val) == 0) {
  129. u8g_i2c_stop();
  130. return 0;
  131. }
  132. // u8g_i2c_stop();
  133. break;
  134. case U8G_COM_MSG_WRITE_SEQ: {
  135. //u8g->pin_list[U8G_PI_SET_A0] = 1;
  136. if (u8g_com_ssd_I2C_start_sequence(u8g) == 0) {
  137. u8g_i2c_stop();
  138. return 0;
  139. }
  140. uint8_t *ptr = (uint8_t *)arg_ptr;
  141. while (arg_val > 0) {
  142. if (u8g_i2c_send_byte(*ptr++) == 0) {
  143. u8g_i2c_stop();
  144. return 0;
  145. }
  146. arg_val--;
  147. }
  148. }
  149. // u8g_i2c_stop();
  150. break;
  151. case U8G_COM_MSG_WRITE_SEQ_P: {
  152. //u8g->pin_list[U8G_PI_SET_A0] = 1;
  153. if (u8g_com_ssd_I2C_start_sequence(u8g) == 0) {
  154. u8g_i2c_stop();
  155. return 0;
  156. }
  157. uint8_t *ptr = (uint8_t *)arg_ptr;
  158. while (arg_val > 0) {
  159. if (u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0)
  160. return 0;
  161. ptr++;
  162. arg_val--;
  163. }
  164. }
  165. // u8g_i2c_stop();
  166. break;
  167. case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
  168. u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
  169. u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */
  170. u8g_i2c_start(0); // send slave address and write bit
  171. u8g_i2c_send_byte(arg_val ? 0x40 : 0x80); // Write to ? Graphics DRAM mode : Command mode
  172. break;
  173. } // switch
  174. return 1;
  175. }
  176. #endif // HAS_GRAPHICAL_LCD
  177. #endif // TARGET_LPC1768