2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
6 * GPIO -- General Purpose Input/Output
8 * Defines a simple and generic interface to access GPIO device.
15 #include <drivers/gpio.h>
18 * The gpio implementation
20 static const gpio_ops_t
*ops
;
22 int gpio_get_direction(int gpio
)
25 assert(ops
->get_direction
!= 0);
28 return ops
->get_direction(gpio
);
31 void gpio_set_direction(int gpio
, int direction
)
34 assert(ops
->set_direction
!= 0);
35 assert((direction
== GPIO_DIR_OUT
) || (direction
== GPIO_DIR_IN
));
38 ops
->set_direction(gpio
, direction
);
41 int gpio_get_value(int gpio
)
44 assert(ops
->get_value
!= 0);
47 return ops
->get_value(gpio
);
50 void gpio_set_value(int gpio
, int value
)
53 assert(ops
->set_value
!= 0);
54 assert((value
== GPIO_LEVEL_LOW
) || (value
== GPIO_LEVEL_HIGH
));
57 ops
->set_value(gpio
, value
);
60 void gpio_set_pull(int gpio
, int pull
)
63 assert(ops
->set_pull
!= 0);
64 assert((pull
== GPIO_PULL_NONE
) || (pull
== GPIO_PULL_UP
) ||
65 (pull
== GPIO_PULL_DOWN
));
68 ops
->set_pull(gpio
, pull
);
71 int gpio_get_pull(int gpio
)
74 assert(ops
->get_pull
!= 0);
77 return ops
->get_pull(gpio
);
81 * Initialize the gpio. The fields in the provided gpio
82 * ops pointer must be valid.
84 void gpio_init(const gpio_ops_t
*ops_ptr
)
86 assert(ops_ptr
!= 0 &&
87 (ops_ptr
->get_direction
!= 0) &&
88 (ops_ptr
->set_direction
!= 0) &&
89 (ops_ptr
->get_value
!= 0) &&
90 (ops_ptr
->set_value
!= 0));