X-Git-Url: http://rtime.felk.cvut.cz/gitweb/pes-rpp/rpp-lib.git/blobdiff_plain/a6707c232617ce5055634f12a868923eb3a10a6a..55433cf00200eebb491a885bb64701d56b60e687:/rpp/include/hal/hal.h diff --git a/rpp/include/hal/hal.h b/rpp/include/hal/hal.h index 3a0ee57..428f824 100644 --- a/rpp/include/hal/hal.h +++ b/rpp/include/hal/hal.h @@ -32,7 +32,176 @@ #error No supported target specified! #endif -#include "hal/gpio.h" -#include "hal/port_gpio.h" +uint8_t hal_gpio_get_pin_cnt(); + +pin_map_element_t* hal_gpio_get_pin_map(); + +/** + * Get port base assigned to port number + * @param[in] port_num Port number <0;4> + * @return Pointer to port registers + */ +gioPORT_t *hal_gpio_get_port_base(uint32_t port_num); + +/** + * Get port number assigned to pin in its descriptor + * @param[in] pin descriptor + * @return Index of port + */ +uint32_t hal_gpio_pin_get_port_num(uint32_t pin_dsc); + +/** + * Get port base from pin descriptor + * Combines two upper defined functions + * @param[in] pin_dcs Pin descriptor + * @return Pointer to port registers + */ +gioPORT_t *hal_gpio_pin_get_port_base(uint32_t pin_dsc); + +/** + * Get pin descriptor assigned to pin name. + * @param[in] pin_name Pointer to string - the name of the pin. + * @param[in] len Length of the name, if terminated by '/0', then len=-1 + * @return Pin descriptor or NULL if not found + */ +uint32_t *hal_gpio_pin_get_dsc(const char *pin_name, int len); + +/** + * Get value from GPIO pin + * @param[in] pin_dsc pin descriptor + * @return value read from specified gpio pin + */ +uint32_t hal_gpio_pin_get_value(uint32_t pin_dsc); + +/** + * Set value to gpio pin + * @param[in] pin_dsc pin descriptor + * @param[in] value value to be assigned to the pin + */ +void hal_gpio_pin_set_value(uint32_t pin_dsc, uint32_t value); + +/** + * Set pin direction to input + * @param[in] pin_dsc pin descriptor + * @return always 0 + */ +int hal_gpio_pin_direction_input(uint32_t pin_dsc); + +/** + * Set pin direction to output + * @param[in] pin_dsc pin descriptor + * @return always 0 + */ +int hal_gpio_pin_direction_output(uint32_t pin_dsc, uint32_t value); + +/** + * Get pin direction + * @param[in] pin_dsc pin descriptor + * @return 1 - output, 0 - input + */ +int hal_gpio_pin_get_direction(uint32_t pin_dsc); + +/** + * Set pin as pull down or pull up and pull resistor enabled or disabled. + * @param[in] pin_dsc Descriptor of the pin + * @param[in] Mode on which pin will be configured to. + * PORT_CONF_MODE_PU - pull up + * PORT_CONF_MODE_PD - pull down + * must be | with + * PORT_CONF_MODE_PEN - pull resistor enable + * PORT_CONF_MODE_PDIS - pull resistor disable + * @return always 0 + */ +uint32_t hal_gpio_pin_conf_mode(uint32_t pin_dsc, uint32_t mode); + +/** + * Configure pin to be open drain or not + * @param[in] pin_dsc Descriptor of the pin + * @param[in] Mode on which pin will be configured to. + * PORT_CONF_OD_OFF - open-drain disabled + * PORT_CONF_OD_ON - open drain enabled + * + * @return always 0 + */ +uint32_t hal_gpio_pin_conf_od(uint32_t pin_dsc, uint32_t od); + +/** + * Configure pin + * @param[in] pin_dsc Descriptor of the pin + * @param[in] Mode on which pin will be configured to. + * PORT_CONF_OD_OFF - open-drain disabled + * PORT_CONF_OD_ON - open drain enabled + * + * PORT_CONF_MODE_PU - pull up + * PORT_CONF_MODE_PD - pull down + * + * PORT_CONF_MODE_PEN - pull resistor enable + * PORT_CONF_MODE_PDIS - pull resistor disable + * + * PORT_CONF_DIR_IN - direction input + * PORT_CONF_DIR_OUT - direction output + * + * PORT_CONF_INIT_LOW - init value 0 + * PORT_CONF_INIT_HIGH - init value 1 + * + * PORT_CONF_FNC_GPIO - port function GPIO + * PORT_CONF_FNC_FNCX - port alternate function X + * + * @return always 0 + */ +uint32_t hal_gpio_pin_conf_set(uint32_t pin_dsc, uint32_t conf); + +/** + * Do the initial pin configuration according values in pin descriptor + * @param[in] pin_dsc pin descriptor + * @return always 0; + */ +uint32_t hal_gpio_pin_conf(uint32_t pin_dsc); + +/** + * Get values of all pins of given port. + * @param[in] config Pointer to array of pin descriptors + * @param[in] num_val Number of pins assigned to the port + * @param[out] values Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1... + * @return always 0 + */ +uint32_t hal_gio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *values); + +/** + * Set values to all pins of given port. + * @param[in] config Pointer to array of pin descriptors + * @param[in] num_val Number of pins assigned to the port + * @param[in] values Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1... + * @return always 0 + */ +uint32_t hal_gio_port_set_val(uint32_t *config, uint32_t num_val, const uint32_t *values); + +/** + * Get port descriptor assigned to port name. + * @param[in] port_name Pointer to string - the name of the port. + * @param[in] len Length of the name, if terminated by '/0', then len=-1 + * @return Port descriptor or NULL if not found + */ +const port_def_t *hal_port_get_definitions(); + +port_desc_t *hal_port_get_dsc(const char *port_name, int len); + +/** + * Get port descriptor assigned to port name. + * @param[in] port_name Pointer to string - the name of the port. + * @param[in] len Length of the name, if terminated by '/0', then len=-1 + * @return Port descriptor or NULL if not found + */ +port_desc_t *hal_port_get_dsc(const char *port_name, int len); + +/** + * Transfer command through the spi + * @param[in] config Address of the SPI + * @param[in] num_bytes Number of bytes to be trasfered + * @param[in] commands SPI command to be sent + * @return spi response + */ +uint32_t hal_spi_port_transfer_command(uint32_t *config, uint32_t num_bytes, const uint32_t *commands); + #endif /* __HAL_H */