5static const char *
const TAG =
"ds2484.onewire";
13 ESP_LOGCONFIG(TAG,
"1-wire bus:");
18 for (uint8_t retry_nr = 0; retry_nr < 10; retry_nr++) {
20 ESP_LOGE(TAG,
"read status error");
23 ESP_LOGVV(TAG,
"status: %02x", *
status);
28 ESP_LOGE(TAG,
"read status error: too many retries");
38 ESP_LOGVV(TAG,
"reset_device");
39 uint8_t device_reset_cmd = 0xf0;
45 ESP_LOGE(TAG,
"reset_device: can't complete");
49 uint8_t write_config[2] = {0xd2, (uint8_t) (config | (~config << 4))};
51 ESP_LOGE(TAG,
"reset_device: can't write config");
55 ESP_LOGE(TAG,
"can't read read8 response");
58 if (response != (write_config[1] & 0xf)) {
59 ESP_LOGE(TAG,
"configuration didn't update");
66 ESP_LOGVV(TAG,
"reset");
67 uint8_t reset_cmd = 0xb4;
75 uint8_t buffer[2] = {0xa5, value};
76 this->
write(buffer, 2);
81 ESP_LOGVV(TAG,
"write8: %02x", value);
86 ESP_LOGVV(TAG,
"write64: %llx", value);
87 for (uint8_t i = 0; i < 8; i++) {
88 this->
write8_((value >> (i * 8)) & 0xff);
93 uint8_t read8_cmd = 0x96;
94 uint8_t set_read_reg_cmd[2] = {0xe1, 0xe1};
97 ESP_LOGE(TAG,
"can't write read8 cmd");
102 ESP_LOGE(TAG,
"can't set read data reg");
106 ESP_LOGE(TAG,
"can't read read8 response");
113 uint8_t response = 0;
114 for (uint8_t i = 0; i < 8; i++) {
115 response |= (this->
read8() << (i * 8));
127 uint8_t buffer[2] = {(uint8_t) 0x78, (uint8_t) (*branch ? 0x80u : 0)};
130 ESP_LOGE(TAG,
"one_wire_triple start: read status error");
134 ESP_LOGV(TAG,
"one_wire_triple: can't write cmd");
138 ESP_LOGE(TAG,
"one_wire_triple: read status error");
141 *id_bit = bool(
status & 0x20);
142 *cmp_id_bit = bool(
status & 0x40);
143 *branch = bool(
status & 0x80);
148 ESP_LOGVV(TAG,
"search_int");
150 ESP_LOGVV(TAG,
"last device flag set, quitting");
154 uint8_t last_zero = 0;
155 uint64_t bit_mask = 1;
159 for (uint8_t bit_number = 1; bit_number <= 64; bit_number++, bit_mask <<= 1) {
165 branch = (
address & bit_mask) > 0;
170 bool id_bit, cmp_id_bit;
171 bool branch_before = branch;
173 ESP_LOGW(TAG,
"one wire triple error, quitting");
177 if (id_bit && cmp_id_bit) {
178 ESP_LOGW(TAG,
"no devices on the bus, quitting");
183 if (!id_bit && !cmp_id_bit && !branch) {
184 last_zero = bit_number;
187 ESP_LOGVV(TAG,
"%d %d branch: %d %d", id_bit, cmp_id_bit, branch_before, branch);
195 ESP_LOGVV(TAG,
"last_discepancy: %d", last_zero);
196 ESP_LOGVV(TAG,
"address: %llx",
address);
void dump_config() override
void write8(uint8_t) override
bool one_wire_triple_(bool *branch, bool *id_bit, bool *cmp_id_bit)
uint64_t search_int() override
bool read_status_(uint8_t *)
bool wait_for_completion_()
void write64(uint64_t) override
uint8_t last_discrepancy_
void reset_search() override
uint64_t read64() override
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
void dump_devices_(const char *tag)
log the found devices
void search()
Search for 1-Wire devices on the bus.
@ ERROR_OK
No error found during execution of method.
Providing packet encoding functions for exchanging data with a remote host.