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

Function _read_bit

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

* @brief Read a bit from the 1-Wire bus and return the value, with recovery time. * @param[in] bus Initialised bus instance. */

Source from the content-addressed store, hash-verified

175 * @param[in] bus Initialised bus instance.
176 */
177static int _read_bit(const OneWireBus * bus)
178{
179 struct modGPIOConfigurationRecord *config = bus->config;
180#if MODDEF_ONEWIRE_DIRECTGPIO
181 volatile IO_REG_TYPE *reg IO_REG_BASE_ATTR = PIN_TO_BASEREG(config->pin);
182#endif
183
184 modCriticalSectionBegin();
185#if MODDEF_ONEWIRE_DIRECTGPIO
186 DIRECT_MODE_OUTPUT(REG, PIN_TO_BITMASK(config->pin));
187#else
188 modGPIOSetMode(config, kModGPIOOutputOpenDrain);
189#endif
190 modGPIOWrite(config, 0); // Drive DQ low
191
192 ets_delay_us(bus->timing->A);
193#if MODDEF_ONEWIRE_DIRECTGPIO
194 DIRECT_MODE_INPUT(reg, PIN_TO_BITMASK(config->pin)); // Release the bus
195#else
196 modGPIOSetMode(config, kModGPIOInput);
197#endif
198 ets_delay_us(bus->timing->E);
199
200 int level = modGPIORead(config);
201
202 modCriticalSectionEnd();
203
204 ets_delay_us(bus->timing->F); // Complete the timeslot and 10us recovery
205
206 return level & 0x01;
207}
208
209/**
210 * @brief Write 1-Wire data byte.

Callers 1

_read_bitsFunction · 0.85

Calls 3

modGPIOSetModeFunction · 0.50
modGPIOWriteFunction · 0.50
modGPIOReadFunction · 0.50

Tested by

no test coverage detected