/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is legOS code, released October 17, 1999.
*
* The Initial Developer of the Original Code is Markus L. Noga.
* Portions created by Markus L. Noga are Copyright (C) 1999
* Markus L. Noga. All Rights Reserved.
*
* Contributor(s): Markus L. Noga <markus@noga.de>
*/
#ifndef __dmotor_h__
#define __dmotor_h__
#include <config.h>
#ifdef CONF_DMOTOR
//
// Definitions
//
typedef enum {
off = 0,
fwd = 1,
rev = 2,
brake = 3
} MotorDirection;
typedef struct {
union {
unsigned assembler;
struct {
unsigned char delta;
volatile unsigned char sum;
} c;
} access;
unsigned char dir;
} MotorState;
#define MIN_SPEED 0
#define MAX_SPEED 255
//
// Variables
//
/*! to be indexed with MotorDirections
\sa MotorDirections
*/
extern const unsigned char dm_a_pattern[4], dm_b_pattern[4], dm_c_pattern[4];
extern MotorState dm_a,
dm_b,
dm_c;
//
// Functions
//
/*! \param dir the direction
*/
extern const inline void motor_a_dir(MotorDirection dir)
{
dm_a.dir = dm_a_pattern[dir];
}
extern const inline void motor_b_dir(MotorDirection dir)
{
dm_b.dir = dm_b_pattern[dir];
}
extern const inline void motor_c_dir(MotorDirection dir)
{
dm_c.dir = dm_c_pattern[dir];
}
extern const inline void motor_a_speed(unsigned char speed)
{
dm_a.access.c.delta = speed;
}
extern const inline void motor_b_speed(unsigned char speed)
{
dm_b.access.c.delta = speed;
}
extern const inline void motor_c_speed(unsigned char speed)
{
dm_c.access.c.delta = speed;
}
#endif // CONF_DMOTOR
#endif // __dmotor_h__
legOS-0.2.4 is released under the