esp32-owb
ESP32-compatible C library for Maxim Integrated 1-Wire Bus.
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Pages
Functions
/home/travis/build/DavidAntliff/esp32-owb/owb.c File Reference
#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...
 

Function Documentation

owb_status owb_uninitialize ( OneWireBus bus)

call to release resources after completing use of the OneWireBus

Parameters
[in]busPointer to initialised bus instance.
Returns
status
owb_status owb_use_crc ( OneWireBus bus,
bool  use_crc 
)

Enable or disable use of CRC checks on device communications.

Parameters
[in]busPointer to initialised bus instance.
[in]use_crcTrue to enable CRC checks, false to disable.
Returns
status
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.

Parameters
[in]busPointer to initialised bus instance.
[in]use_parasitic_powerTrue to enable parasitic power, false to disable.
Returns
status
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.

Parameters
[in]busPointer to initialised bus instance.
[in]gpioSet to GPIO number to use, or GPIO_NUM_NC to disable.
Returns
status
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.

Parameters
[in]busPointer to initialised bus instance.
[out]rom_codethe value read from the device's rom
Returns
status
owb_status owb_verify_rom ( const OneWireBus bus,
OneWireBus_ROMCode  rom_code,
bool *  is_present 
)

Verify the device specified by ROM code is present.

Parameters
[in]busPointer to initialised bus instance.
[in]rom_codeROM code to verify.
[out]is_presentSet to true if a device is present, false if not
Returns
status
owb_status owb_reset ( const OneWireBus bus,
bool *  is_present 
)

Reset the 1-Wire bus.

Parameters
[in]busPointer to initialised bus instance.
[out]is_presentset to true if at least one device is present on the bus
Returns
status
owb_status owb_read_bit ( const OneWireBus bus,
uint8_t *  out 
)

Read a single bit from the 1-Wire bus.

Parameters
[in]busPointer to initialised bus instance.
[out]outThe bit value read from the bus.
Returns
status
owb_status owb_read_byte ( const OneWireBus bus,
uint8_t *  out 
)

Read a single byte from the 1-Wire bus.

Parameters
[in]busPointer to initialised bus instance.
[out]outThe byte value read from the bus (lsb only).
Returns
status
owb_status owb_read_bytes ( const OneWireBus bus,
uint8_t *  buffer,
unsigned int  len 
)

Read a number of bytes from the 1-Wire bus.

Parameters
[in]busPointer to initialised bus instance.
[in,out]bufferPointer to buffer to receive read data.
[in]lenNumber of bytes to read, must not exceed length of receive buffer.
Returns
status.
owb_status owb_write_bit ( const OneWireBus bus,
uint8_t  bit 
)

Write a bit to the 1-Wire bus.

Parameters
[in]busPointer to initialised bus instance.
[in]bitValue to write (lsb only).
Returns
status
owb_status owb_write_byte ( const OneWireBus bus,
uint8_t  data 
)

Write a single byte to the 1-Wire bus.

Parameters
[in]busPointer to initialised bus instance.
[in]dataByte value to write to bus.
Returns
status
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.

Parameters
[in]busPointer to initialised bus instance.
[in]bufferPointer to buffer to write data from.
[in]lenNumber of bytes to write.
Returns
status
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.

Parameters
[in]busPointer to initialised bus instance.
[in]rom_codeROM code to write to bus.
Returns
status
uint8_t owb_crc8_byte ( uint8_t  crc,
uint8_t  data 
)

1-Wire 8-bit CRC lookup.

Parameters
[in]crcStarting CRC value. Pass in prior CRC to accumulate.
[in]dataByte to feed into CRC.
Returns
Resultant CRC value. Should be zero if last byte was the CRC byte and the CRC matches.
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.

Parameters
[in]crcStarting CRC value. Pass in prior CRC to accumulate.
[in]dataArray of bytes to feed into CRC.
[in]lenLength of data array in bytes.
Returns
Resultant CRC value. Should be zero if last byte was the CRC byte and the CRC matches.
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.

Parameters
[in]busPointer to initialised bus instance.
[in,out]statePointer to an existing search state structure.
[out]found_deviceTrue 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.
Returns
status
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.

Parameters
[in]busPointer to initialised bus instance.
[in,out]statePointer to an existing search state structure.
[out]found_deviceTrue 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.
Returns
status
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.

Parameters
[in]rom_codeThe ROM code to convert to string representation.
[out]bufferThe destination for the string representation. It will be null terminated.
[in]lenThe 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.
Returns
pointer to the byte beyond the last byte written
owb_status owb_set_strong_pullup ( const OneWireBus bus,
bool  enable 
)

Enable or disable the strong-pullup GPIO, if configured.

Parameters
[in]busPointer to initialised bus instance.
[in]enableIf 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.
Returns
status