]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/T-HEAD_CB2201_CDK/csi/csi_driver/include/drv_gpio.h
Introduce a port for T-HEAD CK802. A simple demo for T-HEAD CB2201 is also included.
[freertos] / FreeRTOS / Demo / T-HEAD_CB2201_CDK / csi / csi_driver / include / drv_gpio.h
1 /*
2  * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /******************************************************************************
17  * @file     drv_gpio.h
18  * @brief    header file for gpio driver
19  * @version  V1.0
20  * @date     02. June 2017
21  ******************************************************************************/
22
23 #ifndef _CSI_GPIO_H_
24 #define _CSI_GPIO_H_
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #include <stdint.h>
31 #include <stdbool.h>
32 #include <drv_common.h>
33 #include <pin_name.h>
34
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;
39
40 /****** GPIO specific error codes *****/
41 typedef enum {
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
45 } drv_gpio_error_e;
46
47 /*----- GPIO Control Codes: Mode -----*/
48 typedef enum {
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
54 } gpio_mode_e;
55
56 /*----- GPIO Control Codes: Mode Parameters: Data Bits -----*/
57 typedef enum {
58     GPIO_DIRECTION_INPUT             = 0,    ///< gpio as input
59     GPIO_DIRECTION_OUTPUT               ,    ///< gpio as output
60 } gpio_direction_e;
61
62 /*----- GPIO Control Codes: Mode Parameters: Parity -----*/
63 typedef enum {
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
69 } gpio_irq_mode_e;
70
71 /**
72 \brief GPIO Driver Capabilities.
73 */
74 typedef struct  {
75     uint32_t interrupt_mode       : 1;      ///< suphandles GPIO interrupt mode
76     uint32_t pull_mode            : 1;
77 } gpio_capabilities_t;
78
79
80 typedef void (*gpio_event_cb_t)(void *arg);   ///< gpio Event call back.
81
82 /**
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
87 */
88 gpio_port_handle_t csi_gpio_port_initialize(port_name_t port);
89
90 /**
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.
93   \return      error code
94 */
95 int32_t csi_gpio_port_uninitialize(gpio_port_handle_t handle);
96
97 /**
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
101 */
102 gpio_capabilities_t csi_gpio_get_io_capabilities(gpio_port_handle_t handle);
103
104 /**
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
110   \return      error code
111 */
112 int32_t csi_gpio_port_config(gpio_port_handle_t handle,
113                              uint32_t mask,
114                              gpio_mode_e mode,
115                              gpio_direction_e dir);
116
117 /**
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
122   \return      error code
123 */
124 int32_t csi_gpio_port_write(gpio_port_handle_t handle, uint32_t mask, uint32_t value);
125
126 /**
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
131   \return      error code
132 */
133 int32_t csi_gpio_port_read(gpio_port_handle_t handle, uint32_t mask, uint32_t *value);
134
135 /**
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
141 */
142 gpio_pin_handle_t csi_gpio_pin_initialize(pin_t gpio_pin, gpio_event_cb_t cb_event, void *arg);
143
144 /**
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.
147   \return      error code
148 */
149 int32_t csi_gpio_pin_uninitialize(gpio_pin_handle_t handle);
150
151 /**
152   \brief       config pin
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
156   \return      error code
157 */
158 int32_t csi_gpio_pin_config(gpio_pin_handle_t pin,
159                             gpio_mode_e mode,
160                             gpio_direction_e dir);
161
162 /**
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
166   \return      error code
167 */
168 int32_t csi_gpio_pin_write(gpio_pin_handle_t pin, bool value);
169
170 /**
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
174   \return      error code
175 */
176 int32_t csi_gpio_pin_read(gpio_pin_handle_t pin, bool *value);
177
178 /**
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
183   \return      error code
184 */
185 int32_t csi_gpio_pin_irq_set(gpio_pin_handle_t pin, gpio_irq_mode_e mode, bool enable);
186
187
188 #ifdef __cplusplus
189 }
190 #endif
191
192 #endif /* _CSI_GPIO_H_ */