4static const char *
const TAG =
"ds2484.onewire";
12 ESP_LOGCONFIG(TAG,
"1-wire bus:");
17 for (uint8_t retry_nr = 0; retry_nr < 10; retry_nr++) {
19 ESP_LOGE(TAG,
"read status error");
22 ESP_LOGVV(TAG,
"status: %02x", *
status);
27 ESP_LOGE(TAG,
"read status error: too many retries");
37 ESP_LOGVV(TAG,
"reset_device");
38 uint8_t device_reset_cmd = 0xf0;
44 ESP_LOGE(TAG,
"reset_device: can't complete");
48 uint8_t write_config[2] = {0xd2, (uint8_t) (config | (~config << 4))};
50 ESP_LOGE(TAG,
"reset_device: can't write config");
54 ESP_LOGE(TAG,
"can't read read8 response");
57 if (response != (write_config[1] & 0xf)) {
58 ESP_LOGE(TAG,
"configuration didn't update");
65 ESP_LOGVV(TAG,
"reset");
66 uint8_t reset_cmd = 0xb4;
74 uint8_t buffer[2] = {0xa5, value};
75 this->
write(buffer, 2);
80 ESP_LOGVV(TAG,
"write8: %02x", value);
85 ESP_LOGVV(TAG,
"write64: %llx", value);
86 for (uint8_t i = 0; i < 8; i++) {
87 this->
write8_((value >> (i * 8)) & 0xff);
92 uint8_t read8_cmd = 0x96;
93 uint8_t set_read_reg_cmd[2] = {0xe1, 0xe1};
96 ESP_LOGE(TAG,
"can't write read8 cmd");
101 ESP_LOGE(TAG,
"can't set read data reg");
105 ESP_LOGE(TAG,
"can't read read8 response");
112 uint64_t response = 0;
113 for (uint8_t i = 0; i < 8; i++) {
114 response |= (
static_cast<uint64_t
>(this->
read8()) << (i * 8));
126 uint8_t buffer[2] = {(uint8_t) 0x78, (uint8_t) (*branch ? 0x80u : 0)};
129 ESP_LOGE(TAG,
"one_wire_triple start: read status error");
133 ESP_LOGV(TAG,
"one_wire_triple: can't write cmd");
137 ESP_LOGE(TAG,
"one_wire_triple: read status error");
140 *id_bit = bool(
status & 0x20);
141 *cmp_id_bit = bool(
status & 0x40);
142 *branch = bool(
status & 0x80);
147 ESP_LOGVV(TAG,
"search_int");
149 ESP_LOGVV(TAG,
"last device flag set, quitting");
153 uint8_t last_zero = 0;
154 uint64_t bit_mask = 1;
158 for (uint8_t bit_number = 1; bit_number <= 64; bit_number++, bit_mask <<= 1) {
164 branch = (
address & bit_mask) > 0;
169 bool id_bit, cmp_id_bit;
170 bool branch_before = branch;
172 ESP_LOGW(TAG,
"one wire triple error, quitting");
176 if (id_bit && cmp_id_bit) {
177 ESP_LOGW(TAG,
"no devices on the bus, quitting");
182 if (!id_bit && !cmp_id_bit && !branch) {
183 last_zero = bit_number;
186 ESP_LOGVV(TAG,
"%d %d branch: %d %d", id_bit, cmp_id_bit, branch_before, branch);
194 ESP_LOGVV(TAG,
"last_discepancy: %d", last_zero);
195 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) const
writes an array of bytes to a device using an I2CBus
ErrorCode read(uint8_t *data, size_t len) const
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.