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.

89 lines
1.6 KiB

  1. /**
  2. * @file spi.h
  3. * Class declaration for SPI helper files
  4. */
  5. /**
  6. * Example of spi.h class declaration for SPI portability
  7. *
  8. * @defgroup Porting_SPI Porting: SPI
  9. *
  10. *
  11. * @{
  12. */
  13. #ifndef __XMEGASPI_H__
  14. #define __XMEGASPI_H__
  15. #include <avr/io.h>
  16. #include <stdint.h>
  17. //#include <string.h>
  18. //#include <unistd.h>
  19. //#include <stdio.h>
  20. //#include <stdlib.h>
  21. //#include <getopt.h>
  22. //#include <fcntl.h>
  23. //#include <sys/ioctl.h>
  24. //#include <inttypes.h>
  25. //#include <linux/types.h>
  26. //#include <linux/spi/spidev.h>
  27. #define SPI_SS_bm (1<<4) /* SPI SS pin mask 4 */
  28. #define SPI_MOSI_bm (1<<5) /* SPI MOSI pin mask 5 */
  29. #define SPI_MISO_bm (1<<6) /* SPI MISO pin mask 6 */
  30. #define SPI_SCK_bm (1<<7) /* SPI SCK pin mask 7 */
  31. using namespace std;
  32. class SPI {
  33. public:
  34. /**
  35. * SPI constructor
  36. */
  37. SPI();
  38. /**
  39. * Start SPI
  40. * @param port is the SPI port (XMEGA_SPI_PORT_C for SPI on PORTC, XMEGA_SPI_PORT_D on PORTD etc).
  41. */
  42. void begin(uint8_t port);
  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. virtual ~SPI();
  63. private:
  64. /** Default SPI device */
  65. SPI_t * device;
  66. /* Port of the SPI */
  67. PORT_t * port;
  68. void init();
  69. };
  70. #endif /*__XMEGASPI_H__*/
  71. /*@}*/