172#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
212 return _mux->try_lock();
240#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
288#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
326#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
363#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
396#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
448 mutable std::unique_ptr<std::recursive_mutex> _mux;
468 return "ONEWIRE_ANY";
471 return "ONEWIRE_NONE";
473 static constexpr char hex[] =
"0123456789ABCDEF";
476 auto raw = addr.raw();
477 for (
int i = 0;
i < 8; ++
i) {
481 auto byte =
static_cast<uint8_t>((raw >> (
i * 8)) & 0xFF);
490#include "sdkconfig.h"
491#ifdef CONFIG_IDFXX_STD_FORMAT
497struct formatter<
idfxx::onewire::address> {
498 constexpr auto parse(format_parse_context& ctx) {
return ctx.begin(); }
500 template<
typename FormatContext>
503 return std::copy(s.begin(), s.end(), ctx.out());
constexpr address()=default
Constructs an address with value 0 (equivalent to any()).
constexpr uint8_t family() const
Extracts the family code from the address.
constexpr uint64_t raw() const
Returns the underlying 64-bit ROM address.
constexpr bool operator==(const address &) const noexcept=default
Compares two addresses for equality.
constexpr auto operator<=>(const address &) const noexcept=default
Default three-way comparison for ordering.
constexpr address(uint64_t raw)
Constructs an address from a raw 64-bit value.
static constexpr address any()
Returns the wildcard address for single-device buses.
static constexpr address none()
Returns an invalid sentinel address indicating no device.
1-Wire bus controller with thread-safe access.
bool try_lock() const noexcept
Tries to acquire exclusive access without blocking.
void unlock() const
Releases exclusive access to the bus.
result< void > try_skip_rom()
Selects all devices on the bus.
result< void > try_read(std::span< uint8_t > buf)
Reads multiple bytes from the bus into a buffer.
result< std::vector< address > > try_search(uint8_t family_code, size_t max_devices=8)
Searches for devices with a specific family code.
void power()
Actively drives the bus high for parasitic power.
std::vector< address > search(size_t max_devices=8)
Searches for all devices on the bus.
static result< bus > make(gpio pin)
Creates a new 1-Wire bus controller.
uint8_t read()
Reads a single byte from the bus.
result< void > try_write(uint8_t value)
Writes a single byte to the bus.
void read(std::span< uint8_t > buf)
Reads multiple bytes from the bus into a buffer.
void lock() const
Acquires exclusive access to the bus.
void write(std::span< const uint8_t > data)
Writes multiple bytes to the bus.
gpio pin() const noexcept
Returns the GPIO pin.
result< void > try_power()
Actively drives the bus high for parasitic power.
result< void > try_select(address addr)
Selects a specific device by ROM address.
result< uint8_t > try_read()
Reads a single byte from the bus.
bus(gpio pin)
Creates a new 1-Wire bus controller.
void depower() noexcept
Stops driving power onto the bus.
bool reset()
Performs a 1-Wire reset cycle.
result< std::vector< address > > try_search(size_t max_devices=8)
Searches for all devices on the bus.
bus & operator=(bus &&other) noexcept=default
std::vector< address > search(uint8_t family_code, size_t max_devices=8)
Searches for devices with a specific family code.
bus & operator=(const bus &)=delete
void select(address addr)
Selects a specific device by ROM address.
result< void > try_write(std::span< const uint8_t > data)
Writes multiple bytes to the bus.
void write(uint8_t value)
Writes a single byte to the bus.
void skip_rom()
Selects all devices on the bus.
bus(bus &&other) noexcept=default
std::string to_string(core_id c)
Returns a string representation of a CPU core identifier.
bool check_crc16(std::span< const uint8_t > data, std::span< const uint8_t, 2 > inverted_crc, uint16_t crc_iv=0)
Verifies a 16-bit CRC against received data.
uint8_t crc8(std::span< const uint8_t > data)
Computes a Dallas Semiconductor 8-bit CRC.
uint16_t crc16(std::span< const uint8_t > data, uint16_t crc_iv=0)
Computes a Dallas Semiconductor 16-bit CRC.
1-Wire bus protocol classes and utilities.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
result< std::unique_ptr< T > > make_unique(Args &&... args)
Constructs a T via its make() factory and wraps it in a std::unique_ptr.
std::expected< T, std::error_code > result
result type wrapping a value or error code.