1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-20 12:12:24 +01:00

[one_wire][dallas_temp] adjust timings and reduce disabled interrupts (#8744)

Co-authored-by: Samuel Sieb <samuel@sieb.net>
This commit is contained in:
Samuel Sieb
2025-05-11 14:33:50 -07:00
committed by GitHub
parent cdc1a7c646
commit 04147a7f27
6 changed files with 92 additions and 87 deletions

View File

@@ -17,8 +17,15 @@ const uint8_t ONE_WIRE_ROM_SEARCH = 0xF0;
const std::vector<uint64_t> &OneWireBus::get_devices() { return this->devices_; }
bool OneWireBus::reset_() {
int res = this->reset_int();
if (res == -1)
ESP_LOGE(TAG, "1-wire bus is held low");
return res == 1;
}
bool IRAM_ATTR OneWireBus::select(uint64_t address) {
if (!this->reset())
if (!this->reset_())
return false;
this->write8(ONE_WIRE_ROM_SELECT);
this->write64(address);
@@ -31,16 +38,13 @@ void OneWireBus::search() {
this->reset_search();
uint64_t address;
while (true) {
{
InterruptLock lock;
if (!this->reset()) {
// Reset failed or no devices present
return;
}
this->write8(ONE_WIRE_ROM_SEARCH);
address = this->search_int();
if (!this->reset_()) {
// Reset failed or no devices present
return;
}
this->write8(ONE_WIRE_ROM_SEARCH);
address = this->search_int();
if (address == 0)
break;
auto *address8 = reinterpret_cast<uint8_t *>(&address);

View File

@@ -9,14 +9,6 @@ namespace one_wire {
class OneWireBus {
public:
/** Reset the bus, should be done before all write operations.
*
* Takes approximately 1ms.
*
* @return Whether the operation was successful.
*/
virtual bool reset() = 0;
/// Write a word to the bus. LSB first.
virtual void write8(uint8_t val) = 0;
@@ -50,6 +42,20 @@ class OneWireBus {
/// log the found devices
void dump_devices_(const char *tag);
/** Reset the bus, should be done before all write operations.
*
* Takes approximately 1ms.
*
* @return Whether the operation was successful.
*/
bool reset_();
/**
* Bus Reset
* @return -1: signal fail, 0: no device detected, 1: device detected
*/
virtual int reset_int() = 0;
/// Reset the device search.
virtual void reset_search() = 0;