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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifdef STM32F1xx
  24. #include <stm32f1xx_hal.h>
  25. #elif defined(STM32F4xx)
  26. #include <stm32f4xx_hal.h>
  27. #endif
  28. #include "../../../inc/MarlinConfig.h"
  29. // Not using regular SPI interface by default to avoid SPI mode conflicts with other SPI devices
  30. #if !PIN_EXISTS(TOUCH_MISO)
  31. #error "TOUCH_MISO_PIN is not defined."
  32. #elif !PIN_EXISTS(TOUCH_MOSI)
  33. #error "TOUCH_MOSI_PIN is not defined."
  34. #elif !PIN_EXISTS(TOUCH_SCK)
  35. #error "TOUCH_SCK_PIN is not defined."
  36. #elif !PIN_EXISTS(TOUCH_CS)
  37. #error "TOUCH_CS_PIN is not defined."
  38. #endif
  39. #ifndef TOUCH_INT_PIN
  40. #define TOUCH_INT_PIN -1
  41. #endif
  42. #define XPT2046_DFR_MODE 0x00
  43. #define XPT2046_SER_MODE 0x04
  44. #define XPT2046_CONTROL 0x80
  45. enum XPTCoordinate : uint8_t {
  46. XPT2046_X = 0x10 | XPT2046_CONTROL | XPT2046_DFR_MODE,
  47. XPT2046_Y = 0x50 | XPT2046_CONTROL | XPT2046_DFR_MODE,
  48. XPT2046_Z1 = 0x30 | XPT2046_CONTROL | XPT2046_DFR_MODE,
  49. XPT2046_Z2 = 0x40 | XPT2046_CONTROL | XPT2046_DFR_MODE,
  50. };
  51. #ifndef XPT2046_Z1_THRESHOLD
  52. #define XPT2046_Z1_THRESHOLD 10
  53. #endif
  54. class XPT2046 {
  55. private:
  56. static SPI_HandleTypeDef SPIx;
  57. static bool isBusy() { return false; }
  58. static uint16_t getRawData(const XPTCoordinate coordinate);
  59. static bool isTouched();
  60. static inline void DataTransferBegin() { if (SPIx.Instance) { HAL_SPI_Init(&SPIx); } WRITE(TOUCH_CS_PIN, LOW); };
  61. static inline void DataTransferEnd() { WRITE(TOUCH_CS_PIN, HIGH); };
  62. static uint16_t HardwareIO(uint16_t data);
  63. static uint16_t SoftwareIO(uint16_t data);
  64. static uint16_t IO(uint16_t data = 0) { return SPIx.Instance ? HardwareIO(data) : SoftwareIO(data); }
  65. public:
  66. static void Init();
  67. static bool getRawPoint(int16_t *x, int16_t *y);
  68. };