2 * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 /******************************************************************************
18 * @brief header file for gpio driver
21 ******************************************************************************/
32 #include <drv_common.h>
35 /// definition for gpio port handle.
36 typedef void *gpio_port_handle_t;
37 /// definition for gpio pin handle.
38 typedef void *gpio_pin_handle_t;
40 /****** GPIO specific error codes *****/
42 GPIO_ERROR_MODE = (EDRV_SPECIFIC + 1), ///< Specified Mode not suphandleed
43 GPIO_ERROR_DIRECTION, ///< Specified direction not suphandleed
44 GPIO_ERROR_IRQ_MODE, ///< Specified irq mode not suphandleed
47 /*----- GPIO Control Codes: Mode -----*/
49 GPIO_MODE_PULLNONE = 1, ///< pull none for input
50 GPIO_MODE_PULLUP = 5, ///< pull up for input
51 GPIO_MODE_PULLDOWM = 3, ///< pull down for input
52 GPIO_MODE_OPEN_DRAIN = 2, ///< open drain mode for output
53 GPIO_MODE_PUSH_PULL = 4 ///< push-pull mode for output
56 /*----- GPIO Control Codes: Mode Parameters: Data Bits -----*/
58 GPIO_DIRECTION_INPUT = 0, ///< gpio as input
59 GPIO_DIRECTION_OUTPUT , ///< gpio as output
62 /*----- GPIO Control Codes: Mode Parameters: Parity -----*/
64 GPIO_IRQ_MODE_RISING_EDGE = 0, ///< interrupt mode for rising edge
65 GPIO_IRQ_MODE_FALLING_EDGE , ///< interrupt mode for falling edge
66 GPIO_IRQ_MODE_DOUBLE_EDGE , ///< interrupt mode for double edge
67 GPIO_IRQ_MODE_LOW_LEVEL , ///< interrupt mode for low level
68 GPIO_IRQ_MODE_HIGH_LEVEL , ///< interrupt mode for high level
72 \brief GPIO Driver Capabilities.
75 uint32_t interrupt_mode : 1; ///< suphandles GPIO interrupt mode
76 uint32_t pull_mode : 1;
77 } gpio_capabilities_t;
80 typedef void (*gpio_event_cb_t)(void *arg); ///< gpio Event call back.
83 \brief Initialize GPIO module. 1. Initializes the resources needed for the GPIO handle 2.registers event callback function
84 3.get gpio_port_handle
85 \param[in] port port_name.
86 \return gpio_port_handle
88 gpio_port_handle_t csi_gpio_port_initialize(port_name_t port);
91 \brief De-initialize GPIO handle. stops operation and releases the software resources used by the handle
92 \param[in] handle gpio port handle to operate.
95 int32_t csi_gpio_port_uninitialize(gpio_port_handle_t handle);
98 \brief Get gpio capabilities.all pins have same capabilities in one handle
99 \param[in] handle handle instance to operate.
100 \return \ref gpio_capabilities_t
102 gpio_capabilities_t csi_gpio_get_io_capabilities(gpio_port_handle_t handle);
105 \brief config multiple pin within one handle
106 \param[in] handle gpio port handle to operate.
107 \param[in] mask the bitmask to identify which bits in the handle should be included (0 - ignore)
108 \param[in] mode \ref gpio_mode_e
109 \param[in] dir \ref gpio_direction_e
112 int32_t csi_gpio_port_config(gpio_port_handle_t handle,
115 gpio_direction_e dir);
118 \brief Write value to the handle(write value to multiple pins on one handle at the same time)
119 \param[in] handle gpio port handle to operate.
120 \param[in] mask The bitmask to identify which bits in the handle should be included (0 - ignore)
121 \param[in] value the value to be set
124 int32_t csi_gpio_port_write(gpio_port_handle_t handle, uint32_t mask, uint32_t value);
127 \brief Read the current value on the handle(read value of multiple pins on one handle at the same time)
128 \param[in] handle gpio port handle to operate.
129 \param[in] mask The bitmask to identify which bits in the handle should be included (0 - ignore)
130 \param[out] value an integer with each bit corresponding to an associated handle pin setting
133 int32_t csi_gpio_port_read(gpio_port_handle_t handle, uint32_t mask, uint32_t *value);
136 \brief Initialize GPIO handle.
137 \param[in] gpio_pin Pointer to the pin_t.
138 \param[in] cb_event Pointer to \ref gpio_event_cb_t
139 \param[in] arg Pointer to \ref arg used for the callback
140 \return gpio_pin_handle
142 gpio_pin_handle_t csi_gpio_pin_initialize(pin_t gpio_pin, gpio_event_cb_t cb_event, void *arg);
145 \brief De-initialize GPIO pin handle.stops operation and releases the software resources used by the handle.
146 \param[in] handle gpio pin handle to operate.
149 int32_t csi_gpio_pin_uninitialize(gpio_pin_handle_t handle);
153 \param[in] pin gpio pin handle to operate.
154 \param[in] mode \ref gpio_mode_e
155 \param[in] dir \ref gpio_direction_e
158 int32_t csi_gpio_pin_config(gpio_pin_handle_t pin,
160 gpio_direction_e dir);
163 \brief Set one or zero to the selected GPIO pin.
164 \param[in] pin gpio pin handle to operate.
165 \param[in] value the value to be set
168 int32_t csi_gpio_pin_write(gpio_pin_handle_t pin, bool value);
171 \brief Get the value of selected GPIO pin.
172 \param[in] pin gpio pin handle to operate.
173 \param[out] value buf to store the pin value
176 int32_t csi_gpio_pin_read(gpio_pin_handle_t pin, bool *value);
179 \brief set GPIO interrupt mode.
180 \param[in] pin gpio pin handle to operate.
181 \param[in] mode the irq mode to be set
182 \param[in] enable the enable flag
185 int32_t csi_gpio_pin_irq_set(gpio_pin_handle_t pin, gpio_irq_mode_e mode, bool enable);
192 #endif /* _CSI_GPIO_H_ */