Zephyr API Documentation 4.0.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
w1_sensor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022, Thomas Stranger
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
15#ifndef ZEPHYR_INCLUDE_DRIVERS_SENSOR_W1_SENSOR_H_
16#define ZEPHYR_INCLUDE_DRIVERS_SENSOR_W1_SENSOR_H_
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
23#include <zephyr/drivers/w1.h>
24
36
43static inline void w1_rom_to_sensor_value(const struct w1_rom *rom,
44 struct sensor_value *val)
45{
46 val->val1 = sys_get_be64((uint8_t *)rom) & BIT64_MASK(32);
47 val->val2 = sys_get_be64((uint8_t *)rom) >> 32;
48}
49
56static inline void w1_sensor_value_to_rom(const struct sensor_value *val,
57 struct w1_rom *rom)
58{
59 uint64_t temp64 = ((uint64_t)((uint32_t)val->val2) << 32)
60 | (uint32_t)val->val1;
61 sys_put_be64(temp64, (uint8_t *)rom);
62}
63
68#ifdef __cplusplus
69}
70#endif
71
72#endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_W1_SENSOR_H_ */
@ SENSOR_ATTR_PRIV_START
This and higher values are sensor specific.
Definition sensor.h:359
#define BIT64_MASK(n)
64-bit bit mask with bits 0 through n-1 (inclusive) set, or 0 if n is 0.
Definition util_macro.h:74
static void w1_sensor_value_to_rom(const struct sensor_value *val, struct w1_rom *rom)
Function to write an rom id stored in a sensor value to a struct w1_rom ptr.
Definition w1_sensor.h:56
static void w1_rom_to_sensor_value(const struct w1_rom *rom, struct sensor_value *val)
Function to write a w1_rom struct to an sensor value ptr.
Definition w1_sensor.h:43
sensor_attribute_w1
Definition w1_sensor.h:32
@ SENSOR_ATTR_W1_ROM
Device unique 1-Wire ROM.
Definition w1_sensor.h:34
Public APIs for the sensor driver.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Representation of a sensor readout value.
Definition sensor.h:51
int32_t val2
Fractional part of the value (in one-millionth parts).
Definition sensor.h:55
int32_t val1
Integer part of the value.
Definition sensor.h:53
w1_rom struct.
Definition w1.h:434
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:395
static uint64_t sys_get_be64(const uint8_t src[8])
Get a 64-bit integer stored in big-endian format.
Definition byteorder.h:576
Public 1-Wire Driver APIs.