MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / _write_bit

Function _write_bit

modules/drivers/onewire/esp/owb_gpio.c:147–171  ·  view source on GitHub ↗

* @brief Send a 1-Wire write bit, with recovery time. * @param[in] bus Initialised bus instance. * @param[in] bit The value to send. */

Source from the content-addressed store, hash-verified

145 * @param[in] bit The value to send.
146 */
147static void _write_bit(const OneWireBus * bus, int bit)
148{
149 struct modGPIOConfigurationRecord *config = bus->config;
150
151 modCriticalSectionBegin();
152
153 modGPIOWrite(config, 0); // Drive DQ low
154#if MODDEF_ONEWIRE_DIRECTGPIO
155 DIRECT_MODE_OUTPUT(REG, PIN_TO_BITMASK(config->pin));
156#else
157 modGPIOSetMode(config, kModGPIOOutputOpenDrain);
158#endif
159 if (bit) {
160 ets_delay_us(bus->timing->A);
161 modGPIOWrite(config, 1); // Release the bus
162 modCriticalSectionEnd();
163 ets_delay_us(bus->timing->B);
164 }
165 else {
166 ets_delay_us(bus->timing->C);
167 modGPIOWrite(config, 1); // Release the bus
168 modCriticalSectionEnd();
169 ets_delay_us(bus->timing->D);
170 }
171}
172
173/**
174 * @brief Read a bit from the 1-Wire bus and return the value, with recovery time.

Callers 1

_write_bitsFunction · 0.85

Calls 2

modGPIOWriteFunction · 0.50
modGPIOSetModeFunction · 0.50

Tested by

no test coverage detected