Ein Roboter mit bürstenlosem Antrieb, differenzial und NRF24L01 Funk. Großflächig gebaut um ein großes Solarpanel aufzunehmen. https://gitlab.informatik.hs-fulda.de/fdai5253/roboter
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.

93 lines
1.5 KiB

  1. /*
  2. * File: spi.h
  3. * Author: Purinda Gunasekara <purinda@gmail.com>
  4. *
  5. * Created on 24 June 2012, 11:00 AM
  6. */
  7. #ifndef SPI_H
  8. #define SPI_H
  9. /**
  10. * @file spi.h
  11. * \cond HIDDEN_SYMBOLS
  12. * Class declaration for SPI helper files
  13. */
  14. /**
  15. * Example GPIO.h file
  16. *
  17. * @defgroup SPI SPI Example
  18. *
  19. * See RF24_arch_config.h for additional information
  20. * @{
  21. */
  22. #include <inttypes.h>
  23. #include <stdexcept>
  24. #ifndef RF24_SPIDEV_SPEED
  25. /* 8MHz as default */
  26. #define RF24_SPIDEV_SPEED 8000000
  27. #endif
  28. /** Specific excpetion for SPI errors */
  29. class SPIException : public std::runtime_error {
  30. public:
  31. explicit SPIException(const std::string& msg) : std::runtime_error(msg) { }
  32. };
  33. class SPI {
  34. public:
  35. /**
  36. * SPI constructor
  37. */
  38. SPI();
  39. /**
  40. * Start SPI
  41. */
  42. void begin(int busNo,uint32_t spi_speed=RF24_SPIDEV_SPEED);
  43. /**
  44. * Transfer a single byte
  45. * @param tx Byte to send
  46. * @return Data returned via spi
  47. */
  48. uint8_t transfer(uint8_t tx);
  49. /**
  50. * Transfer a buffer of data
  51. * @param tbuf Transmit buffer
  52. * @param rbuf Receive buffer
  53. * @param len Length of the data
  54. */
  55. void transfernb(char* tbuf, char* rbuf, uint32_t len);
  56. /**
  57. * Transfer a buffer of data without an rx buffer
  58. * @param buf Pointer to a buffer of data
  59. * @param len Length of the data
  60. */
  61. void transfern(char* buf, uint32_t len) {
  62. transfernb(buf, buf, len);
  63. }
  64. ~SPI();
  65. private:
  66. int fd;
  67. uint32_t _spi_speed;
  68. void init(uint32_t spi_speed=RF24_SPIDEV_SPEED);
  69. };
  70. /**
  71. * \endcond
  72. */
  73. /*@}*/
  74. #endif /* SPI_H */