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.

u8g_esp32_spi.cpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2022 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. * Copypaste of SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. *
  23. */
  24. #ifdef ARDUINO_ARCH_ESP32
  25. #include "../../inc/MarlinConfig.h"
  26. #if EITHER(MKS_MINI_12864, FYSETC_MINI_12864_2_1)
  27. #include <U8glib-HAL.h>
  28. #include "../shared/HAL_SPI.h"
  29. #include "HAL.h"
  30. #include "SPI.h"
  31. #if ENABLED(SDSUPPORT)
  32. #include "../../sd/cardreader.h"
  33. #if ENABLED(ESP3D_WIFISUPPORT)
  34. #include "sd_ESP32.h"
  35. #endif
  36. #endif
  37. static SPISettings spiConfig;
  38. #ifndef LCD_SPI_SPEED
  39. #ifdef SD_SPI_SPEED
  40. #define LCD_SPI_SPEED SD_SPI_SPEED // Assume SPI speed shared with SD
  41. #else
  42. #define LCD_SPI_SPEED SPI_FULL_SPEED // Use full speed if SD speed is not supplied
  43. #endif
  44. #endif
  45. uint8_t u8g_eps_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
  46. static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
  47. #if ENABLED(PAUSE_LCD_FOR_BUSY_SD)
  48. if (card.flag.saving || card.flag.logging || TERN0(ESP3D_WIFISUPPORT, sd_busy_lock == true)) return 0;
  49. #endif
  50. if (msgInitCount) {
  51. if (msg == U8G_COM_MSG_INIT) msgInitCount--;
  52. if (msgInitCount) return -1;
  53. }
  54. switch (msg) {
  55. case U8G_COM_MSG_STOP: break;
  56. case U8G_COM_MSG_INIT:
  57. OUT_WRITE(DOGLCD_CS, HIGH);
  58. OUT_WRITE(DOGLCD_A0, HIGH);
  59. OUT_WRITE(LCD_RESET_PIN, HIGH);
  60. u8g_Delay(5);
  61. spiBegin();
  62. spiInit(LCD_SPI_SPEED);
  63. break;
  64. case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
  65. WRITE(DOGLCD_A0, arg_val ? HIGH : LOW);
  66. break;
  67. case U8G_COM_MSG_CHIP_SELECT: /* arg_val == 0 means HIGH level of U8G_PI_CS */
  68. WRITE(DOGLCD_CS, arg_val ? LOW : HIGH);
  69. break;
  70. case U8G_COM_MSG_RESET:
  71. WRITE(LCD_RESET_PIN, arg_val);
  72. break;
  73. case U8G_COM_MSG_WRITE_BYTE:
  74. spiSend((uint8_t)arg_val);
  75. break;
  76. case U8G_COM_MSG_WRITE_SEQ:
  77. uint8_t *ptr = (uint8_t*) arg_ptr;
  78. while (arg_val > 0) {
  79. spiSend(*ptr++);
  80. arg_val--;
  81. }
  82. break;
  83. }
  84. return 1;
  85. }
  86. #endif // EITHER(MKS_MINI_12864, FYSETC_MINI_12864_2_1)
  87. #endif // ARDUINO_ARCH_ESP32