dmotor.h
Go to the documentation of this file.
1 
6 /*
7  * The contents of this file are subject to the Mozilla Public License
8  * Version 1.0 (the "License"); you may not use this file except in
9  * compliance with the License. You may obtain a copy of the License
10  * at http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS"
13  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14  * the License for the specific language governing rights and
15  * limitations under the License.
16  *
17  * The Original Code is legOS code, released October 17, 1999.
18  *
19  * The Initial Developer of the Original Code is Markus L. Noga.
20  * Portions created by Markus L. Noga are Copyright (C) 1999
21  * Markus L. Noga. All Rights Reserved.
22  *
23  * Contributor(s): Markus L. Noga <markus@noga.de>
24  */
25 
26 #ifndef __dmotor_h__
27 #define __dmotor_h__
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <config.h>
34 
35 #ifdef CONF_DMOTOR
36 
38 //
39 // Definitions
40 //
42 
44 typedef enum {
45  off = 0,
46  fwd = 1,
47  rev = 2,
48  brake = 3
49 
51 
52 #ifndef DOXYGEN_SHOULD_SKIP_INTERNALS
53 typedef struct {
55  union {
56  unsigned assembler;
57 
58  struct {
59  unsigned char delta;
60 
61  volatile unsigned char sum;
62 
63  } c;
64  } access;
65 
66  unsigned char dir;
67 
68 } MotorState;
69 #endif // DOXYGEN_SHOULD_SKIP_INTERNALS
70 
71 #define MIN_SPEED 0
72 #define MAX_SPEED 255
73 
74 //
76 // Variables
77 //
79 
81 
84 extern const unsigned char dm_a_pattern[4],
85  dm_b_pattern[4],
86  dm_c_pattern[4];
87 
88 extern MotorState dm_a,
89  dm_b,
90  dm_c;
91 
93 //
94 // Functions
95 //
97 
98 #ifdef CONF_VIS
99 
100 /*
101 ** motor_*_dir() functions will display direction arrows, so
102 ** define them in kernel/dmotor.c
103 */
104 extern void motor_a_dir(MotorDirection dir);
105 extern void motor_b_dir(MotorDirection dir);
106 extern void motor_c_dir(MotorDirection dir);
107 
108 #else
109 
110 /*
111 ** No display, so make these functions inline
112 */
114 
116 extern inline void motor_a_dir(MotorDirection dir)
117 {
118  dm_a.dir = dm_a_pattern[dir];
119 }
120 
122 
124 extern inline void motor_b_dir(MotorDirection dir)
125 {
126  dm_b.dir = dm_b_pattern[dir];
127 }
128 
130 
132 extern inline void motor_c_dir(MotorDirection dir)
133 {
134  dm_c.dir = dm_c_pattern[dir];
135 }
136 
137 #endif // ifdef CONF_VIS
138 
139 
141 
143 extern inline void motor_a_speed(unsigned char speed)
144 {
145  dm_a.access.c.delta = speed;
146 }
147 
149 
151 extern inline void motor_b_speed(unsigned char speed)
152 {
153  dm_b.access.c.delta = speed;
154 }
155 
157 
159 extern inline void motor_c_speed(unsigned char speed)
160 {
161  dm_c.access.c.delta = speed;
162 }
163 
164 #endif // CONF_DMOTOR
165 
166 #ifdef __cplusplus
167 }
168 #endif
169 
170 #endif // __dmotor_h__
rev
reverse
Definition: dmotor.h:47
dm_b_pattern
const unsigned char dm_b_pattern[4]
MotorDirection
MotorDirection
the motor directions
Definition: dmotor.h:44
dm_b
MotorState dm_b
motor B state
motor_b_speed
void motor_b_speed(unsigned char speed)
set motor B speed
Definition: dmotor.h:151
dm_c
MotorState dm_c
motor C state
motor_b_dir
void motor_b_dir(MotorDirection dir)
set motor B direction to dir
off
freewheel
Definition: dmotor.h:45
motor_a_speed
void motor_a_speed(unsigned char speed)
set motor A speed
Definition: dmotor.h:143
dm_c_pattern
const unsigned char dm_c_pattern[4]
dm_a_pattern
const unsigned char dm_a_pattern[4]
motor drive patterns
motor_c_speed
void motor_c_speed(unsigned char speed)
set motor C speed
Definition: dmotor.h:159
motor_c_dir
void motor_c_dir(MotorDirection dir)
set motor C direction to dir
motor_a_dir
void motor_a_dir(MotorDirection dir)
set motor A direction to dir
dm_a
MotorState dm_a
motor A state
brake
hold current position
Definition: dmotor.h:48
fwd
forward
Definition: dmotor.h:46

brickOS is released under the Mozilla Public License.
Original code copyright 1998-2005 by the authors.

Generated for brickOS C by doxygen 1.8.16