[4.4.2] Remove 15 m/s limit on estimated vario (#12788)
[betaflight.git] / src / main / drivers / rx / rx_cc2500.c
blob487b2eb78004d1a59ab39f6f1758b6886a08a54c
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
22 * CC2500 SPI drivers
24 #include <stdbool.h>
25 #include <stdint.h>
26 #include <stdlib.h>
28 #include "platform.h"
30 #ifdef USE_RX_CC2500
32 #include "build/build_config.h"
34 #include "pg/rx.h"
35 #include "pg/rx_spi.h"
37 #include "drivers/io.h"
38 #include "drivers/rx/rx_spi.h"
39 #include "drivers/system.h"
40 #include "drivers/time.h"
42 #include "rx_cc2500.h"
44 #define NOP 0xFF
46 void cc2500ReadFifo(uint8_t *dpbuffer, uint8_t len)
48 rxSpiReadCommandMulti(CC2500_3F_RXFIFO | CC2500_READ_BURST, NOP, dpbuffer, len);
51 void cc2500WriteCommand(uint8_t command, uint8_t data)
53 rxSpiWriteCommand(command, data);
56 void cc2500WriteCommandMulti(uint8_t command, const uint8_t *data, uint8_t length)
58 rxSpiWriteCommandMulti(command, data, length);
61 void cc2500WriteFifo(uint8_t *dpbuffer, uint8_t len)
63 cc2500Strobe(CC2500_SFTX); // 0x3B SFTX
64 cc2500WriteCommandMulti(CC2500_3F_TXFIFO | CC2500_WRITE_BURST,
65 dpbuffer, len);
66 cc2500Strobe(CC2500_STX); // 0x35
69 void cc2500ReadRegisterMulti(uint8_t address, uint8_t *data, uint8_t length)
71 rxSpiReadCommandMulti(address, NOP, data, length);
74 void cc2500WriteRegisterMulti(uint8_t address, uint8_t *data,
75 uint8_t length)
77 cc2500WriteCommandMulti(address, data, length);
80 uint8_t cc2500ReadReg(uint8_t reg)
82 return rxSpiReadCommand(reg | 0x80, NOP);
85 void cc2500Strobe(uint8_t address) { rxSpiWriteByte(address); }
87 void cc2500WriteReg(uint8_t address, uint8_t data)
89 cc2500WriteCommand(address, data);
92 void cc2500SetPower(uint8_t power)
94 const uint8_t patable[8] = {
95 0xC5, // -12dbm
96 0x97, // -10dbm
97 0x6E, // -8dbm
98 0x7F, // -6dbm
99 0xA9, // -4dbm
100 0xBB, // -2dbm
101 0xFE, // 0dbm
102 0xFF // 1.5dbm
104 if (power > 7)
105 power = 7;
106 cc2500WriteReg(CC2500_3E_PATABLE, patable[power]);
109 uint8_t cc2500Reset(void)
111 // Writes require an interbyte gap, see fig. 7, pg. 22 in https://www.ti.com/lit/ds/symlink/cc2500.pdf
112 // As such gaps can't be inserted if DMA is being used, inhibit DMA for this device
113 rxSpiDmaEnable(false);
115 cc2500Strobe(CC2500_SRES);
116 delayMicroseconds(1000); // 1000us
117 // CC2500_SetTxRxMode(TXRX_OFF);
118 // RX_EN_off;//off tx
119 // TX_EN_off;//off rx
120 return cc2500ReadReg(CC2500_0E_FREQ1) == 0xC4; // check if reset
122 #endif