37 #ifndef ONE_WIRE_BUS_H
38 #define ONE_WIRE_BUS_H
43 #include "driver/gpio.h"
51 #define OWB_ROM_SEARCH 0xF0
52 #define OWB_ROM_READ 0x33
53 #define OWB_ROM_MATCH 0x55
54 #define OWB_ROM_SKIP 0xCC
55 #define OWB_ROM_SEARCH_ALARM 0xEC
57 #define OWB_ROM_CODE_STRING_LENGTH (17)
60 # define GPIO_NUM_NC (-1)
70 const struct _OneWireBus_Timing *
timing;
88 uint8_t serial_number[6];
145 #define container_of(ptr, type, member) ({ \
146 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
147 (type *)( (char *)__mptr - offsetof(type,member) );})
285 uint8_t
owb_crc8_bytes(uint8_t crc,
const uint8_t * data,
size_t len);
owb_status owb_set_strong_pullup(const OneWireBus *bus, bool enable)
Enable or disable the strong-pullup GPIO, if configured.
owb_status owb_read_byte(const OneWireBus *bus, uint8_t *out)
Read a single byte from the 1-Wire bus.
uint8_t owb_crc8_byte(uint8_t crc, uint8_t data)
1-Wire 8-bit CRC lookup.
owb_status owb_read_rom(const OneWireBus *bus, OneWireBus_ROMCode *rom_code)
Read ROM code from device - only works when there is a single device on the bus.
owb_status owb_use_parasitic_power(OneWireBus *bus, bool use_parasitic_power)
Enable or disable use of parasitic power on the One Wire Bus. This affects how devices signal on the ...
uint8_t owb_crc8_bytes(uint8_t crc, const uint8_t *data, size_t len)
1-Wire 8-bit CRC lookup with accumulation over a block of bytes.
owb_status owb_write_rom_code(const OneWireBus *bus, OneWireBus_ROMCode rom_code)
Write a ROM code to the 1-Wire bus ensuring LSB is sent first.
owb_status owb_write_bytes(const OneWireBus *bus, const uint8_t *buffer, size_t len)
Write a number of bytes to the 1-Wire bus.
char * owb_string_from_rom_code(OneWireBus_ROMCode rom_code, char *buffer, size_t len)
Create a string representation of a ROM code, most significant byte (CRC8) first.
owb_status owb_read_bytes(const OneWireBus *bus, uint8_t *buffer, unsigned int len)
Read a number of bytes from the 1-Wire bus.
owb_status
Represents the result of OWB API functions.
@ OWB_STATUS_PARAMETER_NULL
Function was passed a null pointer.
@ OWB_STATUS_CRC_FAILED
CRC failed on data received from a device or devices.
@ OWB_STATUS_OK
Operation succeeded.
@ OWB_STATUS_TOO_MANY_BITS
Attempt to write an incorrect number of bits to the One Wire Bus.
@ OWB_STATUS_HW_ERROR
A hardware error occurred.
@ OWB_STATUS_NOT_SET
A status value has not been set.
@ OWB_STATUS_NOT_INITIALIZED
Function was passed an uninitialised variable.
@ OWB_STATUS_DEVICE_NOT_RESPONDING
No response received from the addressed device or devices.
owb_status owb_use_crc(OneWireBus *bus, bool use_crc)
Enable or disable use of CRC checks on device communications.
owb_status owb_read_bit(const OneWireBus *bus, uint8_t *out)
Read a single bit from the 1-Wire bus.
owb_status owb_uninitialize(OneWireBus *bus)
call to release resources after completing use of the OneWireBus
owb_status owb_write_byte(const OneWireBus *bus, uint8_t data)
Write a single byte to the 1-Wire bus.
owb_status owb_search_next(const OneWireBus *bus, OneWireBus_SearchState *state, bool *found_device)
Locates the next device on the 1-Wire bus, if present, starting from the provided state....
owb_status owb_write_bit(const OneWireBus *bus, uint8_t bit)
Write a bit to the 1-Wire bus.
owb_status owb_use_strong_pullup_gpio(OneWireBus *bus, gpio_num_t gpio)
Enable or disable use of extra GPIO to activate strong pull-up circuit. This only has effect if paras...
owb_status owb_search_first(const OneWireBus *bus, OneWireBus_SearchState *state, bool *found_device)
Locates the first device on the 1-Wire bus, if present.
owb_status owb_reset(const OneWireBus *bus, bool *is_present)
Reset the 1-Wire bus.
owb_status owb_verify_rom(const OneWireBus *bus, OneWireBus_ROMCode rom_code, bool *is_present)
Verify the device specified by ROM code is present.
Interface definitions for the ESP32 GPIO driver used to communicate with devices on the One Wire Bus.
Interface definitions for ESP32 RMT driver used to communicate with devices on the One Wire Bus.
Provides access via field names.
Represents the state of a device search on the 1-Wire bus.
int last_family_discrepancy
Bit index that identifies the last discrepancy within the first 8-bit family code of the ROM code.
int last_device_flag
Flag to indicate previous search was the last device detected.
OneWireBus_ROMCode rom_code
Device ROM code.
int last_discrepancy
Bit index that identifies from which bit the next search discrepancy check should start.
Structure containing 1-Wire bus information relevant to a single instance.
const struct _OneWireBus_Timing * timing
Pointer to timing information.
gpio_num_t strong_pullup_gpio
Set if an external strong pull-up circuit is required.
bool use_parasitic_power
True if parasitic-powered devices are expected on the bus.
const struct owb_driver * driver
Pointer to hardware driver instance.
bool use_crc
True if CRC checks are to be used when retrieving information from a device on the bus.
owb_status(* read_bits)(const OneWireBus *bus, uint8_t *in, int number_of_bits_to_read)
owb_status(* uninitialize)(const OneWireBus *bus)
owb_status(* write_bits)(const OneWireBus *bus, uint8_t out, int number_of_bits_to_write)
owb_status(* reset)(const OneWireBus *bus, bool *is_present)
Represents a 1-Wire ROM Code. This is a sequence of eight bytes, where the first byte is the family n...