RTEMS
6.3
Toggle main menu visibility
Loading...
Searching...
No Matches
cpukit
include
dev
i2c
ti-tmp112.h
1
/* SPDX-License-Identifier: BSD-2-Clause */
2
3
/*
4
* Copyright (c) 2016-2017 Chris Johns <chrisj@rtems.org>
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
* 1. Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the distribution.
15
*
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
* POSSIBILITY OF SUCH DAMAGE.
27
*/
28
29
/*
30
* TI TMP112
31
* http://www.ti.com/product/TMP112
32
*/
33
34
#ifndef TI_TMP112_H
35
#define TI_TMP112_H
36
37
#include <
dev/i2c/i2c.h
>
38
39
/*
40
* Confirguration.
41
*/
42
#define TI_TMP112_CR_0_25Hz (0 << 6)
43
#define TI_TMP112_CR_1Hz (1 << 6)
44
#define TI_TMP112_CR_4Hz (2 << 6)
/* default */
45
#define TI_TMP112_CR_8Hz (3 << 6)
46
#define TI_TMP112_EM_NORMAL (0 << 4)
/* default */
47
#define TI_TMP112_EM_EXTENDED (1 << 4)
48
#define TI_TMP112_SD_ON (0 << 8)
/* default */
49
#define TI_TMP112_SD_SHUTDOWN (1 << 8)
50
#define TI_TMP112_TM_COMPARATOR (0 << 9)
/* default */
51
#define TI_TMP112_TM_INTERRUPT (1 << 9)
52
#define TI_TMP112_POL_ALERT_LOW (0 << 10)
/* default */
53
#define TI_TMP112_POL_ALERT_HIGH (1 << 10)
54
#define TI_TMP112_FQL_1 (0 << 11)
/* default */
55
#define TI_TMP112_FQL_2 (1 << 11)
56
#define TI_TMP112_FQL_4 (2 << 11)
57
#define TI_TMP112_FQL_6 (3 << 11)
58
59
/*
60
* IO control interface.
61
*/
62
#define TI_TMP112_GET_TEMP (I2C_DEV_IO_CONTROL + 0)
63
#define TI_TMP112_GET_TEMP_RAW (I2C_DEV_IO_CONTROL + 1)
64
#define TI_TMP112_SET_CONFIG (I2C_DEV_IO_CONTROL + 2)
65
#define TI_TMP112_SET_LOW_TEMP (I2C_DEV_IO_CONTROL + 3)
66
#define TI_TMP112_SET_HIGH_TEMP (I2C_DEV_IO_CONTROL + 4)
67
68
/*
69
* Register the device.
70
*/
71
int
i2c_dev_register_ti_tmp112(
const
char
* bus_path,
72
const
char
* dev_path,
73
uint16_t address);
74
75
/*
76
* Get the temperature in degrees C x 10000. To print you would so:
77
*
78
* printf("Temperature is %3d.%04d\n", temp / 10000, temp % 10000);
79
*
80
* If the device is shutdown a single conversion is made waiting for the
81
* conversion to complete.
82
*/
83
static
inline
int
84
ti_tmp112_get_temperature(
int
fd,
int
* temp)
85
{
86
return
ioctl(fd, TI_TMP112_GET_TEMP, temp);
87
}
88
89
/*
90
* Get the temperature as the raw register value.
91
*
92
* If the device is shutdown a single conversion is made waiting for the
93
* conversion to complete.
94
*/
95
static
inline
int
96
ti_tmp112_get_temperature_raw(
int
fd,
unsigned
int
* temp)
97
{
98
return
ioctl(fd, TI_TMP112_GET_TEMP_RAW, temp);
99
}
100
101
/*
102
* Set the configuration.
103
*/
104
static
inline
int
105
ti_tmp112_adc_set_config(
int
fd, uint16_t config)
106
{
107
return
ioctl(fd, TI_TMP112_SET_CONFIG, (
void
*)(uintptr_t) config);
108
}
109
110
/*
111
* Set the low temperature.
112
*/
113
static
inline
int
114
ti_tmp112_set_low_temperator(
int
fd, uint16_t temp)
115
{
116
return
ioctl(fd, TI_TMP112_SET_LOW_TEMP, (
void
*)(uintptr_t) temp);
117
}
118
119
/*
120
* Set the high temperature.
121
*/
122
static
inline
int
123
ti_tmp112_adc_set_high_threshold(
int
fd, uint16_t level)
124
{
125
return
ioctl(fd, TI_TMP112_SET_HIGH_TEMP, (
void
*)(uintptr_t) level);
126
}
127
128
#endif
i2c.h
Inter-Integrated Circuit (I2C) Driver API.
Generated by
1.18.0