Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Check_VL6180XA1_ToF
Fork of X_NUCLEO_6180XA1 by
Components/VL6180X/vl6180x_class.h
- Committer:
- gallonm
- Date:
- 2015-09-17
- Revision:
- 4:a5abf7757947
- Parent:
- 3:454541a079f4
- Child:
- 7:2dc81120c917
File content as of revision 4:a5abf7757947:
/**
******************************************************************************
* @file vl6180x_class.h
* @author AST / EST
* @version V0.0.1
* @date 14-April-2015
* @brief Header file for component VL6180X
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. 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.
* 3. 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 AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 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 __VL6180X_CLASS_H
#define __VL6180X_CLASS_H
/* Includes ------------------------------------------------------------------*/
#include "RangeSensor.h"
#include "LightSensor.h"
#include "DevI2C.h" //temporaneo fino alla creazione della classe x_nucleo_6180xa1
#include "vl6180x_api.h"
#include "vl6180x_cfg.h"
#include "vl6180x_def.h"
#include "vl6180x_types.h"
#include "vl6180x_platform.h"
#include "vl6180x_appcfg.h"
/** default device address */
#define DEFAULT_DEVICE_ADDRESS 0x29
/** default value ECE factor Molecular */
#define DEF_ECE_FACTOR_M 85
/** default value ECE factor Denominator */
#define DEF_ECE_FACTOR_D 100
/** default value ALS integration time */
#define DEF_INT_PEFRIOD 100
/** default value ALS gain */
#define DEF_ALS_GAIN 1
/** default value ALS scaler */
#define DEF_ALS_SCALER 1
/** default value for DMAX Enbale */
#define DEF_DMAX_ENABLE 1
/** default ambient tuning factor %x1000 */
#define DEF_AMBIENT_TUNING 80
/*
typedef struct
{
struct VL6180xDevData_t Data;
uint8_t I2cAddr;
uint8_t DevID;
unsigned Present;
unsigned Ready;
}MyVL6180xDev_t;
*/
/* Classes -------------------------------------------------------------------*/
/** Class representing a VL6180X sensor component
*/
class VL6180X : public RangeSensor, public LightSensor {
public:
/** Constructor
* @param[in] i2c device I2C to be used for communication
* @param[in] device address, 0x29 by default
*/
VL6180X(DevI2C &i2c, uint8_t DevAddr=DEFAULT_DEVICE_ADDRESS) : RangeSensor(), LightSensor(), dev_i2c(i2c)
{
MyDeviceAddress=DevAddr;
RangeLight_id=0;
//MyDevice.I2cAddr=DevAddr;
//MyDevice.DeviID=0;
//MyDevice.Present=0;
//MyDevice.Ready=0;
//oppure MyVL6180xDev_t MyDevice={DevAddr, 0, 0, 0};
}
/** Destructor
*/
/*virtual ~VL6180X()
{
// delete[] memory allocated
VL6180x_SetupGPIOx(MyDevice, 0, 0, 0);
} */
// funzione che setta il paremetro DevID: SetDevID(int n)
// funzione che setta il parametro Present: SetPresent(int n)
// funzione che setta il parametro Ready: SetReady(int n)
// funzione che modifica lo slave address: SetI2CAddress(VL6180xDev_t MyDevice, uint8_t NewAddress))
/*** Interface Methods ***/
// nel momento in cui creo la classe x_nucleo_6180xa1, all'interno definisco un oggetto VL6180xDev_t MyDevice
// definisco una funzione Init() che chiama a sua volta la seguente funzione Init() e gli passo MyDevice
/*virtual*/ int Init() //par:void *init_struct
{
return VL6180x_InitData(MyDevice); // a questa funzione devo passare il parametro di Init()
}
// nel momento in cui creo la classe x_nucleo_6180xa1, all'interno definisco un oggetto uint_t *RangeLight_id
// definisco una funzione ReadID() che chiama a sua volta la seguente funzione ReadID() e gli passo RangeLight_id
/*virtual*/ int ReadID() //par:uint8_t *rl_id
{
return VL6180X_ReadID(&RangeLight_id); // a questa funzione devo passare il parametro di ReadID()
}
/*
virtual int GetRange(int *piData) {
return VL6180X_GetRange(piData);
}
virtual int GetLight(int *piData) {
return VL6180X_GetLight(piData);
}
*/
/* Initialization functions */
int VL6180x_InitData(VL6180xDev_t dev);
/*static*/ int _DMax_InitData(VL6180xDev_t dev);
void _DMax_OneTimeInit(VL6180xDev_t dev);
/*static*/ uint32_t _DMax_RawValueAtRateKCps(VL6180xDev_t dev, int32_t rate);
uint32_t VL6180x_SqrtUint32(uint32_t num);
/* IO read funcitons */
int VL6180X_ReadID(uint8_t *rl_id);
int VL6180X_IO_Read(uint8_t *pBuffer, uint8_t RegisterAddress, uint16_t NumByteToRead);
/* Write and read functions from I2C */
int VL6180x_WrByte(VL6180xDev_t dev, uint16_t index, uint8_t data);
int VL6180x_WrWord(VL6180xDev_t dev, uint16_t index, uint16_t data);
int VL6180x_WrDWord(VL6180xDev_t dev, uint16_t index, uint32_t data);
int VL6180x_RdByte(VL6180xDev_t dev, uint16_t index, uint8_t *data);
int VL6180x_RdWord(VL6180xDev_t dev, uint16_t index, uint16_t *data);
int VL6180x_RdDWord(VL6180xDev_t dev, uint16_t index, uint32_t *data);
int VL6180x_I2CWrite(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToWrite);
int VL6180x_I2CRead(uint8_t DeviceAddr, uint16_t RegisterAddr, uint8_t *pBuffer, uint16_t NumByteToRead);
private:
/*** Methods ***/
/*** Instance Variables ***/
/* IO Device */
//temporaneo
DevI2C &dev_i2c; // creo questa variabile in x_nucleo_6180xa1.h allo stesso modo e poi passo al costruttore del MyDevice il suo indirizzo
//MyVL6180xDev_t MyDevice; in sostituzione di VL6180xDev_t sotto
/* VL6180X Device */
uint8_t MyDeviceAddress;
//temporanei
VL6180xDev_t MyDevice; // creo questa variabile in x_nucleo_6180xa1.h allo stesso modo e poi passo alla funzione Init()
uint8_t RangeLight_id; // creo questa variabile in x_nucleo_6180xa1.h allo stesso modo e poi passo alla funzione ReadID() il suo indirizzo
};
#endif // __VL6180X_CLASS_H
