blob: 5cdd387b891b9d1fc858919315ff5077fddeb9ac [file] [log] [blame]
Kévin Redon69b92d92019-01-24 16:39:20 +01001/**
2 * \file
3 *
4 * \brief Port related functionality declaration.
5 *
6 * Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
7 *
8 * \asf_license_start
9 *
10 * \page License
11 *
12 * Subject to your compliance with these terms, you may use Microchip
13 * software and any derivatives exclusively with Microchip products.
14 * It is your responsibility to comply with third party license terms applicable
15 * to your use of third party software (including open source software) that
16 * may accompany Microchip software.
17 *
18 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
19 * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
20 * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
21 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
22 * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
23 * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
24 * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
25 * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
26 * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
27 * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
28 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
29 *
30 * \asf_license_stop
31 *
32 */
33
34#ifndef _HPL_GPIO_H_INCLUDED
35#define _HPL_GPIO_H_INCLUDED
36
37/**
38 * \addtogroup HPL Port
39 *
40 * \section hpl_port_rev Revision History
41 * - v1.0.0 Initial Release
42 *
43 *@{
44 */
45
46#include <compiler.h>
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51/**
52 * \brief Macros for the pin and port group, lower 5
53 * bits stands for pin number in the group, higher 3
54 * bits stands for port group
55 */
56#define GPIO_PIN(n) (((n)&0x1Fu) << 0)
57#define GPIO_PORT(n) ((n) >> 5)
58#define GPIO(port, pin) ((((port)&0x7u) << 5) + ((pin)&0x1Fu))
59#define GPIO_PIN_FUNCTION_OFF 0xffffffff
60
61/**
62 * \brief PORT pull mode settings
63 */
64enum gpio_pull_mode { GPIO_PULL_OFF, GPIO_PULL_UP, GPIO_PULL_DOWN };
65
66/**
67 * \brief PORT direction settins
68 */
69enum gpio_direction { GPIO_DIRECTION_OFF, GPIO_DIRECTION_IN, GPIO_DIRECTION_OUT };
70
71/**
72 * \brief PORT group abstraction
73 */
74
75enum gpio_port { GPIO_PORTA, GPIO_PORTB, GPIO_PORTC, GPIO_PORTD, GPIO_PORTE };
76
77/**
78 * \name HPL functions
79 */
80//@{
81/**
82 * \brief Port initialization function
83 *
84 * Port initialization function should setup the port module based
85 * on a static configuration file, this function should normally
86 * not be called directly, but is a part of hal_init()
87 */
88void _gpio_init(void);
89
90/**
91 * \brief Set direction on port with mask
92 *
93 * Set data direction for each pin, or disable the pin
94 *
95 * \param[in] port Ports are grouped into groups of maximum 32 pins,
96 * GPIO_PORTA = group 0, GPIO_PORTB = group 1, etc
97 * \param[in] mask Bit mask where 1 means apply direction setting to the
98 * corresponding pin
99 * \param[in] direction GPIO_DIRECTION_OFF = set pin direction to input
100 * and disable input buffer to disable the pin
101 * GPIO_DIRECTION_IN = set pin direction to input
102 * and enable input buffer to enable the pin
103 * GPIO_DIRECTION_OUT = set pin direction to output
104 * and disable input buffer
105 */
106static inline void _gpio_set_direction(const enum gpio_port port, const uint32_t mask,
107 const enum gpio_direction direction);
108
109/**
110 * \brief Set output level on port with mask
111 *
112 * Sets output state on pin to high or low with pin masking
113 *
114 * \param[in] port Ports are grouped into groups of maximum 32 pins,
115 * GPIO_PORTA = group 0, GPIO_PORTB = group 1, etc
116 * \param[in] mask Bit mask where 1 means apply direction setting to
117 * the corresponding pin
118 * \param[in] level true = pin level is set to 1
119 * false = pin level is set to 0
120 */
121static inline void _gpio_set_level(const enum gpio_port port, const uint32_t mask, const bool level);
122
123/**
124 * \brief Change output level to the opposite with mask
125 *
126 * Change pin output level to the opposite with pin masking
127 *
128 * \param[in] port Ports are grouped into groups of maximum 32 pins,
129 * GPIO_PORTA = group 0, GPIO_PORTB = group 1, etc
130 * \param[in] mask Bit mask where 1 means apply direction setting to
131 * the corresponding pin
132 */
133static inline void _gpio_toggle_level(const enum gpio_port port, const uint32_t mask);
134
135/**
136 * \brief Get input levels on all port pins
137 *
138 * Get input level on all port pins, will read IN register if configured to
139 * input and OUT register if configured as output
140 *
141 * \param[in] port Ports are grouped into groups of maximum 32 pins,
142 * GPIO_PORTA = group 0, GPIO_PORTB = group 1, etc
143 */
144static inline uint32_t _gpio_get_level(const enum gpio_port port);
145
146/**
147 * \brief Set pin pull mode
148 *
149 * Set pull mode on a single pin
150 *
151 * \notice This function will automatically change pin direction to input
152 *
153 * \param[in] port Ports are grouped into groups of maximum 32 pins,
154 * GPIO_PORTA = group 0, GPIO_PORTB = group 1, etc
155 * \param[in] pin The pin in the group that pull mode should be selected
156 * for
157 * \param[in] pull_mode GPIO_PULL_OFF = pull resistor on pin is disabled
158 * GPIO_PULL_DOWN = pull resistor on pin will pull pin
159 * level to ground level
160 * GPIO_PULL_UP = pull resistor on pin will pull pin
161 * level to VCC
162 */
163static inline void _gpio_set_pin_pull_mode(const enum gpio_port port, const uint8_t pin,
164 const enum gpio_pull_mode pull_mode);
165
166/**
167 * \brief Set gpio function
168 *
169 * Select which function a gpio is used for
170 *
171 * \param[in] gpio The gpio to set function for
172 * \param[in] function The gpio function is given by a 32-bit wide bitfield
173 * found in the header files for the device
174 *
175 */
176static inline void _gpio_set_pin_function(const uint32_t gpio, const uint32_t function);
177
178#include <hpl_gpio_base.h>
179//@}
180
181#ifdef __cplusplus
182}
183#endif
184/**@}*/
185#endif /* _HPL_GPIO_H_INCLUDED */