no-OS
gpio.h
Go to the documentation of this file.
1 /***************************************************************************/
40 #ifndef GPIO_H_
41 #define GPIO_H_
42 
43 /******************************************************************************/
44 /***************************** Include Files **********************************/
45 /******************************************************************************/
46 
47 #include <stdint.h>
48 
49 /******************************************************************************/
50 /********************** Macros and Constants Definitions **********************/
51 /******************************************************************************/
52 
53 #define GPIO_OUT 0x01
54 #define GPIO_IN 0x00
55 
56 /******************************************************************************/
57 /*************************** Types Declarations *******************************/
58 /******************************************************************************/
59 
65 struct gpio_platform_ops ;
66 
71 typedef struct gpio_init_param {
73  int32_t number;
77  void *extra;
79 
84 typedef struct gpio_desc {
86  int32_t number;
90  void *extra;
91 } gpio_desc;
92 
104 };
105 
113  int32_t (*gpio_ops_get)(struct gpio_desc **, const struct gpio_init_param *);
115  int32_t (*gpio_ops_get_optional)(struct gpio_desc **,
116  const struct gpio_init_param *);
118  int32_t (*gpio_ops_remove)(struct gpio_desc *);
120  int32_t (*gpio_ops_direction_input)(struct gpio_desc *);
122  int32_t (*gpio_ops_direction_output)(struct gpio_desc *, uint8_t);
124  int32_t (*gpio_ops_get_direction)(struct gpio_desc *, uint8_t *);
126  int32_t (*gpio_ops_set_value)(struct gpio_desc *, uint8_t);
128  int32_t (*gpio_ops_get_value)(struct gpio_desc *, uint8_t *);
129 };
130 
131 /******************************************************************************/
132 /************************ Functions Declarations ******************************/
133 /******************************************************************************/
134 
135 /* Obtain the GPIO decriptor. */
136 int32_t gpio_get(struct gpio_desc **desc,
137  const struct gpio_init_param *param);
138 
139 /* Obtain optional GPIO descriptor. */
140 int32_t gpio_get_optional(struct gpio_desc **desc,
141  const struct gpio_init_param *param);
142 
143 /* Free the resources allocated by gpio_get() */
144 int32_t gpio_remove(struct gpio_desc *desc);
145 
146 /* Enable the input direction of the specified GPIO. */
147 int32_t gpio_direction_input(struct gpio_desc *desc);
148 
149 /* Enable the output direction of the specified GPIO. */
150 int32_t gpio_direction_output(struct gpio_desc *desc,
151  uint8_t value);
152 
153 /* Get the direction of the specified GPIO. */
154 int32_t gpio_get_direction(struct gpio_desc *desc,
155  uint8_t *direction);
156 
157 /* Set the value of the specified GPIO. */
158 int32_t gpio_set_value(struct gpio_desc *desc,
159  uint8_t value);
160 
161 /* Get the value of the specified GPIO. */
162 int32_t gpio_get_value(struct gpio_desc *desc,
163  uint8_t *value);
164 
165 #endif // GPIO_H_
gpio_platform_ops::gpio_ops_get_direction
int32_t(* gpio_ops_get_direction)(struct gpio_desc *, uint8_t *)
Definition: gpio.h:124
gpio_platform_ops::gpio_ops_set_value
int32_t(* gpio_ops_set_value)(struct gpio_desc *, uint8_t)
Definition: gpio.h:126
gpio_platform_ops::gpio_ops_remove
int32_t(* gpio_ops_remove)(struct gpio_desc *)
Definition: gpio.h:118
gpio_platform_ops::gpio_ops_get
int32_t(* gpio_ops_get)(struct gpio_desc **, const struct gpio_init_param *)
Definition: gpio.h:113
gpio_direction_output
int32_t gpio_direction_output(struct gpio_desc *desc, uint8_t value)
Enable the output direction of the specified GPIO.
Definition: gpio.c:124
GPIO_LOW
@ GPIO_LOW
Definition: gpio.h:99
gpio_desc
struct gpio_desc gpio_desc
gpio_get_direction
int32_t gpio_get_direction(struct gpio_desc *desc, uint8_t *direction)
Get the direction of the specified GPIO.
Definition: gpio.c:142
gpio_platform_ops::gpio_ops_direction_input
int32_t(* gpio_ops_direction_input)(struct gpio_desc *)
Definition: gpio.h:120
gpio_platform_ops::gpio_ops_get_optional
int32_t(* gpio_ops_get_optional)(struct gpio_desc **, const struct gpio_init_param *)
Definition: gpio.h:115
gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: gpio.h:71
gpio_desc::extra
void * extra
Definition: gpio.h:90
gpio_desc::number
int32_t number
Definition: gpio.h:86
gpio_get_optional
int32_t gpio_get_optional(struct gpio_desc **desc, const struct gpio_init_param *param)
Get the value of an optional GPIO.
Definition: gpio.c:75
gpio_init_param
struct gpio_init_param gpio_init_param
gpio_init_param::platform_ops
const struct gpio_platform_ops * platform_ops
Definition: gpio.h:75
gpio_platform_ops::gpio_ops_get_value
int32_t(* gpio_ops_get_value)(struct gpio_desc *, uint8_t *)
Definition: gpio.h:128
gpio_desc::platform_ops
const struct gpio_platform_ops * platform_ops
Definition: gpio.h:88
gpio_desc
Structure holding the GPIO descriptor.
Definition: gpio.h:84
gpio_values
gpio_values
Enum that holds the possible output states of a GPIO.
Definition: gpio.h:97
gpio_direction_input
int32_t gpio_direction_input(struct gpio_desc *desc)
Enable the input direction of the specified GPIO.
Definition: gpio.c:108
gpio_set_value
int32_t gpio_set_value(struct gpio_desc *desc, uint8_t value)
Set the value of the specified GPIO.
Definition: gpio.c:160
GPIO_HIGH
@ GPIO_HIGH
Definition: gpio.h:101
gpio_get
int32_t gpio_get(struct gpio_desc **desc, const struct gpio_init_param *param)
Obtain the GPIO decriptor.
Definition: gpio.c:55
gpio_platform_ops
Structure holding gpio function pointers that point to the platform specific function.
Definition: gpio.h:111
gpio_init_param::number
int32_t number
Definition: gpio.h:73
GPIO_HIGH_Z
@ GPIO_HIGH_Z
Definition: gpio.h:103
gpio_init_param::extra
void * extra
Definition: gpio.h:77
gpio_remove
int32_t gpio_remove(struct gpio_desc *desc)
Free the resources allocated by gpio_get().
Definition: gpio.c:95
gpio_get_value
int32_t gpio_get_value(struct gpio_desc *desc, uint8_t *value)
Get the value of the specified GPIO.
Definition: gpio.c:177
gpio_platform_ops::gpio_ops_direction_output
int32_t(* gpio_ops_direction_output)(struct gpio_desc *, uint8_t)
Definition: gpio.h:122