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/>.
26 #ifdef USE_TRANSPONDER
28 #include "drivers/transponder_ir.h"
29 #include "drivers/transponder_ir_erlt.h"
31 #if defined(STM32F3) || defined(STM32F4) || defined(STM32F7) || defined(STM32H7) || defined(STM32G4) || defined(UNIT_TEST)
33 static uint16_t dmaBufferOffset
;
34 extern const struct transponderVTable erltTansponderVTable
;
36 void transponderIrInitERLT(transponder_t
*transponder
){
37 transponder
->dma_buffer_size
= TRANSPONDER_DMA_BUFFER_SIZE_ERLT
;
38 transponder
->vTable
= &erltTansponderVTable
;
39 transponder
->timer_hz
= TRANSPONDER_TIMER_MHZ_ERLT
;
40 transponder
->timer_carrier_hz
= TRANSPONDER_CARRIER_HZ_ERLT
;
41 memset(&(transponder
->transponderIrDMABuffer
.erlt
), 0, sizeof(transponder
->transponderIrDMABuffer
.erlt
));
44 void addBitToBuffer(transponder_t
*transponder
, uint8_t cycles
, uint8_t pulsewidth
)
46 for (int i
= 0; i
< cycles
; i
++) {
47 transponder
->transponderIrDMABuffer
.erlt
[dmaBufferOffset
++] = pulsewidth
;
51 void updateTransponderDMABufferERLT(transponder_t
*transponder
, const uint8_t* transponderData
)
53 uint8_t byteToSend
= ~(*transponderData
); //transponderData is stored inverted, so invert before using
54 uint8_t paritysum
= 0; //sum of one bits
56 dmaBufferOffset
= 0; //reset buffer count
58 //start bit 1, always pulsed, bit value = 0
59 addBitToBuffer(transponder
, ERLTCyclesForZeroBit
, transponder
->bitToggleOne
);
61 //start bit 2, always not pulsed, bit value = 0
62 addBitToBuffer(transponder
, ERLTCyclesForZeroBit
, ERLTBitQuiet
);
64 //add data bits, only the 6 LSB
65 for (int i
= 5; i
>= 0; i
--)
67 uint8_t bv
= (byteToSend
>> i
) & 0x01;
69 addBitToBuffer(transponder
, (bv
? ERLTCyclesForOneBit
: ERLTCyclesForZeroBit
), ((i
% 2) ? transponder
->bitToggleOne
: ERLTBitQuiet
));
72 //parity bit, always pulsed, bit value is zero if sum is even, one if odd
73 addBitToBuffer(transponder
, ((paritysum
% 2) ? ERLTCyclesForOneBit
: ERLTCyclesForZeroBit
), transponder
->bitToggleOne
);
75 //add final zero after the pulsed parity bit to stop pulses until the next update
76 transponder
->transponderIrDMABuffer
.erlt
[dmaBufferOffset
++] = ERLTBitQuiet
;
78 //reset buffer size to that required by this ERLT id
79 transponder
->dma_buffer_size
= dmaBufferOffset
;
82 const struct transponderVTable erltTansponderVTable
= {
83 updateTransponderDMABufferERLT
,