38 #include <util/delay.h>
43 _SFR_MEM8(this->twcr) =
cmd;
45 while (!(_SFR_MEM8(this->twcr) & (1 << TWINT1)))
56 status = _SFR_MEM8(this->twsr) & 0xF8;
61 bool i2cMaster::read(uint8_t slaveAddr, uint8_t regAddr, uint8_t numOfBytes, uint8_t *data)
83 for(i = 0; i < (numOfBytes - 1); i++)
103 bool i2cMaster::write(uint8_t slaveAddr, uint8_t regAddr, uint8_t numOfBytes, uint8_t *data)
116 for(i = 0; i < numOfBytes; i++)
118 if(this->
writeByte(*(data + i)) ==
false)
132 if(this->
cmd((1 << TWINT1) | (1 << TWEN1) | (1 << TWEA1)) ==
false)
141 if(this->
cmd((1 << TWINT1) | (1 << TWEN1)) ==
false)
147 *data = _SFR_MEM8(this->twdr);
155 this->
cmd((1<<TWINT1) | (1<<TWSTA1) | (1<<TWEN1) | (1 << TWEA1));
163 _SFR_MEM8(this->twdr) = (addr << 1) | RW;
164 this->
cmd((1 << TWINT1) | (1 << TWEN1) | (1 << TWEA1));
180 return this->
start(addr, RW);
185 _SFR_MEM8(this->twdr) = data;
187 this->
cmd((1 << TWINT1) | (1 << TWEN1) | (1 << TWEA1));
196 _SFR_MEM8(this->twcr) = (1 << TWINT1) | (1 << TWEN1) | (1 << TWSTO1);
200 while (_SFR_MEM8(this->twcr) & (1 << TWSTO1))
224 _SFR_MEM8(this->twbr) = 1;
226 _SFR_MEM8(this->twsr) &= 0xFC;
246 _SFR_MEM8(this->twbr) = 1;
250 void* i2cMaster::operator
new(
size_t size)
252 void *
object = malloc(size);