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_shared_hw_spi.cpp 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /*
  23. based on u8g_com_msp430_hw_spi.c
  24. Universal 8bit Graphics Library
  25. Copyright (c) 2012, olikraus@gmail.com
  26. All rights reserved.
  27. Redistribution and use in source and binary forms, with or without modification,
  28. are permitted provided that the following conditions are met:
  29. * Redistributions of source code must retain the above copyright notice, this list
  30. of conditions and the following disclaimer.
  31. * Redistributions in binary form must reproduce the above copyright notice, this
  32. list of conditions and the following disclaimer in the documentation and/or other
  33. materials provided with the distribution.
  34. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  35. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  36. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  37. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  39. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  41. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  43. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  44. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  45. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  46. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. */
  48. #ifdef __SAM3X8E__
  49. #include "../../inc/MarlinConfigPre.h"
  50. #if HAS_GRAPHICAL_LCD
  51. #include <U8glib.h>
  52. #include "../../Marlin.h"
  53. #define SPI_FULL_SPEED 0
  54. #define SPI_HALF_SPEED 1
  55. #define SPI_QUARTER_SPEED 2
  56. #define SPI_EIGHTH_SPEED 3
  57. #define SPI_SIXTEENTH_SPEED 4
  58. #define SPI_SPEED_5 5
  59. #define SPI_SPEED_6 6
  60. void spiBegin();
  61. void spiInit(uint8_t spiRate);
  62. void spiSend(uint8_t b);
  63. void spiSend(const uint8_t* buf, size_t n);
  64. #include "../shared/Marduino.h"
  65. #include "fastio_Due.h"
  66. void u8g_SetPIOutput_DUE_hw_spi(u8g_t *u8g, uint8_t pin_index) {
  67. PIO_Configure(g_APinDescription[u8g->pin_list[pin_index]].pPort, PIO_OUTPUT_1,
  68. g_APinDescription[u8g->pin_list[pin_index]].ulPin, g_APinDescription[u8g->pin_list[pin_index]].ulPinConfiguration); // OUTPUT
  69. }
  70. void u8g_SetPILevel_DUE_hw_spi(u8g_t *u8g, uint8_t pin_index, uint8_t level) {
  71. volatile Pio* port = g_APinDescription[u8g->pin_list[pin_index]].pPort;
  72. uint32_t mask = g_APinDescription[u8g->pin_list[pin_index]].ulPin;
  73. if (level) port->PIO_SODR = mask;
  74. else port->PIO_CODR = mask;
  75. }
  76. uint8_t u8g_com_HAL_DUE_shared_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
  77. switch (msg) {
  78. case U8G_COM_MSG_STOP:
  79. break;
  80. case U8G_COM_MSG_INIT:
  81. u8g_SetPILevel_DUE_hw_spi(u8g, U8G_PI_CS, 1);
  82. u8g_SetPILevel_DUE_hw_spi(u8g, U8G_PI_A0, 1);
  83. u8g_SetPIOutput_DUE_hw_spi(u8g, U8G_PI_CS);
  84. u8g_SetPIOutput_DUE_hw_spi(u8g, U8G_PI_A0);
  85. u8g_Delay(5);
  86. spiBegin();
  87. #ifndef SPI_SPEED
  88. #define SPI_SPEED SPI_FULL_SPEED // use same SPI speed as SD card
  89. #endif
  90. spiInit(2);
  91. break;
  92. case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
  93. u8g_SetPILevel_DUE_hw_spi(u8g, U8G_PI_A0, arg_val);
  94. break;
  95. case U8G_COM_MSG_CHIP_SELECT:
  96. u8g_SetPILevel_DUE_hw_spi(u8g, U8G_PI_CS, (arg_val ? 0 : 1));
  97. break;
  98. case U8G_COM_MSG_RESET:
  99. break;
  100. case U8G_COM_MSG_WRITE_BYTE:
  101. spiSend((uint8_t)arg_val);
  102. break;
  103. case U8G_COM_MSG_WRITE_SEQ: {
  104. uint8_t *ptr = (uint8_t*) arg_ptr;
  105. while (arg_val > 0) {
  106. spiSend(*ptr++);
  107. arg_val--;
  108. }
  109. }
  110. break;
  111. case U8G_COM_MSG_WRITE_SEQ_P: {
  112. uint8_t *ptr = (uint8_t*) arg_ptr;
  113. while (arg_val > 0) {
  114. spiSend(*ptr++);
  115. arg_val--;
  116. }
  117. }
  118. break;
  119. }
  120. return 1;
  121. }
  122. #endif // HAS_GRAPHICAL_LCD
  123. #endif //__SAM3X8E__