forked from etimou/SomfyRTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRFM69OOK.h
134 lines (119 loc) · 4.98 KB
/
RFM69OOK.h
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// **********************************************************************************
// Driver definition for HopeRF RFM69W/RFM69HW/RFM69CW/RFM69HCW, Semtech SX1231/1231H
// **********************************************************************************
// Copyright Felix Rusu (2014), [email protected]
// http://lowpowerlab.com/
// **********************************************************************************
// License
// **********************************************************************************
// This program is free software; you can redistribute it
// and/or modify it under the terms of the GNU General
// Public License as published by the Free Software
// Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General
// Public License along with this program.
// If not, see <http://www.gnu.org/licenses/>.
//
// Licence can be viewed at
// http://www.gnu.org/licenses/gpl-3.0.txt
//
// Please maintain this license information along with authorship
// and copyright notices in any redistribution of this code
// **********************************************************************************
#ifndef RFM69OOK_h
#define RFM69OOK_h
#include <Arduino.h> //assumes Arduino IDE v1.0 or greater
#define RF69OOK_SPI_CS SS // SS is the SPI slave select pin, for instance D10 on atmega328
// INT0 on AVRs should be connected to RFM69's DIO0 (ex on Atmega328 it's D2, on Atmega644/1284 it's D2)
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
#define RF69OOK_IRQ_PIN 3
#define RF69OOK_IRQ_NUM 1
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
#define RF69OOK_IRQ_PIN 10
#define RF69OOK_IRQ_NUM 0
#elif defined(__AVR_ATmega32U4__)
#define RF69OOK_IRQ_PIN 3
#define RF69OOK_IRQ_NUM 0
#elif defined(ESP8266)
#define RF69OOK_IRQ_PIN D1
#define RF69OOK_IRQ_NUM 0
#elif defined(ESP32)
#define RF69OOK_IRQ_PIN 4
#define RF69OOK_IRQ_NUM 0
#endif
#define RF69OOK_MODE_SLEEP 0 // XTAL OFF
#define RF69OOK_MODE_STANDBY 1 // XTAL ON
#define RF69OOK_MODE_SYNTH 2 // PLL ON
#define RF69OOK_MODE_RX 3 // RX MODE
#define RF69OOK_MODE_TX 4 // TX MODE
#define null 0
#define COURSE_TEMP_COEF -90 // puts the temperature reading in the ballpark, user can fine tune the returned value
#define RF69OOK_FSTEP 61.03515625 // == FXOSC/2^19 = 32mhz/2^19 (p13 in DS)
class RFM69OOK {
public:
static volatile int RSSI; //most accurate RSSI during reception (closest to the reception)
static volatile byte _mode; //should be protected?
RFM69OOK(byte slaveSelectPin=RF69OOK_SPI_CS, byte interruptPin=RF69OOK_IRQ_PIN, bool isRFM69HW=false, byte interruptNum=RF69OOK_IRQ_NUM) {
_slaveSelectPin = slaveSelectPin;
_interruptPin = interruptPin;
_interruptNum = interruptNum;
_mode = RF69OOK_MODE_STANDBY;
_powerLevel = 31;
_isRFM69HW = isRFM69HW;
}
bool initialize();
uint32_t getFrequency();
void setFrequency(uint32_t freqHz);
void setFrequencyMHz(float f);
void setCS(byte newSPISlaveSelect);
int8_t readRSSI(bool forceTrigger=false);
void setHighPower(bool onOFF=true); //have to call it after initialize for RFM69HW
void setPowerLevel(byte level); //reduce/increase transmit power level
void sleep();
byte readTemperature(byte calFactor=0); //get CMOS temperature (8bit)
void rcCalibration(); //calibrate the internal RC oscillator for use in wide temperature variations - see datasheet section [4.3.5. RC Timer Accuracy]
// allow hacking registers by making these public
byte readReg(byte addr);
void writeReg(byte addr, byte val);
void readAllRegs();
// functions related to OOK mode
void receiveBegin();
void receiveEnd();
void transmitBegin();
void transmitEnd();
bool poll();
void send(bool signal);
void attachUserInterrupt(void (*function)());
void setBandwidth(uint8_t bw);
void setBitrate(uint32_t bitrate);
void setRSSIThreshold(int8_t rssi);
void setFixedThreshold(uint8_t threshold);
void setSensitivityBoost(uint8_t value);
void select();
void unselect();
protected:
static void isr0();
void virtual interruptHandler();
static RFM69OOK* selfPointer;
byte _slaveSelectPin;
byte _interruptPin;
byte _interruptNum;
byte _powerLevel;
bool _isRFM69HW;
byte _SPCR;
byte _SPSR;
void setMode(byte mode);
void setHighPowerRegs(bool onOff);
// functions related to OOK mode
void (*userInterrupt)();
void ookInterruptHandler();
};
#endif