]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/include/hal/gpio.h
Separate GPIO HAL interface from the code
[pes-rpp/rpp-lib.git] / rpp / include / hal / gpio.h
1 /* Copyright (C) 2013-2014 Czech Technical University in Prague
2  * Authors:
3  *     - Michal Horn <hornmich@fel.cvut.cz>
4  *
5  * This document contains proprietary information belonging to Czech
6  * Technical University in Prague. Passing on and copying of this
7  * document, and communication of its contents is not permitted
8  * without prior written authorization.
9  *
10  * Abstract:
11  *     The file contains GPIO pins read, write and configure inline functions.
12  */
13
14 /**
15  * @file
16  *
17  *  This file contains gpio pin inline functions.
18  *  - Get pin descriptor from name function
19  *  - Get port base (pointer to registers) from port number
20  *  - Get port number from pin descriptor
21  *  - Get port base (pointer to registers) from pin descriptor
22  *  - Get/Set pin value
23  *  - Get/Set pin direction
24  *  - Set pin configuration (can be used for initial configuration after MCU reset
25  *
26  *  Each pin is defined by its descriptor defined in hal_gpio_platform_def. The descriptor can be obtained
27  *  by hal_gpio_get_pin_dsc by giving a pin name as an argument.
28  */
29
30 #ifndef _HAL_GPIO_H
31 #define _HAL_GPIO_H_
32
33 #include "hal/hal.h"
34
35 extern gioPORT_t *port_id_map[MAX_PORT_CNT];
36 extern pin_map_element_t pin_map[MAX_PIN_CNT];
37
38
39 /**
40  * Get port base assigned to port number
41  * @param[in]   port_num    Port number <0;4>
42  * @return Pointer to port registers
43  */
44 gioPORT_t *hal_gpio_get_port_base(uint32_t port_num);
45
46 /**
47  * Get port number assigned to pin in its descriptor
48  * @param[in]   pin descriptor
49  * @return  Index of port
50  */
51 uint32_t hal_gpio_pin_get_port_num(uint32_t pin_dsc);
52
53 /**
54  * Get port base from pin descriptor
55  * Combines two upper defined functions
56  * @param[in]   pin_dcs Pin descriptor
57  * @return      Pointer to port registers
58  */
59 gioPORT_t *hal_gpio_pin_get_port_base(uint32_t pin_dsc);
60
61 /**
62  *  Get pin descriptor assigned to pin name.
63  *  @param[in]  pin_name    Pointer to string - the name of the pin.
64  *  @param[in]  len         Length of the name, if terminated by '/0', then len=-1
65  *  @return Pin descriptor or NULL if not found
66  */
67 uint32_t *hal_gpio_pin_get_dsc(const char *pin_name, int len);
68
69 /**
70  * Get value from GPIO pin
71  * @param[in]   pin_dsc pin descriptor
72  * @return  value read from specified gpio pin
73  */
74 uint32_t hal_gpio_pin_get_value(uint32_t pin_dsc);
75
76 /**
77  * Set value to gpio pin
78  * @param[in]   pin_dsc pin descriptor
79  * @param[in]   value   value to be assigned to the pin
80  */
81 void hal_gpio_pin_set_value(uint32_t pin_dsc, uint32_t value);
82
83 /**
84  * Set pin direction to input
85  * @param[in] pin_dsc pin descriptor
86  * @return always 0
87  */
88 int hal_gpio_pin_direction_input(uint32_t pin_dsc);
89
90 /**
91  * Set pin direction to output
92  * @param[in] pin_dsc pin descriptor
93  * @return always 0
94  */
95 int hal_gpio_pin_direction_output(uint32_t pin_dsc, uint32_t value);
96
97 /**
98  * Get pin direction
99  * @param[in] pin_dsc pin descriptor
100  * @return 1 - output, 0 - input
101  */
102 int hal_gpio_pin_get_direction(uint32_t pin_dsc);
103
104 /**
105  * Set pin as pull down or pull up and pull resistor enabled or disabled.
106  * @param[in] pin_dsc Descriptor of the pin
107  * @param[in] Mode on which pin will be configured to.
108  *              PORT_CONF_MODE_PU - pull up
109  *              PORT_CONF_MODE_PD - pull down
110  *              must be | with
111  *              PORT_CONF_MODE_PEN - pull resistor enable
112  *              PORT_CONF_MODE_PDIS - pull resistor disable
113  * @return always 0
114  */
115 uint32_t hal_gpio_pin_conf_mode(uint32_t pin_dsc, uint32_t mode);
116
117 /**
118  * Configure pin to be open drain or not
119  * @param[in] pin_dsc Descriptor of the pin
120  * @param[in] Mode on which pin will be configured to.
121  *              PORT_CONF_OD_OFF - open-drain disabled
122  *              PORT_CONF_OD_ON - open drain enabled
123  *
124  * @return always 0
125  */
126 uint32_t hal_gpio_pin_conf_od(uint32_t pin_dsc, uint32_t od);
127
128 /**
129  * Configure pin
130  * @param[in] pin_dsc Descriptor of the pin
131  * @param[in] Mode on which pin will be configured to.
132  *              PORT_CONF_OD_OFF - open-drain disabled
133  *              PORT_CONF_OD_ON - open drain enabled
134  *
135  *              PORT_CONF_MODE_PU - pull up
136  *              PORT_CONF_MODE_PD - pull down
137  *
138  *              PORT_CONF_MODE_PEN - pull resistor enable
139  *              PORT_CONF_MODE_PDIS - pull resistor disable
140  *
141  *              PORT_CONF_DIR_IN - direction input
142  *              PORT_CONF_DIR_OUT - direction output
143  *
144  *              PORT_CONF_INIT_LOW - init value 0
145  *              PORT_CONF_INIT_HIGH - init value 1
146  *
147  *              PORT_CONF_FNC_GPIO - port function GPIO
148  *              PORT_CONF_FNC_FNCX - port alternate function X
149  *
150  * @return always 0
151  */
152 uint32_t hal_gpio_pin_conf_set(uint32_t pin_dsc, uint32_t conf);
153
154 /**
155  * Do the initial pin configuration according values in pin descriptor
156  * @param[in]   pin_dsc pin descriptor
157  * @return always 0;
158  */
159 uint32_t hal_gpio_pin_conf(uint32_t pin_dsc);
160
161
162 #endif //_HAL_GPIO_H_