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.

buttons.h 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. #pragma once
  23. #include "../inc/MarlinConfig.h"
  24. #if ((!HAS_ADC_BUTTONS && IS_NEWPANEL) || BUTTONS_EXIST(EN1, EN2)) && !IS_TFTGLCD_PANEL
  25. #define HAS_ENCODER_WHEEL 1
  26. #endif
  27. #if HAS_ENCODER_WHEEL || ANY_BUTTON(ENC, BACK, UP, DWN, LFT, RT)
  28. #define HAS_DIGITAL_BUTTONS 1
  29. #endif
  30. #if !HAS_ADC_BUTTONS && (IS_RRW_KEYPAD || (HAS_WIRED_LCD && !IS_NEWPANEL))
  31. #define HAS_SHIFT_ENCODER 1
  32. #endif
  33. // I2C buttons must be read in the main thread
  34. #if ANY(LCD_I2C_VIKI, LCD_I2C_PANELOLU2, IS_TFTGLCD_PANEL)
  35. #define HAS_SLOW_BUTTONS 1
  36. #endif
  37. #if HAS_ENCODER_WHEEL
  38. #define ENCODER_PHASE_0 0
  39. #define ENCODER_PHASE_1 2
  40. #define ENCODER_PHASE_2 3
  41. #define ENCODER_PHASE_3 1
  42. #endif
  43. #if IS_RRW_KEYPAD
  44. #define BTN_OFFSET 0 // Bit offset into buttons for shift register values
  45. #define BLEN_KEYPAD_F3 0
  46. #define BLEN_KEYPAD_F2 1
  47. #define BLEN_KEYPAD_F1 2
  48. #define BLEN_KEYPAD_DOWN 3
  49. #define BLEN_KEYPAD_RIGHT 4
  50. #define BLEN_KEYPAD_MIDDLE 5
  51. #define BLEN_KEYPAD_UP 6
  52. #define BLEN_KEYPAD_LEFT 7
  53. #define EN_KEYPAD_F1 _BV(BTN_OFFSET + BLEN_KEYPAD_F1)
  54. #define EN_KEYPAD_F2 _BV(BTN_OFFSET + BLEN_KEYPAD_F2)
  55. #define EN_KEYPAD_F3 _BV(BTN_OFFSET + BLEN_KEYPAD_F3)
  56. #define EN_KEYPAD_DOWN _BV(BTN_OFFSET + BLEN_KEYPAD_DOWN)
  57. #define EN_KEYPAD_RIGHT _BV(BTN_OFFSET + BLEN_KEYPAD_RIGHT)
  58. #define EN_KEYPAD_MIDDLE _BV(BTN_OFFSET + BLEN_KEYPAD_MIDDLE)
  59. #define EN_KEYPAD_UP _BV(BTN_OFFSET + BLEN_KEYPAD_UP)
  60. #define EN_KEYPAD_LEFT _BV(BTN_OFFSET + BLEN_KEYPAD_LEFT)
  61. #define RRK(B) (keypad_buttons & (B))
  62. #ifdef EN_C
  63. #define BUTTON_CLICK() ((buttons & EN_C) || RRK(EN_KEYPAD_MIDDLE))
  64. #else
  65. #define BUTTON_CLICK() RRK(EN_KEYPAD_MIDDLE)
  66. #endif
  67. #endif
  68. #if EITHER(HAS_DIGITAL_BUTTONS, DWIN_CREALITY_LCD)
  69. // Wheel spin pins where BA is 00, 10, 11, 01 (1 bit always changes)
  70. #define BLEN_A 0
  71. #define BLEN_B 1
  72. #define EN_A _BV(BLEN_A)
  73. #define EN_B _BV(BLEN_B)
  74. #define _BUTTON_PRESSED(BN) !READ(BTN_##BN)
  75. #if BUTTON_EXISTS(ENC) || HAS_TOUCH_BUTTONS
  76. #define BLEN_C 2
  77. #define EN_C _BV(BLEN_C)
  78. #endif
  79. #if ENABLED(LCD_I2C_VIKI)
  80. #include <LiquidTWI2.h>
  81. #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
  82. // button and encoder bit positions within 'buttons'
  83. #define B_LE (BUTTON_LEFT << B_I2C_BTN_OFFSET) // The remaining normalized buttons are all read via I2C
  84. #define B_UP (BUTTON_UP << B_I2C_BTN_OFFSET)
  85. #define B_MI (BUTTON_SELECT << B_I2C_BTN_OFFSET)
  86. #define B_DW (BUTTON_DOWN << B_I2C_BTN_OFFSET)
  87. #define B_RI (BUTTON_RIGHT << B_I2C_BTN_OFFSET)
  88. #if BUTTON_EXISTS(ENC) // The pause/stop/restart button is connected to BTN_ENC when used
  89. #define B_ST (EN_C) // Map the pause/stop/resume button into its normalized functional name
  90. #define BUTTON_CLICK() (buttons & (B_MI|B_RI|B_ST)) // Pause/stop also acts as click until a proper pause/stop is implemented.
  91. #else
  92. #define BUTTON_CLICK() (buttons & (B_MI|B_RI))
  93. #endif
  94. // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
  95. #elif ENABLED(LCD_I2C_PANELOLU2)
  96. #if !BUTTON_EXISTS(ENC) // Use I2C if not directly connected to a pin
  97. #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
  98. #define B_MI (PANELOLU2_ENCODER_C << B_I2C_BTN_OFFSET) // requires LiquidTWI2 library v1.2.3 or later
  99. #define BUTTON_CLICK() (buttons & B_MI)
  100. #endif
  101. #endif
  102. #else
  103. #undef BUTTON_EXISTS
  104. #define BUTTON_EXISTS(...) false
  105. // Dummy button, never pressed
  106. #define _BUTTON_PRESSED(BN) false
  107. // Shift register bits correspond to buttons:
  108. #define BL_LE 7 // Left
  109. #define BL_UP 6 // Up
  110. #define BL_MI 5 // Middle
  111. #define BL_DW 4 // Down
  112. #define BL_RI 3 // Right
  113. #define BL_ST 2 // Red Button
  114. #define B_LE _BV(BL_LE)
  115. #define B_UP _BV(BL_UP)
  116. #define B_MI _BV(BL_MI)
  117. #define B_DW _BV(BL_DW)
  118. #define B_RI _BV(BL_RI)
  119. #define B_ST _BV(BL_ST)
  120. #ifndef BUTTON_CLICK
  121. #define BUTTON_CLICK() (buttons & (B_MI|B_ST))
  122. #endif
  123. #endif
  124. #ifndef EN_A
  125. #define EN_A 0
  126. #endif
  127. #ifndef EN_B
  128. #define EN_B 0
  129. #endif
  130. #ifndef EN_C
  131. #define EN_C 0
  132. #endif
  133. #if BUTTON_EXISTS(BACK) || EITHER(HAS_TOUCH_BUTTONS, IS_TFTGLCD_PANEL)
  134. #define BLEN_D 3
  135. #define EN_D _BV(BLEN_D)
  136. #else
  137. #define EN_D 0
  138. #endif
  139. #define BUTTON_PRESSED(BN) (_BUTTON_PRESSED_##BN)
  140. #if BUTTON_EXISTS(EN1)
  141. #define _BUTTON_PRESSED_EN1 _BUTTON_PRESSED(EN1)
  142. #else
  143. #define _BUTTON_PRESSED_EN1 false
  144. #endif
  145. #if BUTTON_EXISTS(EN2)
  146. #define _BUTTON_PRESSED_EN2 _BUTTON_PRESSED(EN2)
  147. #else
  148. #define _BUTTON_PRESSED_EN2 false
  149. #endif
  150. #if BUTTON_EXISTS(ENC_EN)
  151. #define _BUTTON_PRESSED_ENC_EN _BUTTON_PRESSED(ENC_EN)
  152. #else
  153. #define _BUTTON_PRESSED_ENC_EN false
  154. #endif
  155. #if BUTTON_EXISTS(ENC)
  156. #define _BUTTON_PRESSED_ENC _BUTTON_PRESSED(ENC)
  157. #else
  158. #define _BUTTON_PRESSED_ENC false
  159. #endif
  160. #if BUTTON_EXISTS(UP)
  161. #define _BUTTON_PRESSED_UP _BUTTON_PRESSED(UP)
  162. #else
  163. #define _BUTTON_PRESSED_UP false
  164. #endif
  165. #if BUTTON_EXISTS(DWN)
  166. #define _BUTTON_PRESSED_DWN _BUTTON_PRESSED(DWN)
  167. #else
  168. #define _BUTTON_PRESSED_DWN false
  169. #endif
  170. #if BUTTON_EXISTS(LFT)
  171. #define _BUTTON_PRESSED_LFT _BUTTON_PRESSED(LFT)
  172. #else
  173. #define _BUTTON_PRESSED_LFT false
  174. #endif
  175. #if BUTTON_EXISTS(RT)
  176. #define _BUTTON_PRESSED_RT _BUTTON_PRESSED(RT)
  177. #else
  178. #define _BUTTON_PRESSED_RT false
  179. #endif
  180. #if BUTTON_EXISTS(BACK)
  181. #define _BUTTON_PRESSED_BACK _BUTTON_PRESSED(BACK)
  182. #else
  183. #define _BUTTON_PRESSED_BACK false
  184. #endif
  185. #ifndef BUTTON_CLICK
  186. #if EN_C > 0
  187. #define BUTTON_CLICK() (buttons & EN_C)
  188. #else
  189. #define BUTTON_CLICK() false
  190. #endif
  191. #endif
  192. #if EN_D > 0
  193. #define LCD_BACK_CLICKED() (buttons & EN_D)
  194. #else
  195. #define LCD_BACK_CLICKED() false
  196. #endif