1 /*
2  * Copyright (C) 2022 HiHope Open Source Organization .
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  *
14  * limitations under the License.
15  */
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <memory.h>
20 
21 #include "ohos_init.h"
22 #include "cmsis_os2.h"
23 #include "iot_gpio.h"
24 #include "hi_io.h"
25 #include "hi_time.h"
26 #include "iot_pwm.h"
27 #include "hi_pwm.h"
28 
29 #define GPIO0 0
30 #define GPIO1 1
31 #define GPIO9 9
32 #define GPIO10 10
33 #define GPIOFUNC 0
34 #define PWM_FREQ_FREQUENCY  (60000)
35 
gpio_control(unsigned int gpio, IotGpioValue value)36 void gpio_control (unsigned int  gpio, IotGpioValue value)
37 {
38     hi_io_set_func(gpio, GPIOFUNC);
39     IoTGpioSetDir(gpio, IOT_GPIO_DIR_OUT);
40     IoTGpioSetOutputVal(gpio, value);
41 }
42 
car_backward(void)43 void car_backward(void)
44 {
45     gpio_control(GPIO0, IOT_GPIO_VALUE0);
46     gpio_control(GPIO1, IOT_GPIO_VALUE1);
47     gpio_control(GPIO9, IOT_GPIO_VALUE0);
48     gpio_control(GPIO10, IOT_GPIO_VALUE1);
49 }
50 
car_forward(void)51 void car_forward(void)
52 {
53     gpio_control(GPIO0, IOT_GPIO_VALUE1);
54     gpio_control(GPIO1, IOT_GPIO_VALUE0);
55     gpio_control(GPIO9, IOT_GPIO_VALUE1);
56     gpio_control(GPIO10, IOT_GPIO_VALUE0);
57 }
58 
car_left(void)59 void car_left(void)
60 {
61     gpio_control(GPIO0, IOT_GPIO_VALUE0);
62     gpio_control(GPIO1, IOT_GPIO_VALUE0);
63     gpio_control(GPIO9, IOT_GPIO_VALUE1);
64     gpio_control(GPIO10, IOT_GPIO_VALUE0);
65 }
66 
car_right(void)67 void car_right(void)
68 {
69     gpio_control(GPIO0, IOT_GPIO_VALUE1);
70     gpio_control(GPIO1, IOT_GPIO_VALUE0);
71     gpio_control(GPIO9, IOT_GPIO_VALUE0);
72     gpio_control(GPIO10, IOT_GPIO_VALUE0);
73 }
74 
car_stop(void)75 void car_stop(void)
76 {
77     gpio_control(GPIO0, IOT_GPIO_VALUE1);
78     gpio_control(GPIO1, IOT_GPIO_VALUE1);
79     gpio_control(GPIO9, IOT_GPIO_VALUE1);
80     gpio_control(GPIO10, IOT_GPIO_VALUE1);
81 }
82