-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathL298N.c
65 lines (59 loc) · 1.98 KB
/
L298N.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
/*
* _______ .__ __. _______ __ .__ __. _______ _______ .______ .______ __ .__ __. _______
* | ____|| \ | | / _____|| | | \ | | | ____|| ____|| _ \ | _ \ | | | \ | | / _____|
* | |__ | \| | | | __ | | | \| | | |__ | |__ | |_) | | |_) | | | | \| | | | __
* | __| | . ` | | | |_ | | | | . ` | | __| | __| | / | ___/ | | | . ` | | | |_ |
* | |____ | |\ | | |__| | | | | |\ | | |____ | |____ | |\ \----. | | | | | |\ | | |__| |
* |_______||__| \__| \______| |__| |__| \__| |_______||_______|| _| `._____| | _| |__| |__| \__| \______|
*
*/
#ifdef __cplusplus
extern "C"{
#endif
#include "stddef.h"
#include "L298N.h"
Std_Return L298N_MotorControl(int channel,unsigned char rotation )
{
if(channel >= L298N_MOTOR_CHANNEL_MAX)
{
return 1;
}
L298N_PinType_t* pinControl = &L298N_ChannelCfg[channel];
if(pinControl->pinWirteFunc == NULL)
{
return 1;
}
if(rotation == MOTOR_FORWARD)
{
pinControl->pinWirteFunc(pinControl->pinNumA,1);
pinControl->pinWirteFunc(pinControl->pinNumB,0);
}
else if(rotation == MOTOR_REVERSE)
{
pinControl->pinWirteFunc(pinControl->pinNumA,0);
pinControl->pinWirteFunc(pinControl->pinNumB,1);
}
else
{
pinControl->pinWirteFunc(pinControl->pinNumA,0);
pinControl->pinWirteFunc(pinControl->pinNumB,0);
}
return 0;
}
Std_Return L298N_MotorSpeed(int channel,float speed)
{
if(channel >= L298N_MOTOR_CHANNEL_MAX)
{
return 1;
}
L298N_PinType_t* pinControl = &L298N_ChannelCfg[channel];
if(pinControl->pwmWriteFunc == NULL)
{
return 1;
}
pinControl->pwmWriteFunc(pinControl->pwmNNum,speed);
return 0;
}
#ifdef __cplusplus
}
#endif