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/>.
29 #include "drivers/bus_spi.h"
30 #include "drivers/io.h"
31 #include "drivers/io_impl.h"
32 #include "drivers/rx/rx_a7105.h"
33 #include "drivers/rx/rx_spi.h"
35 static IO_t txEnIO
= IO_NONE
;
37 static bool consumeExti
= true;
39 void A7105Init(uint32_t id
, IO_t txEnPin
)
43 //TODO: Create resource for this if it ever gets used
44 IOInit(txEnIO
, OWNER_RX_SPI_CC2500_TX_EN
, 0);
45 IOConfigGPIO(txEnIO
, IOCFG_OUT_PP
);
54 void A7105Config(const uint8_t *regsTable
, uint8_t size
)
57 unsigned timeout
= 1000;
59 for (unsigned i
= 0; i
< size
; i
++) {
60 if (regsTable
[i
] != 0xFF) {
61 A7105WriteReg ((A7105Reg_t
)i
, regsTable
[i
]);
65 A7105Strobe(A7105_STANDBY
);
67 A7105WriteReg(A7105_02_CALC
, 0x01);
69 while ((A7105ReadReg(A7105_02_CALC
) != 0) && timeout
--) {}
71 A7105ReadReg(A7105_22_IF_CALIB_I
);
73 A7105WriteReg(A7105_24_VCO_CURCAL
, 0x13);
74 A7105WriteReg(A7105_25_VCO_SBCAL_I
, 0x09);
75 A7105Strobe(A7105_STANDBY
);
79 bool A7105RxTxFinished(timeUs_t
*timeStamp
)
83 if (consumeExti
&& rxSpiPollExti()) {
84 if (rxSpiGetLastExtiTimeUs()) {
85 *timeStamp
= rxSpiGetLastExtiTimeUs();
95 void A7105SoftReset(void)
97 rxSpiWriteCommand((uint8_t)A7105_00_MODE
, 0x00);
100 uint8_t A7105ReadReg(A7105Reg_t reg
)
102 return rxSpiReadCommand((uint8_t)reg
| 0x40, 0xFF);
105 void A7105WriteReg(A7105Reg_t reg
, uint8_t data
)
107 rxSpiWriteCommand((uint8_t)reg
, data
);
110 void A7105Strobe(A7105State_t state
)
112 if (A7105_TX
== state
|| A7105_RX
== state
) {
120 if (A7105_TX
== state
) {
121 IOHi(txEnIO
); /* enable PA */
123 IOLo(txEnIO
); /* disable PA */
127 rxSpiWriteByte((uint8_t)state
);
130 void A7105WriteID(uint32_t id
)
133 data
[0] = (id
>> 24) & 0xFF;
134 data
[1] = (id
>> 16) & 0xFF;
135 data
[2] = (id
>> 8) & 0xFF;
136 data
[3] = (id
>> 0) & 0xFF;
137 rxSpiWriteCommandMulti((uint8_t)A7105_06_ID_DATA
, &data
[0], sizeof(data
));
140 uint32_t A7105ReadID(void)
144 rxSpiReadCommandMulti((uint8_t)A7105_06_ID_DATA
| 0x40, 0xFF, &data
[0], sizeof(data
));
145 id
= data
[0] << 24 | data
[1] << 16 | data
[2] << 8 | data
[3] << 0;
149 void A7105ReadFIFO(uint8_t *data
, uint8_t num
)
156 A7105Strobe(A7105_RST_RDPTR
); /* reset read pointer */
157 rxSpiReadCommandMulti((uint8_t)A7105_05_FIFO_DATA
| 0x40, 0xFF, data
, num
);
161 void A7105WriteFIFO(uint8_t *data
, uint8_t num
)
168 A7105Strobe(A7105_RST_WRPTR
); /* reset write pointer */
169 rxSpiWriteCommandMulti((uint8_t)A7105_05_FIFO_DATA
, data
, num
);
173 #endif /* USE_RX_FLYSKY */