RTEMS 6.1-rc4
Loading...
Searching...
No Matches
sensor-lm75a.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (c) 2017 embedded brains GmbH & Co. KG
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _DEV_I2C_SENSOR_LM75A_H
37#define _DEV_I2C_SENSOR_LM75A_H
38
39#include <dev/i2c/i2c.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif /* __cplusplus */
44
55int i2c_dev_register_sensor_lm75a(
56 const char *bus_path,
57 const char *dev_path,
58 uint16_t address
59);
60
61typedef enum {
62 SENSOR_LM75A_GET_CONF = I2C_DEV_IO_CONTROL,
63 SENSOR_LM75A_SET_CONF,
64 SENSOR_LM75A_CLEAR_AND_SET_CONF,
65 SENSOR_LM75A_GET_TEMP,
66 SENSOR_LM75A_GET_TOS,
67 SENSOR_LM75A_SET_TOS,
68 SENSOR_LM75A_GET_THYST,
69 SENSOR_LM75A_SET_THYST
70} sensor_lm75a_command;
71
72static inline int sensor_lm75a_get_conf(int fd, uint8_t *val)
73{
74 return ioctl(fd, SENSOR_LM75A_GET_CONF, val);
75}
76
77static inline int sensor_lm75a_set_conf(int fd, uint8_t val)
78{
79 return ioctl(fd, SENSOR_LM75A_SET_CONF, (void *)(uintptr_t) val);
80}
81
82static inline int sensor_lm75a_clear_and_set_conf(
83 int fd,
84 uint8_t clear,
85 uint8_t set
86)
87{
88 uint16_t clear_and_set = (uint16_t) (((uint16_t) set << 8) | clear);
89
90 return ioctl(
91 fd,
92 SENSOR_LM75A_CLEAR_AND_SET_CONF,
93 (void *)(uintptr_t) clear_and_set
94 );
95}
96
97static inline int sensor_lm75a_get_temp(int fd, int16_t *val)
98{
99 return ioctl(fd, SENSOR_LM75A_GET_TEMP, val);
100}
101
102static inline int sensor_lm75a_get_temp_celsius(int fd, double *celsius)
103{
104 int rv;
105 int16_t val;
106
107 rv = ioctl(fd, SENSOR_LM75A_GET_TEMP, &val);
108 *celsius = (((int) val) >> 5) * 0.125;
109 return rv;
110}
111
112static inline int sensor_lm75a_get_tos(int fd, uint16_t *val)
113{
114 return ioctl(fd, SENSOR_LM75A_GET_TOS, val);
115}
116
117static inline int sensor_lm75a_set_tos(int fd, uint16_t val)
118{
119 return ioctl(fd, SENSOR_LM75A_SET_TOS, (void *)(uintptr_t) val);
120}
121
122static inline int sensor_lm75a_get_thyst(int fd, uint16_t *val)
123{
124 return ioctl(fd, SENSOR_LM75A_GET_THYST, val);
125}
126
127static inline int sensor_lm75a_set_thyst(int fd, uint16_t val)
128{
129 return ioctl(fd, SENSOR_LM75A_SET_THYST, (void *)(uintptr_t) val);
130}
131
134#ifdef __cplusplus
135}
136#endif /* __cplusplus */
137
138#endif /* _DEV_I2C_SENSOR_LM75A_H */
Inter-Integrated Circuit (I2C) Driver API.
#define I2C_DEV_IO_CONTROL
Base number for device IO control commands.
Definition: i2c.h:342