1 /* Copyright 2022 Unionman Technology Co., Ltd.
2 *
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 #include <cstdio>
18 #include "gpio_if.h"
19 #include "hdf_log.h"
20 #include "osal_irq.h"
21 #include "osal_time.h"
22
23 #ifdef HDF_LOG_ON
24 #define LOGD(format, ...) \
25 do { \
26 HDF_LOGD("[%{public}s:%{public}d] " format "\n", \
27 __FUNCTION__, __LINE__, \
28 ##__VA_ARGS__); \
29 } while (0)
30
31 #define LOGI(format, ...) \
32 do { \
33 HDF_LOGI("[%{public}s:%{public}d] " format "\n", __FUNCTION__, __LINE__, \
34 ##__VA_ARGS__); \
35 } while (0)
36
37 #define LOGW(format, ...) \
38 do { \
39 HDF_LOGW("[%{public}s:%{public}d] " format "\n", __FUNCTION__, __LINE__, \
40 ##__VA_ARGS__); \
41 } while (0)
42
43 #define LOGE(format, ...) \
44 do { \
45 HDF_LOGE( \
46 "\033[0;32;31m" \
47 "[%{public}s:%{public}d] " format "\033[m" \
48 "\n", \
49 __FUNCTION__, __LINE__, ##__VA_ARGS__); \
50 } while (0)
51 #else
52 #define LOGD(format, ...) \
53 do { \
54 printf("[%s:%d] " format "\n", \
55 __FUNCTION__, __LINE__, \
56 ##__VA_ARGS__); \
57 } while (0)
58
59 #define LOGI(format, ...) \
60 do { \
61 printf("[%s:%d] " format "\n", __FUNCTION__, __LINE__, \
62 ##__VA_ARGS__); \
63 } while (0)
64
65 #define LOGW(format, ...) \
66 do { \
67 printf("[%s:%d] " format "\n", __FUNCTION__, __LINE__, \
68 ##__VA_ARGS__); \
69 } while (0)
70
71 #define LOGE(format, ...) \
72 do { \
73 printf("\033[0;32;31m" \
74 "[%s:%d] " format "\033[m" \
75 "\n", \
76 __FUNCTION__, __LINE__, ##__VA_ARGS__); \
77 } while (0)
78 #endif
79
80 #define SLEEP_TIME_MS (1000)
81 #define TIMEOUT_COUNT (5)
82
main(int argc,char * argv[])83 int32_t main(int argc, char *argv[])
84 {
85 uint16_t gpio = 380; /* GPIO_01, GPIO Num : cat /sys/kernel/debug/gpio */
86 uint32_t count = 0;
87 uint16_t valRead;
88 int32_t ret;
89
90 LOGD("GpioSetDir : Set GPIO_01 (for Unionpi Tiger) DIR_OUT\n");
91
92 ret = GpioSetDir(gpio, GPIO_DIR_OUT);
93 if (ret != HDF_SUCCESS) {
94 LOGE("%s: set dir fail! ret:%d\n", __func__, ret);
95 return ret;
96 }
97
98 for (;;) {
99 (void)GpioRead(gpio, &valRead);
100 LOGD("GpioRead valRead : %d\n", valRead);
101
102 (void)GpioWrite(gpio, (valRead == GPIO_VAL_LOW) ? GPIO_VAL_HIGH : GPIO_VAL_LOW);
103
104 OsalMSleep(SLEEP_TIME_MS);
105
106 count += 1;
107 if (count >= TIMEOUT_COUNT) {
108 LOGE("%s: Wait timeout break!\n", __func__);
109 break;
110 }
111 }
112
113 return HDF_SUCCESS;
114 }
115