Skip to content

Commit cea35db

Browse files
authored
Merge pull request #16 from sogwms/master
[motor] change pointer to void && hide structure
2 parents 2688c15 + 08bc1cb commit cea35db

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

motor/dual_pwm_motor.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
#define DBG_LEVEL DBG_LOG
55
#include <rtdbg.h>
66

7-
static rt_err_t dual_pwm_motor_enable(motor_t mot)
7+
struct dual_pwm_motor
8+
{
9+
struct motor mot;
10+
struct rt_device_pwm *pwm1_dev;
11+
int pwm1_channel;
12+
struct rt_device_pwm *pwm2_dev;
13+
int pwm2_channel;
14+
};
15+
16+
static rt_err_t dual_pwm_motor_enable(void *mot)
817
{
918
RT_ASSERT(mot != RT_NULL);
1019

@@ -16,7 +25,7 @@ static rt_err_t dual_pwm_motor_enable(motor_t mot)
1625
return RT_EOK;
1726
}
1827

19-
static rt_err_t dual_pwm_motor_disable(motor_t mot)
28+
static rt_err_t dual_pwm_motor_disable(void *mot)
2029
{
2130
RT_ASSERT(mot != RT_NULL);
2231

@@ -28,7 +37,7 @@ static rt_err_t dual_pwm_motor_disable(motor_t mot)
2837
return RT_EOK;
2938
}
3039

31-
static rt_err_t dual_pwm_motor_set_speed(motor_t mot, rt_int16_t thousands)
40+
static rt_err_t dual_pwm_motor_set_speed(void *mot, rt_int16_t thousands)
3241
{
3342
RT_ASSERT(mot != RT_NULL);
3443

motor/dual_pwm_motor.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@
33

44
#include "motor.h"
55

6+
struct dual_pwm_motor;
67
typedef struct dual_pwm_motor *dual_pwm_motor_t;
78

8-
struct dual_pwm_motor
9-
{
10-
struct motor mot;
11-
struct rt_device_pwm *pwm1_dev;
12-
int pwm1_channel;
13-
struct rt_device_pwm *pwm2_dev;
14-
int pwm2_channel;
15-
};
16-
179
dual_pwm_motor_t dual_pwm_motor_create(char *pwm1, int pwm1_channel, char *pwm2, int pwm2_channel);
1810

1911
#endif // __DUAL_PWM_MOTOR_H__

motor/motor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ typedef struct motor *motor_t;
1111

1212
struct motor
1313
{
14-
rt_err_t (*enable)(motor_t mot);
15-
rt_err_t (*disable)(motor_t mot);
16-
rt_err_t (*set_speed)(motor_t mot, rt_int16_t thousands);
14+
rt_err_t (*enable)(void *mot);
15+
rt_err_t (*disable)(void *mot);
16+
rt_err_t (*set_speed)(void *mot, rt_int16_t thousands);
1717
};
1818

1919
motor_t motor_create(rt_size_t size);

motor/single_pwm_motor.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
#define DBG_LEVEL DBG_LOG
55
#include <rtdbg.h>
66

7-
static rt_err_t single_pwm_motor_enable(motor_t mot)
7+
struct single_pwm_motor
8+
{
9+
struct motor mot;
10+
struct rt_device_pwm *pwm_dev;
11+
int channel;
12+
rt_base_t pin1;
13+
rt_base_t pin2;
14+
};
15+
16+
static rt_err_t single_pwm_motor_enable(void *mot)
817
{
918
RT_ASSERT(mot != RT_NULL);
1019

@@ -15,7 +24,7 @@ static rt_err_t single_pwm_motor_enable(motor_t mot)
1524
return RT_EOK;
1625
}
1726

18-
static rt_err_t single_pwm_motor_disable(motor_t mot)
27+
static rt_err_t single_pwm_motor_disable(void *mot)
1928
{
2029
RT_ASSERT(mot != RT_NULL);
2130

@@ -26,7 +35,7 @@ static rt_err_t single_pwm_motor_disable(motor_t mot)
2635
return RT_EOK;
2736
}
2837

29-
static rt_err_t single_pwm_motor_set_speed(motor_t mot, rt_int16_t thousands)
38+
static rt_err_t single_pwm_motor_set_speed(void *mot, rt_int16_t thousands)
3039
{
3140
RT_ASSERT(mot != RT_NULL);
3241

motor/single_pwm_motor.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@
33

44
#include "motor.h"
55

6+
struct single_pwm_motor;
67
typedef struct single_pwm_motor *single_pwm_motor_t;
78

8-
struct single_pwm_motor
9-
{
10-
struct motor mot;
11-
struct rt_device_pwm *pwm_dev;
12-
int channel;
13-
rt_base_t pin1;
14-
rt_base_t pin2;
15-
};
16-
179
single_pwm_motor_t single_pwm_motor_create(char *pwm, int channel, rt_base_t pin1, rt_base_t pin2);
1810

1911
#endif // __SINGLE_PWM_MOTOR_H__

0 commit comments

Comments
 (0)