PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

96 lines
4.5KB

  1. // RHNRFSPIDriver.h
  2. // Author: Mike McCauley (mikem@airspayce.com)
  3. // Copyright (C) 2014 Mike McCauley
  4. // $Id: RHNRFSPIDriver.h,v 1.3 2015/12/16 04:55:33 mikem Exp $
  5. #ifndef RHNRFSPIDriver_h
  6. #define RHNRFSPIDriver_h
  7. #include <RHGenericDriver.h>
  8. #include <RHHardwareSPI.h>
  9. class RHGenericSPI;
  10. /////////////////////////////////////////////////////////////////////
  11. /// \class RHNRFSPIDriver RHNRFSPIDriver.h <RHNRFSPIDriver.h>
  12. /// \brief Base class for a RadioHead driver that use the SPI bus
  13. /// to communicate with its transport hardware.
  14. ///
  15. /// This class can be subclassed by Drivers that require to use the SPI bus.
  16. /// It can be configured to use either the RHHardwareSPI class (if there is one available on the platform)
  17. /// of the bitbanged RHSoftwareSPI class. The dfault behaviour is to use a pre-instantiated built-in RHHardwareSPI
  18. /// interface.
  19. ///
  20. /// SPI bus access is protected by ATOMIC_BLOCK_START and ATOMIC_BLOCK_END, which will ensure interrupts
  21. /// are disabled during access.
  22. ///
  23. /// The read and write routines use SPI conventions as used by Nordic NRF radios and otehr devices,
  24. /// but these can be overriden
  25. /// in subclasses if necessary.
  26. ///
  27. /// Application developers are not expected to instantiate this class directly:
  28. /// it is for the use of Driver developers.
  29. class RHNRFSPIDriver : public RHGenericDriver
  30. {
  31. public:
  32. /// Constructor
  33. /// \param[in] slaveSelectPin The controller pin to use to select the desired SPI device. This pin will be driven LOW
  34. /// during SPI communications with the SPI device that uis iused by this Driver.
  35. /// \param[in] spi Reference to the SPI interface to use. The default is to use a default built-in Hardware interface.
  36. RHNRFSPIDriver(uint8_t slaveSelectPin = SS, RHGenericSPI& spi = hardware_spi);
  37. /// Initialise the Driver transport hardware and software.
  38. /// Make sure the Driver is properly configured before calling init().
  39. /// \return true if initialisation succeeded.
  40. bool init();
  41. /// Sends a single command to the device
  42. /// \param[in] command The command code to send to the device.
  43. /// \return Some devices return a status byte during the first data transfer. This byte is returned.
  44. /// it may or may not be meaningfule depending on the the type of device being accessed.
  45. uint8_t spiCommand(uint8_t command);
  46. /// Reads a single register from the SPI device
  47. /// \param[in] reg Register number
  48. /// \return The value of the register
  49. uint8_t spiRead(uint8_t reg);
  50. /// Writes a single byte to the SPI device
  51. /// \param[in] reg Register number
  52. /// \param[in] val The value to write
  53. /// \return Some devices return a status byte during the first data transfer. This byte is returned.
  54. /// it may or may not be meaningfule depending on the the type of device being accessed.
  55. uint8_t spiWrite(uint8_t reg, uint8_t val);
  56. /// Reads a number of consecutive registers from the SPI device using burst read mode
  57. /// \param[in] reg Register number of the first register
  58. /// \param[in] dest Array to write the register values to. Must be at least len bytes
  59. /// \param[in] len Number of bytes to read
  60. /// \return Some devices return a status byte during the first data transfer. This byte is returned.
  61. /// it may or may not be meaningfule depending on the the type of device being accessed.
  62. uint8_t spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len);
  63. /// Write a number of consecutive registers using burst write mode
  64. /// \param[in] reg Register number of the first register
  65. /// \param[in] src Array of new register values to write. Must be at least len bytes
  66. /// \param[in] len Number of bytes to write
  67. /// \return Some devices return a status byte during the first data transfer. This byte is returned.
  68. /// it may or may not be meaningfule depending on the the type of device being accessed.
  69. uint8_t spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len);
  70. /// Set or change the pin to be used for SPI slave select.
  71. /// This can be called at any time to change the
  72. /// pin that will be used for slave select in subsquent SPI operations.
  73. /// \param[in] slaveSelectPin The pin to use
  74. void setSlaveSelectPin(uint8_t slaveSelectPin);
  75. protected:
  76. /// Reference to the RHGenericSPI instance to use to trasnfer data with teh SPI device
  77. RHGenericSPI& _spi;
  78. /// The pin number of the Slave Select pin that is used to select the desired device.
  79. uint8_t _slaveSelectPin;
  80. };
  81. #endif