ESPHome 2026.8.0-dev
Loading...
Searching...
No Matches
ds248x.h
Go to the documentation of this file.
1#pragma once
2
3// DS248x I2C-to-1-Wire Bridge Family
4// Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ds2482-100.pdf
5// Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ds2482-800.pdf
6// Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ds2484.pdf
7
9#include "esphome/core/hal.h"
11
12namespace esphome::ds248x {
13
14// DS248x I2C Commands
15static constexpr uint8_t DS248X_COMMAND_RESET = 0xF0;
16static constexpr uint8_t DS248X_COMMAND_SETREADPTR = 0xE1;
17static constexpr uint8_t DS248X_COMMAND_WRITECONFIG = 0xD2;
18static constexpr uint8_t DS248X_COMMAND_CHANNELSELECT = 0xC3;
19static constexpr uint8_t DS248X_COMMAND_RESETWIRE = 0xB4;
20static constexpr uint8_t DS248X_COMMAND_WRITEBYTE = 0xA5;
21static constexpr uint8_t DS248X_COMMAND_READBYTE = 0x96;
22static constexpr uint8_t DS248X_COMMAND_TRIPLET = 0x78;
23static constexpr uint8_t DS2484_COMMAND_ADJUSTPORT = 0xC3;
24
25// DS2484 "Adjust 1-Wire Port" parameter codes (datasheet Table 6, control byte P[2:0])
26static constexpr uint8_t DS2484_PORT_PARAM_TRSTL = 0x0;
27static constexpr uint8_t DS2484_PORT_PARAM_TMSP = 0x1;
28static constexpr uint8_t DS2484_PORT_PARAM_TW0L = 0x2;
29static constexpr uint8_t DS2484_PORT_PARAM_TREC0 = 0x3;
30static constexpr uint8_t DS2484_PORT_PARAM_RWPU = 0x4;
31
32// DS248x Status Register Bits
33static constexpr uint8_t DS248X_STATUS_BUSY = 0x01;
34static constexpr uint8_t DS248X_STATUS_PPD = 0x02;
35static constexpr uint8_t DS248X_STATUS_SD = 0x04;
36static constexpr uint8_t DS248X_STATUS_RST = 0x10;
37static constexpr uint8_t DS248X_STATUS_SBR = 0x20;
38static constexpr uint8_t DS248X_STATUS_TSB = 0x40;
39static constexpr uint8_t DS248X_STATUS_DIR = 0x80;
40
41// DS248x Register Pointers
42static constexpr uint8_t DS248X_POINTER_STATUS = 0xF0;
43static constexpr uint8_t DS248X_POINTER_DATA = 0xE1;
44static constexpr uint8_t DS248X_POINTER_CONFIG = 0xC3;
45
46// DS248x Configuration Bits
47static constexpr uint8_t DS248X_CONFIG_ACTIVE_PULLUP = 0x01;
48
60 public:
61 void setup() override;
62 void dump_config() override;
63 void on_shutdown() override;
64 float get_setup_priority() const override { return setup_priority::BUS; }
65
66 void set_sleep_pin(InternalGPIOPin *pin) { this->sleep_pin_ = pin; }
67 void set_bus_sleep(bool enabled) { this->bus_sleep_ = enabled; }
68 void set_hub_sleep(bool enabled) { this->hub_sleep_ = enabled; }
69 void set_channel_count(uint8_t count) { this->channel_count_ = count; }
70 void set_active_pullup(bool enabled) { this->active_pullup_ = enabled; }
71
72 // DS2484 Timing Parameters
73 void set_val_trstl(uint8_t val) {
74 this->ds2484_trstl_ = val;
75 this->ds2484_mode_ = true;
76 }
77 void set_val_tmsp(uint8_t val) {
78 this->ds2484_tmsp_ = val;
79 this->ds2484_mode_ = true;
80 }
81 void set_val_tw0l(uint8_t val) {
82 this->ds2484_tw0l_ = val;
83 this->ds2484_mode_ = true;
84 }
85 void set_val_trec0(uint8_t val) {
86 this->ds2484_trec0_ = val;
87 this->ds2484_mode_ = true;
88 }
89 void set_val_rwpu(uint8_t val) {
90 this->ds2484_rwpu_ = val;
91 this->ds2484_mode_ = true;
92 }
93
95 uint8_t get_channel_count() const { return this->channel_count_; }
96
97 // --- Core 1-Wire API (used by DS248xOneWireBus) ---
98 bool select_channel(uint8_t channel);
99 bool ow_reset(bool &presence);
100 bool ow_write_byte(uint8_t byte);
101 bool ow_read_byte(uint8_t &byte);
102
103 // --- Search support (used by DS248xOneWireBus) ---
104 bool search_triplet(bool search_direction, uint8_t &status);
105
106 protected:
108 uint8_t channel_count_ = 1;
109 bool bus_sleep_{false};
110 bool hub_sleep_{false};
111 bool active_pullup_ = false;
112
113 // DS2484 Config
114 bool ds2484_mode_ = false;
115 static constexpr uint8_t DS2484_PARAM_UNSET = 0xFF;
121
123
124 // Internal helpers
125 bool set_read_pointer_(uint8_t ptr);
126 bool wait_busy_();
127 bool device_reset_();
128 bool device_configure_();
129 bool configure_ds2484_port_(uint8_t param, uint8_t val);
130 bool write_config_();
131};
132
133} // namespace esphome::ds248x
DS248x I2C-to-1-Wire Bridge Component.
Definition ds248x.h:59
void set_val_tmsp(uint8_t val)
Definition ds248x.h:77
void set_val_rwpu(uint8_t val)
Definition ds248x.h:89
bool configure_ds2484_port_(uint8_t param, uint8_t val)
Definition ds248x.cpp:138
void set_sleep_pin(InternalGPIOPin *pin)
Definition ds248x.h:66
float get_setup_priority() const override
Definition ds248x.h:64
void set_val_tw0l(uint8_t val)
Definition ds248x.h:81
bool select_channel(uint8_t channel)
Definition ds248x.cpp:194
void set_channel_count(uint8_t count)
Definition ds248x.h:69
void set_val_trstl(uint8_t val)
Definition ds248x.h:73
void set_active_pullup(bool enabled)
Definition ds248x.h:70
uint8_t get_channel_count() const
Get the channel count (1 for DS2482-100/DS2484, 8 for DS2482-800)
Definition ds248x.h:95
bool ow_reset(bool &presence)
Definition ds248x.cpp:229
void set_bus_sleep(bool enabled)
Definition ds248x.h:67
InternalGPIOPin * sleep_pin_
Definition ds248x.h:107
void set_val_trec0(uint8_t val)
Definition ds248x.h:85
bool set_read_pointer_(uint8_t ptr)
Definition ds248x.cpp:67
static constexpr uint8_t DS2484_PARAM_UNSET
Definition ds248x.h:115
bool ow_read_byte(uint8_t &byte)
Definition ds248x.cpp:280
bool ow_write_byte(uint8_t byte)
Definition ds248x.cpp:257
void set_hub_sleep(bool enabled)
Definition ds248x.h:68
bool search_triplet(bool search_direction, uint8_t &status)
Definition ds248x.cpp:300
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:132
mopeka_std_values val[3]
constexpr float BUS
For communication buses like i2c/spi.
Definition component.h:39