14#ifndef ZEPHYR_INCLUDE_DRIVERS_W1_H_
15#define ZEPHYR_INCLUDE_DRIVERS_W1_H_
46#define W1_SLAVE_COUNT(node_id) \
47 (FOR_EACH(F1, (+), DT_SUPPORTS_DEP_ORDS(node_id)) - 1)
48#define W1_INST_SLAVE_COUNT(inst) \
49 (W1_SLAVE_COUNT(DT_DRV_INST(inst)))
206__syscall
int w1_change_bus_lock(
const struct device *dev,
bool lock);
208static inline int z_impl_w1_change_bus_lock(
const struct device *dev,
bool lock)
238 return w1_change_bus_lock(dev,
true);
252 return w1_change_bus_lock(dev,
false);
283static inline int z_impl_w1_reset_bus(
const struct device *dev)
297static inline int z_impl_w1_read_bit(
const struct device *dev)
312static inline int z_impl_w1_write_bit(
const struct device *dev,
bool bit)
326static inline int z_impl_w1_read_byte(
const struct device *dev)
341static inline int z_impl_w1_write_byte(
const struct device *dev,
uint8_t byte)
367 const uint8_t *buffer,
size_t len);
378static inline size_t z_impl_w1_get_slave_count(
const struct device *dev)
383 return ctrl_cfg->slave_count;
403static inline int z_impl_w1_configure(
const struct device *dev,
429#define W1_CMD_SKIP_ROM 0xCC
435#define W1_CMD_MATCH_ROM 0x55
441#define W1_CMD_RESUME 0xA5
449#define W1_CMD_READ_ROM 0x33
455#define W1_CMD_SEARCH_ROM 0xF0
461#define W1_CMD_SEARCH_ALARM 0xEC
467#define W1_CMD_OVERDRIVE_SKIP_ROM 0x3C
473#define W1_CMD_OVERDRIVE_MATCH_ROM 0x69
483#define W1_CRC8_SEED 0x00
485#define W1_CRC8_POLYNOMIAL 0x8C
487#define W1_CRC16_SEED 0x0000
489#define W1_CRC16_POLYNOMIAL 0xa001
494#define W1_SEARCH_ALL_FAMILIES 0x00
497#define W1_ROM_INIT_ZERO \
499 .family = 0, .serial = { 0 }, .crc = 0, \
640 const uint8_t *write_buf,
size_t write_len,
641 uint8_t *read_buf,
size_t read_len);
688 callback, user_data);
709 callback, user_data);
784#include <zephyr/syscalls/w1.h>
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
#define K_FOREVER
Generate infinite timeout delay.
Definition kernel.h:1761
uint8_t crc8(const uint8_t *src, size_t len, uint8_t polynomial, uint8_t initial_value, bool reversed)
Generic function for computing CRC 8.
uint16_t crc16_reflect(uint16_t poly, uint16_t seed, const uint8_t *src, size_t len)
Generic function for computing a CRC-16 with input and output reflection.
int k_mutex_unlock(struct k_mutex *mutex)
Unlock a mutex.
int k_mutex_lock(struct k_mutex *mutex, k_timeout_t timeout)
Lock a mutex.
int w1_read_bit(const struct device *dev)
Read a single bit from 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_bit(const struct device *dev, const bool bit)
Write a single bit to the 1-Wire bus.
size_t w1_get_slave_count(const struct device *dev)
Get the number of slaves on the 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_write_block(const struct device *dev, const uint8_t *buffer, size_t len)
Write a block of data to the 1-Wire bus.
int w1_reset_bus(const struct device *dev)
Reset the 1-Wire bus to prepare slaves for communication.
int w1_configure(const struct device *dev, enum w1_settings_type type, uint32_t value)
Configure parameters of the 1-Wire master.
int(* w1_write_bit_t)(const struct device *dev, bool bit)
Write a single bit to the 1-Wire bus.
Definition w1.h:118
int(* w1_write_byte_t)(const struct device *dev, const uint8_t byte)
Write a single byte to the 1-Wire bus.
Definition w1.h:130
w1_settings_type
Defines the 1-Wire master settings types, which are runtime configurable.
Definition w1.h:56
size_t(* w1_get_slave_count_t)(const struct device *dev)
Get the number of slaves on the bus.
Definition w1.h:150
static int w1_unlock_bus(const struct device *dev)
Unlock the 1-wire bus.
Definition w1.h:250
int(* w1_read_byte_t)(const struct device *dev)
Read a single byte from the 1-Wire bus.
Definition w1.h:124
int(* w1_reset_bus_t)(const struct device *dev)
Reset the 1-Wire bus to prepare slaves for communication.
Definition w1.h:106
int(* w1_change_bus_lock_t)(const struct device *dev, bool lock)
Lock or unlock the 1-Wire bus.
Definition w1.h:163
static int w1_lock_bus(const struct device *dev)
Lock the 1-wire bus to prevent simultaneous access.
Definition w1.h:236
int(* w1_configure_t)(const struct device *dev, enum w1_settings_type type, uint32_t value)
Configure parameters of the 1-Wire master.
Definition w1.h:156
int(* w1_read_bit_t)(const struct device *dev)
Read a single bit from the 1-Wire bus.
Definition w1.h:112
int(* w1_read_block_t)(const struct device *dev, uint8_t *buffer, size_t len)
Read a block of data from the 1-Wire bus.
Definition w1.h:136
int(* w1_write_block_t)(const struct device *dev, const uint8_t *buffer, size_t len)
Write a block of data to the 1-Wire bus.
Definition w1.h:143
@ W1_SETTING_SPEED
Overdrive speed is enabled in case a value of 1 is passed and disabled passing 0.
Definition w1.h:60
@ W1_SETINGS_TYPE_COUNT
Number of different settings types.
Definition w1.h:70
@ W1_SETTING_STRONG_PULLUP
The strong pullup resistor is activated immediately after the next written data block by passing a va...
Definition w1.h:65
static int w1_search_rom(const struct device *dev, w1_search_callback_t callback, void *user_data)
Search for 1-Wire slave on bus.
Definition w1.h:684
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.
Definition w1.h:705
static uint64_t w1_rom_to_uint64(const struct w1_rom *rom)
Function to convert a w1_rom struct to an uint64_t.
Definition w1.h:719
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.
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.
void(* w1_search_callback_t)(struct w1_rom rom, void *user_data)
Define the application callback handler function signature for searches.
Definition w1.h:542
static uint8_t w1_crc8(const uint8_t *src, size_t len)
Compute CRC-8 chacksum as defined in the 1-Wire specification.
Definition w1.h:747
int w1_match_rom(const struct device *dev, const struct w1_slave_config *config)
Select a specific slave by broadcasting a selected ROM.
static uint16_t w1_crc16(const uint16_t seed, const uint8_t *src, const size_t len)
Compute 1-Wire variant of CRC 16.
Definition w1.h:767
#define W1_CMD_SEARCH_ROM
This command allows the bus master to discover the addresses (i.e., ROM codes) of all slave devices o...
Definition w1.h:455
int w1_resume_command(const struct device *dev)
Select the slave last addressed with a Match ROM or Search ROM command.
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.
Definition w1.h:730
#define W1_SEARCH_ALL_FAMILIES
This flag can be passed to searches in order to not filter on family ID.
Definition w1.h:494
int w1_read_rom(const struct device *dev, struct w1_rom *rom)
Read Peripheral 64-bit 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.
#define W1_CRC8_SEED
Seed value used to calculate the 1-Wire 8-bit crc.
Definition w1.h:483
#define W1_CRC16_POLYNOMIAL
Polynomial used to calculate the 1-Wire 16-bit crc.
Definition w1.h:489
int w1_skip_rom(const struct device *dev, const struct w1_slave_config *config)
Select all slaves regardless of ROM.
#define W1_CRC8_POLYNOMIAL
Polynomial used to calculate the 1-Wire 8-bit crc.
Definition w1.h:485
#define W1_CMD_SEARCH_ALARM
This command allows the bus master to identify which devices have experienced an alarm condition.
Definition w1.h:461
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
void * data
Address of the device instance private data.
Definition device.h:523
const void * config
Address of device instance config information.
Definition device.h:517
Kernel mutex structure.
Definition kernel.h:3572
@driver_ops{1-Wire}
Definition w1.h:168
w1_write_block_t write_block
@driver_ops_optional Write a block of data to the 1-Wire bus.
Definition w1.h:192
w1_configure_t configure
@driver_ops_mandatory Configure parameters of the 1-Wire master.
Definition w1.h:194
w1_reset_bus_t reset_bus
@driver_ops_mandatory Reset the 1-Wire bus to prepare slaves for communication.
Definition w1.h:170
w1_change_bus_lock_t change_bus_lock
@driver_ops_optional Lock or unlock bus access.
Definition w1.h:200
w1_read_block_t read_block
@driver_ops_optional Read a block of data from the 1-Wire bus.
Definition w1.h:185
w1_write_bit_t write_bit
@driver_ops_mandatory Write a single bit to the 1-Wire bus.
Definition w1.h:174
w1_read_bit_t read_bit
@driver_ops_mandatory Read a single bit from the 1-Wire bus.
Definition w1.h:172
w1_write_byte_t write_byte
@driver_ops_mandatory Write a single byte to the 1-Wire bus.
Definition w1.h:178
w1_read_byte_t read_byte
@driver_ops_mandatory Read a single byte from the 1-Wire bus.
Definition w1.h:176
@def_driverbackendgroup{1-Wire,w1_interface}
Definition w1.h:85
uint16_t slave_count
Number of connected slaves.
Definition w1.h:87
Data common to all 1-Wire master implementations.
Definition w1.h:97
struct k_mutex bus_lock
The mutex used by w1_lock_bus() and w1_unlock_bus() methods.
Definition w1.h:99
w1_rom struct.
Definition w1.h:505
uint8_t serial[6]
The serial together with the family code composes the unique 56-bit id.
Definition w1.h:514
uint8_t crc
8-bit checksum of the 56-bit unique id.
Definition w1.h:516
uint8_t family
The 1-Wire family code identifying the slave device type.
Definition w1.h:512
Node specific 1-wire configuration struct.
Definition w1.h:525
struct w1_rom rom
Unique 1-Wire ROM.
Definition w1.h:527
uint32_t overdrive
overdrive speed is used if set to 1.
Definition w1.h:529
static void sys_put_be64(uint64_t val, uint8_t dst[8])
Put a 64-bit integer as big-endian to arbitrary location.
Definition byteorder.h:409
static uint64_t sys_get_be64(const uint8_t src[8])
Get a 64-bit integer stored in big-endian format.
Definition byteorder.h:590
CRC computation function.