00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __dmotor_h__
00027 #define __dmotor_h__
00028
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032
00033 #include <config.h>
00034
00035 #ifdef CONF_DMOTOR
00036
00038
00039
00040
00042
00044 typedef enum {
00045 off = 0,
00046 fwd = 1,
00047 rev = 2,
00048 brake = 3
00049
00050 } MotorDirection;
00051
00052 #ifndef DOXYGEN_SHOULD_SKIP_INTERNALS
00053
00054 typedef struct {
00055 union {
00056 unsigned assembler;
00057
00058 struct {
00059 unsigned char delta;
00060
00061 volatile unsigned char sum;
00062
00063 } c;
00064 } access;
00065
00066 unsigned char dir;
00067
00068 } MotorState;
00069 #endif // DOXYGEN_SHOULD_SKIP_INTERNALS
00070
00071 #define MIN_SPEED 0
00072 #define MAX_SPEED 255
00073
00074
00075
00076
00077
00079
00081
00084 extern const unsigned char dm_a_pattern[4],
00085 dm_b_pattern[4],
00086 dm_c_pattern[4];
00087
00088 extern MotorState dm_a,
00089 dm_b,
00090 dm_c;
00091
00093
00094
00095
00097
00098 #ifdef CONF_VIS
00099
00100
00101
00102
00103
00104 extern void motor_a_dir(MotorDirection dir);
00105 extern void motor_b_dir(MotorDirection dir);
00106 extern void motor_c_dir(MotorDirection dir);
00107
00108 #else
00109
00110
00111
00112
00114
00116 extern inline void motor_a_dir(MotorDirection dir)
00117 {
00118 dm_a.dir = dm_a_pattern[dir];
00119 }
00120
00122
00124 extern inline void motor_b_dir(MotorDirection dir)
00125 {
00126 dm_b.dir = dm_b_pattern[dir];
00127 }
00128
00130
00132 extern inline void motor_c_dir(MotorDirection dir)
00133 {
00134 dm_c.dir = dm_c_pattern[dir];
00135 }
00136
00137 #endif // ifdef CONF_VIS
00138
00139
00141
00143 extern inline void motor_a_speed(unsigned char speed)
00144 {
00145 dm_a.access.c.delta = speed;
00146 }
00147
00149
00151 extern inline void motor_b_speed(unsigned char speed)
00152 {
00153 dm_b.access.c.delta = speed;
00154 }
00155
00157
00159 extern inline void motor_c_speed(unsigned char speed)
00160 {
00161 dm_c.access.c.delta = speed;
00162 }
00163
00164 #endif // CONF_DMOTOR
00165
00166 #ifdef __cplusplus
00167 }
00168 #endif
00169
00170 #endif // __dmotor_h__