X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Fdc_motor.h;h=f6fc6c57afa114ba9f354a26d93c28c1c10ed27e;hb=7911a6f01bc8a19f220f98e2fdc8595f65996853;hp=ebd91e280b17b8dbc778e19903b1eec3f5a9d220;hpb=37efb5bdc0504ab6df2e8db0635c9c6f7477e23e;p=bertos.git diff --git a/bertos/drv/dc_motor.h b/bertos/drv/dc_motor.h index ebd91e28..f6fc6c57 100644 --- a/bertos/drv/dc_motor.h +++ b/bertos/drv/dc_motor.h @@ -32,13 +32,12 @@ * * \brief DC motor driver. * - * \version $Id$ - * * \author Daniele Basile * * $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 @@ -47,6 +46,7 @@ #include "hw/hw_dc_motor.h" #include "cfg/cfg_dc_motor.h" +#include "cfg/cfg_pwm.h" #include #include @@ -55,12 +55,8 @@ #include #include - -/** - * 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. +#define DC_MOTOR_NO_DEV_SPEED -1 ///< Disable the speed acquire from device (like trimmer, etc.). /** * Type for DC motor. @@ -73,16 +69,21 @@ 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. + unsigned pwm_dev; ///< Pwm channel. pwm_freq_t freq; ///< Pwm waveform frequency. adc_ch_t adc_ch; ///< ADC channel. adcread_t adc_max; ///< ADC max scale value. adcread_t adc_min; ///< ADC min scale value. - mtime_t sample_delay; ///< Delay before to sampling. bool dir; ///< Default direction for select DC motor. + bool braked; ///< If true the motor is braked when we turn off it. + + dc_speed_t speed; ///< Default speed value for select DC motor. + + int speed_dev_id; ///< Index of the device where read speed, to disable set to DC_MOTOR_NO_DEV_SPEED. } DCMotorConfig; @@ -92,19 +93,39 @@ typedef struct DCMotorConfig */ typedef struct DCMotor { - const DCMotorConfig *cfg; ///< All configuration for select DC motor. - PidContext pid_ctx; ///< Pid control. + const DCMotorConfig *cfg; // All configuration for select DC motor. + PidContext pid_ctx; // Pid control. + +#if !CFG_PWM_ENABLE_OLD_API + Pwm pwm; // Pwm context +#endif - int index; ///< DC motor id. - uint32_t status; ///< Status of select DC motor - dc_speed_t tgt_speed; ///< Target speed for select DC motor + int index; // DC motor id. + uint32_t status; // Status of select DC motor + dc_speed_t tgt_speed; // Target speed for select DC motor + + ticks_t expire_time; // Amount 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_setSpeed(int index, dc_speed_t speed); -void dc_motor_setup(int index, DCMotorConfig *cfg); +void dc_motor_startTimer(int index, mtime_t on_time); +void dc_motor_waitStop(int index); +void dc_motor_setup(int index, DCMotorConfig *dcm_conf); +dc_speed_t dc_motor_readTargetSpeed(int index); +void dc_motor_setPriority(int priority); void dc_motor_init(void); + +/** + * Test function prototypes. + * + * See dc_motor_hwtest.c file. + */ +int dc_motor_testSetUp(void); +void dc_motor_testRun(void); +int dc_motor_testTearDown(void); + #endif /* DRV_DC_MOTOR_H */