]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_FreedomStudio/freedom-metal/metal/gpio.h
Update RISCC-V-RV32-SiFive_HiFive1_FreedomStudio project to latest tools and metal...
[freertos] / FreeRTOS / Demo / RISC-V_RV32_SiFive_HiFive1_FreedomStudio / freedom-metal / metal / gpio.h
index 513687dd7c6c3af5fa4710ba690963b44a0135b4..7645494ff61c949a1c67353cf3ae69a2c7bda367 100644 (file)
@@ -5,6 +5,7 @@
 #define METAL__GPIO_H
 
 #include <metal/compiler.h>
+#include <metal/interrupt.h>
 
 /*!
  * @file gpio.h
@@ -15,14 +16,31 @@ struct metal_gpio;
 
 struct __metal_gpio_vtable {
     int (*disable_input)(struct metal_gpio *, long pins);
+    int (*enable_input)(struct metal_gpio *, long pins);
+    long (*input)(struct metal_gpio *);
     long (*output)(struct metal_gpio *);
+    int (*disable_output)(struct metal_gpio *, long pins);
     int (*enable_output)(struct metal_gpio *, long pins);
     int (*output_set)(struct metal_gpio *, long value);
     int (*output_clear)(struct metal_gpio *, long value);
     int (*output_toggle)(struct metal_gpio *, long value);
     int (*enable_io)(struct metal_gpio *, long pins, long dest);
+    int (*disable_io)(struct metal_gpio *, long pins);
+    int (*config_int)(struct metal_gpio *, long pins, int intr_type);
+    int (*clear_int)(struct metal_gpio *, long pins, int intr_type);
+    struct metal_interrupt* (*interrupt_controller)(struct metal_gpio *gpio);
+    int (*get_interrupt_id)(struct metal_gpio *gpio, int pin);
 };
 
+#define METAL_GPIO_INT_DISABLE       0
+#define METAL_GPIO_INT_RISING        1
+#define METAL_GPIO_INT_FALLING       2
+#define METAL_GPIO_INT_BOTH_EDGE     3
+#define METAL_GPIO_INT_LOW           4
+#define METAL_GPIO_INT_HIGH          5
+#define METAL_GPIO_INT_BOTH_LEVEL    6
+#define METAL_GPIO_INT_MAX           7
+
 /*!
  * @struct metal_gpio
  * @brief The handle for a GPIO interface
@@ -36,7 +54,21 @@ struct metal_gpio {
  * @param device_num The GPIO device index
  * @return The GPIO device handle, or NULL if there is no device at that index
  */
-struct metal_gpio *metal_gpio_get_device(int device_num);
+struct metal_gpio *metal_gpio_get_device(unsigned int device_num);
+
+/*!
+ * @brief enable input on a pin
+ * @param gpio The handle for the GPIO interface
+ * @param pin The pin number indexed from 0
+ * @return 0 if the input is successfully enabled
+ */
+__inline__ int metal_gpio_enable_input(struct metal_gpio *gpio, int pin) {
+    if(!gpio) {
+       return 1;
+    }
+
+    return gpio->vtable->enable_input(gpio, (1 << pin));
+}
 
 /*!
  * @brief Disable input on a pin
@@ -44,7 +76,7 @@ struct metal_gpio *metal_gpio_get_device(int device_num);
  * @param pin The pin number indexed from 0
  * @return 0 if the input is successfully disabled
  */
-inline int metal_gpio_disable_input(struct metal_gpio *gpio, int pin) {
+__inline__ int metal_gpio_disable_input(struct metal_gpio *gpio, int pin) {
     if(!gpio) {
        return 1;
     }
@@ -58,7 +90,7 @@ inline int metal_gpio_disable_input(struct metal_gpio *gpio, int pin) {
  * @param pin The pin number indexed from 0
  * @return 0 if the output is successfully enabled
  */
-inline int metal_gpio_enable_output(struct metal_gpio *gpio, int pin) {
+__inline__ int metal_gpio_enable_output(struct metal_gpio *gpio, int pin) {
     if(!gpio) {
        return 1;
     }
@@ -66,6 +98,20 @@ inline int metal_gpio_enable_output(struct metal_gpio *gpio, int pin) {
     return gpio->vtable->enable_output(gpio, (1 << pin));
 }
 
+/*!
+ * @brief Disable output on a pin
+ * @param gpio The handle for the GPIO interface
+ * @param pin The pin number indexed from 0
+ * @return 0 if the output is successfully disabled
+ */
+__inline__ int metal_gpio_disable_output(struct metal_gpio *gpio, int pin) {
+    if(!gpio) {
+       return 1;
+    }
+
+    return gpio->vtable->disable_output(gpio, (1 << pin));
+}
+
 /*!
  * @brief Set the output value of a GPIO pin
  * @param gpio The handle for the GPIO interface
@@ -73,7 +119,7 @@ inline int metal_gpio_enable_output(struct metal_gpio *gpio, int pin) {
  * @param value The value to set the pin to
  * @return 0 if the output is successfully set
  */
-inline int metal_gpio_set_pin(struct metal_gpio *gpio, int pin, int value) {
+__inline__ int metal_gpio_set_pin(struct metal_gpio *gpio, int pin, int value) {
     if(!gpio) {
        return 1;
     }
@@ -91,7 +137,27 @@ inline int metal_gpio_set_pin(struct metal_gpio *gpio, int pin, int value) {
  * @param pin The pin number indexed from 0
  * @return The value of the GPIO pin
  */
-inline int metal_gpio_get_pin(struct metal_gpio *gpio, int pin) {
+__inline__ int metal_gpio_get_input_pin(struct metal_gpio *gpio, int pin) {
+    if(!gpio) {
+       return 0;
+    }
+
+    long value = gpio->vtable->input(gpio);
+
+    if(value & (1 << pin)) {
+           return 1;
+    } else {
+           return 0;
+    }
+}
+
+/*!
+ * @brief Get the value of the GPIO pin
+ * @param gpio The handle for the GPIO interface
+ * @param pin The pin number indexed from 0
+ * @return The value of the GPIO pin
+ */
+__inline__ int metal_gpio_get_output_pin(struct metal_gpio *gpio, int pin) {
     if(!gpio) {
        return 0;
     }
@@ -111,7 +177,7 @@ inline int metal_gpio_get_pin(struct metal_gpio *gpio, int pin) {
  * @param pin The pin number indexed from 0
  * @return 0 if the pin is successfully cleared
  */
-inline int metal_gpio_clear_pin(struct metal_gpio *gpio, int pin) {
+__inline__ int metal_gpio_clear_pin(struct metal_gpio *gpio, int pin) {
     if(!gpio) {
        return 1;
     }
@@ -125,7 +191,7 @@ inline int metal_gpio_clear_pin(struct metal_gpio *gpio, int pin) {
  * @param pin The pin number indexed from 0
  * @return 0 if the pin is successfully toggled
  */
-inline int metal_gpio_toggle_pin(struct metal_gpio *gpio, int pin) {
+__inline__ int metal_gpio_toggle_pin(struct metal_gpio *gpio, int pin) {
     if(!gpio) {
        return 1;
     }
@@ -140,7 +206,7 @@ inline int metal_gpio_toggle_pin(struct metal_gpio *gpio, int pin) {
  * @param io_function The IO function to set
  * @return 0 if the pinmux is successfully set
  */
-inline int metal_gpio_enable_pinmux(struct metal_gpio *gpio, int pin, int io_function) {
+__inline__ int metal_gpio_enable_pinmux(struct metal_gpio *gpio, int pin, int io_function) {
     if(!gpio) {
        return 1;
     }
@@ -148,4 +214,71 @@ inline int metal_gpio_enable_pinmux(struct metal_gpio *gpio, int pin, int io_fun
     return gpio->vtable->enable_io(gpio, (1 << pin), (io_function << pin));
 }
 
+/*!
+ * @brief Disables the pinmux for a GPIO pin
+ * @param gpio The handle for the GPIO interface
+ * @param pin The bitmask for the pin to disable pinmux on
+ * @return 0 if the pinmux is successfully set
+ */
+__inline__ int metal_gpio_disable_pinmux(struct metal_gpio *gpio, int pin) {
+    if(!gpio) {
+       return 1;
+    }
+
+    return gpio->vtable->disable_io(gpio, (1 << pin));
+}
+
+/*!
+ * @brief Config gpio interrupt type
+ * @param gpio The handle for the GPIO interface
+ * @param pin The bitmask for the pin to enable gpio interrupt
+ * @param intr_type The interrupt type
+ * @return 0 if the interrupt mode is setup properly
+ */
+__inline__ int metal_gpio_config_interrupt(struct metal_gpio *gpio, int pin, int intr_type) {
+    if(!gpio) {
+       return 1;
+    }
+
+    return gpio->vtable->config_int(gpio, (1 << pin), intr_type);
+}
+
+/*!
+ * @brief Clear gpio interrupt status
+ * @param gpio The handle for the GPIO interface
+ * @param pin The bitmask for the pin to clear gpio interrupt
+ * @param intr_type The interrupt type to be clear
+ * @return 0 if the interrupt is cleared
+ */
+__inline__ int metal_gpio_clear_interrupt(struct metal_gpio *gpio, int pin, int intr_type) {
+    if(!gpio) {
+       return 1;
+    }
+
+    return gpio->vtable->clear_int(gpio, (1 << pin), intr_type);
+}
+
+/*!
+ * @brief Get the interrupt controller for a gpio
+ *
+ * @param gpio The handle for the gpio
+ * @return A pointer to the interrupt controller responsible for handling
+ * gpio interrupts.
+ */
+__inline__ struct metal_interrupt*
+    metal_gpio_interrupt_controller(struct metal_gpio *gpio) {
+    return gpio->vtable->interrupt_controller(gpio);
+}
+
+/*!
+ * @brief Get the interrupt id for a gpio
+ *
+ * @param gpio The handle for the gpio
+ * @param pin The bitmask for the pin to get gpio interrupt id
+ * @return The interrupt id corresponding to a gpio.
+ */
+__inline__ int metal_gpio_get_interrupt_id(struct metal_gpio *gpio, int pin) {
+    return gpio->vtable->get_interrupt_id(gpio, pin);
+}
+
 #endif