Bugfix when using sonar as well as rx-parallel-pwm

This allows sonar to be used at the same time as parallel PWM for the receiver.  If the RX_PARALLEL_PWM feature is enabled, then the sonar system uses motor ports 5 and 6, otherwise it uses receiver pins 7 and 8.
This commit is contained in:
Ben Hitchcock 2014-08-08 23:30:25 +08:00 committed by Dominic Clifton
parent 95852d0bdf
commit 74ef19bc34
3 changed files with 10 additions and 7 deletions

View File

@ -464,10 +464,6 @@ void validateAndFixConfig(void)
featureClear(FEATURE_RSSI_ADC);
// current meter needs the same ports
featureClear(FEATURE_CURRENT_METER);
#ifdef SONAR
// sonar needs a free PWM port
featureClear(FEATURE_SONAR);
#endif
#endif
#if defined(STM32F10X_MD) || defined(CHEBUZZ) || defined(STM32F3DISCOVERY)

View File

@ -88,8 +88,8 @@ void hcsr04_init(sonar_config_t config)
gpio_config_t gpio;
EXTI_InitTypeDef EXTIInit;
// enable AFIO for EXTI support - already done is drv_system.c
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph, ENABLE);
// enable AFIO for EXTI support
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
switch (config) {
case sonar_pwm56:

View File

@ -25,6 +25,7 @@
#include "drivers/sonar_hcsr04.h"
#include "config/runtime_config.h"
#include "config/config.h"
#include "flight/flight.h"
@ -37,7 +38,13 @@ int32_t sonarAlt = -1; // in cm , -1 indicate sonar is not in range
void Sonar_init(void)
{
hcsr04_init(sonar_rc78);
// If we are using parallel PWM for our receiver, then use motor pins 5 and 6 for sonar, otherwise use rc pins 7 and 8
if (feature(FEATURE_RX_PARALLEL_PWM)) {
hcsr04_init(sonar_pwm56);
} else {
hcsr04_init(sonar_rc78);
}
sensorsSet(SENSOR_SONAR);
sonarAlt = 0;
}