1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-26 17:55:28 +03:00

Cleanup sonar support for Naze/Flip32/Olimexino. Add Sonar

documentation.
This commit is contained in:
Dominic Clifton 2014-08-13 22:01:39 +01:00
parent 74ef19bc34
commit d0338eac19
8 changed files with 108 additions and 48 deletions

View file

@ -24,6 +24,7 @@
#include "common/axis.h"
#include "drivers/sonar_hcsr04.h"
#include "drivers/gpio.h"
#include "config/runtime_config.h"
#include "config/config.h"
@ -38,12 +39,39 @@ int32_t sonarAlt = -1; // in cm , -1 indicate sonar is not in range
void Sonar_init(void)
{
// 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);
}
#if defined(NAZE)
static const sonarHardware_t const sonarPWM56 = {
.trigger_pin = Pin_8, // PWM5 (PB8) - 5v tolerant
.echo_pin = Pin_9, // PWM6 (PB9) - 5v tolerant
.exti_line = EXTI_Line9,
.exti_pin_source = GPIO_PinSource9,
.exti_irqn = EXTI9_5_IRQn
};
static const sonarHardware_t const sonarRC78 = {
.trigger_pin = Pin_0, // RX7 (PB0) - only 3.3v ( add a 1K Ohms resistor )
.echo_pin = Pin_1, // RX8 (PB1) - only 3.3v ( add a 1K Ohms resistor )
.exti_line = EXTI_Line1,
.exti_pin_source = GPIO_PinSource1,
.exti_irqn = EXTI1_IRQn
};
// 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(&sonarPWM56);
} else {
hcsr04_init(&sonarRC78);
}
#elif defined(OLIMEXINO)
static const sonarHardware_t const sonarHardware = {
.trigger_pin = Pin_0, // RX7 (PB0) - only 3.3v ( add a 1K Ohms resistor )
.echo_pin = Pin_1, // RX8 (PB1) - only 3.3v ( add a 1K Ohms resistor )
.exti_line = EXTI_Line1,
.exti_pin_source = GPIO_PinSource1,
.exti_irqn = EXTI1_IRQn
};
hcsr04_init(&sonarHardware);
#else
#error Sonar not defined for target
#endif
sensorsSet(SENSOR_SONAR);
sonarAlt = 0;