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.6KB

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