From faa6cd7a3c9edf13e0c5349f701bd2633e9d6ff2 Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Wed, 23 Apr 2014 13:18:17 +0200 Subject: [PATCH] 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 110f03c04..ef34d18b1 100644 --- a/radio/src/Makefile +++ b/radio/src/Makefile @@ -703,6 +703,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); +}