Templated Files for Platform Support¶
About General¶
16#ifndef __ARCH_CONFIG_H__
17#define __ARCH_CONFIG_H__
18
19#define RF24_LINUX
20
21#include <stddef.h>
22#include "spi.h"
23#include "gpio.h"
24#include "compatibility.h"
25#include <stdint.h>
26#include <stdio.h>
27#include <time.h>
28#include <string.h>
29#include <sys/time.h>
30
31#define _BV(x) (1 << (x))
32#define _SPI spi
33
34#undef SERIAL_DEBUG
35#ifdef SERIAL_DEBUG
36 #define IF_SERIAL_DEBUG(x) ({x;})
37#else
38 #define IF_SERIAL_DEBUG(x)
39#endif
40
41// Avoid spurious warnings
42#if 1
43 #if !defined(NATIVE) && defined(ARDUINO)
44 #undef PROGMEM
45 #define PROGMEM __attribute__(( section(".progmem.data") ))
46 #undef PSTR
47 #define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
48 #endif
49#endif
50
51typedef uint16_t prog_uint16_t;
52#define PSTR(x) (x)
53#define printf_P printf
54#define strlen_P strlen
55#define PROGMEM
56#define pgm_read_word(p) (*(p))
57#define PRIPSTR "%s"
58#define pgm_read_byte(p) (*(p))
59
60// Function, constant map as a result of migrating from Arduino
61#define LOW GPIO::OUTPUT_LOW
62#define HIGH GPIO::OUTPUT_HIGH
63#define INPUT GPIO::DIRECTION_IN
64#define OUTPUT GPIO::DIRECTION_OUT
65#define digitalWrite(pin, value) GPIO::write(pin, value)
66#define pinMode(pin, direction) GPIO::open(pin, direction)
67#define delay(milisec) __msleep(milisec)
68#define delayMicroseconds(usec) __usleep(usec)
69#define millis() __millis()
70
71#endif // __ARCH_CONFIG_H__
About Includes¶
6#ifndef __RF24_INCLUDES_H__
7#define __RF24_INCLUDES_H__
8
9/**
10 * Define a specific platform for this configuration. For example.
11 * our platform is named "BBB".
12 */
13#define RF24_BBB
14
15/**
16 * Load the correct configuration for this platform
17 */
18#include "BBB/RF24_arch_config.h"
19
20#endif
About Timing¶
13#ifndef COMPATIBLITY_H
14#define COMPATIBLITY_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20#include <stddef.h>
21#include <time.h>
22#include <sys/time.h>
23
24void __msleep(int milisec);
25
26void __usleep(int milisec);
27
28void __start_timer();
29
30long __millis();
31
32#ifdef __cplusplus
33}
34#endif
35
36#endif /* COMPATIBLITY_H */
About GPIO¶
8#include <cstdio>
9
10class GPIO {
11public:
12 /* Constants */
13 static const int DIRECTION_OUT = 1;
14 static const int DIRECTION_IN = 0;
15
16 static const int OUTPUT_HIGH = 1;
17 static const int OUTPUT_LOW = 0;
18
19 GPIO();
20
21 /**
22 * Similar to Arduino pinMode(pin, mode);
23 * @param port
24 * @param DDR
25 */
26 static void open(int port, int DDR);
27
28 /**
29 *
30 * @param port
31 */
32 static void close(int port);
33
34 /**
35 * Similar to Arduino digitalRead(pin);
36 * @param port
37 */
38 static int read(int port);
39
40 /**
41 * Similar to Arduino digitalWrite(pin, state);
42 * @param port
43 * @param value
44 */
45 static void write(int port, int value);
46
47 virtual ~GPIO();
48};
About SPI¶
6#include <string>
7#include <stdint.h>
8#include <unistd.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <getopt.h>
12#include <fcntl.h>
13#include <sys/ioctl.h>
14#include <inttypes.h>
15#include <linux/types.h>
16#include <linux/spi/spidev.h>
17
18using namespace std;
19
20class SPI {
21public:
22
23 /**
24 * SPI constructor
25 */
26 SPI();
27
28 /**
29 * Start SPI
30 */
31 void begin(int busNo);
32
33 /**
34 * Transfer a single byte
35 * @param tx_ Byte to send
36 * @return Data returned via spi
37 */
38 uint8_t transfer(uint8_t tx_);
39
40 /**
41 * Transfer a buffer of data
42 * @param tbuf Transmit buffer
43 * @param rbuf Receive buffer
44 * @param len Length of the data
45 */
46 void transfernb(char* tbuf, char* rbuf, uint32_t len);
47
48 /**
49 * Transfer a buffer of data without an rx buffer
50 * @param buf Pointer to a buffer of data
51 * @param len Length of the data
52 */
53 void transfern(char* buf, uint32_t len);
54
55 virtual ~ SPI();
56
57private:
58
59 /** Default SPI device */
60 string device;
61 /** SPI Mode set */
62 uint8_t mode;
63 /** word size*/
64 uint8_t bits;
65 /** Set SPI speed*/
66 uint32_t speed;
67 int fd;
68
69 void init();
70
71};