PWM Haptic

This commit is contained in:
bsongis
2014-05-11 15:49:18 +02:00
parent 0e2647fa13
commit 72a36b065e
2 changed files with 22 additions and 10 deletions
+1
View File
@@ -380,6 +380,7 @@
// Haptic
#if defined(REVPLUS)
#define RCC_AHB1Periph_GPIOHAPTIC RCC_AHB1Periph_GPIOB
#define GPIO_PinSource_HAPTIC GPIO_PinSource8
#define GPIO_HAPTIC GPIOB
#define PIN_HAPTIC GPIO_Pin_8
#else
+21 -10
View File
@@ -39,8 +39,7 @@
void hapticOff(void)
{
#if defined(REVPLUS)
GPIO_ResetBits(GPIO_HAPTIC, PIN_HAPTIC); // Temp, TODO PWM support
return;
TIM10->CCR1 = 0;
#else
GPIO_ResetBits(GPIO_HAPTIC, PIN_HAPTIC);
#endif
@@ -48,9 +47,11 @@ void hapticOff(void)
#if defined(REVPLUS)
void hapticOn(uint32_t pwmPercent)
{ // pwmPercent 0-100
GPIO_SetBits(GPIO_HAPTIC, PIN_HAPTIC); // Temp, TODO PWM support
return;
{
if (pwmPercent > 100) {
pwmPercent = 100;
}
TIM10->CCR1 = pwmPercent;
}
#else
void hapticOn()
@@ -62,14 +63,24 @@ void hapticOn()
void hapticInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOHAPTIC, ENABLE);
/* GPIO Configuration*/
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = PIN_HAPTIC;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIO_HAPTIC, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIO_HAPTIC, GPIO_PinSource_HAPTIC, GPIO_AF_TIM10);
RCC->APB2ENR |= RCC_APB2ENR_TIM10EN ; // Enable clock
TIM10->ARR = 100 ;
TIM10->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 10000 - 1;
TIM10->CCMR1 = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 ; // PWM
TIM10->CCER = TIM_CCER_CC1E ;
TIM10->CCR1 = 0 ;
TIM10->EGR = 0 ;
TIM10->CR1 = TIM_CR1_CEN ; // Counter enable
}