1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 17:25:13 +03:00

Haptic support

This commit is contained in:
Andre Bernet 2014-04-23 13:18:17 +02:00
parent 95fa0991e6
commit 5c0b8fcb2d
11 changed files with 117 additions and 21 deletions

View file

@ -709,6 +709,12 @@ ifeq ($(PCB), TARANIS)
CPPSRC += targets/taranis/a7105_driver.cpp
endif
ifeq ($(HAPTIC), YES)
CPPDEFS += -DHAPTIC
CPPSRC += haptic.cpp
CPPSRC += targets/taranis/haptic_driver.cpp
endif
endif
CC = $(TRGT)gcc

View file

@ -54,20 +54,20 @@ void hapticQueue::heartbeat()
#else
if (buzzTimeLeft > 0) {
buzzTimeLeft--; // time gets counted down
#if defined(PCBSKY9X)
#if defined(PCBSXY9X) || (defined(PCBTARANIS) && defined(REVPLUS))
hapticOn(g_eeGeneral.hapticStrength * 20);
#else
if (hapticTick-- > 0) {
HAPTIC_ON; // haptic output 'high'
HAPTIC_ON;
}
else {
HAPTIC_OFF; // haptic output 'high'
HAPTIC_OFF;
hapticTick = g_eeGeneral.hapticStrength;
}
#endif
}
else {
HAPTIC_OFF; // haptic output 'high'
HAPTIC_OFF;
if (buzzPause > 0) {
buzzPause--;
}

View file

@ -904,21 +904,6 @@ enum Analogs {
#define BUZZER_ON PORTE |= (1 << OUT_E_BUZZER)
#define BUZZER_OFF PORTE &= ~(1 << OUT_E_BUZZER)
#if defined(HAPTIC)
#if defined(PCBSKY9X)
#define HAPTIC_OFF hapticOff()
#elif defined(PCBGRUVIN9X)
#define HAPTIC_ON PORTD &= ~(1 << OUT_D_HAPTIC)
#define HAPTIC_OFF PORTD |= (1 << OUT_D_HAPTIC)
#else
#define HAPTIC_ON PORTG |= (1 << OUT_G_HAPTIC)
#define HAPTIC_OFF PORTG &= ~(1 << OUT_G_HAPTIC)
#endif
#else
#define HAPTIC_ON
#define HAPTIC_OFF
#endif
#define BITMASK(bit) (1<<(bit))
/// liefert Dimension eines Arrays

View file

@ -185,7 +185,8 @@ void pwrOff();
#define usbPlugged() false
// Haptic driver
#define hapticOff() // TODO hapticOn() cleaner ...
#define HAPTIC_ON PORTD &= ~(1 << OUT_D_HAPTIC)
#define HAPTIC_OFF PORTD |= (1 << OUT_D_HAPTIC)
// Rotary encoder driver
#if ROTARY_ENCODERS <= 2

View file

@ -189,5 +189,7 @@ void pwrOff();
// Haptic driver
#define hapticOff() // TODO hapticOn() cleaner ...
#define HAPTIC_ON PORTD &= ~(1 << OUT_D_HAPTIC)
#define HAPTIC_OFF PORTD |= (1 << OUT_D_HAPTIC)
#endif

View file

@ -239,6 +239,7 @@ extern int8_t Coproc_maxtemp;
// Haptic driver
void hapticOff(void);
void hapticOn(uint32_t pwmPercent);
#define HAPTIC_OFF hapticOff()
// BlueTooth driver
#if defined(BLUETOOTH)

View file

@ -230,6 +230,10 @@ extern uint8_t RotEncoder ;
void rotencPoll();
#endif
// Haptic
#define HAPTIC_ON PORTG |= (1 << OUT_G_HAPTIC)
#define HAPTIC_OFF PORTG &= ~(1 << OUT_G_HAPTIC)
// USB fake driver
#define usbPlugged() false

View file

@ -130,6 +130,10 @@ void interrupt5ms()
AUDIO_HEARTBEAT();
#if defined(HAPTIC)
HAPTIC_HEARTBEAT();
#endif
if ( ++pre_scale >= 2 ) {
pre_scale = 0 ;
per10ms();
@ -156,6 +160,10 @@ void boardInit()
sportInit();
usbInit();
#if defined(HAPTIC)
hapticInit();
#endif
#if defined(DEBUG)
DBGMCU_APB1PeriphConfig(DBGMCU_IWDG_STOP|DBGMCU_TIM1_STOP|DBGMCU_TIM2_STOP|DBGMCU_TIM3_STOP|DBGMCU_TIM6_STOP|DBGMCU_TIM8_STOP|DBGMCU_TIM10_STOP|DBGMCU_TIM13_STOP|DBGMCU_TIM14_STOP, ENABLE);
#endif

View file

@ -239,6 +239,13 @@ void eeWriteBlockCmp(const void *pointer_ram, uint16_t pointer_eeprom, size_t si
// Debug driver
void debugPutc(const char c);
// Haptic
void hapticOff(void);
void hapticOn(uint32_t pwmPercent);
void hapticInit(void);
#define HAPTIC_OFF hapticOff()
#define HAPTIC_ON hapticOn(100)
extern uint8_t currentTrainerMode;
#endif

View file

@ -333,4 +333,15 @@
#define I2C_EEPROM_ADDRESS 0xA2
#define I2C_CAT5137_ADDRESS 0x5C //0101110
// Haptic
#if defined(REVPLUS)
#define RCC_AHB1Periph_GPIOHAPTIC RCC_AHB1Periph_GPIOB
#define GPIO_HAPTIC GPIOB
#define PIN_HAPTIC GPIO_Pin_8
#else
#define RCC_AHB1Periph_GPIOHAPTIC RCC_AHB1Periph_GPIOC
#define GPIO_HAPTIC GPIOC
#define PIN_HAPTIC GPIO_Pin_12
#endif
#endif

View file

@ -0,0 +1,71 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "../../opentx.h"
void hapticOff(void)
{
#if defined(REVPLUS)
return; //TODO PWM support
#else
GPIO_ResetBits(GPIO_HAPTIC, PIN_HAPTIC);
#endif
}
void hapticOn(uint32_t pwmPercent)
{
#if defined(REVPLUS)
// pwmPercent 0-100
return; //TODO PWM support
#else
// No PWM before REVPLUS
GPIO_SetBits(GPIO_HAPTIC, PIN_HAPTIC);
#endif
}
void hapticInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOHAPTIC, ENABLE);
/* GPIO Configuration*/
GPIO_InitStructure.GPIO_Pin = PIN_HAPTIC;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIO_HAPTIC, &GPIO_InitStructure);
}