Statistics
| Branch: | Tag: | Revision:

amiro-lld / include / VL53L0X / v1 / Api_vl53l0x / platform / inc / vl53l0x_platform.h @ 6ebebd4d

History | View | Annotate | Download (8.59 KB)

1
/*******************************************************************************
2
Copyright � 2015, STMicroelectronics International N.V.
3
All rights reserved.
4

5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are met:
7
    * Redistributions of source code must retain the above copyright
8
      notice, this list of conditions and the following disclaimer.
9
    * Redistributions in binary form must reproduce the above copyright
10
      notice, this list of conditions and the following disclaimer in the
11
      documentation and/or other materials provided with the distribution.
12
    * Neither the name of STMicroelectronics nor the
13
      names of its contributors may be used to endorse or promote products
14
      derived from this software without specific prior written permission.
15

16
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
19
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
20
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
21
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
********************************************************************************/
28

    
29

    
30
#ifndef _VL53L0X_PLATFORM_H_
31
#define _VL53L0X_PLATFORM_H_
32

    
33
//#include <periphALtypes.h>
34
//#include <periphAL.h>
35
#include <amiro-lld.h>
36
#include "vl53l0x_def.h"
37
#include "vl53l0x_platform_log.h"
38
#include "vl53l0x_i2c_platform.h"
39

    
40
//#include "alld_vl53l0x.h"
41
//#include "vl53l0x_api_strings.h"
42

    
43

    
44
#ifdef __cplusplus
45
extern "C" {
46
#endif
47

    
48
/**
49
 * @file vl53l0x_platform.h
50
 *
51
 * @brief All end user OS/platform/application porting
52
 */
53

    
54
/**
55
 * @defgroup VL53L0X_platform_group VL53L0X Platform Functions
56
 * @brief    VL53L0X Platform Functions
57
 *  @{
58
 */
59

    
60
/**
61
 * @struct  VL53L0X_Dev_t
62
 * @brief    Generic PAL device type that does link between API and platform abstraction layer
63
 *
64
 */
65
typedef struct {
66
    apalI2CDriver_t* i2cd;              /*!< @brief The I2C Driver.     */
67
    apalTime_t timeout;                 /*!< timeout for chibios I2C interactions */
68
    VL53L0X_DevData_t Data;               /*!< embed ST Ewok Dev  data as "Data"*/
69

    
70
    /*!< user specific field */
71
    uint16_t   I2cDevAddr;                /*!< i2c device address user specific field */
72
    uint8_t   comms_type;                /*!< Type of comms : VL53L0X_COMMS_I2C or VL53L0X_COMMS_SPI */
73
    uint16_t  comms_speed_khz;           /*!< Comms speed [kHz] : typically 400kHz for I2C           */
74

    
75
} VL53L0X_Dev_t;
76

    
77

    
78
/**
79
 * @brief   Declare the device Handle as a pointer of the structure @a VL53L0X_Dev_t.
80
 *
81
 */
82
typedef VL53L0X_Dev_t* VL53L0X_DEV;
83

    
84
/**
85
 * @def PALDevDataGet
86
 * @brief Get ST private structure @a VL53L0X_DevData_t data access
87
 *
88
 * @param Dev       Device Handle
89
 * @param field     ST structure field name
90
 * It maybe used and as real data "ref" not just as "get" for sub-structure item
91
 * like PALDevDataGet(FilterData.field)[i] or PALDevDataGet(FilterData.MeasurementIndex)++
92
 */
93
#define PALDevDataGet(Dev, field) (Dev->Data.field)
94

    
95
/**
96
 * @def PALDevDataSet(Dev, field, data)
97
 * @brief  Set ST private structure @a VL53L0X_DevData_t data field
98
 * @param Dev       Device Handle
99
 * @param field     ST structure field name
100
 * @param data      Data to be set
101
 */
102
#define PALDevDataSet(Dev, field, data) (Dev->Data.field)=(data)
103

    
104

    
105
/**
106
 * @defgroup VL53L0X_registerAccess_group PAL Register Access Functions
107
 * @brief    PAL Register Access Functions
108
 *  @{
109
 */
110

    
111
/**
112
 * Lock comms interface to serialize all commands to a shared I2C interface for a specific device
113
 * @param   Dev       Device Handle
114
 * @return  VL53L0X_ERROR_NONE        Success
115
 * @return  "Other error code"    See ::VL53L0X_Error
116
 */
117
VL53L0X_Error VL53L0X_LockSequenceAccess(VL53L0X_DEV Dev);
118

    
119
/**
120
 * Unlock comms interface to serialize all commands to a shared I2C interface for a specific device
121
 * @param   Dev       Device Handle
122
 * @return  VL53L0X_ERROR_NONE        Success
123
 * @return  "Other error code"    See ::VL53L0X_Error
124
 */
125
VL53L0X_Error VL53L0X_UnlockSequenceAccess(VL53L0X_DEV Dev);
126

    
127

    
128
/**
129
 * Writes the supplied byte buffer to the device
130
 * @param   Dev       Device Handle
131
 * @param   index     The register index
132
 * @param   pdata     Pointer to uint8_t buffer containing the data to be written
133
 * @param   count     Number of bytes in the supplied byte buffer
134
 * @return  VL53L0X_ERROR_NONE        Success
135
 * @return  "Other error code"    See ::VL53L0X_Error
136
 */
137
VL53L0X_Error VL53L0X_WriteMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count);
138

    
139
/**
140
 * Reads the requested number of bytes from the device
141
 * @param   Dev       Device Handle
142
 * @param   index     The register index
143
 * @param   pdata     Pointer to the uint8_t buffer to store read data
144
 * @param   count     Number of uint8_t's to read
145
 * @return  VL53L0X_ERROR_NONE        Success
146
 * @return  "Other error code"    See ::VL53L0X_Error
147
 */
148
VL53L0X_Error VL53L0X_ReadMulti(VL53L0X_DEV Dev, uint8_t index, uint8_t *pdata, uint32_t count);
149

    
150
/**
151
 * Write single byte register
152
 * @param   Dev       Device Handle
153
 * @param   index     The register index
154
 * @param   data      8 bit register data
155
 * @return  VL53L0X_ERROR_NONE        Success
156
 * @return  "Other error code"    See ::VL53L0X_Error
157
 */
158
VL53L0X_Error VL53L0X_WrByte(VL53L0X_DEV Dev, uint8_t index, uint8_t data);
159

    
160
/**
161
 * Write word register
162
 * @param   Dev       Device Handle
163
 * @param   index     The register index
164
 * @param   data      16 bit register data
165
 * @return  VL53L0X_ERROR_NONE        Success
166
 * @return  "Other error code"    See ::VL53L0X_Error
167
 */
168
VL53L0X_Error VL53L0X_WrWord(VL53L0X_DEV Dev, uint8_t index, uint16_t data);
169

    
170
/**
171
 * Write double word (4 byte) register
172
 * @param   Dev       Device Handle
173
 * @param   index     The register index
174
 * @param   data      32 bit register data
175
 * @return  VL53L0X_ERROR_NONE        Success
176
 * @return  "Other error code"    See ::VL53L0X_Error
177
 */
178
VL53L0X_Error VL53L0X_WrDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t data);
179

    
180
/**
181
 * Read single byte register
182
 * @param   Dev       Device Handle
183
 * @param   index     The register index
184
 * @param   data      pointer to 8 bit data
185
 * @return  VL53L0X_ERROR_NONE        Success
186
 * @return  "Other error code"    See ::VL53L0X_Error
187
 */
188
VL53L0X_Error VL53L0X_RdByte(VL53L0X_DEV Dev, uint8_t index, uint8_t *data);
189

    
190
/**
191
 * Read word (2byte) register
192
 * @param   Dev       Device Handle
193
 * @param   index     The register index
194
 * @param   data      pointer to 16 bit data
195
 * @return  VL53L0X_ERROR_NONE        Success
196
 * @return  "Other error code"    See ::VL53L0X_Error
197
 */
198
VL53L0X_Error VL53L0X_RdWord(VL53L0X_DEV Dev, uint8_t index, uint16_t *data);
199

    
200
/**
201
 * Read dword (4byte) register
202
 * @param   Dev       Device Handle
203
 * @param   index     The register index
204
 * @param   data      pointer to 32 bit data
205
 * @return  VL53L0X_ERROR_NONE        Success
206
 * @return  "Other error code"    See ::VL53L0X_Error
207
 */
208
VL53L0X_Error VL53L0X_RdDWord(VL53L0X_DEV Dev, uint8_t index, uint32_t *data);
209

    
210
/**
211
 * Threat safe Update (read/modify/write) single byte register
212
 *
213
 * Final_reg = (Initial_reg & and_data) |or_data
214
 *
215
 * @param   Dev        Device Handle
216
 * @param   index      The register index
217
 * @param   AndData    8 bit and data
218
 * @param   OrData     8 bit or data
219
 * @return  VL53L0X_ERROR_NONE        Success
220
 * @return  "Other error code"    See ::VL53L0X_Error
221
 */
222
VL53L0X_Error VL53L0X_UpdateByte(VL53L0X_DEV Dev, uint8_t index, uint8_t AndData, uint8_t OrData);
223

    
224
/** @} end of VL53L0X_registerAccess_group */
225

    
226

    
227
/**
228
 * @brief execute delay in all polling API call
229
 *
230
 * A typical multi-thread or RTOs implementation is to sleep the task for some 5ms (with 100Hz max rate faster polling is not needed)
231
 * if nothing specific is need you can define it as an empty/void macro
232
 * @code
233
 * #define VL53L0X_PollingDelay(...) (void)0
234
 * @endcode
235
 * @param Dev       Device Handle
236
 * @return  VL53L0X_ERROR_NONE        Success
237
 * @return  "Other error code"    See ::VL53L0X_Error
238
 */
239
//VL53L0X_Error VL53L0X_PollingDelay(VL53L0X_DEV Dev); /* usually best implemented as a real function */
240

    
241
/** @} end of VL53L0X_platform_group */
242

    
243
#ifdef __cplusplus
244
}
245
#endif
246

    
247
#endif  /* _VL53L0X_PLATFORM_H_ */
248

    
249

    
250