Changes to the library related to interrupt mode.
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Dependents: Display_53L0A1_IntSatelites Display_53L0A1_InterruptMode
Fork of X_NUCLEO_53L0A1 by
Components/VL53L0X/vl53l0x_platform.h@12:820afb1af4ef, 2017-06-14 (annotated)
- Committer:
- JerrySzczurak
- Date:
- Wed Jun 14 14:10:45 2017 +0000
- Revision:
- 12:820afb1af4ef
- Parent:
- 0:c523920bcc09
Library change to work in interrupt continuous ranging mode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
johnAlexander | 0:c523920bcc09 | 1 | /******************************************************************************* |
johnAlexander | 0:c523920bcc09 | 2 | Copyright © 2015, STMicroelectronics International N.V. |
johnAlexander | 0:c523920bcc09 | 3 | All rights reserved. |
johnAlexander | 0:c523920bcc09 | 4 | |
johnAlexander | 0:c523920bcc09 | 5 | Redistribution and use in source and binary forms, with or without |
johnAlexander | 0:c523920bcc09 | 6 | modification, are permitted provided that the following conditions are met: |
johnAlexander | 0:c523920bcc09 | 7 | * Redistributions of source code must retain the above copyright |
johnAlexander | 0:c523920bcc09 | 8 | notice, this list of conditions and the following disclaimer. |
johnAlexander | 0:c523920bcc09 | 9 | * Redistributions in binary form must reproduce the above copyright |
johnAlexander | 0:c523920bcc09 | 10 | notice, this list of conditions and the following disclaimer in the |
johnAlexander | 0:c523920bcc09 | 11 | documentation and/or other materials provided with the distribution. |
johnAlexander | 0:c523920bcc09 | 12 | * Neither the name of STMicroelectronics nor the |
johnAlexander | 0:c523920bcc09 | 13 | names of its contributors may be used to endorse or promote products |
johnAlexander | 0:c523920bcc09 | 14 | derived from this software without specific prior written permission. |
johnAlexander | 0:c523920bcc09 | 15 | |
johnAlexander | 0:c523920bcc09 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
johnAlexander | 0:c523920bcc09 | 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
johnAlexander | 0:c523920bcc09 | 18 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND |
johnAlexander | 0:c523920bcc09 | 19 | NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED. |
johnAlexander | 0:c523920bcc09 | 20 | IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY |
johnAlexander | 0:c523920bcc09 | 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
johnAlexander | 0:c523920bcc09 | 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
johnAlexander | 0:c523920bcc09 | 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
johnAlexander | 0:c523920bcc09 | 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
johnAlexander | 0:c523920bcc09 | 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
johnAlexander | 0:c523920bcc09 | 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
johnAlexander | 0:c523920bcc09 | 27 | ********************************************************************************/ |
johnAlexander | 0:c523920bcc09 | 28 | |
johnAlexander | 0:c523920bcc09 | 29 | |
johnAlexander | 0:c523920bcc09 | 30 | #ifndef _VL53L0X_PLATFORM_H_ |
johnAlexander | 0:c523920bcc09 | 31 | #define _VL53L0X_PLATFORM_H_ |
johnAlexander | 0:c523920bcc09 | 32 | |
johnAlexander | 0:c523920bcc09 | 33 | #include "vl53l0x_def.h" |
johnAlexander | 0:c523920bcc09 | 34 | #include "vl53l0x_platform_log.h" |
johnAlexander | 0:c523920bcc09 | 35 | #include "vl53l0x_i2c_platform.h" |
johnAlexander | 0:c523920bcc09 | 36 | |
johnAlexander | 0:c523920bcc09 | 37 | #ifdef __cplusplus |
johnAlexander | 0:c523920bcc09 | 38 | extern "C" { |
johnAlexander | 0:c523920bcc09 | 39 | #endif |
johnAlexander | 0:c523920bcc09 | 40 | |
johnAlexander | 0:c523920bcc09 | 41 | /** |
johnAlexander | 0:c523920bcc09 | 42 | * @file vl53l0_platform.h |
johnAlexander | 0:c523920bcc09 | 43 | * |
johnAlexander | 0:c523920bcc09 | 44 | * @brief All end user OS/platform/application porting |
johnAlexander | 0:c523920bcc09 | 45 | */ |
johnAlexander | 0:c523920bcc09 | 46 | |
johnAlexander | 0:c523920bcc09 | 47 | /** |
johnAlexander | 0:c523920bcc09 | 48 | * @defgroup VL53L0X_platform_group VL53L0 Platform Functions |
johnAlexander | 0:c523920bcc09 | 49 | * @brief VL53L0 Platform Functions |
johnAlexander | 0:c523920bcc09 | 50 | * @{ |
johnAlexander | 0:c523920bcc09 | 51 | */ |
johnAlexander | 0:c523920bcc09 | 52 | |
johnAlexander | 0:c523920bcc09 | 53 | /** |
johnAlexander | 0:c523920bcc09 | 54 | * @struct VL53L0X_Dev_t |
johnAlexander | 0:c523920bcc09 | 55 | * @brief Generic PAL device type that does link between API and platform abstraction layer |
johnAlexander | 0:c523920bcc09 | 56 | * |
johnAlexander | 0:c523920bcc09 | 57 | */ |
johnAlexander | 0:c523920bcc09 | 58 | typedef struct { |
johnAlexander | 0:c523920bcc09 | 59 | VL53L0X_DevData_t Data; /*!< embed ST Ewok Dev data as "Data"*/ |
johnAlexander | 0:c523920bcc09 | 60 | |
johnAlexander | 0:c523920bcc09 | 61 | /*!< user specific field */ |
johnAlexander | 0:c523920bcc09 | 62 | uint8_t I2cDevAddr; /*!< i2c device address user specific field */ |
johnAlexander | 0:c523920bcc09 | 63 | uint8_t comms_type; /*!< Type of comms : VL53L0X_COMMS_I2C or VL53L0X_COMMS_SPI */ |
johnAlexander | 0:c523920bcc09 | 64 | uint16_t comms_speed_khz; /*!< Comms speed [kHz] : typically 400kHz for I2C */ |
johnAlexander | 0:c523920bcc09 | 65 | |
johnAlexander | 0:c523920bcc09 | 66 | } VL53L0X_Dev_t; |
johnAlexander | 0:c523920bcc09 | 67 | |
johnAlexander | 0:c523920bcc09 | 68 | |
johnAlexander | 0:c523920bcc09 | 69 | /** |
johnAlexander | 0:c523920bcc09 | 70 | * @brief Declare the device Handle as a pointer of the structure @a VL53L0X_Dev_t. |
johnAlexander | 0:c523920bcc09 | 71 | * |
johnAlexander | 0:c523920bcc09 | 72 | */ |
johnAlexander | 0:c523920bcc09 | 73 | typedef VL53L0X_Dev_t* VL53L0X_DEV; |
johnAlexander | 0:c523920bcc09 | 74 | |
johnAlexander | 0:c523920bcc09 | 75 | /** |
johnAlexander | 0:c523920bcc09 | 76 | * @def PALDevDataGet |
johnAlexander | 0:c523920bcc09 | 77 | * @brief Get ST private structure @a VL53L0X_DevData_t data access |
johnAlexander | 0:c523920bcc09 | 78 | * |
johnAlexander | 0:c523920bcc09 | 79 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 80 | * @param field ST structure field name |
johnAlexander | 0:c523920bcc09 | 81 | * It maybe used and as real data "ref" not just as "get" for sub-structure item |
johnAlexander | 0:c523920bcc09 | 82 | * like PALDevDataGet(FilterData.field)[i] or PALDevDataGet(FilterData.MeasurementIndex)++ |
johnAlexander | 0:c523920bcc09 | 83 | */ |
johnAlexander | 0:c523920bcc09 | 84 | #define PALDevDataGet(Dev, field) (Dev->Data.field) |
johnAlexander | 0:c523920bcc09 | 85 | |
johnAlexander | 0:c523920bcc09 | 86 | /** |
johnAlexander | 0:c523920bcc09 | 87 | * @def PALDevDataSet(Dev, field, data) |
johnAlexander | 0:c523920bcc09 | 88 | * @brief Set ST private structure @a VL53L0X_DevData_t data field |
johnAlexander | 0:c523920bcc09 | 89 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 90 | * @param field ST structure field name |
johnAlexander | 0:c523920bcc09 | 91 | * @param data Data to be set |
johnAlexander | 0:c523920bcc09 | 92 | */ |
johnAlexander | 0:c523920bcc09 | 93 | #define PALDevDataSet(Dev, field, data) (Dev->Data.field)=(data) |
johnAlexander | 0:c523920bcc09 | 94 | |
johnAlexander | 0:c523920bcc09 | 95 | |
johnAlexander | 0:c523920bcc09 | 96 | /** |
johnAlexander | 0:c523920bcc09 | 97 | * @defgroup VL53L0X_registerAccess_group PAL Register Access Functions |
johnAlexander | 0:c523920bcc09 | 98 | * @brief PAL Register Access Functions |
johnAlexander | 0:c523920bcc09 | 99 | * @{ |
johnAlexander | 0:c523920bcc09 | 100 | */ |
johnAlexander | 0:c523920bcc09 | 101 | |
johnAlexander | 0:c523920bcc09 | 102 | /** |
johnAlexander | 0:c523920bcc09 | 103 | * Lock comms interface to serialize all commands to a shared I2C interface for a specific device |
johnAlexander | 0:c523920bcc09 | 104 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 105 | * @return VL53L0X_ERROR_NONE Success |
johnAlexander | 0:c523920bcc09 | 106 | * @return "Other error code" See ::VL53L0X_Error |
johnAlexander | 0:c523920bcc09 | 107 | */ |
johnAlexander | 0:c523920bcc09 | 108 | VL53L0X_Error VL53L0X_LockSequenceAccess(VL53L0X_DEV Dev); |
johnAlexander | 0:c523920bcc09 | 109 | |
johnAlexander | 0:c523920bcc09 | 110 | /** |
johnAlexander | 0:c523920bcc09 | 111 | * Unlock comms interface to serialize all commands to a shared I2C interface for a specific device |
johnAlexander | 0:c523920bcc09 | 112 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 113 | * @return VL53L0X_ERROR_NONE Success |
johnAlexander | 0:c523920bcc09 | 114 | * @return "Other error code" See ::VL53L0X_Error |
johnAlexander | 0:c523920bcc09 | 115 | */ |
johnAlexander | 0:c523920bcc09 | 116 | VL53L0X_Error VL53L0X_UnlockSequenceAccess(VL53L0X_DEV Dev); |
johnAlexander | 0:c523920bcc09 | 117 | |
johnAlexander | 0:c523920bcc09 | 118 | |
johnAlexander | 0:c523920bcc09 | 119 | /** |
johnAlexander | 0:c523920bcc09 | 120 | * Writes the supplied byte buffer to the device |
johnAlexander | 0:c523920bcc09 | 121 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 122 | * @param index The register index |
johnAlexander | 0:c523920bcc09 | 123 | * @param pdata Pointer to uint8_t buffer containing the data to be written |
johnAlexander | 0:c523920bcc09 | 124 | * @param count Number of bytes in the supplied byte buffer |
johnAlexander | 0:c523920bcc09 | 125 | * @return VL53L0X_ERROR_NONE Success |
johnAlexander | 0:c523920bcc09 | 126 | * @return "Other error code" See ::VL53L0X_Error |
johnAlexander | 0:c523920bcc09 | 127 | */ |
johnAlexander | 0:c523920bcc09 | 128 | VL53L0X_Error VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count); |
johnAlexander | 0:c523920bcc09 | 129 | |
johnAlexander | 0:c523920bcc09 | 130 | /** |
johnAlexander | 0:c523920bcc09 | 131 | * Reads the requested number of bytes from the device |
johnAlexander | 0:c523920bcc09 | 132 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 133 | * @param index The register index |
johnAlexander | 0:c523920bcc09 | 134 | * @param pdata Pointer to the uint8_t buffer to store read data |
johnAlexander | 0:c523920bcc09 | 135 | * @param count Number of uint8_t's to read |
johnAlexander | 0:c523920bcc09 | 136 | * @return VL53L0X_ERROR_NONE Success |
johnAlexander | 0:c523920bcc09 | 137 | * @return "Other error code" See ::VL53L0X_Error |
johnAlexander | 0:c523920bcc09 | 138 | */ |
johnAlexander | 0:c523920bcc09 | 139 | VL53L0X_Error VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count); |
johnAlexander | 0:c523920bcc09 | 140 | |
johnAlexander | 0:c523920bcc09 | 141 | /** |
johnAlexander | 0:c523920bcc09 | 142 | * Write single byte register |
johnAlexander | 0:c523920bcc09 | 143 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 144 | * @param index The register index |
johnAlexander | 0:c523920bcc09 | 145 | * @param data 8 bit register data |
johnAlexander | 0:c523920bcc09 | 146 | * @return VL53L0X_ERROR_NONE Success |
johnAlexander | 0:c523920bcc09 | 147 | * @return "Other error code" See ::VL53L0X_Error |
johnAlexander | 0:c523920bcc09 | 148 | */ |
johnAlexander | 0:c523920bcc09 | 149 | VL53L0X_Error VL53L0X_WrByte(VL53L0X_DEV Dev, uint8_t index, uint8_t data); |
johnAlexander | 0:c523920bcc09 | 150 | |
johnAlexander | 0:c523920bcc09 | 151 | /** |
johnAlexander | 0:c523920bcc09 | 152 | * Write word register |
johnAlexander | 0:c523920bcc09 | 153 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 154 | * @param index The register index |
johnAlexander | 0:c523920bcc09 | 155 | * @param data 16 bit register data |
johnAlexander | 0:c523920bcc09 | 156 | * @return VL53L0X_ERROR_NONE Success |
johnAlexander | 0:c523920bcc09 | 157 | * @return "Other error code" See ::VL53L0X_Error |
johnAlexander | 0:c523920bcc09 | 158 | */ |
johnAlexander | 0:c523920bcc09 | 159 | VL53L0X_Error VL53L0X_WrWord(VL53L0X_DEV Dev, uint8_t index, uint16_t data); |
johnAlexander | 0:c523920bcc09 | 160 | |
johnAlexander | 0:c523920bcc09 | 161 | /** |
johnAlexander | 0:c523920bcc09 | 162 | * Write double word (4 byte) register |
johnAlexander | 0:c523920bcc09 | 163 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 164 | * @param index The register index |
johnAlexander | 0:c523920bcc09 | 165 | * @param data 32 bit register data |
johnAlexander | 0:c523920bcc09 | 166 | * @return VL53L0X_ERROR_NONE Success |
johnAlexander | 0:c523920bcc09 | 167 | * @return "Other error code" See ::VL53L0X_Error |
johnAlexander | 0:c523920bcc09 | 168 | */ |
johnAlexander | 0:c523920bcc09 | 169 | VL53L0X_Error VL53L0X_WrDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t data); |
johnAlexander | 0:c523920bcc09 | 170 | |
johnAlexander | 0:c523920bcc09 | 171 | /** |
johnAlexander | 0:c523920bcc09 | 172 | * Read single byte register |
johnAlexander | 0:c523920bcc09 | 173 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 174 | * @param index The register index |
johnAlexander | 0:c523920bcc09 | 175 | * @param data pointer to 8 bit data |
johnAlexander | 0:c523920bcc09 | 176 | * @return VL53L0X_ERROR_NONE Success |
johnAlexander | 0:c523920bcc09 | 177 | * @return "Other error code" See ::VL53L0X_Error |
johnAlexander | 0:c523920bcc09 | 178 | */ |
johnAlexander | 0:c523920bcc09 | 179 | VL53L0X_Error VL53L0X_RdByte(VL53L0X_DEV Dev, uint8_t index, uint8_t *data); |
johnAlexander | 0:c523920bcc09 | 180 | |
johnAlexander | 0:c523920bcc09 | 181 | /** |
johnAlexander | 0:c523920bcc09 | 182 | * Read word (2byte) register |
johnAlexander | 0:c523920bcc09 | 183 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 184 | * @param index The register index |
johnAlexander | 0:c523920bcc09 | 185 | * @param data pointer to 16 bit data |
johnAlexander | 0:c523920bcc09 | 186 | * @return VL53L0X_ERROR_NONE Success |
johnAlexander | 0:c523920bcc09 | 187 | * @return "Other error code" See ::VL53L0X_Error |
johnAlexander | 0:c523920bcc09 | 188 | */ |
johnAlexander | 0:c523920bcc09 | 189 | VL53L0X_Error VL53L0X_RdWord(VL53L0X_DEV Dev, uint8_t index, uint16_t *data); |
johnAlexander | 0:c523920bcc09 | 190 | |
johnAlexander | 0:c523920bcc09 | 191 | /** |
johnAlexander | 0:c523920bcc09 | 192 | * Read dword (4byte) register |
johnAlexander | 0:c523920bcc09 | 193 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 194 | * @param index The register index |
johnAlexander | 0:c523920bcc09 | 195 | * @param data pointer to 32 bit data |
johnAlexander | 0:c523920bcc09 | 196 | * @return VL53L0X_ERROR_NONE Success |
johnAlexander | 0:c523920bcc09 | 197 | * @return "Other error code" See ::VL53L0X_Error |
johnAlexander | 0:c523920bcc09 | 198 | */ |
johnAlexander | 0:c523920bcc09 | 199 | VL53L0X_Error VL53L0X_RdDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t *data); |
johnAlexander | 0:c523920bcc09 | 200 | |
johnAlexander | 0:c523920bcc09 | 201 | /** |
johnAlexander | 0:c523920bcc09 | 202 | * Threat safe Update (read/modify/write) single byte register |
johnAlexander | 0:c523920bcc09 | 203 | * |
johnAlexander | 0:c523920bcc09 | 204 | * Final_reg = (Initial_reg & and_data) |or_data |
johnAlexander | 0:c523920bcc09 | 205 | * |
johnAlexander | 0:c523920bcc09 | 206 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 207 | * @param index The register index |
johnAlexander | 0:c523920bcc09 | 208 | * @param AndData 8 bit and data |
johnAlexander | 0:c523920bcc09 | 209 | * @param OrData 8 bit or data |
johnAlexander | 0:c523920bcc09 | 210 | * @return VL53L0X_ERROR_NONE Success |
johnAlexander | 0:c523920bcc09 | 211 | * @return "Other error code" See ::VL53L0X_Error |
johnAlexander | 0:c523920bcc09 | 212 | */ |
johnAlexander | 0:c523920bcc09 | 213 | VL53L0X_Error VL53L0X_UpdateByte(VL53L0X_DEV Dev, uint8_t index, uint8_t AndData, uint8_t OrData); |
johnAlexander | 0:c523920bcc09 | 214 | |
johnAlexander | 0:c523920bcc09 | 215 | /** @} end of VL53L0X_registerAccess_group */ |
johnAlexander | 0:c523920bcc09 | 216 | |
johnAlexander | 0:c523920bcc09 | 217 | |
johnAlexander | 0:c523920bcc09 | 218 | /** |
johnAlexander | 0:c523920bcc09 | 219 | * @brief execute delay in all polling API call |
johnAlexander | 0:c523920bcc09 | 220 | * |
johnAlexander | 0:c523920bcc09 | 221 | * A typical multi-thread or RTOs implementation is to sleep the task for some 5ms (with 100Hz max rate faster polling is not needed) |
johnAlexander | 0:c523920bcc09 | 222 | * if nothing specific is need you can define it as an empty/void macro |
johnAlexander | 0:c523920bcc09 | 223 | * @code |
johnAlexander | 0:c523920bcc09 | 224 | * #define VL53L0X_PollingDelay(...) (void)0 |
johnAlexander | 0:c523920bcc09 | 225 | * @endcode |
johnAlexander | 0:c523920bcc09 | 226 | * @param Dev Device Handle |
johnAlexander | 0:c523920bcc09 | 227 | * @return VL53L0X_ERROR_NONE Success |
johnAlexander | 0:c523920bcc09 | 228 | * @return "Other error code" See ::VL53L0X_Error |
johnAlexander | 0:c523920bcc09 | 229 | */ |
johnAlexander | 0:c523920bcc09 | 230 | VL53L0X_Error VL53L0X_PollingDelay(VL53L0X_DEV Dev); /* usually best implemented as a real function */ |
johnAlexander | 0:c523920bcc09 | 231 | |
johnAlexander | 0:c523920bcc09 | 232 | /** @} end of VL53L0X_platform_group */ |
johnAlexander | 0:c523920bcc09 | 233 | |
johnAlexander | 0:c523920bcc09 | 234 | #ifdef __cplusplus |
johnAlexander | 0:c523920bcc09 | 235 | } |
johnAlexander | 0:c523920bcc09 | 236 | #endif |
johnAlexander | 0:c523920bcc09 | 237 | |
johnAlexander | 0:c523920bcc09 | 238 | #endif /* _VL53L0X_PLATFORM_H_ */ |
johnAlexander | 0:c523920bcc09 | 239 | |
johnAlexander | 0:c523920bcc09 | 240 | |
johnAlexander | 0:c523920bcc09 | 241 | |
johnAlexander | 0:c523920bcc09 | 242 |