blob: b086628917f2132756364b669dcf3d3acad98c1b (
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
42
43
44
45
46
47
48
49
50
51
|
#include "config.h"
void applyConfig(Config config){
// Apply modulation and mode
byte reg=readReg(REG_OP_MODE) &0x3F ; // Fetch opmode register and clear modulation and mode bits
reg=reg | config.mod; // Apply modulation and mode
writeReg(REG_OP_MODE,reg); // Send register back to module
// Apply carrier frequency
int cFreq=config.cFreq/FSTEP;
reg=cFreq >> 16 ;
writeReg(REG_FRF_MSB,reg); // Send register to module
reg=(cFreq&0x00FFFF) >> 8 ;
writeReg(REG_FRF_MID,reg); /// Send register to module
reg=(cFreq&0x0000FF);
writeReg(REG_FRF_LSB,reg); // Send register to module
// Set LNAGain
reg=readReg(REG_LNA) & 0x7F;
writeReg(REG_LNA, reg|config.lnaGain);
// Apply PaBoost, max output power and outputPower
byte Pmax=round((config.maxPower-10.8)/0.6);
Pmax=(Pmax & 0x07)<<4;
byte outputPower;
if(config.paSelect==PA_SELECT_ON){
outputPower=config.outputPower-32;
}
else{
outputPower=config.outputPower-Pmax+15;
}
outputPower=config.outputPower & 0x0F;
reg=config.paSelect|outputPower|Pmax;
writeReg(REG_PA_CONFIG, reg);
// Apply FSK configuration
if(config.mod==MOD_FSK){
applyFSKConfig(config.fsk);
}
}
void applyMode(Config config){
// Apply modulation and mode
byte reg=readReg(REG_OP_MODE) &0xF8 ; // Fetch opmode register and clear mode
reg=config.mode | reg; // Apply mode
writeReg(REG_OP_MODE,reg); // Send register back to module
}
|