/
ds18b20.h
89 lines (80 loc) · 2.46 KB
/
ds18b20.h
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
/**
* @file drivers/ds18b20.h
*
* @section License
* Copyright (C) 2014-2016, Erik Moqvist
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* This file is part of the Simba project.
*/
#ifndef __DRIVERS_DS18B20_H__
#define __DRIVERS_DS18B20_H__
#include "simba.h"
struct ds18b20_driver_t {
struct owi_driver_t *owi_p;
struct ds18b20_driver_t *next_p;
};
/**
* Initialize the DS18B20 driver module. This function must be called
* before calling any other function in this module.
*
* The module will only be initialized once even if this function is
* called multiple times.
*
* @return zero(0) or negative error code.
*/
int ds18b20_module_init(void);
/**
* Initialize given driver object.
*
* @param[out] self_p Driver object to be initialized.
* @param[in] owi_p One-Wire (OWI) driver.
*
* @return zero(0) or negative error code.
*/
int ds18b20_init(struct ds18b20_driver_t *self_p,
struct owi_driver_t *owi_p);
/**
* Start temperature convertion on all sensors.
*
* @param[in] self_p Driver object to be initialized.
*
* @return zero(0) or negative error code.
*/
int ds18b20_convert(struct ds18b20_driver_t *self_p);
/**
* Get the temperature for given device identity.
*
* @param[in] self_p Driver object to be initialized.
* @param[in] id_p Device identity.
* @param[out] temp_p Measured temperature in Q4.4 to Q8.4 depending
* on resolution.
*
* @return zero(0) or negative error code.
*/
int ds18b20_get_temperature(struct ds18b20_driver_t *self_p,
uint8_t *id_p,
int *temp_p);
/**
* Get temperature for given device identity returned formatted as a
* string.
*
* @param[in] self_p Driver object to be initialized.
* @param[in] id_p Device identity.
* @param[in] buf_p Buffer.
*
* @return Buffer or NULL.
*/
char *ds18b20_get_temperature_str(struct ds18b20_driver_t *self_p,
uint8_t *id_p,
char *buf_p);
#endif