Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
cc2500_common.c
Go to the documentation of this file.
1 #include "cc2500_compat.h"
2 
3 #include "peripherals/cc2500.h"
4 #include "cc2500_settings.h"
5 #include "cc2500_common.h"
6 #include "cc2500_rx.h"
7 
8 // betaflight/src/main/rx/cc2500_common.c @ 50bbe0b
9 /*
10  * This file is part of Cleanflight and Betaflight.
11  *
12  * Cleanflight and Betaflight are free software. You can redistribute
13  * this software and/or modify this software under the terms of the
14  * GNU General Public License as published by the Free Software
15  * Foundation, either version 3 of the License, or (at your option)
16  * any later version.
17  *
18  * Cleanflight and Betaflight are distributed in the hope that they
19  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21  * See the GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this software.
25  *
26  * If not, see <http://www.gnu.org/licenses/>.
27  */
28 
29 #include <stdbool.h>
30 
31 //#include "platform.h"
32 
33 #if defined(USE_RX_FRSKY_SPI) || defined(USE_RX_SFHSS_SPI)
34 
35 //#include "common/maths.h"
36 //
37 //#include "drivers/io.h"
38 //#include "drivers/rx/rx_cc2500.h"
39 //#include "drivers/time.h"
40 //
41 //#include "fc/config.h"
42 //
43 //#include "pg/pg.h"
44 //#include "pg/pg_ids.h"
45 //#include "pg/rx.h"
46 //#include "pg/rx_spi.h"
47 //#include "pg/rx_spi_cc2500.h"
48 //
49 //#include "rx/rx.h"
50 //#include "rx/rx_spi.h"
51 //
52 //#include "cc2500_common.h"
53 
54 static IO_t gdoPin;
55 #if defined(USE_RX_CC2500_SPI_PA_LNA)
56 static IO_t txEnPin;
57 static IO_t rxLnaEnPin;
58 #if defined(USE_RX_CC2500_SPI_DIVERSITY)
59 static IO_t antSelPin;
60 #endif
61 #endif
63 
65 {
66  return rssiDbm;
67 }
68 
70 {
71  if (value >= 128) {
72  rssiDbm = ((((uint16_t)value) * 18) >> 5) - 82;
73  } else {
74  rssiDbm = ((((uint16_t)value) * 18) >> 5) + 65;
75  }
76 
78 }
79 
80 bool cc2500getGdo(void)
81 {
82  return IORead(gdoPin);
83 }
84 
85 #if defined(USE_RX_CC2500_SPI_PA_LNA) && defined(USE_RX_CC2500_SPI_DIVERSITY)
86 void cc2500switchAntennae(void)
87 {
88  static bool alternativeAntennaSelected = true;
89 
90  if (antSelPin) {
91  if (alternativeAntennaSelected) {
92  IOLo(antSelPin);
93  } else {
94  IOHi(antSelPin);
95  }
96  alternativeAntennaSelected = !alternativeAntennaSelected;
97  }
98 }
99 #endif
100 #if defined(USE_RX_CC2500_SPI_PA_LNA)
101 void cc2500TxEnable(void)
102 {
103  if (txEnPin) {
104  IOHi(txEnPin);
105  }
106 }
107 
108 void cc2500TxDisable(void)
109 {
110  if (txEnPin) {
111  IOLo(txEnPin);
112  }
113 }
114 #endif
115 
116 static bool cc2500SpiDetect(void)
117 {
118  const uint8_t chipPartNum = cc2500ReadReg(CC2500_30_PARTNUM | CC2500_READ_BURST); //CC2500 read registers chip part num
119  const uint8_t chipVersion = cc2500ReadReg(CC2500_31_VERSION | CC2500_READ_BURST); //CC2500 read registers chip version
120  if (chipPartNum == 0x80 && chipVersion == 0x03) {
121  return true;
122  }
123 
124  return false;
125 }
126 
127 bool cc2500SpiInit(void)
128 {
129  if (rxCc2500SpiConfig()->chipDetectEnabled && !cc2500SpiDetect()) {
130  return false;
131  }
132 
133  // gpio init here
134  gdoPin = IOGetByTag(rxSpiConfig()->extiIoTag);
135 
136  if (!gdoPin) {
137  return false;
138  }
139 
142 #if defined(USE_RX_CC2500_SPI_PA_LNA)
143  if (rxCc2500SpiConfig()->lnaEnIoTag) {
144  rxLnaEnPin = IOGetByTag(rxCc2500SpiConfig()->lnaEnIoTag);
145  IOInit(rxLnaEnPin, OWNER_RX_SPI_CC2500_LNA_EN, 0);
146  IOConfigGPIO(rxLnaEnPin, IOCFG_OUT_PP);
147 
148  IOHi(rxLnaEnPin); // always on at the moment
149  }
150  if (rxCc2500SpiConfig()->txEnIoTag) {
151  txEnPin = IOGetByTag(rxCc2500SpiConfig()->txEnIoTag);
152  IOInit(txEnPin, OWNER_RX_SPI_CC2500_TX_EN, 0);
153  IOConfigGPIO(txEnPin, IOCFG_OUT_PP);
154  } else {
155  txEnPin = IO_NONE;
156  }
157 #if defined(USE_RX_CC2500_SPI_DIVERSITY)
158  if (rxCc2500SpiConfig()->antSelIoTag) {
159  antSelPin = IOGetByTag(rxCc2500SpiConfig()->antSelIoTag);
160  IOInit(antSelPin, OWNER_RX_SPI_CC2500_ANT_SEL, 0);
161  IOConfigGPIO(antSelPin, IOCFG_OUT_PP);
162 
163  IOHi(antSelPin);
164  } else {
165  antSelPin = IO_NONE;
166  }
167 #endif
168 #endif // USE_RX_CC2500_SPI_PA_LNA
169 
170 #if defined(USE_RX_CC2500_SPI_PA_LNA)
171  cc2500TxDisable();
172 #endif // USE_RX_CC2500_SPI_PA_LNA
173 
174  if (rssiSource == RSSI_SOURCE_NONE) {
176  }
177 
178  return true;
179 }
180 #endif
uint8_t cc2500ReadReg(uint8_t reg)
Definition: cc2500.c:199
@ CC2500_31_VERSION
Definition: cc2500.h:115
@ CC2500_30_PARTNUM
Definition: cc2500.h:114
#define CC2500_READ_BURST
Definition: cc2500.h:137
bool cc2500SpiInit(void)
static int16_t rssiDbm
Definition: cc2500_common.c:62
static IO_t gdoPin
Definition: cc2500_common.c:54
bool cc2500getGdo(void)
Definition: cc2500_common.c:80
static bool cc2500SpiDetect(void)
void cc2500setRssiDbm(uint8_t value)
Definition: cc2500_common.c:69
uint16_t cc2500getRssiDbm(void)
Definition: cc2500_common.c:64
@ IOCFG_IN_FLOATING
@ IOCFG_OUT_PP
#define IOHi(io)
#define IOInit(io, owner, index)
#define IOGetByTag(io)
@ OWNER_RX_SPI_EXTI
#define IO_NONE
#define IORead(gpio)
#define IOLo(io)
#define IOConfigGPIO(io, cfg)
void setRssi(uint16_t rssiValue, rssiSource_e source)
Definition: cc2500_rx.c:723
rssiSource_e rssiSource
Definition: cc2500_rx.c:100
@ RSSI_SOURCE_RX_PROTOCOL
Definition: cc2500_rx.h:158
@ RSSI_SOURCE_NONE
Definition: cc2500_rx.h:155
const rxSpiConfig_t * rxSpiConfig(void)
const rxCc2500SpiConfig_t * rxCc2500SpiConfig(void)
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98