-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecu_dc_motor.c
101 lines (96 loc) · 3.68 KB
/
ecu_dc_motor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* File : ecu_dc_motor.c
* Author : Mohamed Ahmed Abdel Wahab
* LinkedIn : https://www.linkedin.com/in/mohamed-abdel-wahab-162413253/
* Github : https://github.com/moabdelwahab6611
* Created on May 29, 2023, 9:24 PM
*/
/**************************Includes-Section*****************************/
#include "ecu_dc_motor.h"
/***********************************************************************/
/*****************Software Interfaces Functions-Section*****************/
/*
* @Brief : Initialize the assigned pin to be OUTPUT and turn the DC Motor OFF or ON.
* @Param _dc_motor : Pointer to the DC Motor module configurations.
* @Return Status of the function.
* (E_OK) : The function done successfully.
* (E_NOT_OK) : The function has issue while performing this action.
*/
Std_ReturnType dc_motor_initialize(const dc_motor_t *_dc_motor)
{
Std_ReturnType ret = E_OK;
if(NULL == _dc_motor)
{
ret = E_NOT_OK;
}
else
{
gpio_pin_intialize(&(_dc_motor->dc_motor_pin[DC_MOTOR_PIN1])); /* @Brief : To initialize DC Motor pin1. */
gpio_pin_intialize(&(_dc_motor->dc_motor_pin[DC_MOTOR_PIN2])); /* @Brief : To initialize DC Motor pin2. */
}
return ret;
}
/*
* @Brief : To make the DC Motor move right.
* @Param _dc_motor : Pointer to the DC Motor module configurations.
* @Return Status of the function.
* (E_OK) : The function done successfully.
* (E_NOT_OK) : The function has issue while performing this action.
*/
Std_ReturnType dc_motor_move_right(const dc_motor_t *_dc_motor)
{
Std_ReturnType ret = E_OK;
if(NULL == _dc_motor)
{
ret = E_NOT_OK;
}
else
{
gpio_pin_write_logic(&(_dc_motor->dc_motor_pin[DC_MOTOR_PIN1]), GPIO_HIGH); /* @Brief : To write logic high on DC Motor pin1. */
gpio_pin_write_logic(&(_dc_motor->dc_motor_pin[DC_MOTOR_PIN2]), GPIO_LOW); /* @Brief : To write logic low on DC Motor pin2. */
}
return ret;
}
/*
* @Brief : To make the DC Motor move left.
* @Param _dc_motor : Pointer to the DC Motor module configurations.
* @Return Status of the function.
* (E_OK) : The function done successfully.
* (E_NOT_OK) : The function has issue while performing this action.
*/
Std_ReturnType dc_motor_move_left(const dc_motor_t *_dc_motor)
{
Std_ReturnType ret = E_OK;
if(NULL == _dc_motor)
{
ret = E_NOT_OK;
}
else
{
gpio_pin_write_logic(&(_dc_motor->dc_motor_pin[DC_MOTOR_PIN1]), GPIO_LOW); /* @Brief : To write logic low on DC Motor pin1. */
gpio_pin_write_logic(&(_dc_motor->dc_motor_pin[DC_MOTOR_PIN2]), GPIO_HIGH); /* @Brief : To write logic high on DC Motor pin2. */
}
return ret;
}
/*
* @Brief : To stop the DC Motor.
* @Param _dc_motor : Pointer to the DC Motor module configurations.
* @Return Status of the function.
* (E_OK) : The function done successfully.
* (E_NOT_OK) : The function has issue while performing this action.
*/
Std_ReturnType dc_motor_stop(const dc_motor_t *_dc_motor)
{
Std_ReturnType ret = E_OK;
if(NULL == _dc_motor)
{
ret = E_NOT_OK;
}
else
{
gpio_pin_write_logic(&(_dc_motor->dc_motor_pin[DC_MOTOR_PIN1]), GPIO_LOW); /* @Brief : To write logic low on DC Motor pin1. */
gpio_pin_write_logic(&(_dc_motor->dc_motor_pin[DC_MOTOR_PIN2]), GPIO_LOW); /* @Brief : To write logic low on DC Motor pin2. */
}
return ret;
}
/***********************************************************************/