The VL53L1CB proximity sensor, based on ST’s FlightSense™, Time-of-Flight technology.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   VL53L1CB_noshield_1sensor_polls_auton VL53L1CB_noshield_1sensor_interrupt_auton X_NUCLEO_53L1A2

Based on VL53L1 library, this is a library for the VL53L1CB ToF chip.

Committer:
lugandc
Date:
Wed Jul 21 17:06:38 2021 +0200
Revision:
18:0696efe39d08
Parent:
3:bb32dc22b2f8
Cleanup i2c functions, removed all bad references to L1X
Cleanup VL53L1CB class:
- i2c device object is passed in a consistent way in MyDevice structure
- removed useless functions
Updated VL53L1CB component driver with bare driver release 6.6.7 content

Who changed what in which revision?

UserRevisionLine numberNew contents of line
charlesmn 0:3ac96e360672 1 /* Define to prevent from recursive inclusion --------------------------------*/
charlesmn 0:3ac96e360672 2 #ifndef __DEV_ToF_I2C_H
charlesmn 0:3ac96e360672 3 #define __DEV_ToF_I2C_H
charlesmn 0:3ac96e360672 4
charlesmn 0:3ac96e360672 5 /* Includes ------------------------------------------------------------------*/
charlesmn 0:3ac96e360672 6
charlesmn 0:3ac96e360672 7 #include "mbed.h"
charlesmn 0:3ac96e360672 8
charlesmn 0:3ac96e360672 9 #include "pinmap.h"
charlesmn 0:3ac96e360672 10
charlesmn 0:3ac96e360672 11 //Class replacing DevI2C class as it was not implementing a 16bit address registers
charlesmn 0:3ac96e360672 12 class ToF_DevI2C : public I2C
charlesmn 0:3ac96e360672 13 {
charlesmn 0:3ac96e360672 14 public:
charlesmn 0:3ac96e360672 15 /** Create a DevI2C Master interface, connected to the specified pins
charlesmn 0:3ac96e360672 16 *
charlesmn 0:3ac96e360672 17 * @param sda I2C data line pin
charlesmn 0:3ac96e360672 18 * @param scl I2C clock line pin
charlesmn 0:3ac96e360672 19 */
charlesmn 0:3ac96e360672 20 ToF_DevI2C(PinName sda, PinName scl) : I2C(sda, scl) { printf ("hello\n");}
charlesmn 0:3ac96e360672 21
charlesmn 0:3ac96e360672 22 /**
charlesmn 0:3ac96e360672 23 * @brief Writes a buffer towards the I2C peripheral device.
charlesmn 0:3ac96e360672 24 * @param pBuffer pointer to the byte-array data to send
charlesmn 0:3ac96e360672 25 * @param DeviceAddr specifies the peripheral device slave address.
charlesmn 0:3ac96e360672 26 * @param RegisterAddr specifies the internal address register
charlesmn 0:3ac96e360672 27 * where to start writing to (must be correctly masked).
charlesmn 0:3ac96e360672 28 * @param NumByteToWrite number of bytes to be written.
charlesmn 0:3ac96e360672 29 * @retval 0 if ok,
charlesmn 0:3ac96e360672 30 * @retval -1 if an I2C error has occured, or
charlesmn 0:3ac96e360672 31 * @retval -2 on temporary buffer overflow (i.e. NumByteToWrite was too high)
charlesmn 0:3ac96e360672 32 * @note On some devices if NumByteToWrite is greater
charlesmn 0:3ac96e360672 33 * than one, the RegisterAddr must be masked correctly!
charlesmn 0:3ac96e360672 34 */
lugandc 18:0696efe39d08 35 int ToF_i2c_write(uint8_t* pBuffer, uint8_t DeviceAddr, uint16_t RegisterAddr,
charlesmn 0:3ac96e360672 36 uint16_t NumByteToWrite) {
charlesmn 0:3ac96e360672 37 int ret;
charlesmn 0:3ac96e360672 38 uint8_t tmp[TEMP_BUF_SIZE];
charlesmn 0:3ac96e360672 39
charlesmn 0:3ac96e360672 40 if(NumByteToWrite >= TEMP_BUF_SIZE) return -2;
charlesmn 0:3ac96e360672 41
charlesmn 0:3ac96e360672 42 // First, send device address. Then, send data and STOP condition
charlesmn 0:3ac96e360672 43 tmp[0] = RegisterAddr >> 8;
charlesmn 0:3ac96e360672 44 tmp[1] = RegisterAddr & 0x0FF;
charlesmn 0:3ac96e360672 45 memcpy(tmp+2, pBuffer, NumByteToWrite);
charlesmn 0:3ac96e360672 46
charlesmn 0:3ac96e360672 47 ret = write(DeviceAddr, (const char*)tmp, NumByteToWrite+2, false);
charlesmn 0:3ac96e360672 48
charlesmn 0:3ac96e360672 49 if(ret) return -1;
charlesmn 0:3ac96e360672 50 return 0;
charlesmn 0:3ac96e360672 51 }
charlesmn 0:3ac96e360672 52
charlesmn 0:3ac96e360672 53 /**
charlesmn 0:3ac96e360672 54 * @brief Reads a buffer from the I2C peripheral device.
charlesmn 0:3ac96e360672 55 * @param pBuffer pointer to the byte-array to read data in to
charlesmn 0:3ac96e360672 56 * @param DeviceAddr specifies the peripheral device slave address.
charlesmn 0:3ac96e360672 57 * @param RegisterAddr specifies the internal address register
charlesmn 0:3ac96e360672 58 * where to start reading from (must be correctly masked).
charlesmn 0:3ac96e360672 59 * @param NumByteToRead number of bytes to be read.
charlesmn 0:3ac96e360672 60 * @retval 0 if ok,
charlesmn 0:3ac96e360672 61 * @retval -1 if an I2C error has occured
charlesmn 0:3ac96e360672 62 * @note On some devices if NumByteToWrite is greater
charlesmn 0:3ac96e360672 63 * than one, the RegisterAddr must be masked correctly!
charlesmn 0:3ac96e360672 64 */
charlesmn 0:3ac96e360672 65 int ToF_i2c_read(uint8_t* pBuffer, uint8_t DeviceAddr, uint16_t RegisterAddr,
charlesmn 0:3ac96e360672 66 uint16_t NumByteToRead) {
charlesmn 0:3ac96e360672 67 int ret;
charlesmn 0:3ac96e360672 68 uint8_t ExpanderData[2];
charlesmn 0:3ac96e360672 69 ExpanderData[0] = RegisterAddr >> 8;
charlesmn 0:3ac96e360672 70 ExpanderData[1] = RegisterAddr & 0x0FF;
charlesmn 0:3ac96e360672 71 /* Send device address, with no STOP condition */
charlesmn 0:3ac96e360672 72 ret = write(DeviceAddr, (const char*)ExpanderData, 2, true);
charlesmn 0:3ac96e360672 73 if(!ret) {
charlesmn 0:3ac96e360672 74 /* Read data, with STOP condition */
charlesmn 0:3ac96e360672 75 ret = read(DeviceAddr, (char*)pBuffer, NumByteToRead, false);
charlesmn 0:3ac96e360672 76 }
charlesmn 0:3ac96e360672 77
charlesmn 0:3ac96e360672 78 if(ret) return -1;
charlesmn 0:3ac96e360672 79 return 0;
charlesmn 0:3ac96e360672 80 }
charlesmn 0:3ac96e360672 81
charlesmn 0:3ac96e360672 82 private:
charlesmn 0:3ac96e360672 83 static const unsigned int TEMP_BUF_SIZE = 256;
charlesmn 0:3ac96e360672 84 };
charlesmn 0:3ac96e360672 85
lugandc 18:0696efe39d08 86 #endif /* __DEV_ToF_I2C_H */