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_com_HAL_DUE_sw_spi_shared.cpp 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. /**
  23. * Based on u8g_com_st7920_hw_spi.c
  24. *
  25. * Universal 8bit Graphics Library
  26. *
  27. * Copyright (c) 2011, olikraus@gmail.com
  28. * All rights reserved.
  29. *
  30. * Redistribution and use in source and binary forms, with or without modification,
  31. * are permitted provided that the following conditions are met:
  32. *
  33. * * Redistributions of source code must retain the above copyright notice, this list
  34. * of conditions and the following disclaimer.
  35. *
  36. * * Redistributions in binary form must reproduce the above copyright notice, this
  37. * list of conditions and the following disclaimer in the documentation and/or other
  38. * materials provided with the distribution.
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  41. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  42. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  43. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  44. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  45. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  46. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  47. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  48. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  49. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  50. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  51. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  52. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  53. */
  54. #ifdef ARDUINO_ARCH_SAM
  55. #include "../../../inc/MarlinConfigPre.h"
  56. #if HAS_GRAPHICAL_LCD
  57. #include "../../shared/Delay.h"
  58. #include <U8glib.h>
  59. #include "u8g_com_HAL_DUE_sw_spi_shared.h"
  60. void u8g_SetPIOutput_DUE(u8g_t *u8g, uint8_t pin_index) {
  61. PIO_Configure(g_APinDescription[u8g->pin_list[pin_index]].pPort, PIO_OUTPUT_1,
  62. g_APinDescription[u8g->pin_list[pin_index]].ulPin, g_APinDescription[u8g->pin_list[pin_index]].ulPinConfiguration); // OUTPUT
  63. }
  64. void u8g_SetPILevel_DUE(u8g_t *u8g, uint8_t pin_index, uint8_t level) {
  65. volatile Pio* port = g_APinDescription[u8g->pin_list[pin_index]].pPort;
  66. uint32_t mask = g_APinDescription[u8g->pin_list[pin_index]].ulPin;
  67. if (level) port->PIO_SODR = mask; else port->PIO_CODR = mask;
  68. }
  69. Pio *SCK_pPio, *MOSI_pPio;
  70. uint32_t SCK_dwMask, MOSI_dwMask;
  71. void u8g_spiSend_sw_DUE_mode_0(uint8_t val) { // 3MHz
  72. LOOP_L_N(i, 8) {
  73. if (val & 0x80)
  74. MOSI_pPio->PIO_SODR = MOSI_dwMask;
  75. else
  76. MOSI_pPio->PIO_CODR = MOSI_dwMask;
  77. DELAY_NS(48);
  78. SCK_pPio->PIO_SODR = SCK_dwMask;
  79. DELAY_NS(905);
  80. val <<= 1;
  81. SCK_pPio->PIO_CODR = SCK_dwMask;
  82. }
  83. }
  84. void u8g_spiSend_sw_DUE_mode_3(uint8_t val) { // 3.5MHz
  85. LOOP_L_N(i, 8) {
  86. SCK_pPio->PIO_CODR = SCK_dwMask;
  87. DELAY_NS(50);
  88. if (val & 0x80)
  89. MOSI_pPio->PIO_SODR = MOSI_dwMask;
  90. else
  91. MOSI_pPio->PIO_CODR = MOSI_dwMask;
  92. val <<= 1;
  93. DELAY_NS(10);
  94. SCK_pPio->PIO_SODR = SCK_dwMask;
  95. DELAY_NS(70);
  96. }
  97. }
  98. #endif // HAS_GRAPHICAL_LCD
  99. #endif // ARDUINO_ARCH_SAM