Contains Ayoub's Ranging and Custom interfaces for the VL53L3CX
custom_ranging_sensor.c@1:dae4cb24beec, 2021-07-21 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
charlesmn | 0:c1910e04fc6c | 1 | /** |
charlesmn | 0:c1910e04fc6c | 2 | ****************************************************************************** |
charlesmn | 0:c1910e04fc6c | 3 | * @file custom_ranging_sensor.c |
charlesmn | 0:c1910e04fc6c | 4 | * @author IMG SW Application Team |
charlesmn | 0:c1910e04fc6c | 5 | * @brief This file provides BSP Ranging Sensors interface for custom boards |
charlesmn | 0:c1910e04fc6c | 6 | ****************************************************************************** |
charlesmn | 0:c1910e04fc6c | 7 | * @attention |
charlesmn | 0:c1910e04fc6c | 8 | * |
charlesmn | 0:c1910e04fc6c | 9 | * <h2><center>© Copyright (c) 2021 STMicroelectronics. |
charlesmn | 0:c1910e04fc6c | 10 | * All rights reserved.</center></h2> |
charlesmn | 0:c1910e04fc6c | 11 | * |
charlesmn | 0:c1910e04fc6c | 12 | * This software component is licensed by ST under BSD 3-Clause license, |
charlesmn | 0:c1910e04fc6c | 13 | * the "License"; You may not use this file except in compliance with the |
charlesmn | 0:c1910e04fc6c | 14 | * License. You may obtain a copy of the License at: |
charlesmn | 0:c1910e04fc6c | 15 | * opensource.org/licenses/BSD-3-Clause |
charlesmn | 0:c1910e04fc6c | 16 | * |
charlesmn | 0:c1910e04fc6c | 17 | ****************************************************************************** |
charlesmn | 0:c1910e04fc6c | 18 | */ |
charlesmn | 0:c1910e04fc6c | 19 | |
charlesmn | 0:c1910e04fc6c | 20 | /* Includes ------------------------------------------------------------------*/ |
charlesmn | 0:c1910e04fc6c | 21 | #include "custom_ranging_sensor.h" |
charlesmn | 0:c1910e04fc6c | 22 | #include "vl53lx_platform.h" |
charlesmn | 0:c1910e04fc6c | 23 | #include "spi_interface.h" |
charlesmn | 0:c1910e04fc6c | 24 | #include "PinNames.h" |
charlesmn | 0:c1910e04fc6c | 25 | |
charlesmn | 0:c1910e04fc6c | 26 | void wait_ms(int ms); |
charlesmn | 0:c1910e04fc6c | 27 | |
charlesmn | 0:c1910e04fc6c | 28 | void *CUSTOM_RANGING_CompObj[CUSTOM_RANGING_INSTANCES_NBR] = {0}; |
charlesmn | 0:c1910e04fc6c | 29 | static RANGING_SENSOR_Drv_t *CUSTOM_RANGING_Drv[CUSTOM_RANGING_INSTANCES_NBR]; |
charlesmn | 0:c1910e04fc6c | 30 | static RANGING_SENSOR_Capabilities_t RANGING_SENSOR_Cap[CUSTOM_RANGING_INSTANCES_NBR]; |
charlesmn | 0:c1910e04fc6c | 31 | |
charlesmn | 0:c1910e04fc6c | 32 | #if (USE_CUSTOM_RANGING_VL53L3CX == 1U) |
charlesmn | 0:c1910e04fc6c | 33 | static int32_t VL53L3CX_Probe(uint32_t Instance); |
charlesmn | 0:c1910e04fc6c | 34 | #endif |
charlesmn | 0:c1910e04fc6c | 35 | |
charlesmn | 0:c1910e04fc6c | 36 | /** |
charlesmn | 0:c1910e04fc6c | 37 | * @brief Initializes the ranging sensor. |
charlesmn | 0:c1910e04fc6c | 38 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 39 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 40 | */ |
charlesmn | 0:c1910e04fc6c | 41 | int32_t CUSTOM_RANGING_SENSOR_Init(uint32_t Instance) |
charlesmn | 0:c1910e04fc6c | 42 | { |
charlesmn | 0:c1910e04fc6c | 43 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 44 | |
charlesmn | 0:c1910e04fc6c | 45 | printf("CUSTOM_RANGING_SENSOR_Init %d >= %d \n",Instance,CUSTOM_RANGING_INSTANCES_NBR); |
charlesmn | 0:c1910e04fc6c | 46 | |
charlesmn | 0:c1910e04fc6c | 47 | if (Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 48 | { |
charlesmn | 0:c1910e04fc6c | 49 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 50 | } |
charlesmn | 0:c1910e04fc6c | 51 | else |
charlesmn | 0:c1910e04fc6c | 52 | { |
charlesmn | 0:c1910e04fc6c | 53 | CUSTOM_RANGING_SENSOR_SetPowerMode(Instance, CUSTOM_RANGING_POWERMODE_OFF); |
charlesmn | 0:c1910e04fc6c | 54 | CUSTOM_RANGING_SENSOR_SetPowerMode(Instance, CUSTOM_RANGING_POWERMODE_ON); |
charlesmn | 0:c1910e04fc6c | 55 | |
charlesmn | 0:c1910e04fc6c | 56 | switch (Instance) |
charlesmn | 0:c1910e04fc6c | 57 | { |
charlesmn | 0:c1910e04fc6c | 58 | #if (USE_CUSTOM_RANGING_VL53L3CX == 1U) |
charlesmn | 0:c1910e04fc6c | 59 | case CUSTOM_VL53L3CX: |
charlesmn | 0:c1910e04fc6c | 60 | if (VL53L3CX_Probe(Instance) != BSP_ERROR_NONE) |
charlesmn | 0:c1910e04fc6c | 61 | { |
charlesmn | 0:c1910e04fc6c | 62 | ret = BSP_ERROR_NO_INIT; |
charlesmn | 0:c1910e04fc6c | 63 | } |
charlesmn | 0:c1910e04fc6c | 64 | else |
charlesmn | 0:c1910e04fc6c | 65 | { |
charlesmn | 0:c1910e04fc6c | 66 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 67 | } |
charlesmn | 0:c1910e04fc6c | 68 | break; |
charlesmn | 0:c1910e04fc6c | 69 | #endif |
charlesmn | 0:c1910e04fc6c | 70 | default: |
charlesmn | 0:c1910e04fc6c | 71 | ret = BSP_ERROR_UNKNOWN_COMPONENT; |
charlesmn | 0:c1910e04fc6c | 72 | break; |
charlesmn | 0:c1910e04fc6c | 73 | } |
charlesmn | 0:c1910e04fc6c | 74 | } |
charlesmn | 0:c1910e04fc6c | 75 | |
charlesmn | 0:c1910e04fc6c | 76 | return ret; |
charlesmn | 0:c1910e04fc6c | 77 | } |
charlesmn | 0:c1910e04fc6c | 78 | |
charlesmn | 0:c1910e04fc6c | 79 | /** |
charlesmn | 0:c1910e04fc6c | 80 | * @brief Deinitializes the ranging sensor. |
charlesmn | 0:c1910e04fc6c | 81 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 82 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 83 | */ |
charlesmn | 0:c1910e04fc6c | 84 | int32_t CUSTOM_RANGING_SENSOR_DeInit(uint32_t Instance) |
charlesmn | 0:c1910e04fc6c | 85 | { |
charlesmn | 0:c1910e04fc6c | 86 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 87 | |
charlesmn | 0:c1910e04fc6c | 88 | if(Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 89 | { |
charlesmn | 0:c1910e04fc6c | 90 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 91 | } |
charlesmn | 0:c1910e04fc6c | 92 | else if (CUSTOM_RANGING_Drv[Instance]->DeInit(CUSTOM_RANGING_CompObj[Instance]) < 0) |
charlesmn | 0:c1910e04fc6c | 93 | { |
charlesmn | 0:c1910e04fc6c | 94 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 95 | } |
charlesmn | 0:c1910e04fc6c | 96 | else |
charlesmn | 0:c1910e04fc6c | 97 | { |
charlesmn | 0:c1910e04fc6c | 98 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 99 | } |
charlesmn | 0:c1910e04fc6c | 100 | |
charlesmn | 0:c1910e04fc6c | 101 | return ret; |
charlesmn | 0:c1910e04fc6c | 102 | } |
charlesmn | 0:c1910e04fc6c | 103 | |
charlesmn | 0:c1910e04fc6c | 104 | /** |
charlesmn | 0:c1910e04fc6c | 105 | * @brief Read the ranging sensor device ID. |
charlesmn | 0:c1910e04fc6c | 106 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 107 | * @param pId Pointer to the device ID. |
charlesmn | 0:c1910e04fc6c | 108 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 109 | */ |
charlesmn | 0:c1910e04fc6c | 110 | int32_t CUSTOM_RANGING_SENSOR_ReadID(uint32_t Instance, uint32_t *pId) |
charlesmn | 0:c1910e04fc6c | 111 | { |
charlesmn | 0:c1910e04fc6c | 112 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 113 | |
charlesmn | 0:c1910e04fc6c | 114 | if (Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 115 | { |
charlesmn | 0:c1910e04fc6c | 116 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 117 | } |
charlesmn | 0:c1910e04fc6c | 118 | else if (CUSTOM_RANGING_Drv[Instance]->ReadID(CUSTOM_RANGING_CompObj[Instance], pId) < 0) |
charlesmn | 0:c1910e04fc6c | 119 | { |
charlesmn | 0:c1910e04fc6c | 120 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 121 | } |
charlesmn | 0:c1910e04fc6c | 122 | else |
charlesmn | 0:c1910e04fc6c | 123 | { |
charlesmn | 0:c1910e04fc6c | 124 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 125 | } |
charlesmn | 0:c1910e04fc6c | 126 | |
charlesmn | 0:c1910e04fc6c | 127 | return ret; |
charlesmn | 0:c1910e04fc6c | 128 | } |
charlesmn | 0:c1910e04fc6c | 129 | |
charlesmn | 0:c1910e04fc6c | 130 | /** |
charlesmn | 0:c1910e04fc6c | 131 | * @brief Get the ranging sensor capabilities. |
charlesmn | 0:c1910e04fc6c | 132 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 133 | * @param pCapabilities Pointer to the ranging sensor capabilities. |
charlesmn | 0:c1910e04fc6c | 134 | * @note This function should be called after the init. |
charlesmn | 0:c1910e04fc6c | 135 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 136 | */ |
charlesmn | 0:c1910e04fc6c | 137 | int32_t CUSTOM_RANGING_SENSOR_GetCapabilities(uint32_t Instance, RANGING_SENSOR_Capabilities_t *pCapabilities) |
charlesmn | 0:c1910e04fc6c | 138 | { |
charlesmn | 0:c1910e04fc6c | 139 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 140 | |
charlesmn | 0:c1910e04fc6c | 141 | if (Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 142 | { |
charlesmn | 0:c1910e04fc6c | 143 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 144 | } |
charlesmn | 0:c1910e04fc6c | 145 | else if (CUSTOM_RANGING_Drv[Instance]->GetCapabilities(CUSTOM_RANGING_CompObj[Instance], pCapabilities) < 0) |
charlesmn | 0:c1910e04fc6c | 146 | { |
charlesmn | 0:c1910e04fc6c | 147 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 148 | } |
charlesmn | 0:c1910e04fc6c | 149 | else |
charlesmn | 0:c1910e04fc6c | 150 | { |
charlesmn | 0:c1910e04fc6c | 151 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 152 | } |
charlesmn | 0:c1910e04fc6c | 153 | |
charlesmn | 0:c1910e04fc6c | 154 | return ret; |
charlesmn | 0:c1910e04fc6c | 155 | } |
charlesmn | 0:c1910e04fc6c | 156 | |
charlesmn | 0:c1910e04fc6c | 157 | /** |
charlesmn | 0:c1910e04fc6c | 158 | * @brief Set the ranging configuration profile. |
charlesmn | 0:c1910e04fc6c | 159 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 160 | * @param pConfig Pointer to the new configuration profile to be applied. |
charlesmn | 0:c1910e04fc6c | 161 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 162 | */ |
charlesmn | 0:c1910e04fc6c | 163 | int32_t CUSTOM_RANGING_SENSOR_ConfigProfile(uint32_t Instance, RANGING_SENSOR_ProfileConfig_t *pConfig) |
charlesmn | 0:c1910e04fc6c | 164 | { |
charlesmn | 0:c1910e04fc6c | 165 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 166 | |
charlesmn | 0:c1910e04fc6c | 167 | if (Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 168 | { |
charlesmn | 0:c1910e04fc6c | 169 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 170 | } |
charlesmn | 0:c1910e04fc6c | 171 | else if (CUSTOM_RANGING_Drv[Instance]->ConfigProfile(CUSTOM_RANGING_CompObj[Instance], pConfig) < 0) |
charlesmn | 0:c1910e04fc6c | 172 | { |
charlesmn | 0:c1910e04fc6c | 173 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 174 | } |
charlesmn | 0:c1910e04fc6c | 175 | else |
charlesmn | 0:c1910e04fc6c | 176 | { |
charlesmn | 0:c1910e04fc6c | 177 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 178 | } |
charlesmn | 0:c1910e04fc6c | 179 | |
charlesmn | 0:c1910e04fc6c | 180 | return ret; |
charlesmn | 0:c1910e04fc6c | 181 | } |
charlesmn | 0:c1910e04fc6c | 182 | |
charlesmn | 0:c1910e04fc6c | 183 | /** |
charlesmn | 0:c1910e04fc6c | 184 | * @brief Configure the Region of Interest of the ranging sensor. |
charlesmn | 0:c1910e04fc6c | 185 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 186 | * @param pConfig Pointer to the ROI configuration struct. |
charlesmn | 0:c1910e04fc6c | 187 | * @note Should be called only if the device supports CustomROI. |
charlesmn | 0:c1910e04fc6c | 188 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 189 | */ |
charlesmn | 0:c1910e04fc6c | 190 | int32_t CUSTOM_RANGING_SENSOR_ConfigROI(uint32_t Instance, RANGING_SENSOR_ROIConfig_t *pConfig) |
charlesmn | 0:c1910e04fc6c | 191 | { |
charlesmn | 0:c1910e04fc6c | 192 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 193 | |
charlesmn | 0:c1910e04fc6c | 194 | if (Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 195 | { |
charlesmn | 0:c1910e04fc6c | 196 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 197 | } |
charlesmn | 0:c1910e04fc6c | 198 | else if (RANGING_SENSOR_Cap[Instance].CustomROI == 0) |
charlesmn | 0:c1910e04fc6c | 199 | { |
charlesmn | 0:c1910e04fc6c | 200 | ret = BSP_ERROR_FEATURE_NOT_SUPPORTED; |
charlesmn | 0:c1910e04fc6c | 201 | } |
charlesmn | 0:c1910e04fc6c | 202 | else if (CUSTOM_RANGING_Drv[Instance]->ConfigROI(CUSTOM_RANGING_CompObj[Instance], pConfig) < 0) |
charlesmn | 0:c1910e04fc6c | 203 | { |
charlesmn | 0:c1910e04fc6c | 204 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 205 | } |
charlesmn | 0:c1910e04fc6c | 206 | else |
charlesmn | 0:c1910e04fc6c | 207 | { |
charlesmn | 0:c1910e04fc6c | 208 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 209 | } |
charlesmn | 0:c1910e04fc6c | 210 | |
charlesmn | 0:c1910e04fc6c | 211 | return ret; |
charlesmn | 0:c1910e04fc6c | 212 | } |
charlesmn | 0:c1910e04fc6c | 213 | |
charlesmn | 0:c1910e04fc6c | 214 | /** |
charlesmn | 0:c1910e04fc6c | 215 | * @brief Configure the IT event generation parameters. |
charlesmn | 0:c1910e04fc6c | 216 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 217 | * @param pConfig Pointer to the IT configuration struct. |
charlesmn | 0:c1910e04fc6c | 218 | * @note The threshold modes can be used only if supported by the device (check the capabilities) |
charlesmn | 0:c1910e04fc6c | 219 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 220 | */ |
charlesmn | 0:c1910e04fc6c | 221 | int32_t CUSTOM_RANGING_SENSOR_ConfigIT(uint32_t Instance, RANGING_SENSOR_ITConfig_t *pConfig) |
charlesmn | 0:c1910e04fc6c | 222 | { |
charlesmn | 0:c1910e04fc6c | 223 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 224 | |
charlesmn | 0:c1910e04fc6c | 225 | if (Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 226 | { |
charlesmn | 0:c1910e04fc6c | 227 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 228 | } |
charlesmn | 0:c1910e04fc6c | 229 | else if (CUSTOM_RANGING_Drv[Instance]->ConfigIT(CUSTOM_RANGING_CompObj[Instance], pConfig) < 0) |
charlesmn | 0:c1910e04fc6c | 230 | { |
charlesmn | 0:c1910e04fc6c | 231 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 232 | } |
charlesmn | 0:c1910e04fc6c | 233 | else |
charlesmn | 0:c1910e04fc6c | 234 | { |
charlesmn | 0:c1910e04fc6c | 235 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 236 | } |
charlesmn | 0:c1910e04fc6c | 237 | |
charlesmn | 0:c1910e04fc6c | 238 | return ret; |
charlesmn | 0:c1910e04fc6c | 239 | } |
charlesmn | 0:c1910e04fc6c | 240 | |
charlesmn | 0:c1910e04fc6c | 241 | /** |
charlesmn | 0:c1910e04fc6c | 242 | * @brief Get the last distance measurement information. |
charlesmn | 0:c1910e04fc6c | 243 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 244 | * @param pResult Pointer to the result struct. |
charlesmn | 0:c1910e04fc6c | 245 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 246 | */ |
charlesmn | 0:c1910e04fc6c | 247 | int32_t CUSTOM_RANGING_SENSOR_GetDistance(uint32_t Instance, RANGING_SENSOR_Result_t *pResult) |
charlesmn | 0:c1910e04fc6c | 248 | { |
charlesmn | 0:c1910e04fc6c | 249 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 250 | |
charlesmn | 0:c1910e04fc6c | 251 | if (Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 252 | { |
charlesmn | 0:c1910e04fc6c | 253 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 254 | } |
charlesmn | 0:c1910e04fc6c | 255 | else if (CUSTOM_RANGING_Drv[Instance]->GetDistance(CUSTOM_RANGING_CompObj[Instance], pResult) < 0) |
charlesmn | 0:c1910e04fc6c | 256 | { |
charlesmn | 0:c1910e04fc6c | 257 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 258 | } |
charlesmn | 0:c1910e04fc6c | 259 | else |
charlesmn | 0:c1910e04fc6c | 260 | { |
charlesmn | 0:c1910e04fc6c | 261 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 262 | } |
charlesmn | 0:c1910e04fc6c | 263 | |
charlesmn | 0:c1910e04fc6c | 264 | return ret; |
charlesmn | 0:c1910e04fc6c | 265 | } |
charlesmn | 0:c1910e04fc6c | 266 | |
charlesmn | 0:c1910e04fc6c | 267 | /** |
charlesmn | 0:c1910e04fc6c | 268 | * @brief Start ranging. |
charlesmn | 0:c1910e04fc6c | 269 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 270 | * @param Mode The desired ranging mode. |
charlesmn | 0:c1910e04fc6c | 271 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 272 | */ |
charlesmn | 0:c1910e04fc6c | 273 | int32_t CUSTOM_RANGING_SENSOR_Start(uint32_t Instance, uint8_t Mode) |
charlesmn | 0:c1910e04fc6c | 274 | { |
charlesmn | 0:c1910e04fc6c | 275 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 276 | |
charlesmn | 0:c1910e04fc6c | 277 | if (Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 278 | { |
charlesmn | 0:c1910e04fc6c | 279 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 280 | } |
charlesmn | 0:c1910e04fc6c | 281 | else if (CUSTOM_RANGING_Drv[Instance]->Start(CUSTOM_RANGING_CompObj[Instance], Mode) < 0) |
charlesmn | 0:c1910e04fc6c | 282 | { |
charlesmn | 0:c1910e04fc6c | 283 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 284 | } |
charlesmn | 0:c1910e04fc6c | 285 | else |
charlesmn | 0:c1910e04fc6c | 286 | { |
charlesmn | 0:c1910e04fc6c | 287 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 288 | } |
charlesmn | 0:c1910e04fc6c | 289 | |
charlesmn | 0:c1910e04fc6c | 290 | return ret; |
charlesmn | 0:c1910e04fc6c | 291 | } |
charlesmn | 0:c1910e04fc6c | 292 | |
charlesmn | 0:c1910e04fc6c | 293 | /** |
charlesmn | 0:c1910e04fc6c | 294 | * @brief Stop ranging. |
charlesmn | 0:c1910e04fc6c | 295 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 296 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 297 | */ |
charlesmn | 0:c1910e04fc6c | 298 | int32_t CUSTOM_RANGING_SENSOR_Stop(uint32_t Instance) |
charlesmn | 0:c1910e04fc6c | 299 | { |
charlesmn | 0:c1910e04fc6c | 300 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 301 | |
charlesmn | 0:c1910e04fc6c | 302 | if (Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 303 | { |
charlesmn | 0:c1910e04fc6c | 304 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 305 | } |
charlesmn | 0:c1910e04fc6c | 306 | else if (CUSTOM_RANGING_Drv[Instance]->Stop(CUSTOM_RANGING_CompObj[Instance]) < 0) |
charlesmn | 0:c1910e04fc6c | 307 | { |
charlesmn | 0:c1910e04fc6c | 308 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 309 | } |
charlesmn | 0:c1910e04fc6c | 310 | else |
charlesmn | 0:c1910e04fc6c | 311 | { |
charlesmn | 0:c1910e04fc6c | 312 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 313 | } |
charlesmn | 0:c1910e04fc6c | 314 | |
charlesmn | 0:c1910e04fc6c | 315 | return ret; |
charlesmn | 0:c1910e04fc6c | 316 | } |
charlesmn | 0:c1910e04fc6c | 317 | |
charlesmn | 0:c1910e04fc6c | 318 | /** |
charlesmn | 0:c1910e04fc6c | 319 | * @brief Set The I2C address of the device. |
charlesmn | 0:c1910e04fc6c | 320 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 321 | * @param Address New I2C address. |
charlesmn | 0:c1910e04fc6c | 322 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 323 | */ |
charlesmn | 0:c1910e04fc6c | 324 | int32_t CUSTOM_RANGING_SENSOR_SetAddress(uint32_t Instance, uint16_t Address) |
charlesmn | 0:c1910e04fc6c | 325 | { |
charlesmn | 0:c1910e04fc6c | 326 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 327 | |
charlesmn | 0:c1910e04fc6c | 328 | if (Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 329 | { |
charlesmn | 0:c1910e04fc6c | 330 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 331 | } |
charlesmn | 0:c1910e04fc6c | 332 | else if (CUSTOM_RANGING_Drv[Instance]->SetAddress(CUSTOM_RANGING_CompObj[Instance], Address) < 0) |
charlesmn | 0:c1910e04fc6c | 333 | { |
charlesmn | 0:c1910e04fc6c | 334 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 335 | } |
charlesmn | 0:c1910e04fc6c | 336 | else |
charlesmn | 0:c1910e04fc6c | 337 | { |
charlesmn | 0:c1910e04fc6c | 338 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 339 | } |
charlesmn | 0:c1910e04fc6c | 340 | |
charlesmn | 0:c1910e04fc6c | 341 | return ret; |
charlesmn | 0:c1910e04fc6c | 342 | } |
charlesmn | 0:c1910e04fc6c | 343 | |
charlesmn | 0:c1910e04fc6c | 344 | /** |
charlesmn | 0:c1910e04fc6c | 345 | * @brief Get the I2C address of the device. |
charlesmn | 0:c1910e04fc6c | 346 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 347 | * @param pAddress Pointer to the current I2C address. |
charlesmn | 0:c1910e04fc6c | 348 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 349 | */ |
charlesmn | 0:c1910e04fc6c | 350 | int32_t CUSTOM_RANGING_SENSOR_GetAddress(uint32_t Instance, uint16_t *pAddress) |
charlesmn | 0:c1910e04fc6c | 351 | { |
charlesmn | 0:c1910e04fc6c | 352 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 353 | |
charlesmn | 0:c1910e04fc6c | 354 | if (Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 355 | { |
charlesmn | 0:c1910e04fc6c | 356 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 357 | } |
charlesmn | 0:c1910e04fc6c | 358 | else if (CUSTOM_RANGING_Drv[Instance]->GetAddress(CUSTOM_RANGING_CompObj[Instance], (uint32_t*)pAddress) < 0) |
charlesmn | 0:c1910e04fc6c | 359 | { |
charlesmn | 0:c1910e04fc6c | 360 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 361 | } |
charlesmn | 0:c1910e04fc6c | 362 | else |
charlesmn | 0:c1910e04fc6c | 363 | { |
charlesmn | 0:c1910e04fc6c | 364 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 365 | } |
charlesmn | 0:c1910e04fc6c | 366 | |
charlesmn | 0:c1910e04fc6c | 367 | return ret; |
charlesmn | 0:c1910e04fc6c | 368 | } |
charlesmn | 0:c1910e04fc6c | 369 | |
charlesmn | 0:c1910e04fc6c | 370 | /** |
charlesmn | 0:c1910e04fc6c | 371 | * @brief Set the power mode. |
charlesmn | 0:c1910e04fc6c | 372 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 373 | * @param PowerMode New power mode to be entered. |
charlesmn | 0:c1910e04fc6c | 374 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 375 | */ |
charlesmn | 0:c1910e04fc6c | 376 | int32_t CUSTOM_RANGING_SENSOR_SetPowerMode(uint32_t Instance, uint32_t PowerMode) |
charlesmn | 0:c1910e04fc6c | 377 | { |
charlesmn | 0:c1910e04fc6c | 378 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 379 | |
charlesmn | 0:c1910e04fc6c | 380 | if (Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 381 | { |
charlesmn | 0:c1910e04fc6c | 382 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 383 | } |
charlesmn | 0:c1910e04fc6c | 384 | else if (PowerMode == CUSTOM_RANGING_POWERMODE_ON) |
charlesmn | 0:c1910e04fc6c | 385 | { |
charlesmn | 0:c1910e04fc6c | 386 | switch (Instance) |
charlesmn | 0:c1910e04fc6c | 387 | { |
charlesmn | 0:c1910e04fc6c | 388 | #if (USE_CUSTOM_RANGING_VL53L3CX == 1U) |
charlesmn | 0:c1910e04fc6c | 389 | case CUSTOM_VL53L3CX: |
charlesmn | 0:c1910e04fc6c | 390 | set_gpio_pin( CUSTOM_VL53L3CX_XSHUT_PIN, 1); |
charlesmn | 0:c1910e04fc6c | 391 | // HAL_GPIO_WritePin(CUSTOM_VL53L3CX_XSHUT_PORT, |
charlesmn | 0:c1910e04fc6c | 392 | // CUSTOM_VL53L3CX_XSHUT_PIN, GPIO_PIN_SET); |
charlesmn | 0:c1910e04fc6c | 393 | // HAL_Delay(2); |
charlesmn | 0:c1910e04fc6c | 394 | wait_ms(2); |
charlesmn | 0:c1910e04fc6c | 395 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 396 | break; |
charlesmn | 0:c1910e04fc6c | 397 | #endif |
charlesmn | 0:c1910e04fc6c | 398 | default: |
charlesmn | 0:c1910e04fc6c | 399 | ret = BSP_ERROR_UNKNOWN_COMPONENT; |
charlesmn | 0:c1910e04fc6c | 400 | break; |
charlesmn | 0:c1910e04fc6c | 401 | } |
charlesmn | 0:c1910e04fc6c | 402 | } |
charlesmn | 0:c1910e04fc6c | 403 | else if (PowerMode == CUSTOM_RANGING_POWERMODE_OFF) |
charlesmn | 0:c1910e04fc6c | 404 | { |
charlesmn | 0:c1910e04fc6c | 405 | switch (Instance) |
charlesmn | 0:c1910e04fc6c | 406 | { |
charlesmn | 0:c1910e04fc6c | 407 | #if (USE_CUSTOM_RANGING_VL53L3CX == 1U) |
charlesmn | 0:c1910e04fc6c | 408 | case CUSTOM_VL53L3CX: |
charlesmn | 0:c1910e04fc6c | 409 | set_gpio_pin(CUSTOM_VL53L3CX_XSHUT_PIN, 0); |
charlesmn | 0:c1910e04fc6c | 410 | // HAL_GPIO_WritePin(CUSTOM_VL53L3CX_XSHUT_PORT, |
charlesmn | 0:c1910e04fc6c | 411 | // CUSTOM_VL53L3CX_XSHUT_PIN, GPIO_PIN_RESET); |
charlesmn | 0:c1910e04fc6c | 412 | // HAL_Delay(2); |
charlesmn | 0:c1910e04fc6c | 413 | wait_ms(2); |
charlesmn | 0:c1910e04fc6c | 414 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 415 | break; |
charlesmn | 0:c1910e04fc6c | 416 | #endif |
charlesmn | 0:c1910e04fc6c | 417 | default: |
charlesmn | 0:c1910e04fc6c | 418 | ret = BSP_ERROR_UNKNOWN_COMPONENT; |
charlesmn | 0:c1910e04fc6c | 419 | break; |
charlesmn | 0:c1910e04fc6c | 420 | } |
charlesmn | 0:c1910e04fc6c | 421 | } |
charlesmn | 0:c1910e04fc6c | 422 | else |
charlesmn | 0:c1910e04fc6c | 423 | { |
charlesmn | 0:c1910e04fc6c | 424 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 425 | } |
charlesmn | 0:c1910e04fc6c | 426 | |
charlesmn | 0:c1910e04fc6c | 427 | return ret; |
charlesmn | 0:c1910e04fc6c | 428 | } |
charlesmn | 0:c1910e04fc6c | 429 | |
charlesmn | 0:c1910e04fc6c | 430 | /** |
charlesmn | 0:c1910e04fc6c | 431 | * @brief Set the power mode. |
charlesmn | 0:c1910e04fc6c | 432 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 433 | * @param pPowerMode Pointer to the current power mode. |
charlesmn | 0:c1910e04fc6c | 434 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 435 | */ |
charlesmn | 0:c1910e04fc6c | 436 | int32_t CUSTOM_RANGING_SENSOR_GetPowerMode(uint32_t Instance, uint32_t *pPowerMode) |
charlesmn | 0:c1910e04fc6c | 437 | { |
charlesmn | 0:c1910e04fc6c | 438 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 439 | |
charlesmn | 0:c1910e04fc6c | 440 | if (Instance >= CUSTOM_RANGING_INSTANCES_NBR) |
charlesmn | 0:c1910e04fc6c | 441 | { |
charlesmn | 0:c1910e04fc6c | 442 | ret = BSP_ERROR_WRONG_PARAM; |
charlesmn | 0:c1910e04fc6c | 443 | } |
charlesmn | 0:c1910e04fc6c | 444 | else if (CUSTOM_RANGING_Drv[Instance]->GetPowerMode(CUSTOM_RANGING_CompObj[Instance], pPowerMode) < 0) |
charlesmn | 0:c1910e04fc6c | 445 | { |
charlesmn | 0:c1910e04fc6c | 446 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 447 | } |
charlesmn | 0:c1910e04fc6c | 448 | else |
charlesmn | 0:c1910e04fc6c | 449 | { |
charlesmn | 0:c1910e04fc6c | 450 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 451 | } |
charlesmn | 0:c1910e04fc6c | 452 | |
charlesmn | 0:c1910e04fc6c | 453 | return ret; |
charlesmn | 0:c1910e04fc6c | 454 | } |
charlesmn | 0:c1910e04fc6c | 455 | |
charlesmn | 0:c1910e04fc6c | 456 | #if (USE_CUSTOM_RANGING_VL53L3CX == 1U) |
charlesmn | 0:c1910e04fc6c | 457 | /** |
charlesmn | 0:c1910e04fc6c | 458 | * @brief Register Bus IOs if component ID is OK. |
charlesmn | 0:c1910e04fc6c | 459 | * @param Instance Ranging sensor instance. |
charlesmn | 0:c1910e04fc6c | 460 | * @retval BSP status |
charlesmn | 0:c1910e04fc6c | 461 | */ |
charlesmn | 0:c1910e04fc6c | 462 | static int32_t VL53L3CX_Probe(uint32_t Instance) |
charlesmn | 0:c1910e04fc6c | 463 | { |
charlesmn | 0:c1910e04fc6c | 464 | int32_t ret; |
charlesmn | 0:c1910e04fc6c | 465 | VL53L3CX_IO_t IOCtx; |
charlesmn | 0:c1910e04fc6c | 466 | uint32_t id; |
charlesmn | 0:c1910e04fc6c | 467 | static VL53L3CX_Object_t VL53L3CXObj; |
charlesmn | 0:c1910e04fc6c | 468 | |
charlesmn | 0:c1910e04fc6c | 469 | /* Configure the ranging sensor driver */ |
charlesmn | 0:c1910e04fc6c | 470 | IOCtx.Address = RANGING_SENSOR_VL53L3CX_ADDRESS; |
charlesmn | 0:c1910e04fc6c | 471 | // IOCtx.Init = CUSTOM_VL53L3CX_I2C_Init; |
charlesmn | 0:c1910e04fc6c | 472 | // IOCtx.DeInit = CUSTOM_VL53L3CX_I2C_DeInit; |
charlesmn | 0:c1910e04fc6c | 473 | // IOCtx.WriteReg = CUSTOM_VL53L3CX_I2C_WriteReg; |
charlesmn | 0:c1910e04fc6c | 474 | // IOCtx.ReadReg = CUSTOM_VL53L3CX_I2C_ReadReg; |
charlesmn | 0:c1910e04fc6c | 475 | // IOCtx.GetTick = BSP_GetTick; |
charlesmn | 0:c1910e04fc6c | 476 | IOCtx.GetTick = GetTickCountMs; // 1ms ticks |
charlesmn | 0:c1910e04fc6c | 477 | |
charlesmn | 0:c1910e04fc6c | 478 | if (VL53L3CX_RegisterBusIO(&VL53L3CXObj, &IOCtx) != VL53L3CX_OK) |
charlesmn | 0:c1910e04fc6c | 479 | { |
charlesmn | 0:c1910e04fc6c | 480 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 481 | } |
charlesmn | 0:c1910e04fc6c | 482 | else if (VL53L3CX_ReadID(&VL53L3CXObj, &id) != VL53L3CX_OK) |
charlesmn | 0:c1910e04fc6c | 483 | { |
charlesmn | 0:c1910e04fc6c | 484 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 485 | } |
charlesmn | 0:c1910e04fc6c | 486 | else |
charlesmn | 0:c1910e04fc6c | 487 | { |
charlesmn | 0:c1910e04fc6c | 488 | if (id != VL53L3CX_ID) |
charlesmn | 0:c1910e04fc6c | 489 | { |
charlesmn | 0:c1910e04fc6c | 490 | ret = BSP_ERROR_UNKNOWN_COMPONENT; |
charlesmn | 0:c1910e04fc6c | 491 | } |
charlesmn | 0:c1910e04fc6c | 492 | else |
charlesmn | 0:c1910e04fc6c | 493 | { |
charlesmn | 0:c1910e04fc6c | 494 | CUSTOM_RANGING_Drv[Instance] = (RANGING_SENSOR_Drv_t *) &VL53L3CX_RANGING_SENSOR_Driver; |
charlesmn | 0:c1910e04fc6c | 495 | CUSTOM_RANGING_CompObj[Instance] = &VL53L3CXObj; |
charlesmn | 0:c1910e04fc6c | 496 | |
charlesmn | 0:c1910e04fc6c | 497 | if (CUSTOM_RANGING_Drv[Instance]->Init(CUSTOM_RANGING_CompObj[Instance]) != VL53L3CX_OK) |
charlesmn | 0:c1910e04fc6c | 498 | { |
charlesmn | 0:c1910e04fc6c | 499 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 500 | } |
charlesmn | 0:c1910e04fc6c | 501 | else if (CUSTOM_RANGING_Drv[Instance]->GetCapabilities(CUSTOM_RANGING_CompObj[Instance], &RANGING_SENSOR_Cap[Instance]) != VL53L3CX_OK) |
charlesmn | 0:c1910e04fc6c | 502 | { |
charlesmn | 0:c1910e04fc6c | 503 | ret = BSP_ERROR_COMPONENT_FAILURE; |
charlesmn | 0:c1910e04fc6c | 504 | } |
charlesmn | 0:c1910e04fc6c | 505 | else |
charlesmn | 0:c1910e04fc6c | 506 | { |
charlesmn | 0:c1910e04fc6c | 507 | ret = BSP_ERROR_NONE; |
charlesmn | 0:c1910e04fc6c | 508 | } |
charlesmn | 0:c1910e04fc6c | 509 | } |
charlesmn | 0:c1910e04fc6c | 510 | } |
charlesmn | 0:c1910e04fc6c | 511 | |
charlesmn | 0:c1910e04fc6c | 512 | return ret; |
charlesmn | 0:c1910e04fc6c | 513 | } |
charlesmn | 0:c1910e04fc6c | 514 | #endif |
charlesmn | 0:c1910e04fc6c | 515 | |
charlesmn | 0:c1910e04fc6c | 516 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
charlesmn | 0:c1910e04fc6c | 517 |