8 static const char *
const TAG =
"dallas.one_wire";
20 uint8_t retries = 125;
54 uint32_t delay0 = bit ? 6 : 60;
55 uint32_t delay1 = bit ? 54 : 5;
89 uint32_t timing_constant = 12;
91 uint32_t timing_constant = 14;
96 while (
micros() - start < timing_constant)
104 if (now - start < 60)
111 for (uint8_t i = 0; i < 8; i++) {
117 for (uint8_t i = 0; i < 64; i++) {
118 this->
write_bit(
bool((1ULL << i) & val));
124 for (uint8_t i = 0; i < 8; i++) {
125 ret |= (uint8_t(this->
read_bit()) << i);
131 for (uint8_t i = 0; i < 8; i++) {
132 ret |= (uint64_t(this->
read_bit()) << i);
137 this->
write8(ONE_WIRE_ROM_SELECT);
152 if (!this->
reset()) {
159 uint8_t id_bit_number = 1;
160 uint8_t last_zero = 0;
161 uint8_t rom_byte_number = 0;
162 bool search_result =
false;
163 uint8_t rom_byte_mask = 1;
168 this->
write8(ONE_WIRE_ROM_SEARCH);
175 if (id_bit && cmp_id_bit) {
182 if (id_bit != cmp_id_bit) {
188 branch = (this->
rom_number8_()[rom_byte_number] & rom_byte_mask) > 0;
194 last_zero = id_bit_number;
203 this->
rom_number8_()[rom_byte_number] &= ~rom_byte_mask;
210 if (rom_byte_mask == 0u) {
215 }
while (rom_byte_number < 8);
218 if (id_bit_number >= 65) {
224 search_result =
true;
227 search_result = search_result && (this->
rom_number8_()[0] != 0);
228 if (!search_result) {
236 std::vector<uint64_t> res;
240 while ((address = this->
search()) != 0u)
241 res.push_back(address);
void reset_search()
Reset the device search.
void skip()
Write a command to the bus that addresses all devices by skipping the ROM.
const int ONE_WIRE_ROM_SEARCH
bool reset()
Reset the bus, should be done before all write operations.
uint32_t IRAM_ATTR HOT micros()
void write_bit(bool bit)
Write a single bit to the bus, takes about 70µs.
ESPOneWire(InternalGPIOPin *pin)
std::vector< uint64_t > search_vec()
Helper that wraps search in a std::vector.
const uint8_t ONE_WIRE_ROM_SELECT
bool read_bit()
Read a single bit from the bus, takes about 70µs.
void write8(uint8_t val)
Write a word to the bus. LSB first.
void pin_mode(gpio::Flags flags)
uint8_t read8()
Read an 8 bit word from the bus.
uint8_t last_discrepancy_
uint64_t read64()
Read an 64-bit unsigned integer from the bus.
virtual ISRInternalGPIOPin to_isr() const =0
Helper class to disable interrupts.
uint64_t search()
Search for a 1-Wire device on the bus. Returns 0 if all devices have been found.
uint8_t * rom_number8_()
Helper to get the internal 64-bit unsigned rom number as a 8-bit integer pointer. ...
void select(uint64_t address)
Select a specific address on the bus for the following command.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
void write64(uint64_t val)
Write a 64 bit unsigned integer to the bus. LSB first.
void digital_write(bool value)