-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathRFM69.h
More file actions
145 lines (125 loc) · 5.94 KB
/
RFM69.h
File metadata and controls
145 lines (125 loc) · 5.94 KB
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
135
136
137
138
139
140
141
142
143
144
// **********************************************************************************
// Driver definition for HopeRF RFM69W/RFM69HW/RFM69CW/RFM69HCW, Semtech SX1231/1231H
// **********************************************************************************
// Copyright Felix Rusu 2016, http://www.LowPowerLab.com/contact
// **********************************************************************************
// 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.
//
// 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
// **********************************************************************************
// **********************************************************************************
// Converted to AVR environment by Zulkar Nayem
// **********************************************************************************
#include <avr/io.h>
#ifndef RFM69_h
#define RFM69_h
// Definitions
#if defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
# define SS_DDR DDRB
# define SS_PORT PORTB
# define SS_PIN PB2
# define INT_DDR DDRD
# define INT_PORT PORTD
# define INT_PIN PIND
# define INT_pin_num 2
# define INT_PIN_n PD2
# define INTn INT0
# define ISCn0 ISC00
# define ISCn1 ISC01
# define INT_VECT INT0_vect
# define EICRn EICRA
#elif defined (__AVR_ATmega64__)
# define SS_DDR DDRB
# define SS_PORT PORTB
# define SS_PIN PB0
# define INT_DDR DDRE
# define INT_PORT PORTE
# define INT_PIN PINE
# define INT_pin_num 5
# define INT_PIN_n PE5
# define INTn INT5
# define ISCn0 ISC50
# define ISCn1 ISC51
# define INT_VECT INT5_vect
# define EICRn EICRB
#elif defined(__AVR_ATtiny84A__)
# define SS_DDR DDRA
# define SS_PORT PORTA
# define SS_PIN PINA3
# define INT_DDR DDRB
# define INT_PORT PORTB
# define INT_PIN PINB
# define INT_pin_num 2
# define INT_PIN_n PINB2
# define INTn INT0
# define ISCn0 ISC00
# define ISCn1 ISC01
# define INT_VECT EXT_INT0_vect
# define EICRn MCUCR
#endif
#define RF69_MAX_DATA_LEN 61 // to take advantage of the built in AES/CRC we want to limit the frame size to the internal FIFO size (66 bytes - 3 bytes overhead - 2 bytes crc)
#define CSMA_LIMIT -90 // upper RX signal sensitivity threshold in dBm for carrier sense access
#define RF69_MODE_SLEEP 0 // XTAL OFF
#define RF69_MODE_STANDBY 1 // XTAL ON
#define RF69_MODE_SYNTH 2 // PLL ON
#define RF69_MODE_RX 3 // RX MODE
#define RF69_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 RF69_BROADCAST_ADDR 0
#define RF69_CSMA_LIMIT_MS 1000
#define RF69_TX_LIMIT_MS 1000
#define RF69_FSTEP 61.03515625 // == FXOSC / 2^19 = 32MHz / 2^19 (p13 in datasheet) / FXOSC = module crystal oscillator frequency
// TWS: define CTLbyte bits
#define RFM69_CTL_SENDACK 0x80
#define RFM69_CTL_REQACK 0x40
// Global Variables
volatile uint8_t DATA[RF69_MAX_DATA_LEN+1]; // RX/TX payload buffer, including end of string NULL char
// Function Declerations
void rfm69_init(uint16_t freqBand, uint8_t nodeID, uint8_t networkID);
void setAddress(uint8_t addr);
void setNetwork(uint8_t networkID);
uint8_t canSend();
void send(uint8_t toAddress, const void* buffer, uint8_t bufferSize, uint8_t requestACK);
uint8_t sendWithRetry(uint8_t toAddress, const void* buffer, uint8_t bufferSize, uint8_t retries, uint8_t retryWaitTime);
uint8_t ACKRequested();
uint8_t ACKReceived(uint8_t fromNodeID);
void receiveBegin();
uint8_t receiveDone();
void sendACK(const void* buffer, uint8_t bufferSize);
uint32_t getFrequency();
void setFrequency(uint32_t freqHz);
void encrypt(const char* key);
int16_t readRSSI(uint8_t forceTrigger);
void setHighPower(uint8_t onOFF); // has to be called after initialize() for RFM69HW
void setPowerLevel(uint8_t level); // reduce/increase transmit power level
void sleep();
uint8_t readTemperature(uint8_t calFactor); // 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]
uint8_t readReg(uint8_t addr);
void writeReg(uint8_t addr, uint8_t val);
void sendFrame(uint8_t toAddress, const void* buffer, uint8_t size, uint8_t requestACK, uint8_t sendACK);
void setMode(uint8_t mode);
void setHighPowerRegs(uint8_t onOff);
void promiscuous(uint8_t onOff);
void maybeInterrupts();
void select();
void unselect();
uint8_t receiveDone();
#endif