LwOW

group LWOW

Lightweight onewire.

Note

Functions with _raw suffix do no implement locking mechanism when used with operating system.

Defines

LWOW_UNUSED(x)

Unused variable macro

LWOW_ASSERT(msg, c)

Assert check function.

It returns lwowERRPAR if condition check fails

Parameters
  • msg[in] Optional message parameter to print on failure

  • c[in] Condition to check for

LWOW_ASSERT0(msg, c)

Assert check function with return 0

It returns 0 if condition check fails

Parameters
  • msg[in] Optional message parameter to print on failure

  • c[in] Condition to check for

LWOW_ARRAYSIZE(x)

Get size of statically declared array.

Parameters
  • x[in] Input array

Returns

Number of array elements

LWOW_CMD_RSCRATCHPAD

Read scratchpad command for 1-Wire devices

LWOW_CMD_WSCRATCHPAD

Write scratchpad command for 1-Wire devices

LWOW_CMD_CPYSCRATCHPAD

Copy scratchpad command for 1-Wire devices

LWOW_CMD_RECEEPROM

Read EEPROM command

LWOW_CMD_RPWRSUPPLY

Read power supply command

LWOW_CMD_SEARCHROM

Search ROM command

LWOW_CMD_READROM

Read ROM command

LWOW_CMD_MATCHROM

Match ROM command. Select device with specific ROM

LWOW_CMD_SKIPROM

Skip ROM, select all devices

Typedefs

typedef lwowr_t (*lwow_search_cb_fn)(lwow_t *const owobj, const lwow_rom_t *const rom_id, size_t index, void *arg)

Search callback function implementation.

Param ow

[in] 1-Wire handle

Param rom_id

[in] Rom address when new device detected. Set to NULL when search finished

Param index

[in] Current device index When rom_id = NULL, value indicates number of total devices found

Param arg

[in] Custom user argument

Return

lwowOK on success, member of lwowr_t otherwise

Enums

enum lwowr_t

1-Wire result enumeration

Values:

enumerator lwowOK = 0x00

Device returned OK

enumerator lwowERRPRESENCE

Presence was not successful

enumerator lwowERRNODEV

No device connected, maybe device removed during scan?

enumerator lwowERRTXRX

Error while exchanging data

enumerator lwowERRBAUD

Error setting baudrate

enumerator lwowERRPAR

Parameter error

enumerator lwowERR

General-Purpose error

Functions

lwowr_t lwow_init(lwow_t *const owobj, const lwow_ll_drv_t *const ll_drv, void *arg)

Initialize OneWire instance.

Parameters
  • owobj[in] OneWire instance

  • ll_drv[in] Low-level driver

  • arg[in] Custom argument

Returns

lwowOK on success, member of lwowr_t otherwise

void lwow_deinit(lwow_t *const ow)

Deinitialize OneWire instance.

Parameters

owobj[in] OneWire instance

lwowr_t lwow_protect(lwow_t *const owobj, const uint8_t protect)

Protect 1-wire from concurrent access.

Note

Used only for OS systems

Parameters
  • owobj[inout] 1-Wire handle

  • protect[in] Set to 1 to protect core, 0 otherwise

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_unprotect(lwow_t *const owobj, const uint8_t protect)

Unprotect 1-wire from concurrent access, previously protected with lwow_protect.

Note

Used only for OS systems

Parameters
  • owobj[inout] 1-Wire handle

  • protect[in] Set to 1 to unprotect core, 0 otherwise

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_reset_raw(lwow_t *const owobj)

Reset 1-Wire bus and set connected devices to idle state.

Parameters

owobj[inout] 1-Wire handle

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_reset(lwow_t *const owobj)

Reset 1-Wire bus and set connected devices to idle state.

Note

This function is thread-safe

Parameters

owobj[inout] 1-Wire handle

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_write_byte_ex_raw(lwow_t *const owobj, const uint8_t btw, uint8_t *const byr)

Write byte over OW and read its response.

Parameters
  • owobj[inout] 1-Wire handle

  • btw[in] Byte to write

  • byr[out] Pointer to read value. Set to NULL if not used

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_write_byte_ex(lwow_t *const owobj, const uint8_t btw, uint8_t *const byr)

Write byte over OW and read its response.

Note

This function is thread-safe

Parameters
  • owobj[inout] 1-Wire handle

  • btw[in] Byte to write

  • byr[out] Pointer to read value. Set to NULL if not used

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_read_byte_ex_raw(lwow_t *const owobj, uint8_t *const byr)

Read byte from OW device.

Parameters
  • owobj[inout] 1-Wire handle

  • byr[out] Pointer to save read value

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_read_byte_ex(lwow_t *const owobj, uint8_t *const byr)

Read byte from OW device.

Note

This function is thread-safe

Parameters
  • owobj[inout] 1-Wire handle

  • byr[out] Pointer to save read value

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_read_bit_ex_raw(lwow_t *const owobj, uint8_t *const byr)

Read sinle bit from OW device.

Parameters
  • owobj[inout] 1-Wire handle

  • br[out] Pointer to save read value, either 1 or 0

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_read_bit_ex(lwow_t *const owobj, uint8_t *const byr)

Read sinle bit from OW device.

Note

This function is thread-safe

Parameters
  • owobj[inout] 1-Wire handle

  • br[out] Pointer to save read value, either 1 or 0

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_search_reset_raw(lwow_t *const ow)

Reset search.

Parameters

owobj[inout] 1-Wire handle

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_search_reset(lwow_t *const ow)

Reset search.

Note

This function is thread-safe

Parameters

owobj[inout] 1-Wire handle

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_search_raw(lwow_t *const owobj, lwow_rom_t *const rom_id)

Search for devices on 1-wire bus.

Note

To reset search and to start over, use lwow_search_reset function

Parameters
  • owobj[inout] 1-Wire handle

  • rom_id[out] Pointer to ROM structure to save ROM

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_search(lwow_t *const owobj, lwow_rom_t *const rom_id)

Search for devices on 1-wire bus.

Note

To reset search and to start over, use lwow_search_reset function

Note

This function is thread-safe

Parameters
  • owobj[inout] 1-Wire handle

  • rom_id[out] Pointer to ROM structure to save ROM

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_search_with_command_raw(lwow_t *const owobj, const uint8_t cmd, lwow_rom_t *const rom_id)

Search for devices on 1-wire bus with custom search command.

Note

To reset search and to start over, use lwow_search_reset function

Parameters
  • owobj[inout] 1-Wire handle

  • cmd[in] command to use for search operation

  • rom_id[out] Pointer to ROM structure to store address

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_search_with_command(lwow_t *const owobj, const uint8_t cmd, lwow_rom_t *const rom_id)

Search for devices on 1-wire bus with custom search command.

Note

To reset search and to start over, use lwow_search_reset function

Note

This function is thread-safe

Parameters
  • owobj[inout] 1-Wire handle

  • cmd[in] command to use for search operation

  • rom_id[out] Pointer to ROM structure to store address

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_search_with_command_callback(lwow_t *const owobj, const uint8_t cmd, size_t *const roms_found, const lwow_search_cb_fn func, void *const arg)

Search devices on 1-wire network by using callback function and custom search command.

When new device is detected, callback function func is called to notify user

Note

This function is thread-safe

Parameters
  • owobj[in] 1-Wire handle

  • cmd[in] 1-Wire search command

  • roms_found[out] Output variable to save number of found devices. Set to NULL if not used

  • func[in] Callback function to call for each device

  • arg[in] Custom user argument, used in callback function

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_search_with_callback(lwow_t *const owobj, size_t *const roms_found, const lwow_search_cb_fn func, void *const arg)

Search devices on 1-wire network by using callback function and SEARCH_ROM 1-Wire command.

When new device is detected, callback function func is called to notify user

Note

This function is thread-safe

Parameters
  • owobj[in] 1-Wire handle

  • roms_found[out] Output variable to save number of found devices. Set to NULL if not used

  • func[in] Callback function to call for each device

  • arg[in] Custom user argument, used in callback function

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_search_devices_with_command_raw(lwow_t *const owobj, const uint8_t cmd, lwow_rom_t *const rom_id_arr, const size_t rom_len, size_t *const roms_found)

Search for devices on 1-Wire network with command and store ROM IDs to input array.

Parameters
  • owobj[in] 1-Wire handle

  • cmd[in] 1-Wire search command

  • rom_id_arr[in] Pointer to output array to store found ROM IDs into

  • rom_len[in] Length of input ROM array

  • roms_found[out] Output variable to save number of found devices. Set to NULL if not used

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_search_devices_with_command(lwow_t *const owobj, const uint8_t cmd, lwow_rom_t *const rom_id_arr, const size_t rom_len, size_t *const roms_found)

Search for devices on 1-Wire network with command and store ROM IDs to input array.

Note

This function is thread-safe

Parameters
  • owobj[in] 1-Wire handle

  • cmd[in] 1-Wire search command

  • rom_id_arr[in] Pointer to output array to store found ROM IDs into

  • rom_len[in] Length of input ROM array

  • roms_found[out] Output variable to save number of found devices. Set to NULL if not used

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_search_devices_raw(lwow_t *const owobj, lwow_rom_t *const rom_id_arr, const size_t rom_len, size_t *const roms_found)

Search for devices on 1-Wire network with default command and store ROM IDs to input array.

Parameters
  • owobj[in] 1-Wire handle

  • rom_id_arr[in] Pointer to output array to store found ROM IDs into

  • rom_len[in] Length of input ROM array

  • roms_found[out] Output variable to save number of found devices. Set to NULL if not used

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_search_devices(lwow_t *const owobj, lwow_rom_t *const rom_id_arr, const size_t rom_len, size_t *const roms_found)

Search for devices on 1-Wire network with default command and store ROM IDs to input array.

Note

This function is thread-safe

Parameters
  • owobj[in] 1-Wire handle

  • rom_id_arr[in] Pointer to output array to store found ROM IDs into

  • rom_len[in] Length of input ROM array

  • roms_found[out] Output variable to save number of found devices. Set to NULL if not used

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_match_rom_raw(lwow_t *const owobj, const lwow_rom_t *const rom_id)

Select device on 1-wire network with exact ROM number.

Parameters
  • owobj[in] 1-Wire handle

  • rom_id[in] 1-Wire device address to match device

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_match_rom(lwow_t *const owobj, const lwow_rom_t *const rom_id)

Select device on 1-wire network with exact ROM number.

Note

This function is thread-safe

Parameters
  • owobj[in] 1-Wire handle

  • rom_id[in] 1-Wire device address to match device

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_match_or_skip_rom_raw(lwow_t *const owobj, const lwow_rom_t *const rom_id)

Select specific device or send skip ROM command, depending on the rom_id parameter.

Parameters
  • owobj[in] 1-Wire handle

  • rom_id[in] 1-Wire device address to match device or NULL to skip the match

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_match_or_skip_rom(lwow_t *const owobj, const lwow_rom_t *const rom_id)

Select specific device or send skip ROM command, depending on the rom_id parameter.

Note

This function is thread-safe

Parameters
  • owobj[in] 1-Wire handle

  • rom_id[in] 1-Wire device address to match device or NULL to skip the match

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_skip_rom_raw(lwow_t *const owobj)

Skip ROM address and select all devices on the network.

Parameters

owobj[in] 1-Wire handle

Returns

lwowOK on success, member of lwowr_t otherwise

lwowr_t lwow_skip_rom(lwow_t *const owobj)

Skip ROM address and select all devices on the network.

Note

This function is thread-safe

Parameters

owobj[in] 1-Wire handle

Returns

lwowOK on success, member of lwowr_t otherwise

uint8_t lwow_crc(const void *const in, const size_t len)

Calculate CRC-8 of input data.

Note

This function is reentrant

Parameters
  • inp[in] Input data

  • len[in] Number of bytes

Returns

Calculated CRC

struct lwow_rom_t
#include <lwow.h>

ROM structure.

Public Members

uint8_t rom[8]

8-bytes ROM address

struct lwow_t
#include <lwow.h>

1-Wire structure

Public Members

lwow_rom_t rom

ROM address of last device found. When searching for new devices, we always need last found address, to be able to decide which way to go next time during scan.

uint8_t disrepancy

Disrepancy value on last search

void *arg

User custom argument

const lwow_ll_drv_t *ll_drv

Low-level functions driver

LWOW_CFG_OS_MUTEX_HANDLE mutex

Mutex handle