Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / drivers / transponder_ir_arcitimer.c
blobd262904aa5f1519375d136887114487d645f4b6b
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>
25 #include "platform.h"
27 #ifdef USE_TRANSPONDER
29 #include "drivers/transponder_ir.h"
30 #include "drivers/transponder_ir_arcitimer.h"
32 #if defined(STM32F3) || defined(STM32F4) || defined(STM32F7) || defined(STM32H7) || defined(STM32G4) || defined(UNIT_TEST)
34 extern const struct transponderVTable arcitimerTansponderVTable;
35 static uint16_t dmaBufferOffset;
37 void transponderIrInitArcitimer(transponder_t *transponder){
38 // from drivers/transponder_ir.h
39 transponder->gap_toggles = TRANSPONDER_GAP_TOGGLES_ARCITIMER;
40 transponder->dma_buffer_size = TRANSPONDER_DMA_BUFFER_SIZE_ARCITIMER;
41 transponder->vTable = &arcitimerTansponderVTable;
42 transponder->timer_hz = TRANSPONDER_TIMER_MHZ_ARCITIMER;
43 transponder->timer_carrier_hz = TRANSPONDER_CARRIER_HZ_ARCITIMER;
44 memset(&(transponder->transponderIrDMABuffer.arcitimer), 0, sizeof(transponder->transponderIrDMABuffer.arcitimer));
47 void updateTransponderDMABufferArcitimer(transponder_t *transponder, const uint8_t* transponderData)
49 uint8_t byteIndex;
50 uint8_t bitIndex;
51 uint8_t hightStateIndex;
52 for (byteIndex = 0; byteIndex < TRANSPONDER_DATA_LENGTH_ARCITIMER; byteIndex++) {
53 uint8_t byteToSend = *transponderData;
54 transponderData++;
55 for (bitIndex = 0; bitIndex < TRANSPONDER_BITS_PER_BYTE_ARCITIMER; bitIndex++)
57 bool isHightState = byteToSend & (1 << (bitIndex));
58 for (hightStateIndex = 0; hightStateIndex < TRANSPONDER_TOGGLES_PER_BIT_ARCITIMER; hightStateIndex++)
60 transponder->transponderIrDMABuffer.arcitimer[dmaBufferOffset] = isHightState ? transponder->bitToggleOne : 0;
61 dmaBufferOffset++;
65 dmaBufferOffset = 0;
70 const struct transponderVTable arcitimerTansponderVTable = {
71 updateTransponderDMABufferArcitimer,
74 #endif
75 #endif