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 27 #define GPIO2 2 28 #define COUNT 10 set_angle(unsigned int duty)29void set_angle(unsigned int duty) 30 { 31 unsigned int time = 20000; 32 IoTGpioInit(GPIO2); 33 IoTGpioSetDir(GPIO2, IOT_GPIO_DIR_OUT); 34 IoTGpioSetOutputVal(GPIO2, IOT_GPIO_VALUE1); 35 hi_udelay(duty); 36 IoTGpioSetOutputVal(GPIO2, IOT_GPIO_VALUE0); 37 hi_udelay(time - duty); 38 } 39 40 /* Steering gear turn left */ engine_turn_left(void)41void engine_turn_left(void) 42 { 43 unsigned int angle = 1000; 44 for (int i = 0; i < COUNT; i++) { 45 set_angle(angle); 46 } 47 } 48 49 /* Steering gear turn right */ engine_turn_right(void)50void engine_turn_right(void) 51 { 52 unsigned int angle = 2000; 53 for (int i = 0; i < COUNT; i++) { 54 set_angle(angle); 55 } 56 } 57 58 /* Steering gear return to middle */ regress_middle(void)59void regress_middle(void) 60 { 61 unsigned int angle = 1500; 62 for (int i = 0; i < COUNT; i++) { 63 set_angle(angle); 64 } 65 } 66