ported to use hardware I2C

Dependents:   tc_agent Line_Trace_No_collision_Light_control_longer_dis

Committer:
maruta
Date:
Tue Jul 19 03:50:10 2016 +0000
Revision:
0:61de426fb945
ported to use hardware I2C;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maruta 0:61de426fb945 1 #include "S11059.h"
maruta 0:61de426fb945 2
maruta 0:61de426fb945 3 S11059::S11059(PinName sda, PinName scl): _i2c(sda,scl){
maruta 0:61de426fb945 4 char dat[2];
maruta 0:61de426fb945 5 dat[0] = 0x00;
maruta 0:61de426fb945 6 dat[1] = 0x8a;
maruta 0:61de426fb945 7 _i2c.write(S11059_ADDR,dat,2);
maruta 0:61de426fb945 8 dat[1] = 0x0a;
maruta 0:61de426fb945 9 _i2c.write(S11059_ADDR,dat,2);
maruta 0:61de426fb945 10 }
maruta 0:61de426fb945 11
maruta 0:61de426fb945 12 void S11059::update(){
maruta 0:61de426fb945 13 uint8_t buf[8];
maruta 0:61de426fb945 14 char dataout[1]={0x03};
maruta 0:61de426fb945 15 _i2c.write(S11059_ADDR, (char *) dataout, 1);
maruta 0:61de426fb945 16 _i2c.read(S11059_ADDR, (char *) buf,8);
maruta 0:61de426fb945 17 r=buf[0]<<8|buf[1];
maruta 0:61de426fb945 18 g=buf[2]<<8|buf[3];
maruta 0:61de426fb945 19 b=buf[4]<<8|buf[5];
maruta 0:61de426fb945 20 }
maruta 0:61de426fb945 21
maruta 0:61de426fb945 22 S11059::~S11059(){
maruta 0:61de426fb945 23 }