Zephyr API Documentation 4.0.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
w1.h File Reference

Public 1-Wire Driver APIs. More...

#include <zephyr/types.h>
#include <zephyr/device.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/crc.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/syscalls/w1.h>

Go to the source code of this file.

Data Structures

struct  w1_rom
 w1_rom struct. More...
 
struct  w1_slave_config
 Node specific 1-wire configuration struct. More...
 

Macros

#define W1_SEARCH_ALL_FAMILIES   0x00
 This flag can be passed to searches in order to not filter on family ID.
 
#define W1_ROM_INIT_ZERO
 Initialize all w1_rom struct members to zero.
 
1-Wire ROM Commands
#define W1_CMD_SKIP_ROM   0xCC
 This command allows the bus master to read the slave devices without providing their ROM code.
 
#define W1_CMD_MATCH_ROM   0x55
 This command allows the bus master to address a specific slave device by providing its ROM code.
 
#define W1_CMD_RESUME   0xA5
 This command allows the bus master to resume a previous read out from where it left off.
 
#define W1_CMD_READ_ROM   0x33
 This command allows the bus master to read the ROM code from a single slave device.
 
#define W1_CMD_SEARCH_ROM   0xF0
 This command allows the bus master to discover the addresses (i.e., ROM codes) of all slave devices on the bus.
 
#define W1_CMD_SEARCH_ALARM   0xEC
 This command allows the bus master to identify which devices have experienced an alarm condition.
 
#define W1_CMD_OVERDRIVE_SKIP_ROM   0x3C
 This command allows the bus master to address all devices on the bus and then switch them to overdrive speed.
 
#define W1_CMD_OVERDRIVE_MATCH_ROM   0x69
 This command allows the bus master to address a specific device and switch it to overdrive speed.
 
CRC Defines
#define W1_CRC8_SEED   0x00
 Seed value used to calculate the 1-Wire 8-bit crc.
 
#define W1_CRC8_POLYNOMIAL   0x8C
 Polynomial used to calculate the 1-Wire 8-bit crc.
 
#define W1_CRC16_SEED   0x0000
 Seed value used to calculate the 1-Wire 16-bit crc.
 
#define W1_CRC16_POLYNOMIAL   0xa001
 Polynomial used to calculate the 1-Wire 16-bit crc.
 

Typedefs

typedef void(* w1_search_callback_t) (struct w1_rom rom, void *user_data)
 Define the application callback handler function signature for searches.
 

Enumerations

enum  w1_settings_type { W1_SETTING_SPEED , W1_SETTING_STRONG_PULLUP , W1_SETINGS_TYPE_COUNT }
 Defines the 1-Wire master settings types, which are runtime configurable. More...
 

Functions

static int w1_lock_bus (const struct device *dev)
 Lock the 1-wire bus to prevent simultaneous access.
 
static int w1_unlock_bus (const struct device *dev)
 Unlock the 1-wire bus.
 
int w1_reset_bus (const struct device *dev)
 Reset the 1-Wire bus to prepare slaves for communication.
 
int w1_read_bit (const struct device *dev)
 Read a single bit from the 1-Wire bus.
 
int w1_write_bit (const struct device *dev, const bool bit)
 Write a single bit to the 1-Wire bus.
 
int w1_read_byte (const struct device *dev)
 Read a single byte from the 1-Wire bus.
 
int w1_write_byte (const struct device *dev, uint8_t byte)
 Write a single byte to the 1-Wire bus.
 
int w1_read_block (const struct device *dev, uint8_t *buffer, size_t len)
 Read a block of data from the 1-Wire bus.
 
int w1_write_block (const struct device *dev, const uint8_t *buffer, size_t len)
 Write a block of data from the 1-Wire bus.
 
size_t w1_get_slave_count (const struct device *dev)
 Get the number of slaves on the bus.
 
int w1_configure (const struct device *dev, enum w1_settings_type type, uint32_t value)
 Configure parameters of the 1-Wire master.
 
int w1_read_rom (const struct device *dev, struct w1_rom *rom)
 Read Peripheral 64-bit ROM.
 
int w1_match_rom (const struct device *dev, const struct w1_slave_config *config)
 Select a specific slave by broadcasting a selected ROM.
 
int w1_resume_command (const struct device *dev)
 Select the slave last addressed with a Match ROM or Search ROM command.
 
int w1_skip_rom (const struct device *dev, const struct w1_slave_config *config)
 Select all slaves regardless of ROM.
 
int w1_reset_select (const struct device *dev, const struct w1_slave_config *config)
 In single drop configurations use Skip Select command, otherwise use Match ROM command.
 
int w1_write_read (const struct device *dev, const struct w1_slave_config *config, const uint8_t *write_buf, size_t write_len, uint8_t *read_buf, size_t read_len)
 Write then read data from the 1-Wire slave with matching ROM.
 
int w1_search_bus (const struct device *dev, uint8_t command, uint8_t family, w1_search_callback_t callback, void *user_data)
 Search 1-wire slaves on the bus.
 
static int w1_search_rom (const struct device *dev, w1_search_callback_t callback, void *user_data)
 Search for 1-Wire slave on bus.
 
static int w1_search_alarm (const struct device *dev, w1_search_callback_t callback, void *user_data)
 Search for 1-Wire slaves with an active alarm.
 
static uint64_t w1_rom_to_uint64 (const struct w1_rom *rom)
 Function to convert a w1_rom struct to an uint64_t.
 
static void w1_uint64_to_rom (const uint64_t rom64, struct w1_rom *rom)
 Function to write an uint64_t to struct w1_rom pointer.
 
static uint8_t w1_crc8 (const uint8_t *src, size_t len)
 Compute CRC-8 chacksum as defined in the 1-Wire specification.
 
static uint16_t w1_crc16 (const uint16_t seed, const uint8_t *src, const size_t len)
 Compute 1-Wire variant of CRC 16.
 

Detailed Description

Public 1-Wire Driver APIs.