My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

spi.h 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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. #ifndef __SPI_H__
  23. #define __SPI_H__
  24. #include <stdint.h>
  25. #include "softspi.h"
  26. template<uint8_t MisoPin, uint8_t MosiPin, uint8_t SckPin>
  27. class Spi {
  28. static SoftSPI<MisoPin, MosiPin, SckPin> softSpi;
  29. public:
  30. inline __attribute__((always_inline))
  31. static void init() {
  32. softSpi.begin();
  33. }
  34. inline __attribute__((always_inline))
  35. static void send(uint8_t data) {
  36. softSpi.send(data);
  37. }
  38. inline __attribute__((always_inline))
  39. static uint8_t receive() {
  40. return softSpi.receive();
  41. }
  42. };
  43. //hardware spi
  44. template<>
  45. class Spi<MISO_PIN, MOSI_PIN, SCK_PIN> {
  46. public:
  47. inline __attribute__((always_inline))
  48. static void init() {
  49. OUT_WRITE(SCK_PIN, LOW);
  50. OUT_WRITE(MOSI_PIN, HIGH);
  51. SET_INPUT(MISO_PIN);
  52. WRITE(MISO_PIN, HIGH);
  53. }
  54. inline __attribute__((always_inline))
  55. static uint8_t receive() {
  56. SPDR = 0;
  57. for (;!TEST(SPSR, SPIF););
  58. return SPDR;
  59. }
  60. };
  61. #endif