Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / drivers / transponder_ir_ilap.c
blob0749c40656dac485fa4ce7d1d0109b912cbdffa2
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/>.
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <string.h>
24 #include "platform.h"
26 #ifdef USE_TRANSPONDER
28 #include "drivers/transponder_ir.h"
29 #include "drivers/transponder_ir_ilap.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 ilapTansponderVTable;
36 void transponderIrInitIlap(transponder_t *transponder){
37 // from drivers/transponder_ir.h
38 transponder->gap_toggles = TRANSPONDER_GAP_TOGGLES_ILAP;
39 transponder->dma_buffer_size = TRANSPONDER_DMA_BUFFER_SIZE_ILAP;
40 transponder->vTable = &ilapTansponderVTable;
41 transponder->timer_hz = TRANSPONDER_TIMER_MHZ_ILAP;
42 transponder->timer_carrier_hz = TRANSPONDER_CARRIER_HZ_ILAP;
43 memset(&(transponder->transponderIrDMABuffer.ilap), 0, sizeof(transponder->transponderIrDMABuffer.ilap));
47 void updateTransponderDMABufferIlap(transponder_t *transponder, const uint8_t* transponderData)
49 uint8_t byteIndex;
50 uint8_t bitIndex;
51 uint8_t toggleIndex;
52 for (byteIndex = 0; byteIndex < TRANSPONDER_DATA_LENGTH_ILAP; byteIndex++) {
53 uint8_t byteToSend = *transponderData;
54 transponderData++;
55 for (bitIndex = 0; bitIndex < TRANSPONDER_BITS_PER_BYTE_ILAP; bitIndex++)
57 bool doToggles = false;
58 if (bitIndex == 0) {
59 doToggles = true;
61 else if (bitIndex == TRANSPONDER_BITS_PER_BYTE_ILAP - 1) {
62 doToggles = false;
64 else {
65 doToggles = byteToSend & (1 << (bitIndex - 1));
67 for (toggleIndex = 0; toggleIndex < TRANSPONDER_TOGGLES_PER_BIT_ILAP; toggleIndex++)
69 if (doToggles) {
70 transponder->transponderIrDMABuffer.ilap[dmaBufferOffset] = transponder->bitToggleOne;
72 else {
73 transponder->transponderIrDMABuffer.ilap[dmaBufferOffset] = 0;
75 dmaBufferOffset++;
77 transponder->transponderIrDMABuffer.ilap[dmaBufferOffset] = 0;
78 dmaBufferOffset++;
81 dmaBufferOffset = 0;
84 const struct transponderVTable ilapTansponderVTable = {
85 updateTransponderDMABufferIlap,
88 #endif
89 #endif