Contains Ayoub's Ranging and Custom interfaces for the VL53L3CX

Committer:
charlesmn
Date:
Wed Jul 21 14:47:53 2021 +0000
Revision:
1:dae4cb24beec
Parent:
0:c1910e04fc6c
strip out commented out code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
charlesmn 0:c1910e04fc6c 1 /**
charlesmn 0:c1910e04fc6c 2 ******************************************************************************
charlesmn 0:c1910e04fc6c 3 * @file vl53l3cx.h
charlesmn 0:c1910e04fc6c 4 * @author IMG SW Application Team
charlesmn 0:c1910e04fc6c 5 * @brief This file contains all the functions prototypes for the vl53l3cx.c
charlesmn 0:c1910e04fc6c 6 * driver.
charlesmn 0:c1910e04fc6c 7 ******************************************************************************
charlesmn 0:c1910e04fc6c 8 * @attention
charlesmn 0:c1910e04fc6c 9 *
charlesmn 0:c1910e04fc6c 10 * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
charlesmn 0:c1910e04fc6c 11 * All rights reserved.</center></h2>
charlesmn 0:c1910e04fc6c 12 *
charlesmn 0:c1910e04fc6c 13 * This software component is licensed by ST under BSD 3-Clause license,
charlesmn 0:c1910e04fc6c 14 * the "License"; You may not use this file except in compliance with the
charlesmn 0:c1910e04fc6c 15 * License. You may obtain a copy of the License at:
charlesmn 0:c1910e04fc6c 16 * opensource.org/licenses/BSD-3-Clause
charlesmn 0:c1910e04fc6c 17 *
charlesmn 0:c1910e04fc6c 18 ******************************************************************************
charlesmn 0:c1910e04fc6c 19 */
charlesmn 0:c1910e04fc6c 20
charlesmn 0:c1910e04fc6c 21 /* Define to prevent recursive inclusion -------------------------------------*/
charlesmn 0:c1910e04fc6c 22 #ifndef VL53L3CX_H
charlesmn 0:c1910e04fc6c 23 #define VL53L3CX_H
charlesmn 0:c1910e04fc6c 24
charlesmn 0:c1910e04fc6c 25 #ifdef __cplusplus
charlesmn 0:c1910e04fc6c 26 extern "C" {
charlesmn 0:c1910e04fc6c 27 #endif
charlesmn 0:c1910e04fc6c 28
charlesmn 0:c1910e04fc6c 29 /* Includes ------------------------------------------------------------------*/
charlesmn 0:c1910e04fc6c 30 #include <stddef.h>
charlesmn 0:c1910e04fc6c 31 #include <math.h>
charlesmn 0:c1910e04fc6c 32 #include "vl53lx_def.h"
charlesmn 0:c1910e04fc6c 33
charlesmn 0:c1910e04fc6c 34 //#include "mbed.h"
charlesmn 0:c1910e04fc6c 35
charlesmn 0:c1910e04fc6c 36 #include "pinmap.h"
charlesmn 0:c1910e04fc6c 37
charlesmn 0:c1910e04fc6c 38
charlesmn 0:c1910e04fc6c 39 /** @addtogroup BSP
charlesmn 0:c1910e04fc6c 40 * @{
charlesmn 0:c1910e04fc6c 41 */
charlesmn 0:c1910e04fc6c 42
charlesmn 0:c1910e04fc6c 43 /** @addtogroup Components
charlesmn 0:c1910e04fc6c 44 * @{
charlesmn 0:c1910e04fc6c 45 */
charlesmn 0:c1910e04fc6c 46
charlesmn 0:c1910e04fc6c 47 /** @addtogroup VL53L3CX
charlesmn 0:c1910e04fc6c 48 * @{
charlesmn 0:c1910e04fc6c 49 */
charlesmn 0:c1910e04fc6c 50
charlesmn 0:c1910e04fc6c 51 /** @defgroup VL53L3CX_Exported_Constants Exported Constants
charlesmn 0:c1910e04fc6c 52 * @{
charlesmn 0:c1910e04fc6c 53 */
charlesmn 0:c1910e04fc6c 54 #define VL53L3CX_ID (0xEAAAU)
charlesmn 0:c1910e04fc6c 55 #define VL53L3CX_ID_REG (0x010FU)
charlesmn 0:c1910e04fc6c 56
charlesmn 0:c1910e04fc6c 57 #define VL53L3CX_DEVICE_ADDRESS (0x52U)
charlesmn 0:c1910e04fc6c 58 #define VL53L3CX_NB_TARGET_PER_ZONE (4U)
charlesmn 0:c1910e04fc6c 59 #define VL53L3CX_MAX_NB_ZONES (1U)
charlesmn 0:c1910e04fc6c 60
charlesmn 0:c1910e04fc6c 61 /* vl53l3cx ranging profiles */
charlesmn 0:c1910e04fc6c 62 #define VL53L3CX_PROFILE_SHORT (VL53LX_DISTANCEMODE_SHORT)
charlesmn 0:c1910e04fc6c 63 #define VL53L3CX_PROFILE_MEDIUM (VL53LX_DISTANCEMODE_MEDIUM)
charlesmn 0:c1910e04fc6c 64 #define VL53L3CX_PROFILE_LONG (VL53LX_DISTANCEMODE_LONG)
charlesmn 0:c1910e04fc6c 65
charlesmn 0:c1910e04fc6c 66 /* vl53l3cx ranging modes */
charlesmn 0:c1910e04fc6c 67 #define VL53L3CX_MODE_BLOCKING_CONTINUOUS (1U)
charlesmn 0:c1910e04fc6c 68 #define VL53L3CX_MODE_BLOCKING_ONESHOT (2U)
charlesmn 0:c1910e04fc6c 69 #define VL53L3CX_MODE_ASYNC_CONTINUOUS (3U)
charlesmn 0:c1910e04fc6c 70 #define VL53L3CX_MODE_ASYNC_ONESHOT (4U)
charlesmn 0:c1910e04fc6c 71
charlesmn 0:c1910e04fc6c 72 /* vl53l3cx error codes */
charlesmn 0:c1910e04fc6c 73 #define VL53L3CX_OK (0)
charlesmn 0:c1910e04fc6c 74 #define VL53L3CX_ERROR (-1)
charlesmn 0:c1910e04fc6c 75 #define VL53L3CX_INVALID_PARAM (-2)
charlesmn 0:c1910e04fc6c 76 #define VL53L3CX_TIMEOUT (-3)
charlesmn 0:c1910e04fc6c 77 #define VL53L3CX_NOT_IMPLEMENTED (-4)
charlesmn 0:c1910e04fc6c 78 /**
charlesmn 0:c1910e04fc6c 79 * @}
charlesmn 0:c1910e04fc6c 80 */
charlesmn 0:c1910e04fc6c 81
charlesmn 0:c1910e04fc6c 82 /** @defgroup VL53L3CX_Exported_Types Exported Types
charlesmn 0:c1910e04fc6c 83 * @{
charlesmn 0:c1910e04fc6c 84 */
charlesmn 0:c1910e04fc6c 85 typedef int32_t (*VL53L3CX_Init_Func)(void);
charlesmn 0:c1910e04fc6c 86 typedef int32_t (*VL53L3CX_DeInit_Func)(void);
charlesmn 0:c1910e04fc6c 87 typedef int32_t (*VL53L3CX_GetTick_Func)(void);
charlesmn 0:c1910e04fc6c 88 typedef int32_t (*VL53L3CX_Delay_Func)(uint32_t);
charlesmn 0:c1910e04fc6c 89 typedef int32_t (*VL53L3CX_WriteReg_Func)(uint16_t, uint8_t *, uint16_t);
charlesmn 0:c1910e04fc6c 90 typedef int32_t (*VL53L3CX_ReadReg_Func)(uint16_t, uint8_t *, uint16_t);
charlesmn 0:c1910e04fc6c 91 typedef void (*VL53L3CX_Interrupt_Func)(void);
charlesmn 0:c1910e04fc6c 92
charlesmn 0:c1910e04fc6c 93 typedef struct
charlesmn 0:c1910e04fc6c 94 {
charlesmn 0:c1910e04fc6c 95 VL53L3CX_Init_Func Init;
charlesmn 0:c1910e04fc6c 96 VL53L3CX_DeInit_Func DeInit;
charlesmn 0:c1910e04fc6c 97 uint16_t Address;
charlesmn 0:c1910e04fc6c 98 VL53L3CX_WriteReg_Func WriteReg;
charlesmn 0:c1910e04fc6c 99 VL53L3CX_ReadReg_Func ReadReg;
charlesmn 0:c1910e04fc6c 100 VL53L3CX_GetTick_Func GetTick;
charlesmn 0:c1910e04fc6c 101 } VL53L3CX_IO_t;
charlesmn 0:c1910e04fc6c 102
charlesmn 0:c1910e04fc6c 103 typedef struct
charlesmn 0:c1910e04fc6c 104 {
charlesmn 0:c1910e04fc6c 105 VL53LX_DevData_t Data; /*!< ranging sensor context */
charlesmn 0:c1910e04fc6c 106 } VL53LX_Dev_t;
charlesmn 0:c1910e04fc6c 107
charlesmn 0:c1910e04fc6c 108 typedef struct
charlesmn 0:c1910e04fc6c 109 {
charlesmn 0:c1910e04fc6c 110 VL53L3CX_IO_t IO;
charlesmn 0:c1910e04fc6c 111 VL53LX_Dev_t Dev;
charlesmn 0:c1910e04fc6c 112 uint8_t IsInitialized; /*!< NotInitialized: 0, Initialized: 1 */
charlesmn 0:c1910e04fc6c 113 uint8_t IsRanging; /*!< Not Started: 0, Started: 1 */
charlesmn 0:c1910e04fc6c 114 uint8_t IsBlocking; /*!< Interrupt: 0, Polling: 1 */
charlesmn 0:c1910e04fc6c 115 uint8_t IsContinuous; /*!< One shot: 0, Continuous: 1 */
charlesmn 0:c1910e04fc6c 116 uint8_t IsAmbientEnabled; /*!< Enabled: 0, Disabled: 1 */
charlesmn 0:c1910e04fc6c 117 uint8_t IsSignalEnabled; /*!< Enabled: 0, Disabled: 1 */
charlesmn 0:c1910e04fc6c 118 uint8_t RangingProfile;
charlesmn 0:c1910e04fc6c 119 uint32_t EnableInterrupt; /*<! Enable: 1, Disable: 0 */
charlesmn 0:c1910e04fc6c 120 PinName pin_gpio1; // name of interrupt pin
charlesmn 0:c1910e04fc6c 121 VL53L3CX_Interrupt_Func Interrupt_Func;
charlesmn 0:c1910e04fc6c 122 } VL53L3CX_Object_t;
charlesmn 0:c1910e04fc6c 123
charlesmn 0:c1910e04fc6c 124 typedef struct
charlesmn 0:c1910e04fc6c 125 {
charlesmn 0:c1910e04fc6c 126 uint32_t NumberOfTargets;
charlesmn 0:c1910e04fc6c 127 uint32_t Distance[VL53L3CX_NB_TARGET_PER_ZONE]; /*!< millimeter */
charlesmn 0:c1910e04fc6c 128 uint32_t Status[VL53L3CX_NB_TARGET_PER_ZONE]; /*!< 0: OK, 1: NOK */
charlesmn 0:c1910e04fc6c 129 float_t Ambient[VL53L3CX_NB_TARGET_PER_ZONE]; /*!< kcps / spad */
charlesmn 0:c1910e04fc6c 130 float_t Signal[VL53L3CX_NB_TARGET_PER_ZONE]; /*!< kcps / spad */
charlesmn 0:c1910e04fc6c 131 } VL53L3CX_TargetResult_t;
charlesmn 0:c1910e04fc6c 132
charlesmn 0:c1910e04fc6c 133 typedef struct
charlesmn 0:c1910e04fc6c 134 {
charlesmn 0:c1910e04fc6c 135 uint32_t NumberOfZones;
charlesmn 0:c1910e04fc6c 136 VL53L3CX_TargetResult_t ZoneResult[VL53L3CX_MAX_NB_ZONES];
charlesmn 0:c1910e04fc6c 137 } VL53L3CX_Result_t;
charlesmn 0:c1910e04fc6c 138
charlesmn 0:c1910e04fc6c 139 typedef struct
charlesmn 0:c1910e04fc6c 140 {
charlesmn 0:c1910e04fc6c 141 uint32_t Criteria;
charlesmn 0:c1910e04fc6c 142 uint32_t LowThreshold;
charlesmn 0:c1910e04fc6c 143 uint32_t HighThreshold;
charlesmn 0:c1910e04fc6c 144 } VL53L3CX_ITConfig_t;
charlesmn 0:c1910e04fc6c 145
charlesmn 0:c1910e04fc6c 146 typedef struct
charlesmn 0:c1910e04fc6c 147 {
charlesmn 0:c1910e04fc6c 148 uint8_t TopLeftX; /*!< Top Left x coordinate: 0-15 range */
charlesmn 0:c1910e04fc6c 149 uint8_t TopLeftY; /*!< Top Left y coordinate: 0-15 range */
charlesmn 0:c1910e04fc6c 150 uint8_t BotRightX; /*!< Bot Right x coordinate: 0-15 range */
charlesmn 0:c1910e04fc6c 151 uint8_t BotRightY; /*!< Bot Right y coordinate: 0-15 range */
charlesmn 0:c1910e04fc6c 152 } VL53L3CX_ROIConfig_t;
charlesmn 0:c1910e04fc6c 153
charlesmn 0:c1910e04fc6c 154 typedef struct
charlesmn 0:c1910e04fc6c 155 {
charlesmn 0:c1910e04fc6c 156 uint8_t RangingProfile;
charlesmn 0:c1910e04fc6c 157 uint32_t TimingBudget; /*!< Expressed in milliseconds */
charlesmn 0:c1910e04fc6c 158 uint32_t Frequency; /*!< Expressed in Hz */
charlesmn 0:c1910e04fc6c 159 uint32_t EnableAmbient; /*<! Enable: 1, Disable: 0 */
charlesmn 0:c1910e04fc6c 160 uint32_t EnableSignal; /*<! Enable: 1, Disable: 0 */
charlesmn 0:c1910e04fc6c 161 PinName pin_gpio1; // name of interrupt pin
charlesmn 0:c1910e04fc6c 162 uint32_t EnableInterrupt; /*<! Enable: 1, Disable: 0 */
charlesmn 0:c1910e04fc6c 163 VL53L3CX_Interrupt_Func Interrupt_Func;
charlesmn 0:c1910e04fc6c 164 } VL53L3CX_ProfileConfig_t;
charlesmn 0:c1910e04fc6c 165
charlesmn 0:c1910e04fc6c 166 typedef struct
charlesmn 0:c1910e04fc6c 167 {
charlesmn 0:c1910e04fc6c 168 uint32_t NumberOfZones;
charlesmn 0:c1910e04fc6c 169 uint32_t MaxNumberOfTargetsPerZone;
charlesmn 0:c1910e04fc6c 170 uint32_t CustomROI; /*<! Not available: 0, Available: 1 */
charlesmn 0:c1910e04fc6c 171 uint32_t ThresholdDetection; /*<! Not available: 0, Available: 1 */
charlesmn 0:c1910e04fc6c 172 } VL53L3CX_Capabilities_t;
charlesmn 0:c1910e04fc6c 173
charlesmn 0:c1910e04fc6c 174 typedef struct
charlesmn 0:c1910e04fc6c 175 {
charlesmn 0:c1910e04fc6c 176 int32_t (*Init)(VL53L3CX_Object_t *);
charlesmn 0:c1910e04fc6c 177 int32_t (*DeInit)(VL53L3CX_Object_t *);
charlesmn 0:c1910e04fc6c 178 int32_t (*ReadID)(VL53L3CX_Object_t *, uint32_t *);
charlesmn 0:c1910e04fc6c 179 int32_t (*GetCapabilities)(VL53L3CX_Object_t *, VL53L3CX_Capabilities_t *);
charlesmn 0:c1910e04fc6c 180 int32_t (*ConfigProfile)(VL53L3CX_Object_t *, VL53L3CX_ProfileConfig_t *);
charlesmn 0:c1910e04fc6c 181 int32_t (*ConfigROI)(VL53L3CX_Object_t *, VL53L3CX_ROIConfig_t *);
charlesmn 0:c1910e04fc6c 182 int32_t (*ConfigIT)(VL53L3CX_Object_t *, VL53L3CX_ITConfig_t *);
charlesmn 0:c1910e04fc6c 183 int32_t (*GetDistance)(VL53L3CX_Object_t *, VL53L3CX_Result_t *);
charlesmn 0:c1910e04fc6c 184 int32_t (*Start)(VL53L3CX_Object_t *, uint32_t);
charlesmn 0:c1910e04fc6c 185 int32_t (*Stop)(VL53L3CX_Object_t *);
charlesmn 0:c1910e04fc6c 186 int32_t (*SetAddress)(VL53L3CX_Object_t *, uint32_t);
charlesmn 0:c1910e04fc6c 187 int32_t (*GetAddress)(VL53L3CX_Object_t *, uint32_t *);
charlesmn 0:c1910e04fc6c 188 int32_t (*SetPowerMode)(VL53L3CX_Object_t *, uint32_t);
charlesmn 0:c1910e04fc6c 189 int32_t (*GetPowerMode)(VL53L3CX_Object_t *, uint32_t *);
charlesmn 0:c1910e04fc6c 190 } VL53L3CX_RANGING_SENSOR_Drv_t;
charlesmn 0:c1910e04fc6c 191 /**
charlesmn 0:c1910e04fc6c 192 * @}
charlesmn 0:c1910e04fc6c 193 */
charlesmn 0:c1910e04fc6c 194
charlesmn 0:c1910e04fc6c 195 /** @defgroup VL53L3CX_Exported_Functions VL53L3CX Exported Functions
charlesmn 0:c1910e04fc6c 196 * @{
charlesmn 0:c1910e04fc6c 197 */
charlesmn 0:c1910e04fc6c 198 /* RANGING_SENSOR methods */
charlesmn 0:c1910e04fc6c 199 int32_t VL53L3CX_RegisterBusIO(VL53L3CX_Object_t *pObj, VL53L3CX_IO_t *pIO);
charlesmn 0:c1910e04fc6c 200 int32_t VL53L3CX_Init(VL53L3CX_Object_t *pObj);
charlesmn 0:c1910e04fc6c 201 int32_t VL53L3CX_DeInit(VL53L3CX_Object_t *pObj);
charlesmn 0:c1910e04fc6c 202 int32_t VL53L3CX_ReadID(VL53L3CX_Object_t *pObj, uint32_t *pId);
charlesmn 0:c1910e04fc6c 203 int32_t VL53L3CX_GetCapabilities(VL53L3CX_Object_t *pObj, VL53L3CX_Capabilities_t *pCap);
charlesmn 0:c1910e04fc6c 204 int32_t VL53L3CX_ConfigProfile(VL53L3CX_Object_t *pObj, VL53L3CX_ProfileConfig_t *pConfig);
charlesmn 0:c1910e04fc6c 205 int32_t VL53L3CX_ConfigROI(VL53L3CX_Object_t *pObj, VL53L3CX_ROIConfig_t *pROIConfig);
charlesmn 0:c1910e04fc6c 206 int32_t VL53L3CX_ConfigIT(VL53L3CX_Object_t *pObj, VL53L3CX_ITConfig_t *pITConfig);
charlesmn 0:c1910e04fc6c 207 int32_t VL53L3CX_GetDistance(VL53L3CX_Object_t *pObj, VL53L3CX_Result_t *pResult);
charlesmn 0:c1910e04fc6c 208 int32_t VL53L3CX_Start(VL53L3CX_Object_t *pObj, uint32_t Mode);
charlesmn 0:c1910e04fc6c 209 int32_t VL53L3CX_Stop(VL53L3CX_Object_t *pObj);
charlesmn 0:c1910e04fc6c 210 int32_t VL53L3CX_SetAddress(VL53L3CX_Object_t *pObj, uint32_t Address);
charlesmn 0:c1910e04fc6c 211 int32_t VL53L3CX_GetAddress(VL53L3CX_Object_t *pObj, uint32_t *pAddress);
charlesmn 0:c1910e04fc6c 212 int32_t VL53L3CX_SetPowerMode(VL53L3CX_Object_t *pObj, uint32_t PowerMode);
charlesmn 0:c1910e04fc6c 213 int32_t VL53L3CX_GetPowerMode(VL53L3CX_Object_t *pObj, uint32_t *pPowerMode);
charlesmn 0:c1910e04fc6c 214
charlesmn 0:c1910e04fc6c 215 /* additional methods */
charlesmn 0:c1910e04fc6c 216 int32_t VL53L3CX_OffsetCalibration(VL53L3CX_Object_t *pObj, uint32_t CalDistance);
charlesmn 0:c1910e04fc6c 217 int32_t VL53L3CX_XTalkCalibration(VL53L3CX_Object_t *pObj);
charlesmn 0:c1910e04fc6c 218 /**
charlesmn 0:c1910e04fc6c 219 * @}
charlesmn 0:c1910e04fc6c 220 */
charlesmn 0:c1910e04fc6c 221
charlesmn 0:c1910e04fc6c 222 /* RANGING_SENSOR driver structure */
charlesmn 0:c1910e04fc6c 223 extern VL53L3CX_RANGING_SENSOR_Drv_t VL53L3CX_RANGING_SENSOR_Driver;
charlesmn 0:c1910e04fc6c 224
charlesmn 0:c1910e04fc6c 225 #ifdef __cplusplus
charlesmn 0:c1910e04fc6c 226 }
charlesmn 0:c1910e04fc6c 227 #endif
charlesmn 0:c1910e04fc6c 228
charlesmn 0:c1910e04fc6c 229 #endif /* VL53L3CX_H */
charlesmn 0:c1910e04fc6c 230 /**
charlesmn 0:c1910e04fc6c 231 * @}
charlesmn 0:c1910e04fc6c 232 */
charlesmn 0:c1910e04fc6c 233
charlesmn 0:c1910e04fc6c 234 /**
charlesmn 0:c1910e04fc6c 235 * @}
charlesmn 0:c1910e04fc6c 236 */
charlesmn 0:c1910e04fc6c 237
charlesmn 0:c1910e04fc6c 238 /**
charlesmn 0:c1910e04fc6c 239 * @}
charlesmn 0:c1910e04fc6c 240 */
charlesmn 0:c1910e04fc6c 241
charlesmn 0:c1910e04fc6c 242 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
charlesmn 0:c1910e04fc6c 243