esp32-owb
ESP32-compatible C library for Maxim Integrated 1-Wire Bus.
|
#include <stddef.h>
#include <stdbool.h>
#include <inttypes.h>
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "sdkconfig.h"
#include "driver/gpio.h"
#include "owb.h"
#include "owb_gpio.h"
Functions | |
owb_status | owb_uninitialize (OneWireBus *bus) |
call to release resources after completing use of the OneWireBus More... | |
owb_status | owb_use_crc (OneWireBus *bus, bool use_crc) |
Enable or disable use of CRC checks on device communications. More... | |
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 bus, as devices cannot signal by pulling the bus low when it is pulled high. More... | |
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 parasitic power mode is enabled. signal by pulling the bus low when it is pulled high. More... | |
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. More... | |
owb_status | owb_verify_rom (const OneWireBus *bus, OneWireBus_ROMCode rom_code, bool *is_present) |
Verify the device specified by ROM code is present. More... | |
owb_status | owb_reset (const OneWireBus *bus, bool *a_device_present) |
Reset the 1-Wire bus. More... | |
owb_status | owb_read_bit (const OneWireBus *bus, uint8_t *out) |
Read a single bit from the 1-Wire bus. More... | |
owb_status | owb_read_byte (const OneWireBus *bus, uint8_t *out) |
Read a single byte from the 1-Wire bus. More... | |
owb_status | owb_read_bytes (const OneWireBus *bus, uint8_t *buffer, unsigned int len) |
Read a number of bytes from the 1-Wire bus. More... | |
owb_status | owb_write_bit (const OneWireBus *bus, const uint8_t bit) |
Write a bit to the 1-Wire bus. More... | |
owb_status | owb_write_byte (const OneWireBus *bus, uint8_t data) |
Write a single byte to the 1-Wire bus. More... | |
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. More... | |
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. More... | |
uint8_t | owb_crc8_byte (uint8_t crc, uint8_t data) |
1-Wire 8-bit CRC lookup. More... | |
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. More... | |
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. More... | |
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. Further calls will yield additional devices, if present. More... | |
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. More... | |
owb_status | owb_set_strong_pullup (const OneWireBus *bus, bool enable) |
Enable or disable the strong-pullup GPIO, if configured. More... | |
owb_status owb_uninitialize | ( | OneWireBus * | bus | ) |
call to release resources after completing use of the OneWireBus
[in] | bus | Pointer to initialised bus instance. |
owb_status owb_use_crc | ( | OneWireBus * | bus, |
bool | use_crc | ||
) |
Enable or disable use of CRC checks on device communications.
[in] | bus | Pointer to initialised bus instance. |
[in] | use_crc | True to enable CRC checks, false to disable. |
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 bus, as devices cannot signal by pulling the bus low when it is pulled high.
[in] | bus | Pointer to initialised bus instance. |
[in] | use_parasitic_power | True to enable parasitic power, false to disable. |
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 parasitic power mode is enabled. signal by pulling the bus low when it is pulled high.
[in] | bus | Pointer to initialised bus instance. |
[in] | gpio | Set to GPIO number to use, or GPIO_NUM_NC to disable. |
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.
[in] | bus | Pointer to initialised bus instance. |
[out] | rom_code | the value read from the device's rom |
owb_status owb_verify_rom | ( | const OneWireBus * | bus, |
OneWireBus_ROMCode | rom_code, | ||
bool * | is_present | ||
) |
Verify the device specified by ROM code is present.
[in] | bus | Pointer to initialised bus instance. |
[in] | rom_code | ROM code to verify. |
[out] | is_present | Set to true if a device is present, false if not |
owb_status owb_reset | ( | const OneWireBus * | bus, |
bool * | is_present | ||
) |
Reset the 1-Wire bus.
[in] | bus | Pointer to initialised bus instance. |
[out] | is_present | set to true if at least one device is present on the bus |
owb_status owb_read_bit | ( | const OneWireBus * | bus, |
uint8_t * | out | ||
) |
Read a single bit from the 1-Wire bus.
[in] | bus | Pointer to initialised bus instance. |
[out] | out | The bit value read from the bus. |
owb_status owb_read_byte | ( | const OneWireBus * | bus, |
uint8_t * | out | ||
) |
Read a single byte from the 1-Wire bus.
[in] | bus | Pointer to initialised bus instance. |
[out] | out | The byte value read from the bus (lsb only). |
owb_status owb_read_bytes | ( | const OneWireBus * | bus, |
uint8_t * | buffer, | ||
unsigned int | len | ||
) |
Read a number of bytes from the 1-Wire bus.
[in] | bus | Pointer to initialised bus instance. |
[in,out] | buffer | Pointer to buffer to receive read data. |
[in] | len | Number of bytes to read, must not exceed length of receive buffer. |
owb_status owb_write_bit | ( | const OneWireBus * | bus, |
uint8_t | bit | ||
) |
Write a bit to the 1-Wire bus.
[in] | bus | Pointer to initialised bus instance. |
[in] | bit | Value to write (lsb only). |
owb_status owb_write_byte | ( | const OneWireBus * | bus, |
uint8_t | data | ||
) |
Write a single byte to the 1-Wire bus.
[in] | bus | Pointer to initialised bus instance. |
[in] | data | Byte value to write to bus. |
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.
[in] | bus | Pointer to initialised bus instance. |
[in] | buffer | Pointer to buffer to write data from. |
[in] | len | Number of bytes to write. |
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.
[in] | bus | Pointer to initialised bus instance. |
[in] | rom_code | ROM code to write to bus. |
uint8_t owb_crc8_byte | ( | uint8_t | crc, |
uint8_t | data | ||
) |
1-Wire 8-bit CRC lookup.
[in] | crc | Starting CRC value. Pass in prior CRC to accumulate. |
[in] | data | Byte to feed into CRC. |
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.
[in] | crc | Starting CRC value. Pass in prior CRC to accumulate. |
[in] | data | Array of bytes to feed into CRC. |
[in] | len | Length of data array in bytes. |
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.
[in] | bus | Pointer to initialised bus instance. |
[in,out] | state | Pointer to an existing search state structure. |
[out] | found_device | True if a device is found, false if no devices are found. If a device is found, the ROM Code can be obtained from the state. |
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. Further calls will yield additional devices, if present.
[in] | bus | Pointer to initialised bus instance. |
[in,out] | state | Pointer to an existing search state structure. |
[out] | found_device | True if a device is found, false if no devices are found. If a device is found, the ROM Code can be obtained from the state. |
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.
[in] | rom_code | The ROM code to convert to string representation. |
[out] | buffer | The destination for the string representation. It will be null terminated. |
[in] | len | The length of the buffer in bytes. 64-bit ROM codes require 16 characters to represent as a string, plus a null terminator, for 17 bytes. See OWB_ROM_CODE_STRING_LENGTH. |
owb_status owb_set_strong_pullup | ( | const OneWireBus * | bus, |
bool | enable | ||
) |
Enable or disable the strong-pullup GPIO, if configured.
[in] | bus | Pointer to initialised bus instance. |
[in] | enable | If true, enable the external strong pull-up by setting the GPIO high. If false, disable the external strong pull-up by setting the GPIO low. |