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.

xpt2046.h 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #pragma once
  20. #include "../../../inc/MarlinConfig.h"
  21. #if ENABLED(TOUCH_BUTTONS_HW_SPI)
  22. #include <SPI.h>
  23. #endif
  24. #ifndef TOUCH_MISO_PIN
  25. #define TOUCH_MISO_PIN SD_MISO_PIN
  26. #endif
  27. #ifndef TOUCH_MOSI_PIN
  28. #define TOUCH_MOSI_PIN SD_MOSI_PIN
  29. #endif
  30. #ifndef TOUCH_SCK_PIN
  31. #define TOUCH_SCK_PIN SD_SCK_PIN
  32. #endif
  33. #ifndef TOUCH_CS_PIN
  34. #define TOUCH_CS_PIN SD_SS_PIN
  35. #endif
  36. #ifndef TOUCH_INT_PIN
  37. #define TOUCH_INT_PIN -1
  38. #endif
  39. #define XPT2046_DFR_MODE 0x00
  40. #define XPT2046_SER_MODE 0x04
  41. #define XPT2046_CONTROL 0x80
  42. enum XPTCoordinate : uint8_t {
  43. XPT2046_X = 0x10 | XPT2046_CONTROL | XPT2046_DFR_MODE,
  44. XPT2046_Y = 0x50 | XPT2046_CONTROL | XPT2046_DFR_MODE,
  45. XPT2046_Z1 = 0x30 | XPT2046_CONTROL | XPT2046_DFR_MODE,
  46. XPT2046_Z2 = 0x40 | XPT2046_CONTROL | XPT2046_DFR_MODE,
  47. };
  48. #if !defined(XPT2046_Z1_THRESHOLD)
  49. #define XPT2046_Z1_THRESHOLD 10
  50. #endif
  51. class XPT2046 {
  52. private:
  53. static bool isBusy() { return false; }
  54. static uint16_t getRawData(const XPTCoordinate coordinate);
  55. static bool isTouched();
  56. static inline void DataTransferBegin();
  57. static inline void DataTransferEnd();
  58. #if ENABLED(TOUCH_BUTTONS_HW_SPI)
  59. static uint16_t HardwareIO(uint16_t data);
  60. #endif
  61. static uint16_t SoftwareIO(uint16_t data);
  62. static uint16_t IO(uint16_t data = 0);
  63. public:
  64. #if ENABLED(TOUCH_BUTTONS_HW_SPI)
  65. static SPIClass SPIx;
  66. #endif
  67. static void Init();
  68. static bool getRawPoint(int16_t *x, int16_t *y);
  69. };