brickOS C++ v0.9.0
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
30extern "C" {
31#endif
32
33#include <config.h>
34
35#ifdef CONF_DMOTOR
36
38//
39// Definitions
40//
42
44typedef enum {
45 off = 0,
46 fwd = 1,
47 rev = 2,
48 brake = 3
49
51
52#ifndef DOXYGEN_SHOULD_SKIP_INTERNALS
54typedef 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
75//
76// Variables
77//
79
81
84extern const unsigned char dm_a_pattern[4],
87
88extern MotorState dm_a,
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*/
104extern void motor_a_dir(MotorDirection dir);
105extern void motor_b_dir(MotorDirection dir);
106extern void motor_c_dir(MotorDirection dir);
107
108#else
109
110/*
111** No display, so make these functions inline
112*/
114
116extern inline void motor_a_dir(MotorDirection dir)
117{
118 dm_a.dir = dm_a_pattern[dir];
119}
120
122
124extern inline void motor_b_dir(MotorDirection dir)
125{
126 dm_b.dir = dm_b_pattern[dir];
127}
128
130
132extern 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
143extern inline void motor_a_speed(unsigned char speed)
144{
145 dm_a.access.c.delta = speed;
146}
147
149
151extern inline void motor_b_speed(unsigned char speed)
152{
153 dm_b.access.c.delta = speed;
154}
155
157
159extern 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__
const unsigned char dm_a_pattern[4]
motor drive patterns
void motor_c_speed(unsigned char speed)
set motor C speed
Definition dmotor.h:159
void motor_b_speed(unsigned char speed)
set motor B speed
Definition dmotor.h:151
MotorState dm_b
motor B state
Definition dmotor.h:89
const unsigned char dm_b_pattern[4]
Definition dmotor.h:85
MotorState dm_a
motor A state
void motor_b_dir(MotorDirection dir)
set motor B direction to dir
const unsigned char dm_c_pattern[4]
Definition dmotor.h:86
MotorState dm_c
motor C state
Definition dmotor.h:90
MotorDirection
the motor directions
Definition dmotor.h:44
@ fwd
forward
Definition dmotor.h:46
@ rev
reverse
Definition dmotor.h:47
@ brake
hold current position
Definition dmotor.h:48
@ off
freewheel
Definition dmotor.h:45
void motor_a_dir(MotorDirection dir)
set motor A direction to dir
void motor_c_dir(MotorDirection dir)
set motor C direction to dir
void motor_a_speed(unsigned char speed)
set motor A speed
Definition dmotor.h:143