1 /* Copyright (C) 2013-2014 Czech Technical University in Prague
3 * - Michal Horn <hornmich@fel.cvut.cz>
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.
11 * The file contains GPIO pins read, write and configure inline functions.
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
23 * - Get/Set pin direction
24 * - Set pin configuration (can be used for initial configuration after MCU reset
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.
35 extern gioPORT_t *port_id_map[MAX_PORT_CNT];
36 extern pin_map_element_t pin_map[MAX_PIN_CNT];
40 * Get port base assigned to port number
41 * @param[in] port_num Port number <0;4>
42 * @return Pointer to port registers
44 gioPORT_t *hal_gpio_get_port_base(uint32_t port_num);
47 * Get port number assigned to pin in its descriptor
48 * @param[in] pin descriptor
49 * @return Index of port
51 uint32_t hal_gpio_pin_get_port_num(uint32_t pin_dsc);
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
59 gioPORT_t *hal_gpio_pin_get_port_base(uint32_t pin_dsc);
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
67 uint32_t *hal_gpio_pin_get_dsc(const char *pin_name, int len);
70 * Get value from GPIO pin
71 * @param[in] pin_dsc pin descriptor
72 * @return value read from specified gpio pin
74 uint32_t hal_gpio_pin_get_value(uint32_t pin_dsc);
77 * Set value to gpio pin
78 * @param[in] pin_dsc pin descriptor
79 * @param[in] value value to be assigned to the pin
81 void hal_gpio_pin_set_value(uint32_t pin_dsc, uint32_t value);
84 * Set pin direction to input
85 * @param[in] pin_dsc pin descriptor
88 int hal_gpio_pin_direction_input(uint32_t pin_dsc);
91 * Set pin direction to output
92 * @param[in] pin_dsc pin descriptor
95 int hal_gpio_pin_direction_output(uint32_t pin_dsc, uint32_t value);
99 * @param[in] pin_dsc pin descriptor
100 * @return 1 - output, 0 - input
102 int hal_gpio_pin_get_direction(uint32_t pin_dsc);
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
111 * PORT_CONF_MODE_PEN - pull resistor enable
112 * PORT_CONF_MODE_PDIS - pull resistor disable
115 uint32_t hal_gpio_pin_conf_mode(uint32_t pin_dsc, uint32_t mode);
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
126 uint32_t hal_gpio_pin_conf_od(uint32_t pin_dsc, uint32_t od);
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
135 * PORT_CONF_MODE_PU - pull up
136 * PORT_CONF_MODE_PD - pull down
138 * PORT_CONF_MODE_PEN - pull resistor enable
139 * PORT_CONF_MODE_PDIS - pull resistor disable
141 * PORT_CONF_DIR_IN - direction input
142 * PORT_CONF_DIR_OUT - direction output
144 * PORT_CONF_INIT_LOW - init value 0
145 * PORT_CONF_INIT_HIGH - init value 1
147 * PORT_CONF_FNC_GPIO - port function GPIO
148 * PORT_CONF_FNC_FNCX - port alternate function X
152 uint32_t hal_gpio_pin_conf_set(uint32_t pin_dsc, uint32_t conf);
155 * Do the initial pin configuration according values in pin descriptor
156 * @param[in] pin_dsc pin descriptor
159 uint32_t hal_gpio_pin_conf(uint32_t pin_dsc);
162 #endif //_HAL_GPIO_H_