Initial import

This commit is contained in:
erwin
2023-06-29 22:14:17 +02:00
parent 14c1d42cbf
commit 90cb70e140
245 changed files with 292356 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
Thank you for opening an issue on an Adafruit Arduino library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:
- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
something isn't working as expected. In many cases the problem is a common issue
that you will more quickly receive help from the forum community. GitHub issues
are meant for known defects in the code. If you don't know if there is a defect
in the code then start with troubleshooting on the forum first.
- **If following a tutorial or guide be sure you didn't miss a step.** Carefully
check all of the steps and commands to run have been followed. Consult the
forum if you're unsure or have questions about steps in a guide/tutorial.
- **For Arduino projects check these very common issues to ensure they don't apply**:
- For uploading sketches or communicating with the board make sure you're using
a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes
very hard to tell the difference between a data and charge cable! Try using the
cable with other devices or swapping to another cable to confirm it is not
the problem.
- **Be sure you are supplying adequate power to the board.** Check the specs of
your board and plug in an external power supply. In many cases just
plugging a board into your computer is not enough to power it and other
peripherals.
- **Double check all soldering joints and connections.** Flakey connections
cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints.
- **Ensure you are using an official Arduino or Adafruit board.** We can't
guarantee a clone board will have the same functionality and work as expected
with this code and don't support them.
If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:
- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE**
- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO
VERSION HERE**
- List the steps to reproduce the problem below (if possible attach a sketch or
copy the sketch code in too): **LIST REPRO STEPS BELOW**

View File

@@ -0,0 +1,26 @@
Thank you for creating a pull request to contribute to Adafruit's GitHub code!
Before you open the request please review the following guidelines and tips to
help it be more easily integrated:
- **Describe the scope of your change--i.e. what the change does and what parts
of the code were modified.** This will help us understand any risks of integrating
the code.
- **Describe any known limitations with your change.** For example if the change
doesn't apply to a supported platform of the library please mention it.
- **Please run any tests or examples that can exercise your modified code.** We
strive to not break users of the code and running tests/examples helps with this
process.
Thank you again for contributing! We will try to test and integrate the change
as soon as we can, but be aware we have many GitHub repositories to manage and
can't immediately respond to every request. There is no need to bump or check in
on a pull request (it will clutter the discussion of the request).
Also don't be worried if the request is closed or not integrated--sometimes the
priorities of Adafruit's GitHub code (education, ease of use) might not match the
priorities of the pull request. Don't fret, the open source community thrives on
forks and GitHub makes it easy to keep your changes in a forked repo.
After reviewing the guidelines above you can delete this text from the pull request.

View File

@@ -0,0 +1,42 @@
name: Arduino Library CI
on: [pull_request, push, repository_dispatch]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
repository: adafruit/ci-arduino
path: ci
- name: pre-install
run: bash ci/actions_install.sh
- name: test platforms
run: python3 ci/build_platform.py main_platforms
- name: clang
run: python3 ci/run-clang-format.py -r ./src/Adafruit_*
- name: doxygen
env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
PRETTYNAME : "Adafruit VL53L1X Library"
run: bash ci/doxy_gen_and_deploy.sh
- name: Upload build artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ github.event.repository.name }}.${{ github.sha }}
path: |
examples/*/build/*/*.hex
examples/*/build/*/*.bin
examples/*/build/*/*.uf2

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,23 @@
COPYRIGHT(c) 2018 STMicroelectronics
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 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 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.

View File

@@ -0,0 +1,41 @@
# Adafruit VL53L1X Library [![Build Status](https://travis-ci.com/adafruit/Adafruit_VL53L1X.svg?branch=master)](https://travis-ci.com/adafruit/Adafruit_VL53L1X) [![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_VL53L1X/html/index.html)
<img src="https://cdn-shop.adafruit.com/970x728/3967-00.jpg" height="300"/>
This is a library for the Adafruit VL53L1X time-of-flight breakout:
* https://www.adafruit.com/products/3967
Check out the links above for our tutorials and wiring diagrams. This chip uses I2C to communicate
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
Uses ST's VL53L1X underlying api implementation
BSD license, all text above must be included in any redistribution
## API
This sensor uses I2C to communicate. And I2C instance is required to access to the sensor.
The API provides simple distance measure, single swipe gesture detection,
directional (left/right) swipe gesture detection and single tap gesture detection.
## Note
The maximum detection distance is influenced by the color of the target and
the indoor or outdoor situation due to absence or presence of external
infrared.
The detection range can be comprise between ~40cm and ~400cm. (see chapter 5 of
the VL53L1X datasheet).
The library should work also with standard Arduino boards. In this case you just
need to adjust the code in the sketch in order to use the correct Wire instance and
the correct pin number for XSHUT and GPIO1 pins.
## Documentation
You can find the source files at
https://github.com/stm32duino/VL53L1X
The VL53L1X datasheet is available at
https://www.st.com/content/st_com/en/products/imaging-and-photonics-solutions/proximity-sensors/vl53l1x.html

View File

@@ -0,0 +1,62 @@
#include "Adafruit_VL53L1X.h"
#define IRQ_PIN 2
#define XSHUT_PIN 3
Adafruit_VL53L1X vl53 = Adafruit_VL53L1X(XSHUT_PIN, IRQ_PIN);
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println(F("Adafruit VL53L1X sensor demo"));
Wire.begin();
if (! vl53.begin(0x29, &Wire)) {
Serial.print(F("Error on init of VL sensor: "));
Serial.println(vl53.vl_status);
while (1) delay(10);
}
Serial.println(F("VL53L1X sensor OK!"));
Serial.print(F("Sensor ID: 0x"));
Serial.println(vl53.sensorID(), HEX);
if (! vl53.startRanging()) {
Serial.print(F("Couldn't start ranging: "));
Serial.println(vl53.vl_status);
while (1) delay(10);
}
Serial.println(F("Ranging started"));
// Valid timing budgets: 15, 20, 33, 50, 100, 200 and 500ms!
vl53.setTimingBudget(50);
Serial.print(F("Timing budget (ms): "));
Serial.println(vl53.getTimingBudget());
/*
vl.VL53L1X_SetDistanceThreshold(100, 300, 3, 1);
vl.VL53L1X_SetInterruptPolarity(0);
*/
}
void loop() {
int16_t distance;
if (vl53.dataReady()) {
// new measurement for the taking!
distance = vl53.distance();
if (distance == -1) {
// something went wrong!
Serial.print(F("Couldn't get distance: "));
Serial.println(vl53.vl_status);
return;
}
Serial.print(F("Distance: "));
Serial.print(distance);
Serial.println(" mm");
// data is read out, time for another reading!
vl53.clearInterrupt();
}
}

View File

@@ -0,0 +1,164 @@
#######################################
# Syntax Coloring Map For VL53L1X
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
ComponentObject KEYWORD1
RangeSensor KEYWORD1
VL53L1X KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
end KEYWORD2
VL53L1X_On KEYWORD2
VL53L1X_Off KEYWORD2
InitSensor KEYWORD2
Init KEYWORD2
ReadID KEYWORD2
GetDistance KEYWORD2
VL53L1X_GetSWVersion KEYWORD2
VL53L1X_SetI2CAddress KEYWORD2
VL53L1X_SensorInit KEYWORD2
VL53L1X_ClearInterrupt KEYWORD2
VL53L1X_SetInterruptPolarity KEYWORD2
VL53L1X_GetInterruptPolarity KEYWORD2
VL53L1X_StartRanging KEYWORD2
VL53L1X_StopRanging KEYWORD2
VL53L1X_CheckForDataReady KEYWORD2
VL53L1X_SetTimingBudgetInMs KEYWORD2
VL53L1X_GetTimingBudgetInMs KEYWORD2
VL53L1X_SetDistanceMode KEYWORD2
VL53L1X_GetDistanceMode KEYWORD2
VL53L1X_SetInterMeasurementInMs KEYWORD2
VL53L1X_GetInterMeasurementInMs KEYWORD2
VL53L1X_BootState KEYWORD2
VL53L1X_GetSensorId KEYWORD2
VL53L1X_GetDistance KEYWORD2
VL53L1X_GetSignalPerSpad KEYWORD2
VL53L1X_GetAmbientPerSpad KEYWORD2
VL53L1X_GetSignalRate KEYWORD2
VL53L1X_GetSpadNb KEYWORD2
VL53L1X_GetAmbientRate KEYWORD2
VL53L1X_GetRangeStatus KEYWORD2
VL53L1X_SetOffset KEYWORD2
VL53L1X_GetOffset KEYWORD2
VL53L1X_SetXtalk KEYWORD2
VL53L1X_GetXtalk KEYWORD2
VL53L1X_SetDistanceThreshold KEYWORD2
VL53L1X_GetDistanceThresholdWindow KEYWORD2
VL53L1X_GetDistanceThresholdLow KEYWORD2
VL53L1X_GetDistanceThresholdHigh KEYWORD2
VL53L1X_SetROI KEYWORD2
VL53L1X_GetROI_XY KEYWORD2
VL53L1X_SetROICenter KEYWORD2
VL53L1X_GetROICenter KEYWORD2
VL53L1X_SetSignalThreshold KEYWORD2
VL53L1X_GetSignalThreshold KEYWORD2
VL53L1X_SetSigmaThreshold KEYWORD2
VL53L1X_GetSigmaThreshold KEYWORD2
VL53L1X_StartTemperatureUpdate KEYWORD2
VL53L1X_CalibrateOffset KEYWORD2
VL53L1X_CalibrateXtalk KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
VL53L1X_IMPLEMENTATION_VER_MAJOR LITERAL1
VL53L1X_IMPLEMENTATION_VER_MINOR LITERAL1
VL53L1X_IMPLEMENTATION_VER_SUB LITERAL1
VL53L1X_IMPLEMENTATION_VER_REVISION LITERAL1
SOFT_RESET LITERAL1
VL53L1X_I2C_SLAVE__DEVICE_ADDRESS LITERAL1
VL53L1X_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND LITERAL1
ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS LITERAL1
ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS LITERAL1
ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS LITERAL1
ALGO__PART_TO_PART_RANGE_OFFSET_MM LITERAL1
MM_CONFIG__INNER_OFFSET_MM LITERAL1
MM_CONFIG__OUTER_OFFSET_MM LITERAL1
GPIO_HV_MUX__CTRL LITERAL1
GPIO__TIO_HV_STATUS LITERAL1
SYSTEM__INTERRUPT_CONFIG_GPIO LITERAL1
PHASECAL_CONFIG__TIMEOUT_MACROP LITERAL1
RANGE_CONFIG__TIMEOUT_MACROP_A_HI LITERAL1
RANGE_CONFIG__VCSEL_PERIOD_A LITERAL1
RANGE_CONFIG__VCSEL_PERIOD_B LITERAL1
RANGE_CONFIG__TIMEOUT_MACROP_B_HI LITERAL1
RANGE_CONFIG__TIMEOUT_MACROP_B_LO LITERAL1
RANGE_CONFIG__SIGMA_THRESH LITERAL1
RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS LITERAL1
RANGE_CONFIG__VALID_PHASE_HIGH LITERAL1
VL53L1X_SYSTEM__INTERMEASUREMENT_PERIOD LITERAL1
SYSTEM__THRESH_HIGH LITERAL1
SYSTEM__THRESH_LOW LITERAL1
SD_CONFIG__WOI_SD0 LITERAL1
SD_CONFIG__INITIAL_PHASE_SD0 LITERAL1
ROI_CONFIG__USER_ROI_CENTRE_SPAD LITERAL1
ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE LITERAL1
SYSTEM__SEQUENCE_CONFIG LITERAL1
VL53L1X_SYSTEM__GROUPED_PARAMETER_HOLD LITERAL1
SYSTEM__INTERRUPT_CLEAR LITERAL1
SYSTEM__MODE_START LITERAL1
VL53L1X_RESULT__RANGE_STATUS LITERAL1
VL53L1X_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0 LITERAL1
RESULT__AMBIENT_COUNT_RATE_MCPS_SD LITERAL1
VL53L1X_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 LITERAL1
VL53L1X_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0 LITERAL1
VL53L1X_RESULT__OSC_CALIBRATE_VAL LITERAL1
VL53L1X_FIRMWARE__SYSTEM_STATUS LITERAL1
VL53L1X_IDENTIFICATION__MODEL_ID LITERAL1
VL53L1X_ROI_CONFIG__MODE_ROI_CENTRE_SPAD LITERAL1
VL53L1X_DEFAULT_DEVICE_ADDRESS LITERAL1
ALGO__PART_TO_PART_RANGE_OFFSET_MM LITERAL1
MM_CONFIG__INNER_OFFSET_MM LITERAL1
MM_CONFIG__OUTER_OFFSET_MM LITERAL1
VL53L1X_ERROR_NONE LITERAL1
VL53L1X_ERROR_CALIBRATION_WARNING LITERAL1
VL53L1X_ERROR_MIN_CLIPPED LITERAL1
VL53L1X_ERROR_UNDEFINED LITERAL1
VL53L1X_ERROR_INVALID_PARAMS LITERAL1
VL53L1X_ERROR_NOT_SUPPORTED LITERAL1
VL53L1X_ERROR_RANGE_ERROR LITERAL1
VL53L1X_ERROR_TIME_OUT LITERAL1
VL53L1X_ERROR_MODE_NOT_SUPPORTED LITERAL1
VL53L1X_ERROR_BUFFER_TOO_SMALL LITERAL1
VL53L1X_ERROR_COMMS_BUFFER_TOO_SMALL LITERAL1
VL53L1X_ERROR_GPIO_NOT_EXISTING LITERAL1
VL53L1X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED LITERAL1
VL53L1X_ERROR_CONTROL_INTERFACE LITERAL1
VL53L1X_ERROR_INVALID_COMMAND LITERAL1
VL53L1X_ERROR_DIVISION_BY_ZERO LITERAL1
VL53L1X_ERROR_REF_SPAD_INIT LITERAL1
VL53L1X_ERROR_GPH_SYNC_CHECK_FAIL LITERAL1
VL53L1X_ERROR_STREAM_COUNT_CHECK_FAIL LITERAL1
VL53L1X_ERROR_GPH_ID_CHECK_FAIL LITERAL1
VL53L1X_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL LITERAL1
VL53L1X_ERROR_ZONE_GPH_ID_CHECK_FAIL LITERAL1
VL53L1X_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL LITERAL1
VL53L1X_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL LITERAL1
VL53L1X_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL LITERAL1
VL53L1X_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL LITERAL1
VL53L1X_ERROR_ZONE_CAL_NO_SAMPLE_FAIL LITERAL1
VL53L1X_ERROR_TUNING_PARM_KEY_MISMATCH LITERAL1
VL53L1X_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS LITERAL1
VL53L1X_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH LITERAL1
VL53L1X_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW LITERAL1
VL53L1X_WARNING_OFFSET_CAL_MISSING_SAMPLES LITERAL1
VL53L1X_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH LITERAL1
VL53L1X_WARNING_OFFSET_CAL_RATE_TOO_HIGH LITERAL1
VL53L1X_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW LITERAL1
VL53L1X_WARNING_ZONE_CAL_MISSING_SAMPLES LITERAL1
VL53L1X_WARNING_ZONE_CAL_SIGMA_TOO_HIGH LITERAL1
VL53L1X_WARNING_ZONE_CAL_RATE_TOO_HIGH LITERAL1
VL53L1X_WARNING_XTALK_MISSING_SAMPLES LITERAL1
VL53L1X_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT LITERAL1
VL53L1X_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT LITERAL1
VL53L1X_ERROR_NOT_IMPLEMENTED LITERAL1
VL53L1X_ERROR_PLATFORM_SPECIFIC_START LITERAL1

View File

@@ -0,0 +1,10 @@
name=Adafruit VL53L1X
version=3.1.0
author=Adafruit
maintainer=adafruit <support@adafruit.com>
sentence=Sensor driver for VL53L1X / VL53L1CX Time of Flight sensor
paragraph=Sensor driver for VL53L1X / VL53L1CX Time of Flight sensor
category=Sensors
url=https://github.com/adafruit/Adafruit_VL53L1X
architectures=*
depends=Adafruit BusIO

View File

@@ -0,0 +1,266 @@
/*!
* @file Adafruit_VL53L1X.cpp
*
* @mainpage Adafruit VL53L1X time-of-flight sensor
*
* @section intro_sec Introduction
*
* This is the documentation for Adafruit's VL53L1X driver for the
* Arduino platform. It is designed specifically to work with the
* Adafruit VL53L1X breakout: https://www.adafruit.com/product/3967
*
* These sensors use I2C to communicate, 2 pins (SCL+SDA) are required
* to interface with the breakout.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* @section dependencies Dependencies
*
*
* @section author Author
*
* Written by Limor Fried/Ladyada for Adafruit Industries.
*
* @section license License
*
* BSD license, all text here must be included in any redistribution.
*
*/
#include "Adafruit_VL53L1X.h"
/**************************************************************************/
/*!
@brief Create a new VL53L1X instance
@param shutdown_pin Optional specify pin attached to shutdown
@param irq_pin Optional specify pin attached to interrupt
*/
/**************************************************************************/
Adafruit_VL53L1X::Adafruit_VL53L1X(uint8_t shutdown_pin, uint8_t irq_pin)
: VL53L1X(NULL, irq_pin) {
_shutdown_pin = shutdown_pin;
_irq_pin = irq_pin;
}
/**************************************************************************/
/*!
@brief Setups the I2C interface and hardware
@param i2c_addr Optional I2C address the sensor can be found on. Default is
0x29
@param theWire Optional The Wire bus object to use.
@param debug Optional debug flag. If true, debug information will print out
via Serial.print during setup. Defaults to false.
@returns True if device is set up, false on any failure
*/
/**************************************************************************/
bool Adafruit_VL53L1X::begin(uint8_t i2c_addr, TwoWire *theWire, bool debug) {
if (_shutdown_pin != -1) {
pinMode(_shutdown_pin, OUTPUT);
digitalWrite(_shutdown_pin, HIGH);
digitalWrite(_shutdown_pin, LOW);
delay(5);
digitalWrite(_shutdown_pin, HIGH);
}
delay(5);
theWire->begin();
MyDevice.I2cHandle = theWire;
dev_i2c = theWire;
vl_status = InitSensor(i2c_addr * 2);
if (vl_status != VL53L1X_ERROR_NONE) {
return false;
}
if (sensorID() != 0xEACC) {
return false;
}
/*
Status = VL53L1_software_reset(pMyDevice);
if (Status != VL53L1_ERROR_NONE) return false;
// from Nucleo main.c
Status = VL53L1_WaitDeviceBooted(pMyDevice);
if (Status != VL53L1_ERROR_NONE) return false;
if (debug)
Serial.println("DataInit");
Status = VL53L1_DataInit(pMyDevice); // Data initialization
if (Status != VL53L1_ERROR_NONE) return false;
if (debug)
Serial.println("StaticInit");
Status = VL53L1_StaticInit(pMyDevice);
if (Status != VL53L1_ERROR_NONE) return false;
Status = VL53L1_GetDeviceInfo(pMyDevice, &DeviceInfo );
if (Status != VL53L1_ERROR_NONE) return false;
if (debug) {
Serial.println( F( "VL53L1X Info:" ) );
Serial.print( F( "Device Name: ") ); Serial.print( DeviceInfo.Name );
Serial.print( F( ", Type: " ) ); Serial.print( DeviceInfo.Type );
Serial.print( F( ", ID: " ) ); Serial.println( DeviceInfo.ProductId );
Serial.print( F( "Rev Major: " ) ); Serial.print(
DeviceInfo.ProductRevisionMajor ); Serial.print( F( ", Minor: " ) );
Serial.println( DeviceInfo.ProductRevisionMinor );
}
if (! SetDistanceMode(VL53L1_DISTANCEMODE_LONG)) return false;
if (! SetMeasurementTimingBudgetMicroSeconds(50000)) return false;
if (! SetInterMeasurementPeriodMilliSeconds(50)) return false;
*/
return true;
}
/**************************************************************************/
/*!
@brief Get the sensor ID.
@returns The sensor ID.
*/
/**************************************************************************/
uint16_t Adafruit_VL53L1X::sensorID(void) {
uint16_t sensorID = 0;
vl_status = VL53L1X_GetSensorId(&sensorID);
return sensorID;
}
/**************************************************************************/
/*!
@brief Get the distance.
@returns The distance.
*/
/**************************************************************************/
int16_t Adafruit_VL53L1X::distance(void) {
uint16_t distance;
uint8_t rangeStatus;
vl_status = VL53L1X_GetRangeStatus(&rangeStatus);
if ((vl_status != VL53L1X_ERROR_NONE) || (rangeStatus != 0x0)) {
return -1;
}
vl_status = VL53L1X_GetDistance(&distance);
if (vl_status != VL53L1X_ERROR_NONE) {
return -1;
}
return (int16_t)distance;
}
/**************************************************************************/
/*!
@brief Clear the interrupt.
@returns True if successful, otherwise false.
*/
/**************************************************************************/
bool Adafruit_VL53L1X::clearInterrupt(void) {
vl_status = VL53L1X_ClearInterrupt();
return (vl_status == VL53L1X_ERROR_NONE);
}
/**************************************************************************/
/*!
@brief Set the interrupt polarity.
@param polarity The polarity to set as a boolean.
@returns True if successful, otherwise false.
*/
/**************************************************************************/
bool Adafruit_VL53L1X::setIntPolarity(bool polarity) {
vl_status = VL53L1X_SetInterruptPolarity(polarity);
return (vl_status == VL53L1X_ERROR_NONE);
}
/**************************************************************************/
/*!
@brief Get the interrupt polarity.
@returns Polarity as a boolean.
*/
/**************************************************************************/
bool Adafruit_VL53L1X::getIntPolarity(void) {
uint8_t x = 0;
vl_status = VL53L1X_GetInterruptPolarity(&x);
return (bool)x;
}
/**************************************************************************/
/*!
@brief Start ranging operations.
@returns True if successful, otherwise false.
*/
/**************************************************************************/
bool Adafruit_VL53L1X::startRanging(void) {
vl_status = VL53L1X_StartRanging();
return (vl_status == VL53L1X_ERROR_NONE);
}
/**************************************************************************/
/*!
@brief Stop ranging operations.
@returns True if successful, otherwise false.
*/
/**************************************************************************/
bool Adafruit_VL53L1X::stopRanging(void) {
vl_status = VL53L1X_StopRanging();
return (vl_status == VL53L1X_ERROR_NONE);
}
/**************************************************************************/
/*!
@brief Check status of new data.
@returns True if new data available, otherwise false.
*/
/**************************************************************************/
bool Adafruit_VL53L1X::dataReady(void) {
uint8_t x = 0;
vl_status = VL53L1X_CheckForDataReady(&x);
return (bool)x;
}
/**************************************************************************/
/*!
@brief Set the timing budget.
@param ms Timing budget in milliseconds.
@returns True if successful, otherwise false.
*/
/**************************************************************************/
bool Adafruit_VL53L1X::setTimingBudget(uint16_t ms) {
vl_status = VL53L1X_SetTimingBudgetInMs(ms);
return (vl_status == VL53L1X_ERROR_NONE);
}
/**************************************************************************/
/*!
@brief Get the timing budget.
@returns Timing budget in milliseconds.
*/
/**************************************************************************/
uint16_t Adafruit_VL53L1X::getTimingBudget(void) {
uint16_t ms = 0;
vl_status = VL53L1X_GetTimingBudgetInMs(&ms);
if (vl_status == VL53L1X_ERROR_NONE) {
return ms;
}
return 0;
}
/*
}
boolean Adafruit_VL53L1X::SetDistanceMode(VL53L1_DistanceModes mode) {
Status = VL53L1_SetDistanceMode(pMyDevice, mode );
return (Status == VL53L1_ERROR_NONE);
}
boolean
Adafruit_VL53L1X::GetRangingMeasurementData(VL53L1_RangingMeasurementData_t
*ranging) { Status = VL53L1_GetRangingMeasurementData(pMyDevice, ranging);
return (Status == VL53L1_ERROR_NONE);
}
*/

View File

@@ -0,0 +1,75 @@
/*!
* @file Adafruit_VL53L1X.h
This is a library for the Adafruit VL53L1X Sensor Breakout
Designed specifically to work with the VL53L1X sensor from Adafruit
----> https://www.adafruit.com/products/3967
These sensors use I2C to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#ifndef ADAFRUIT_VL53L1X_H
#define ADAFRUIT_VL53L1X_H
#include "Wire.h"
#include "vl53l1x_class.h"
#define VL53L1X_I2C_ADDR 0x29 ///< Default sensor I2C address
/**************************************************************************/
/*!
@brief Class that stores state and functions for interacting with VL53L1X
time-of-flight sensor chips
*/
/**************************************************************************/
class Adafruit_VL53L1X : public VL53L1X {
public:
Adafruit_VL53L1X(uint8_t shutdown_pin = -1, uint8_t irq_pin = -1);
bool begin(uint8_t i2c_addr = VL53L1X_I2C_ADDR, TwoWire *theWire = &Wire,
bool debug = false);
uint16_t sensorID(void);
bool startRanging(void);
bool stopRanging(void);
bool setTimingBudget(uint16_t ms);
uint16_t getTimingBudget(void);
bool dataReady(void);
int16_t distance(void);
bool clearInterrupt(void);
bool setIntPolarity(bool polarity);
bool getIntPolarity(void);
/*
boolean SetDistanceMode(VL53L1_DistanceModes mode);
boolean SetMeasurementTimingBudgetMicroSeconds(uint32_t budget);
boolean SetInterMeasurementPeriodMilliSeconds(uint32_t period);
boolean StartMeasurement(void);
boolean WaitMeasurementDataReady(void);
boolean GetRangingMeasurementData(VL53L1_RangingMeasurementData_t *ranging);
*/
VL53L1X_ERROR vl_status; /**< VL53L1X API Error Status */
private:
int8_t _irq_pin, _shutdown_pin;
/*
VL53L1_Dev_t MyDevice;
VL53L1_Dev_t *pMyDevice = &MyDevice;
//VL53L1X_Version_t Version;
//VL53L1X_Version_t *pVersion = &Version;
VL53L1_DeviceInfo_t DeviceInfo;
*/
};
#endif

View File

@@ -0,0 +1,75 @@
/**
******************************************************************************
* @file ComponentObject.h
* @author AST
* @version V1.0.0
* @date April 13th, 2015
* @brief This file contains the abstract class describing the interface of a
* generic component.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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 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 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __COMPONENT_OBJECT_CLASS_H
#define __COMPONENT_OBJECT_CLASS_H
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/* Classes ------------------------------------------------------------------*/
/** An abstract class for Generic components.
*/
class ComponentObject
{
public:
/**
* @brief Initializing the component.
* @param[in] init pointer to device specific initalization structure.
* @retval "0" in case of success, an error code otherwise.
*/
virtual int Init() = 0;
/**
* @brief Getting the ID of the component.
* @param[out] id pointer to an allocated variable to store the ID into.
* @retval "0" in case of success, an error code otherwise.
*/
virtual int ReadID() = 0;
};
#endif /* __COMPONENT_OBJECT_CLASS_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,60 @@
/**
******************************************************************************
* @file RangeSensor.h
* @author AST / EST
* @version V0.0.1
* @date 13-April-2015
* @brief This file contains the abstract class describing in general
* the interfaces of a range sensor
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* 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 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 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.
*
******************************************************************************
*/
/* Define to prevent from recursive inclusion --------------------------------*/
#ifndef __RANGE_SENSOR_CLASS_H
#define __RANGE_SENSOR_CLASS_H
/* Includes ------------------------------------------------------------------*/
#include <ComponentObject.h>
/* Classes ------------------------------------------------------------------*/
/** An abstract class for range sensors
*/
class RangeSensor : public ComponentObject
{
public:
/**
* @brief Get current range [mm]
* @param[out] piData Pointer to where to store range to
* @return 0 in case of success, an error code otherwise
*/
virtual int GetDistance(uint32_t *piData) = 0;
};
#endif /* __RANGE_SENSOR_CLASS_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,593 @@
/*******************************************************************************
Copyright © 2018, 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.
*****************************************************************************/
#ifndef __VL53L1X_CLASS_H
#define __VL53L1X_CLASS_H
#ifdef _MSC_VER
# ifdef VL53L1X_API_EXPORTS
# define VL53L1X_API __declspec(dllexport)
# else
# define VL53L1X_API
# endif
#else
# define VL53L1X_API
#endif
/* Includes ------------------------------------------------------------------*/
#include "Arduino.h"
#include "Wire.h"
#include "RangeSensor.h"
#include "vl53l1x_error_codes.h"
#define VL53L1X_IMPLEMENTATION_VER_MAJOR 1
#define VL53L1X_IMPLEMENTATION_VER_MINOR 0
#define VL53L1X_IMPLEMENTATION_VER_SUB 1
#define VL53L1X_IMPLEMENTATION_VER_REVISION 0000
typedef int8_t VL53L1X_ERROR;
#define VL53L1X_I2C_SLAVE__DEVICE_ADDRESS 0x0001
#define VL53L1X_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 VL53L1X_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 VL53L1X_SYSTEM__GROUPED_PARAMETER_HOLD 0x0082
#define SYSTEM__INTERRUPT_CLEAR 0x0086
#define SYSTEM__MODE_START 0x0087
#define VL53L1X_RESULT__RANGE_STATUS 0x0089
#define VL53L1X_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0 0x008C
#define RESULT__AMBIENT_COUNT_RATE_MCPS_SD 0x0090
#define VL53L1X_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 0x0096
#define VL53L1X_RESULT__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0 0x0098
#define VL53L1X_RESULT__OSC_CALIBRATE_VAL 0x00DE
#define VL53L1X_FIRMWARE__SYSTEM_STATUS 0x00E5
#define VL53L1X_IDENTIFICATION__MODEL_ID 0x010F
#define VL53L1X_ROI_CONFIG__MODE_ROI_CENTRE_SPAD 0x013E
#define VL53L1X_DEFAULT_DEVICE_ADDRESS 0x52
/****************************************
* 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;
typedef struct
{
uint8_t I2cDevAddr;
TwoWire *I2cHandle;
} VL53L1X_Dev_t;
typedef VL53L1X_Dev_t *VL53L1X_DEV;
/* Classes -------------------------------------------------------------------*/
/** Class representing a VL53L1X sensor component
*/
class VL53L1X : public RangeSensor
{
public:
/** Constructor
* @param[in] i2c device I2C to be used for communication
* @param[in] pin shutdown pin to be used as component GPIO0
*/
VL53L1X(TwoWire *i2c, int pin) : RangeSensor(), dev_i2c(i2c), gpio0(pin)
{
Device = &MyDevice;
memset((void *)Device, 0x0, sizeof(VL53L1X_Dev_t));
MyDevice.I2cDevAddr=VL53L1X_DEFAULT_DEVICE_ADDRESS;
MyDevice.I2cHandle = i2c;
}
/** Destructor
*/
virtual ~VL53L1X() {}
/* warning: VL53L1X class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor.
The warning should request to introduce a virtual destructor to make sure to delete the object */
virtual int begin()
{
if(gpio0 >= 0)
{
pinMode(gpio0, OUTPUT);
}
return 0;
}
virtual int end()
{
if(gpio0 >= 0)
{
pinMode(gpio0, INPUT);
}
return 0;
}
/*** Interface Methods ***/
/*** High level API ***/
/**
* @brief PowerOn the sensor
* @return void
*/
/* turns on the sensor */
virtual void VL53L1X_On(void)
{
if(gpio0 >= 0)
{
digitalWrite(gpio0, HIGH);
}
delay(10);
}
/**
* @brief PowerOff the sensor
* @return void
*/
/* turns off the sensor */
virtual void VL53L1X_Off(void)
{
if(gpio0 >= 0)
{
digitalWrite(gpio0, LOW);
}
delay(10);
}
/**
* @brief Initialize the sensor with default values
* @return 0 on Success
*/
VL53L1X_ERROR InitSensor(uint8_t address)
{
VL53L1X_ERROR status = 0;
uint8_t sensorState = 0;
VL53L1X_Off();
VL53L1X_On();
status = VL53L1X_SetI2CAddress(address);
#ifdef DEBUG_MODE
uint8_t byteData;
uint16_t wordData;
status = VL53L1X_RdByte(Device, 0x010F, &byteData);
Serial.println("VL53L1X Model_ID: " + String(byteData));
status = VL53L1X_RdByte(Device, 0x0110, &byteData);
Serial.println("VL53L1X Module_Type: " + String(byteData));
status = VL53L1X_RdWord(Device, 0x010F, &wordData);
Serial.println("VL53L1X: " + String(wordData));
#endif
while (!sensorState && !status)
{
status = VL53L1X_BootState(&sensorState);
delay(2);
}
if(!status)
{
status = VL53L1X_SensorInit();
}
return status;
}
/**
*
* @brief One time device initialization
* @param void
* @return 0 on success, @a #CALIBRATION_WARNING if failed
*/
virtual int Init()
{
return VL53L1X_SensorInit();
}
/* Read function of the ID device */
virtual int ReadID()
{
uint16_t sensorId;
VL53L1X_GetSensorId(&sensorId);
if (sensorId == 0xEEAC)
return 0;
return -1;
}
/**
* @brief Get ranging result and only that
* @param pRange_mm Pointer to range distance
* @return 0 on success
*/
int GetDistance(uint32_t *piData)
{
int status;
uint16_t distance;
status = VL53L1X_GetDistance(&distance);
*piData = (uint32_t) distance;
return status;
}
/* VL53L1X_api.h functions */
/**
* @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(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();
/**
* @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();
/**
* @brief This function programs the interrupt polarity\n
* 1=active high (default), 0=active low
*/
VL53L1X_ERROR VL53L1X_SetInterruptPolarity(uint8_t IntPol);
/**
* @brief This function returns the current interrupt polarity\n
* 1=active high (default), 0=active low
*/
VL53L1X_ERROR VL53L1X_GetInterruptPolarity(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();
/**
* @brief This function stops the ranging.
*/
VL53L1X_ERROR VL53L1X_StopRanging();
/**
* @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(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(uint16_t TimingBudgetInMs);
/**
* @brief This function returns the current timing budget in ms.
*/
VL53L1X_ERROR VL53L1X_GetTimingBudgetInMs(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(uint16_t DistanceMode);
/**
* @brief This function returns the current distance mode (1=short, 2=long).
*/
VL53L1X_ERROR VL53L1X_GetDistanceMode(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(uint16_t InterMeasurementInMs);
/**
* @brief This function returns the Intermeasurement period in ms.
*/
VL53L1X_ERROR VL53L1X_GetInterMeasurementInMs(uint16_t * pIM);
/**
* @brief This function returns the boot state of the device (1:booted, 0:not booted)
*/
VL53L1X_ERROR VL53L1X_BootState(uint8_t *state);
/**
* @brief This function returns the sensor id, sensor Id must be 0xEEAC
*/
VL53L1X_ERROR VL53L1X_GetSensorId(uint16_t *id);
/**
* @brief This function returns the distance measured by the sensor in mm
*/
VL53L1X_ERROR VL53L1X_GetDistance(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(uint16_t *signalPerSp);
/**
* @brief This function returns the ambient per SPAD in kcps/SPAD
*/
VL53L1X_ERROR VL53L1X_GetAmbientPerSpad(uint16_t *amb);
/**
* @brief This function returns the returned signal in kcps.
*/
VL53L1X_ERROR VL53L1X_GetSignalRate(uint16_t *signalRate);
/**
* @brief This function returns the current number of enabled SPADs
*/
VL53L1X_ERROR VL53L1X_GetSpadNb(uint16_t *spNb);
/**
* @brief This function returns the ambient rate in kcps
*/
VL53L1X_ERROR VL53L1X_GetAmbientRate(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(uint8_t *rangeStatus);
/**
* @brief This function programs the offset correction in mm
* @param OffsetValue:the offset correction value to program in mm
*/
VL53L1X_ERROR VL53L1X_SetOffset(int16_t OffsetValue);
/**
* @brief This function returns the programmed offset correction value in mm
*/
VL53L1X_ERROR VL53L1X_GetOffset(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(uint16_t XtalkValue);
/**
* @brief This function returns the current programmed xtalk correction value in cps
*/
VL53L1X_ERROR VL53L1X_GetXtalk(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(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(uint16_t *window);
/**
* @brief This function returns the low threshold in mm
*/
VL53L1X_ERROR VL53L1X_GetDistanceThresholdLow(uint16_t *low);
/**
* @brief This function returns the high threshold in mm
*/
VL53L1X_ERROR VL53L1X_GetDistanceThresholdHigh(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(uint16_t X, uint16_t Y);
/**
*@brief This function returns width X and height Y
*/
VL53L1X_ERROR VL53L1X_GetROI_XY(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(uint8_t ROICenter);
/**
*@brief This function returns the current user ROI center
*/
VL53L1X_ERROR VL53L1X_GetROICenter(uint8_t *ROICenter);
/**
* @brief This function programs a new signal threshold in kcps (default=1024 kcps\n
*/
VL53L1X_ERROR VL53L1X_SetSignalThreshold(uint16_t signal);
/**
* @brief This function returns the current signal threshold in kcps
*/
VL53L1X_ERROR VL53L1X_GetSignalThreshold(uint16_t *signal);
/**
* @brief This function programs a new sigma threshold in mm (default=15 mm)
*/
VL53L1X_ERROR VL53L1X_SetSigmaThreshold(uint16_t sigma);
/**
* @brief This function returns the current sigma threshold in mm
*/
VL53L1X_ERROR VL53L1X_GetSigmaThreshold(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();
/* VL53L1X_calibration.h functions */
/**
* @brief This function performs the offset calibration.\n
* The function returns the offset value found and programs the offset compensation into the device.
* @param TargetDistInMm target distance in mm, ST recommended 100 mm
* Target reflectance = grey17%
* @return 0:success, !=0: failed
* @return offset pointer contains the offset found in mm
*/
int8_t VL53L1X_CalibrateOffset(uint16_t TargetDistInMm, int16_t *offset);
/**
* @brief This function performs the xtalk calibration.\n
* The function returns the xtalk value found and programs the xtalk compensation to the device
* @param TargetDistInMm target distance in mm\n
* The target distance : the distance where the sensor start to "under range"\n
* due to the influence of the photons reflected back from the cover glass becoming strong\n
* It's also called inflection point\n
* Target reflectance = grey 17%
* @return 0: success, !=0: failed
* @return xtalk pointer contains the xtalk value found in cps (number of photons in count per second)
*/
int8_t VL53L1X_CalibrateXtalk(uint16_t TargetDistInMm, uint16_t *xtalk);
protected:
/* Write and read functions from I2C */
VL53L1X_ERROR VL53L1X_WrByte(VL53L1X_DEV dev, uint16_t index, uint8_t data);
VL53L1X_ERROR VL53L1X_WrWord(VL53L1X_DEV dev, uint16_t index, uint16_t data);
VL53L1X_ERROR VL53L1X_WrDWord(VL53L1X_DEV dev, uint16_t index, uint32_t data);
VL53L1X_ERROR VL53L1X_RdByte(VL53L1X_DEV dev, uint16_t index, uint8_t *data);
VL53L1X_ERROR VL53L1X_RdWord(VL53L1X_DEV dev, uint16_t index, uint16_t *data);
VL53L1X_ERROR VL53L1X_RdDWord(VL53L1X_DEV dev, uint16_t index, uint32_t *data);
VL53L1X_ERROR VL53L1X_UpdateByte(VL53L1X_DEV dev, uint16_t index, uint8_t AndData, uint8_t OrData);
VL53L1X_ERROR VL53L1X_WriteMulti(VL53L1X_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count);
VL53L1X_ERROR VL53L1X_ReadMulti(VL53L1X_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count);
VL53L1X_ERROR VL53L1X_I2CWrite(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes);
VL53L1X_ERROR VL53L1X_I2CRead(uint8_t dev, uint16_t index, uint8_t *data, uint16_t number_of_bytes);
VL53L1X_ERROR VL53L1X_GetTickCount(uint32_t *ptick_count_ms);
VL53L1X_ERROR VL53L1X_WaitUs(VL53L1X_Dev_t *pdev, int32_t wait_us);
VL53L1X_ERROR VL53L1X_WaitMs(VL53L1X_Dev_t *pdev, int32_t wait_ms);
VL53L1X_ERROR VL53L1X_WaitValueMaskEx(VL53L1X_Dev_t *pdev, uint32_t timeout_ms, uint16_t index, uint8_t value, uint8_t mask, uint32_t poll_delay_ms);
protected:
/* IO Device */
TwoWire *dev_i2c;
/* Digital out pin */
int gpio0;
/* Device data */
VL53L1X_Dev_t MyDevice;
VL53L1X_DEV Device;
};
#endif /* _VL53L1X_CLASS_H_ */

View File

@@ -0,0 +1,251 @@
/*
* Copyright (c) 2017, STMicroelectronics - All Rights Reserved
*
* This file is part of VL53L1X Core and is 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 is strictly prohibited unless
* specifically authorized in writing by STMicroelectronics.
*
*
********************************************************************************
*
* Alternatively, VL53L1X 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 vl53l1_error_codes.h
*
* @brief Error Code definitions for VL53L1X API.
*
*/
#ifndef _VL53L1X_ERROR_CODES_H_
#define _VL53L1X_ERROR_CODES_H_
#ifdef __cplusplus
extern "C" {
#endif
/****************************************
* PRIVATE define do not edit
****************************************/
/** @defgroup VL53L1X_define_Error_group Error and Warning code returned by API
* The following DEFINE are used to identify the PAL ERROR
* @{
*/
typedef int8_t VL53L1X_Error;
#define VL53L1X_ERROR_NONE ((VL53L1X_Error) 0)
#define VL53L1X_ERROR_CALIBRATION_WARNING ((VL53L1X_Error) - 1)
/*!< Warning invalid calibration data may be in used
\a VL53L1X_InitData()
\a VL53L1X_GetOffsetCalibrationData
\a VL53L1X_SetOffsetCalibrationData */
#define VL53L1X_ERROR_MIN_CLIPPED ((VL53L1X_Error) - 2)
/*!< Warning parameter passed was clipped to min before to be applied */
#define VL53L1X_ERROR_UNDEFINED ((VL53L1X_Error) - 3)
/*!< Unqualified error */
#define VL53L1X_ERROR_INVALID_PARAMS ((VL53L1X_Error) - 4)
/*!< Parameter passed is invalid or out of range */
#define VL53L1X_ERROR_NOT_SUPPORTED ((VL53L1X_Error) - 5)
/*!< Function is not supported in current mode or configuration */
#define VL53L1X_ERROR_RANGE_ERROR ((VL53L1X_Error) - 6)
/*!< Device report a ranging error interrupt status */
#define VL53L1X_ERROR_TIME_OUT ((VL53L1X_Error) - 7)
/*!< Aborted due to time out */
#define VL53L1X_ERROR_MODE_NOT_SUPPORTED ((VL53L1X_Error) - 8)
/*!< Asked mode is not supported by the device */
#define VL53L1X_ERROR_BUFFER_TOO_SMALL ((VL53L1X_Error) - 9)
/*!< ... */
#define VL53L1X_ERROR_COMMS_BUFFER_TOO_SMALL ((VL53L1X_Error) - 10)
/*!< Supplied buffer is larger than I2C supports */
#define VL53L1X_ERROR_GPIO_NOT_EXISTING ((VL53L1X_Error) - 11)
/*!< User tried to setup a non-existing GPIO pin */
#define VL53L1X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED ((VL53L1X_Error) - 12)
/*!< unsupported GPIO functionality */
#define VL53L1X_ERROR_CONTROL_INTERFACE ((VL53L1X_Error) - 13)
/*!< error reported from IO functions */
#define VL53L1X_ERROR_INVALID_COMMAND ((VL53L1X_Error) - 14)
/*!< The command is not allowed in the current device state
* (power down) */
#define VL53L1X_ERROR_DIVISION_BY_ZERO ((VL53L1X_Error) - 15)
/*!< In the function a division by zero occurs */
#define VL53L1X_ERROR_REF_SPAD_INIT ((VL53L1X_Error) - 16)
/*!< Error during reference SPAD initialization */
#define VL53L1X_ERROR_GPH_SYNC_CHECK_FAIL ((VL53L1X_Error) - 17)
/*!< GPH sync interrupt check fail - API out of sync with device*/
#define VL53L1X_ERROR_STREAM_COUNT_CHECK_FAIL ((VL53L1X_Error) - 18)
/*!< Stream count check fail - API out of sync with device */
#define VL53L1X_ERROR_GPH_ID_CHECK_FAIL ((VL53L1X_Error) - 19)
/*!< GPH ID check fail - API out of sync with device */
#define VL53L1X_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL ((VL53L1X_Error) - 20)
/*!< Zone dynamic config stream count check failed - API out of sync */
#define VL53L1X_ERROR_ZONE_GPH_ID_CHECK_FAIL ((VL53L1X_Error) - 21)
/*!< Zone dynamic config GPH ID check failed - API out of sync */
#define VL53L1X_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL ((VL53L1X_Error) - 22)
/*!< Thrown when run_xtalk_extraction fn has 0 succesful samples
* when using the full array to sample the xtalk. In this case there is
* not enough information to generate new Xtalk parm info. The function
* will exit and leave the current xtalk parameters unaltered */
#define VL53L1X_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL ((VL53L1X_Error) - 23)
/*!< Thrown when run_xtalk_extraction fn has found that the
* avg sigma estimate of the full array xtalk sample is > than the
* maximal limit allowed. In this case the xtalk sample is too noisy for
* measurement. The function will exit and leave the current xtalk parameters
* unaltered. */
#define VL53L1X_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL ((VL53L1X_Error) - 24)
/*!< Thrown if there one of stages has no valid offset calibration
* samples. A fatal error calibration not valid */
#define VL53L1X_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL ((VL53L1X_Error) - 25)
/*!< Thrown if there one of stages has zero effective SPADS
* Traps the case when MM1 SPADs is zero.
* A fatal error calibration not valid */
#define VL53L1X_ERROR_ZONE_CAL_NO_SAMPLE_FAIL ((VL53L1X_Error) - 26)
/*!< Thrown if then some of the zones have no valid samples
* A fatal error calibration not valid */
#define VL53L1X_ERROR_TUNING_PARM_KEY_MISMATCH ((VL53L1X_Error) - 27)
/*!< Thrown if the tuning file key table version does not match with
* expected value. The driver expects the key table version to match
* the compiled default version number in the define
* #VL53L1X_TUNINGPARM_KEY_TABLE_VERSION_DEFAULT
* */
#define VL53L1X_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS ((VL53L1X_Error) - 28)
/*!< Thrown if there are less than 5 good SPADs are available. */
#define VL53L1X_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH ((VL53L1X_Error) - 29)
/*!< Thrown if the final reference rate is greater than
the upper reference rate limit - default is 40 Mcps.
Implies a minimum Q3 (x10) SPAD (5) selected */
#define VL53L1X_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW ((VL53L1X_Error) - 30)
/*!< Thrown if the final reference rate is less than
the lower reference rate limit - default is 10 Mcps.
Implies maximum Q1 (x1) SPADs selected */
#define VL53L1X_WARNING_OFFSET_CAL_MISSING_SAMPLES ((VL53L1X_Error) - 31)
/*!< Thrown if there is less than the requested number of
* valid samples. */
#define VL53L1X_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH ((VL53L1X_Error) - 32)
/*!< Thrown if the offset calibration range sigma estimate is greater
* than 8.0 mm. This is the recommended min value to yield a stable
* offset measurement */
#define VL53L1X_WARNING_OFFSET_CAL_RATE_TOO_HIGH ((VL53L1X_Error) - 33)
/*!< Thrown when VL53L1X_run_offset_calibration() peak rate is greater
than that 50.0Mcps. This is the recommended max rate to avoid
pile-up influencing the offset measurement */
#define VL53L1X_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW ((VL53L1X_Error) - 34)
/*!< Thrown when VL53L1X_run_offset_calibration() when one of stages
range has less that 5.0 effective SPADS. This is the recommended
min value to yield a stable offset */
#define VL53L1X_WARNING_ZONE_CAL_MISSING_SAMPLES ((VL53L1X_Error) - 35)
/*!< Thrown if one of more of the zones have less than
the requested number of valid samples */
#define VL53L1X_WARNING_ZONE_CAL_SIGMA_TOO_HIGH ((VL53L1X_Error) - 36)
/*!< Thrown if one or more zones have sigma estimate value greater
* than 8.0 mm. This is the recommended min value to yield a stable
* offset measurement */
#define VL53L1X_WARNING_ZONE_CAL_RATE_TOO_HIGH ((VL53L1X_Error) - 37)
/*!< Thrown if one of more zones have peak rate higher than
that 50.0Mcps. This is the recommended max rate to avoid
pile-up influencing the offset measurement */
#define VL53L1X_WARNING_XTALK_MISSING_SAMPLES ((VL53L1X_Error) - 38)
/*!< Thrown to notify that some of the xtalk samples did not yield
* valid ranging pulse data while attempting to measure
* the xtalk signal in vl53l1_run_xtalk_extract(). This can signify any of
* the zones are missing samples, for further debug information the
* xtalk_results struct should be referred to. This warning is for
* notification only, the xtalk pulse and shape have still been generated
*/
#define VL53L1X_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT ((VL53L1X_Error) - 39)
/*!< Thrown to notify that some of teh xtalk samples used for gradient
* generation did not yield valid ranging pulse data while attempting to
* measure the xtalk signal in vl53l1_run_xtalk_extract(). This can signify
* that any one of the zones 0-3 yielded no successful samples. The
* xtalk_results struct should be referred to for further debug info.
* This warning is for notification only, the xtalk pulse and shape
* have still been generated.
*/
#define VL53L1X_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT ((VL53L1X_Error) - 40)
/*!< Thrown to notify that some of the xtalk samples used for gradient
* generation did not pass the sigma limit check while attempting to
* measure the xtalk signal in vl53l1_run_xtalk_extract(). This can signify
* that any one of the zones 0-3 yielded an avg sigma_mm value > the limit.
* The xtalk_results struct should be referred to for further debug info.
* This warning is for notification only, the xtalk pulse and shape
* have still been generated.
*/
#define VL53L1X_ERROR_NOT_IMPLEMENTED ((VL53L1X_Error) - 41)
/*!< Tells requested functionality has not been implemented yet or
* not compatible with the device */
#define VL53L1X_ERROR_PLATFORM_SPECIFIC_START ((VL53L1X_Error) - 60)
/*!< Tells the starting code for platform */
/** @} VL53L1X_define_Error_group */
#ifdef __cplusplus
}
#endif
#endif /* _VL53L1X_ERROR_CODES_H_ */