5static const char *
const TAG =
"ds2484.onewire";
8 ESP_LOGCONFIG(TAG,
"Running setup");
14 ESP_LOGCONFIG(TAG,
"1-wire bus:");
19 for (uint8_t retry_nr = 0; retry_nr < 10; retry_nr++) {
21 ESP_LOGE(TAG,
"read status error");
24 ESP_LOGVV(TAG,
"status: %02x", *
status);
29 ESP_LOGE(TAG,
"read status error: too many retries");
39 ESP_LOGVV(TAG,
"reset_device");
40 uint8_t device_reset_cmd = 0xf0;
46 ESP_LOGE(TAG,
"reset_device: can't complete");
50 uint8_t write_config[2] = {0xd2, (uint8_t) (config | (~config << 4))};
52 ESP_LOGE(TAG,
"reset_device: can't write config");
56 ESP_LOGE(TAG,
"can't read read8 response");
59 if (response != (write_config[1] & 0xf)) {
60 ESP_LOGE(TAG,
"configuration didn't update");
67 ESP_LOGVV(TAG,
"reset");
68 uint8_t reset_cmd = 0xb4;
76 uint8_t buffer[2] = {0xa5, value};
77 this->
write(buffer, 2);
82 ESP_LOGVV(TAG,
"write8: %02x", value);
87 ESP_LOGVV(TAG,
"write64: %llx", value);
88 for (uint8_t i = 0; i < 8; i++) {
89 this->
write8_((value >> (i * 8)) & 0xff);
94 uint8_t read8_cmd = 0x96;
95 uint8_t set_read_reg_cmd[2] = {0xe1, 0xe1};
98 ESP_LOGE(TAG,
"can't write read8 cmd");
103 ESP_LOGE(TAG,
"can't set read data reg");
107 ESP_LOGE(TAG,
"can't read read8 response");
114 uint8_t response = 0;
115 for (uint8_t i = 0; i < 8; i++) {
116 response |= (this->
read8() << (i * 8));
128 uint8_t buffer[2] = {(uint8_t) 0x78, (uint8_t) (*branch ? 0x80u : 0)};
131 ESP_LOGE(TAG,
"one_wire_triple start: read status error");
135 ESP_LOGV(TAG,
"one_wire_triple: can't write cmd");
139 ESP_LOGE(TAG,
"one_wire_triple: read status error");
142 *id_bit = bool(
status & 0x20);
143 *cmp_id_bit = bool(
status & 0x40);
144 *branch = bool(
status & 0x80);
149 ESP_LOGVV(TAG,
"search_int");
151 ESP_LOGVV(TAG,
"last device flag set, quitting");
155 uint8_t last_zero = 0;
156 uint64_t bit_mask = 1;
160 for (uint8_t bit_number = 1; bit_number <= 64; bit_number++, bit_mask <<= 1) {
166 branch = (
address & bit_mask) > 0;
171 bool id_bit, cmp_id_bit;
172 bool branch_before = branch;
174 ESP_LOGW(TAG,
"one wire triple error, quitting");
178 if (id_bit && cmp_id_bit) {
179 ESP_LOGW(TAG,
"no devices on the bus, quitting");
184 if (!id_bit && !cmp_id_bit && !branch) {
185 last_zero = bit_number;
188 ESP_LOGVV(TAG,
"%d %d branch: %d %d", id_bit, cmp_id_bit, branch_before, branch);
196 ESP_LOGVV(TAG,
"last_discepancy: %d", last_zero);
197 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.