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 // Burst writes require an interbyte gap, see fig. 7, pg. 22 in https://www.ti.com/lit/ds/symlink/cc2500.pdf
54 // As such gaps can't be inserted if DMA is being used, inhibit DMA on this bus for the duration of this call
55 rxSpiDmaEnable(false);
56 rxSpiWriteCommand(command
, data
);
60 void cc2500WriteCommandMulti(uint8_t command
, const uint8_t *data
, uint8_t length
)
62 // Burst writes require an interbyte gap, see fig. 7, pg. 22 in https://www.ti.com/lit/ds/symlink/cc2500.pdf
63 // As such gaps can't be inserted if DMA is being used, inhibit DMA on this bus for the duration of this call
64 rxSpiDmaEnable(false);
65 rxSpiWriteCommandMulti(command
, data
, length
);
69 void cc2500WriteFifo(uint8_t *dpbuffer
, uint8_t len
)
71 cc2500Strobe(CC2500_SFTX
); // 0x3B SFTX
72 cc2500WriteCommandMulti(CC2500_3F_TXFIFO
| CC2500_WRITE_BURST
,
74 cc2500Strobe(CC2500_STX
); // 0x35
77 void cc2500ReadRegisterMulti(uint8_t address
, uint8_t *data
, uint8_t length
)
79 rxSpiReadCommandMulti(address
, NOP
, data
, length
);
82 void cc2500WriteRegisterMulti(uint8_t address
, uint8_t *data
,
85 cc2500WriteCommandMulti(address
, data
, length
);
88 uint8_t cc2500ReadReg(uint8_t reg
)
90 return rxSpiReadCommand(reg
| 0x80, NOP
);
93 void cc2500Strobe(uint8_t address
) { rxSpiWriteByte(address
); }
95 void cc2500WriteReg(uint8_t address
, uint8_t data
)
97 cc2500WriteCommand(address
, data
);
100 void cc2500SetPower(uint8_t power
)
102 const uint8_t patable
[8] = {
114 cc2500WriteReg(CC2500_3E_PATABLE
, patable
[power
]);
117 uint8_t cc2500Reset(void)
119 cc2500Strobe(CC2500_SRES
);
120 delayMicroseconds(1000); // 1000us
121 // CC2500_SetTxRxMode(TXRX_OFF);
122 // RX_EN_off;//off tx
123 // TX_EN_off;//off rx
124 return cc2500ReadReg(CC2500_0E_FREQ1
) == 0xC4; // check if reset