RTEMS  5.0.0
sensor-lm75a.h
Go to the documentation of this file.
1 
9 /*
10  * Copyright (c) 2017 embedded brains GmbH. All rights reserved.
11  *
12  * embedded brains GmbH
13  * Dornierstr. 4
14  * 82178 Puchheim
15  * Germany
16  * <rtems@embedded-brains.de>
17  *
18  * The license and distribution terms for this file may be
19  * found in the file LICENSE in this distribution or at
20  * http://www.rtems.org/license/LICENSE.
21  */
22 
23 #ifndef _DEV_I2C_SENSOR_LM75A_H
24 #define _DEV_I2C_SENSOR_LM75A_H
25 
26 #include <dev/i2c/i2c.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31 
42 int i2c_dev_register_sensor_lm75a(
43  const char *bus_path,
44  const char *dev_path,
45  uint16_t address
46 );
47 
48 typedef enum {
49  SENSOR_LM75A_GET_CONF = I2C_DEV_IO_CONTROL,
50  SENSOR_LM75A_SET_CONF,
51  SENSOR_LM75A_CLEAR_AND_SET_CONF,
52  SENSOR_LM75A_GET_TEMP,
53  SENSOR_LM75A_GET_TOS,
54  SENSOR_LM75A_SET_TOS,
55  SENSOR_LM75A_GET_THYST,
56  SENSOR_LM75A_SET_THYST
57 } sensor_lm75a_command;
58 
59 static inline int sensor_lm75a_get_conf(int fd, uint8_t *val)
60 {
61  return ioctl(fd, SENSOR_LM75A_GET_CONF, val);
62 }
63 
64 static inline int sensor_lm75a_set_conf(int fd, uint8_t val)
65 {
66  return ioctl(fd, SENSOR_LM75A_SET_CONF, (void *)(uintptr_t) val);
67 }
68 
69 static inline int sensor_lm75a_clear_and_set_conf(
70  int fd,
71  uint8_t clear,
72  uint8_t set
73 )
74 {
75  uint16_t clear_and_set = (uint16_t) (((uint16_t) set << 8) | clear);
76 
77  return ioctl(
78  fd,
79  SENSOR_LM75A_CLEAR_AND_SET_CONF,
80  (void *)(uintptr_t) clear_and_set
81  );
82 }
83 
84 static inline int sensor_lm75a_get_temp(int fd, int16_t *val)
85 {
86  return ioctl(fd, SENSOR_LM75A_GET_TEMP, val);
87 }
88 
89 static inline int sensor_lm75a_get_temp_celsius(int fd, double *celsius)
90 {
91  int rv;
92  int16_t val;
93 
94  rv = ioctl(fd, SENSOR_LM75A_GET_TEMP, &val);
95  *celsius = (((int) val) >> 5) * 0.125;
96  return rv;
97 }
98 
99 static inline int sensor_lm75a_get_tos(int fd, uint16_t *val)
100 {
101  return ioctl(fd, SENSOR_LM75A_GET_TOS, val);
102 }
103 
104 static inline int sensor_lm75a_set_tos(int fd, uint16_t val)
105 {
106  return ioctl(fd, SENSOR_LM75A_SET_TOS, (void *)(uintptr_t) val);
107 }
108 
109 static inline int sensor_lm75a_get_thyst(int fd, uint16_t *val)
110 {
111  return ioctl(fd, SENSOR_LM75A_GET_THYST, val);
112 }
113 
114 static inline int sensor_lm75a_set_thyst(int fd, uint16_t val)
115 {
116  return ioctl(fd, SENSOR_LM75A_SET_THYST, (void *)(uintptr_t) val);
117 }
118 
121 #ifdef __cplusplus
122 }
123 #endif /* __cplusplus */
124 
125 #endif /* _DEV_I2C_SENSOR_LM75A_H */
#define I2C_DEV_IO_CONTROL
Base number for device IO control commands.
Definition: i2c.h:285
Inter-Integrated Circuit (I2C) Driver API.