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)
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/>.
32 #include "build/build_config.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"
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
,
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
,
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] = {
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