Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (7.975 KB)

1
/*
2
 * COPYRIGHT (C) STMicroelectronics 2014. All rights reserved.
3
 *
4
 * This software is the confidential and proprietary information of
5
 * STMicroelectronics ("Confidential Information").  You shall not
6
 * disclose such Confidential Information and shall use it only in
7
 * accordance with the terms of the license agreement you entered into
8
 * with STMicroelectronics
9
 *
10
 * Programming Golden Rule: Keep it Simple!
11
 *
12
 */
13

    
14
/**
15
 * @file   VL53L0X_platform.h
16
 * @brief  Function prototype definitions for Ewok Platform layer.
17
 *
18
 */
19

    
20
//MUST WRITE OWN
21

    
22
#ifndef _VL53L0X_I2C_PLATFORM_H_
23
#define _VL53L0X_I2C_PLATFORM_H_
24

    
25
#include <amiro-lld.h>
26
#include <periphAL.h>
27
#include <stdio.h>
28
#include <stdlib.h>
29
#include <time.h>
30

    
31
#include "vl53l0x_def.h"
32

    
33

    
34
#ifdef __cplusplus
35
extern "C" {
36
#endif
37

    
38
// Include uint8_t, unit16_t  etc definitions
39

    
40
#include <stdint.h>
41
#include <stdarg.h>
42

    
43

    
44
/**
45
 *  @brief Typedef defining .\n
46
 * The developer shoud modify this to suit the platform being deployed.
47
 *
48
 */
49

    
50
// enum  {TRUE = true, FALSE = false};
51

    
52
/**
53
 * @brief Typedef defining 8 bit unsigned char type.\n
54
 * The developer shoud modify this to suit the platform being deployed.
55
 *
56
 */
57

    
58
#ifndef bool_t
59
typedef unsigned char bool_t;
60
#endif
61

    
62

    
63
#define           I2C                0x01
64
#define           SPI                0x00
65

    
66
#define    COMMS_BUFFER_SIZE    64  // MUST be the same size as the SV task buffer
67

    
68
#define    BYTES_PER_WORD        2
69
#define    BYTES_PER_DWORD       4
70

    
71
#define    VL53L0X_MAX_STRING_LENGTH_PLT       256
72

    
73
/**
74
 * @brief  Initialise platform comms.
75
 *
76
 * @param  comms_type      - selects between I2C and SPI
77
 * @param  comms_speed_khz - unsigned short containing the I2C speed in kHz
78
 *
79
 * @return status - status 0 = ok, 1 = error
80
 *
81
 */
82

    
83

    
84

    
85

    
86

    
87

    
88

    
89
int32_t VL53L0X_write_multi(apalI2CDriver_t* i2cd, uint8_t address, uint8_t reg, uint8_t *pdata, int32_t count, apalTime_t timeout);
90

    
91

    
92
/**
93
 * @brief  Reads the requested number of bytes from the device
94
 *
95
 * Wrapper for SystemVerilog Read Multi task
96
 *
97
 * @code
98
 *
99
 * Example:
100
 *
101
 * uint8_t buffer[COMMS_BUFFER_SIZE];
102
 *
103
 * int status = status  = VL53L0X_read_multi(DEVICE_ID, buffer, 2)
104
 *
105
 * @endcode
106
 *
107
 * @param  address - uint8_t device address value
108
 * @param  index - uint8_t register index value
109
 * @param  pdata - pointer to the uint8_t buffer to store read data
110
 * @param  count - number of uint8_t's to read
111
 *
112
 * @return status - SystemVerilog status 0 = ok, 1 = error
113
 *
114
 */
115

    
116
int32_t VL53L0X_read_multi(apalI2CDriver_t* i2cd, uint8_t address, uint8_t index, uint8_t *pdata, size_t count, apalTime_t timeout);
117

    
118

    
119
/**
120
 * @brief  Writes a single byte to the device
121
 *
122
 * Wrapper for SystemVerilog Write Byte task
123
 *
124
 * @code
125
 *
126
 * Example:
127
 *
128
 * uint8_t page_number = MAIN_SELECT_PAGE;
129
 *
130
 * int status = VL53L0X_write_byte(PAGE_SELECT, page_number);
131
 *
132
 * @endcode
133
 *
134
 * @param  address - uint8_t device address value
135
 * @param  index - uint8_t register index value
136
 * @param  data  - uint8_t data value to write
137
 *
138
 * @return status - SystemVerilog status 0 = ok, 1 = error
139
 *
140
 */
141

    
142
int32_t VL53L0X_write_byte(apalI2CDriver_t* i2cd, uint8_t address, uint8_t index, uint8_t data, apalTime_t timeout);
143

    
144

    
145
/**
146
 * @brief  Writes a single word (16-bit unsigned) to the device
147
 *
148
 * Manages the big-endian nature of the device (first byte written is the MS byte).
149
 * Uses SystemVerilog Write Multi task.
150
 *
151
 * @code
152
 *
153
 * Example:
154
 *
155
 * uint16_t nvm_ctrl_pulse_width = 0x0004;
156
 *
157
 * int status = VL53L0X_write_word(NVM_CTRL__PULSE_WIDTH_MSB, nvm_ctrl_pulse_width);
158
 *
159
 * @endcode
160
 *
161
 * @param  address - uint8_t device address value
162
 * @param  index - uint8_t register index value
163
 * @param  data  - uin16_t data value write
164
 *
165
 * @return status - SystemVerilog status 0 = ok, 1 = error
166
 *
167
 */
168

    
169
int32_t VL53L0X_write_word(apalI2CDriver_t* i2cd, uint8_t address, uint8_t index, uint16_t data, apalTime_t timeout);
170

    
171

    
172
/**
173
 * @brief  Writes a single dword (32-bit unsigned) to the device
174
 *
175
 * Manages the big-endian nature of the device (first byte written is the MS byte).
176
 * Uses SystemVerilog Write Multi task.
177
 *
178
 * @code
179
 *
180
 * Example:
181
 *
182
 * uint32_t nvm_data = 0x0004;
183
 *
184
 * int status = VL53L0X_write_dword(NVM_CTRL__DATAIN_MMM, nvm_data);
185
 *
186
 * @endcode
187
 *
188
 * @param  address - uint8_t device address value
189
 * @param  index - uint8_t register index value
190
 * @param  data  - uint32_t data value to write
191
 *
192
 * @return status - SystemVerilog status 0 = ok, 1 = error
193
 *
194
 */
195

    
196
int32_t VL53L0X_write_dword(apalI2CDriver_t* i2cd, uint8_t address, uint8_t index, uint32_t data, apalTime_t timeout);
197

    
198

    
199

    
200
/**
201
 * @brief  Reads a single byte from the device
202
 *
203
 * Uses SystemVerilog Read Byte task.
204
 *
205
 * @code
206
 *
207
 * Example:
208
 *
209
 * uint8_t device_status = 0;
210
 *
211
 * int status = VL53L0X_read_byte(STATUS, &device_status);
212
 *
213
 * @endcode
214
 *
215
 * @param  address - uint8_t device address value
216
 * @param  index  - uint8_t register index value
217
 * @param  pdata  - pointer to uint8_t data value
218
 *
219
 * @return status - SystemVerilog status 0 = ok, 1 = error
220
 *
221
 */
222

    
223
int32_t VL53L0X_read_byte(apalI2CDriver_t* i2cd, uint8_t address, uint8_t index, uint8_t *pdata, apalTime_t timeout);
224

    
225

    
226
/**
227
 * @brief  Reads a single word (16-bit unsigned) from the device
228
 *
229
 * Manages the big-endian nature of the device (first byte read is the MS byte).
230
 * Uses SystemVerilog Read Multi task.
231
 *
232
 * @code
233
 *
234
 * Example:
235
 *
236
 * uint16_t timeout = 0;
237
 *
238
 * int status = VL53L0X_read_word(TIMEOUT_OVERALL_PERIODS_MSB, &timeout);
239
 *
240
 * @endcode
241
 *
242
 * @param  address - uint8_t device address value
243
 * @param  index  - uint8_t register index value
244
 * @param  pdata  - pointer to uint16_t data value
245
 *
246
 * @return status - SystemVerilog status 0 = ok, 1 = error
247
 *
248
 */
249

    
250
int32_t VL53L0X_read_word(apalI2CDriver_t* i2cd, uint8_t address, uint8_t index, uint16_t *pdata, apalTime_t timeout);
251

    
252

    
253
/**
254
 * @brief  Reads a single dword (32-bit unsigned) from the device
255
 *
256
 * Manages the big-endian nature of the device (first byte read is the MS byte).
257
 * Uses SystemVerilog Read Multi task.
258
 *
259
 * @code
260
 *
261
 * Example:
262
 *
263
 * uint32_t range_1 = 0;
264
 *
265
 * int status = VL53L0X_read_dword(RANGE_1_MMM, &range_1);
266
 *
267
 * @endcode
268
 *
269
 * @param  address - uint8_t device address value
270
 * @param  index - uint8_t register index value
271
 * @param  pdata - pointer to uint32_t data value
272
 *
273
 * @return status - SystemVerilog status 0 = ok, 1 = error
274
 *
275
 */
276

    
277
int32_t VL53L0X_read_dword(apalI2CDriver_t* i2cd, uint8_t address, uint8_t index, uint32_t *pdata, apalTime_t timeout);
278

    
279

    
280
/**
281
 * @brief  Implements a programmable wait in us
282
 *
283
 * Wrapper for SystemVerilog Wait in micro seconds task
284
 *
285
 * @param  wait_us - integer wait in micro seconds
286
 *
287
 * @return status - SystemVerilog status 0 = ok, 1 = error
288
 *
289
 */
290

    
291
int32_t VL53L0X_platform_wait_us(int32_t wait_us);
292

    
293

    
294
/**
295
 * @brief  Implements a programmable wait in ms
296
 *
297
 * Wrapper for SystemVerilog Wait in milli seconds task
298
 *
299
 * @param  wait_ms - integer wait in milli seconds
300
 *
301
 * @return status - SystemVerilog status 0 = ok, 1 = error
302
 *
303
 */
304

    
305
int32_t VL53L0X_wait_ms(int32_t wait_ms);
306

    
307

    
308
/**
309
 * @brief Set GPIO value
310
 *
311
 * @param  level  - input  level - either 0 or 1
312
 *
313
 * @return status - SystemVerilog status 0 = ok, 1 = error
314
 *
315
 */
316

    
317
int32_t VL53L0X_set_gpio(uint8_t  level);
318

    
319

    
320
/**
321
 * @brief Get GPIO value
322
 *
323
 * @param  plevel - uint8_t pointer to store GPIO level (0 or 1)
324
 *
325
 * @return status - SystemVerilog status 0 = ok, 1 = error
326
 *
327
 */
328

    
329
int32_t VL53L0X_get_gpio(uint8_t *plevel);
330

    
331
/**
332
 * @brief Release force on GPIO
333
 *
334
 * @return status - SystemVerilog status 0 = ok, 1 = error
335
 *
336
 */
337

    
338
int32_t VL53L0X_release_gpio(void);
339

    
340

    
341
/**
342
* @brief Get the frequency of the timer used for ranging results time stamps
343
*
344
* @param[out] ptimer_freq_hz : pointer for timer frequency
345
*
346
* @return status : 0 = ok, 1 = error
347
*
348
*/
349

    
350
int32_t VL53L0X_get_timer_frequency(int32_t *ptimer_freq_hz);
351

    
352
/**
353
* @brief Get the timer value in units of timer_freq_hz (see VL53L0X_get_timestamp_frequency())
354
*
355
* @param[out] ptimer_count : pointer for timer count value
356
*
357
* @return status : 0 = ok, 1 = error
358
*
359
*/
360

    
361
int32_t VL53L0X_get_timer_value(int32_t *ptimer_count);
362

    
363

    
364

    
365

    
366

    
367
#ifdef __cplusplus
368
}
369
#endif
370

    
371
#endif //_VL53L0X_I2C_PLATFORM_H_
372