Skip to content

Commit

Permalink
#302: Add VL53L1 driver
Browse files Browse the repository at this point in the history
  • Loading branch information
ataffanel committed Mar 21, 2018
1 parent b9a871f commit 11c39c2
Show file tree
Hide file tree
Showing 44 changed files with 49,275 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ ST_OBJ_CF2 += usbd_ioreq.o usbd_req.o usbd_core.o
# libdw dw1000 driver
VPATH_CF2 += vendor/libdw1000/src

# vl53l1 driver
VPATH_CF2 += $(LIB)/vl53l1/core/src

# FreeRTOS
VPATH += $(PORT)
PORT_OBJ = port.o
Expand Down Expand Up @@ -124,7 +127,7 @@ PROJ_OBJ_CF2 += ak8963.o eeprom.o maxsonar.o piezo.o
PROJ_OBJ_CF2 += uart_syslink.o swd.o uart1.o uart2.o watchdog.o
PROJ_OBJ_CF2 += cppm.o
PROJ_OBJ_CF2 += bmi055_accel.o bmi055_gyro.o bmi160.o bmp280.o bstdr_comm_support.o bmm150.o
PROJ_OBJ_CF2 += pca9685.o vl53l0x.o pca95x4.o
PROJ_OBJ_CF2 += pca9685.o vl53l0x.o pca95x4.o vl53l1x.o
# USB Files
PROJ_OBJ_CF2 += usb_bsp.o usblink.o usbd_desc.o usb.o

Expand All @@ -136,6 +139,11 @@ PROJ_OBJ_CF2 += sensors_$(SENSORS).o
# libdw
PROJ_OBJ_CF2 += libdw1000.o libdw1000Spi.o

# vl53l1 lib
PROJ_OBJ_CF2 += vl53l1_api_core.o vl53l1_api.o vl53l1_core.o vl53l1_silicon_core.o vl53l1_api_strings.o
PROJ_OBJ_CF2 += vl53l1_api_calibration.o vl53l1_api_debug.o vl53l1_api_preset_modes.o vl53l1_error_strings.o
PROJ_OBJ_CF2 += vl53l1_register_funcs.o vl53l1_wait.o vl53l1_core_support.o

# Modules
PROJ_OBJ += system.o comm.o console.o pid.o crtpservice.o param.o
PROJ_OBJ += log.o worker.o trigger.o sitaw.o queuemonitor.o msp.o
Expand Down Expand Up @@ -230,6 +238,8 @@ INCLUDES_CF2 += -I$(LIB)/STM32_USB_OTG_Driver/inc
INCLUDES_CF2 += -Isrc/deck/interface -Isrc/deck/drivers/interface
INCLUDES_CF2 += -Ivendor/libdw1000/inc
INCLUDES_CF2 += -I$(LIB)/FatFS
INCLUDES_CF2 += -I$(LIB)/vl53l1
INCLUDES_CF2 += -I$(LIB)/vl53l1/core/inc

ifeq ($(USE_FPU), 1)
PROCESSOR = -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
Expand Down
282 changes: 282 additions & 0 deletions src/drivers/interface/vl53l1x.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
/*******************************************************************************
Copyright (C) 2016, 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_H_
#define _VL53L1X_H_

#include "vl53l1_ll_def.h"
#include "vl53l1_platform_user_data.h"
#include "vl53l1_api.h"

#ifdef __cplusplus
extern "C"
{
#endif

#define VL53L1X_DEFAULT_ADDRESS 0b0101001

#define USE_I2C_2V8

/**
* @file vl53l1_platform.h
*
* @brief All end user OS/platform/application porting
*/

bool vl53l1xInit(VL53L1_Dev_t *pdev, I2C_Dev *I2Cx);

bool vl53l1xTestConnection(VL53L1_Dev_t* pdev);

VL53L1_Error vl53l1xSetI2CAddress(VL53L1_Dev_t* pdev, uint8_t address);

/**
* @brief Writes the supplied byte buffer to the device
*
* @param[in] pdev : pointer to device structure (device handle)
* @param[in] index : uint16_t register index value
* @param[in] pdata : pointer to uint8_t (byte) buffer containing the data to be written
* @param[in] count : number of bytes in the supplied byte buffer
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/

VL53L1_Error VL53L1_WriteMulti(
VL53L1_Dev_t *pdev,
uint16_t index,
uint8_t *pdata,
uint32_t count);


/**
* @brief Reads the requested number of bytes from the device
*
* @param[in] pdev : pointer to device structure (device handle)
* @param[in] index : uint16_t register index value
* @param[out] pdata : pointer to the uint8_t (byte) buffer to store read data
* @param[in] count : number of bytes to read
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/

VL53L1_Error VL53L1_ReadMulti(
VL53L1_Dev_t *pdev,
uint16_t index,
uint8_t *pdata,
uint32_t count);


/**
* @brief Writes a single byte to the device
*
* @param[in] pdev : pointer to device structure (device handle)
* @param[in] index : uint16_t register index value
* @param[in] data : uint8_t data value to write
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/

VL53L1_Error VL53L1_WrByte(
VL53L1_Dev_t *pdev,
uint16_t index,
uint8_t data);


/**
* @brief Writes a single word (16-bit unsigned) to the device
*
* Manages the big-endian nature of the device register map
* (first byte written is the MS byte).
*
* @param[in] pdev : pointer to device structure (device handle)
* @param[in] index : uint16_t register index value
* @param[in] data : uin16_t data value write
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/

VL53L1_Error VL53L1_WrWord(
VL53L1_Dev_t *pdev,
uint16_t index,
uint16_t data);


/**
* @brief Writes a single dword (32-bit unsigned) to the device
*
* Manages the big-endian nature of the device register map
* (first byte written is the MS byte).
*
* @param[in] pdev : pointer to device structure (device handle)
* @param[in] index : uint16_t register index value
* @param[in] data : uint32_t data value to write
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/

VL53L1_Error VL53L1_WrDWord(
VL53L1_Dev_t *pdev,
uint16_t index,
uint32_t data);



/**
* @brief Reads a single byte from the device
*
* @param[in] pdev : pointer to device structure (device handle)
* @param[in] index : uint16_t register index
* @param[out] pdata : pointer to uint8_t data value
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*
*/

VL53L1_Error VL53L1_RdByte(
VL53L1_Dev_t *pdev,
uint16_t index,
uint8_t *pdata);


/**
* @brief Reads a single word (16-bit unsigned) from the device
*
* Manages the big-endian nature of the device (first byte read is the MS byte).
*
* @param[in] pdev : pointer to device structure (device handle)
* @param[in] index : uint16_t register index value
* @param[out] pdata : pointer to uint16_t data value
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/

VL53L1_Error VL53L1_RdWord(
VL53L1_Dev_t *pdev,
uint16_t index,
uint16_t *pdata);


/**
* @brief Reads a single dword (32-bit unsigned) from the device
*
* Manages the big-endian nature of the device (first byte read is the MS byte).
*
* @param[in] pdev : pointer to device structure (device handle)
* @param[in] index : uint16_t register index value
* @param[out] pdata : pointer to uint32_t data value
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/

VL53L1_Error VL53L1_RdDWord(
VL53L1_Dev_t *pdev,
uint16_t index,
uint32_t *pdata);



/**
* @brief Implements a programmable wait in us
*
* @param[in] pdev : pointer to device structure (device handle)
* @param[in] wait_us : integer wait in micro seconds
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/

VL53L1_Error VL53L1_WaitUs(
VL53L1_Dev_t *pdev,
int32_t wait_us);


/**
* @brief Implements a programmable wait in ms
*
* @param[in] pdev : pointer to device structure (device handle)
* @param[in] wait_ms : integer wait in milliseconds
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/

VL53L1_Error VL53L1_WaitMs(
VL53L1_Dev_t *pdev,
int32_t wait_ms);

/*
* @brief Gets current system tick count in [ms]
*
* @return time_ms : current time in [ms]
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/

VL53L1_Error VL53L1_GetTickCount(
uint32_t *ptime_ms);


/**
* @brief Register "wait for value" polling routine
*
* Port of the V2WReg Script function WaitValueMaskEx()
*
* @param[in] pdev : pointer to device structure (device handle)
* @param[in] timeout_ms : timeout in [ms]
* @param[in] index : uint16_t register index value
* @param[in] value : value to wait for
* @param[in] mask : mask to be applied before comparison with value
* @param[in] poll_delay_ms : polling delay been each read transaction in [ms]
*
* @return VL53L1_ERROR_NONE Success
* @return "Other error code" See ::VL53L1_Error
*/

VL53L1_Error VL53L1_WaitValueMaskEx(
VL53L1_Dev_t *pdev,
uint32_t timeout_ms,
uint16_t index,
uint8_t value,
uint8_t mask,
uint32_t poll_delay_ms);

#ifdef __cplusplus
}
#endif

#endif

Loading

0 comments on commit 11c39c2

Please sign in to comment.