-
Notifications
You must be signed in to change notification settings - Fork 39
/
hal_ll_gpio.h
278 lines (262 loc) · 11 KB
/
hal_ll_gpio.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/****************************************************************************
**
** 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 hal_ll_gpio.h
* @brief This file contains all the functions prototypes for the GPIO library.
*/
#ifndef _HAL_LL_GPIO_H_
#define _HAL_LL_GPIO_H_
#include "hal_ll_gpio_port.h"
#ifdef __cplusplus
extern "C"{
#endif
/**
* @brief Function configures pin.
*
* Configures pin to digital output or digital input.
* Sets only the pin defined by pin mask in
* hal_ll_gpio_pin_t structure.
*
* @param *pin Pin object context.
* Configured during this functions process.
* @param name Pin name -- PA0, PA1...
* @param direction Pin direction.
* HAL_LL_GPIO_DIGITAL_INPUT
* HAL_LL_GPIO_DIGITAL_OUTPUT
*
* @return None.
*/
void hal_ll_gpio_configure_pin(hal_ll_gpio_pin_t *pin, hal_ll_pin_name_t name, hal_ll_gpio_direction_t direction);
/**
* @brief Read pin input.
*
* Checks pin data input register value and
* returns logical state.
*
* @param *pin Pin object context.
* Configured during hal_ll_gpio_configure_pin.
*
* @return uint8_t Pin logical state.
* 1/true -- pin high state -- 1.8V or more detected
* 0/false -- pin low state -- 1.8V or less detected
*/
#if defined(FLATTEN_ME) && (FLATTEN_ME_LEVEL >= FLATTEN_ME_LEVEL_LOW)
#define hal_ll_gpio_read_pin_input(_handle) ((((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base) != NULL) ? \
(((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base)->istat & ((hal_ll_gpio_pin_t *)_handle)->mask) : \
(0))
#else
uint8_t hal_ll_gpio_read_pin_input(hal_ll_gpio_pin_t *pin);
#endif
/**
* @brief Read pin output.
*
* Checks pin data output register value and
* returns logical state.
*
* @param *pin Pin object context.
* Configured during hal_ll_gpio_configure_pin.
*
* @return uint8_t Pin logical state.
* 1/true -- pin high state -- 1.8V or more detected
* 0/false -- pin low state -- 1.8V or less detected
*/
#if defined(FLATTEN_ME) && (FLATTEN_ME_LEVEL >= FLATTEN_ME_LEVEL_LOW)
#define hal_ll_gpio_read_pin_output(_handle) ((((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base) != NULL) ? \
(((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base)->octl & ((hal_ll_gpio_pin_t *)_handle)->mask) : \
(0))
#else
uint8_t hal_ll_gpio_read_pin_output(hal_ll_gpio_pin_t *pin);
#endif
/**
* @brief Writes pin output state.
*
* Sets single pin logical state.
*
* @param *pin Pin object context.
* Configured during hal_ll_gpio_configure_pin.
* @param value Pin logical state.
* 1/true -- sets pin high state -- over 1.8V
* 0/false -- sets pin low state -- less than 1.8V
*
* @return None
*/
#if defined(FLATTEN_ME) && (FLATTEN_ME_LEVEL >= FLATTEN_ME_LEVEL_LOW)
#define hal_ll_gpio_write_pin_output(_handle,_value) ((((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base) != NULL) ? \
((_value > 0) ? \
(((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base)->bop = ((hal_ll_gpio_pin_t *)_handle)->mask) : \
(((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base)->bop = ((uint32_t)((hal_ll_gpio_pin_t *)_handle)->mask << RESET_PINS_OFFSET))) : \
(0))
#else
void hal_ll_gpio_write_pin_output(hal_ll_gpio_pin_t *pin, uint8_t value);
#endif
/**
* @brief Toggles pin logical state.
*
* Checks current state of pin
* and toggles it.
*
* @param *pin Pin object context.
* Configured during hal_ll_gpio_configure_pin.
*
* @return None
*/
#if defined(FLATTEN_ME) && (FLATTEN_ME_LEVEL >= FLATTEN_ME_LEVEL_LOW)
#define hal_ll_gpio_toggle_pin_output(_handle) ((((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base) != NULL) ? \
((((((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base)->octl & ((hal_ll_gpio_pin_t *)_handle)->mask))) ? \
(((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base)->bop = ((uint32_t)((hal_ll_gpio_pin_t *)_handle)->mask << RESET_PINS_OFFSET)) : \
(((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base)->bop = ((hal_ll_gpio_pin_t *)_handle)->mask)) : \
(0))
#else
void hal_ll_gpio_toggle_pin_output(hal_ll_gpio_pin_t *pin);
#endif
/**
* @brief Sets pin logical state.
*
* Sets pin logical state to high.
*
* @param *pin Pin object context.
* Configured during hal_ll_gpio_configure_pin.
*
* @return None
*/
#if defined(FLATTEN_ME) && (FLATTEN_ME_LEVEL >= FLATTEN_ME_LEVEL_LOW)
#define hal_ll_gpio_set_pin_output(_handle) ((((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base) != NULL) ? \
(((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base)->bop = ((hal_ll_gpio_pin_t *)_handle)->mask) : \
(0))
#else
void hal_ll_gpio_set_pin_output(hal_ll_gpio_pin_t *pin);
#endif
/**
* @brief Sets pin logical state.
*
* Sets pin logical state to low.
*
* @param *pin Pin object context.
* Configured during hal_ll_gpio_configure_pin.
*
* @return None
*/
#if defined(FLATTEN_ME) && (FLATTEN_ME_LEVEL >= FLATTEN_ME_LEVEL_LOW)
#define hal_ll_gpio_clear_pin_output(_handle) ((((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base) != NULL) ? \
(((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_pin_t *)_handle)->base)->bc = (uint32_t)((hal_ll_gpio_pin_t *)_handle)->mask) : \
(0))
#else
void hal_ll_gpio_clear_pin_output(hal_ll_gpio_pin_t *pin);
#endif
/**
* @brief Configures port.
*
* Configures port according to specified
* direction. Takes into consideration only
* pins defined by mask.
*
* @param *port Port object context.
* Configured during this functions process.
* @param name Port name.
* @param mask Port pin mask.
* @param direction Port pin direction.
* HAL_LL_GPIO_DIGITAL_INPUT
* HAL_LL_GPIO_DIGITAL_OUTPUT
*
* @return None
*/
void hal_ll_gpio_configure_port(hal_ll_gpio_port_t *port, hal_ll_port_name_t name, hal_ll_gpio_mask_t mask, hal_ll_gpio_direction_t direction);
/**
* @brief Read port input value.
*
* Checks port data input register value and
* returns it.
*
* @param *port Port object context.
* Configured during hal_ll_gpio_configure_port.
*
* @return hal_ll_port_size_t Port input data register value.
*/
#if defined(FLATTEN_ME) && (FLATTEN_ME_LEVEL >= FLATTEN_ME_LEVEL_LOW)
#define hal_ll_gpio_read_port_input(_handle) ((((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_port_t *)_handle)->base) != NULL) ? \
((hal_ll_port_size_t)((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_port_t *)_handle)->base)->istat & ((hal_ll_gpio_port_t *)_handle)->mask) : \
(0))
#else
hal_ll_port_size_t hal_ll_gpio_read_port_input(hal_ll_gpio_port_t *port);
#endif
/**
* @brief Read port output value.
*
* Checks port data output register value and
* returns it.
*
* @param *port Port object context.
* Configured during hal_ll_gpio_configure_port.
* @return hal_ll_port_size_t Port output data register value.
*/
#if defined(FLATTEN_ME) && (FLATTEN_ME_LEVEL >= FLATTEN_ME_LEVEL_LOW)
#define hal_ll_gpio_read_port_output(_handle) ((((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_port_t *)_handle)->base) != NULL) ? \
((hal_ll_port_size_t)(((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_port_t *)_handle)->base)->octl) & (((hal_ll_gpio_port_t *)_handle)->mask)) : \
(0))
#else
hal_ll_port_size_t hal_ll_gpio_read_port_output(hal_ll_gpio_port_t *port);
#endif
/**
* @brief Set port state.
*
* Sets port output state.
* Will take into consideration only
* port pins defined by mask in
* port object context.
*
* @param *port Port object context.
* Configured during hal_ll_gpio_configure_port.
* @param value Port output value
*
* @return None
*/
#if defined(FLATTEN_ME) && (FLATTEN_ME_LEVEL >= FLATTEN_ME_LEVEL_LOW)
#define hal_ll_gpio_write_port_output(_handle,_value) ((((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_port_t *)_handle)->base) != NULL) ? \
(((hal_ll_gpio_base_handle_t *)((hal_ll_gpio_port_t *)_handle)->base)->bop = \
((hal_ll_port_size_t)_value & ((hal_ll_gpio_port_t *)_handle)->mask) | \
((uint32_t)(~(hal_ll_port_size_t)_value & ((hal_ll_gpio_port_t *)_handle)->mask) << RESET_PINS_OFFSET)) : \
(0))
#else
void hal_ll_gpio_write_port_output(hal_ll_gpio_port_t *port, hal_ll_port_size_t value);
#endif
#ifdef __cplusplus
}
#endif
#endif // _HAL_LL_GPIO_H_
// ------------------------------------------------------------------------- END