Skip to content

Commit b840379

Browse files
author
guoyongchao
committed
[motor] expose subclass objects
1 parent f926c88 commit b840379

File tree

4 files changed

+28
-29
lines changed

4 files changed

+28
-29
lines changed

motor/dual_pwm_motor.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@
44
#define DBG_LEVEL DBG_LOG
55
#include <rtdbg.h>
66

7-
typedef struct dual_pwm_motor *dual_pwm_motor_t;
8-
9-
struct dual_pwm_motor
10-
{
11-
struct motor mot;
12-
struct rt_device_pwm *pwm1_dev;
13-
int pwm1_channel;
14-
struct rt_device_pwm *pwm2_dev;
15-
int pwm2_channel;
16-
};
17-
187
static rt_err_t dual_pwm_motor_enable(motor_t mot)
198
{
209
RT_ASSERT(mot != RT_NULL);
@@ -74,7 +63,7 @@ static rt_err_t dual_pwm_motor_set_speed(motor_t mot, rt_int16_t thousands)
7463
return RT_EOK;
7564
}
7665

77-
motor_t dual_pwm_motor_create(char *pwm1, int pwm1_channel, char *pwm2, int pwm2_channel)
66+
dual_pwm_motor_t dual_pwm_motor_create(char *pwm1, int pwm1_channel, char *pwm2, int pwm2_channel)
7867
{
7968
dual_pwm_motor_t new_motor = (dual_pwm_motor_t)motor_create(sizeof(struct dual_pwm_motor));
8069
if (new_motor == RT_NULL)
@@ -102,5 +91,5 @@ motor_t dual_pwm_motor_create(char *pwm1, int pwm1_channel, char *pwm2, int pwm2
10291
new_motor->mot.disable = dual_pwm_motor_disable;
10392
new_motor->mot.set_speed = dual_pwm_motor_set_speed;
10493

105-
return &new_motor->mot;
94+
return new_motor;
10695
}

motor/dual_pwm_motor.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33

44
#include "motor.h"
55

6-
motor_t dual_pwm_motor_create(char *pwm1, int pwm1_channel, char *pwm2, int pwm2_channel);
6+
typedef struct dual_pwm_motor *dual_pwm_motor_t;
7+
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+
17+
dual_pwm_motor_t dual_pwm_motor_create(char *pwm1, int pwm1_channel, char *pwm2, int pwm2_channel);
718

819
#endif // __DUAL_PWM_MOTOR_H__

motor/single_pwm_motor.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@
44
#define DBG_LEVEL DBG_LOG
55
#include <rtdbg.h>
66

7-
typedef struct single_pwm_motor *single_pwm_motor_t;
8-
9-
struct single_pwm_motor
10-
{
11-
struct motor mot;
12-
struct rt_device_pwm *pwm_dev;
13-
int channel;
14-
rt_base_t pin1;
15-
rt_base_t pin2;
16-
};
17-
18-
197
static rt_err_t single_pwm_motor_enable(motor_t mot)
208
{
219
RT_ASSERT(mot != RT_NULL);
@@ -76,7 +64,7 @@ static rt_err_t single_pwm_motor_set_speed(motor_t mot, rt_int16_t thousands)
7664
}
7765

7866

79-
motor_t single_pwm_motor_create(char *pwm, int channel, rt_base_t pin1, rt_base_t pin2)
67+
single_pwm_motor_t single_pwm_motor_create(char *pwm, int channel, rt_base_t pin1, rt_base_t pin2)
8068
{
8169
single_pwm_motor_t new_motor = (single_pwm_motor_t)motor_create(sizeof(struct single_pwm_motor));
8270
if (new_motor == RT_NULL)
@@ -101,5 +89,5 @@ motor_t single_pwm_motor_create(char *pwm, int channel, rt_base_t pin1, rt_base_
10189
rt_pin_mode(new_motor->pin1, PIN_MODE_OUTPUT);
10290
rt_pin_mode(new_motor->pin2, PIN_MODE_OUTPUT);
10391

104-
return &new_motor->mot;
92+
return new_motor;
10593
}

motor/single_pwm_motor.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33

44
#include "motor.h"
55

6-
motor_t single_pwm_motor_create(char *pwm, int channel, rt_base_t pin1, rt_base_t pin2);
6+
typedef struct single_pwm_motor *single_pwm_motor_t;
7+
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+
17+
single_pwm_motor_t single_pwm_motor_create(char *pwm, int channel, rt_base_t pin1, rt_base_t pin2);
718

819
#endif // __SINGLE_PWM_MOTOR_H__

0 commit comments

Comments
 (0)