Open RTS
Full implementation of the Somfy RTS protocol
Loading...
Searching...
No Matches
rfm69.h
Go to the documentation of this file.
1#ifndef RFM69_H
2#define RFM69_H
3
4#include <stdbool.h>
5
6#include "../../hal/spi_module.h"
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
24struct rfm69 {
25 struct spi_module *spi_module;
26 int power;
27 int mode;
28};
29
30// Oscillator
31#define RFM69_FXOSC 32000000.0
32#define RFM69_FSTEP (RFM69_FXOSC / 524288)
33
34// Known version numbers
35#define SX1231_VERSION 0x23
36#define RFM69_VERSION 0x24
37
38// Register map
39enum {
40 RFM69_REG_OP_MODE = 0x01,
41 RFM69_REG_DATA_MODUL = 0x02,
42 RFM69_REG_BITRATE_MSB = 0x03,
43 RFM69_REG_BITRATE_LSB = 0x04,
44 RFM69_REG_FRF_MSB = 0x07,
45 RFM69_REG_FRF_MID = 0x08,
46 RFM69_REG_FRF_LSB = 0x09,
47 RFM69_REG_VERSION = 0x10,
48 RFM69_REG_PA_LEVEL = 0x11,
49 RFM69_REG_OCP = 0x13,
50 RFM69_REG_RX_BW = 0x19,
51 RFM69_REG_OOK_PEAK = 0x1B,
52 RFM69_REG_OOK_FIX = 0x1D,
53 RFM69_REG_IRQ_FLAGS_1 = 0x27,
54 RFM69_REG_TEST_PA_1 = 0x5A,
55 RFM69_REG_TEST_PA_2 = 0x5C,
56};
57
58// RegOpMode (0x01)
59enum {
60 RFM69_MODE = 0x1C,
61 RFM69_MODE_SLEEP = 0x00,
62 RFM69_MODE_STDBY = 0x04,
63 RFM69_MODE_FS = 0x08,
64 RFM69_MODE_TX = 0x0C,
65 RFM69_MODE_RX = 0x10,
66};
67
68// RegDataModul (0x02)
69enum {
70 RFM69_DATA_MODE = 0x60,
71 RFM69_DATA_MODE_PACKET = 0x00,
72 RFM69_DATA_MODE_CONTINUOUS_SYNC = 0x40,
73 RFM69_DATA_MODE_CONTINUOUS = 0x60,
74 RFM69_MODULATION_TYPE = 0x08,
75 RFM69_MODULATION_TYPE_FSK = 0x00,
76 RFM69_MODULATION_TYPE_OOK = 0x08,
77 RFM69_MODULATION_SHAPING = 0x03,
78 RFM69_MODULATION_SHAPING_NONE = 0x00,
79};
80
81// RegPaLevel (0x11)
82enum {
83 RFM69_PA0_OFF = 0x00,
84 RFM69_PA0_ON = 0x80,
85 RFM69_PA1_OFF = 0x00,
86 RFM69_PA1_ON = 0x40,
87 RFM69_PA2_OFF = 0x00,
88 RFM69_PA2_ON = 0x20,
89 RFM69_OUTPUT_POWER = 0x1F,
90};
91
92// RegOcp (0x13)
93enum {
94 RFM69_OCP_ON = 0x1A,
95 RFM69_OCP_OFF = 0x0F,
96};
97
98// RegRxBw (0x19)
99enum {
100 RFM69_RX_BW_MANT = 0x18,
101 RFM69_RX_BW_MANT_16 = 0x00,
102 RFM69_RX_BW_MANT_20 = 0x08,
103 RFM69_RX_BW_MANT_24 = 0x10,
104 RFM69_RX_BW_EXP = 0x07,
105};
106
107enum {
108 RFM69_RXBW = 0x1F,
109 RFM69_RXBW_1_3 = 0x17,
110 RFM69_RXBW_1_6 = 0x0F,
111 RFM69_RXBW_2_0 = 0x07,
112 RFM69_RXBW_2_6 = 0x16,
113 RFM69_RXBW_3_1 = 0x0E,
114 RFM69_RXBW_3_9 = 0x06,
115 RFM69_RXBW_5_2 = 0x15,
116 RFM69_RXBW_6_3 = 0x0D,
117 RFM69_RXBW_7_8 = 0x05,
118 RFM69_RXBW_10_4 = 0x14,
119 RFM69_RXBW_12_5 = 0x0C,
120 RFM69_RXBW_15_6 = 0x04,
121 RFM69_RXBW_20_8 = 0x13,
122 RFM69_RXBW_25 = 0x0B,
123 RFM69_RXBW_31_3 = 0x03,
124 RFM69_RXBW_41_7 = 0x12,
125 RFM69_RXBW_50 = 0x0A,
126 RFM69_RXBW_62_5 = 0x02,
127 RFM69_RXBW_83_3 = 0x11,
128 RFM69_RXBW_100 = 0x09,
129 RFM69_RXBW_125 = 0x01,
130 RFM69_RXBW_166_7 = 0x10,
131 RFM69_RXBW_200 = 0x08,
132 RFM69_RXBW_250 = 0x00,
133};
134
135// RegOokPeak (0x1B)
136enum {
137 RFM69_OOK_THRESH_TYPE = 0xC0,
138 RFM69_OOK_THRESH_TYPE_FIXED = 0x00,
139 RFM69_OOK_THRESH_TYPE_PEAK = 0x40,
140 RFM69_OOK_THRESH_TYPE_AVERAGE = 0x80,
141};
142
143// RegIrqFlags1 (0x27)
144enum {
145 RFM69_MODE_READY = 0x80,
146};
147
148// RegTestPa1 (0x5A)
149enum {
150 RFM69_TEST_PA_1_NORMAL = 0x55,
151 RFM69_TEST_PA_1_BOOST = 0x5D,
152};
153
154// RegTestPa2 (0x5C)
155enum {
156 RFM69_TEST_PA_2_NORMAL = 0x70,
157 RFM69_TEST_PA_2_BOOST = 0x7C,
158};
159
170int rfm69_init(struct rfm69 *radio, struct spi_module *spi);
171
172void rfm69_set_data_mode(struct rfm69 *radio, uint8_t mode);
173void rfm69_set_modulation_type(struct rfm69 *radio, uint8_t modulation);
174void rfm69_set_frequency(struct rfm69 *radio, unsigned long freq);
175void rfm69_set_bitrate(struct rfm69 *radio, uint16_t bitrate);
176void rfm69_set_rx_bandwidth(struct rfm69 *radio, uint32_t bw);
177void rfm69_set_transmit_power(struct rfm69 *radio, int8_t power, bool high_power);
178void rfm69_set_mode(struct rfm69 *radio, uint8_t mode);
179
184#ifdef __cplusplus
185} // extern "C"
186#endif
187
188#endif // RFM69_H
An SPI-attached SX1231 or RFM69 radio module.
Definition rfm69.h:24
Hardware abstraction layer for userland SPI drivers.
Definition spi_module.h:22
uint8_t mode
The SPI mode to use for transfers.
Definition spi_module.h:36