Zephyr API Documentation 4.4.99
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
16#ifndef ZEPHYR_INCLUDE_DRIVERS_SENSOR_W1_SENSOR_H_
17#define ZEPHYR_INCLUDE_DRIVERS_SENSOR_W1_SENSOR_H_
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
24#include <zephyr/drivers/w1.h>
25
33
52
59static inline void w1_rom_to_sensor_value(const struct w1_rom *rom,
60 struct sensor_value *val)
61{
62 val->val1 = sys_get_be64((uint8_t *)rom) & BIT64_MASK(32);
63 val->val2 = sys_get_be64((uint8_t *)rom) >> 32;
64}
65
72static inline void w1_sensor_value_to_rom(const struct sensor_value *val,
73 struct w1_rom *rom)
74{
75 uint64_t temp64 = ((uint64_t)((uint32_t)val->val2) << 32)
76 | (uint32_t)val->val1;
77 sys_put_be64(temp64, (uint8_t *)rom);
78}
79
83
84#ifdef __cplusplus
85}
86#endif
87
88#endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_W1_SENSOR_H_ */
@ SENSOR_ATTR_PRIV_START
This and higher values are sensor specific.
Definition sensor.h:448
#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:80
static void w1_sensor_value_to_rom(const struct sensor_value *val, struct w1_rom *rom)
Decode a sensor_value into a w1_rom.
Definition w1_sensor.h:72
static void w1_rom_to_sensor_value(const struct w1_rom *rom, struct sensor_value *val)
Encode a w1_rom as a sensor_value.
Definition w1_sensor.h:59
sensor_attribute_w1
Extended sensor attributes for 1-Wire sensors.
Definition w1_sensor.h:37
@ SENSOR_ATTR_W1_ROM
Device unique 1-Wire ROM identifier.
Definition w1_sensor.h:50
Main header file for sensor driver API.
__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:55
int32_t val2
Fractional part of the value (in one-millionth parts).
Definition sensor.h:59
int32_t val1
Integer part of the value.
Definition sensor.h:57
w1_rom struct.
Definition w1.h:414
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
Main header file for 1-Wire driver API.