FIX: AT32 not reading ESC (#14220)
[betaflight.git] / src / platform / APM32 / camera_control_apm32.c
blobb34467c5a5289fac5431ada764fd1b540961919b
1 /*
2 * This file is part of Betaflight.
4 * Betaflight is free software. You can redistribute this software
5 * and/or modify this software under the terms of the GNU General
6 * Public License as published by the Free Software Foundation,
7 * either version 3 of the License, or (at your option) any later
8 * version.
10 * Betaflight is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this software.
19 * If not, see <http://www.gnu.org/licenses/>.
22 #include "platform.h"
24 #ifdef USE_CAMERA_CONTROL
26 #include <math.h>
28 #include "drivers/camera_control_impl.h"
29 #include "drivers/nvic.h"
30 #include "drivers/pwm_output.h"
32 #ifdef CAMERA_CONTROL_SOFTWARE_PWM_AVAILABLE
33 #include "build/atomic.h"
34 #endif
36 #ifdef CAMERA_CONTROL_HARDWARE_PWM_AVAILABLE
37 void cameraControlHardwarePwmInit(timerChannel_t *channel, const timerHardware_t *timerHardware, uint8_t inverted)
39 pwmOutConfig(channel, timerHardware, timerClock(TMR6), CAMERA_CONTROL_PWM_RESOLUTION, 0, inverted);
41 #endif
43 #ifdef CAMERA_CONTROL_SOFTWARE_PWM_AVAILABLE
44 void TMR6_DAC_IRQHandler(void)
46 cameraControlHi();
47 TMR6->STS = 0;
50 void TMR7_IRQHandler(void)
52 cameraControlLo();
53 TMR7->STS = 0;
56 void cameraControlSoftwarePwmInit(void)
58 DAL_NVIC_SetPriority(TMR6_DAC_IRQn, NVIC_PRIORITY_BASE(NVIC_PRIO_TIMER), NVIC_PRIORITY_SUB(NVIC_PRIO_TIMER));
59 DAL_NVIC_EnableIRQ(TMR6_DAC_IRQn);
61 DAL_NVIC_SetPriority(TMR7_IRQn, NVIC_PRIORITY_BASE(NVIC_PRIO_TIMER), NVIC_PRIORITY_SUB(NVIC_PRIO_TIMER));
62 DAL_NVIC_EnableIRQ(TMR7_IRQn);
64 __DAL_RCM_TMR6_CLK_ENABLE();
65 __DAL_RCM_TMR7_CLK_ENABLE();
66 DDL_TMR_SetPrescaler(TMR6, 0);
67 DDL_TMR_SetPrescaler(TMR7, 0);
70 void cameraControlSoftwarePwmEnable(uint32_t hiTime, uint32_t period)
72 DDL_TMR_SetCounter(TMR6, hiTime);
73 DDL_TMR_SetAutoReload(TMR6, period);
75 DDL_TMR_SetCounter(TMR7, 0);
76 DDL_TMR_SetAutoReload(TMR7, period);
78 // Start two timers as simultaneously as possible
79 ATOMIC_BLOCK(NVIC_PRIO_TIMER) {
80 DDL_TMR_EnableCounter(TMR6);
81 DDL_TMR_EnableCounter(TMR7);
84 // Enable interrupt generation
85 DDL_TMR_EnableIT_UPDATE(TMR6);
86 DDL_TMR_EnableIT_UPDATE(TMR7);
89 void cameraControlSoftwarePwmDisable(void)
91 DDL_TMR_DisableCounter(TMR6);
92 DDL_TMR_DisableCounter(TMR7);
94 TMR6->DIEN = 0;
95 TMR7->DIEN = 0;
97 #endif
99 #endif // USE_CAMERA_CONTROL