---vl6180dr
This commit is contained in:
92
main_prog/vl6180/Target/vl6180_appcfg.h
Normal file
92
main_prog/vl6180/Target/vl6180_appcfg.h
Normal file
@@ -0,0 +1,92 @@
|
||||
|
||||
/*******************************************************************************
|
||||
Copyright © 2014, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* vl6180_appcfg.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef VL6180_APPCFG_H_
|
||||
#define VL6180_APPCFG_H_
|
||||
|
||||
|
||||
/**
|
||||
* @def VL6180_SINGLE_DEVICE_DRIVER
|
||||
* @brief enable lightweight single vl6180 device driver
|
||||
*
|
||||
* value 1 => single device capable
|
||||
* Configure optimized APi for single device driver with static data and minimal use of ref pointer \n
|
||||
* limited to single device driver or application in non multi thread/core environment \n
|
||||
*
|
||||
* value 0 => multiple device capable user must review "device" structure and type in porting files
|
||||
* @ingroup Configuration
|
||||
*/
|
||||
#define VL6180_SINGLE_DEVICE_DRIVER 1
|
||||
|
||||
|
||||
/**
|
||||
* @def VL6180_RANGE_STATUS_ERRSTRING
|
||||
* @brief when define include range status Error string and related
|
||||
*
|
||||
* The string table lookup require some space in read only area
|
||||
* @ingroup Configuration
|
||||
*/
|
||||
#define VL6180_RANGE_STATUS_ERRSTRING 1
|
||||
|
||||
/**
|
||||
* @def VL6180_SAFE_POLLING_ENTER
|
||||
*
|
||||
* @brief Ensure safe polling method when set
|
||||
*
|
||||
* Polling for a condition can be hazardous and result in infinite looping if any previous interrupt status
|
||||
* condition is not cleared. \n
|
||||
* Setting these flags enforce error clearing on start of polling method to avoid it.
|
||||
* the drawback are : \n
|
||||
* @li extra use-less i2c bus usage and traffic
|
||||
* @li potentially slower measure rate.
|
||||
* If application ensure interrupt get clear on mode or interrupt configuration change
|
||||
* then keep option disabled. \n
|
||||
* To be safe set these option to 1
|
||||
* @ingroup Configuration
|
||||
*/
|
||||
#define VL6180_SAFE_POLLING_ENTER 0
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable function start/end logging
|
||||
*
|
||||
* requires porting @a #LOG_FUNCTION_START @a #LOG_FUNCTION_END @a #LOG_FUNCTION_END_FMT
|
||||
* @ingroup Configuration
|
||||
*/
|
||||
#define VL6180_LOG_ENABLE 0
|
||||
|
||||
|
||||
|
||||
#endif /* VL6180_APPCFG_H_ */
|
||||
241
main_prog/vl6180/Target/vl6180_i2c.c
Normal file
241
main_prog/vl6180/Target/vl6180_i2c.c
Normal file
@@ -0,0 +1,241 @@
|
||||
|
||||
/*******************************************************************************
|
||||
Copyright © 2019, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* @file vl6180_i2c.c
|
||||
*
|
||||
* Copyright (C) 2019 ST MicroElectronics
|
||||
*
|
||||
* provide variable word size byte/Word/dword VL6180 register access via i2c
|
||||
*
|
||||
*/
|
||||
#include "vl6180_i2c.h"
|
||||
|
||||
#ifndef I2C_BUFFER_CONFIG
|
||||
#error "I2C_BUFFER_CONFIG not defined"
|
||||
/* TODO you must define value for I2C_BUFFER_CONFIG in configuration or platform h */
|
||||
#endif
|
||||
|
||||
|
||||
#if I2C_BUFFER_CONFIG == 0
|
||||
/* GLOBAL config buffer */
|
||||
uint8_t i2c_global_buffer[VL6180_MAX_I2C_XFER_SIZE];
|
||||
|
||||
#define DECL_I2C_BUFFER
|
||||
#define VL6180_GetI2cBuffer(dev, n_byte) i2c_global_buffer
|
||||
|
||||
#elif I2C_BUFFER_CONFIG == 1
|
||||
/* ON STACK */
|
||||
#define DECL_I2C_BUFFER uint8_t LocBuffer[VL6180_MAX_I2C_XFER_SIZE];
|
||||
#define VL6180_GetI2cBuffer(dev, n_byte) LocBuffer
|
||||
#elif I2C_BUFFER_CONFIG == 2
|
||||
/* user define buffer type declare DECL_I2C_BUFFER as access via VL6180_GetI2cBuffer */
|
||||
#define DECL_I2C_BUFFER
|
||||
#else
|
||||
#error "invalid I2C_BUFFER_CONFIG "
|
||||
#endif
|
||||
|
||||
|
||||
int VL6180_WrByte(VL6180Dev_t dev, uint16_t index, uint8_t data){
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
DECL_I2C_BUFFER
|
||||
VL6180_I2C_USER_VAR
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
|
||||
buffer=VL6180_GetI2cBuffer(dev,3);
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
buffer[2]=data;
|
||||
|
||||
status=VL6180_I2CWrite(dev, buffer,(uint8_t)3);
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
return status;
|
||||
}
|
||||
|
||||
int VL6180_WrWord(VL6180Dev_t dev, uint16_t index, uint16_t data){
|
||||
int status;
|
||||
DECL_I2C_BUFFER
|
||||
uint8_t *buffer;
|
||||
VL6180_I2C_USER_VAR
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
|
||||
buffer=VL6180_GetI2cBuffer(dev,4);
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
buffer[2]=data>>8;
|
||||
buffer[3]=data&0xFF;
|
||||
|
||||
status=VL6180_I2CWrite(dev, buffer,(uint8_t)4);
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
return status;
|
||||
}
|
||||
|
||||
int VL6180_WrDWord(VL6180Dev_t dev, uint16_t index, uint32_t data){
|
||||
VL6180_I2C_USER_VAR
|
||||
DECL_I2C_BUFFER
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
buffer=VL6180_GetI2cBuffer(dev,6);
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
buffer[2]=data>>24;
|
||||
buffer[3]=(data>>16)&0xFF;
|
||||
buffer[4]=(data>>8)&0xFF;;
|
||||
buffer[5]=data&0xFF;
|
||||
status=VL6180_I2CWrite(dev, buffer,(uint8_t)6);
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int VL6180_UpdateByte(VL6180Dev_t dev, uint16_t index, uint8_t AndData, uint8_t OrData){
|
||||
VL6180_I2C_USER_VAR
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
DECL_I2C_BUFFER
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
|
||||
buffer=VL6180_GetI2cBuffer(dev,3);
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
|
||||
status=VL6180_I2CWrite(dev, (uint8_t *)buffer,(uint8_t)2);
|
||||
if( !status ){
|
||||
/* read data direct onto buffer */
|
||||
status=VL6180_I2CRead(dev, &buffer[2],1);
|
||||
if( !status ){
|
||||
buffer[2]=(buffer[2]&AndData)|OrData;
|
||||
status=VL6180_I2CWrite(dev, buffer, (uint8_t)3);
|
||||
}
|
||||
}
|
||||
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int VL6180_RdByte(VL6180Dev_t dev, uint16_t index, uint8_t *data){
|
||||
VL6180_I2C_USER_VAR
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
DECL_I2C_BUFFER
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
|
||||
buffer=VL6180_GetI2cBuffer(dev,2);
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
|
||||
status=VL6180_I2CWrite(dev, buffer, (uint8_t)2);
|
||||
if( !status ){
|
||||
status=VL6180_I2CRead(dev, buffer,1);
|
||||
if( !status ){
|
||||
*data=buffer[0];
|
||||
}
|
||||
}
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int VL6180_RdWord(VL6180Dev_t dev, uint16_t index, uint16_t *data){
|
||||
VL6180_I2C_USER_VAR
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
DECL_I2C_BUFFER
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
|
||||
buffer=VL6180_GetI2cBuffer(dev,2);
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
|
||||
status=VL6180_I2CWrite(dev, buffer, (uint8_t)2);
|
||||
if( !status){
|
||||
status=VL6180_I2CRead(dev, buffer,2);
|
||||
if( !status ){
|
||||
/* VL6180 register are Big endian if cpu is be direct read direct into *data is possible */
|
||||
*data=((uint16_t)buffer[0]<<8)|(uint16_t)buffer[1];
|
||||
}
|
||||
}
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
return status;
|
||||
}
|
||||
|
||||
int VL6180_RdDWord(VL6180Dev_t dev, uint16_t index, uint32_t *data){
|
||||
VL6180_I2C_USER_VAR
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
DECL_I2C_BUFFER
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
buffer=VL6180_GetI2cBuffer(dev,4);
|
||||
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
|
||||
status=VL6180_I2CWrite(dev, (uint8_t *) buffer, (uint8_t)2);
|
||||
if( !status ){
|
||||
status=VL6180_I2CRead(dev, buffer,4);
|
||||
if( !status ){
|
||||
/* VL6180 register are Big endian if cpu is be direct read direct into data is possible */
|
||||
*data=((uint32_t)buffer[0]<<24)|((uint32_t)buffer[1]<<16)|((uint32_t)buffer[2]<<8)|((uint32_t)buffer[3]);
|
||||
}
|
||||
}
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
int VL6180_RdMulti(VL6180Dev_t dev, uint16_t index, uint8_t *data, int nData){
|
||||
VL6180_I2C_USER_VAR
|
||||
int status;
|
||||
uint8_t *buffer;
|
||||
DECL_I2C_BUFFER
|
||||
|
||||
VL6180_GetI2CAccess(dev);
|
||||
buffer=VL6180_GetI2cBuffer(dev,2);
|
||||
|
||||
buffer[0]=index>>8;
|
||||
buffer[1]=index&0xFF;
|
||||
|
||||
status=VL6180_I2CWrite(dev, (uint8_t *) buffer, (uint8_t)2);
|
||||
if( !status ){
|
||||
status=VL6180_I2CRead(dev, data, nData);
|
||||
}
|
||||
VL6180_DoneI2CAcces(dev);
|
||||
return status;
|
||||
}
|
||||
166
main_prog/vl6180/Target/vl6180_i2c.h
Normal file
166
main_prog/vl6180/Target/vl6180_i2c.h
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* $Date: 2015-01-08 14:30:24 +0100 (Thu, 08 Jan 2015) $
|
||||
* $Revision: 2039 $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file vl6180_i2c.h
|
||||
*
|
||||
* @brief CCI interface to "raw i2c" translation layer
|
||||
*/
|
||||
|
||||
#ifndef VL6180_I2C_H_
|
||||
#define VL6180_I2C_H_
|
||||
|
||||
#include "vl6180_platform.h"
|
||||
|
||||
/**
|
||||
* @defgroup cci_i2c CCI to RAW I2C translation layer
|
||||
*
|
||||
* This optional tranlation layer is implemented in __platform/cci-i2c__ directory. If user uses this translation layer for his platform, only @a VL6180_I2CRead() and
|
||||
* @a VL6180_I2CWrite() functions need to be implemented. Also, some code adaption (via macro) is required for multi-threading and for multiple device support.
|
||||
*
|
||||
* File vl6180_i2c.c implements device register access via raw i2c access. If the targeted application and platform has no multi-thread, no multi-cpu and uses single
|
||||
* device, then nothing else is required than the 2 mandatory function : @a VL6180_I2CRead() and @a VL6180_I2CWrite().\n
|
||||
* In other cases, review and customize @a VL6180_GetI2CAccess() and @a VL6180_DoneI2CAccess() functions as well as @a #VL6180_I2C_USER_VAR macro. This should be enough
|
||||
* to conform to a wide range of platform OS and application requirements .\n
|
||||
*
|
||||
* If your configured i2c for per device buffer via @a #I2C_BUFFER_CONFIG == 2, you must implement @a VL6180_GetI2cBuffer()
|
||||
*
|
||||
* __I2C Port sample__ \n
|
||||
* A __linux kernel__ port need a "long flags" var for its spin_lock in all functions. the following code example declares a spin lock "lock" in the custom device structure. \n
|
||||
* @code
|
||||
struct MyVL6180Dev_t {
|
||||
struct VL6180DevData_t StData;
|
||||
...
|
||||
spinlock_t i2c_lock;
|
||||
};
|
||||
typedef struct MyVL6180Dev_t *VL6180Dev_t;
|
||||
|
||||
#define VL6180_I2C_USER_VAR unsigned long flags;
|
||||
#define GetI2CAccess(dev) spin_lock_irqsave(dev->i2c_lock, flags)
|
||||
#define DoneI2CAccess(dev) spin_unlock_irqrestore(dev->i2c_lock,flags)
|
||||
@endcode
|
||||
|
||||
* __POSIX pthread__ application porting could be as follows :\n
|
||||
* @code
|
||||
struct MyVL6180Dev_t {
|
||||
struct VL6180DevData_t StData;
|
||||
...
|
||||
pthread_mutex_t *lock;
|
||||
};
|
||||
typedef struct MyVL6180Dev_t *VL6180Dev_t;
|
||||
|
||||
#define VL6180_I2C_USER_VAR //no need
|
||||
#define VL6180_GetI2CAccess(dev) pthread_mutex_lock(dev->lock)
|
||||
#define VL6180_DoneI2CAcces(dev) pthread_mutex_unlock(dev->lock)
|
||||
* @endcode
|
||||
*/
|
||||
|
||||
/**
|
||||
* @def I2C_BUFFER_CONFIG
|
||||
*
|
||||
* @brief Configure device register I2C access
|
||||
*
|
||||
* @li 0 : one GLOBAL buffer \n
|
||||
* Use one global buffer of MAX_I2C_XFER_SIZE byte in data space \n
|
||||
* This solution is not multi-device compliant nor multi-thread cpu safe \n
|
||||
* It can be the best option for small 8/16 bit MCU without stack and limited ram (STM8s, 80C51 ...)
|
||||
*
|
||||
* @li 1 : ON_STACK/local \n
|
||||
* Use local variable (on stack) buffer \n
|
||||
* This solution is multi-thread with use of i2c resource lock or mutex see @a VL6180_GetI2CAccess() \n
|
||||
*
|
||||
* @li 2 : User defined \n
|
||||
* Per device potentially dynamic allocated. Requires @a VL6180_GetI2cBuffer() to be implemented.
|
||||
* @ingroup Configuration
|
||||
*/
|
||||
#define I2C_BUFFER_CONFIG 1
|
||||
|
||||
/**
|
||||
* @brief Write data buffer to VL6180 device via i2c
|
||||
* @param dev The device to write to
|
||||
* @param buff The data buffer
|
||||
* @param len The length of the transaction in byte
|
||||
* @return 0 on success
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
int VL6180_I2CWrite(VL6180Dev_t dev, uint8_t *buff, uint8_t len);
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Read data buffer from VL6180 device via i2c
|
||||
* @param dev The device to read from
|
||||
* @param buff The data buffer to fill
|
||||
* @param len The length of the transaction in byte
|
||||
* @return 0 on success
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
int VL6180_I2CRead(VL6180Dev_t dev, uint8_t *buff, uint8_t len);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Declare any required variables used by i2c lock (@a VL6180_DoneI2CAccess() and @a VL6180_GetI2CAccess())
|
||||
* and buffer access : @a VL6180_GetI2cBuffer()
|
||||
*
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
#define VL6180_I2C_USER_VAR
|
||||
|
||||
/**
|
||||
* @brief Acquire lock or mutex for access to i2c data buffer and bus.\n
|
||||
* Delete the default VL6180_GetI2CAccess 'do-nothing' macro below if you decide to implement this function.
|
||||
*
|
||||
* This function is used to perform i2c bus level and multiple access locking required for multi thread/proccess system.\n
|
||||
* Multiple access (read and update) will lock once and do multiple basic i2c rd/wr to complete the overall transfer.\n
|
||||
* When no locking is needed this can be a void macro.\n
|
||||
*
|
||||
* @param dev the device
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
void VL6180_GetI2CAccess(VL6180Dev_t dev);
|
||||
|
||||
/**
|
||||
* @def VL6180_GetI2CAccess
|
||||
* @brief Default 'do-nothing' macro for @a VL6180_GetI2CAccess(). Delete if used.
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
#define VL6180_GetI2CAccess(dev) (void)0 /* TODO delete if function used */
|
||||
|
||||
/**
|
||||
* @brief Release acquired lock or mutex for i2c access.\n
|
||||
* Delete default VL6180_DoneI2CAccess 'do-nothing' macro below if implementing that function.
|
||||
*
|
||||
* This function is used to release the acquired lock.
|
||||
* @param dev The device
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
void VL6180_DoneI2CAccess(VL6180Dev_t dev);
|
||||
|
||||
/** @def VL6180_DoneI2CAcces
|
||||
* @brief Default 'do-nothing' macro for @a VL6180_DoneI2CAcces(). Delete if used.
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
#define VL6180_DoneI2CAcces(dev) (void)0 /*TODO delete if function used */
|
||||
|
||||
/**
|
||||
* @brief Provided data buffer for i2c access for at least n_byte.
|
||||
*
|
||||
* You must implement it when i2c @a #I2C_BUFFER_CONFIG is set to 2 (User defined).\n
|
||||
* This is used used in the context of #VL6180_I2C_USER_VAR
|
||||
*
|
||||
* @param dev The device
|
||||
* @param n_byte Minimal number of byte
|
||||
* @return The buffer (cannot fail return not checked)
|
||||
* @ingroup cci_i2c
|
||||
*/
|
||||
uint8_t *VL6180_GetI2cBuffer(VL6180Dev_t dev, int n_byte);
|
||||
#if I2C_BUFFER_CONFIG == 2
|
||||
#error /* TODO add your macro of code here for VL6180_GetI2cBuffer */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* VL6180_I2C_H_ */
|
||||
115
main_prog/vl6180/Target/vl6180_platform.h
Normal file
115
main_prog/vl6180/Target/vl6180_platform.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2019, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* vl6180_platform.h STM32 Nucelo F401 single device using generic cci-i2c
|
||||
* trace via swo port some GnuArm eclipse toolset */
|
||||
|
||||
#ifndef VL6180_PLATFORM
|
||||
#define VL6180_PLATFORM
|
||||
|
||||
|
||||
#include "vl6180_appcfg.h"
|
||||
#include "vl6180_def.h"
|
||||
|
||||
|
||||
|
||||
#define VL6180_DEV_DATA_ATTR
|
||||
|
||||
#define ROMABLE_DATA
|
||||
/* #define ROMABLE_DATA __attribute__ ((section ("user_rom"))) */
|
||||
|
||||
|
||||
|
||||
#if VL6180_LOG_ENABLE
|
||||
/* dot not include non ansi here trace was a case :( */
|
||||
#ifdef TRACE
|
||||
#include "diag/trace.h"
|
||||
extern volatile uint32_t g_TickCnt;
|
||||
#define LOG_GET_TIME() g_TickCnt
|
||||
#else
|
||||
/* these is nto stm32 vl6180 GNuArm eclpse build*/
|
||||
#define trace_printf(...) (void)0
|
||||
#define LOG_GET_TIME() (int)0 /* add your code here expect to be an integer native (%d) type value */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define LOG_FUNCTION_START(fmt, ... ) \
|
||||
trace_printf("beg %s start @%d\t" fmt "\n", __func__, LOG_GET_TIME(), ##__VA_ARGS__)
|
||||
|
||||
#define LOG_FUNCTION_END(status)\
|
||||
trace_printf("end %s @%d %d\n", __func__, LOG_GET_TIME(), (int)status)
|
||||
|
||||
#define LOG_FUNCTION_END_FMT(status, fmt, ... )\
|
||||
trace_printf("End %s @%d %d\t"fmt"\n" , __func__, LOG_GET_TIME(), (int)status, ##__VA_ARGS__)
|
||||
|
||||
#define VL6180_ErrLog(msg, ... )\
|
||||
do{\
|
||||
trace_printf("ERR in %s line %d\n" msg, __func__, __LINE__, ##__VA_ARGS__);\
|
||||
}while(0)
|
||||
|
||||
#else /* VL6180_LOG_ENABLE no logging */
|
||||
void OnErrLog(void);
|
||||
#define LOG_FUNCTION_START(...) (void)0
|
||||
#define LOG_FUNCTION_END(...) (void)0
|
||||
#define LOG_FUNCTION_END_FMT(...) (void)0
|
||||
#define VL6180_ErrLog(... ) OnErrLog()
|
||||
#endif
|
||||
|
||||
|
||||
#if VL6180_SINGLE_DEVICE_DRIVER
|
||||
typedef uint8_t VL6180Dev_t;
|
||||
|
||||
#else /* VL6180_SINGLE_DEVICE_DRIVER */
|
||||
|
||||
struct MyVL6180Dev_t {
|
||||
struct VL6180DevData_t Data;
|
||||
#if I2C_BUFFER_CONFIG == 2
|
||||
uint8_t i2c_buffer[VL6180_MAX_I2C_XFER_SIZE];
|
||||
#define VL6180_GetI2cBuffer(dev, n) ((dev)->i2c_buffer)
|
||||
#endif
|
||||
};
|
||||
typedef struct MyVL6180Dev_t *VL6180Dev_t;
|
||||
|
||||
#define VL6180DevDataGet(dev, field) (dev->Data.field)
|
||||
#define VL6180DevDataSet(dev, field, data) (dev->Data.field)=(data)
|
||||
|
||||
#endif /* #else VL6180_SINGLE_DEVICE_DRIVER */
|
||||
|
||||
void VL6180_PollDelay(VL6180Dev_t dev);
|
||||
|
||||
void DISP_ExecLoopBody(void);
|
||||
#define VL6180_PollDelay(dev) DISP_ExecLoopBody();
|
||||
|
||||
|
||||
#endif /* VL6180_PLATFORM */
|
||||
|
||||
|
||||
|
||||
62
main_prog/vl6180/Target/vl6180_types.h
Normal file
62
main_prog/vl6180/Target/vl6180_types.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2014, STMicroelectronics International N.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of STMicroelectronics nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef VL6180_TYPES_H_
|
||||
#define VL6180_TYPES_H_
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h> /* these is for NULL */
|
||||
|
||||
#ifndef NULL
|
||||
#error "review NULL definition or add required include "
|
||||
#endif
|
||||
|
||||
#if !defined(STDINT_H) && !defined(_GCC_STDINT_H) && !defined(__STDINT_DECLS) && !defined(_STDINT) && !defined(_STDINT_H)
|
||||
|
||||
#pragma message("Please review type definition of STDINT define for your platform and add to list above ")
|
||||
|
||||
/*
|
||||
* target platform do not provide stdint or use a different #define than above
|
||||
* to avoid seeing the message below addapt the #define list above or implement
|
||||
* all type and delete these pragma
|
||||
*/
|
||||
|
||||
typedef unsigned int uint32_t;
|
||||
typedef int int32_t;
|
||||
|
||||
typedef unsigned short uint16_t;
|
||||
typedef short int16_t;
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
|
||||
typedef signed char int8_t;
|
||||
|
||||
#endif /* _STDINT_H */
|
||||
|
||||
#endif /* VL6180_TYPES_H_ */
|
||||
Reference in New Issue
Block a user