Creating a project about VL6180XA1 for TT_Mxx

Committer:
ThunderSoft
Date:
Fri Apr 26 09:34:53 2019 +0000
Revision:
3:7a97a01bad5e
Parent:
0:293917667c17
"update the mbed-os code to support TT_M4G9"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThunderSoft 0:293917667c17 1 #include "common_define.h"
ThunderSoft 0:293917667c17 2
ThunderSoft 0:293917667c17 3
ThunderSoft 0:293917667c17 4
ThunderSoft 0:293917667c17 5
ThunderSoft 0:293917667c17 6 void i2cWrite(I2C * dev_i2c,uint8_t address,uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
ThunderSoft 0:293917667c17 7 {
ThunderSoft 0:293917667c17 8 uint8_t temp_buffer[NumByteToWrite + 1];
ThunderSoft 0:293917667c17 9 temp_buffer[0] = RegisterAddr;
ThunderSoft 0:293917667c17 10 memcpy(temp_buffer + 1,pBuffer,NumByteToWrite);
ThunderSoft 0:293917667c17 11 dev_i2c->write((int)address,(const char *)temp_buffer,NumByteToWrite + 1);
ThunderSoft 0:293917667c17 12 }
ThunderSoft 0:293917667c17 13
ThunderSoft 0:293917667c17 14
ThunderSoft 0:293917667c17 15 void i2cRead(I2C * dev_i2c,uint8_t address,uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
ThunderSoft 0:293917667c17 16 {
ThunderSoft 0:293917667c17 17 dev_i2c->write((int)address,(const char *)&RegisterAddr,1);
ThunderSoft 0:293917667c17 18 dev_i2c->read((int)address,(char *)pBuffer,NumByteToRead);
ThunderSoft 0:293917667c17 19 }
ThunderSoft 0:293917667c17 20
ThunderSoft 0:293917667c17 21 void i2cWriteForVL6180X(I2C * dev_i2c,uint8_t address,uint8_t* pBuffer, uint16_t RegisterAddr, uint16_t NumByteToWrite)
ThunderSoft 0:293917667c17 22 {
ThunderSoft 0:293917667c17 23 uint8_t temp_buffer[NumByteToWrite + 2];
ThunderSoft 0:293917667c17 24 temp_buffer[0] = (RegisterAddr >> 8) & 0xff;
ThunderSoft 0:293917667c17 25 temp_buffer[1] = (RegisterAddr) & 0xff;
ThunderSoft 0:293917667c17 26 memcpy(temp_buffer + 2,pBuffer,NumByteToWrite);
ThunderSoft 0:293917667c17 27 dev_i2c->write((int)address,(const char *)temp_buffer,NumByteToWrite + 2);
ThunderSoft 0:293917667c17 28 }
ThunderSoft 0:293917667c17 29
ThunderSoft 0:293917667c17 30 void i2cReadForVL6180X(I2C * dev_i2c,uint8_t address,uint8_t* pBuffer, uint16_t RegisterAddr, uint16_t NumByteToRead)
ThunderSoft 0:293917667c17 31 {
ThunderSoft 0:293917667c17 32 uint8_t temp_buffer[2];
ThunderSoft 0:293917667c17 33 temp_buffer[0] = (RegisterAddr >> 8) & 0xff;
ThunderSoft 0:293917667c17 34 temp_buffer[1] = (RegisterAddr) & 0xff;
ThunderSoft 0:293917667c17 35 dev_i2c->write((int)address,(const char *)temp_buffer,2);
ThunderSoft 0:293917667c17 36 dev_i2c->read((int)address,(char *)pBuffer,NumByteToRead);
ThunderSoft 0:293917667c17 37 }
ThunderSoft 0:293917667c17 38
ThunderSoft 0:293917667c17 39 void i2cReadForFXS_MUTIL(I2C * dev_i2c,uint8_t address,uint8_t* pBuffer, uint16_t RegisterAddr, uint16_t NumByteToRead)
ThunderSoft 0:293917667c17 40 {
ThunderSoft 0:293917667c17 41 dev_i2c->write((int)address,(const char *)&RegisterAddr,1,true);
ThunderSoft 0:293917667c17 42 dev_i2c->read((int)address,(char *)pBuffer,NumByteToRead);
ThunderSoft 0:293917667c17 43 }
ThunderSoft 0:293917667c17 44
ThunderSoft 0:293917667c17 45 void i2cWriteForFXS_MUTIL(I2C * dev_i2c,uint8_t address,uint8_t* pBuffer, uint16_t RegisterAddr, uint16_t NumByteToWrite)
ThunderSoft 0:293917667c17 46 {
ThunderSoft 0:293917667c17 47 uint8_t temp_buffer[NumByteToWrite + 1];
ThunderSoft 0:293917667c17 48 temp_buffer[0] = RegisterAddr;
ThunderSoft 0:293917667c17 49 memcpy(temp_buffer + 1,pBuffer,NumByteToWrite);
ThunderSoft 0:293917667c17 50 dev_i2c->write((int)address,(const char *)temp_buffer,NumByteToWrite + 1);
ThunderSoft 0:293917667c17 51 }