1 /* 2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 * 4 * 5 */ 6 7 /* Define to prevent recursive inclusion -------------------------------------*/ 8 #ifndef __VL53L0X_PLATFORM_H 9 #define __VL53L0X_PLATFORM_H 10 11 #ifdef __cplusplus 12 extern "C" 13 { 14 #endif 15 16 /* Includes 17 * ------------------------------------------------------------------*/ 18 19 #include "vl53l0x/vl53l0x_def.h" 20 #include "vl53l0x/vl53l0x_platform_log.h" 21 22 #define VL53L0X_OsDelay(...) aos_msleep(2) 23 24 /* Exported types 25 * ------------------------------------------------------------*/ 26 /** 27 * @struct VL53L0X_Dev_t 28 * @brief Generic PAL device type that does link between API and platform 29 * abstraction layer 30 * 31 */ 32 typedef struct 33 { 34 VL53L0X_DevData_t Data; /*!< embed ST Ewok Dev data as "Data"*/ 35 36 /*!< user specific field */ 37 38 uint8_t I2cDevAddr; 39 40 char DevLetter; 41 42 int Id; 43 int Present; 44 int Enabled; 45 int Ready; 46 47 uint8_t comms_type; 48 uint16_t comms_speed_khz; 49 50 int LeakyRange; 51 int LeakyFirst; 52 uint8_t RangeStatus; 53 uint8_t PreviousRangeStatus; 54 FixPoint1616_t SignalRateRtnMegaCps; 55 uint16_t EffectiveSpadRtnCount; 56 57 } VL53L0X_Dev_t; 58 59 60 /** 61 * @brief Declare the device Handle as a pointer of the structure @a 62 * VL53L0X_Dev_t. 63 * 64 */ 65 typedef VL53L0X_Dev_t *VL53L0X_DEV; 66 67 /* Exported constants --------------------------------------------------------*/ 68 /* Exported macros -----------------------------------------------------------*/ 69 /** 70 * @def PALDevDataGet 71 * @brief Get ST private structure @a VL53L0X_DevData_t data access 72 * 73 * @param Dev Device Handle 74 * @param field ST structure field name 75 * It maybe used and as real data "ref" not just as "get" for sub-structure item 76 * like PALDevDataGet(FilterData.field)[i] or 77 * PALDevDataGet(FilterData.MeasurementIndex)++ 78 */ 79 #define PALDevDataGet(Dev, field) (Dev->Data.field) 80 81 /** 82 * @def PALDevDataSet(Dev, field, data) 83 * @brief Set ST private structure @a VL53L0X_DevData_t data field 84 * @param Dev Device Handle 85 * @param field ST structure field name 86 * @param data Data to be set 87 */ 88 #define PALDevDataSet(Dev, field, data) (Dev->Data.field) = (data) 89 90 #define VL53L0X_COPYSTRING(str, ...) strcpy(str, ##__VA_ARGS__) 91 /* Private macros 92 * ------------------------------------------------------------*/ 93 /* Exported functions 94 * --------------------------------------------------------*/ 95 96 /** 97 * Lock comms interface to serialize all commands to a shared I2C interface 98 * for a specific device 99 * @param Dev Device Handle 100 * @return VL53L0X_ERROR_NONE Success 101 * @return "Other error code" See ::VL53L0X_Error 102 */ 103 VL53L0X_Error VL53L0X_LockSequenceAccess(VL53L0X_DEV Dev); 104 105 /** 106 * Unlock comms interface to serialize all commands to a shared I2C 107 * interface for a specific device 108 * @param Dev Device Handle 109 * @return VL53L0X_ERROR_NONE Success 110 * @return "Other error code" See ::VL53L0X_Error 111 */ 112 VL53L0X_Error VL53L0X_UnlockSequenceAccess(VL53L0X_DEV Dev); 113 114 115 /** 116 * Writes the supplied byte buffer to the device 117 * @param Dev Device Handle 118 * @param index The register index 119 * @param pdata Pointer to uint8_t buffer containing the data to be 120 * written 121 * @param count Number of bytes in the supplied byte buffer 122 * @return VL53L0X_ERROR_NONE Success 123 * @return "Other error code" See ::VL53L0X_Error 124 */ 125 VL53L0X_Error VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index, 126 uint8_t *pdata, uint32_t count); 127 128 /** 129 * Reads the requested number of bytes from the device 130 * @param Dev Device Handle 131 * @param index The register index 132 * @param pdata Pointer to the uint8_t buffer to store read data 133 * @param count Number of uint8_t's to read 134 * @return VL53L0X_ERROR_NONE Success 135 * @return "Other error code" See ::VL53L0X_Error 136 */ 137 VL53L0X_Error VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, 138 uint8_t *pdata, uint32_t count); 139 140 /** 141 * Write single byte register 142 * @param Dev Device Handle 143 * @param index The register index 144 * @param data 8 bit register data 145 * @return VL53L0X_ERROR_NONE Success 146 * @return "Other error code" See ::VL53L0X_Error 147 */ 148 VL53L0X_Error VL53L0X_WrByte(VL53L0X_DEV Dev, uint8_t index, uint8_t data); 149 150 /** 151 * Write word register 152 * @param Dev Device Handle 153 * @param index The register index 154 * @param data 16 bit register data 155 * @return VL53L0X_ERROR_NONE Success 156 * @return "Other error code" See ::VL53L0X_Error 157 */ 158 VL53L0X_Error VL53L0X_WrWord(VL53L0X_DEV Dev, uint8_t index, uint16_t data); 159 160 /** 161 * Write double word (4 byte) register 162 * @param Dev Device Handle 163 * @param index The register index 164 * @param data 32 bit register data 165 * @return VL53L0X_ERROR_NONE Success 166 * @return "Other error code" See ::VL53L0X_Error 167 */ 168 VL53L0X_Error VL53L0X_WrDWord(VL53L0X_DEV Dev, uint8_t index, 169 uint32_t data); 170 171 /** 172 * Read single byte register 173 * @param Dev Device Handle 174 * @param index The register index 175 * @param data pointer to 8 bit data 176 * @return VL53L0X_ERROR_NONE Success 177 * @return "Other error code" See ::VL53L0X_Error 178 */ 179 VL53L0X_Error VL53L0X_RdByte(VL53L0X_DEV Dev, uint8_t index, uint8_t *data); 180 181 /** 182 * Read word (2byte) register 183 * @param Dev Device Handle 184 * @param index The register index 185 * @param data pointer to 16 bit data 186 * @return VL53L0X_ERROR_NONE Success 187 * @return "Other error code" See ::VL53L0X_Error 188 */ 189 VL53L0X_Error VL53L0X_RdWord(VL53L0X_DEV Dev, uint8_t index, 190 uint16_t *data); 191 192 /** 193 * Read dword (4byte) register 194 * @param Dev Device Handle 195 * @param index The register index 196 * @param data pointer to 32 bit data 197 * @return VL53L0X_ERROR_NONE Success 198 * @return "Other error code" See ::VL53L0X_Error 199 */ 200 VL53L0X_Error VL53L0X_RdDWord(VL53L0X_DEV Dev, uint8_t index, 201 uint32_t *data); 202 203 /** 204 * Threat safe Update (read/modify/write) single byte register 205 * 206 * Final_reg = (Initial_reg & and_data) |or_data 207 * 208 * @param Dev Device Handle 209 * @param index The register index 210 * @param AndData 8 bit and data 211 * @param OrData 8 bit or data 212 * @return VL53L0X_ERROR_NONE Success 213 * @return "Other error code" See ::VL53L0X_Error 214 */ 215 VL53L0X_Error VL53L0X_UpdateByte(VL53L0X_DEV Dev, uint8_t index, 216 uint8_t AndData, uint8_t OrData); 217 218 /** @} end of VL53L0X_registerAccess_group */ 219 220 221 /** 222 * @brief execute delay in all polling API call 223 * 224 * A typical multi-thread or RTOs implementation is to sleep the task for 225 * some 5ms (with 100Hz max rate faster polling is not needed) if nothing 226 * specific is need you can define it as an empty/void macro 227 * @code 228 * #define VL53L0X_PollingDelay(...) (void)0 229 * @endcode 230 * @param Dev Device Handle 231 * @return VL53L0X_ERROR_NONE Success 232 * @return "Other error code" See ::VL53L0X_Error 233 */ 234 VL53L0X_Error VL53L0X_PollingDelay( 235 VL53L0X_DEV Dev); /* usually best implemented as a real function */ 236 237 #ifdef __cplusplus 238 } 239 #endif 240 241 #endif /* __VL53L0X_PLATFORM_H */ 242 243 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 244