PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RHHardwareSPI1.h 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // RHHardwareSPI.h
  2. // Author: Mike McCauley (mikem@airspayce.com)
  3. // Copyright (C) 2011 Mike McCauley
  4. // Contributed by Joanna Rutkowska
  5. // $Id: RHHardwareSPI.h,v 1.9 2014/08/12 00:54:52 mikem Exp $
  6. #ifndef RHHardwareSPI1_h
  7. #define RHHardwareSPI1_h
  8. #if defined(__arm__) && defined(TEENSYDUINO) && (defined(KINETISL) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__)|| defined(__IMXRT1062__))
  9. #include <RHGenericSPI.h>
  10. /////////////////////////////////////////////////////////////////////
  11. /// \class RHHardwareSPI RHHardwareSPI.h <RHHardwareSPI.h>
  12. /// \brief Encapsulate a hardware SPI bus interface
  13. ///
  14. /// This concrete subclass of GenericSPIClass encapsulates the standard Arduino hardware and other
  15. /// hardware SPI interfaces.
  16. class RHHardwareSPI1 : public RHGenericSPI
  17. {
  18. #ifdef RH_HAVE_HARDWARE_SPI
  19. public:
  20. /// Constructor
  21. /// Creates an instance of a hardware SPI interface, using whatever SPI hardware is available on
  22. /// your processor platform. On Arduino and Uno32, uses SPI. On Maple, uses HardwareSPI.
  23. /// \param[in] frequency One of RHGenericSPI::Frequency to select the SPI bus frequency. The frequency
  24. /// is mapped to the closest available bus frequency on the platform.
  25. /// \param[in] bitOrder Select the SPI bus bit order, one of RHGenericSPI::BitOrderMSBFirst or
  26. /// RHGenericSPI::BitOrderLSBFirst.
  27. /// \param[in] dataMode Selects the SPI bus data mode. One of RHGenericSPI::DataMode
  28. RHHardwareSPI1(Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst, DataMode dataMode = DataMode0);
  29. /// Transfer a single octet to and from the SPI interface
  30. /// \param[in] data The octet to send
  31. /// \return The octet read from SPI while the data octet was sent
  32. uint8_t transfer(uint8_t data);
  33. // SPI Configuration methods
  34. /// Enable SPI interrupts
  35. /// This can be used in an SPI slave to indicate when an SPI message has been received
  36. /// It will cause the SPI_STC_vect interrupt vectr to be executed
  37. void attachInterrupt();
  38. /// Disable SPI interrupts
  39. /// This can be used to diable the SPI interrupt in slaves where that is supported.
  40. void detachInterrupt();
  41. /// Initialise the SPI library
  42. /// Call this after configuring the SPI interface and before using it to transfer data.
  43. /// Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.
  44. void begin();
  45. /// Disables the SPI bus (leaving pin modes unchanged).
  46. /// Call this after you have finished using the SPI interface.
  47. void end();
  48. #if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined(SPI_HAS_TRANSACTION)
  49. public:
  50. void beginTransaction();
  51. void endTransaction();
  52. SPISettings _settings;
  53. #endif
  54. #else
  55. // not supported on ATTiny etc
  56. uint8_t transfer(uint8_t data) {return 0;}
  57. void begin(){}
  58. void end(){}
  59. #endif
  60. };
  61. // Built in default instance
  62. extern RHHardwareSPI1 hardware_spi1;
  63. #else
  64. #error ("RadioHead SPI1 only supported on Teensy 3.5, 3.6, 4 and LC")
  65. #endif
  66. #endif