Revision f0dd1ac4

View differences:

drivers/VL53L1X/v1/alld_VL53L1X.c
1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  Thomas Schöpping et al.
4

  
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

  
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU Lesser General Public License for more details.
14

  
15
You should have received a copy of the GNU Lesser General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

  
19
/**
20
 * @file    alld_VL53L1X.c
21
 * @brief   ToF sensor function implementations.
22
 *
23
 * @addtogroup lld_vl53l1x
24
 * @{
25
 */
26

  
1 27
#include <alld_VL53L1X.h>
2
//#include "vl53l1_platform.h"
3 28
#include <vl53l1_api.h>
4
// #include "vl53l1_platform_log.h"
29
#include <string.h>
5 30

  
31
/******************************************************************************/
32
/* LOCAL DEFINITIONS                                                          */
33
/******************************************************************************/
6 34

  
7
// #include "stm32xxx_hal.h"
8
#include <string.h>
35
/**
36
 * @brief   I2C communication timeout (in microseconds).
37
 * @details Cutsom values can be set via alldconf.h file.
38
 */
39
#if !defined(VL53L1X_LLD_I2C_TIMEOUT) || defined(__DOXYGEN__)
40
# define VL53L1X_LLD_I2C_TIMEOUT               ((apalTime_t)1000)
41
#endif
42

  
43
/******************************************************************************/
44
/* EXPORTED VARIABLES                                                         */
45
/******************************************************************************/
46

  
47
/******************************************************************************/
48
/* LOCAL TYPES                                                                */
49
/******************************************************************************/
50

  
51
/******************************************************************************/
52
/* LOCAL VARIABLES                                                            */
53
/******************************************************************************/
54

  
55
/******************************************************************************/
56
/* LOCAL FUNCTIONS                                                            */
57
/******************************************************************************/
58

  
59
/******************************************************************************/
60
/* EXPORTED FUNCTIONS                                                         */
61
/******************************************************************************/
62

  
63
/* interface functions for ST API *********************************************/
9 64

  
10
apalExitStatus_t hello_world(void){
11
    return APAL_STATUS_OK;
65
/**
66
 * @brief   Initialization of communication interface (I2C).
67
 * @details Function not supported.
68
 *          Initialization must be done by OS or application instead.
69
 *
70
 * @param[in] pdev              VL53L1X device handle.
71
 * @param[in] comms_type        I2C speed class (?).
72
 * @param[in] comms_speed_khz   I2C transmission frequency.
73
 *
74
 * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
75
 */
76
VL53L1_Error VL53L1_CommsInitialise(VL53L1_Dev_t *pdev, uint8_t comms_type, uint16_t comms_speed_khz)
77
{
78
  apalDbgAssert(pdev != NULL);
79

  
80
  (void)pdev;
81
  (void)comms_type;
82
  (void)comms_speed_khz;
83

  
84
  return VL53L1_ERROR_NOT_SUPPORTED;
12 85
}
13 86

  
14 87
/**
15
 * @brief Set the GPIO1 to a specific state.
16
 * @param[in]   ledp        The LED driver object.
17
 * @param[in]   led_state   The state to set the LED to.
18
 * @return                  An indicator whether the call was successful.
88
 * @brief   Deinitialization of communication interface (I2C).
89
 * @details Function not supported.
90
 *          Deinitialization must be done by OS or application instead.
91
 *
92
 * @param[in] pdev  VL53L1X device handle.
93
 *
94
 * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
19 95
 */
20
apalExitStatus_t vl53l1x_GPIO1_set(const VL53L1XDriver* const vlx, const gpio_lld_state_t state)
96
VL53L1_Error VL53L1_CommsClose(VL53L1_Dev_t *pdev)
21 97
{
22
  apalDbgAssert(vlx != NULL);
23
  
24
  return apalControlGpioSet(vlx->xshut, (state == GPIO_LLD_STATE_ON) ? APAL_GPIO_ON : APAL_GPIO_OFF);
98
  apalDbgAssert(pdev != NULL);
99

  
100
  (void)pdev;
101

  
102
  return VL53L1_ERROR_NOT_SUPPORTED;
25 103
}
26 104

  
105
/**
106
 * @brief   Transmit multiple bytes of data via I2C.
107
 *
108
 * @param[in] pdev    Device handle.
109
 * @param[in] index   Register address to write to.
110
 * @param[in] pdata   Data buffer to be transmitted.
111
 * @param[in] count   Number of bytes to transmit.
112
 *
113
 * @return  Status indicating whether the call was successful.
114
 * @retval  VL53L1_ERROR_NONE       Transmission was successful.
115
 * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
116
 * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
117
 */
118
VL53L1_Error VL53L1_WriteMulti(VL53L1_Dev_t *pdev, uint16_t index, uint8_t *pdata, uint32_t count)
119
{
120
  apalDbgAssert(pdev != NULL);
27 121

  
122
  // prepare transmit buffer with prepended address bytes.
123
  uint8_t txbuf[sizeof(uint16_t) + count];
124
  txbuf[0] = index >> 8;
125
  txbuf[1] = index & 0xFF;
126
  memcpy(&txbuf[2], pdata, count);
28 127

  
128
  // transmit address and data
129
  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), NULL, 0, VL53L1X_LLD_I2C_TIMEOUT);
29 130

  
131
  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
132
         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
133
}
30 134

  
135
/**
136
 * @brief   Read multiple bytes of data via I2C.
137
 *
138
 * @param[in]   pdev    Device handle.
139
 * @param[in]   index   Register address to read from.
140
 * @param[out]  pdata   Data buffer to store read data to.
141
 * @param[in]   count   Number of bytes to read.
142
 *
143
 * @return  Status indicating whether the call was successful.
144
 * @retval  VL53L1_ERROR_NONE       Transmission was successful.
145
 * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
146
 * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
147
 */
148
VL53L1_Error VL53L1_ReadMulti(VL53L1_Dev_t *pdev, uint16_t index, uint8_t *pdata, uint32_t count)
149
{
150
  apalDbgAssert(pdev != NULL);
31 151

  
152
  // prepare address buffer
153
  uint8_t txbuf[sizeof(uint16_t)] = {index >> 8, index & 0xFF};
32 154

  
33
// #define I2C_TIME_OUT_BASE   10
34
// #define I2C_TIME_OUT_BYTE   1
155
  // transmit address and recieve data
156
  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), pdata, count, VL53L1X_LLD_I2C_TIMEOUT);
35 157

  
36
// #ifdef VL53L1_LOG_ENABLE
37
// #define trace_print(level, ...) VL53L1_trace_print_module_function(VL53L1_TRACE_MODULE_PLATFORM, level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
38
// #define trace_i2c(...) VL53L1_trace_print_module_function(VL53L1_TRACE_MODULE_NONE, VL53L1_TRACE_LEVEL_NONE, VL53L1_TRACE_FUNCTION_I2C, ##__VA_ARGS__)
39
// #endif
158
  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
159
         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
160
}
40 161

  
41
// #ifndef HAL_I2C_MODULE_ENABLED
42
// #warning "HAL I2C module must be enable "
43
// #endif
162
/**
163
 * @brief   Transmit a single byte via I2C.
164
 *
165
 * @param[in] pdev              Device handle.
166
 * @param[in] index             Register address to write to.
167
 * @param[in] VL53L1_PRM_00005  Byte to transmit.
168
 *
169
 * @return  Status indicating whether the call was successful.
170
 * @retval  VL53L1_ERROR_NONE       Transmission was successful.
171
 * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
172
 * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
173
 */
174
VL53L1_Error VL53L1_WrByte(VL53L1_Dev_t *pdev, uint16_t index, uint8_t VL53L1_PRM_00005)
175
{
176
  apalDbgAssert(pdev != NULL);
177

  
178
  // prepare transmit buffer with prepended address bytes.
179
  uint8_t txbuf[sizeof(uint16_t) + sizeof(uint8_t)] = {index >> 8, index & 0xFF,
180
                                                       VL53L1_PRM_00005};
44 181

  
45
//extern I2C_HandleTypeDef hi2c1;
46
//#define VL53L0X_pI2cHandle    (&hi2c1)
182
  // transmit address and data
183
  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), NULL, 0, VL53L1X_LLD_I2C_TIMEOUT);
47 184

  
48
/* when not customized by application define dummy one */
49
// #ifndef VL53L1_GetI2cBus
50
/** This macro can be overloaded by user to enforce i2c sharing in RTOS context
185
  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
186
         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
187
}
188

  
189
/**
190
 * @brief   Transmit a 16-bit data word via I2C.
191
 *
192
 * @param[in] pdev              Device handle.
193
 * @param[in] index             Register address to write to.
194
 * @param[in] VL53L1_PRM_00005  16-bit data word to transmit.
195
 *
196
 * @return  Status indicating whether the call was successful.
197
 * @retval  VL53L1_ERROR_NONE       Transmission was successful.
198
 * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
199
 * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
51 200
 */
52
// #   define VL53L1_GetI2cBus(...) (void)0
53
// #endif
201
VL53L1_Error VL53L1_WrWord(VL53L1_Dev_t *pdev, uint16_t index, uint16_t VL53L1_PRM_00005)
202
{
203
  apalDbgAssert(pdev != NULL);
204

  
205
  // prepare transmit buffer with prepended address bytes.
206
  uint8_t txbuf[sizeof(uint16_t) + sizeof(uint16_t)] = {index >> 8, index & 0xFF,
207
                                                        (VL53L1_PRM_00005 >> 8) & 0xFF,
208
                                                        (VL53L1_PRM_00005 >> 0) & 0xFF};
54 209

  
55
// #ifndef VL53L1_PutI2cBus
56
/** This macro can be overloaded by user to enforce i2c sharing in RTOS context
210
  // transmit address and data
211
  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), NULL, 0, VL53L1X_LLD_I2C_TIMEOUT);
212

  
213
  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
214
         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
215
}
216

  
217
/**
218
 * @brief   Transmit a 32-bit data word via I2C.
219
 *
220
 * @param[in] pdev              Device handle.
221
 * @param[in] index             Register address to write to.
222
 * @param[in] VL53L1_PRM_00005  32-bit data word to transmit.
223
 *
224
 * @return  Status indicating whether the call was successful.
225
 * @retval  VL53L1_ERROR_NONE       Transmission was successful.
226
 * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
227
 * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
57 228
 */
58
// #   define VL53L1_PutI2cBus(...) (void)0
59
// #endif
229
VL53L1_Error VL53L1_WrDWord(VL53L1_Dev_t *pdev,uint16_t index, uint32_t VL53L1_PRM_00005)
230
{
231
  apalDbgAssert(pdev != NULL);
232

  
233
  // prepare transmit buffer with prepended address bytes.
234
  uint8_t txbuf[sizeof(uint16_t) + sizeof(uint32_t)] = {index >> 8, index & 0xFF,
235
                                                        (VL53L1_PRM_00005 >> 24) & 0xFF,
236
                                                        (VL53L1_PRM_00005 >> 16) & 0xFF,
237
                                                        (VL53L1_PRM_00005 >> 8) & 0xFF,
238
                                                        (VL53L1_PRM_00005 >> 0) & 0xFF};
60 239

  
61
#define I2C_TIME_OUT_BASE   10
62
#define I2C_TIME_OUT_BYTE   1
240
  // transmit address and data
241
  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), NULL, 0, VL53L1X_LLD_I2C_TIMEOUT);
63 242

  
64
uint8_t _I2CBuffer[256] = { 0 };
65
uint8_t rx_buf[256];
66
uint8_t tx_buf[256];
243
  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
244
         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
245
}
67 246

  
68
int _I2CWrite(VL53L1_DEV Dev, uint8_t *pdata, uint32_t count) {
69
    int status = 0;
70
    int i2c_time_out = 1000 * (I2C_TIME_OUT_BASE + count * I2C_TIME_OUT_BYTE);
247
/**
248
 * @brief   Read a single byte via I2C.
249
 *
250
 * @param[in]   pdev    Device handle.
251
 * @param[in]   index   Register address to read from.
252
 * @param[out]  pdata   Single byte buffer to store the read data to.
253
 *
254
 * @return  Status indicating whether the call was successful.
255
 * @retval  VL53L1_ERROR_NONE       Transmission was successful.
256
 * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
257
 * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
258
 */
259
VL53L1_Error VL53L1_RdByte(VL53L1_Dev_t *pdev, uint16_t index, uint8_t *pdata)
260
{
261
  apalDbgAssert(pdev != NULL);
71 262

  
72
    apalExitStatus_t status2 = apalI2CMasterTransmit(Dev->vl53l1x.i2cd, Dev->vl53l1x.addr, pdata, count, rx_buf, 0, 100);
73
    return status;
263
  // prepare address buffer
264
  uint8_t txbuf[sizeof(uint16_t)] = {index >> 8, index & 0xFF};
265

  
266
  // transmit address and recieve data
267
  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), pdata, 1, VL53L1X_LLD_I2C_TIMEOUT);
268

  
269
  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
270
         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
74 271
}
75 272

  
76
int _I2CRead(VL53L1_DEV Dev, uint8_t *pdata, uint32_t count) {
77
   int status = 0;
78
//   apalI2CMasterReceive(Dev->vl53l1x->i2cd, Dev->vl53l1x->addr, uint8_t* const rxbuf, const size_t rxbytes, const apalTime_t timeout)
273
/**
274
 * @brief   Read a 16-bit data word via I2C.
275
 *
276
 * @param[in]   pdev    Device handle.
277
 * @param[in]   index   Register address to read from.
278
 * @param[out]  pdata   16-bit buffer to store the read data to.
279
 *
280
 * @return  Status indicating whether the call was successful.
281
 * @retval  VL53L1_ERROR_NONE       Transmission was successful.
282
 * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
283
 * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
284
 */
285
VL53L1_Error VL53L1_RdWord(VL53L1_Dev_t *pdev,uint16_t index, uint16_t *pdata)
286
{
287
  apalDbgAssert(pdev != NULL);
288

  
289
  // prepare address buffer
290
  uint8_t txbuf[sizeof(uint16_t)] = {index >> 8, index & 0xFF};
291
  // prepare receive buffer
292
  uint8_t rxbuf[sizeof(uint16_t)];
293

  
294
  // transmit address and recieve data
295
  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), rxbuf, sizeof(rxbuf), VL53L1X_LLD_I2C_TIMEOUT);
296

  
297
  // fill return value
298
  *pdata = (((uint16_t)rxbuf[0]) << 8) &
299
           (((uint16_t)rxbuf[1]) << 0);
79 300

  
80
   return status;
301
  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
302
         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
81 303
}
82 304

  
83
// TODO: Needs to be defined
305
/**
306
 * @brief   Read a 32-bit data word via I2C.
307
 *
308
 * @param[in]   pdev    Device handle.
309
 * @param[in]   index   Register address to read from.
310
 * @param[out]  pdata   32-bit buffer to store the read data to.
311
 *
312
 * @return  Status indicating whether the call was successful.
313
 * @retval  VL53L1_ERROR_NONE       Transmission was successful.
314
 * @retval  VL53L1_ERROR_TIME_OUT   Transmission timed out.
315
 * @retval  VL53L1_ERROR_UNDEFINED  Transmission failed for some other reason.
316
 */
317
VL53L1_Error VL53L1_RdDWord(VL53L1_Dev_t *pdev,uint16_t index, uint32_t *pdata)
318
{
319
  apalDbgAssert(pdev != NULL);
320

  
321
  // prepare address buffer
322
  uint8_t txbuf[sizeof(uint16_t)] = {index >> 8, index & 0xFF};
323
  // prepare receive buffer
324
  uint8_t rxbuf[sizeof(uint32_t)];
84 325

  
85
VL53L1_Error VL53L1_WriteMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count) {
86
    VL53L1_Error Status = VL53L1_ERROR_NONE;
326
  apalExitStatus_t status = apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), rxbuf, sizeof(rxbuf), VL53L1X_LLD_I2C_TIMEOUT);
87 327

  
88
    return Status;
328
  // fill return value
329
  *pdata = (((uint32_t)rxbuf[0]) << 24) &
330
           (((uint32_t)rxbuf[1]) << 16) &
331
           (((uint32_t)rxbuf[2]) << 8) &
332
           (((uint32_t)rxbuf[3]) << 0);
333

  
334
  return (status == APAL_STATUS_OK || status > 0) ? VL53L1_ERROR_NONE :
335
         (status == APAL_STATUS_TIMEOUT) ? VL53L1_ERROR_TIME_OUT : VL53L1_ERROR_UNDEFINED;
89 336
}
90 337

  
91
// the ranging_sensor_comms.dll will take care of the page selection
92
VL53L1_Error VL53L1_ReadMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count) {
93
    VL53L1_Error Status = VL53L1_ERROR_NONE;
94
    return Status;
338
/**
339
 * @brief   Wait for a specified amount of microseconds.
340
 *
341
 * @param[in] pdev      Device handle.
342
 * @param[in] wait_us   Time to wait in microsecnonds.
343
 *
344
 * @return  Always returns VL53L1_ERROR_NONE.
345
 */
346
VL53L1_Error VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us)
347
{
348
  (void)pdev;
349

  
350
  apalSleep(wait_us);
351

  
352
  return VL53L1_ERROR_NONE;
95 353
}
96 354

  
97
VL53L1_Error VL53L1_WrByte(VL53L1_DEV Dev, uint16_t index, uint8_t data) {
98
    VL53L1_Error Status = VL53L1_ERROR_NONE;
99
    // printf("Starting to write byte: %X\n", data);
100
     int32_t status_int;
355
/**
356
 * @brief   Wait for a specified amount of milliseconds.
357
 *
358
 * @param[in] pdev      Device handle.
359
 * @param[in] wait_ms   Time to wait in milliseconds.
360
 *
361
 * @return  Always returns VL53L1_ERROR_NONE.
362
 */
363
VL53L1_Error VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms)
364
{
365
  (void)pdev;
101 366

  
102
    _I2CBuffer[0] = index>>8;
103
    _I2CBuffer[1] = index&0xFF;
104
    _I2CBuffer[2] = data;
367
  apalSleep(wait_ms * 1000);
105 368

  
106
    _I2CWrite(Dev, _I2CBuffer, 3);
369
  return VL53L1_ERROR_NONE;
370
}
107 371

  
108
    return Status;
372
/**
373
 * @brief   Retrieve the frequency of a timer?
374
 * @details Function not supported since it is not used by the ST API.
375
 * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
376
 *
377
 * @param[out]  ptimer_freq_hz  Buffer to store the timer frequency to.
378
 *
379
 * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
380
 */
381
VL53L1_Error VL53L1_GetTimerFrequency(int32_t *ptimer_freq_hz)
382
{
383
  apalDbgAssert(ptimer_freq_hz != NULL);
384

  
385
  (void)ptimer_freq_hz;
386

  
387
  return VL53L1_ERROR_NOT_SUPPORTED;
109 388
}
110 389

  
111
VL53L1_Error VL53L1_WrWord(VL53L1_DEV Dev, uint16_t index, uint16_t data) {
112
    VL53L1_Error Status = VL53L1_ERROR_NONE;
113
    return Status;
390
/**
391
 * @brief   Retrieve the current value of a timer?
392
 * @details Function not supported since it is not used by the ST API.
393
 * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
394
 *
395
 * @param[out]  ptimer_count  Buffer to store the current timer value to.
396
 *
397
 * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
398
 */
399
VL53L1_Error VL53L1_GetTimerValue(int32_t *ptimer_count)
400
{
401
  apalDbgAssert(ptimer_count != NULL);
402

  
403
  (void)ptimer_count;
404

  
405
  return VL53L1_ERROR_NOT_SUPPORTED;
114 406
}
115 407

  
116
VL53L1_Error VL53L1_WrDWord(VL53L1_DEV Dev, uint16_t index, uint32_t data) {
117
    VL53L1_Error Status = VL53L1_ERROR_NONE;
118
    return Status;
408
/**
409
 * @brief   Set the mode for a GPIO.
410
 * @details Function not supported since it is not used by the ST API.
411
 * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
412
 *
413
 * @param[in] pin   GPIO pin to modify.
414
 * @param[in] mode  Mode to set for the GPIO.
415
 *
416
 * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
417
 */
418
VL53L1_Error VL53L1_GpioSetMode(uint8_t pin, uint8_t mode)
419
{
420
  (void)pin;
421
  (void)mode;
422

  
423
  return VL53L1_ERROR_NOT_SUPPORTED;
119 424
}
120 425

  
121
VL53L1_Error VL53L1_UpdateByte(VL53L1_DEV Dev, uint16_t index, uint8_t AndData, uint8_t OrData) {
122
    VL53L1_Error Status = VL53L1_ERROR_NONE;
123
    return Status;
426
/**
427
 * @brief   Set the output value for a GPIO.
428
 * @details Function not supported since it is not used by the ST API.
429
 * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
430
 *
431
 * @param[in] pin     GPIO pin to set.
432
 * @param[in] value   Value to set for the GPIO.
433
 *
434
 * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
435
 */
436
VL53L1_Error VL53L1_GpioSetValue(uint8_t pin, uint8_t value)
437
{
438
  (void)pin;
439
  (void)value;
440

  
441
  return VL53L1_ERROR_NOT_SUPPORTED;
124 442
}
125 443

  
126
VL53L1_Error VL53L1_RdByte(VL53L1_DEV Dev, uint16_t index, uint8_t *data) {
127
    VL53L1_Error Status = VL53L1_ERROR_NONE;
128
    
129
    uint8_t indx[2] = { index >> 8, index & 0xFF };
130
    apalExitStatus_t status2 = apalI2CMasterTransmit(Dev->vl53l1x.i2cd, Dev->vl53l1x.addr, indx, 2, data, 1, 0);
444
/**
445
 * @brief   Read the input value of a GPIO.
446
 * @details Function not supported since it is not used by the ST API.
447
 * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
448
 *
449
 * @param[in]   pin     GPIO pin to read.
450
 * @param[out]  pvalue  Buffer to write the read value to.
451
 *
452
 * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
453
 */
454
VL53L1_Error VL53L1_GpioGetValue(uint8_t pin, uint8_t *pvalue)
455
{
456
  (void)pin;
457
  (void)pvalue;
131 458

  
132
    return Status;
459
  return VL53L1_ERROR_NOT_SUPPORTED;
133 460
}
134 461

  
135
VL53L1_Error VL53L1_RdWord(VL53L1_DEV Dev, uint16_t index, uint16_t *data) {
136
    VL53L1_Error Status = VL53L1_ERROR_NONE;
137
    return Status;
462
/**
463
 * @brief   Set to XSHUT GPIO.
464
 * @details Function not supported since it is not used by the ST API.
465
 * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
466
 *
467
 * @param[in] value   Value to set the XSHUT GPIO to.
468
 *
469
 * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
470
 */
471
VL53L1_Error VL53L1_GpioXshutdown(uint8_t value)
472
{
473
  (void)value;
474

  
475
  return VL53L1_ERROR_NOT_SUPPORTED;
138 476
}
139 477

  
140
VL53L1_Error VL53L1_RdDWord(VL53L1_DEV Dev, uint16_t index, uint32_t *data) {
141
    VL53L1_Error Status = VL53L1_ERROR_NONE;
142
    return Status;
478
/**
479
 * @brief   Select a GPIO communication interface?
480
 * @details Function not supported since it is not used by the ST API.
481
 * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
482
 *
483
 * @param[in] value   Identifier of the interface to select?
484
 *
485
 * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
486
 */
487
VL53L1_Error VL53L1_GpioCommsSelect(uint8_t value)
488
{
489
  (void)value;
490

  
491
  return VL53L1_ERROR_NOT_SUPPORTED;
143 492
}
144 493

  
145
VL53L1_Error VL53L1_GetTickCount(
146
	uint32_t *ptick_count_ms)
494
/**
495
 * @brief   Enable power?
496
 * @details Function not supported since it is not used by the ST API.
497
 * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
498
 *
499
 * @param[in] value   ?
500
 *
501
 * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
502
 */
503
VL53L1_Error VL53L1_GpioPowerEnable(uint8_t value)
147 504
{
148
	VL53L1_Error status  = VL53L1_ERROR_NONE;
149
	return status;
505
  (void)value;
506

  
507
  return VL53L1_ERROR_NOT_SUPPORTED;
150 508
}
151 509

  
152
//#define trace_print(level, ...) \
153
//	_LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_PLATFORM, \
154
//	level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
510
/**
511
 * @brief   Enable GPIO interrupt.
512
 * @details Function not supported since it is not used by the ST API.
513
 * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
514
 *
515
 * @param[in] fucntion    Callback function to be executed on interrupt.
516
 * @param[in] edge_type   Signal edge to trigger an interrupts.
517
 *
518
 * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
519
 */
520
VL53L1_Error VL53L1_GpioInterruptEnable(void (*function)(void), uint8_t edge_type)
521
{
522
  (void)function;
523
  (void)edge_type;
155 524

  
156
//#define trace_i2c(...) \
157
//	_LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_NONE, \
158
//	VL53L1_TRACE_LEVEL_NONE, VL53L1_TRACE_FUNCTION_I2C, ##__VA_ARGS__)
525
  return VL53L1_ERROR_NOT_SUPPORTED;
526
}
159 527

  
160
VL53L1_Error VL53L1_GetTimerFrequency(int32_t *ptimer_freq_hz)
528
/**
529
 * @brief   Disable GPIO interrupt.
530
 * @details Function not supported since it is not used by the ST API.
531
 * @note    Intention of this function is unknown as it is neither documented nor used by the ST API.
532
 *
533
 * @return  Always returns VL53L1_ERROR_NOT_SUPPORTED.
534
 */
535
VL53L1_Error VL53L1_GpioInterruptDisable(void)
161 536
{
162
	VL53L1_Error status  = VL53L1_ERROR_NONE;
163
	return status;
537
  return VL53L1_ERROR_NOT_SUPPORTED;
164 538
}
165 539

  
166
VL53L1_Error VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms){
167
	VL53L1_Error status  = VL53L1_ERROR_NONE;
168
	return status;
540
/**
541
 * @brief   Retrieve the current system tick count.
542
 *
543
 * @param[out]  ptime_ms  Buffer to store the current system tick count to.
544
 *
545
 * @return  Always returns VL53L1_ERROR_NONE.
546
 */
547
VL53L1_Error VL53L1_GetTickCount(uint32_t *ptime_ms)
548
{
549
  *ptime_ms = apalGetTime() / 1000;
550

  
551
  return VL53L1_ERROR_NONE;
169 552
}
170 553

  
171
VL53L1_Error VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us){
172
	VL53L1_Error status  = VL53L1_ERROR_NONE;
173
	return status;
554
/**
555
 * @brief   Wait for a specific register to match a (masked) value.
556
 *
557
 * @param[in] pdev            Device handle.
558
 * @param[in] timeout_ms      Timeout value in milliseconds.
559
 * @param[in] index           Register address to check.
560
 * @param[in] value           Value to be matched.
561
 * @param[in] mask            Mask to apply to the register value.
562
 *                            Must not be 0x00.
563
 * @param[in] poll_delay_ms   Poll delay in milliseconds.
564
 *
565
 * @return  Status indicating whether the call was successful.
566
 * @retval  VL53L1_ERROR_NONE       Value matched before timeout.
567
 * @retval  VL53L1_ERROR_TIME_OUT   Value did not match before timeout occurred.
568
 * @retval  VL53L1_ERROR_UNDEFINED  I2C communication failed.
569
 */
570
VL53L1_Error VL53L1_WaitValueMaskEx(VL53L1_Dev_t *pdev, uint32_t timeout_ms, uint16_t index, uint8_t value, uint8_t mask, uint32_t poll_delay_ms)
571
{
572
  apalDbgAssert(pdev != NULL);
573
  apalDbgAssert(mask != 0x00);
574

  
575
  // local variables
576
  const apalTime_t starttime = apalGetTime();
577
  apalTime_t transmissionstartoffset, transmissionendoffset;
578
  apalTime_t remaintime = timeout_ms * 1000;
579
  uint8_t txbuf[sizeof(uint16_t)] = {index >> 8, index & 0xFF};
580
  uint8_t rxbuf[sizeof(uint8_t)];
581

  
582
  // infinite loop will return from within
583
  for(;;) {
584
    // measure time before transmission
585
    transmissionstartoffset = apalGetTime() - starttime;
586

  
587
    // try transmission
588
    if (apalI2CMasterTransmit(pdev->Interface.i2cd, pdev->Interface.addr, txbuf, sizeof(txbuf), rxbuf, sizeof(rxbuf), (remaintime < VL53L1X_LLD_I2C_TIMEOUT) ? remaintime : VL53L1X_LLD_I2C_TIMEOUT) < 0) {
589
      return VL53L1_ERROR_UNDEFINED;
590
    }
591

  
592
    // check returned data
593
    if ((rxbuf[0] & mask) == value) {
594
      return VL53L1_ERROR_NONE;
595
    }
596

  
597
    // measure time after transmission
598
    transmissionendoffset = apalGetTime() - starttime;
599

  
600
    // check for timeout and recalculate remaining time
601
    if (transmissionendoffset < timeout_ms * 1000) {
602
      remaintime = (timeout_ms * 1000) - transmissionendoffset;
603
    } else {
604
      return VL53L1_ERROR_TIME_OUT;
605
    }
606

  
607
    // sleep one poll delay, or the remaining time
608
    if (remaintime > (poll_delay_ms * 1000) - (transmissionendoffset - transmissionstartoffset)) {
609
      apalSleep((poll_delay_ms * 1000) - (transmissionendoffset - transmissionstartoffset));
610
    } else {
611
      apalSleep(remaintime);
612
      return VL53L1_ERROR_TIME_OUT;
613
    }
614

  
615
    // recalculate remaining time
616
    remaintime = apalGetTime() - starttime;
617
    if (remaintime < timeout_ms * 1000) {
618
      remaintime = (timeout_ms * 1000) - remaintime;
619
    } else {
620
      return VL53L1_ERROR_TIME_OUT;
621
    }
622
  }
174 623
}
175 624

  
176
VL53L1_Error VL53L1_WaitValueMaskEx(
177
	VL53L1_Dev_t *pdev,
178
	uint32_t      timeout_ms,
179
	uint16_t      index,
180
	uint8_t       value,
181
	uint8_t       mask,
182
	uint32_t      poll_delay_ms)
625
/* driver functions ***********************************************************/
626

  
627
/**
628
 * @brief   Read the current activation state of the device.
629
 *
630
 * @param[in]   vl53l1x   Driver object to check.
631
 * @param[out]  state     State of the device.
632
 *
633
 * @return  Indicator whether the call was successful.
634
 */
635
apalExitStatus_t vl53l1x_lld_getState(VL53L1XDriver* vl53l1x, vl53l1x_lld_state_t* state)
183 636
{
184
	VL53L1_Error status  = VL53L1_ERROR_NONE;
185
	return status;
637
  apalDbgAssert(vl53l1x != NULL);
638
  apalDbgAssert(state != NULL);
639

  
640
  apalControlGpioState_t gpio_state;
641
  apalExitStatus_t status = apalControlGpioGet(vl53l1x->Interface.xshut, &gpio_state);
642
  *state = gpio_state == APAL_GPIO_ON ? VL53L1X_LLD_STATE_ON : VL53L1X_LLD_STATE_OFF;
643

  
644
  return status;
186 645
}
187 646

  
647
/**
648
 * @brief   Performs initialization procedure according to manual after device
649
 *          brought out of reset.
650
 *
651
 * @param[in,out] vl53l1x   Device to be initialized.
652
 *
653
 * @return  Indicator whether the call was successful.
654
 */
655
apalExitStatus_t vl53l1x_lld_init(VL53L1XDriver* vl53l1x)
656
{
657
  apalDbgAssert(vl53l1x != NULL);
658

  
659
  // local variables
660
  apalExitStatus_t status;
661
  VL53L1_Error errval;
662

  
663
  // check whether the device is already active
664
  {
665
    vl53l1x_lld_state_t xshut_state;
666
    status = vl53l1x_lld_getState(vl53l1x, &xshut_state);
667
    if (status != APAL_STATUS_OK) {
668
      return APAL_STATUS_ERROR;
669
    }
670
    // return warning if the device is already active
671
    if (xshut_state == VL53L1X_LLD_STATE_ON) {
672
      return APAL_STATUS_WARNING;
673
    }
674
  }
675

  
676
  // activate the device
677
  apalDbgPrintf("apalControlGpioSet()\n");
678
  status |= apalControlGpioSet(vl53l1x->Interface.xshut, APAL_GPIO_ON);
679
  apalDbgPrintf("\tstatus: %d\n", status);
680

  
681
  // initialize device as described in manual
682
  apalDbgPrintf("VL53L1_WaitDeviceBooted()\n");
683
  errval = VL53L1_WaitDeviceBooted(vl53l1x);
684
  status |= (errval == VL53L1_ERROR_NONE) ? APAL_STATUS_SUCCESS : APAL_STATUS_ERROR;
685
  apalDbgPrintf("\tstatus: %d\terrval: %d\n", status, errval);
686
  apalDbgPrintf("VL53L1_DataInit()\n");
687
  errval = VL53L1_DataInit(vl53l1x);
688
  status |= (errval == VL53L1_ERROR_NONE) ? APAL_STATUS_SUCCESS : APAL_STATUS_ERROR;
689
  apalDbgPrintf("\tstatus: %d\terrval: %d\n", status, errval);
690
  apalDbgPrintf("VL53L1_StaticInit()\n");
691
  errval = VL53L1_StaticInit(vl53l1x);
692
  status |= (errval == VL53L1_ERROR_NONE) ? APAL_STATUS_SUCCESS : APAL_STATUS_ERROR;
693
  apalDbgPrintf("\tstatus: %d\terrval: %d\n", status, errval);
694

  
695
  return status;
696
}
188 697

  
698
/**
699
 * @brief   Reset a device by deactivating the XSHUT signal.
700
 *
701
 * @param[in] vl53l1x   Device to reset.
702
 *
703
 * @return  Indicator whether the call was successful.
704
 */
705
apalExitStatus_t vl53l1x_lld_reset(VL53L1XDriver* vl53l1x)
706
{
707
  return apalControlGpioSet(vl53l1x->Interface.xshut, APAL_GPIO_OFF);
708
}
189 709

  
710
/** @} */
drivers/VL53L1X/v1/alld_VL53L1X.h
1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  Thomas Schöpping et al.
4

  
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

  
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU Lesser General Public License for more details.
14

  
15
You should have received a copy of the GNU Lesser General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

  
1 19
/**
2 20
 * @file    alld_VL53L1X.h
3
 * @brief   Touch sensor macros and structures.
21
 * @brief   ToF sensor macros and structures.
4 22
 *
5
 * @addtogroup lld_touch
23
 * @addtogroup lld_vl53l1x
6 24
 * @{
7 25
 */
8 26

  
......
10 28
#define AMIROLLD_VL53L1X_H
11 29

  
12 30
#include <amiro-lld.h>
13
#include <alld_VL53L1X_types.h>
14 31
#include <vl53l1_api.h>
32

  
15 33
/******************************************************************************/
16 34
/* CONSTANTS                                                                  */
17 35
/******************************************************************************/
18
// 400kHz
19
#define VL53L1X_LLD_I2C_MAXFREQUENCY 400000
20 36

  
21
/* Default I2C address */
22
/* #define VL53L1X_LLD_I2C_ADDR_DEFAULT      0x52 */
23
#define VL53L1X_LLD_I2C_ADDR_DEFAULT           0x29
37
/**
38
 * @brief   Maximum I2C frequency (in Hz).
39
 */
40
#define VL53L1X_LLD_I2C_MAXFREQUENCY            1000000
24 41

  
25
#define VL53L1X_LLD_BOOTDURATION     1200
42
/**
43
 * @brief   Default I2C address.
44
 */
45
#define VL53L1X_LLD_I2C_ADDR_DEFAULT            0x29
26 46

  
27 47
/******************************************************************************/
28 48
/* SETTINGS                                                                   */
......
36 56
/* DATA STRUCTURES AND TYPES                                                  */
37 57
/******************************************************************************/
38 58

  
59
/*
60
 * Structures and types are declared in a separate file, because ST API requires
61
 * this information, too.
62
 */
63
#include <vl53l1_platform_user_data.h>
64

  
39 65
/**
40
 * @brief The state of the GPIOs.
66
 * @brief   The state of the VL53L1X device.
67
 * @details Represents the state of the XSHUT signal.
41 68
 */
42 69
typedef enum {
43
  GPIO_LLD_STATE_OFF = 0x00,   /**< 'on' state of the LED */
44
  GPIO_LLD_STATE_ON  = 0x01,   /**< 'off' state of the LED */
45
} gpio_lld_state_t;
70
  VL53L1X_LLD_STATE_OFF = 0x00, /**< Device is deactivated via XSHUT signal. */
71
  VL53L1X_LLD_STATE_ON  = 0x01, /**< Device is active according to XSHUT signal. */
72
} vl53l1x_lld_state_t;
46 73

  
47 74
/******************************************************************************/
48 75
/* MACROS                                                                     */
......
55 82
#ifdef __cplusplus
56 83
extern "C" {
57 84
#endif
58
  apalExitStatus_t hello_world(void);
59
  apalExitStatus_t vl53l1x_GPIO1_set(const VL53L1XDriver* const vlx, const gpio_lld_state_t state);
60

  
85
  apalExitStatus_t vl53l1x_lld_getState(VL53L1XDriver* vl53l1x, vl53l1x_lld_state_t* state);
86
  apalExitStatus_t vl53l1x_lld_init(VL53L1XDriver* vl53l1x);
87
  apalExitStatus_t vl53l1x_lld_reset(VL53L1XDriver* vl53l1x);
61 88
#ifdef __cplusplus
62 89
}
63 90
#endif
64 91

  
65

  
66 92
/******************************************************************************/
67 93
/* INLINE FUNCTIONS                                                           */
68 94
/******************************************************************************/
69 95

  
70

  
71

  
72 96
#endif /* AMIROLLD_VL53L1X_H */
97

  
98
/** @} */
drivers/VL53L1X/v1/alld_VL53L1X.mk
1 1
################################################################################
2 2
# AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous  #
3 3
# Mini Robot (AMiRo) platform.                                                 #
4
# Copyright (C) 2016..2019  Thomas Schöpping et al.                            #
4
# Copyright (C) 2016..2020  Thomas Schöpping et al.                            #
5 5
#                                                                              #
6 6
# This program is free software: you can redistribute it and/or modify         #
7 7
# it under the terms of the GNU General Public License as published by         #
......
28 28

  
29 29
# include paths
30 30
AMIROLLD_INC += $(AMIROLLD_ST_VL53L1X) \
31
				$(AMIROLLD_ST_VL53L1X)/api/core \
32
				$(AMIROLLD_ST_VL53L1X)/api/platform \
33

  
34
# $(info    AMIROLLD_INC is $(AMIROLLD_INC))
31
                $(AMIROLLD_ST_VL53L1X)/api/core \
32
                $(AMIROLLD_ST_VL53L1X)/api/platform
35 33

  
36 34
# C source files
37 35
AMIROLLD_CSRC += $(AMIROLLD_ST_VL53L1X)alld_VL53L1X.c \
38
				 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_api_calibration.c \
39
				 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_api_core.c \
40
				 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_api_debug.c \
41
				 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_api_preset_modes.c \
42
				 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_api_strings.c \
43
				 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_api.c \
44
				 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_core_support.c \
45
				 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_core.c \
46
				 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_error_strings.c \
47
				 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_register_funcs.c \
48
				 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_silicon_core.c \
49
				 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_wait.c \
36
                 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_api.c \
37
                 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_api_calibration.c \
38
                 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_api_core.c \
39
                 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_api_debug.c \
40
                 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_api_preset_modes.c \
41
                 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_api_strings.c \
42
                 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_core.c \
43
                 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_core_support.c \
44
                 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_error_strings.c \
45
                 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_register_funcs.c \
46
                 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_silicon_core.c \
47
                 $(AMIROLLD_ST_VL53L1X)api/core/vl53l1_wait.c
50 48

  
51
# $(info    AMIROLLD_CSRC is $(AMIROLLD_CSRC))
drivers/VL53L1X/v1/alld_VL53L1X_types.h
1
#ifndef AMIROLLD_VL53L1X_TYPES_H
2
#define AMIROLLD_VL53L1X_TYPES_H
3
#include <amiro-lld.h>
4

  
5
/**
6
 * @brief The VL53L1X driver struct
7
 */
8
typedef struct {
9
  apalI2CDriver_t* i2cd;
10
  apalI2Caddr_t addr;       /**< @brief The I2C Driver.     */
11
  const apalControlGpio_t* gpio1;
12
  const apalControlGpio_t* xshut;
13
} VL53L1XDriver;
14

  
15
#endif
drivers/VL53L1X/v1/api/core/vl53l1_wait.c
418 418
	uint32_t      timeout_ms)
419 419
{
420 420
	/**
421
	 * Polls the bit 0 of the FIRMWARE_SYSTEM_STATUS register to see if
421
	 * Polls the bit 0 of the FIRMWARE__SYSTEM_STATUS register to see if
422 422
	 * the firmware is ready.
423 423
	 */
424 424

  
drivers/VL53L1X/v1/api/platform/vl53l1_platform.c
104 104

  
105 105
// int _I2CWrite(VL53L1_DEV Dev, uint8_t *pdata, uint32_t count) {
106 106
//     int status = 0;
107
//    apalExitStatus_t status = apalI2CMasterTransmit(Dev.vl53l1x->i2cd, (apalI2Caddr_t)VL53L1X_LLD_I2C_ADDR_FIXED, txbuf, 1, rxbuf, 2, timeout);
108 107
//     return status;
109 108
// }
110 109

  
111 110
// int _I2CRead(VL53L1_DEV Dev, uint8_t *pdata, uint32_t count) {
112 111
//    int status = 0;
113
//    return status;
112
//    return Status;
114 113
// }
115 114

  
116
// TODO: Needs to be defined
117

  
118 115
VL53L1_Error VL53L1_WriteMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count) {
119 116
    VL53L1_Error Status = VL53L1_ERROR_NONE;
120

  
121 117
    return Status;
122 118
}
123 119

  
drivers/VL53L1X/v1/api/platform/vl53l1_platform_user_data.h
59 59
*
60 60
********************************************************************************
61 61
*
62
* Modified for use within AMiRo-LLD.
63
*
64
* AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous
65
* Mini Robot (AMiRo) platform.
66
* Copyright (C) 2016..2020  Thomas Schöpping et al.
67
*
68
********************************************************************************
69
*
62 70
*/
63 71

  
64 72
#ifndef _VL53L1_PLATFORM_USER_DATA_H_
65 73
#define _VL53L1_PLATFORM_USER_DATA_H_
66
// #include "stm32xxx_hal.h"
74

  
67 75
#include "vl53l1_def.h"
68
#include <alld_VL53L1X_types.h>
76
#include <periphAL.h>
77

  
69 78
#ifdef __cplusplus
70 79
extern "C"
71 80
{
72 81
#endif
73 82

  
83
/**
84
 * @brief VL53L1X interface related data structure.
85
 */
86
typedef struct {
87
  /**
88
   * @brief   Pointer to the associated I2C driver.
89
   */
90
  apalI2CDriver_t* i2cd;
91

  
92
  /**
93
   * @brief   Currently set I2C device address.
94
   */
95
  apalI2Caddr_t addr;
74 96

  
75
// typedef struct {
76
//     uint32_t dummy;
77
// } I2C_HandleTypeDef;
97
  /**
98
   * @brief   Pointer to the GPIO driver for the GPIO1 signal.
99
   */
100
  const apalControlGpio_t* gpio1;
78 101

  
79
typedef struct {
102
  /**
103
   * @brief   Pointer to the GPIO driver for the XSHUT signal.
104
   */
105
  const apalControlGpio_t* xshut;
106
} VL53L1_IfData_t;
80 107

  
81
	VL53L1_DevData_t   Data;
108
/**
109
 * @brief   VL53L1X device driver structure as to be used by the ST API.
110
 */
111
typedef struct {
112
  /**
113
   * @brief   Device data as specified by the ST API.
114
   */
115
  VL53L1_DevData_t   Data;
82 116

  
83
	// uint8_t   I2cDevAddr;
84
	// uint8_t   comms_type;
85
	// uint16_t  comms_speed_khz;
86
	// uint32_t  new_data_ready_poll_duration_ms;
87
	// I2C_HandleTypeDef *I2cHandle;
88
	VL53L1XDriver vl53l1x;
117
  /**
118
   * @brief   Interface data.
119
   */
120
  VL53L1_IfData_t     Interface;
89 121

  
90 122
} VL53L1_Dev_t;
91 123

  
124
/**
125
 * @brief   Typedef as it is used by the ST API.
126
 */
92 127
typedef VL53L1_Dev_t *VL53L1_DEV;
93 128

  
129
/**
130
 * @brief   Typedef matching the PeriphAL conventions.
131
 */
132
typedef VL53L1_Dev_t VL53L1XDriver;
133

  
94 134
#define VL53L1DevDataGet(Dev, field) (Dev->Data.field)
95 135
#define VL53L1DevDataSet(Dev, field, VL53L1_PRM_00005) ((Dev->Data.field) = (VL53L1_PRM_00005))
96 136
#define VL53L1DevStructGetLLDriverHandle(Dev) (&Dev->Data.LLData)
97 137
#define VL53L1DevStructGetLLResultsHandle(Dev) (&Dev->Data.llresults)
138

  
98 139
#ifdef __cplusplus
99 140
}
100 141
#endif
101
#endif
142

  
143
#endif /* _VL53L1_PLATFORM_USER_DATA_H_ */
drivers/VL53L1X/v1/api/platform/vl53l1_platform_user_defines.h
58 58
*
59 59
********************************************************************************
60 60
*
61
* Modified for use within AMiRo-LLD.
62
*
63
* AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous
64
* Mini Robot (AMiRo) platform.
65
* Copyright (C) 2016..2020  Thomas Schöpping et al.
66
*
67
********************************************************************************
68
*
61 69
*/
62 70

  
63 71

  
64 72
#ifndef _VL53L1_PLATFORM_USER_DEFINES_H_
65 73
#define _VL53L1_PLATFORM_USER_DEFINES_H_
66 74

  
75
#include <amiro-lld.h>
76

  
67 77
#ifdef __cplusplus
68 78
extern "C"
69 79
{
......
75 85
 * @brief  All end user OS/platform/application definitions
76 86
 */
77 87

  
88
/**
89
 * @brief   Flag to set I2C signal level to 2.8V instead of 1.8V.
90
 */
91
#if (defined(VL53L1X_LLD_I2C_2V8) && (VL53L1X_LLD_I2C_2V8 == true)) || defined(__DOXYGEN__)
92
# define USE_I2C_2V8
93
#endif
78 94

  
79 95
/**
80 96
 * @def do_division_u
......
125 141
}
126 142
#endif
127 143

  
128
#endif // _VL53L1_PLATFORM_USER_DEFINES_H_
144
#endif /* _VL53L1_PLATFORM_USER_DEFINES_H_ */
periphAL.h
127 127
 */
128 128
#define apalDbgAssert(c) apalDbgAssertMsg(c, "%s(%u): apalDbgAssert failed", __FILE__, __LINE__)
129 129

  
130
#else /* (AMIROLLD_CFG_DBG == true) */
131

  
132
#define apalDbgAssertMsg(c, fmt, ...)
133

  
134
#define apalDbgPrintf(fmt, ...)                 0
135

  
136
#define apalDbgAssert(c)
137

  
130 138
#endif /* (AMIROLLD_CFG_DBG == true) */
131 139

  
132 140
/*============================================================================*/
......
161 169
  void apalSleep(apalTime_t us);
162 170
#endif
163 171

  
172
#if !defined(apalGetTime) || defined(__DOXYGEN__)
173
  /**
174
   * @brief Retrieve current system time in microseconds.
175
   * @details Return value may differ from true system time due to overflows.
176
   *
177
   * @return  Current system time.
178
   */
179
  apalTime_t apalGetTime(void);
180
#endif
181

  
164 182
#ifdef __cplusplus
165 183
}
166 184
#endif

Also available in: Unified diff