|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
1-Wire bus controller with thread-safe access. More...
Public Member Functions | |
| bus (gpio pin) | |
| Creates a new 1-Wire bus controller. | |
| ~bus ()=default | |
| bus (const bus &)=delete | |
| bus & | operator= (const bus &)=delete |
| bus (bus &&other) noexcept=default | |
| bus & | operator= (bus &&other) noexcept=default |
| void | lock () const |
| Acquires exclusive access to the bus. | |
| bool | try_lock () const noexcept |
| Tries to acquire exclusive access without blocking. | |
| void | unlock () const |
| Releases exclusive access to the bus. | |
| gpio | pin () const noexcept |
| Returns the GPIO pin. | |
| bool | reset () |
| Performs a 1-Wire reset cycle. | |
| void | select (address addr) |
| Selects a specific device by ROM address. | |
| void | skip_rom () |
| Selects all devices on the bus. | |
| result< void > | try_select (address addr) |
| Selects a specific device by ROM address. | |
| result< void > | try_skip_rom () |
| Selects all devices on the bus. | |
| void | write (uint8_t value) |
| Writes a single byte to the bus. | |
| void | write (std::span< const uint8_t > data) |
| Writes multiple bytes to the bus. | |
| result< void > | try_write (uint8_t value) |
| Writes a single byte to the bus. | |
| result< void > | try_write (std::span< const uint8_t > data) |
| Writes multiple bytes to the bus. | |
| uint8_t | read () |
| Reads a single byte from the bus. | |
| void | read (std::span< uint8_t > buf) |
| Reads multiple bytes from the bus into a buffer. | |
| result< uint8_t > | try_read () |
| Reads a single byte from the bus. | |
| result< void > | try_read (std::span< uint8_t > buf) |
| Reads multiple bytes from the bus into a buffer. | |
| void | power () |
| Actively drives the bus high for parasitic power. | |
| result< void > | try_power () |
| Actively drives the bus high for parasitic power. | |
| void | depower () noexcept |
| Stops driving power onto the bus. | |
| std::vector< address > | search (size_t max_devices=8) |
| Searches for all devices on the bus. | |
| std::vector< address > | search (uint8_t family_code, size_t max_devices=8) |
| Searches for devices with a specific family code. | |
| result< std::vector< address > > | try_search (size_t max_devices=8) |
| Searches for all devices on the bus. | |
| result< std::vector< address > > | try_search (uint8_t family_code, size_t max_devices=8) |
| Searches for devices with a specific family code. | |
Static Public Member Functions | |
| static result< bus > | make (gpio pin) |
| Creates a new 1-Wire bus controller. | |
1-Wire bus controller with thread-safe access.
Provides low-level 1-Wire bus operations: reset, ROM commands, data transfer, parasitic power control, and device search. Satisfies the Lockable named requirement for use with std::lock_guard and std::unique_lock.
This type is non-copyable and move-only. Result-returning methods on a moved-from object return errc::invalid_state. Simple accessors return default/null values. The Lockable methods (lock/try_lock/unlock) silently no-op on a moved-from object.
Definition at line 170 of file onewire.hpp.
|
explicit |
Creates a new 1-Wire bus controller.
| pin | GPIO pin connected to the 1-Wire bus. |
| std::system_error | if the pin is not connected. |
|
default |
|
defaultnoexcept |
|
noexcept |
|
inline |
Acquires exclusive access to the bus.
Definition at line 200 of file onewire.hpp.
Creates a new 1-Wire bus controller.
| pin | GPIO pin connected to the 1-Wire bus. |
| invalid_state | If the pin is not connected. |
|
inlinenoexcept |
Returns the GPIO pin.
Definition at line 224 of file onewire.hpp.
|
inline |
Actively drives the bus high for parasitic power.
Some devices need more power than the pull-up resistor can provide during certain operations (e.g., temperature conversion).
| std::system_error | on failure (e.g., bus is being held low). |
Definition at line 373 of file onewire.hpp.
References try_power(), and idfxx::unwrap().
|
inline |
Reads a single byte from the bus.
| std::system_error | on bus communication failure. |
Definition at line 334 of file onewire.hpp.
References try_read(), and idfxx::unwrap().
Reads multiple bytes from the bus into a buffer.
| buf | The buffer to read into. |
| std::system_error | on bus communication failure. |
Definition at line 343 of file onewire.hpp.
References try_read(), and idfxx::unwrap().
| bool idfxx::onewire::bus::reset | ( | ) |
Performs a 1-Wire reset cycle.
Must be called before issuing ROM commands (select/skip_rom).
Searches for all devices on the bus.
| max_devices | Maximum number of devices to discover. |
| std::system_error | on bus communication failure. |
Definition at line 405 of file onewire.hpp.
References try_search(), and idfxx::unwrap().
|
inline |
Searches for devices with a specific family code.
| family_code | The family code to filter by (e.g., 0x28 for DS18B20). |
| max_devices | Maximum number of devices to discover. |
| std::system_error | on bus communication failure. |
Definition at line 416 of file onewire.hpp.
References try_search(), and idfxx::unwrap().
Selects a specific device by ROM address.
Issues a "ROM select" command on the bus. A reset() must be performed before calling this method.
| addr | The ROM address of the device to select. |
| std::system_error | on bus communication failure. |
Definition at line 251 of file onewire.hpp.
References try_select(), and idfxx::unwrap().
|
inline |
Selects all devices on the bus.
Issues a "skip ROM" command. A reset() must be performed before calling this method.
| std::system_error | on bus communication failure. |
Definition at line 262 of file onewire.hpp.
References try_skip_rom(), and idfxx::unwrap().
|
inlinenoexcept |
Tries to acquire exclusive access without blocking.
Definition at line 208 of file onewire.hpp.
Actively drives the bus high for parasitic power.
Some devices need more power than the pull-up resistor can provide during certain operations (e.g., temperature conversion).
Referenced by power().
Reads multiple bytes from the bus into a buffer.
| buf | The buffer to read into. |
| result< std::vector< address > > idfxx::onewire::bus::try_search | ( | uint8_t | family_code, |
| size_t | max_devices = 8 |
||
| ) |
Searches for devices with a specific family code.
| family_code | The family code to filter by (e.g., 0x28 for DS18B20). |
| max_devices | Maximum number of devices to discover. |
Selects all devices on the bus.
Issues a "skip ROM" command. A reset() must be performed before calling this method.
Referenced by skip_rom().
Writes multiple bytes to the bus.
| data | The bytes to write. |
|
inline |
Releases exclusive access to the bus.
Definition at line 216 of file onewire.hpp.
Writes multiple bytes to the bus.
| data | The bytes to write. |
| std::system_error | on bus communication failure. |
Definition at line 305 of file onewire.hpp.
References try_write(), and idfxx::unwrap().
Writes a single byte to the bus.
| value | The byte to write. |
| std::system_error | on bus communication failure. |
Definition at line 296 of file onewire.hpp.
References try_write(), and idfxx::unwrap().