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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 DMA_HandleTypeDef DMAtx;
  43. static uint32_t ReadID(uint16_t Reg);
  44. static void Transmit(uint16_t Data);
  45. static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);
  46. public:
  47. static void Init();
  48. static uint32_t GetID();
  49. static bool isBusy();
  50. static void Abort();
  51. static void DataTransferBegin(uint16_t DataWidth = DATASIZE_16BIT);
  52. static void DataTransferEnd() { WRITE(TFT_CS_PIN, HIGH); };
  53. static void DataTransferAbort();
  54. static void WriteData(uint16_t Data) { Transmit(Data); }
  55. static void WriteReg(uint16_t Reg) { WRITE(TFT_A0_PIN, LOW); Transmit(Reg); WRITE(TFT_A0_PIN, HIGH); }
  56. static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_MINC_ENABLE, Data, Count); }
  57. static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); }
  58. };