1 /* Copyright (C) 2012-2013 Czech Technical University in Prague
4 * - Michal Horn <hornmich@fel.cvut.cz>
6 * This document contains proprietary information belonging to Czech
7 * Technical University in Prague. Passing on and copying of this
8 * document, and communication of its contents is not permitted
9 * without prior written authorization.
14 * This file contains gpio pin configuration functions.
15 * Some additional function for setting and getting pin values, getting
16 * descriptors etc. are defined in header file as inline functions.
18 * Each pin is defined by its descriptor defined in hal_gpio_platform_def. The descriptor can be obtained
19 * by hal_gpio_get_pin_dsc by giving a pin name as an argument.
25 * Set pin as pull down or pull up and pull resistor enabled or disabled.
26 * @param[in] pin_dsc Descriptor of the pin
27 * @param[in] Mode on which pin will be configured to.
28 * PORT_CONF_MODE_PU - pull up
29 * PORT_CONF_MODE_PD - pull down
31 * PORT_CONF_MODE_PEN - pull resistor enable
32 * PORT_CONF_MODE_PDIS - pull resistor disable
35 uint32_t hal_gpio_pin_conf_mode(uint32_t pin_dsc, uint32_t mode)
37 gioPORT_t *gioPort = hal_gpio_pin_get_port_base(pin_dsc);
39 if (mode & PORT_CONF_MODE_PTYPE_MASK)
40 gioPort->PSL |= (1 << (pin_dsc & 0x1f));
42 gioPort->PSL &= ~(1 << (pin_dsc & 0x1f));
43 if (mode & PORT_CONF_MODE_PEN_MASK)
44 gioPort->PULDIS |= (1 << (pin_dsc & 0x1f));
46 gioPort->PULDIS &= ~(1 << (pin_dsc & 0x1f));
51 * Configure pin to be open drain or not
52 * @param[in] pin_dsc Descriptor of the pin
53 * @param[in] Mode on which pin will be configured to.
54 * PORT_CONF_OD_OFF - open-drain disabled
55 * PORT_CONF_OD_ON - open drain enabled
59 uint32_t hal_gpio_pin_conf_od(uint32_t pin_dsc, uint32_t od)
61 gioPORT_t *gioPort = hal_gpio_pin_get_port_base(pin_dsc);
63 if (od & PORT_CONF_OD_ON)
64 gioPort->PDR |= (1 << (pin_dsc & 0x1f));
66 gioPort->PDR &= ~(1 << (pin_dsc & 0x1f));
72 * @param[in] pin_dsc Descriptor of the pin
73 * @param[in] Mode on which pin will be configured to.
74 * PORT_CONF_OD_OFF - open-drain disabled
75 * PORT_CONF_OD_ON - open drain enabled
77 * PORT_CONF_MODE_PU - pull up
78 * PORT_CONF_MODE_PD - pull down
80 * PORT_CONF_MODE_PEN - pull resistor enable
81 * PORT_CONF_MODE_PDIS - pull resistor disable
83 * PORT_CONF_DIR_IN - direction input
84 * PORT_CONF_DIR_OUT - direction output
86 * PORT_CONF_INIT_LOW - init value 0
87 * PORT_CONF_INIT_HIGH - init value 1
89 * PORT_CONF_FNC_GPIO - port function GPIO
90 * PORT_CONF_FNC_FNCX - port alternate function X
94 uint32_t hal_gpio_pin_conf_set(uint32_t pin_dsc, uint32_t conf)
96 pin_dsc &= ~PORT_CONF_MASK;
97 hal_gpio_pin_conf_mode(pin_dsc, conf & PORT_CONF_MODE_MASK);
98 hal_gpio_pin_conf_od(pin_dsc, conf & PORT_CONF_OD_MASK);
99 if (conf & PORT_CONF_SET_DIR) {
100 if ((conf & PORT_CONF_DIR_MASK) == (PORT_CONF_DIR_IN & PORT_CONF_DIR_MASK))
101 hal_gpio_pin_direction_input(pin_dsc);
103 hal_gpio_pin_direction_output(pin_dsc, conf & PORT_CONF_INIT_HIGH);