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.

tft_spi.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #else
  28. #error SPI TFT is currently only supported on STM32F1 and STM32F4 hardware.
  29. #endif
  30. #ifndef LCD_READ_ID
  31. #define LCD_READ_ID 0x04 // Read display identification information (0xD3 on ILI9341)
  32. #endif
  33. #ifndef LCD_READ_ID4
  34. #define LCD_READ_ID4 0xD3 // Read display identification information (0xD3 on ILI9341)
  35. #endif
  36. #define DATASIZE_8BIT SPI_DATASIZE_8BIT
  37. #define DATASIZE_16BIT SPI_DATASIZE_16BIT
  38. #define TFT_IO_DRIVER TFT_SPI
  39. class TFT_SPI {
  40. private:
  41. static SPI_HandleTypeDef SPIx;
  42. static uint32_t ReadID(uint16_t Reg);
  43. static void Transmit(uint16_t Data);
  44. static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);
  45. #if ENABLED(USE_SPI_DMA_TC)
  46. static void TransmitDMA_IT(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);
  47. #endif
  48. public:
  49. static DMA_HandleTypeDef DMAtx;
  50. static void Init();
  51. static uint32_t GetID();
  52. static bool isBusy();
  53. static void Abort();
  54. static void DataTransferBegin(uint16_t DataWidth = DATASIZE_16BIT);
  55. static void DataTransferEnd() { WRITE(TFT_CS_PIN, HIGH); };
  56. static void DataTransferAbort();
  57. static void WriteData(uint16_t Data) { Transmit(Data); }
  58. static void WriteReg(uint16_t Reg) { WRITE(TFT_A0_PIN, LOW); Transmit(Reg); WRITE(TFT_A0_PIN, HIGH); }
  59. static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_MINC_ENABLE, Data, Count); }
  60. #if ENABLED(USE_SPI_DMA_TC)
  61. static void WriteSequenceIT(uint16_t *Data, uint16_t Count) { TransmitDMA_IT(DMA_MINC_ENABLE, Data, Count); }
  62. #endif
  63. static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); }
  64. static void WriteMultiple(uint16_t Color, uint32_t Count) {
  65. static uint16_t Data; Data = Color;
  66. while (Count > 0) {
  67. TransmitDMA(DMA_MINC_DISABLE, &Data, Count > 0xFFFF ? 0xFFFF : Count);
  68. Count = Count > 0xFFFF ? Count - 0xFFFF : 0;
  69. }
  70. }
  71. };