2 * Hardware Abstraction Layer library interface file.
6 * @copyright Copyright (C) 2013, 2015 Czech Technical University in Prague
8 * @author Carlos Jenkins <carlos@jenkins.co.cr>
16 #if defined(TARGET_POSIX)
17 #include "hal/_rm48_hdk/gpio_def.h"
18 #include "hal/_rm48_hdk/port_def.h"
19 #elif defined(TARGET_RM48_HDK)
20 #include "hal/_rm48_hdk/gpio_def.h"
21 #include "hal/_rm48_hdk/port_def.h"
22 #elif defined(TARGET_TMS570_HDK)
23 #include "hal/_tms570_hdk/gpio_def.h"
24 #include "hal/_tms570_hdk/port_def.h"
25 #elif defined(TARGET_TMS570_HYDCTR)
26 #include "hal/_tms570_hydctr/gpio_def.h"
27 #include "hal/_tms570_hydctr/port_def.h"
28 #elif defined(TARGET_TMS570_RPP)
29 #include "hal/_tms570_rpp/gpio_def.h"
30 #include "hal/_tms570_rpp/port_def.h"
32 #error No supported target specified!
35 uint8_t hal_gpio_get_pin_cnt();
37 pin_map_element_t* hal_gpio_get_pin_map();
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_set_dir_in(uint32_t pin_dsc);
91 * Set pin direction to output
92 * @param[in] pin_dsc pin descriptor
95 int hal_gpio_pin_set_dir_out(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_dir(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_set_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_set_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_set_config(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_configure(uint32_t pin_dsc);
162 * Get values of all pins of given port.
163 * @param[in] config Pointer to array of pin descriptors
164 * @param[in] num_val Number of pins assigned to the port
165 * @param[out] values Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1...
168 uint32_t hal_gpio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *values);
171 * Set values to all pins of given port.
172 * @param[in] config Pointer to array of pin descriptors
173 * @param[in] num_val Number of pins assigned to the port
174 * @param[in] values Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1...
177 uint32_t hal_gpio_port_set_val(uint32_t *config, uint32_t num_val, const uint32_t *values);
180 * Get port descriptor assigned to port name.
181 * @param[in] port_name Pointer to string - the name of the port.
182 * @param[in] len Length of the name, if terminated by '/0', then len=-1
183 * @return Port descriptor or NULL if not found
185 const port_def_t *hal_port_get_map();
187 port_desc_t *hal_port_get_dsc(const char *port_name, int len);
190 * Get port descriptor assigned to port name.
191 * @param[in] port_name Pointer to string - the name of the port.
192 * @param[in] len Length of the name, if terminated by '/0', then len=-1
193 * @return Port descriptor or NULL if not found
195 port_desc_t *hal_port_get_dsc(const char *port_name, int len);
198 * Transfer command through the spi
199 * @param[in] config Address of the SPI
200 * @param[in] num_bytes Number of bytes to be trasfered
201 * @param[in] commands SPI command to be sent
202 * @return spi response
204 uint32_t hal_spi_port_transfer_command(uint32_t *config, uint32_t num_bytes, const uint32_t *commands);