mirror of
https://github.com/esphome/esphome.git
synced 2026-09-16 17:48:40 +00:00
Merge remote-tracking branch 'upstream/finite-set-mask-ctz' into integration
This commit is contained in:
@@ -4,8 +4,7 @@
|
||||
|
||||
#include "esphome/core/automation.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ota {
|
||||
namespace esphome::ota {
|
||||
|
||||
class OTAStateChangeTrigger final : public Trigger<OTAState>, public OTAStateListener {
|
||||
public:
|
||||
@@ -67,6 +66,5 @@ class OTAErrorTrigger final : public Trigger<uint8_t>, public OTAStateListener {
|
||||
OTAComponent *parent_;
|
||||
};
|
||||
|
||||
} // namespace ota
|
||||
} // namespace esphome
|
||||
} // namespace esphome::ota
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "ota_backend.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ota {
|
||||
namespace esphome::ota {
|
||||
|
||||
#ifdef USE_OTA_STATE_LISTENER
|
||||
OTAGlobalCallback *global_ota_callback{nullptr}; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
@@ -34,5 +33,4 @@ void OTAComponent::notify_state_(OTAState state, float progress, uint8_t error)
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace ota
|
||||
} // namespace esphome
|
||||
} // namespace esphome::ota
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
#include <vector>
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace ota {
|
||||
namespace esphome::ota {
|
||||
|
||||
enum OTAResponseTypes {
|
||||
OTA_RESPONSE_OK = 0x00,
|
||||
@@ -117,5 +116,4 @@ OTAGlobalCallback *get_global_ota_callback();
|
||||
// - notify_state_deferred_() when in separate task (e.g., web_server OTA)
|
||||
// This ensures proper listener execution in all contexts.
|
||||
#endif
|
||||
} // namespace ota
|
||||
} // namespace esphome
|
||||
} // namespace esphome::ota
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
|
||||
#include <Update.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace ota {
|
||||
namespace esphome::ota {
|
||||
|
||||
static const char *const TAG = "ota.arduino_libretiny";
|
||||
|
||||
@@ -66,7 +65,5 @@ OTAResponseTypes ArduinoLibreTinyOTABackend::end() {
|
||||
|
||||
void ArduinoLibreTinyOTABackend::abort() { Update.abort(); }
|
||||
|
||||
} // namespace ota
|
||||
} // namespace esphome
|
||||
|
||||
} // namespace esphome::ota
|
||||
#endif // USE_LIBRETINY
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ota {
|
||||
namespace esphome::ota {
|
||||
|
||||
class ArduinoLibreTinyOTABackend final {
|
||||
public:
|
||||
@@ -22,7 +21,5 @@ class ArduinoLibreTinyOTABackend final {
|
||||
|
||||
std::unique_ptr<ArduinoLibreTinyOTABackend> make_ota_backend();
|
||||
|
||||
} // namespace ota
|
||||
} // namespace esphome
|
||||
|
||||
} // namespace esphome::ota
|
||||
#endif // USE_LIBRETINY
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
|
||||
#include <Updater.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace ota {
|
||||
namespace esphome::ota {
|
||||
|
||||
static const char *const TAG = "ota.arduino_rp2040";
|
||||
|
||||
@@ -75,8 +74,6 @@ void ArduinoRP2040OTABackend::abort() {
|
||||
rp2040::preferences_prevent_write(false);
|
||||
}
|
||||
|
||||
} // namespace ota
|
||||
} // namespace esphome
|
||||
|
||||
} // namespace esphome::ota
|
||||
#endif // USE_RP2040
|
||||
#endif // USE_ARDUINO
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/macros.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ota {
|
||||
namespace esphome::ota {
|
||||
|
||||
class ArduinoRP2040OTABackend final {
|
||||
public:
|
||||
@@ -24,8 +23,6 @@ class ArduinoRP2040OTABackend final {
|
||||
|
||||
std::unique_ptr<ArduinoRP2040OTABackend> make_ota_backend();
|
||||
|
||||
} // namespace ota
|
||||
} // namespace esphome
|
||||
|
||||
} // namespace esphome::ota
|
||||
#endif // USE_RP2040
|
||||
#endif // USE_ARDUINO
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
#include <esp_task_wdt.h>
|
||||
#include <spi_flash_mmap.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace ota {
|
||||
namespace esphome::ota {
|
||||
|
||||
std::unique_ptr<IDFOTABackend> make_ota_backend() { return make_unique<IDFOTABackend>(); }
|
||||
|
||||
@@ -112,6 +111,5 @@ void IDFOTABackend::abort() {
|
||||
this->update_handle_ = 0;
|
||||
}
|
||||
|
||||
} // namespace ota
|
||||
} // namespace esphome
|
||||
} // namespace esphome::ota
|
||||
#endif // USE_ESP32
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
|
||||
#include <esp_ota_ops.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace ota {
|
||||
namespace esphome::ota {
|
||||
|
||||
class IDFOTABackend final {
|
||||
public:
|
||||
@@ -29,6 +28,5 @@ class IDFOTABackend final {
|
||||
|
||||
std::unique_ptr<IDFOTABackend> make_ota_backend();
|
||||
|
||||
} // namespace ota
|
||||
} // namespace esphome
|
||||
} // namespace esphome::ota
|
||||
#endif // USE_ESP32
|
||||
|
||||
@@ -294,12 +294,10 @@ void Component::disable_loop() {
|
||||
App.disable_component_loop_(this);
|
||||
}
|
||||
}
|
||||
void Component::enable_loop() {
|
||||
if ((this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP_DONE) {
|
||||
ESP_LOGVV(TAG, "%s loop enabled", LOG_STR_ARG(this->get_component_log_str()));
|
||||
this->set_component_state_(COMPONENT_STATE_LOOP);
|
||||
App.enable_component_loop_(this);
|
||||
}
|
||||
void Component::enable_loop_slow_path_() {
|
||||
ESP_LOGVV(TAG, "%s loop enabled", LOG_STR_ARG(this->get_component_log_str()));
|
||||
this->set_component_state_(COMPONENT_STATE_LOOP);
|
||||
App.enable_component_loop_(this);
|
||||
}
|
||||
void IRAM_ATTR HOT Component::enable_loop_soon_any_context() {
|
||||
// This method is thread and ISR-safe because:
|
||||
|
||||
@@ -242,7 +242,10 @@ class Component {
|
||||
* @note Components should call this->enable_loop() on themselves, not on other components.
|
||||
* This ensures the component's state is properly updated along with the loop partition.
|
||||
*/
|
||||
void enable_loop();
|
||||
void enable_loop() {
|
||||
if ((this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP_DONE)
|
||||
this->enable_loop_slow_path_();
|
||||
}
|
||||
|
||||
/** Thread and ISR-safe version of enable_loop() that can be called from any context.
|
||||
*
|
||||
@@ -344,6 +347,8 @@ class Component {
|
||||
virtual void call_setup();
|
||||
void call_dump_config_();
|
||||
|
||||
void enable_loop_slow_path_();
|
||||
|
||||
/// Helper to set component state (clears state bits and sets new state)
|
||||
inline void set_component_state_(uint8_t state) {
|
||||
this->component_state_ &= ~COMPONENT_STATE_MASK;
|
||||
|
||||
@@ -119,7 +119,7 @@ template<typename ValueType, typename BitPolicy = DefaultBitPolicy<ValueType, 16
|
||||
|
||||
constexpr ValueType operator*() const {
|
||||
// Return value for the first set bit
|
||||
return BitPolicy::from_bit(find_next_set_bit(mask_, 0));
|
||||
return BitPolicy::from_bit(find_lowest_set_bit(mask_));
|
||||
}
|
||||
|
||||
constexpr Iterator &operator++() {
|
||||
@@ -151,17 +151,32 @@ template<typename ValueType, typename BitPolicy = DefaultBitPolicy<ValueType, 16
|
||||
/// Get the first value from a raw bitmask
|
||||
/// Used for optimizing intersection logic (e.g., "pick first suitable mode")
|
||||
static constexpr ValueType first_value_from_mask(bitmask_t mask) {
|
||||
return BitPolicy::from_bit(find_next_set_bit(mask, 0));
|
||||
return BitPolicy::from_bit(find_lowest_set_bit(mask));
|
||||
}
|
||||
|
||||
/// Find the next set bit in a bitmask starting from a given position
|
||||
/// Returns the bit position, or MAX_BITS if no more bits are set
|
||||
static constexpr int find_next_set_bit(bitmask_t mask, int start_bit) {
|
||||
int bit = start_bit;
|
||||
/// Find the lowest set bit in a bitmask
|
||||
/// Returns the bit position, or MAX_BITS if no bits are set
|
||||
static constexpr int find_lowest_set_bit(bitmask_t mask) {
|
||||
if (mask == 0) {
|
||||
return BitPolicy::MAX_BITS;
|
||||
}
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
int bit;
|
||||
if constexpr (sizeof(bitmask_t) <= sizeof(unsigned int)) {
|
||||
bit = __builtin_ctz(static_cast<unsigned int>(mask));
|
||||
} else if constexpr (sizeof(bitmask_t) <= sizeof(uint32_t)) {
|
||||
bit = __builtin_ctzl(static_cast<uint32_t>(mask));
|
||||
} else {
|
||||
bit = __builtin_ctzll(static_cast<uint64_t>(mask));
|
||||
}
|
||||
return bit < BitPolicy::MAX_BITS ? bit : BitPolicy::MAX_BITS;
|
||||
#else
|
||||
int bit = 0;
|
||||
while (bit < BitPolicy::MAX_BITS && !(mask & (static_cast<bitmask_t>(1) << bit))) {
|
||||
++bit;
|
||||
}
|
||||
return bit;
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user