25 #ifndef ACE_WIRE_SIMPLE_WIRE_INTERFACE_H
26 #define ACE_WIRE_SIMPLE_WIRE_INTERFACE_H
72 uint8_t dataPin, uint8_t clockPin, uint8_t delayMicros
76 mDelayMicros(delayMicros)
88 digitalWrite(mClockPin, LOW);
89 digitalWrite(mDataPin, LOW);
116 uint8_t effectiveAddr = (addr << 1) | 0x00;
117 uint8_t res =
write(effectiveAddr);
132 for (uint8_t i = 0; i < 8; ++i) {
148 uint8_t ack = readAck();
175 uint8_t
requestFrom(uint8_t addr, uint8_t quantity,
bool sendStop =
true) {
176 mQuantity = quantity;
177 mSendStop = sendStop;
186 uint8_t effectiveAddr = (addr << 1) | 0x01;
187 uint8_t ack =
write(effectiveAddr);
189 return (ack == 1) ? quantity : 0;
207 if (! mQuantity)
return 0xff;
212 for (uint8_t i = 0; i < 8; ++i) {
215 uint8_t bit = digitalRead(mDataPin);
245 uint8_t readAck()
const {
253 uint8_t ack = digitalRead(mDataPin);
261 void sendAck()
const {
268 void sendNack()
const {
274 void bitDelay()
const { delayMicroseconds(mDelayMicros); }
276 void clockHigh()
const { pinMode(mClockPin, INPUT); bitDelay(); }
278 void clockLow()
const { pinMode(mClockPin, OUTPUT); bitDelay(); }
280 void dataHigh()
const { pinMode(mDataPin, INPUT); bitDelay(); }
282 void dataLow()
const { pinMode(mDataPin, OUTPUT); bitDelay(); }
285 uint8_t
const mDataPin;
286 uint8_t
const mClockPin;
287 uint8_t
const mDelayMicros;