Code re-organisation: src/platform/xxx for the MCU type (#13955)
[betaflight.git] / src / platform / STM32 / camera_control_stm32.c
blobb32173747b7c3961fe7dcdcb6b501144061989f6
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(TIM6), CAMERA_CONTROL_PWM_RESOLUTION, 0, inverted);
41 #endif
43 #ifdef CAMERA_CONTROL_SOFTWARE_PWM_AVAILABLE
44 void TIM6_DAC_IRQHandler(void)
46 cameraControlHi();
47 TIM6->SR = 0;
50 void TIM7_IRQHandler(void)
52 cameraControlLo();
53 TIM7->SR = 0;
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
61 NVIC_Init(&nvicTIM6);
63 NVIC_InitTypeDef nvicTIM7 = {
64 TIM7_IRQn, NVIC_PRIORITY_BASE(NVIC_PRIO_TIMER), NVIC_PRIORITY_SUB(NVIC_PRIO_TIMER), ENABLE
66 NVIC_Init(&nvicTIM7);
68 RCC->APB1ENR |= RCC_APB1Periph_TIM6 | RCC_APB1Periph_TIM7;
69 TIM6->PSC = 0;
70 TIM7->PSC = 0;
73 void cameraControlSoftwarePwmEnable(uint32_t hiTime, uint32_t period)
75 TIM6->CNT = hiTime;
76 TIM6->ARR = period;
78 TIM7->CNT = 0;
79 TIM7->ARR = 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;
96 TIM6->DIER = 0;
97 TIM7->DIER = 0;
99 #endif
101 #endif // USE_CAMERA_CONTROL