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
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/>.
24 #ifdef USE_CAMERA_CONTROL
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"
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(TIM6
), CAMERA_CONTROL_PWM_RESOLUTION
, 0, inverted
);
43 #ifdef CAMERA_CONTROL_SOFTWARE_PWM_AVAILABLE
44 void TIM6_DAC_IRQHandler(void)
50 void TIM7_IRQHandler(void)
56 void cameraControlSoftwarePwmInit(void)
58 NVIC_InitTypeDef nvicTIM6
= {
59 TIM6_DAC_IRQn
, NVIC_PRIORITY_BASE(NVIC_PRIO_TIMER
), NVIC_PRIORITY_SUB(NVIC_PRIO_TIMER
), ENABLE
63 NVIC_InitTypeDef nvicTIM7
= {
64 TIM7_IRQn
, NVIC_PRIORITY_BASE(NVIC_PRIO_TIMER
), NVIC_PRIORITY_SUB(NVIC_PRIO_TIMER
), ENABLE
68 RCC
->APB1ENR
|= RCC_APB1Periph_TIM6
| RCC_APB1Periph_TIM7
;
73 void cameraControlSoftwarePwmEnable(uint32_t hiTime
, uint32_t period
)
81 // Start two timers as simultaneously as possible
82 ATOMIC_BLOCK(NVIC_PRIO_TIMER
) {
83 TIM6
->CR1
= TIM_CR1_CEN
;
84 TIM7
->CR1
= TIM_CR1_CEN
;
87 // Enable interrupt generation
88 TIM6
->DIER
= TIM_IT_Update
;
89 TIM7
->DIER
= TIM_IT_Update
;
92 void cameraControlSoftwarePwmDisable(void)
94 TIM6
->CR1
&= ~TIM_CR1_CEN
;
95 TIM7
->CR1
&= ~TIM_CR1_CEN
;
101 #endif // USE_CAMERA_CONTROL