Creating a project about VL6180XA1 for TT_Mxx

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers common_define.cpp Source File

common_define.cpp

00001 #include "common_define.h"
00002 
00003 
00004 
00005 
00006 void i2cWrite(I2C * dev_i2c,uint8_t address,uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
00007 {
00008     uint8_t temp_buffer[NumByteToWrite + 1];
00009     temp_buffer[0] = RegisterAddr;
00010     memcpy(temp_buffer + 1,pBuffer,NumByteToWrite);
00011     dev_i2c->write((int)address,(const char *)temp_buffer,NumByteToWrite + 1);
00012 }
00013 
00014 
00015 void i2cRead(I2C * dev_i2c,uint8_t address,uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
00016 {
00017     dev_i2c->write((int)address,(const char *)&RegisterAddr,1);
00018     dev_i2c->read((int)address,(char *)pBuffer,NumByteToRead);
00019 }
00020 
00021 void i2cWriteForVL6180X(I2C * dev_i2c,uint8_t address,uint8_t* pBuffer, uint16_t RegisterAddr, uint16_t NumByteToWrite)
00022 {   
00023     uint8_t temp_buffer[NumByteToWrite + 2];
00024     temp_buffer[0] = (RegisterAddr >> 8) & 0xff;
00025     temp_buffer[1] = (RegisterAddr) & 0xff;
00026     memcpy(temp_buffer + 2,pBuffer,NumByteToWrite);
00027     dev_i2c->write((int)address,(const char *)temp_buffer,NumByteToWrite + 2);
00028 }
00029 
00030 void i2cReadForVL6180X(I2C * dev_i2c,uint8_t address,uint8_t* pBuffer, uint16_t RegisterAddr, uint16_t NumByteToRead)
00031 {
00032     uint8_t temp_buffer[2];
00033     temp_buffer[0] = (RegisterAddr >> 8) & 0xff;
00034     temp_buffer[1] = (RegisterAddr) & 0xff;
00035     dev_i2c->write((int)address,(const char *)temp_buffer,2);
00036     dev_i2c->read((int)address,(char *)pBuffer,NumByteToRead);
00037 }
00038 
00039 void i2cReadForFXS_MUTIL(I2C * dev_i2c,uint8_t address,uint8_t* pBuffer, uint16_t RegisterAddr, uint16_t NumByteToRead)
00040 {
00041     dev_i2c->write((int)address,(const char *)&RegisterAddr,1,true);
00042     dev_i2c->read((int)address,(char *)pBuffer,NumByteToRead);
00043 }
00044 
00045 void i2cWriteForFXS_MUTIL(I2C * dev_i2c,uint8_t address,uint8_t* pBuffer, uint16_t RegisterAddr, uint16_t NumByteToWrite)
00046 {
00047     uint8_t temp_buffer[NumByteToWrite + 1];
00048     temp_buffer[0] = RegisterAddr;
00049     memcpy(temp_buffer + 1,pBuffer,NumByteToWrite);
00050     dev_i2c->write((int)address,(const char *)temp_buffer,NumByteToWrite + 1);
00051 }