21 static BIT started = 0;
30 static BIT internalTimeoutOccurred = 0;
45 halfPeriodUs = (500 + freqKHz - 1) / freqKHz;
65 void i2cClearScl(
void)
70 void i2cClearSda(
void)
75 void i2cWaitForHighScl(
uint16 timeoutMs)
78 while (i2cReadScl() == 0)
80 if (
getMs() - time > timeoutMs)
82 internalTimeoutOccurred = 1;
99 i2cWaitForHighScl(timeout);
100 if (internalTimeoutOccurred)
return;
121 i2cWaitForHighScl(timeout);
122 if (internalTimeoutOccurred)
return;
139 void i2cWriteBit(
BIT b)
152 i2cWaitForHighScl(timeout);
153 if (internalTimeoutOccurred)
return;
177 i2cWaitForHighScl(timeout);
178 if (internalTimeoutOccurred)
return 0;
195 internalTimeoutOccurred = 0;
197 for (i = 0; i < 8; i++)
199 i2cWriteBit(byte & 0x80);
200 if (internalTimeoutOccurred)
return 0;
204 if (internalTimeoutOccurred)
return 0;
209 if (internalTimeoutOccurred)
return 0;
223 internalTimeoutOccurred = 0;
225 for (i = 0; i < 8; i++)
228 if (internalTimeoutOccurred)
return 0;
229 byte = (byte << 1) | b;
233 if (internalTimeoutOccurred)
return 0;
void setDigitalInput(uint8 pinNumber, BIT pulled) __reentrant
Configures the specified pin as an input.
void setDigitalOutput(uint8 pinNumber, BIT value) __reentrant
Configures the specified pin as a digital output.
void i2cSetTimeout(uint16 timeoutMs)
void i2cSetFrequency(uint16 freqKHz)
uint8 i2cReadByte(BIT nack)
void delayMicroseconds(uint8 microseconds)
BIT i2cWriteByte(uint8 byte)
BIT isPinHigh(uint8 pinNumber) __reentrant
Returns the current input or output value of the pin.