7static const char *
const TAG =
"ds248x";
10 ESP_LOGCONFIG(TAG,
"Setting up DS248x...");
21 ESP_LOGD(TAG,
"Probing DS248x...");
24 ESP_LOGD(TAG,
"Device responded! Status: 0x%02x",
status);
26 ESP_LOGW(TAG,
"Device did not respond. Trying reset anyway...");
30 ESP_LOGW(TAG,
"DS248x reset failed during setup!");
35 ESP_LOGE(TAG,
"DS248x configuration failed!");
43 ESP_LOGI(TAG,
"DS248x initialized successfully.");
53 ESP_LOGCONFIG(TAG,
"DS248x:");
56 ESP_LOGCONFIG(TAG,
" Active Pullup: %s", YESNO(this->
active_pullup_));
58 ESP_LOGCONFIG(TAG,
" DS2484 Mode: enabled");
65static constexpr uint32_t BUSY_TIMEOUT_MS = 5;
76 }
while (
millis() - start < BUSY_TIMEOUT_MS);
77 ESP_LOGW(TAG,
"DS248x busy timeout");
81 ESP_LOGE(TAG,
"DS248x recovery failed after busy timeout");
88 ESP_LOGD(TAG,
"Resetting device...");
89 uint8_t cmd = DS248X_COMMAND_RESET;
97 if (!(
status & DS248X_STATUS_RST)) {
98 ESP_LOGW(TAG,
"Device reset failed (RST bit not set)");
107 ESP_LOGD(TAG,
"Configuring device...");
110 ESP_LOGW(TAG,
"Config write/verify failed");
114 ESP_LOGD(TAG,
"Configured successfully");
139 uint8_t cmd = DS2484_COMMAND_ADJUSTPORT;
141 uint8_t data = ((param & 0x07) << 5) | (
val & 0x0F);
150 ESP_LOGW(TAG,
"DS2484 port config failed (param %d)", param);
160 config |= DS248X_CONFIG_ACTIVE_PULLUP;
163 uint8_t config_byte = (config & 0x0F) | ((~config & 0x0F) << 4);
165 if (!this->
write_byte(DS248X_COMMAND_WRITECONFIG, config_byte)) {
166 ESP_LOGW(TAG,
"Failed to write config byte");
176 ESP_LOGW(TAG,
"Failed to read back config byte");
180 if ((read_config & 0x0F) != (config_byte & 0x0F)) {
181 ESP_LOGW(TAG,
"Config mismatch! Wrote 0x%02x, Read 0x%02x", config_byte, read_config);
191static constexpr uint8_t CHANNEL_WRITE_CODES[8] = {0xF0, 0xE1, 0xD2, 0xC3, 0xB4, 0xA5, 0x96, 0x87};
192static constexpr uint8_t CHANNEL_READ_CODES[8] = {0xB8, 0xB1, 0xAA, 0xA3, 0x9C, 0x95, 0x8E, 0x87};
203 if (!this->
write_byte(DS248X_COMMAND_CHANNELSELECT, CHANNEL_WRITE_CODES[channel])) {
214 if (read_code != CHANNEL_READ_CODES[channel]) {
215 ESP_LOGW(TAG,
"Channel select failed! Expected 0x%02x, got 0x%02x", CHANNEL_READ_CODES[channel], read_code);
233 uint8_t cmd = DS248X_COMMAND_RESETWIRE;
238 ESP_LOGW(TAG,
"ow_reset: wait busy failed");
244 ESP_LOGW(TAG,
"ow_reset: read status failed");
248 if (
status & DS248X_STATUS_SD) {
249 ESP_LOGW(TAG,
"Short detected on 1-Wire bus!");
253 presence = (
status & DS248X_STATUS_PPD);
262 ESP_LOGW(TAG,
"Device busy before writing byte 0x%02x",
byte);
266 uint8_t cmd[2] = {DS248X_COMMAND_WRITEBYTE,
byte};
268 ESP_LOGW(TAG,
"I2C write failed for byte 0x%02x",
byte);
273 ESP_LOGW(TAG,
"Timeout waiting for write byte to complete!");
284 uint8_t cmd = DS248X_COMMAND_READBYTE;
307 uint8_t buffer[2] = {DS248X_COMMAND_TRIPLET,
static_cast<uint8_t
>(search_direction ? 0x80 : 0x00)};
void mark_failed()
Mark this component as failed.
virtual void pin_mode(gpio::Flags flags)=0
virtual void digital_write(bool value)=0
bool configure_ds2484_port_(uint8_t param, uint8_t val)
bool select_channel(uint8_t channel)
bool ow_reset(bool &presence)
InternalGPIOPin * sleep_pin_
void on_shutdown() override
bool set_read_pointer_(uint8_t ptr)
static constexpr uint8_t DS2484_PARAM_UNSET
bool ow_read_byte(uint8_t &byte)
bool ow_write_byte(uint8_t byte)
bool search_triplet(bool search_direction, uint8_t &status)
void dump_config() 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
bool write_byte(uint8_t a_register, uint8_t data) const
@ ERROR_OK
No error found during execution of method.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
void HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()