summaryrefslogtreecommitdiffstats
path: root/Sensor Watch Starter Project/hal/include/hpl_gpio.h
blob: 5cdd387b891b9d1fc858919315ff5077fddeb9ac (plain)
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
/**
 * \file
 *
 * \brief Port related functionality declaration.
 *
 * Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
 *
 * \asf_license_start
 *
 * \page License
 *
 * Subject to your compliance with these terms, you may use Microchip
 * software and any derivatives exclusively with Microchip products.
 * It is your responsibility to comply with third party license terms applicable
 * to your use of third party software (including open source software) that
 * may accompany Microchip software.
 *
 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
 * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
 * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
 * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
 * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
 * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
 * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
 * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
 *
 * \asf_license_stop
 *
 */

#ifndef _HPL_GPIO_H_INCLUDED
#define _HPL_GPIO_H_INCLUDED

/**
 * \addtogroup HPL Port
 *
 * \section hpl_port_rev Revision History
 * - v1.0.0 Initial Release
 *
 *@{
 */

#include <compiler.h>

#ifdef __cplusplus
extern "C" {
#endif
/**
 * \brief Macros for the pin and port group, lower 5
 * bits stands for pin number in the group, higher 3
 * bits stands for port group
 */
#define GPIO_PIN(n) (((n)&0x1Fu) << 0)
#define GPIO_PORT(n) ((n) >> 5)
#define GPIO(port, pin) ((((port)&0x7u) << 5) + ((pin)&0x1Fu))
#define GPIO_PIN_FUNCTION_OFF 0xffffffff

/**
 * \brief PORT pull mode settings
 */
enum gpio_pull_mode { GPIO_PULL_OFF, GPIO_PULL_UP, GPIO_PULL_DOWN };

/**
 * \brief PORT direction settins
 */
enum gpio_direction { GPIO_DIRECTION_OFF, GPIO_DIRECTION_IN, GPIO_DIRECTION_OUT };

/**
 * \brief PORT group abstraction
 */

enum gpio_port { GPIO_PORTA, GPIO_PORTB, GPIO_PORTC, GPIO_PORTD, GPIO_PORTE };

/**
 * \name HPL functions
 */
//@{
/**
 * \brief Port initialization function
 *
 * Port initialization function should setup the port module based
 * on a static configuration file, this function should normally
 * not be called directly, but is a part of hal_init()
 */
void _gpio_init(void);

/**
 * \brief Set direction on port with mask
 *
 * Set data direction for each pin, or disable the pin
 *
 * \param[in] port      Ports are grouped into groups of maximum 32 pins,
 *                      GPIO_PORTA = group 0, GPIO_PORTB = group 1, etc
 * \param[in] mask      Bit mask where 1 means apply direction setting to the
 *                      corresponding pin
 * \param[in] direction GPIO_DIRECTION_OFF  = set pin direction to input
 *                      and disable input buffer to disable the pin
 *                      GPIO_DIRECTION_IN   = set pin direction to input
 *                      and enable input buffer to enable the pin
 *                      GPIO_DIRECTION_OUT  = set pin direction to output
 *                      and disable input buffer
 */
static inline void _gpio_set_direction(const enum gpio_port port, const uint32_t mask,
                                       const enum gpio_direction direction);

/**
 * \brief Set output level on port with mask
 *
 * Sets output state on pin to high or low with pin masking
 *
 * \param[in] port  Ports are grouped into groups of maximum 32 pins,
 *                  GPIO_PORTA = group 0, GPIO_PORTB = group 1, etc
 * \param[in] mask  Bit mask where 1 means apply direction setting to
 *                  the corresponding pin
 * \param[in] level true  = pin level is set to 1
 *                  false = pin level is set to 0
 */
static inline void _gpio_set_level(const enum gpio_port port, const uint32_t mask, const bool level);

/**
 * \brief Change output level to the opposite with mask
 *
 * Change pin output level to the opposite with pin masking
 *
 * \param[in] port  Ports are grouped into groups of maximum 32 pins,
 *                  GPIO_PORTA = group 0, GPIO_PORTB = group 1, etc
 * \param[in] mask  Bit mask where 1 means apply direction setting to
 *                  the corresponding pin
 */
static inline void _gpio_toggle_level(const enum gpio_port port, const uint32_t mask);

/**
 * \brief Get input levels on all port pins
 *
 * Get input level on all port pins, will read IN register if configured to
 * input and OUT register if configured as output
 *
 * \param[in] port  Ports are grouped into groups of maximum 32 pins,
 *                  GPIO_PORTA = group 0, GPIO_PORTB = group 1, etc
 */
static inline uint32_t _gpio_get_level(const enum gpio_port port);

/**
 * \brief Set pin pull mode
 *
 * Set pull mode on a single pin
 *
 * \notice This function will automatically change pin direction to input
 *
 * \param[in] port      Ports are grouped into groups of maximum 32 pins,
 *                      GPIO_PORTA = group 0, GPIO_PORTB = group 1, etc
 * \param[in] pin       The pin in the group that pull mode should be selected
 *                      for
 * \param[in] pull_mode GPIO_PULL_OFF  = pull resistor on pin is disabled
 *                      GPIO_PULL_DOWN = pull resistor on pin will pull pin
 *                      level to ground level
 *                      GPIO_PULL_UP   = pull resistor on pin will pull pin
 *                      level to VCC
 */
static inline void _gpio_set_pin_pull_mode(const enum gpio_port port, const uint8_t pin,
                                           const enum gpio_pull_mode pull_mode);

/**
 * \brief Set gpio function
 *
 * Select which function a gpio is used for
 *
 * \param[in] gpio     The gpio to set function for
 * \param[in] function The gpio function is given by a 32-bit wide bitfield
 *                     found in the header files for the device
 *
 */
static inline void _gpio_set_pin_function(const uint32_t gpio, const uint32_t function);

#include <hpl_gpio_base.h>
//@}

#ifdef __cplusplus
}
#endif
/**@}*/
#endif /* _HPL_GPIO_H_INCLUDED */