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 // Haptic
#if defined(REVPLUS) #if defined(REVPLUS)
#define RCC_AHB1Periph_GPIOHAPTIC RCC_AHB1Periph_GPIOB #define RCC_AHB1Periph_GPIOHAPTIC RCC_AHB1Periph_GPIOB
#define GPIO_PinSource_HAPTIC GPIO_PinSource8
#define GPIO_HAPTIC GPIOB #define GPIO_HAPTIC GPIOB
#define PIN_HAPTIC GPIO_Pin_8 #define PIN_HAPTIC GPIO_Pin_8
#else #else
+21 -10
View File
@@ -39,8 +39,7 @@
void hapticOff(void) void hapticOff(void)
{ {
#if defined(REVPLUS) #if defined(REVPLUS)
GPIO_ResetBits(GPIO_HAPTIC, PIN_HAPTIC); // Temp, TODO PWM support TIM10->CCR1 = 0;
return;
#else #else
GPIO_ResetBits(GPIO_HAPTIC, PIN_HAPTIC); GPIO_ResetBits(GPIO_HAPTIC, PIN_HAPTIC);
#endif #endif
@@ -48,9 +47,11 @@ void hapticOff(void)
#if defined(REVPLUS) #if defined(REVPLUS)
void hapticOn(uint32_t pwmPercent) void hapticOn(uint32_t pwmPercent)
{ // pwmPercent 0-100 {
GPIO_SetBits(GPIO_HAPTIC, PIN_HAPTIC); // Temp, TODO PWM support if (pwmPercent > 100) {
return; pwmPercent = 100;
}
TIM10->CCR1 = pwmPercent;
} }
#else #else
void hapticOn() void hapticOn()
@@ -62,14 +63,24 @@ void hapticOn()
void hapticInit(void) void hapticInit(void)
{ {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOHAPTIC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOHAPTIC, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIO Configuration*/
GPIO_InitStructure.GPIO_Pin = PIN_HAPTIC; GPIO_InitStructure.GPIO_Pin = PIN_HAPTIC;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIO_HAPTIC, &GPIO_InitStructure); 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
} }