summaryrefslogtreecommitdiffstats
path: root/rf_test/rfm.c
blob: 1b88773d0ffe31b307ef7d62bdd6a441923d3375 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "rfm.h"
#include "spi.h"

#define READ_MASK  0x7F
#define WRITE_MASK 0x80

static inline void send_cmd(uint8_t addr, uint8_t val)
{
	uint8_t ra, wa;

	ra = addr | READ_MASK;
	wa = addr | WRITE_MASK; 

	while (spi_recv(ra) != val)
		spi_send(wa, val);
}

void rfm_init(uint8_t addr)
{
	spi_init();

	// mode: standby + packet
	send_cmd(0x01, 0x44);

	// rx interrupt on DPIO0
	send_cmd(0x25, 0x40);
	send_cmd(0x26, 0x07);

	// packet format: 8 bits + whitening + crc + addr filtering
	send_cmd(0x37, 0x52);
	send_cmd(0x38, 0x08);
	send_cmd(0x38, addr);

	// disable encryption
	send_cmd(0x3D, 0x02);
}

void rfm_send(uint8_t addr, uint8_t data)
{
	
}