Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
cc2500_common.c
Go to the documentation of this file.
1#include "cc2500_compat.h"
2
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
54static IO_t gdoPin;
55#if defined(USE_RX_CC2500_SPI_PA_LNA)
56static IO_t txEnPin;
57static IO_t rxLnaEnPin;
58#if defined(USE_RX_CC2500_SPI_DIVERSITY)
59static 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
80bool cc2500getGdo(void)
81{
82 return IORead(gdoPin);
83}
84
85#if defined(USE_RX_CC2500_SPI_PA_LNA) && defined(USE_RX_CC2500_SPI_DIVERSITY)
86void cc2500switchAntennae(void)
87{
88 static bool alternativeAntennaSelected = true;
89
90 if (antSelPin) {
93 } else {
95 }
97 }
98}
99#endif
100#if defined(USE_RX_CC2500_SPI_PA_LNA)
101void cc2500TxEnable(void)
102{
103 if (txEnPin) {
104 IOHi(txEnPin);
105 }
106}
107
108void cc2500TxDisable(void)
109{
110 if (txEnPin) {
111 IOLo(txEnPin);
112 }
113}
114#endif
115
116static 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
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)
147
148 IOHi(rxLnaEnPin); // always on at the moment
149 }
154 } else {
156 }
157#if defined(USE_RX_CC2500_SPI_DIVERSITY)
162
164 } else {
166 }
167#endif
168#endif // USE_RX_CC2500_SPI_PA_LNA
169
170#if defined(USE_RX_CC2500_SPI_PA_LNA)
172#endif // USE_RX_CC2500_SPI_PA_LNA
173
176 }
177
178 return true;
179}
180#endif
uint8_t cc2500ReadReg(uint8_t reg)
Definition cc2500.c:199
#define CC2500_READ_BURST
Definition cc2500.h:137
@ CC2500_31_VERSION
Definition cc2500.h:115
@ CC2500_30_PARTNUM
Definition cc2500.h:114
bool cc2500SpiInit(void)
static int16_t rssiDbm
static IO_t gdoPin
bool cc2500getGdo(void)
static bool cc2500SpiDetect(void)
void cc2500setRssiDbm(uint8_t value)
uint16_t cc2500getRssiDbm(void)
@ 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 rxCc2500SpiConfig_t * rxCc2500SpiConfig(void)
const rxSpiConfig_t * rxSpiConfig(void)
uint16_t foo
Definition main_demo5.c:58
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.