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 
79 };
80 
85 typedef struct gpio_init_param {
87  int32_t number;
93  void *extra;
95 
100 typedef struct gpio_desc {
102  int32_t number;
108  void *extra;
109 } gpio_desc;
110 
122 };
123 
131  int32_t (*gpio_ops_get)(struct gpio_desc **, const struct gpio_init_param *);
133  int32_t (*gpio_ops_get_optional)(struct gpio_desc **,
134  const struct gpio_init_param *);
136  int32_t (*gpio_ops_remove)(struct gpio_desc *);
138  int32_t (*gpio_ops_direction_input)(struct gpio_desc *);
140  int32_t (*gpio_ops_direction_output)(struct gpio_desc *, uint8_t);
142  int32_t (*gpio_ops_get_direction)(struct gpio_desc *, uint8_t *);
144  int32_t (*gpio_ops_set_value)(struct gpio_desc *, uint8_t);
146  int32_t (*gpio_ops_get_value)(struct gpio_desc *, uint8_t *);
147 };
148 
149 /******************************************************************************/
150 /************************ Functions Declarations ******************************/
151 /******************************************************************************/
152 
153 /* Obtain the GPIO decriptor. */
154 int32_t gpio_get(struct gpio_desc **desc,
155  const struct gpio_init_param *param);
156 
157 /* Obtain optional GPIO descriptor. */
158 int32_t gpio_get_optional(struct gpio_desc **desc,
159  const struct gpio_init_param *param);
160 
161 /* Free the resources allocated by gpio_get() */
162 int32_t gpio_remove(struct gpio_desc *desc);
163 
164 /* Enable the input direction of the specified GPIO. */
165 int32_t gpio_direction_input(struct gpio_desc *desc);
166 
167 /* Enable the output direction of the specified GPIO. */
168 int32_t gpio_direction_output(struct gpio_desc *desc,
169  uint8_t value);
170 
171 /* Get the direction of the specified GPIO. */
172 int32_t gpio_get_direction(struct gpio_desc *desc,
173  uint8_t *direction);
174 
175 /* Set the value of the specified GPIO. */
176 int32_t gpio_set_value(struct gpio_desc *desc,
177  uint8_t value);
178 
179 /* Get the value of the specified GPIO. */
180 int32_t gpio_get_value(struct gpio_desc *desc,
181  uint8_t *value);
182 
183 #endif // GPIO_H_
gpio_init_param::pull
enum gpio_pull_up pull
Definition: gpio.h:89
gpio_desc::pull
enum gpio_pull_up pull
Definition: gpio.h:104
gpio_platform_ops::gpio_ops_get_direction
int32_t(* gpio_ops_get_direction)(struct gpio_desc *, uint8_t *)
Definition: gpio.h:142
gpio_platform_ops::gpio_ops_set_value
int32_t(* gpio_ops_set_value)(struct gpio_desc *, uint8_t)
Definition: gpio.h:144
gpio_platform_ops::gpio_ops_remove
int32_t(* gpio_ops_remove)(struct gpio_desc *)
Definition: gpio.h:136
NO_OS_PULL_NONE
@ NO_OS_PULL_NONE
Definition: gpio.h:72
gpio_platform_ops::gpio_ops_get
int32_t(* gpio_ops_get)(struct gpio_desc **, const struct gpio_init_param *)
Definition: gpio.h:131
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
NO_OS_PULL_UP
@ NO_OS_PULL_UP
Definition: gpio.h:74
GPIO_LOW
@ GPIO_LOW
Definition: gpio.h:117
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:138
gpio_platform_ops::gpio_ops_get_optional
int32_t(* gpio_ops_get_optional)(struct gpio_desc **, const struct gpio_init_param *)
Definition: gpio.h:133
gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: gpio.h:85
gpio_desc::extra
void * extra
Definition: gpio.h:108
NO_OS_PULL_UP_WEAK
@ NO_OS_PULL_UP_WEAK
Definition: gpio.h:77
gpio_desc::number
int32_t number
Definition: gpio.h:102
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:91
gpio_platform_ops::gpio_ops_get_value
int32_t(* gpio_ops_get_value)(struct gpio_desc *, uint8_t *)
Definition: gpio.h:146
gpio_desc::platform_ops
const struct gpio_platform_ops * platform_ops
Definition: gpio.h:106
gpio_desc
Structure holding the GPIO descriptor.
Definition: gpio.h:100
gpio_values
gpio_values
Enum that holds the possible output states of a GPIO.
Definition: gpio.h:115
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:119
gpio_get
int32_t gpio_get(struct gpio_desc **desc, const struct gpio_init_param *param)
Obtain the GPIO decriptor.
Definition: gpio.c:55
NO_OS_PULL_DOWN
@ NO_OS_PULL_DOWN
Definition: gpio.h:76
gpio_platform_ops
Structure holding gpio function pointers that point to the platform specific function.
Definition: gpio.h:129
gpio_init_param::number
int32_t number
Definition: gpio.h:87
GPIO_HIGH_Z
@ GPIO_HIGH_Z
Definition: gpio.h:121
gpio_init_param::extra
void * extra
Definition: gpio.h:93
NO_OS_PULL_DOWN_WEAK
@ NO_OS_PULL_DOWN_WEAK
Definition: gpio.h:78
gpio_remove
int32_t gpio_remove(struct gpio_desc *desc)
Free the resources allocated by gpio_get().
Definition: gpio.c:95
gpio_pull_up
gpio_pull_up
Enum that holds the possible pull up/ pull down resistor configuration.
Definition: gpio.h:71
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:140