PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
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.

74 lines
2.8KB

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