Skip to content

Commit 216a642

Browse files
committed
Added function to set output power level.
1 parent f1b6b20 commit 216a642

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

include/rf.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,11 @@
224224
#define RF_RF_SETUP_RF_DR_LOW 0x20
225225
#define RF_RF_SETUP_PLL_LOCK 0x10
226226
#define RF_RF_SETUP_RF_DR_HIGH 0x08
227-
#define RF_RF_SETUP_RF_PWR 0x06
227+
#define RF_RF_SETUP_RF_PWR 0x06
228228
#define RF_RF_SETUP_RF_PWR_0_DBM 0x06
229-
#define RF_RF_SETUP_RF_PWR_NEG_6_DBM 0x04
230-
#define RF_RF_SETUP_RF_PWR_NEG_12_DBM 0x02
231-
#define RF_RF_SETUP_RF_PWR_NEG_18_DBM 0x00
229+
#define RF_RF_SETUP_RF_PWR_NEG_6_DBM 0x04
230+
#define RF_RF_SETUP_RF_PWR_NEG_12_DBM 0x02
231+
#define RF_RF_SETUP_RF_PWR_NEG_18_DBM 0x00
232232
//The following can be used in lieu of RF_RF_SETUP_RF_DR_LOW and RF_RF_SETUP_RF_DR_HIGH to set the data rate
233233
#define RF_RF_SETUP_RF_DR_2_MBPS RF_RF_SETUP_RF_DR_HIGH
234234
#define RF_RF_SETUP_RF_DR_1_MBPS 0
@@ -383,6 +383,8 @@ void rf_power_up_param(bool rx_active_mode, uint8_t config);
383383
void rf_power_down();
384384
void rf_power_down_param(uint8_t config);
385385

386+
void rf_set_output_power(uint8_t);
387+
386388
uint8_t rf_write_register(uint8_t regnumber, uint8_t * dataptr, uint16_t len);
387389
uint8_t rf_read_register(uint8_t regnumber, uint8_t * dataptr, uint16_t len);
388390
uint8_t rf_read_register_1_byte(uint8_t regnumber);

src/rf/src/rf_set_output_power.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/////////////////////////////////////////////////////////////////////////////
2+
//
3+
// File: rf_output_power.c
4+
//
5+
// Copyright Dean Cording, 2013
6+
//
7+
// The author provides no guarantees, warantees, or promises, implied or
8+
// otherwise. By using this software you agree to indemnify the author
9+
// of any damages incurred by using it.
10+
//
11+
/////////////////////////////////////////////////////////////////////////////
12+
13+
/////////////////////////////////////////////////////////////////////////////
14+
// This library is free software; you can redistribute it and/or
15+
// modify it under the terms of the GNU Lesser General Public
16+
// License as published by the Free Software Foundation; either
17+
// version 2.1 of the License, or (at your option) any later version.
18+
//
19+
// This library is distributed in the hope that it will be useful,
20+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22+
// Lesser General Public License for more details.
23+
//
24+
// You should have received a copy of the GNU Lesser General Public
25+
// License along with this library; if not, write to the Free Software
26+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27+
/////////////////////////////////////////////////////////////////////////////
28+
29+
#include "rf.h"
30+
#include "rf_src.h"
31+
32+
33+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
34+
//
35+
// void rf_set_output_power(uint8_t power)
36+
//
37+
// Description:
38+
// Sets the TX power level of the device (0dBm, -6dBm, -12dBm, -18dBm)
39+
//
40+
// Parameters:
41+
// uint8_t power - new power level RF_RF_SETUP_RF_PWR_[0|NEG_6|NEG_12|NEG_18]_DBM
42+
//
43+
// Return value:
44+
// None
45+
//
46+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
47+
void rf_set_output_power(uint8_t power)
48+
{
49+
if (power <= RF_RF_SETUP_RF_PWR_0_DBM) {
50+
uint8_t rf_setup = rf_read_register_1_byte(RF_RF_SETUP);
51+
rf_setup = (rf_setup & ~RF_RF_SETUP_RF_PWR) | power;
52+
rf_write_register(RF_RF_SETUP, &rf_setup, 1);
53+
}
54+
}

0 commit comments

Comments
 (0)