-
Notifications
You must be signed in to change notification settings - Fork 38
/
drv_one_wire.c
133 lines (111 loc) · 4.05 KB
/
drv_one_wire.c
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
126
127
128
129
130
131
132
133
/****************************************************************************
**
** Copyright (C) ${COPYRIGHT_YEAR} MikroElektronika d.o.o.
** Contact: https://www.mikroe.com/contact
**
** This file is part of the mikroSDK package
**
** Commercial License Usage
**
** Licensees holding valid commercial NECTO compilers AI licenses may use this
** file in accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The MikroElektronika Company.
** For licensing terms and conditions see
** https://www.mikroe.com/legal/software-license-agreement.
** For further information use the contact form at
** https://www.mikroe.com/contact.
**
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used for
** non-commercial projects under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
****************************************************************************/
/*!
* @file drv_one_wire.c
* @brief One Wire driver implementation.
*/
#include "drv_one_wire.h"
err_t one_wire_open( one_wire_t *obj ) {
if ( !obj ) {
return ONE_WIRE_ERROR;
}
if ( HAL_PIN_NC == obj->data_pin || obj->state ) {
return ONE_WIRE_ERROR;
}
if ( ONE_WIRE_SUCCESS != hal_one_wire_open( obj ) ) {
return ONE_WIRE_ERROR;
} else {
return ONE_WIRE_SUCCESS;
}
}
void one_wire_configure_default( one_wire_t *obj ) {
if ( obj ) {
obj->data_pin = 0xFFFFFFFF;
obj->state = false;
}
}
err_t one_wire_reset( one_wire_t *obj ) {
if ( hal_one_wire_reset( obj ) ) {
return ONE_WIRE_ERROR;
}
return ONE_WIRE_SUCCESS;
}
err_t one_wire_read_rom( one_wire_t *obj, one_wire_rom_address_t *device_rom_address ) {
if ( hal_one_wire_read_rom( obj, device_rom_address ) ) {
return ONE_WIRE_ERROR;
}
return ONE_WIRE_SUCCESS;
}
err_t one_wire_skip_rom( one_wire_t *obj ) {
if ( hal_one_wire_skip_rom( obj ) ) {
return ONE_WIRE_ERROR;
}
return ONE_WIRE_SUCCESS;
}
err_t one_wire_match_rom( one_wire_t *obj, one_wire_rom_address_t *device_rom_address ) {
if ( hal_one_wire_match_rom( obj, device_rom_address ) ) {
return ONE_WIRE_ERROR;
}
return ONE_WIRE_SUCCESS;
}
err_t one_wire_search_first_device( one_wire_t *obj, one_wire_rom_address_t *one_wire_device_list ) {
if ( hal_one_wire_search_first_device( obj, one_wire_device_list ) ) {
return ONE_WIRE_ERROR;
}
return ONE_WIRE_SUCCESS;
}
err_t one_wire_search_next_device( one_wire_t *obj, one_wire_rom_address_t *one_wire_device_list ) {
if ( hal_one_wire_search_next_device( obj, one_wire_device_list ) ) {
return ONE_WIRE_ERROR;
}
return ONE_WIRE_SUCCESS;
}
err_t one_wire_write_byte( one_wire_t *obj, uint8_t *write_data_buffer, size_t write_data_length ) {
if ( hal_one_wire_write_byte( obj, write_data_buffer, write_data_length ) ) {
return ONE_WIRE_ERROR;
}
return ONE_WIRE_SUCCESS;
}
err_t one_wire_read_byte( one_wire_t *obj, uint8_t *read_data_buffer, size_t read_data_length ) {
if ( hal_one_wire_read_byte( obj, read_data_buffer, read_data_length ) ) {
return ONE_WIRE_ERROR;
}
return ONE_WIRE_SUCCESS;
}
// ------------------------------------------------------------------------- END