jc42.h
3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright (C) 2017 Koen Zandberg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup drivers_jc42 JC42 compliant temperature sensor driver
* @ingroup drivers_sensors
*
* @brief JC42 compliant temperature sensor driver
*
* ## Description
*
* The connection between the MCU and jc42 compliant temperature sensors is
* based on a I2C-interface. There are multiple jc42 compliant temperature
* sensors available such as the mcp9804 and the MAX6604. This driver reads the
* temperature from these sensors. The sensors support a alarm wire, but this
* is not supported by this driver.
*
* @{
*
* @file
* @brief Driver for jc42 compliant temperature sensors
*
* @author Koen Zandberg <koen@bergzand.net>
*/
#ifndef JC42_H
#define JC42_H
#include "periph/i2c.h"
#include "saul.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @name jc42 status return codes
* @{
*/
#define JC42_OK (0)
#define JC42_NOI2C (-1)
#define JC42_NODEV (-2)
/** @} */
/**
* @brief Device descriptor for a jc42 device
*/
typedef struct {
i2c_t i2c; /**< I2C device that sensor is connected to */
uint8_t addr; /**< I2C address of this particular sensor */
} jc42_t;
/**
* @brief Device initialization parameters
*/
typedef struct {
i2c_t i2c; /**< I2C device that sensor is connected to */
i2c_speed_t speed; /**< I2C device speed */
uint8_t addr; /**< Configured address of the sensor */
} jc42_params_t;
/**
* @brief Export SAUL endpoint
*/
extern const saul_driver_t jc42_temperature_saul_driver;
/**
* @brief Initialize a jc42 device
*
* @param[out] dev device descriptor
* @param[in] params jc42 initialization struct
*
*
* @return 0 on success
* @return -1 on error
*/
int jc42_init(jc42_t* dev, const jc42_params_t* params);
/**
* @brief Get content of configuration register
*
* @param[in] dev device descriptor
* @param[out] data buffer where config register will be written to
*
* @return 0 on success
* @return -1 on error
*/
int jc42_get_config(const jc42_t* dev, uint16_t* data);
/**
* @brief Set content of configuration register
*
* @param[in] dev device descriptor
* @param[in] data new value for configuration register
*
* @return 0 on success
* @return -1 on error
*/
int jc42_set_config(const jc42_t* dev, uint16_t data);
/**
* @brief Get measured temperature
*
* @param[in] dev device descriptor
* @param[out] temperature uint16_t buffer where temperature will be written to in centi-degree
*
* @return 0 on success
* @return -1 on error
*/
int jc42_get_temperature(const jc42_t* dev, int16_t* temperature);
#ifdef __cplusplus
}
#endif
#endif /* JC42_H */
/** @} */