Attempt to fix the cfg and hw file path logic.
[bertos.git] / bertos / drv / dc_motor.h
index 9aac6548e3235461d1731c3363c1a59a91f21ead..32a0b13c2a5687f12c66bd1350e5d63ca2424806 100644 (file)
  * -->
  *
  *
- * \brief DC motor driver (interface)
- *
- * \version $Id$
- *
+ * \brief DC motor driver.
+*
  * \author Daniele Basile <asterix@develer.com>
+ *
+ * $WIZ$ module_name = "dc_motor"
+ * $WIZ$ module_depends = "pwm", "pid_control", "adc", "timer"
+ * $WIZ$ module_configuration = "bertos/cfg/cfg_dc_motor.h"
+ * $WIZ$ module_hw = "bertos/hw/hw_dc_motor.h"
  */
 
 #ifndef DRV_DC_MOTOR_H
 #define DRV_DC_MOTOR_H
 
-#include "hw_dc_motor.h"
+#include "hw/hw_dc_motor.h"
+
+#include "cfg/cfg_dc_motor.h"
+#include <cfg/macros.h>
 
 #include <algo/pid_control.h>
 
 #include <drv/timer.h>
 #include <drv/adc.h>
 
-#include <cfg/macros.h>
+/*
+ * DC motor mode stop.
+ */
+#define DC_MOTOR_DISABLE_MODE      0   ///< Disable the DC motor shutting down the driver
+#define DC_MOTOR_IDLE_MODE         1   ///< Put the motor pins in short circuit
 
-#include "appconfig.h"
 
-/**
- * Define status bit for DC motor device.
- */
-#define DC_MOTOR_ACTIVE     BV(0)     ///< DC motor enable or disable flag.
-#define DC_MOTOR_DIR        BV(1)     ///< Spin direction of DC motor.
+#define DC_MOTOR_NO_EXPIRE  -1         ///< The DC motor runs do not expire, so it runs forever.
 
 /**
  * Type for DC motor.
@@ -69,6 +74,7 @@ typedef uint16_t dc_speed_t;
 typedef struct DCMotorConfig
 {
        PidCfg pid_cfg;         ///< Pid control.
+       bool pid_enable;        ///< Flag to disable or enable pid control.
 
        PwmDev pwm_dev;         ///< Pwm channel.
        pwm_freq_t freq;        ///< Pwm waveform frequency.
@@ -80,6 +86,11 @@ typedef struct DCMotorConfig
 
        bool dir;               ///< Default direction for select DC motor.
 
+       dc_speed_t speed;       ///< Fixed speed value for select DC motor, if enable_dev_speed flag is false.
+
+       adc_ch_t speed_dev_id;  ///< Index of the device where read speed.
+       bool enable_dev_speed;  ///< If this flag is true read target speed from device, otherwise use fixed speed.
+
 } DCMotorConfig;
 
 
@@ -93,14 +104,19 @@ typedef struct DCMotor
 
        int index;                ///< DC motor id.
        uint32_t status;          ///< Status of select DC motor
+       dc_speed_t zero_speed;    ///< Start value for motor speed (Value read from adc when motor is off)
        dc_speed_t tgt_speed;     ///< Target speed for select DC motor
 
+       ticks_t expire_time;      ///< Among of time that  dc motor run
+
 } DCMotor;
 
 void dc_motor_setDir(int index, bool dir);
-void dc_motor_enable(int index, bool state);
+void dc_motor_enable(int index, bool state, int mode);
 void dc_motor_setSpeed(int index, dc_speed_t speed);
+void dc_motor_setTimer(int index, mtime_t on_time);
 void dc_motor_setup(int index, DCMotorConfig *cfg);
-void dc_motor_init(void);
+dc_speed_t dc_motor_readTargetSpeed(int index);
+void dc_motor_init(int priority);
 
 #endif /* DRV_DC_MOTOR_H */