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.

HAL_SPI.h 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #pragma once
  23. /**
  24. * HAL/HAL_SPI.h
  25. * Core Marlin definitions for SPI, implemented in the HALs
  26. */
  27. #include <stdint.h>
  28. /**
  29. * SPI speed where 0 <= index <= 6
  30. *
  31. * Approximate rates :
  32. *
  33. * 0 : 8 - 10 MHz
  34. * 1 : 4 - 5 MHz
  35. * 2 : 2 - 2.5 MHz
  36. * 3 : 1 - 1.25 MHz
  37. * 4 : 500 - 625 kHz
  38. * 5 : 250 - 312 kHz
  39. * 6 : 125 - 156 kHz
  40. *
  41. * On AVR, actual speed is F_CPU/2^(1 + index).
  42. * On other platforms, speed should be in range given above where possible.
  43. */
  44. #define SPI_FULL_SPEED 0 // Set SCK to max rate
  45. #define SPI_HALF_SPEED 1 // Set SCK rate to half of max rate
  46. #define SPI_QUARTER_SPEED 2 // Set SCK rate to quarter of max rate
  47. #define SPI_EIGHTH_SPEED 3 // Set SCK rate to 1/8 of max rate
  48. #define SPI_SIXTEENTH_SPEED 4 // Set SCK rate to 1/16 of max rate
  49. #define SPI_SPEED_5 5 // Set SCK rate to 1/32 of max rate
  50. #define SPI_SPEED_6 6 // Set SCK rate to 1/64 of max rate
  51. // Standard SPI functions
  52. /** Initialize SPI bus */
  53. void spiBegin(void);
  54. /** Configure SPI for specified SPI speed */
  55. void spiInit(uint8_t spiRate);
  56. /** Write single byte to SPI */
  57. void spiSend(uint8_t b);
  58. /** Read single byte from SPI */
  59. uint8_t spiRec(void);
  60. /** Read from SPI into buffer */
  61. void spiRead(uint8_t* buf, uint16_t nbyte);
  62. /** Write token and then write from 512 byte buffer to SPI (for SD card) */
  63. void spiSendBlock(uint8_t token, const uint8_t* buf);
  64. /** Begin SPI transaction, set clock, bit order, data mode */
  65. void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode);