blob: cf6958f52b6a25e04f5f00990d1fca83f6104d78 [file] [log] [blame]
jb.qi4b7d3e92023-09-26 23:30:34 -07001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <sc_bsp.h>
5#include <errno.h>
6#include "lynq-gpio.h"
7#include "liblog/lynq_deflog.h"
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#define USER_LOG_TAG "LYNQ_GPIO"
14
15/*****************************************
16* @brief:lynq_gpio_init
17* @param count [IN]:4
18* @param sum [OUT]:NA
19* @return :success 0, failed -1
20* @todo:NA
21* @see:NA
22* @warning:NA
23******************************************/
24
25int lynq_gpio_init(int gpio, int direction, int value, int pullsel)
26{
27 LYLOGSET(LOG_INFO);
28 LYLOGEINIT(USER_LOG_TAG);
29
30 test_gpio_handle[gpio] = sc_gpio_init(gpio, direction, value, pullsel);
31 if (!test_gpio_handle[gpio])
32 {
33 LYINFLOG("do_gpio_init failed, err:%d", errno);
34 return -1;
35 }
36 return 0;
37}
38
39/*****************************************
40* @brief:lynq_gpio_deinit
41* @param count [IN]:1
42* @param sum [OUT]:NA
43* @return :success 0, failed -1
44* @todo:NA
45* @see:NA
46* @warning:NA
47******************************************/
48
49
50int lynq_gpio_deinit(int gpio)
51{
52 int ret;
53 LYLOGSET(LOG_INFO);
54 LYLOGEINIT(USER_LOG_TAG);
55
56 ret = sc_gpio_uninit(test_gpio_handle[gpio]);
57 if (ret)
58 {
59 LYINFLOG("do_gpio_uninit failed, err:%d", ret);
60 return -1;
61 }
62 return 0;
63}
64
65/*****************************************
66* @brief:lynq_gpio_direction_set
67* @param count [IN]:2
68* @param sum [OUT]:NA
69* @return :success 0, failed -1
70* @todo:NA
71* @see:NA
72* @warning:NA
73******************************************/
74
75int lynq_gpio_direction_set(int gpio, int direction)
76{
77 int ret;
78 LYLOGSET(LOG_INFO);
79 LYLOGEINIT(USER_LOG_TAG);
80 if(direction != 0 && direction != 1)
81 {
82 LYINFLOG("input direction is error\n");
83 return -1;
84 }
85 ret = sc_gpio_direction_set(test_gpio_handle[gpio], direction, 0);
86 if (ret)
87 {
88 LYINFLOG("do_gpio_input set direction failed, err:%d\n", ret);
89 return -1;;
90 }
91 return 0;
92}
93
94/*****************************************
95* @brief:lynq_gpio_value_set
96* @param count [IN]:2
97* @param sum [OUT]:NA
98* @return :success 0, failed -1
99* @todo:NA
100* @see:NA
101* @warning:NA
102******************************************/
103
104int lynq_gpio_value_set(int gpio, int value)
105{
106 int ret;
107 LYLOGSET(LOG_INFO);
108 LYLOGEINIT(USER_LOG_TAG);
109 if(value != 0 && value != 1)
110 {
111 LYINFLOG("input value is error\n");
112 return -1;
113 }
114 ret = sc_gpio_direction_set(test_gpio_handle[gpio], 1, 0);
115 if (ret)
116 {
117 LYINFLOG("do_gpio_input set direction failed, err:%d\n", ret);
118 return -1;;
119 }
120 ret = sc_gpio_value_set(test_gpio_handle[gpio], value);
121 if (ret)
122 {
123 LYINFLOG("do_gpio_output set value failed, err:%d\n", ret);
124 return -1;
125 }
126 else
127 {
128 LYINFLOG("gpio%d set value:%d\n", gpio, value);
129 }
130 return 0;
131}
132
133/*****************************************
134* @brief:lynq_gpio_value_set
135* @param count [IN]:1
136* @param sum [OUT]:NA
137* @return :success 0, failed -1
138* @todo:NA
139* @see:NA
140* @warning:NA
141******************************************/
142
143
144int lynq_gpio_value_get(int gpio)
145{
146 int ret;
147 int value;
148 LYLOGSET(LOG_INFO);
149 LYLOGEINIT(USER_LOG_TAG);
150 ret = sc_gpio_value_get(test_gpio_handle[gpio], &value);
151 if (ret)
152 {
153 LYINFLOG("do_gpio_input get value failed, err:%d\n", ret);
154 return -1;
155 }
156 else
157 {
158 LYINFLOG("gpio%d value:%d\n", gpio, value);
159 }
160 return value;
161}
162
163/*****************************************
164* @brief:lynq_gpio_pullsel_set
165* @param count [IN]:2
166* @param sum [OUT]:NA
167* @return :success 0, failed -1
168* @todo:NA
169* @see:NA
170* @warning:NA
171******************************************/
172
173
174int lynq_gpio_pullsel_set(int gpio, int pullsel)
175{
176 int ret;
177 LYLOGSET(LOG_INFO);
178 LYLOGEINIT(USER_LOG_TAG);
179 ret = sc_gpio_pullsel_set(test_gpio_handle[gpio], pullsel);
180 if (ret)
181 {
182 LYINFLOG("do_gpio_input get pull failed, err:%d\n", ret);
183 return -1;
184 }
185 else
186 {
187 LYINFLOG("gpio%d pull:%d\n", gpio, pullsel);
188 }
189 return 0;
190}
191
192/*****************************************
193* @brief:lynq_gpio_pullsel_get
194* @param count [IN]:1
195* @param sum [OUT]:NA
196* @return :success >=0, failed -1
197* @todo:NA
198* @see:NA
199* @warning:NA
200******************************************/
201
202
203int lynq_gpio_pullsel_get(int gpio)
204{
205 int ret;
206 int pullsel;
207 LYLOGSET(LOG_INFO);
208 LYLOGEINIT(USER_LOG_TAG);
209 ret = sc_gpio_pullsel_get(test_gpio_handle[gpio], &pullsel);
210 if (ret)
211 {
212 LYINFLOG("do_gpio_input get pull failed, err:%d\n", ret);
213 return -1;
214 }
215 else
216 {
217 LYINFLOG("gpio%d pull:%d\n", gpio, pullsel);
218 }
219 return pullsel;
220}
221
222
223DEFINE_LYNQ_LIB_LOG(LYNQ_GPIO)
224
225#ifdef __cplusplus
226}
227#endif
228
229
230