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.

84 lines
1.7 KiB

  1. /*
  2. * TMRh20 2015
  3. * SPI layer for RF24 <-> BCM2835
  4. */
  5. /**
  6. * @file spi.h
  7. * \cond HIDDEN_SYMBOLS
  8. * Class declaration for SPI helper files
  9. */
  10. #ifndef _SPI_H_INCLUDED
  11. #define _SPI_H_INCLUDED
  12. #include <stdio.h>
  13. #include "bcm2835.h"
  14. #include "interrupt.h"
  15. #define SPI_HAS_TRANSACTION
  16. #define MSBFIRST BCM2835_SPI_BIT_ORDER_MSBFIRST
  17. #define SPI_MODE0 BCM2835_SPI_MODE0
  18. #define RF24_SPI_SPEED BCM2835_SPI_SPEED_8MHZ
  19. class SPISettings {
  20. public:
  21. SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) {
  22. init(clock,bitOrder,dataMode);
  23. }
  24. SPISettings() { init(RF24_SPI_SPEED, MSBFIRST, SPI_MODE0); }
  25. uint32_t clck;
  26. uint8_t border;
  27. uint8_t dmode;
  28. private:
  29. void init(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) {
  30. clck = clock;
  31. border = bitOrder;
  32. dmode = dataMode;
  33. }
  34. friend class SPIClass;
  35. };
  36. class SPI {
  37. public:
  38. SPI();
  39. virtual ~SPI();
  40. inline static uint8_t transfer(uint8_t _data);
  41. inline static void transfernb(char* tbuf, char* rbuf, uint32_t len);
  42. inline static void transfern(char* buf, uint32_t len);
  43. static void begin(int busNo);
  44. static void end();
  45. static void setBitOrder(uint8_t bit_order);
  46. static void setDataMode(uint8_t data_mode);
  47. static void setClockDivider(uint16_t spi_speed);
  48. static void chipSelect(int csn_pin);
  49. static void beginTransaction(SPISettings settings);
  50. static void endTransaction();
  51. };
  52. uint8_t SPI::transfer(uint8_t _data) {
  53. uint8_t data = bcm2835_spi_transfer(_data);
  54. return data;
  55. }
  56. void SPI::transfernb(char* tbuf, char* rbuf, uint32_t len){
  57. bcm2835_spi_transfernb( tbuf, rbuf, len);
  58. }
  59. void SPI::transfern(char* buf, uint32_t len)
  60. {
  61. transfernb(buf, buf, len);
  62. }
  63. /**
  64. * \endcond
  65. */
  66. #endif