From 5c0b8fcb2d16ad6ffe99e27f34c8537d49999b55 Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Wed, 23 Apr 2014 13:18:17 +0200 Subject: [PATCH 1/6] Haptic support --- radio/src/Makefile | 6 ++ radio/src/haptic.cpp | 8 +-- radio/src/opentx.h | 15 ----- radio/src/targets/gruvin9x/board_gruvin9x.h | 3 +- radio/src/targets/mega2560/board_mega2560.h | 2 + radio/src/targets/sky9x/board_sky9x.h | 3 +- radio/src/targets/stock/board_stock.h | 4 ++ radio/src/targets/taranis/board_taranis.cpp | 8 +++ radio/src/targets/taranis/board_taranis.h | 7 ++ radio/src/targets/taranis/hal.h | 11 ++++ radio/src/targets/taranis/haptic_driver.cpp | 71 +++++++++++++++++++++ 11 files changed, 117 insertions(+), 21 deletions(-) create mode 100644 radio/src/targets/taranis/haptic_driver.cpp 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..158d8ca57 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(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--; } 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..a38cecff1 100644 --- a/radio/src/targets/gruvin9x/board_gruvin9x.h +++ b/radio/src/targets/gruvin9x/board_gruvin9x.h @@ -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 diff --git a/radio/src/targets/mega2560/board_mega2560.h b/radio/src/targets/mega2560/board_mega2560.h index 5943e87c4..42bb029f8 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..237435f9b 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..497232ad0 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..a84dff53e 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); +} From c22ee587cdd970893aa886aa50da8126df46c99e Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Wed, 23 Apr 2014 15:03:17 +0200 Subject: [PATCH 2/6] Enable haptic fields for Taranis, add option for revisions < REVPLUS --- companion/src/firmwares/opentx/opentxinterface.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index 13b7c86f5..741396fbc 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -558,10 +558,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; @@ -572,10 +569,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: @@ -1218,6 +1212,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); @@ -1228,6 +1223,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); From 5c4f70469608a614e5ed547f20d72e43617f92ea Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Wed, 23 Apr 2014 13:59:30 +0200 Subject: [PATCH 3/6] Typo --- radio/src/haptic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/haptic.cpp b/radio/src/haptic.cpp index 158d8ca57..3cbaf4cf4 100644 --- a/radio/src/haptic.cpp +++ b/radio/src/haptic.cpp @@ -54,7 +54,7 @@ void hapticQueue::heartbeat() #else if (buzzTimeLeft > 0) { buzzTimeLeft--; // time gets counted down -#if defined(PCBSXY9X) || (defined(PCBTARANIS) && defined(REVPLUS)) +#if defined(PCBSKY9X) || (defined(PCBTARANIS) && defined(REVPLUS)) hapticOn(g_eeGeneral.hapticStrength * 20); #else if (hapticTick-- > 0) { From 225ea5d63dec03fbcd0656a32e3fa12eb5fb8bee Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Wed, 23 Apr 2014 13:49:10 +0200 Subject: [PATCH 4/6] Gruvin is an m2560 --- radio/src/targets/gruvin9x/board_gruvin9x.h | 1 + 1 file changed, 1 insertion(+) diff --git a/radio/src/targets/gruvin9x/board_gruvin9x.h b/radio/src/targets/gruvin9x/board_gruvin9x.h index a38cecff1..73ddc822f 100644 --- a/radio/src/targets/gruvin9x/board_gruvin9x.h +++ b/radio/src/targets/gruvin9x/board_gruvin9x.h @@ -185,6 +185,7 @@ 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) From db1336522e4bd5ff08397a8762df08e037f8fc70 Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Mon, 28 Apr 2014 12:54:08 +0200 Subject: [PATCH 5/6] Cosmetics --- radio/src/haptic.cpp | 6 +++--- radio/src/targets/gruvin9x/board_gruvin9x.h | 4 ++-- radio/src/targets/mega2560/board_mega2560.h | 4 ++-- radio/src/targets/sky9x/board_sky9x.h | 2 +- radio/src/targets/stock/board_stock.h | 4 ++-- radio/src/targets/taranis/board_taranis.h | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/radio/src/haptic.cpp b/radio/src/haptic.cpp index 3cbaf4cf4..ec0139795 100644 --- a/radio/src/haptic.cpp +++ b/radio/src/haptic.cpp @@ -58,16 +58,16 @@ void hapticQueue::heartbeat() hapticOn(g_eeGeneral.hapticStrength * 20); #else if (hapticTick-- > 0) { - HAPTIC_ON; + HAPTIC_ON(); } else { - HAPTIC_OFF; + HAPTIC_OFF(); hapticTick = g_eeGeneral.hapticStrength; } #endif } else { - HAPTIC_OFF; + HAPTIC_OFF(); if (buzzPause > 0) { buzzPause--; } diff --git a/radio/src/targets/gruvin9x/board_gruvin9x.h b/radio/src/targets/gruvin9x/board_gruvin9x.h index 73ddc822f..f44ba4ba6 100644 --- a/radio/src/targets/gruvin9x/board_gruvin9x.h +++ b/radio/src/targets/gruvin9x/board_gruvin9x.h @@ -186,8 +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) +#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 42bb029f8..dcaf703de 100644 --- a/radio/src/targets/mega2560/board_mega2560.h +++ b/radio/src/targets/mega2560/board_mega2560.h @@ -189,7 +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) +#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 237435f9b..89d8be49a 100644 --- a/radio/src/targets/sky9x/board_sky9x.h +++ b/radio/src/targets/sky9x/board_sky9x.h @@ -239,7 +239,7 @@ extern int8_t Coproc_maxtemp; // Haptic driver void hapticOff(void); void hapticOn(uint32_t pwmPercent); -#define HAPTIC_OFF hapticOff() +#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 497232ad0..e0f7b33c7 100644 --- a/radio/src/targets/stock/board_stock.h +++ b/radio/src/targets/stock/board_stock.h @@ -231,8 +231,8 @@ void rotencPoll(); #endif // Haptic -#define HAPTIC_ON PORTG |= (1 << OUT_G_HAPTIC) -#define HAPTIC_OFF PORTG &= ~(1 << OUT_G_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.h b/radio/src/targets/taranis/board_taranis.h index a84dff53e..dd697079a 100644 --- a/radio/src/targets/taranis/board_taranis.h +++ b/radio/src/targets/taranis/board_taranis.h @@ -243,8 +243,8 @@ void debugPutc(const char c); void hapticOff(void); void hapticOn(uint32_t pwmPercent); void hapticInit(void); -#define HAPTIC_OFF hapticOff() -#define HAPTIC_ON hapticOn(100) +#define HAPTIC_OFF() hapticOff() +#define HAPTIC_ON() hapticOn(100) extern uint8_t currentTrainerMode; From 937481d7618beb4b2b3f866880961f0f8caf31e4 Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Mon, 28 Apr 2014 22:37:06 +0200 Subject: [PATCH 6/6] Haptic in Taranis simu --- companion/src/firmwares/opentx/opentxTaranisSimulator.cpp | 3 +++ 1 file changed, 3 insertions(+) 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"