Explorar el Código

[motor] expose subclass objects

guoyongchao hace 6 años
padre
commit
b840379824
Se han modificado 4 ficheros con 28 adiciones y 29 borrados
  1. 2 13
      motor/dual_pwm_motor.c
  2. 12 1
      motor/dual_pwm_motor.h
  3. 2 14
      motor/single_pwm_motor.c
  4. 12 1
      motor/single_pwm_motor.h

+ 2 - 13
motor/dual_pwm_motor.c

@@ -4,17 +4,6 @@
 #define DBG_LEVEL DBG_LOG
 #include <rtdbg.h>
 
-typedef struct dual_pwm_motor *dual_pwm_motor_t;
-
-struct dual_pwm_motor
-{
-    struct motor mot;
-    struct rt_device_pwm *pwm1_dev;
-    int pwm1_channel;
-    struct rt_device_pwm *pwm2_dev;
-    int pwm2_channel;
-};
-
 static rt_err_t dual_pwm_motor_enable(motor_t mot)
 {
     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)
     return RT_EOK;
 }
 
-motor_t dual_pwm_motor_create(char *pwm1, int pwm1_channel, char *pwm2, int pwm2_channel)
+dual_pwm_motor_t dual_pwm_motor_create(char *pwm1, int pwm1_channel, char *pwm2, int pwm2_channel)
 {
     dual_pwm_motor_t new_motor = (dual_pwm_motor_t)motor_create(sizeof(struct dual_pwm_motor));
     if (new_motor == RT_NULL)
@@ -102,5 +91,5 @@ motor_t dual_pwm_motor_create(char *pwm1, int pwm1_channel, char *pwm2, int pwm2
     new_motor->mot.disable = dual_pwm_motor_disable;
     new_motor->mot.set_speed = dual_pwm_motor_set_speed;
 
-    return &new_motor->mot;
+    return new_motor;
 }

+ 12 - 1
motor/dual_pwm_motor.h

@@ -3,6 +3,17 @@
 
 #include "motor.h"
 
-motor_t  dual_pwm_motor_create(char *pwm1, int pwm1_channel, char *pwm2, int pwm2_channel);
+typedef struct dual_pwm_motor *dual_pwm_motor_t;
+
+struct dual_pwm_motor
+{
+    struct motor mot;
+    struct rt_device_pwm *pwm1_dev;
+    int pwm1_channel;
+    struct rt_device_pwm *pwm2_dev;
+    int pwm2_channel;
+};
+
+dual_pwm_motor_t dual_pwm_motor_create(char *pwm1, int pwm1_channel, char *pwm2, int pwm2_channel);
 
 #endif // __DUAL_PWM_MOTOR_H__

+ 2 - 14
motor/single_pwm_motor.c

@@ -4,18 +4,6 @@
 #define DBG_LEVEL         DBG_LOG
 #include <rtdbg.h>
 
-typedef struct single_pwm_motor *single_pwm_motor_t;
-
-struct single_pwm_motor
-{
-    struct motor mot;
-    struct rt_device_pwm *pwm_dev;
-    int channel;
-    rt_base_t pin1;
-    rt_base_t pin2;
-};
-
-
 static rt_err_t single_pwm_motor_enable(motor_t mot)
 {
     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)
 }
 
 
-motor_t single_pwm_motor_create(char *pwm, int channel, rt_base_t pin1, rt_base_t pin2)
+single_pwm_motor_t single_pwm_motor_create(char *pwm, int channel, rt_base_t pin1, rt_base_t pin2)
 {
     single_pwm_motor_t new_motor = (single_pwm_motor_t)motor_create(sizeof(struct single_pwm_motor));
     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_
     rt_pin_mode(new_motor->pin1, PIN_MODE_OUTPUT);
     rt_pin_mode(new_motor->pin2, PIN_MODE_OUTPUT);
 
-    return &new_motor->mot;
+    return new_motor;
 }

+ 12 - 1
motor/single_pwm_motor.h

@@ -3,6 +3,17 @@
 
 #include "motor.h"
 
-motor_t  single_pwm_motor_create(char *pwm, int channel, rt_base_t pin1, rt_base_t pin2);
+typedef struct single_pwm_motor *single_pwm_motor_t;
+
+struct single_pwm_motor
+{
+    struct motor mot;
+    struct rt_device_pwm *pwm_dev;
+    int channel;
+    rt_base_t pin1;
+    rt_base_t pin2;
+};
+
+single_pwm_motor_t  single_pwm_motor_create(char *pwm, int channel, rt_base_t pin1, rt_base_t pin2);
 
 #endif // __SINGLE_PWM_MOTOR_H__