Michael Wilkens / TCA9548

Fork of libTCS34725 by Michael Wilkens

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TCA9548.cpp Source File

TCA9548.cpp

00001 #include "TCA9548.h"
00002 
00003 TCA9548::TCA9548() : i2c(PB_9,PB_8) {}
00004 TCA9548::TCA9548(PinName i2c_sda, PinName i2c_scl) : i2c(i2c_sda,i2c_scl) {}
00005 
00006 void TCA9548::i2cWrite8(uint8_t addr, char data){
00007     char packet[1] = {data & 0xFF}; 
00008     i2c.write(addr,packet,1,false); //only write address and data ~ no reg
00009     wait(0.01);
00010 }
00011 
00012 bool TCA9548::init(uint8_t iCh){
00013     i2c.frequency(400000);
00014     channel = iCh;
00015     i2cWrite8(DEV_ADDR,(char)iCh);
00016     return true;
00017 }
00018 
00019 bool TCA9548::init(){
00020     i2c.frequency(400000);
00021     channel = 0;
00022     i2cWrite8(DEV_ADDR,0);
00023     wait(0.05);
00024     return true;
00025 }
00026 
00027 void TCA9548::ch(uint8_t newCh){
00028     channel = newCh;
00029     i2cWrite8(DEV_ADDR,(char)newCh);
00030     wait(0.05);
00031 }