-
Notifications
You must be signed in to change notification settings - Fork 38
/
hal_ll_gpio_port.h
200 lines (179 loc) · 6.47 KB
/
hal_ll_gpio_port.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
/****************************************************************************
**
** 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_PORT_H_
#define _HAL_LL_GPIO_PORT_H_
#ifdef __cplusplus
extern "C"{
#endif
#include "hal_ll_target.h"
#include "hal_ll_gpio_constants.h"
#define RESET_PINS_OFFSET 16
/**
* Helper macros for GPIO HAL
*/
#define GPIO_MODULE_STRUCT_END -1
#define GPIO_AF_OFFSET 8
#define VALUE(pin, func) (pin | (func << GPIO_AF_OFFSET))
/**
* GPIO module struct defining pins and proprietary functions
*/
typedef struct
{
uint32_t pins[13];
uint32_t configs[13];
uint32_t gpio_remap;
} module_struct;
/**
* @brief GPIO control structure.
* @details Structure used for all GPIO
* functionalities.
* @note Addresses start from one of the following:
* GPIOA base address: 0x40010800
* GPIOB base address: 0x40010C00
* GPIOC base address: 0x40011000
* GPIOD base address: 0x40011400
* GPIOE base address: 0x40011800
*/
typedef struct
{
uint32_t ctl0; /* Port control register 0. Address offset 0x00. */
uint32_t ctl1; /* Port control register 1. Address offset 0x04. */
uint32_t istat; /* Port input status register. Address offset 0x08. */
uint32_t octl; /* Port output control register. Address offset 0x0C. */
uint32_t bop; /* Port bit operate register. Address offset 0x10. */
uint32_t bc; /* Port bit clear register. Address offset 0x14. */
uint32_t lock; /* Port configuration lock register. Address offset 0x18. */
} hal_ll_gpio_base_handle_t;
/**
* @brief AFIO control structure.
* @details Structure used for alternate functions,
* external interrupts and events.
* @note Addresses start from the following:
* AFIO base address: 0x40010000
*/
typedef struct
{
uint32_t ec; /* Event control register. Address offset 0x00. */
uint32_t pcf0; /* Alternate function I/O port configuration register 0. Address offset 0x04. */
uint32_t extiss0; /* External interrupt sources selection register 0. Address offset 0x08. */
uint32_t extiss1; /* External interrupt sources selection register 1. Address offset 0x0C. */
uint32_t extiss2; /* External interrupt sources selection register 2. Address offset 0x10. */
uint32_t extiss3; /* External interrupt sources selection register 3. Address offset 0x14. */
uint32_t __unused1; /* Unused. Address offset 0x18. */
uint32_t pcf1; /* Alternate function I/O port configuration register 1. Address offset 0x1C. */
} hal_ll_gpio_afio_handle_t;
/**
* Handle and mask types.
*/
typedef handle_t hal_ll_gpio_base_t;
/**
* Enum used for pin direction selection.
*/
typedef enum
{
HAL_LL_GPIO_DIGITAL_INPUT = 0,
HAL_LL_GPIO_DIGITAL_OUTPUT = 1
} hal_ll_gpio_direction_t;
/**
* Enum used for pin direction selection.
*/
typedef struct hal_ll_gpio_t
{
hal_ll_gpio_base_t base;
hal_ll_gpio_mask_t mask;
};
/**
* Pin and port data types.
*/
typedef struct hal_ll_gpio_t hal_ll_gpio_pin_t;
typedef struct hal_ll_gpio_t hal_ll_gpio_port_t;
/**
* @brief Get pins port index within a list of available ports
* @param name - desired pin
* @return uint8_t value from 0 to PORT_COUNT-1
*/
uint8_t hal_ll_gpio_port_index( hal_ll_pin_name_t name );
/**
* @brief Get pin mask of provided pin within proprietery port
* @param name - desired pin
* @return uint32_t
*/
uint32_t hal_ll_gpio_pin_mask( hal_ll_pin_name_t name );
/**
* @brief Get base address of ports registers
* @param name - desired port
* @return uint32_t address of first regsiter
*/
uint32_t hal_ll_gpio_port_base( hal_ll_port_name_t name );
/**
* @brief Set pin as analog input
* @param port - port base address acquired from hal_gpio_ll_port_base
* @param pin_mask - pin mask acquired from hal_gpio_ll_pin_mask
* @return none
*/
void hal_ll_gpio_analog_input( uint32_t *port, uint16_t pin_mask );
/**
* @brief Set pin as digital input
* @param port - port base address acquired from hal_gpio_ll_port_base
* @param pin_mask - pin mask acquired from hal_gpio_ll_pin_mask
* @return none
*/
void hal_ll_gpio_digital_input( uint32_t *port, uint16_t pin_mask );
/**
* @brief Set pin as digital output
* @param port - port base address acquired from hal_gpio_ll_port_base
* @param pin_mask - pin mask acquired from hal_gpio_ll_pin_mask
* @return none
*/
void hal_ll_gpio_digital_output( uint32_t *port, uint16_t pin_mask );
/**
* @brief Initialize structure of pins associated to specific peripheral
* @param module - desired module pins structure
* @return none
*/
void hal_ll_gpio_module_struct_init( module_struct const *module, bool state );
#ifdef __cplusplus
}
#endif
#endif // _HAL_LL_GPIO_PORT_H_
// ------------------------------------------------------------------------- END