• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @file wm_gpio.h
18  *
19  * @brief GPIO Driver Module
20  *
21  * @author dave
22  *
23  * Copyright (c) 2014 Winner Microelectronics Co., Ltd.
24  */
25 #ifndef WM_GPIO_H
26 #define WM_GPIO_H
27 
28 #include "wm_type_def.h"
29 #include "wm_io.h"
30 
31 /** gpio interrupte callback function */
32 typedef void (*tls_gpio_irq_callback)(void *arg);
33 
34 /** Indicating gpio direction */
35 enum tls_gpio_dir {
36     WM_GPIO_DIR_OUTPUT,    /**< output */
37     WM_GPIO_DIR_INPUT      /**< input */
38 };
39 
40 /** Indicating gpio attribute */
41 enum tls_gpio_attr {
42     WM_GPIO_ATTR_FLOATING,    /**< floating status */
43     WM_GPIO_ATTR_PULLHIGH,    /**< pull high */
44     WM_GPIO_ATTR_PULLLOW      /**< pull low */
45 };
46 
47 /** Indicating gpio interrupt trigger type */
48 enum tls_gpio_irq_trig {
49     WM_GPIO_IRQ_TRIG_RISING_EDGE,    /**< rising edge arises the interrupt */
50     WM_GPIO_IRQ_TRIG_FALLING_EDGE,   /**< falling edge arises the interrupt */
51     WM_GPIO_IRQ_TRIG_DOUBLE_EDGE,    /**< both rising edge and falling edge arise the interrupt */
52     WM_GPIO_IRQ_TRIG_HIGH_LEVEL,     /**< high power level arises the interrupt */
53     WM_GPIO_IRQ_TRIG_LOW_LEVEL       /**< low power level arises the interrupt */
54 };
55 
56 /**
57  * @defgroup Driver_APIs Driver APIs
58  * @brief Driver APIs
59  */
60 
61 /**
62  * @addtogroup Driver_APIs
63  * @{
64  */
65 
66 /**
67  * @defgroup GPIO_Driver_APIs GPIO Driver APIs
68  * @brief GPIO driver APIs
69  */
70 
71 /**
72  * @addtogroup GPIO_Driver_APIs
73  * @{
74  */
75 
76 /**
77  * @brief          	This function is used to config gpio function
78  *
79  * @param[in]      	gpio_pin    	gpio pin num
80  * @param[in]      	dir         		gpio direction
81  * @param[in]      	attr        		gpio attribute
82  *
83  * @return         None
84  *
85  * @note			None
86  */
87 void tls_gpio_cfg(enum tls_io_name gpio_pin, enum tls_gpio_dir dir, enum tls_gpio_attr attr);
88 
89 /**
90  * @brief          This function is used to read gpio status
91  *
92  * @param[in]      gpio_pin    gpio pin num
93  *
94  * @retval         0     power level is low
95  * @retval         1     power level is high
96  *
97  * @note           None
98  */
99 u8 tls_gpio_read(enum tls_io_name gpio_pin);
100 
101 /**
102  * @brief          	This function is used to modify gpio status
103  *
104  * @param[in]      	gpio_pin    	gpio pin num
105  * @param[in]      	value       	power level
106  *                        	0: 			low  power level
107  * 				1: 			high power level
108  *
109  * @return         	None
110  *
111  * @note           None
112  */
113 void tls_gpio_write(enum tls_io_name gpio_pin, u8 value);
114 
115 /**
116  * @brief          This function is used to config gpio interrupt
117  *
118  * @param[in]      gpio_pin    gpio pin num
119  * @param[in]      mode        interrupt trigger type
120  *
121  * @return         None
122  *
123  * @note           None
124  */
125 void tls_gpio_irq_enable(enum tls_io_name gpio_pin, enum tls_gpio_irq_trig mode);
126 
127 /**
128  * @brief          This function is used to disable gpio interrupt
129  *
130  * @param[in]      gpio_pin    gpio pin num
131  *
132  * @return         None
133  *
134  * @note           None
135  */
136 void tls_gpio_irq_disable(enum tls_io_name gpio_pin);
137 
138 /**
139  * @brief          This function is used to get gpio interrupt status
140  *
141  * @param[in]      gpio_pin    gpio pin num
142  *
143  * @retval         0     no interrupt happened
144  * @retval         1     interrupt happened
145  *
146  * @note           None
147  */
148 u8 tls_get_gpio_irq_status(enum tls_io_name gpio_pin);
149 
150 /**
151  * @brief          This function is used to clear gpio interrupt flag
152  *
153  * @param[in]      gpio_pin    gpio pin num
154  *
155  * @return         None
156  *
157  * @note           None
158  */
159 void tls_clr_gpio_irq_status(enum tls_io_name gpio_pin);
160 
161 /**
162  * @brief          This function is used to register gpio interrupt
163  *
164  * @param[in]      gpio_pin    gpio pin num
165  * @param[in]      callback    the gpio interrupt call back function
166  * @param[in]      arg         parammeter for the callback
167  *
168  * @return         None
169  *
170  * @note
171  * gpio callback function is called in interrupt,
172  * so can not operate the critical data in the callback fuuction,
173  * recommendation to send messages to other tasks to operate it.
174  */
175 void tls_gpio_isr_register(enum tls_io_name gpio_pin,
176                            tls_gpio_irq_callback callback,
177                            void *arg);
178 /**
179  * @}
180  */
181 
182 /**
183  * @}
184  */
185 
186 #endif /* end of WM_GPIO_H */
187 
188