blob: 58d0ea0b1c475e2c4ec701abe7b6b4e892777c1b [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 }
jb.qif71d3672025-03-05 19:24:00 -0800114
jb.qi4b7d3e92023-09-26 23:30:34 -0700115 ret = sc_gpio_value_set(test_gpio_handle[gpio], value);
116 if (ret)
117 {
118 LYINFLOG("do_gpio_output set value failed, err:%d\n", ret);
119 return -1;
120 }
121 else
122 {
123 LYINFLOG("gpio%d set value:%d\n", gpio, value);
124 }
125 return 0;
126}
127
128/*****************************************
129* @brief:lynq_gpio_value_set
130* @param count [IN]:1
131* @param sum [OUT]:NA
132* @return :success 0, failed -1
133* @todo:NA
134* @see:NA
135* @warning:NA
136******************************************/
137
138
139int lynq_gpio_value_get(int gpio)
140{
141 int ret;
142 int value;
143 LYLOGSET(LOG_INFO);
144 LYLOGEINIT(USER_LOG_TAG);
145 ret = sc_gpio_value_get(test_gpio_handle[gpio], &value);
146 if (ret)
147 {
148 LYINFLOG("do_gpio_input get value failed, err:%d\n", ret);
149 return -1;
150 }
151 else
152 {
153 LYINFLOG("gpio%d value:%d\n", gpio, value);
154 }
155 return value;
156}
157
158/*****************************************
159* @brief:lynq_gpio_pullsel_set
160* @param count [IN]:2
161* @param sum [OUT]:NA
162* @return :success 0, failed -1
163* @todo:NA
164* @see:NA
165* @warning:NA
166******************************************/
167
168
169int lynq_gpio_pullsel_set(int gpio, int pullsel)
170{
171 int ret;
172 LYLOGSET(LOG_INFO);
173 LYLOGEINIT(USER_LOG_TAG);
174 ret = sc_gpio_pullsel_set(test_gpio_handle[gpio], pullsel);
175 if (ret)
176 {
177 LYINFLOG("do_gpio_input get pull failed, err:%d\n", ret);
178 return -1;
179 }
180 else
181 {
182 LYINFLOG("gpio%d pull:%d\n", gpio, pullsel);
183 }
184 return 0;
185}
186
187/*****************************************
188* @brief:lynq_gpio_pullsel_get
189* @param count [IN]:1
190* @param sum [OUT]:NA
191* @return :success >=0, failed -1
192* @todo:NA
193* @see:NA
194* @warning:NA
195******************************************/
196
197
198int lynq_gpio_pullsel_get(int gpio)
199{
200 int ret;
201 int pullsel;
202 LYLOGSET(LOG_INFO);
203 LYLOGEINIT(USER_LOG_TAG);
204 ret = sc_gpio_pullsel_get(test_gpio_handle[gpio], &pullsel);
205 if (ret)
206 {
207 LYINFLOG("do_gpio_input get pull failed, err:%d\n", ret);
208 return -1;
209 }
210 else
211 {
212 LYINFLOG("gpio%d pull:%d\n", gpio, pullsel);
213 }
214 return pullsel;
215}
216
217
218DEFINE_LYNQ_LIB_LOG(LYNQ_GPIO)
219
220#ifdef __cplusplus
221}
222#endif
223
224
225