Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rangefinder vl53l1x #6572

Merged
merged 4 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ main_sources(COMMON_SRC
drivers/rangefinder/rangefinder_srf10.h
drivers/rangefinder/rangefinder_vl53l0x.c
drivers/rangefinder/rangefinder_vl53l0x.h
drivers/rangefinder/rangefinder_vl53l1x.c
drivers/rangefinder/rangefinder_vl53l1x.h
drivers/rangefinder/rangefinder_virtual.c
drivers/rangefinder/rangefinder_virtual.h

Expand Down
1 change: 1 addition & 0 deletions src/main/drivers/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ typedef enum {
DEVHW_SRF10,
DEVHW_HCSR04_I2C, // DIY-style adapter
DEVHW_VL53L0X,
DEVHW_VL53L1X,

/* Other hardware */
DEVHW_MS4525, // Pitot meter
Expand Down
1,693 changes: 1,693 additions & 0 deletions src/main/drivers/rangefinder/rangefinder_vl53l1x.c

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions src/main/drivers/rangefinder/rangefinder_vl53l1x.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* This file is part of INAV.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU General Public License Version 3, as described below:
*
* This file is free software: you may copy, redistribute and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This file 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

#pragma once

#define RANGEFINDER_VL53L1X_TASK_PERIOD_MS (40)

bool vl53l1xDetect(rangefinderDev_t *dev);
2 changes: 1 addition & 1 deletion src/main/fc/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tables:
values: ["NONE", "AUTO", "ADXL345", "MPU6050", "MMA845x", "BMA280", "LSM303DLHC", "MPU6000", "MPU6500", "MPU9250", "BMI160", "ICM20689", "FAKE"]
enum: accelerationSensor_e
- name: rangefinder_hardware
values: ["NONE", "HCSR04", "SRF10", "INAV_I2C", "VL53L0X", "MSP", "UNUSED", "BENEWAKE"]
values: ["NONE", "HCSR04", "SRF10", "INAV_I2C", "VL53L0X", "MSP", "UNUSED", "BENEWAKE", "VL53L1X"]
enum: rangefinderType_e
- name: mag_hardware
values: ["NONE", "AUTO", "HMC5883", "AK8975", "GPSMAG", "MAG3110", "AK8963", "IST8310", "QMC5883", "MPU9250", "IST8308", "LIS3MDL", "MSP", "FAKE"]
Expand Down
10 changes: 10 additions & 0 deletions src/main/sensors/rangefinder.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "drivers/rangefinder/rangefinder_srf10.h"
#include "drivers/rangefinder/rangefinder_hcsr04_i2c.h"
#include "drivers/rangefinder/rangefinder_vl53l0x.h"
#include "drivers/rangefinder/rangefinder_vl53l1x.h"
#include "drivers/rangefinder/rangefinder_virtual.h"

#include "fc/config.h"
Expand Down Expand Up @@ -131,6 +132,15 @@ static bool rangefinderDetect(rangefinderDev_t * dev, uint8_t rangefinderHardwar
#endif
break;

case RANGEFINDER_VL53L1X:
#if defined(USE_RANGEFINDER_VL53L1X)
if (vl53l1xDetect(dev)) {
rangefinderHardware = RANGEFINDER_VL53L1X;
rescheduleTask(TASK_RANGEFINDER, TASK_PERIOD_MS(RANGEFINDER_VL53L1X_TASK_PERIOD_MS));
}
#endif
break;

case RANGEFINDER_MSP:
#if defined(USE_RANGEFINDER_MSP)
if (virtualRangefinderDetect(dev, &rangefinderMSPVtable)) {
Expand Down
1 change: 1 addition & 0 deletions src/main/sensors/rangefinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef enum {
RANGEFINDER_MSP = 5,
RANGEFINDER_UNUSED = 6, // Was UIB
RANGEFINDER_BENEWAKE = 7,
RANGEFINDER_VL53L1X = 8,
} rangefinderType_e;

typedef struct rangefinderConfig_s {
Expand Down
1 change: 1 addition & 0 deletions src/main/target/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
#define USE_RANGEFINDER_MSP
#define USE_RANGEFINDER_BENEWAKE
#define USE_RANGEFINDER_VL53L0X
#define USE_RANGEFINDER_VL53L1X
#define USE_RANGEFINDER_HCSR04_I2C

// Allow default optic flow boards
Expand Down
9 changes: 9 additions & 0 deletions src/main/target/common_hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@
#endif
#endif

#if defined(USE_RANGEFINDER_VL53L1X)
#if !defined(VL53L1X_I2C_BUS) && defined(RANGEFINDER_I2C_BUS)
#define VL53L1X_I2C_BUS RANGEFINDER_I2C_BUS
#endif

#if defined(VL53L1X_I2C_BUS)
BUSDEV_REGISTER_I2C(busdev_vl53l1x, DEVHW_VL53L1X, VL53L1X_I2C_BUS, 0x29, NONE, DEVFLAGS_USE_RAW_REGISTERS, 0);
#endif
#endif

/** AIRSPEED SENSORS **/

Expand Down