RTEMS: cpukit/include/dev/i2c/ti-tmp112.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
ti-tmp112.h
1/*
2 * Copyright (c) 2016-2017 Chris Johns <chrisj@rtems.org>
3 * All rights reserved.
4 *
5 * The license and distribution terms for this file may be
6 * found in the file LICENSE in this distribution or at
7 * http://www.rtems.org/license/LICENSE.
8 */
9
10/*
11 * TI TMP112
12 * http://www.ti.com/product/TMP112
13 */
14
15#ifndef TI_TMP112_H
16#define TI_TMP112_H
17
18#include <dev/i2c/i2c.h>
19
20/*
21 * Confirguration.
22 */
23#define TI_TMP112_CR_0_25Hz (0 << 6)
24#define TI_TMP112_CR_1Hz (1 << 6)
25#define TI_TMP112_CR_4Hz (2 << 6) /* default */
26#define TI_TMP112_CR_8Hz (3 << 6)
27#define TI_TMP112_EM_NORMAL (0 << 4) /* default */
28#define TI_TMP112_EM_EXTENDED (1 << 4)
29#define TI_TMP112_SD_ON (0 << 8) /* default */
30#define TI_TMP112_SD_SHUTDOWN (1 << 8)
31#define TI_TMP112_TM_COMPARATOR (0 << 9) /* default */
32#define TI_TMP112_TM_INTERRUPT (1 << 9)
33#define TI_TMP112_POL_ALERT_LOW (0 << 10) /* default */
34#define TI_TMP112_POL_ALERT_HIGH (1 << 10)
35#define TI_TMP112_FQL_1 (0 << 11) /* default */
36#define TI_TMP112_FQL_2 (1 << 11)
37#define TI_TMP112_FQL_4 (2 << 11)
38#define TI_TMP112_FQL_6 (3 << 11)
39
40/*
41 * IO control interface.
42 */
43#define TI_TMP112_GET_TEMP (I2C_DEV_IO_CONTROL + 0)
44#define TI_TMP112_GET_TEMP_RAW (I2C_DEV_IO_CONTROL + 1)
45#define TI_TMP112_SET_CONFIG (I2C_DEV_IO_CONTROL + 2)
46#define TI_TMP112_SET_LOW_TEMP (I2C_DEV_IO_CONTROL + 3)
47#define TI_TMP112_SET_HIGH_TEMP (I2C_DEV_IO_CONTROL + 4)
48
49/*
50 * Register the device.
51 */
52int i2c_dev_register_ti_tmp112(const char* bus_path,
53 const char* dev_path,
54 uint16_t address);
55
56/*
57 * Get the temperature in degrees C x 10000. To print you would so:
58 *
59 * printf("Temperature is %3d.%04d\n", temp / 10000, temp % 10000);
60 *
61 * If the device is shutdown a single conversion is made waiting for the
62 * conversion to complete.
63 */
64static inline int
65ti_tmp112_get_temperature(int fd, int* temp)
66{
67 return ioctl(fd, TI_TMP112_GET_TEMP, temp);
68}
69
70/*
71 * Get the temperature as the raw register value.
72 *
73 * If the device is shutdown a single conversion is made waiting for the
74 * conversion to complete.
75 */
76static inline int
77ti_tmp112_get_temperature_raw(int fd, unsigned int* temp)
78{
79 return ioctl(fd, TI_TMP112_GET_TEMP_RAW, temp);
80}
81
82/*
83 * Set the configuration.
84 */
85static inline int
86ti_tmp112_adc_set_config(int fd, uint16_t config)
87{
88 return ioctl(fd, TI_TMP112_SET_CONFIG, (void *)(uintptr_t) config);
89}
90
91/*
92 * Set the low temperature.
93 */
94static inline int
95ti_tmp112_set_low_temperator(int fd, uint16_t temp)
96{
97 return ioctl(fd, TI_TMP112_SET_LOW_TEMP, (void *)(uintptr_t) temp);
98}
99
100/*
101 * Set the high temperature.
102 */
103static inline int
104ti_tmp112_adc_set_high_threshold(int fd, uint16_t level)
105{
106 return ioctl(fd, TI_TMP112_SET_HIGH_TEMP, (void *)(uintptr_t) level);
107}
108
109#endif
i2c.h
Inter-Integrated Circuit (I2C) Driver API.
config_s
Definition: deflate.c:115