PWM Haptic
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user