diff --git a/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp b/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp index b2e92ee81..52ada6c30 100644 --- a/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp +++ b/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp @@ -52,6 +52,7 @@ #define LUA #define LUA_MODEL_SCRIPTS #define EEPROM_VARIANT 3 +#define HAPTIC #define NUM_POTS 5 @@ -99,6 +100,8 @@ inline int geteepromsize() { #include "radio/src/targets/taranis/keys_driver.cpp" #include "radio/src/keys.cpp" #include "radio/src/bmp.cpp" +#include "radio/src/haptic.cpp" +#include "radio/src/targets/taranis/haptic_driver.cpp" // TODO Because FatFS in not C++ there cannot be namespaces there and the functions are defined several times! #undef SDCARD #include "radio/src/simpgmspace.cpp" diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index cf989f92b..1797e50b2 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -559,10 +559,7 @@ int OpenTxFirmware::getCapability(const Capability capability) case SoundPitch: return 1; case Haptic: - if (IS_TARANIS(board)) - return 0; - else - return 1; + return 1; case ModelTrainerEnable: if (IS_TARANIS(board)) return 1; @@ -573,10 +570,7 @@ int OpenTxFirmware::getCapability(const Capability capability) return 1; case HapticLength: case HapticMode: - if (IS_TARANIS(board)) - return 0; - else - return 1; + return 1; case Beeperlen: return 1; case MaxVolume: @@ -1219,6 +1213,7 @@ void registerOpenTxFirmwares() openTx->addOption("noheli", QObject::tr("Disable HELI menu and cyclic mix support")); openTx->addOption("notemplates", QObject::tr("Disable TEMPLATES menu")); openTx->addOption("nogvars", QObject::tr("Disable Global variables")); + openTx->addOption("haptic", QObject::tr("Haptic module installed")); openTx->addOption("ppmus", QObject::tr("Channel values displayed in us")); openTx->addOption("sqt5font", QObject::tr("Use alternative SQT5 font")); openTx->addOptions(fai_options); @@ -1229,6 +1224,7 @@ void registerOpenTxFirmwares() openTx->addOption("noheli", QObject::tr("Disable HELI menu and cyclic mix support")); openTx->addOption("notemplates", QObject::tr("Disable TEMPLATES menu")); openTx->addOption("nogvars", QObject::tr("Disable Global variables")); + openTx->addOption("haptic", QObject::tr("Haptic module installed")); openTx->addOption("ppmus", QObject::tr("Channel values displayed in us")); openTx->addOption("sqt5font", QObject::tr("Use alternative SQT5 font")); openTx->addOptions(fai_options); diff --git a/radio/src/Makefile b/radio/src/Makefile index 8d93005c1..f2162c5bc 100644 --- a/radio/src/Makefile +++ b/radio/src/Makefile @@ -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 diff --git a/radio/src/haptic.cpp b/radio/src/haptic.cpp index ff97d6f21..ec0139795 100644 --- a/radio/src/haptic.cpp +++ b/radio/src/haptic.cpp @@ -54,20 +54,20 @@ void hapticQueue::heartbeat() #else if (buzzTimeLeft > 0) { buzzTimeLeft--; // time gets counted down -#if defined(PCBSKY9X) +#if defined(PCBSKY9X) || (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--; } diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 5c607aea9..1ddafc247 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -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 diff --git a/radio/src/targets/gruvin9x/board_gruvin9x.h b/radio/src/targets/gruvin9x/board_gruvin9x.h index 2d10ea8f8..f44ba4ba6 100644 --- a/radio/src/targets/gruvin9x/board_gruvin9x.h +++ b/radio/src/targets/gruvin9x/board_gruvin9x.h @@ -186,6 +186,8 @@ 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) // Rotary encoder driver #if ROTARY_ENCODERS <= 2 diff --git a/radio/src/targets/mega2560/board_mega2560.h b/radio/src/targets/mega2560/board_mega2560.h index 5943e87c4..dcaf703de 100644 --- a/radio/src/targets/mega2560/board_mega2560.h +++ b/radio/src/targets/mega2560/board_mega2560.h @@ -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 diff --git a/radio/src/targets/sky9x/board_sky9x.h b/radio/src/targets/sky9x/board_sky9x.h index 45f45e936..89d8be49a 100644 --- a/radio/src/targets/sky9x/board_sky9x.h +++ b/radio/src/targets/sky9x/board_sky9x.h @@ -237,8 +237,9 @@ extern int8_t Coproc_temp; extern int8_t Coproc_maxtemp; // Haptic driver -void hapticOff(void) ; +void hapticOff(void); void hapticOn(uint32_t pwmPercent); +#define HAPTIC_OFF() hapticOff() // BlueTooth driver #if defined(BLUETOOTH) diff --git a/radio/src/targets/stock/board_stock.h b/radio/src/targets/stock/board_stock.h index 53c99012f..e0f7b33c7 100644 --- a/radio/src/targets/stock/board_stock.h +++ b/radio/src/targets/stock/board_stock.h @@ -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 diff --git a/radio/src/targets/taranis/board_taranis.cpp b/radio/src/targets/taranis/board_taranis.cpp index 5266f1c98..dca639737 100644 --- a/radio/src/targets/taranis/board_taranis.cpp +++ b/radio/src/targets/taranis/board_taranis.cpp @@ -130,6 +130,10 @@ void interrupt5ms() AUDIO_HEARTBEAT(); +#if defined(HAPTIC) + HAPTIC_HEARTBEAT(); +#endif + if ( ++pre_scale >= 2 ) { pre_scale = 0 ; per10ms(); @@ -155,6 +159,10 @@ void boardInit() eepromInit(); 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); diff --git a/radio/src/targets/taranis/board_taranis.h b/radio/src/targets/taranis/board_taranis.h index 195dc3e3e..dd697079a 100644 --- a/radio/src/targets/taranis/board_taranis.h +++ b/radio/src/targets/taranis/board_taranis.h @@ -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 diff --git a/radio/src/targets/taranis/hal.h b/radio/src/targets/taranis/hal.h index 592feb2c7..ef6bfa74b 100644 --- a/radio/src/targets/taranis/hal.h +++ b/radio/src/targets/taranis/hal.h @@ -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 diff --git a/radio/src/targets/taranis/haptic_driver.cpp b/radio/src/targets/taranis/haptic_driver.cpp new file mode 100644 index 000000000..8fe82268c --- /dev/null +++ b/radio/src/targets/taranis/haptic_driver.cpp @@ -0,0 +1,71 @@ +/* + * Authors (alphabetical order) + * - Andre Bernet + * - Andreas Weitl + * - Bertrand Songis + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - Gabriel Birkus + * - Jean-Pierre Parisy + * - Karl Szmutny + * - Michael Blandford + * - Michal Hlavinka + * - Pat Mackenzie + * - Philip Moss + * - Rob Thomson + * - Romolo Manfredini + * - 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); +}