From c9ae9644283a8d6f62e4a6852b91d2253363e1d0 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 20 Jan 2016 21:40:53 +0100 Subject: [PATCH] [Horus] Haptic now OK --- radio/src/CMakeLists.txt | 2 +- radio/src/audio_arm.h | 2 +- radio/src/opentx.cpp | 4 +--- radio/src/opentx.h | 1 - radio/src/targets/horus/board_horus.h | 1 + radio/src/targets/horus/hal.h | 6 +++--- radio/src/targets/horus/haptic_driver.cpp | 18 ++++++++++++------ .../horus/{pwr_driver.c => pwr_driver.cpp} | 3 +++ 8 files changed, 22 insertions(+), 15 deletions(-) rename radio/src/targets/horus/{pwr_driver.c => pwr_driver.cpp} (95%) diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index 100bd9b14..80241ea5d 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -83,7 +83,7 @@ if(PCB STREQUAL HORUS) lcd_driver.cpp delays.c usb_driver.c - pwr_driver.c + pwr_driver.cpp sdram_driver.c led_driver.cpp ) diff --git a/radio/src/audio_arm.h b/radio/src/audio_arm.h index 94f565171..799747673 100644 --- a/radio/src/audio_arm.h +++ b/radio/src/audio_arm.h @@ -55,7 +55,7 @@ enum AudioBufferState typedef uint16_t audio_data_t; #define AUDIO_DATA_SILENCE 0x8000 #define AUDIO_DATA_MIN 0 - #define AUDIO_DATA_MAX UINT16_MAX + #define AUDIO_DATA_MAX 0xffff #define AUDIO_BITS_PER_SAMPLE 16 #elif defined(PCBHORUS) typedef int16_t audio_data_t; diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index c1615f3a8..a90802870 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1996,7 +1996,7 @@ void opentxClose() } #endif -#if !defined(PCBTARANIS) +#if !defined(PCBTARANIS) && !defined(COLORLCD) if (storageDirtyMsk & EE_MODEL) { displayPopup(STR_SAVEMODEL); } @@ -2021,8 +2021,6 @@ void opentxClose() } #endif - - #if defined(NAVIGATION_STICKS) uint8_t getSticksNavigationEvent() { diff --git a/radio/src/opentx.h b/radio/src/opentx.h index fc51d327b..b33b2b577 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -25,7 +25,6 @@ #include #include #include -#include #if defined(SIMU) #define SWITCH_SIMU(a, b) (a) diff --git a/radio/src/targets/horus/board_horus.h b/radio/src/targets/horus/board_horus.h index a515d09e0..80d33ec40 100644 --- a/radio/src/targets/horus/board_horus.h +++ b/radio/src/targets/horus/board_horus.h @@ -291,6 +291,7 @@ void sportSendBuffer(uint8_t *buffer, uint32_t count); // Haptic driver void hapticInit(void); +void hapticDone(void); void hapticOff(void); #define HAPTIC_OFF() hapticOff() void hapticOn(uint32_t pwmPercent); diff --git a/radio/src/targets/horus/hal.h b/radio/src/targets/horus/hal.h index 7335a802e..c1bd3bde9 100644 --- a/radio/src/targets/horus/hal.h +++ b/radio/src/targets/horus/hal.h @@ -245,11 +245,11 @@ // Haptic #define HAPTIC_RCC_AHB1Periph RCC_AHB1Periph_GPIOA -#define HAPTIC_RCC_APB2Periph RCC_APB2ENR_TIM11EN +#define HAPTIC_RCC_APB2Periph RCC_APB2ENR_TIM9EN #define HAPTIC_GPIO GPIOA #define HAPTIC_GPIO_PIN GPIO_Pin_2 -#define HAPTIC_GPIO_TIMER TIM11 -#define HAPTIC_GPIO_AF GPIO_AF_TIM11 +#define HAPTIC_GPIO_TIMER TIM9 +#define HAPTIC_GPIO_AF GPIO_AF_TIM9 #define HAPTIC_GPIO_PinSource GPIO_PinSource2 // Internal Module diff --git a/radio/src/targets/horus/haptic_driver.cpp b/radio/src/targets/horus/haptic_driver.cpp index b6a276103..a097575c8 100644 --- a/radio/src/targets/horus/haptic_driver.cpp +++ b/radio/src/targets/horus/haptic_driver.cpp @@ -45,12 +45,18 @@ void hapticInit(void) GPIO_PinAFConfig(HAPTIC_GPIO, HAPTIC_GPIO_PinSource, HAPTIC_GPIO_AF); - HAPTIC_GPIO_TIMER->ARR = 100 ; + HAPTIC_GPIO_TIMER->ARR = 100; HAPTIC_GPIO_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 10000 - 1; - HAPTIC_GPIO_TIMER->CCMR1 = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 ; // PWM - HAPTIC_GPIO_TIMER->CCER = TIM_CCER_CC1E ; + HAPTIC_GPIO_TIMER->CCMR1 = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2; // PWM + HAPTIC_GPIO_TIMER->CCER = TIM_CCER_CC1E; - HAPTIC_GPIO_TIMER->CCR1 = 0 ; - HAPTIC_GPIO_TIMER->EGR = 0 ; - HAPTIC_GPIO_TIMER->CR1 = TIM_CR1_CEN ; // Counter enable + HAPTIC_GPIO_TIMER->CCR1 = 0; + HAPTIC_GPIO_TIMER->EGR = 0; + HAPTIC_GPIO_TIMER->CR1 = TIM_CR1_CEN; // counter enable +} + +void hapticDone(void) +{ + hapticOff(); + RCC_AHB1PeriphClockCmd(HAPTIC_RCC_AHB1Periph, DISABLE); } diff --git a/radio/src/targets/horus/pwr_driver.c b/radio/src/targets/horus/pwr_driver.cpp similarity index 95% rename from radio/src/targets/horus/pwr_driver.c rename to radio/src/targets/horus/pwr_driver.cpp index 81192c99d..e04fc8dec 100644 --- a/radio/src/targets/horus/pwr_driver.c +++ b/radio/src/targets/horus/pwr_driver.cpp @@ -64,6 +64,9 @@ void pwrOff() GPIO_Init(AUDIO_SHUTDOWN_GPIO, &GPIO_InitStructure); GPIO_ResetBits(AUDIO_SHUTDOWN_GPIO, AUDIO_SHUTDOWN_GPIO_PIN); + // Shutdown the Haptic + hapticDone(); + GPIO_ResetBits(PWR_GPIO, PWR_GPIO_PIN_ON); }