MCPcopy Create free account
hub / github.com/PaulStoffregen/OneWire / write_bit

Method write_bit

OneWire.cpp:213–235  ·  view source on GitHub ↗

Write a bit. Port and bit is used to cut lookup time and provide more certain timing.

Source from the content-addressed store, hash-verified

211// more certain timing.
212//
213void CRIT_TIMING OneWire::write_bit(uint8_t v)
214{
215 IO_REG_TYPE mask IO_REG_MASK_ATTR = bitmask;
216 __attribute__((unused)) volatile IO_REG_TYPE *reg IO_REG_BASE_ATTR = baseReg;
217
218 if (v & 1) {
219 noInterrupts();
220 DIRECT_WRITE_LOW(reg, mask);
221 DIRECT_MODE_OUTPUT(reg, mask); // drive output low
222 delayMicroseconds(10);
223 DIRECT_WRITE_HIGH(reg, mask); // drive output high
224 interrupts();
225 delayMicroseconds(55);
226 } else {
227 noInterrupts();
228 DIRECT_WRITE_LOW(reg, mask);
229 DIRECT_MODE_OUTPUT(reg, mask); // drive output low
230 delayMicroseconds(65);
231 DIRECT_WRITE_HIGH(reg, mask); // drive output high
232 interrupts();
233 delayMicroseconds(5);
234 }
235}
236
237//
238// Read a bit. Port and bit is used to cut lookup time and provide

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected