25 #ifndef ACE_WIRE_SIMPLE_WIRE_INTERFACE_H
26 #define ACE_WIRE_SIMPLE_WIRE_INTERFACE_H
73 uint8_t dataPin, uint8_t clockPin, uint8_t delayMicros
77 mDelayMicros(delayMicros)
89 digitalWrite(mClockPin, LOW);
90 digitalWrite(mDataPin, LOW);
117 uint8_t effectiveAddr = (addr << 1) | 0x00;
118 uint8_t res =
write(effectiveAddr);
133 for (uint8_t i = 0; i < 8; ++i) {
149 uint8_t ack = readAck();
177 uint8_t addr, uint8_t quantity,
bool sendStop =
true)
const {
178 mQuantity = quantity;
179 mSendStop = sendStop;
188 uint8_t effectiveAddr = (addr << 1) | 0x01;
189 uint8_t status =
write(effectiveAddr);
191 return (status == 0) ? 0 : quantity;
209 if (! mQuantity)
return 0xff;
214 for (uint8_t i = 0; i < 8; ++i) {
217 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;
289 mutable uint8_t mQuantity;
290 mutable bool mSendStop;