Zephyr Project API  3.2.0
A Scalable Open Source RTOS
w1.h File Reference

Public 1-Wire Driver APIs. More...

#include <zephyr/types.h>
#include <zephyr/device.h>
#include <zephyr/sys/crc.h>
#include <zephyr/sys/byteorder.h>
#include <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
 
#define W1_ROM_INIT_ZERO
 
1-Wire ROM Commands
#define W1_CMD_SKIP_ROM   0xCC
 
#define W1_CMD_MATCH_ROM   0x55
 
#define W1_CMD_RESUME   0xA5
 
#define W1_CMD_READ_ROM   0x33
 
#define W1_CMD_SEARCH_ROM   0xF0
 
#define W1_CMD_SEARCH_ALARM   0xEC
 
#define W1_CMD_OVERDRIVE_SKIP_ROM   0x3C
 
#define W1_CMD_OVERDRIVE_MATCH_ROM   0x69
 
CRC Defines
#define W1_CRC8_SEED   0x00
 
#define W1_CRC8_POLYNOMIAL   0x8C
 
#define W1_CRC16_SEED   0x0000
 
#define W1_CRC16_POLYNOMIAL   0xa001
 

Typedefs

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

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. More...
 
static int w1_unlock_bus (const struct device *dev)
 Unlock the 1-wire bus. More...
 
int w1_reset_bus (const struct device *dev)
 Reset the 1-Wire bus to prepare slaves for communication. More...
 
int w1_read_bit (const struct device *dev)
 Read a single bit from the 1-Wire bus. More...
 
int w1_write_bit (const struct device *dev, const bool bit)
 Write a single bit to the 1-Wire bus. More...
 
int w1_read_byte (const struct device *dev)
 Read a single byte from the 1-Wire bus. More...
 
int w1_write_byte (const struct device *dev, uint8_t byte)
 Write a single byte to the 1-Wire bus. More...
 
int w1_read_block (const struct device *dev, uint8_t *buffer, size_t len)
 Read a block of data from the 1-Wire bus. More...
 
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. More...
 
size_t w1_get_slave_count (const struct device *dev)
 Get the number of slaves on the bus. More...
 
int w1_configure (const struct device *dev, enum w1_settings_type type, uint32_t value)
 Configure parameters of the 1-Wire master. More...
 
int w1_read_rom (const struct device *dev, struct w1_rom *rom)
 Read Peripheral 64-bit ROM. More...
 
int w1_match_rom (const struct device *dev, const struct w1_slave_config *config)
 Select a specific slave by broadcasting a selected ROM. More...
 
int w1_resume_command (const struct device *dev)
 Select the slave last addressed with a Match ROM or Search ROM commnad. More...
 
int w1_skip_rom (const struct device *dev, const struct w1_slave_config *config)
 Select all slaves regardless of ROM. More...
 
int w1_reset_select (const struct device *dev, const struct w1_slave_config *config)
 In single drop configurations use Skip Select command, otherweise use Match ROM command. More...
 
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. More...
 
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. More...
 
static int w1_search_rom (const struct device *dev, w1_search_callback_t callback, void *user_data)
 Search for 1-Wire slave on bus. More...
 
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. More...
 
static uint64_t w1_rom_to_uint64 (const struct w1_rom *rom)
 Function to convert a w1_rom struct to an uint64_t. More...
 
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. More...
 
static uint8_t w1_crc8 (const uint8_t *src, size_t len)
 Compute CRC-8 chacksum as defined in the 1-Wire specification. More...
 
static uint16_t w1_crc16 (const uint16_t seed, const uint8_t *src, const size_t len)
 Compute 1-Wire variant of CRC 16. More...
 

Detailed Description

Public 1-Wire Driver APIs.