1 /* vl53l1_platform.h - Zephyr customization of ST vl53l1x library. */ 2 3 /* 4 * Copyright (c) 2017 STMicroelectronics 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9 #ifndef ZEPHYR_DRIVERS_SENSOR_VL53L1X_VL53L1_PLATFORM_H_ 10 #define ZEPHYR_DRIVERS_SENSOR_VL53L1X_VL53L1_PLATFORM_H_ 11 12 #include <string.h> 13 #include "vl53l1_ll_def.h" 14 #include "vl53l1_platform_log.h" 15 #include "vl53l1_platform_user_data.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 /** 22 * Writes the supplied byte buffer to the device 23 * @param pdev Pointer to device structure (device handle) 24 * @param index Register index value 25 * @param pdata Pointer to uint8_t (byte) buffer containing the data to be written 26 * @param count Number of bytes in the supplied byte buffer 27 * @return VL53L1_ERROR_NONE Success 28 * @return "Other error code" See ::VL53L1_Error 29 */ 30 VL53L1_Error VL53L1_WriteMulti(VL53L1_Dev_t *pdev, uint16_t index, 31 uint8_t *pdata, uint32_t count); 32 33 /** 34 * Reads the requested number of bytes from the device 35 * @param pdev Pointer to device structure (device handle) 36 * @param index Register index value 37 * @param pdata Pointer to the uint8_t (byte) buffer to store read data 38 * @param count Number of bytes to read 39 * @return VL53L1_ERROR_NONE Success 40 * @return "Other error code" See ::VL53L1_Error 41 */ 42 VL53L1_Error VL53L1_ReadMulti(VL53L1_Dev_t *pdev, uint16_t index, 43 uint8_t *pdata, uint32_t count); 44 45 /** 46 * Writes a single byte to the device 47 * @param pdev Pointer to device structure (device handle) 48 * @param index Register index value 49 * @param data Data value to write 50 * @return VL53L1_ERROR_NONE Success 51 * @return "Other error code" See ::VL53L1_Error 52 */ 53 VL53L1_Error VL53L1_WrByte(VL53L1_Dev_t *pdev, uint16_t index, uint8_t data); 54 55 /** 56 * Writes a single word (16-bit unsigned) to the device 57 * @param pdev Pointer to device structure (device handle) 58 * @param index Register index value 59 * @param data Data value write 60 * @return VL53L1_ERROR_NONE Success 61 * @return "Other error code" See ::VL53L1_Error 62 */ 63 VL53L1_Error VL53L1_WrWord(VL53L1_Dev_t *pdev, uint16_t index, uint16_t data); 64 65 /** 66 * Writes a single dword (32-bit unsigned) to the device 67 * @param pdev Pointer to device structure (device handle) 68 * @param index Register index value 69 * @param data Data value to write 70 * @return VL53L1_ERROR_NONE Success 71 * @return "Other error code" See ::VL53L1_Error 72 */ 73 VL53L1_Error VL53L1_WrDWord(VL53L1_Dev_t *pdev, uint16_t index, uint32_t data); 74 75 /** 76 * Reads a single byte from the device 77 * @param pdev Pointer to device structure (device handle) 78 * @param index Register index 79 * @param pdata Pointer to uint8_t data value 80 * @return VL53L1_ERROR_NONE Success 81 * @return "Other error code" See ::VL53L1_Error 82 */ 83 VL53L1_Error VL53L1_RdByte(VL53L1_Dev_t *pdev, uint16_t index, uint8_t *pdata); 84 85 /** 86 * Reads a single word (16-bit unsigned) from the device 87 * @param pdev Pointer to device structure (device handle) 88 * @param index Register index value 89 * @param pdata Pointer to uint16_t data value 90 * @return VL53L1_ERROR_NONE Success 91 * @return "Other error code" See ::VL53L1_Error 92 */ 93 VL53L1_Error VL53L1_RdWord(VL53L1_Dev_t *pdev, uint16_t index, uint16_t *pdata); 94 95 /** 96 * Reads a single double word (32-bit unsigned) from the device 97 * @param pdev Pointer to device structure (device handle) 98 * @param index Register index value 99 * @param pdata Pointer to uint32_t data value 100 * @return VL53L1_ERROR_NONE Success 101 * @return "Other error code" See ::VL53L1_Error 102 */ 103 VL53L1_Error VL53L1_RdDWord(VL53L1_Dev_t *pdev, uint16_t index, uint32_t *pdata); 104 105 /** 106 * Implements a programmable wait in us 107 * @param pdev Pointer to device structure (device handle) 108 * @param wait_us Integer wait in micro seconds 109 * @return VL53L1_ERROR_NONE Success 110 * @return "Other error code" See ::VL53L1_Error 111 */ 112 VL53L1_Error VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us); 113 114 /** 115 * Implements a programmable wait in ms 116 * @param pdev Pointer to device structure (device handle) 117 * @param wait_ms Integer wait in milliseconds 118 * @return VL53L1_ERROR_NONE Success 119 * @return "Other error code" See ::VL53L1_Error 120 */ 121 VL53L1_Error VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms); 122 123 /** 124 * Gets current system tick count in [ms] 125 * @param Pointer to current time in [ms] 126 * @return VL53L1_ERROR_NONE Success 127 * @return "Other error code" See ::VL53L1_Error 128 */ 129 VL53L1_Error VL53L1_GetTickCount(uint32_t *ptime_ms); 130 131 /** 132 * Register "wait for value" polling routine 133 * @param dev Pointer to device structure (device handle) 134 * @param timeout Timeout in [ms] 135 * @param i Register index value 136 * @param val Value to wait for 137 * @param mask Mask to be applied before comparison with value 138 * @param delay Polling delay between each read transaction in [ms] 139 * @return VL53L1_ERROR_NONE Success 140 * @return "Other error code" See ::VL53L1_Error 141 */ 142 VL53L1_Error VL53L1_WaitValueMaskEx(VL53L1_Dev_t *dev, uint32_t timeout, uint16_t i, uint8_t val, 143 uint8_t mask, uint32_t delay); 144 145 #ifdef __cplusplus 146 } 147 #endif 148 149 #endif 150