Fix doc path
[opentx.git] / radio / src / targets / horus / haptic_driver.cpp
blobb4dc1db64ee41f02770fe35bbbed0b88759d336c
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "opentx.h"
23 void hapticOff(void)
25 HAPTIC_TIMER_COMPARE_VALUE = 0;
28 void hapticOn(uint32_t pwmPercent)
30 if (pwmPercent > 100) {
31 pwmPercent = 100;
33 HAPTIC_TIMER_COMPARE_VALUE = pwmPercent;
36 void hapticInit(void)
38 GPIO_InitTypeDef GPIO_InitStructure;
39 GPIO_InitStructure.GPIO_Pin = HAPTIC_GPIO_PIN;
40 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
41 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
42 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
43 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
44 GPIO_Init(HAPTIC_GPIO, &GPIO_InitStructure);
46 GPIO_PinAFConfig(HAPTIC_GPIO, HAPTIC_GPIO_PinSource, HAPTIC_GPIO_AF);
48 HAPTIC_GPIO_TIMER->ARR = 100;
49 HAPTIC_GPIO_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 10000 - 1;
50 HAPTIC_GPIO_TIMER->CCMR1 = HAPTIC_TIMER_MODE; // PWM
51 HAPTIC_GPIO_TIMER->CCER = HAPTIC_TIMER_OUTPUT_ENABLE;
53 hapticOff();
55 HAPTIC_GPIO_TIMER->EGR = 0;
56 HAPTIC_GPIO_TIMER->CR1 = TIM_CR1_CEN; // counter enable
59 void hapticDone(void)
61 hapticOff();
62 RCC_AHB1PeriphClockCmd(HAPTIC_RCC_AHB1Periph, DISABLE);