]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Separate GPIO HAL interface from the code
authorMichal Horn <michal@apartman.cz>
Thu, 16 Jul 2015 07:41:00 +0000 (09:41 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 2 Aug 2015 18:09:44 +0000 (20:09 +0200)
The implementation of the functions is moved to the source file, leaving only commented
function prototypes of the interface functions in the header and hiding the internal
functions in the source file.

Move GPIO HAL functions definitions from the header file fo the source file

Move functions comments from the source files to the header files

rpp/include/hal/gpio.h
rpp/include/hal/port_gpio.h
rpp/include/hal/port_spi.h
rpp/src/hal/gpio.c
rpp/src/hal/port_gpio.c
rpp/src/hal/port_spi.c

index 5bc603f6aa084ef26d207e7ade6f95cd0d94be17..fd82c65fa0d9c66be4dc1b8b004afd3942f30ab5 100644 (file)
 extern gioPORT_t *port_id_map[MAX_PORT_CNT];
 extern pin_map_element_t pin_map[MAX_PIN_CNT];
 
-/**
- *  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
- */
-static inline uint32_t *hal_gpio_pin_get_dsc(const char *pin_name, int len)
-{
-       uint32_t i;
-       const char *pin_name_ptr;
-       char pin_name_term[32];
-
-       if (len != -1) {    // pin name not terminated by '\0'
-               strncpy(pin_name_term, pin_name, len);
-               pin_name_term[len] = '\0';
-               pin_name_ptr = pin_name_term;
-       }
-       else pin_name_ptr = pin_name;
-
-       for (i = 0; i < MAX_PIN_CNT; i++) {
-               if (strcmp(pin_name_ptr, pin_map[i].pin_name) == 0)
-                       return &pin_map[i].pin_desc;
-       }
-       return NULL;
-}
 
 /**
  * Get port base assigned to port number
  * @param[in]   port_num    Port number <0;4>
  * @return Pointer to port registers
  */
-static inline gioPORT_t *hal_gpio_get_port_base(uint32_t port_num)
-{
-       return port_id_map[port_num];
-}
+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
  */
-static inline uint32_t hal_gpio_pin_get_port_num(uint32_t pin_dsc)
-{
-
-       return (pin_dsc & ~PORT_CONF_MASK) >> PORT_SHIFT;
-}
+uint32_t hal_gpio_pin_get_port_num(uint32_t pin_dsc);
 
 /**
  * Get port base from pin descriptor
@@ -88,72 +56,99 @@ static inline uint32_t hal_gpio_pin_get_port_num(uint32_t pin_dsc)
  * @param[in]   pin_dcs Pin descriptor
  * @return      Pointer to port registers
  */
-static inline gioPORT_t *hal_gpio_pin_get_port_base(uint32_t pin_dsc)
-{
-       return hal_gpio_get_port_base(hal_gpio_pin_get_port_num(pin_dsc));
-}
+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
  */
-static inline uint32_t hal_gpio_pin_get_value(uint32_t pin_dsc)
-{
-       return ((hal_gpio_pin_get_port_base(pin_dsc)->DIN) >> (pin_dsc & 0x1f)) & 1;
-}
+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
  */
-static inline void hal_gpio_pin_set_value(uint32_t pin_dsc, uint32_t value)
-{
-       if (value)
-               hal_gpio_pin_get_port_base(pin_dsc)->DSET = 1 << (pin_dsc & 0x1f);
-       else
-               hal_gpio_pin_get_port_base(pin_dsc)->DCLR = 1 << (pin_dsc & 0x1f);
-}
+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
  */
-static inline int hal_gpio_pin_direction_input(uint32_t pin_dsc)
-{
-       hal_gpio_pin_get_port_base(pin_dsc)->DIR &= ~(1 << (pin_dsc & 0x1f));
-       return 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
  */
-static inline int hal_gpio_pin_direction_output(uint32_t pin_dsc, uint32_t value)
-{
-       hal_gpio_pin_set_value(pin_dsc, value);
-       hal_gpio_pin_get_port_base(pin_dsc)->DIR |= (1 << (pin_dsc & 0x1f));
-       return 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
  */
-static inline int hal_gpio_pin_get_direction(uint32_t pin_dsc)
-{
-       return (hal_gpio_pin_get_port_base(pin_dsc)->DIR >> (pin_dsc & 0x1f)) & 1;
-}
-
+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);
 
 /**
@@ -161,10 +156,7 @@ uint32_t hal_gpio_pin_conf_set(uint32_t pin_dsc, uint32_t conf);
  * @param[in]   pin_dsc pin descriptor
  * @return always 0;
  */
-static inline uint32_t hal_gpio_pin_conf(uint32_t pin_dsc)
-{
-       return hal_gpio_pin_conf_set(pin_dsc, pin_dsc);
-}
+uint32_t hal_gpio_pin_conf(uint32_t pin_dsc);
 
 
 #endif //_HAL_GPIO_H_
index f2d38d75d4c6be06f1fb8beb753fd69b64b72df7..a3d527716457776746e189d0afaba343dbc02c8e 100644 (file)
 //#include "sys_common.h"
 #include "hal/hal.h"
 
+/**
+ * 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);
 
 #endif /* PORT_GPIO_H_ */
index ad56907082f8a6bfd0d3e03f1ad36be901ec5046..f08c4e1491f2e34ea73a029fb04f13f4ec51d67f 100644 (file)
 //#include "sys_common.h"
 #include "hal/hal.h"
 
+/**
+ * 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);
 
 
index 5a7ec123b89561b0ae0243761c8810977d03a684..0912b8a1686fd84f6beb20304d023c701649ccad 100644 (file)
 
 #include "hal/hal.h"
 
-/**
- * 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
- */
+gioPORT_t *hal_gpio_get_port_base(uint32_t port_num)
+{
+       return port_id_map[port_num];
+}
+
+uint32_t hal_gpio_pin_get_port_num(uint32_t pin_dsc)
+{
+
+       return (pin_dsc & ~PORT_CONF_MASK) >> PORT_SHIFT;
+}
+
+gioPORT_t *hal_gpio_pin_get_port_base(uint32_t pin_dsc)
+{
+       return hal_gpio_get_port_base(hal_gpio_pin_get_port_num(pin_dsc));
+}
+
+
+uint32_t *hal_gpio_pin_get_dsc(const char *pin_name, int len)
+{
+       uint32_t i;
+       const char *pin_name_ptr;
+       char pin_name_term[32];
+
+       if (len != -1) {    // pin name not terminated by '\0'
+               strncpy(pin_name_term, pin_name, len);
+               pin_name_term[len] = '\0';
+               pin_name_ptr = pin_name_term;
+       }
+       else pin_name_ptr = pin_name;
+
+       for (i = 0; i < MAX_PIN_CNT; i++) {
+               if (strcmp(pin_name_ptr, pin_map[i].pin_name) == 0)
+                       return &pin_map[i].pin_desc;
+       }
+       return NULL;
+}
+
+
+uint32_t hal_gpio_pin_get_value(uint32_t pin_dsc)
+{
+       return ((hal_gpio_pin_get_port_base(pin_dsc)->DIN) >> (pin_dsc & 0x1f)) & 1;
+}
+
+
+void hal_gpio_pin_set_value(uint32_t pin_dsc, uint32_t value)
+{
+       if (value)
+               hal_gpio_pin_get_port_base(pin_dsc)->DSET = 1 << (pin_dsc & 0x1f);
+       else
+               hal_gpio_pin_get_port_base(pin_dsc)->DCLR = 1 << (pin_dsc & 0x1f);
+}
+
+
+int hal_gpio_pin_direction_input(uint32_t pin_dsc)
+{
+       hal_gpio_pin_get_port_base(pin_dsc)->DIR &= ~(1 << (pin_dsc & 0x1f));
+       return 0;
+}
+
+int hal_gpio_pin_direction_output(uint32_t pin_dsc, uint32_t value)
+{
+       hal_gpio_pin_set_value(pin_dsc, value);
+       hal_gpio_pin_get_port_base(pin_dsc)->DIR |= (1 << (pin_dsc & 0x1f));
+       return 0;
+}
+
+int hal_gpio_pin_get_direction(uint32_t pin_dsc)
+{
+       return (hal_gpio_pin_get_port_base(pin_dsc)->DIR >> (pin_dsc & 0x1f)) & 1;
+}
+
+
 uint32_t hal_gpio_pin_conf_mode(uint32_t pin_dsc, uint32_t mode)
 {
        gioPORT_t *gioPort = hal_gpio_pin_get_port_base(pin_dsc);
@@ -47,15 +108,7 @@ uint32_t hal_gpio_pin_conf_mode(uint32_t pin_dsc, uint32_t mode)
        return 0;
 }
 
-/**
- * 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)
 {
        gioPORT_t *gioPort = hal_gpio_pin_get_port_base(pin_dsc);
@@ -67,30 +120,7 @@ uint32_t hal_gpio_pin_conf_od(uint32_t pin_dsc, uint32_t od)
        return 0;
 }
 
-/**
- * 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)
 {
        pin_dsc &= ~PORT_CONF_MASK;
@@ -105,3 +135,8 @@ uint32_t hal_gpio_pin_conf_set(uint32_t pin_dsc, uint32_t conf)
 
        return 0;
 }
+
+uint32_t hal_gpio_pin_conf(uint32_t pin_dsc)
+{
+       return hal_gpio_pin_conf_set(pin_dsc, pin_dsc);
+}
index 79e990ede0b3dee4674d388e5dc4a9ab4ba0dff2..71efad2b8110bae711f802670cd636111467f6ef 100644 (file)
 
 #include "hal/hal.h"
 
-/**
- * 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)
 {
        uint32_t i;
@@ -33,13 +26,6 @@ uint32_t hal_gio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *valu
        return 0;
 }
 
-/**
- * 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)
 {
        uint32_t i;
index 21fbe63f9b5f328a20196874815d12828b952ad1..f1cb47efed2fb94a3de882b31e87fa037e9f87df 100644 (file)
  *         This file contains getter and setter functions for SPI port type.
  */
 
-//#include "hal_port_spi.h"
-// Cannot include upper layer
-//#include "drv_spi.h"
-//#include "cmdproc.h"
 #include "hal/spi.h"
 
 #define PORT_BUF 4
@@ -26,14 +22,6 @@ uint8_t spi_port_buf_tx[PORT_BUF];
 /** Buffer for spi response */
 uint8_t spi_port_buf_rx[PORT_BUF];
 
-
-/**
- * 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)
 {
        spi_drv_t *ifc;