mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-30 19:47:50 +08:00
VL53L1X laser ranger driver and sonar module (#2519)
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
<!DOCTYPE module SYSTEM "module.dtd">
|
||||||
|
|
||||||
|
<module name="sonar_vl53l1x" dir="sonar">
|
||||||
|
<doc>
|
||||||
|
<description>
|
||||||
|
VL53L1X laser ranger AGL driver
|
||||||
|
</description>
|
||||||
|
<configure name="SONAR_VL53L1X_I2C_DEV" value="i2c1" description="I2C device to use for the VL53L1X sensor"/>
|
||||||
|
<define name="SONAR_VL53L1X_I2C_ADDR" value="0x52" description="I2C address"/>
|
||||||
|
<define name="SONAR_VL53L1X_OFFSET" value="0" description="sensor offset in mm - default is 0"/>
|
||||||
|
<define name="SONAR_VL53L1X_TIMINGBUDGET_MS" value="100" description="Timing budget per measurement"/>
|
||||||
|
<define name="SONAR_VL53L1X_INTERMEASUREMENT_MS" value="100" description="Time between measurements"/>
|
||||||
|
<define name="SONAR_VL53L1X_DISTANCEMODE" value="2" description="Sensor distance mode"/>
|
||||||
|
<define name="USE_SONAR" value="" description="activate use of sonar in INS extended filter (only rotorcraft)"/>
|
||||||
|
</doc>
|
||||||
|
|
||||||
|
<settings>
|
||||||
|
<dl_settings>
|
||||||
|
<dl_settings name="sonar_vl53l1x">
|
||||||
|
<dl_setting var="sonar_vl53l1x.offset_mm" min="-1000" step="1" max="1000" shortname="offset_mm"/>
|
||||||
|
</dl_settings>
|
||||||
|
</dl_settings>
|
||||||
|
</settings>
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<file name="sonar_vl53l1x.h"/>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<init fun="sonar_vl53l1x_init()"/>
|
||||||
|
<periodic fun="sonar_vl53l1x_read()" period="0.020"/>
|
||||||
|
|
||||||
|
<makefile target="ap|sim">
|
||||||
|
<file name="sonar_vl53l1x.c"/>
|
||||||
|
</makefile>
|
||||||
|
<makefile target="ap">
|
||||||
|
<configure name="SONAR_VL53L1X_I2C_DEV" default="i2c1" case="lower|upper"/>
|
||||||
|
<define name="SONAR_VL53L1X_I2C_DEV" value="$(SONAR_VL53L1X_I2C_DEV_LOWER)"/>
|
||||||
|
<define name="USE_$(SONAR_VL53L1X_I2C_DEV_UPPER)"/>
|
||||||
|
<file name="vl53l1_platform.c" dir="peripherals"/>
|
||||||
|
<file name="vl53l1x_api.c" dir="peripherals"/>
|
||||||
|
<file name="vl53l1x_nonblocking.c" dir="peripherals"/>
|
||||||
|
</makefile>
|
||||||
|
|
||||||
|
</module>
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Tom van Dijk <tomvand@users.noreply.github.com>
|
||||||
|
*
|
||||||
|
* This file is part of paparazzi.
|
||||||
|
*
|
||||||
|
* paparazzi is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sonar_vl53l1x.h"
|
||||||
|
|
||||||
|
#include "mcu_periph/i2c.h"
|
||||||
|
#include "peripherals/vl53l1x_nonblocking.h"
|
||||||
|
#include "subsystems/abi.h"
|
||||||
|
|
||||||
|
#ifdef SITL
|
||||||
|
#include "state.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "subsystems/datalink/downlink.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SONAR_VL53L1X_I2C_ADDR
|
||||||
|
#define SONAR_VL53L1X_I2C_ADDR 0x52
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Signed distance offset in mm
|
||||||
|
#ifndef SONAR_VL53L1X_OFFSET
|
||||||
|
#define SONAR_VL53L1X_OFFSET 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* VL53L1X configuration */
|
||||||
|
// Time budget for single measurement
|
||||||
|
// Allowed values: 15, 20, 33, 50, 100, 200, 500
|
||||||
|
// see VL53L1X_SetTimingBudgetInMs
|
||||||
|
#ifndef SONAR_VL53L1X_TIMINGBUDGET_MS
|
||||||
|
#define SONAR_VL53L1X_TIMINGBUDGET_MS 100
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Allowed values: 1 (short, max ~1.3m), 2 (long, max ~4m)
|
||||||
|
// see VL53L1X_SetDistanceMode
|
||||||
|
#ifndef SONAR_VL53L1X_DISTANCEMODE
|
||||||
|
#define SONAR_VL53L1X_DISTANCEMODE 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Time between measurements
|
||||||
|
// Should be larger than or equal to timing budget
|
||||||
|
// see VL53L1X_SetInterMeasurementInMs
|
||||||
|
// Note: may be limited by module periodic frequency
|
||||||
|
#ifndef SONAR_VL53L1X_INTERMEASUREMENT_MS
|
||||||
|
#define SONAR_VL53L1X_INTERMEASUREMENT_MS SONAR_VL53L1X_TIMINGBUDGET_MS
|
||||||
|
#endif
|
||||||
|
#if SONAR_VL53L1X_INTERMEASUREMENT_MS < SONAR_VL53L1X_TIMINGBUDGET_MS
|
||||||
|
#warning SONAR_VL53L1X_INTERMEASUREMENT_MS should be greater than or equal to SONAR_VL53L1X_TIMINGBUDGET_MS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
struct sonar_vl53l1x_dev sonar_vl53l1x;
|
||||||
|
|
||||||
|
|
||||||
|
static void sonar_vl53l1x_publish(uint16_t range_mm)
|
||||||
|
{
|
||||||
|
float range_ofs_m = (range_mm + sonar_vl53l1x.offset_mm) * 1.0e-3f;
|
||||||
|
|
||||||
|
// Send ABI message
|
||||||
|
uint32_t now_ts = get_sys_time_usec();
|
||||||
|
AbiSendMsgAGL(AGL_VL53L1X_ID, now_ts, range_ofs_m);
|
||||||
|
|
||||||
|
#ifdef SENSOR_SYNC_SEND_SONAR
|
||||||
|
// Send Telemetry report
|
||||||
|
DOWNLINK_SEND_SONAR(DefaultChannel, DefaultDevice, &range_mm, &range_ofs_m);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void sonar_vl53l1x_init(void)
|
||||||
|
{
|
||||||
|
// Set up structs
|
||||||
|
sonar_vl53l1x.dev.i2c_p = &SONAR_VL53L1X_I2C_DEV;
|
||||||
|
sonar_vl53l1x.dev.i2c_trans.slave_addr = SONAR_VL53L1X_I2C_ADDR;
|
||||||
|
sonar_vl53l1x.offset_mm = SONAR_VL53L1X_OFFSET;
|
||||||
|
|
||||||
|
/* Initialize sensor */
|
||||||
|
#ifndef SITL
|
||||||
|
uint8_t state;
|
||||||
|
do {
|
||||||
|
VL53L1X_BootState(&sonar_vl53l1x.dev, &state);
|
||||||
|
} while (!state);
|
||||||
|
VL53L1X_SensorInit(&sonar_vl53l1x.dev);
|
||||||
|
/* Configure sensor */
|
||||||
|
VL53L1X_SetTimingBudgetInMs(&sonar_vl53l1x.dev, SONAR_VL53L1X_TIMINGBUDGET_MS);
|
||||||
|
VL53L1X_SetDistanceMode(&sonar_vl53l1x.dev, SONAR_VL53L1X_DISTANCEMODE);
|
||||||
|
VL53L1X_SetInterMeasurementInMs(&sonar_vl53l1x.dev, SONAR_VL53L1X_INTERMEASUREMENT_MS);
|
||||||
|
/* Start measurement */
|
||||||
|
VL53L1X_StartRanging(&sonar_vl53l1x.dev);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void sonar_vl53l1x_read(void)
|
||||||
|
{
|
||||||
|
#ifndef SITL
|
||||||
|
uint8_t isDataReady;
|
||||||
|
uint16_t range_mm;
|
||||||
|
switch (sonar_vl53l1x.read_state) {
|
||||||
|
case 0:
|
||||||
|
// Wait for data ready
|
||||||
|
if (!VL53L1X_NonBlocking_CheckForDataReady(&sonar_vl53l1x.dev, &isDataReady)) { return; } // Check in progress
|
||||||
|
sonar_vl53l1x.read_state++;
|
||||||
|
/* Falls through. */
|
||||||
|
case 1:
|
||||||
|
// Get ranging data
|
||||||
|
if (!VL53L1X_NonBlocking_GetDistance(&sonar_vl53l1x.dev, &range_mm)) { return; } // Read in progress
|
||||||
|
sonar_vl53l1x_publish(range_mm);
|
||||||
|
sonar_vl53l1x.read_state++;
|
||||||
|
/* Falls through. */
|
||||||
|
case 2:
|
||||||
|
// Clear interrupt
|
||||||
|
if (!VL53L1X_NonBlocking_ClearInterrupt(&sonar_vl53l1x.dev)) { return; } // Clear in progress
|
||||||
|
sonar_vl53l1x.read_state = 0;
|
||||||
|
break;
|
||||||
|
default: return;
|
||||||
|
}
|
||||||
|
#else // SITL
|
||||||
|
float range_mm = stateGetPositionEnu_f()->z * 1.0e3f;
|
||||||
|
if (range_mm > 0.0f && range_mm < 5.0f) {
|
||||||
|
sonar_vl53l1x_publish(range_mm)
|
||||||
|
}
|
||||||
|
#endif // SITL
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Tom van Dijk <tomvand@users.noreply.github.com>
|
||||||
|
*
|
||||||
|
* This file is part of paparazzi.
|
||||||
|
*
|
||||||
|
* paparazzi is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SONAR_VL53L1X_H
|
||||||
|
#define SONAR_VL53L1X_H
|
||||||
|
|
||||||
|
#include "peripherals/vl53l1x_api.h"
|
||||||
|
|
||||||
|
struct sonar_vl53l1x_dev {
|
||||||
|
VL53L1_Dev_t dev;
|
||||||
|
int16_t offset_mm;
|
||||||
|
uint8_t read_state;
|
||||||
|
};
|
||||||
|
extern struct sonar_vl53l1x_dev sonar_vl53l1x;
|
||||||
|
|
||||||
|
extern void sonar_vl53l1x_init(void);
|
||||||
|
extern void sonar_vl53l1x_read(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of VL53L1 Platform
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
|
||||||
|
*
|
||||||
|
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "vl53l1_platform.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
int8_t VL53L1_WriteMulti(VL53L1_DEV dev, uint16_t index, uint8_t *pdata, uint32_t count)
|
||||||
|
{
|
||||||
|
assert(2 + count <= I2C_BUF_LEN);
|
||||||
|
dev->i2c_trans.buf[0] = (index & 0xFF00) >> 8; // MSB first
|
||||||
|
dev->i2c_trans.buf[1] = (index & 0x00FF);
|
||||||
|
memcpy((uint8_t *) dev->i2c_trans.buf + 2, pdata, count);
|
||||||
|
return !i2c_blocking_transmit(dev->i2c_p, &dev->i2c_trans,
|
||||||
|
dev->i2c_trans.slave_addr, 2 + count);
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t VL53L1_ReadMulti(VL53L1_DEV dev, uint16_t index, uint8_t *pdata, uint32_t count)
|
||||||
|
{
|
||||||
|
assert(count <= I2C_BUF_LEN);
|
||||||
|
dev->i2c_trans.buf[0] = (index & 0xFF00) >> 8; // MSB first
|
||||||
|
dev->i2c_trans.buf[1] = (index & 0x00FF);
|
||||||
|
int8_t ret = !i2c_blocking_transceive(dev->i2c_p, &dev->i2c_trans,
|
||||||
|
dev->i2c_trans.slave_addr, 2, count);
|
||||||
|
memcpy(pdata, (uint8_t *) dev->i2c_trans.buf, count);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t VL53L1_WrByte(VL53L1_DEV dev, uint16_t index, uint8_t data)
|
||||||
|
{
|
||||||
|
return VL53L1_WriteMulti(dev, index, &data, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t VL53L1_WrWord(VL53L1_DEV dev, uint16_t index, uint16_t data)
|
||||||
|
{
|
||||||
|
uint8_t data_u8[] = {
|
||||||
|
(data & 0xFF00) >> 8,
|
||||||
|
(data & 0x00FF)
|
||||||
|
};
|
||||||
|
return VL53L1_WriteMulti(dev, index, data_u8, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t VL53L1_WrDWord(VL53L1_DEV dev, uint16_t index, uint32_t data)
|
||||||
|
{
|
||||||
|
uint8_t data_u8[] = {
|
||||||
|
(data & 0xFF000000) >> 24,
|
||||||
|
(data & 0x00FF0000) >> 16,
|
||||||
|
(data & 0x0000FF00) >> 8,
|
||||||
|
(data & 0x000000FF)
|
||||||
|
};
|
||||||
|
return VL53L1_WriteMulti(dev, index, data_u8, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t VL53L1_RdByte(VL53L1_DEV dev, uint16_t index, uint8_t *data)
|
||||||
|
{
|
||||||
|
return VL53L1_ReadMulti(dev, index, data, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t VL53L1_RdWord(VL53L1_DEV dev, uint16_t index, uint16_t *data)
|
||||||
|
{
|
||||||
|
uint8_t data_u8[2];
|
||||||
|
int8_t ret = VL53L1_ReadMulti(dev, index, data_u8, 2);
|
||||||
|
*data = (data_u8[0] << 8) | data_u8[1];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t VL53L1_RdDWord(VL53L1_DEV dev, uint16_t index, uint32_t *data)
|
||||||
|
{
|
||||||
|
uint8_t data_u8[4];
|
||||||
|
int8_t ret = VL53L1_ReadMulti(dev, index, data_u8, 4);
|
||||||
|
*data = (data_u8[0] << 24) |
|
||||||
|
(data_u8[1] << 16) |
|
||||||
|
(data_u8[2] << 8) |
|
||||||
|
(data_u8[3]);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Tom van Dijk <tomvand@users.noreply.github.com>
|
||||||
|
* Adapted from STSW-IMG009 vl53l1_platform.h
|
||||||
|
*
|
||||||
|
* This file is part of paparazzi.
|
||||||
|
*
|
||||||
|
* paparazzi is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file vl53l1_platform.h
|
||||||
|
* @brief Those platform functions are platform dependent and have to be implemented by the user
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _VL53L1_PLATFORM_H_
|
||||||
|
#define _VL53L1_PLATFORM_H_
|
||||||
|
|
||||||
|
#include "vl53l1_types.h"
|
||||||
|
|
||||||
|
#include "mcu_periph/i2c.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
struct i2c_periph *i2c_p;
|
||||||
|
struct i2c_transaction i2c_trans;
|
||||||
|
struct NonBlocking {
|
||||||
|
/* I2C Read/write state machine */
|
||||||
|
uint8_t i2c_state;
|
||||||
|
/* State machine for nonblocking functions */
|
||||||
|
uint8_t state;
|
||||||
|
uint8_t IntPol;
|
||||||
|
} nonblocking;
|
||||||
|
} VL53L1_Dev_t;
|
||||||
|
|
||||||
|
typedef VL53L1_Dev_t *VL53L1_DEV;
|
||||||
|
|
||||||
|
/** @brief VL53L1_WriteMulti() definition.\n
|
||||||
|
* To be implemented by the developer
|
||||||
|
*/
|
||||||
|
int8_t VL53L1_WriteMulti(
|
||||||
|
VL53L1_DEV dev,
|
||||||
|
uint16_t index,
|
||||||
|
uint8_t *pdata,
|
||||||
|
uint32_t count);
|
||||||
|
/** @brief VL53L1_ReadMulti() definition.\n
|
||||||
|
* To be implemented by the developer
|
||||||
|
*/
|
||||||
|
int8_t VL53L1_ReadMulti(
|
||||||
|
VL53L1_DEV dev,
|
||||||
|
uint16_t index,
|
||||||
|
uint8_t *pdata,
|
||||||
|
uint32_t count);
|
||||||
|
/** @brief VL53L1_WrByte() definition.\n
|
||||||
|
* To be implemented by the developer
|
||||||
|
*/
|
||||||
|
int8_t VL53L1_WrByte(
|
||||||
|
VL53L1_DEV dev,
|
||||||
|
uint16_t index,
|
||||||
|
uint8_t data);
|
||||||
|
/** @brief VL53L1_WrWord() definition.\n
|
||||||
|
* To be implemented by the developer
|
||||||
|
*/
|
||||||
|
int8_t VL53L1_WrWord(
|
||||||
|
VL53L1_DEV dev,
|
||||||
|
uint16_t index,
|
||||||
|
uint16_t data);
|
||||||
|
/** @brief VL53L1_WrDWord() definition.\n
|
||||||
|
* To be implemented by the developer
|
||||||
|
*/
|
||||||
|
int8_t VL53L1_WrDWord(
|
||||||
|
VL53L1_DEV dev,
|
||||||
|
uint16_t index,
|
||||||
|
uint32_t data);
|
||||||
|
/** @brief VL53L1_RdByte() definition.\n
|
||||||
|
* To be implemented by the developer
|
||||||
|
*/
|
||||||
|
int8_t VL53L1_RdByte(
|
||||||
|
VL53L1_DEV dev,
|
||||||
|
uint16_t index,
|
||||||
|
uint8_t *pdata);
|
||||||
|
/** @brief VL53L1_RdWord() definition.\n
|
||||||
|
* To be implemented by the developer
|
||||||
|
*/
|
||||||
|
int8_t VL53L1_RdWord(
|
||||||
|
VL53L1_DEV dev,
|
||||||
|
uint16_t index,
|
||||||
|
uint16_t *pdata);
|
||||||
|
/** @brief VL53L1_RdDWord() definition.\n
|
||||||
|
* To be implemented by the developer
|
||||||
|
*/
|
||||||
|
int8_t VL53L1_RdDWord(
|
||||||
|
VL53L1_DEV dev,
|
||||||
|
uint16_t index,
|
||||||
|
uint32_t *pdata);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
Copyright (C) 2015, STMicroelectronics International N.V.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
* Neither the name of STMicroelectronics nor the
|
||||||
|
names of its contributors may be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||||
|
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
********************************************************************************/
|
||||||
|
/**
|
||||||
|
* @file vl53l1_types.h
|
||||||
|
* @brief VL53L1 types definition
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _VL53L1_TYPES_H_
|
||||||
|
#define _VL53L1_TYPES_H_
|
||||||
|
|
||||||
|
/** @defgroup porting_type Basic type definition
|
||||||
|
* @ingroup api_platform
|
||||||
|
*
|
||||||
|
* @brief file vl53l1_types.h files hold basic type definition that may requires porting
|
||||||
|
*
|
||||||
|
* contains type that must be defined for the platform\n
|
||||||
|
* when target platform and compiler provide stdint.h and stddef.h it is enough to include it.\n
|
||||||
|
* If stdint.h is not available review and adapt all signed and unsigned 8/16/32 bits basic types. \n
|
||||||
|
* If stddef.h is not available review and adapt NULL definition .
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifndef NULL
|
||||||
|
#error "Error NULL definition should be done. Please add required include "
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(STDINT_H) && !defined(_STDINT_H) && !defined(_GCC_STDINT_H) && !defined(__STDINT_DECLS) && !defined(_GCC_WRAP_STDINT_H) && !defined(_STDINT)
|
||||||
|
|
||||||
|
#pragma message("Please review type definition of STDINT define for your platform and add to list above ")
|
||||||
|
|
||||||
|
/*
|
||||||
|
* target platform do not provide stdint or use a different #define than above
|
||||||
|
* to avoid seeing the message below addapt the #define list above or implement
|
||||||
|
* all type and delete these pragma
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** \ingroup VL53L1_portingType_group
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
typedef unsigned long long uint64_t;
|
||||||
|
|
||||||
|
|
||||||
|
/** @brief Typedef defining 32 bit unsigned int type.\n
|
||||||
|
* The developer should modify this to suit the platform being deployed.
|
||||||
|
*/
|
||||||
|
typedef unsigned int uint32_t;
|
||||||
|
|
||||||
|
/** @brief Typedef defining 32 bit int type.\n
|
||||||
|
* The developer should modify this to suit the platform being deployed.
|
||||||
|
*/
|
||||||
|
typedef int int32_t;
|
||||||
|
|
||||||
|
/** @brief Typedef defining 16 bit unsigned short type.\n
|
||||||
|
* The developer should modify this to suit the platform being deployed.
|
||||||
|
*/
|
||||||
|
typedef unsigned short uint16_t;
|
||||||
|
|
||||||
|
/** @brief Typedef defining 16 bit short type.\n
|
||||||
|
* The developer should modify this to suit the platform being deployed.
|
||||||
|
*/
|
||||||
|
typedef short int16_t;
|
||||||
|
|
||||||
|
/** @brief Typedef defining 8 bit unsigned char type.\n
|
||||||
|
* The developer should modify this to suit the platform being deployed.
|
||||||
|
*/
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
|
||||||
|
/** @brief Typedef defining 8 bit char type.\n
|
||||||
|
* The developer should modify this to suit the platform being deployed.
|
||||||
|
*/
|
||||||
|
typedef signed char int8_t;
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
#endif /* _STDINT_H */
|
||||||
|
|
||||||
|
|
||||||
|
/** use where fractional values are expected
|
||||||
|
*
|
||||||
|
* Given a floating point value f it's .16 bit point is (int)(f*(1<<16))*/
|
||||||
|
typedef uint32_t FixPoint1616_t;
|
||||||
|
|
||||||
|
#endif /* VL53L1_TYPES_H_ */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,393 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
|
||||||
|
*
|
||||||
|
* This file : part of VL53L1 Core and : dual licensed,
|
||||||
|
* either 'STMicroelectronics
|
||||||
|
* Proprietary license'
|
||||||
|
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||||
|
*
|
||||||
|
********************************************************************************
|
||||||
|
*
|
||||||
|
* 'STMicroelectronics Proprietary license'
|
||||||
|
*
|
||||||
|
********************************************************************************
|
||||||
|
*
|
||||||
|
* License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||||
|
* terms at www.st.com/sla0081
|
||||||
|
*
|
||||||
|
* STMicroelectronics confidential
|
||||||
|
* Reproduction and Communication of this document : strictly prohibited unless
|
||||||
|
* specifically authorized in writing by STMicroelectronics.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
********************************************************************************
|
||||||
|
*
|
||||||
|
* Alternatively, VL53L1 Core may be distributed under the terms of
|
||||||
|
* 'BSD 3-clause "New" or "Revised" License', in which case the following
|
||||||
|
* provisions apply instead of the ones mentioned above :
|
||||||
|
*
|
||||||
|
********************************************************************************
|
||||||
|
*
|
||||||
|
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
********************************************************************************
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file vl53l1x_api.h
|
||||||
|
* @brief Functions definition
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef VL53L1X_API_H_
|
||||||
|
#define VL53L1X_API_H_
|
||||||
|
|
||||||
|
#include "vl53l1_platform.h"
|
||||||
|
|
||||||
|
#define VL53L1X_IMPLEMENTATION_VER_MAJOR 3
|
||||||
|
#define VL53L1X_IMPLEMENTATION_VER_MINOR 3
|
||||||
|
#define VL53L1X_IMPLEMENTATION_VER_SUB 0
|
||||||
|
#define VL53L1X_IMPLEMENTATION_VER_REVISION 0000
|
||||||
|
|
||||||
|
typedef int8_t VL53L1X_ERROR;
|
||||||
|
|
||||||
|
#define SOFT_RESET 0x0000
|
||||||
|
#define VL53L1_I2C_SLAVE__DEVICE_ADDRESS 0x0001
|
||||||
|
#define VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND 0x0008
|
||||||
|
#define ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS 0x0016
|
||||||
|
#define ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS 0x0018
|
||||||
|
#define ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS 0x001A
|
||||||
|
#define ALGO__PART_TO_PART_RANGE_OFFSET_MM 0x001E
|
||||||
|
#define MM_CONFIG__INNER_OFFSET_MM 0x0020
|
||||||
|
#define MM_CONFIG__OUTER_OFFSET_MM 0x0022
|
||||||
|
#define GPIO_HV_MUX__CTRL 0x0030
|
||||||
|
#define GPIO__TIO_HV_STATUS 0x0031
|
||||||
|
#define SYSTEM__INTERRUPT_CONFIG_GPIO 0x0046
|
||||||
|
#define PHASECAL_CONFIG__TIMEOUT_MACROP 0x004B
|
||||||
|
#define RANGE_CONFIG__TIMEOUT_MACROP_A_HI 0x005E
|
||||||
|
#define RANGE_CONFIG__VCSEL_PERIOD_A 0x0060
|
||||||
|
#define RANGE_CONFIG__VCSEL_PERIOD_B 0x0063
|
||||||
|
#define RANGE_CONFIG__TIMEOUT_MACROP_B_HI 0x0061
|
||||||
|
#define RANGE_CONFIG__TIMEOUT_MACROP_B_LO 0x0062
|
||||||
|
#define RANGE_CONFIG__SIGMA_THRESH 0x0064
|
||||||
|
#define RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS 0x0066
|
||||||
|
#define RANGE_CONFIG__VALID_PHASE_HIGH 0x0069
|
||||||
|
#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD 0x006C
|
||||||
|
#define SYSTEM__THRESH_HIGH 0x0072
|
||||||
|
#define SYSTEM__THRESH_LOW 0x0074
|
||||||
|
#define SD_CONFIG__WOI_SD0 0x0078
|
||||||
|
#define SD_CONFIG__INITIAL_PHASE_SD0 0x007A
|
||||||
|
#define ROI_CONFIG__USER_ROI_CENTRE_SPAD 0x007F
|
||||||
|
#define ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE 0x0080
|
||||||
|
#define SYSTEM__SEQUENCE_CONFIG 0x0081
|
||||||
|
#define VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD 0x0082
|
||||||
|
#define SYSTEM__INTERRUPT_CLEAR 0x0086
|
||||||
|
#define SYSTEM__MODE_START 0x0087
|
||||||
|
#define VL53L1_RESULT__RANGE_STATUS 0x0089
|
||||||
|
#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0 0x008C
|
||||||
|
#define RESULT__AMBIENT_COUNT_RATE_MCPS_SD 0x0090
|
||||||
|
#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 0x0096
|
||||||
|
#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0 0x0098
|
||||||
|
#define VL53L1_RESULT__OSC_CALIBRATE_VAL 0x00DE
|
||||||
|
#define VL53L1_FIRMWARE__SYSTEM_STATUS 0x00E5
|
||||||
|
#define VL53L1_IDENTIFICATION__MODEL_ID 0x010F
|
||||||
|
#define VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD 0x013E
|
||||||
|
|
||||||
|
/****************************************
|
||||||
|
* PRIVATE define do not edit
|
||||||
|
****************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief defines SW Version
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint8_t major; /*!< major number */
|
||||||
|
uint8_t minor; /*!< minor number */
|
||||||
|
uint8_t build; /*!< build number */
|
||||||
|
uint32_t revision; /*!< revision number */
|
||||||
|
} VL53L1X_Version_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief defines packed reading results type
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint8_t Status; /*!< ResultStatus */
|
||||||
|
uint16_t Distance; /*!< ResultDistance */
|
||||||
|
uint16_t Ambient; /*!< ResultAmbient */
|
||||||
|
uint16_t SigPerSPAD;/*!< ResultSignalPerSPAD */
|
||||||
|
uint16_t NumSPADs; /*!< ResultNumSPADs */
|
||||||
|
} VL53L1X_Result_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the SW driver version
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetSWVersion(VL53L1X_Version_t *pVersion);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function sets the sensor I2C address used in case multiple devices application, default address 0x52
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_SetI2CAddress(VL53L1_DEV, uint8_t new_address);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function loads the 135 bytes default values to initialize the sensor.
|
||||||
|
* @param dev Device address
|
||||||
|
* @return 0:success, != 0:failed
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_SensorInit(VL53L1_DEV dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function clears the interrupt, to be called after a ranging data reading
|
||||||
|
* to arm the interrupt for the next data ready event.
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_ClearInterrupt(VL53L1_DEV dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function programs the interrupt polarity\n
|
||||||
|
* 1=active high (default), 0=active low
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_SetInterruptPolarity(VL53L1_DEV dev, uint8_t IntPol);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the current interrupt polarity\n
|
||||||
|
* 1=active high (default), 0=active low
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetInterruptPolarity(VL53L1_DEV dev, uint8_t *pIntPol);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function starts the ranging distance operation\n
|
||||||
|
* The ranging operation is continuous. The clear interrupt has to be done after each get data to allow the interrupt to raise when the next data is ready\n
|
||||||
|
* 1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required.
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_StartRanging(VL53L1_DEV dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function stops the ranging.
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_StopRanging(VL53L1_DEV dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function checks if the new ranging data is available by polling the dedicated register.
|
||||||
|
* @param : isDataReady==0 -> not ready; isDataReady==1 -> ready
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_CheckForDataReady(VL53L1_DEV dev, uint8_t *isDataReady);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function programs the timing budget in ms.
|
||||||
|
* Predefined values = 15, 20, 33, 50, 100(default), 200, 500.
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_SetTimingBudgetInMs(VL53L1_DEV dev, uint16_t TimingBudgetInMs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the current timing budget in ms.
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetTimingBudgetInMs(VL53L1_DEV dev, uint16_t *pTimingBudgetInMs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function programs the distance mode (1=short, 2=long(default)).
|
||||||
|
* Short mode max distance is limited to 1.3 m but better ambient immunity.\n
|
||||||
|
* Long mode can range up to 4 m in the dark with 200 ms timing budget.
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_SetDistanceMode(VL53L1_DEV dev, uint16_t DistanceMode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the current distance mode (1=short, 2=long).
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetDistanceMode(VL53L1_DEV dev, uint16_t *pDistanceMode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function programs the Intermeasurement period in ms\n
|
||||||
|
* Intermeasurement period must be >/= timing budget. This condition is not checked by the API,
|
||||||
|
* the customer has the duty to check the condition. Default = 100 ms
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_SetInterMeasurementInMs(VL53L1_DEV dev,
|
||||||
|
uint32_t InterMeasurementInMs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the Intermeasurement period in ms.
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetInterMeasurementInMs(VL53L1_DEV dev, uint16_t *pIM);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the boot state of the device (1:booted, 0:not booted)
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_BootState(VL53L1_DEV dev, uint8_t *state);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the sensor id, sensor Id must be 0xEEAC
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetSensorId(VL53L1_DEV dev, uint16_t *id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the distance measured by the sensor in mm
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetDistance(VL53L1_DEV dev, uint16_t *distance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the returned signal per SPAD in kcps/SPAD.
|
||||||
|
* With kcps stands for Kilo Count Per Second
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetSignalPerSpad(VL53L1_DEV dev, uint16_t *signalPerSp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the ambient per SPAD in kcps/SPAD
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetAmbientPerSpad(VL53L1_DEV dev, uint16_t *amb);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the returned signal in kcps.
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetSignalRate(VL53L1_DEV dev, uint16_t *signalRate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the current number of enabled SPADs
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetSpadNb(VL53L1_DEV dev, uint16_t *spNb);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the ambient rate in kcps
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetAmbientRate(VL53L1_DEV dev, uint16_t *ambRate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the ranging status error \n
|
||||||
|
* (0:no error, 1:sigma failed, 2:signal failed, ..., 7:wrap-around)
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetRangeStatus(VL53L1_DEV dev, uint8_t *rangeStatus);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns measurements and the range status in a single read access
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetResult(VL53L1_DEV dev, VL53L1X_Result_t *pResult);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function programs the offset correction in mm
|
||||||
|
* @param OffsetValue:the offset correction value to program in mm
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_SetOffset(VL53L1_DEV dev, int16_t OffsetValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the programmed offset correction value in mm
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetOffset(VL53L1_DEV dev, int16_t *Offset);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function programs the xtalk correction value in cps (Count Per Second).\n
|
||||||
|
* This is the number of photons reflected back from the cover glass in cps.
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_SetXtalk(VL53L1_DEV dev, uint16_t XtalkValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the current programmed xtalk correction value in cps
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetXtalk(VL53L1_DEV dev, uint16_t *Xtalk);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function programs the threshold detection mode\n
|
||||||
|
* Example:\n
|
||||||
|
* VL53L1X_SetDistanceThreshold(dev,100,300,0,1): Below 100 \n
|
||||||
|
* VL53L1X_SetDistanceThreshold(dev,100,300,1,1): Above 300 \n
|
||||||
|
* VL53L1X_SetDistanceThreshold(dev,100,300,2,1): Out of window \n
|
||||||
|
* VL53L1X_SetDistanceThreshold(dev,100,300,3,1): In window \n
|
||||||
|
* @param dev : device address
|
||||||
|
* @param ThreshLow(in mm) : the threshold under which one the device raises an interrupt if Window = 0
|
||||||
|
* @param ThreshHigh(in mm) : the threshold above which one the device raises an interrupt if Window = 1
|
||||||
|
* @param Window detection mode : 0=below, 1=above, 2=out, 3=in
|
||||||
|
* @param IntOnNoTarget = 1 (No longer used - just use 1)
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_SetDistanceThreshold(VL53L1_DEV dev, uint16_t ThreshLow,
|
||||||
|
uint16_t ThreshHigh, uint8_t Window,
|
||||||
|
uint8_t IntOnNoTarget);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the window detection mode (0=below; 1=above; 2=out; 3=in)
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetDistanceThresholdWindow(VL53L1_DEV dev, uint16_t *window);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the low threshold in mm
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetDistanceThresholdLow(VL53L1_DEV dev, uint16_t *low);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the high threshold in mm
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetDistanceThresholdHigh(VL53L1_DEV dev, uint16_t *high);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function programs the ROI (Region of Interest)\n
|
||||||
|
* The ROI position is centered, only the ROI size can be reprogrammed.\n
|
||||||
|
* The smallest acceptable ROI size = 4\n
|
||||||
|
* @param X:ROI Width; Y=ROI Height
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_SetROI(VL53L1_DEV dev, uint16_t X, uint16_t Y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*@brief This function returns width X and height Y
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetROI_XY(VL53L1_DEV dev, uint16_t *ROI_X, uint16_t *ROI_Y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*@brief This function programs the new user ROI center, please to be aware that there is no check in this function.
|
||||||
|
*if the ROI center vs ROI size is out of border the ranging function return error #13
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_SetROICenter(VL53L1_DEV dev, uint8_t ROICenter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*@brief This function returns the current user ROI center
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetROICenter(VL53L1_DEV dev, uint8_t *ROICenter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function programs a new signal threshold in kcps (default=1024 kcps\n
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_SetSignalThreshold(VL53L1_DEV dev, uint16_t signal);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the current signal threshold in kcps
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetSignalThreshold(VL53L1_DEV dev, uint16_t *signal);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function programs a new sigma threshold in mm (default=15 mm)
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_SetSigmaThreshold(VL53L1_DEV dev, uint16_t sigma);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the current sigma threshold in mm
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_GetSigmaThreshold(VL53L1_DEV dev, uint16_t *signal);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function performs the temperature calibration.
|
||||||
|
* It is recommended to call this function any time the temperature might have changed by more than 8 deg C
|
||||||
|
* without sensor ranging activity for an extended period.
|
||||||
|
*/
|
||||||
|
VL53L1X_ERROR VL53L1X_StartTemperatureUpdate(VL53L1_DEV dev);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Tom van Dijk <tomvand@users.noreply.github.com>
|
||||||
|
*
|
||||||
|
* This file is part of paparazzi.
|
||||||
|
*
|
||||||
|
* paparazzi is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/** @file peripherals/vl53l1x_nonblocking.c
|
||||||
|
* @brief Non-blocking runtime functions for the VL53L1X.
|
||||||
|
*
|
||||||
|
* These functions are adapted from vl53l1x_api.c to use the non-blocking
|
||||||
|
* version of I2C functions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "vl53l1x_nonblocking.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
// Returns true upon completion
|
||||||
|
static bool VL53L1_NonBlocking_WriteMulti(VL53L1_DEV dev, uint16_t index, uint8_t *pdata, uint32_t count)
|
||||||
|
{
|
||||||
|
switch (dev->nonblocking.i2c_state) {
|
||||||
|
case 0:
|
||||||
|
assert(2 + count <= I2C_BUF_LEN);
|
||||||
|
dev->i2c_trans.buf[0] = (index & 0xFF00) >> 8; // MSB first
|
||||||
|
dev->i2c_trans.buf[1] = (index & 0x00FF);
|
||||||
|
for (uint8_t i = 0; i < count; ++i) { dev->i2c_trans.buf[i + 2] = pdata[i]; }
|
||||||
|
i2c_transmit(dev->i2c_p, &dev->i2c_trans, dev->i2c_trans.slave_addr, 2 + count);
|
||||||
|
dev->nonblocking.i2c_state++;
|
||||||
|
/* Falls through. */
|
||||||
|
case 1:
|
||||||
|
if (dev->i2c_trans.status == I2CTransFailed) {
|
||||||
|
dev->nonblocking.i2c_state = 0; // Try again.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (dev->i2c_trans.status != I2CTransSuccess) { return false; } // Wait for transaction to complete.
|
||||||
|
// Transaction success
|
||||||
|
dev->nonblocking.i2c_state = 0;
|
||||||
|
return true;
|
||||||
|
default: return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns true upon completion
|
||||||
|
static bool VL53L1_NonBlocking_ReadMulti(VL53L1_DEV dev, uint16_t index, uint8_t *pdata, uint32_t count)
|
||||||
|
{
|
||||||
|
switch (dev->nonblocking.i2c_state) {
|
||||||
|
case 0:
|
||||||
|
assert(count <= I2C_BUF_LEN);
|
||||||
|
dev->i2c_trans.buf[0] = (index & 0xFF00) >> 8; // MSB first
|
||||||
|
dev->i2c_trans.buf[1] = (index & 0x00FF);
|
||||||
|
i2c_transceive(dev->i2c_p, &dev->i2c_trans, dev->i2c_trans.slave_addr, 2, count);
|
||||||
|
dev->nonblocking.i2c_state++;
|
||||||
|
/* Falls through. */
|
||||||
|
case 1:
|
||||||
|
if (dev->i2c_trans.status == I2CTransFailed) {
|
||||||
|
dev->nonblocking.i2c_state = 0; // Try again.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (dev->i2c_trans.status != I2CTransSuccess) { return false; } // Wait for transaction to complete.
|
||||||
|
// Transaction success
|
||||||
|
for (uint8_t i = 0; i < count; ++i) { pdata[i] = dev->i2c_trans.buf[i]; }
|
||||||
|
dev->nonblocking.i2c_state = 0;
|
||||||
|
return true;
|
||||||
|
default: return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns true upon completion
|
||||||
|
bool VL53L1X_NonBlocking_CheckForDataReady(VL53L1_DEV dev, uint8_t *isDataReady)
|
||||||
|
{
|
||||||
|
uint8_t Temp;
|
||||||
|
switch (dev->nonblocking.state) {
|
||||||
|
case 0:
|
||||||
|
// GetInterruptPolarity
|
||||||
|
if (!VL53L1_NonBlocking_ReadMulti(dev, GPIO_HV_MUX__CTRL, &Temp, 1)) { return false; }
|
||||||
|
Temp = Temp & 0x10;
|
||||||
|
dev->nonblocking.IntPol = !(Temp >> 4);
|
||||||
|
dev->nonblocking.state++;
|
||||||
|
/* Falls through. */
|
||||||
|
case 1:
|
||||||
|
/* Read in the register to check if a new value is available */
|
||||||
|
if (!VL53L1_NonBlocking_ReadMulti(dev, GPIO__TIO_HV_STATUS, &Temp, 1)) { return false; }
|
||||||
|
if ((Temp & 1) == dev->nonblocking.IntPol) {
|
||||||
|
*isDataReady = 1;
|
||||||
|
} else {
|
||||||
|
*isDataReady = 0;
|
||||||
|
}
|
||||||
|
dev->nonblocking.state = 0;
|
||||||
|
return true;
|
||||||
|
default: return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns true upon completion
|
||||||
|
bool VL53L1X_NonBlocking_GetDistance(VL53L1_DEV dev, uint16_t *distance)
|
||||||
|
{
|
||||||
|
uint8_t tmp[2];
|
||||||
|
if (!VL53L1_NonBlocking_ReadMulti(dev, VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0,
|
||||||
|
tmp, 2)) { return false; }
|
||||||
|
*distance = (tmp[0] << 8) | tmp[1];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns true upon completion
|
||||||
|
bool VL53L1X_NonBlocking_ClearInterrupt(VL53L1_DEV dev)
|
||||||
|
{
|
||||||
|
uint8_t data = 0x01;
|
||||||
|
return VL53L1_NonBlocking_WriteMulti(dev, SYSTEM__INTERRUPT_CLEAR, &data, 1);
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Tom van Dijk <tomvand@users.noreply.github.com>
|
||||||
|
*
|
||||||
|
* This file is part of paparazzi.
|
||||||
|
*
|
||||||
|
* paparazzi is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/** @file peripherals/vl53l1x_nonblocking.h
|
||||||
|
* @brief Non-blocking runtime functions for the VL53L1X.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef VL53L1X_NONBLOCKING_H
|
||||||
|
#define VL53L1X_NONBLOCKING_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "vl53l1x_api.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function checks if the new ranging data is available by polling the dedicated register.
|
||||||
|
* @param : isDataReady==0 -> not ready; isDataReady==1 -> ready
|
||||||
|
* @return: TRUE upon completion
|
||||||
|
*/
|
||||||
|
bool VL53L1X_NonBlocking_CheckForDataReady(VL53L1_DEV dev, uint8_t *isDataReady);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function returns the distance measured by the sensor in mm
|
||||||
|
* @return: TRUE upon completion
|
||||||
|
*/
|
||||||
|
bool VL53L1X_NonBlocking_GetDistance(VL53L1_DEV dev, uint16_t *distance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function clears the interrupt, to be called after a ranging data reading
|
||||||
|
* to arm the interrupt for the next data ready event.
|
||||||
|
* @return: TRUE upon completion
|
||||||
|
*/
|
||||||
|
bool VL53L1X_NonBlocking_ClearInterrupt(VL53L1_DEV dev);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // VL53L1X_NONBLOCKING_H
|
||||||
@@ -169,6 +169,10 @@
|
|||||||
#define AGL_LIDAR_TFMINI_ID 11
|
#define AGL_LIDAR_TFMINI_ID 11
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef AGL_VL53L1X_ID
|
||||||
|
#define AGL_VL53L1X_ID 12
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IDs of magnetometer sensors (including IMUs with mag)
|
* IDs of magnetometer sensors (including IMUs with mag)
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user