[tuxdroid-svn] r495 - firmware/tuxcore/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-09-06 16:32:24
|
Author: jaguarondi Date: 2007-09-06 17:25:15 +0200 (Thu, 06 Sep 2007) New Revision: 495 Added: firmware/tuxcore/trunk/hardware.h Modified: firmware/tuxcore/trunk/global.h firmware/tuxcore/trunk/ir.c firmware/tuxcore/trunk/led.c firmware/tuxcore/trunk/motors.h firmware/tuxcore/trunk/sensors.c Log: * Moved all defines related to I/O ports to hardware.h. Doxygen comments added. Modified: firmware/tuxcore/trunk/global.h =================================================================== --- firmware/tuxcore/trunk/global.h 2007-09-06 15:23:54 UTC (rev 494) +++ firmware/tuxcore/trunk/global.h 2007-09-06 15:25:15 UTC (rev 495) @@ -19,150 +19,16 @@ /* $Id$ */ -#ifndef GLOBAL_H -#define GLOBAL_H +/** \file global.h + \brief Global ressources +*/ +#ifndef _GLOBAL_H_ +#define _GLOBAL_H_ + #include <avr/io.h> #include "common/commands.h" -/* - * -------------------------------------------------------- - * SWITCHES - * -------------------------------------------------------- - */ - -/* Switches */ -// #define SW_PT PORTB [> switch port <] -// #define SW_PIN PINB [> switch input port <] -// #define SW_DDR DDRB [> switch DDR <] -// #define SW_MK (_BV(PB3) | _BV(PB4) | _BV(PB5)) -// #define SW_LW_MK _BV(PB3) [> left wing switch <] -// #define SW_RW_MK _BV(PB4) [> right wing switch <] -#define SW_HD_PIN PINB /* head switch input port */ -#define SW_HD_PT PORTB /* head switch port */ -#define SW_HD_DDR DDRB /* head switch DDR */ -#define SW_HD_MK _BV(PB5) /* head switch */ - -/* Position Switches */ -#define PSW_SPIN_MK _BV(PD3) /* spin switch */ -#define PSW_SPIN_PT PORTD -#define PSW_SPIN_PIN PIND -#define PSW_SPIN_DDR DDRD -#define PSW_WINGS_MK _BV(PC1) /* wings switch */ -#define PSW_WINGS_PT PORTC -#define PSW_WINGS_PIN PINC -#define PSW_WINGS_DDR DDRC -#define PSW_MOUTH_PT PORTB -#define PSW_MOUTH_PIN PINB -#define PSW_MOUTH_DDR DDRB -#define PSW_MOUTH_O_MK _BV(PB3) /* mouth switch when opened */ -#define PSW_MOUTH_C_MK _BV(PB4) /* mouth switch when closed */ -#define PSW_MOUTH_MK (PSW_MOUTH_O_MK | PSW_MOUTH_C_MK) -#define PSW_EYES_PT PORTD -#define PSW_EYES_PIN PIND -#define PSW_EYES_DDR DDRD -#define PSW_EYES_O_MK _BV(PD6) /* eyes switch when opened */ -#define PSW_EYES_C_MK _BV(PD7) /* eyes switch when closed */ -#define PSW_EYES_MK (PSW_EYES_O_MK | PSW_EYES_C_MK) - -/* - * -------------------------------------------------------- - * IR - * -------------------------------------------------------- - */ - -#define IR_LED_PT PORTD /* ir led */ -#define IR_LED_DDR DDRD -#define IR_LED_MK _BV(PD5) -#define IR_REC_PT PORTD /* ir receiver */ -#define IR_REC_PIN PIND -#define IR_REC_DDR DDRD -#define IR_REC_MK _BV(PD2) - -/* - * -------------------------------------------------------- - * PHOTOTRANSISTOR - * -------------------------------------------------------- - */ - -#define LIGHT_PU_PORT PORTC -#define LIGHT_PU_MK _BV(PC0) -#define LIGHT_PU_DDR DDRC - -/* - * -------------------------------------------------------- - * CHARGER - * -------------------------------------------------------- - */ - -#define CHARGER_INH_PT PORTB -#define CHARGER_INH_DDR DDRB -#define CHARGER_INH_MK _BV(PB6) - -/* - * -------------------------------------------------------- - * LEDs - * -------------------------------------------------------- - */ - -#define LED_PT PORTC /* blue eye leds */ -#define LED_PIN PINC /* blue eye leds */ -#define LED_DDR DDRC -#define LED_L_MK _BV(PC2) /* right blue led */ -#define LED_R_MK _BV(PC3) /* left blue led */ -#define LED_MK (LED_R_MK | LED_L_MK) - -/* - * -------------------------------------------------------- - * ETERNAL I/O - * -------------------------------------------------------- - */ - -#define EXIO_PT PORTB -#define EXIO_DDR DDRB -#define EXIO_PIN PINB -#define EXIO_MK _BV(PB7) - -/* - * -------------------------------------------------------- - * MOTORS - * -------------------------------------------------------- - */ - -/* I/O */ -// #define MOT_PT PORTD [> motors port <] -// #define MOT_DDR DDRD -// #define MOT_MK (MOT_WINGS_FW | MOT_WINGS_BW | MOT_MOUTH_MK | MOT_EYES_MK | MOT_SPIN_R_MK | MOT_SPIN_L_MK) -#define MOT_WINGS_BW_MK _BV(PD4) /* wing motor forward */ -#define MOT_WINGS_BW_PT PORTD -#define MOT_WINGS_BW_DDR DDRD -#define MOT_WINGS_FW_MK _BV(PB0) /* wing motor backward */ -#define MOT_WINGS_FW_PT PORTB -#define MOT_WINGS_FW_DDR DDRB -#define wingsPwmMask pwmMaskB -#define MOT_MOUTH_MK _BV(PD1) /* mouth motor (forward) */ -#define MOT_MOUTH_PT PORTD -#define MOT_MOUTH_DDR DDRD -#define MOT_IMOUTH_MK _BV(PD0) /* inverted mouth motor (backward) */ -#define MOT_IMOUTH_PT PORTD -#define MOT_IMOUTH_DDR DDRD -#define MOT_IEYES_MK _BV(PD1) /* inverted eyes motor (backward) */ -#define MOT_IEYES_PT PORTD -#define MOT_IEYES_DDR DDRD -#define MOT_EYES_MK _BV(PD0) /* eyes motor (forward) */ -#define MOT_EYES_PT PORTD -#define MOT_EYES_DDR DDRD -#define MOT_SPIN_R_MK _BV(PB2) /* spin motor, turn on the right */ -#define MOT_SPIN_R_PT PORTB -#define MOT_SPIN_R_DDR DDRB -#define MOT_SPIN_L_MK _BV(PB1) /* spin motor, turn on the left */ -#define MOT_SPIN_L_PT PORTB -#define MOT_SPIN_L_DDR DDRB -#define MOT_SPIN_MK (MOT_SPIN_L_MK | MOT_SPIN_R_MK) -#define MOT_SPIN_DDR DDRB -#define MOT_SPIN_PT PORTB -#define spinPwmMask pwmMaskB - /* Control */ #define EYES_OPEN_DLY 4 /* 4ms unit */ #define EYES_ICLOSE_DLY 4 /* 4ms unit */ @@ -172,6 +38,8 @@ #define SPIN_STOP_DLY 10 /* 4ms unit */ #define WINGS_STOP_DLY 4 /* 4ms unit */ +#define wingsPwmMask pwmMaskB +#define spinPwmMask pwmMaskB /* * -------------------------------------------------------- * STATUS @@ -379,4 +247,5 @@ #define sigout_unset turnLeftLedOff #define sigin_ini() {LED_PT &= ~LED_R_MK; LED_DDR &= ~LED_R_MK;} /* used as signal input */ #define sigin (LED_PIN & LED_R_MK) /* wait for tester to be as pull up */ -#endif + +#endif /* _GLOBAL_H_ */ Added: firmware/tuxcore/trunk/hardware.h =================================================================== --- firmware/tuxcore/trunk/hardware.h (rev 0) +++ firmware/tuxcore/trunk/hardware.h 2007-09-06 15:25:15 UTC (rev 495) @@ -0,0 +1,262 @@ +/* + * TUXCORE - Firmware for the 'core' CPU of tuxdroid + * Copyright (C) 2007 C2ME S.A. <tux...@c2...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* $Id$ */ + +/** \file hardware.h + \brief Hardware configuration of the I/O pins +*/ + +#ifndef _HARDWARE_H_ +#define _HARDWARE_H_ + +#include <avr/io.h> + +/** \defgroup hardware Hardware configuration + * + * Description of all the hardware connected to the I/O of the CPU. + */ + +/** \ingroup hardware */ +/*! @{ */ + +/** + * \name Head button + * The head button switch shortcuts to ground when pressed. + * @{ */ +/** Head button PIN (input port). */ +#define SW_HD_PIN PINB +/** Head button PORT. */ +#define SW_HD_PT PORTB +/** Head button DDR. */ +#define SW_HD_DDR DDRB +/** Head button mask.*/ +#define SW_HD_MK _BV(PB5) +/*! @} */ + +/** + * \name Position switches + * All position switches shortcuts to ground when pressed. + * + * - The spin switch is presed approximately each quarter of turn. + * - The flipper switch is pressed when the flippers are up or down. There's + * only one switch for both positions so it's tricky to know the absolute + * position of the flippers. + * - The eyes and mouth both have 2 switches to detect when they are open or + * closed. The corresponding switch is pressed when a plain position is + * reached. In between, both switches are released. + * @{ */ +/** Spin switch mask. */ +#define PSW_SPIN_MK _BV(PD3) +/** Spin switch PIN. */ +#define PSW_SPIN_PIN PIND +/** Spin switch PORT. */ +#define PSW_SPIN_PT PORTD +/** Spin switch DDR. */ +#define PSW_SPIN_DDR DDRD +/** Flippers position switch PIN. */ +#define PSW_WINGS_PIN PINC +/** Flippers position switch PORT. */ +#define PSW_WINGS_PT PORTC +/** Flippers position switch DDR. */ +#define PSW_WINGS_DDR DDRC +/** Flippers position switch mask. */ +#define PSW_WINGS_MK _BV(PC1) +/** Mouth position switches PIN. */ +#define PSW_MOUTH_PIN PINB +/** Mouth position switches PORT. */ +#define PSW_MOUTH_PT PORTB +/** Mouth position switches DDR. */ +#define PSW_MOUTH_DDR DDRB +/** Mouth open position switch mask. */ +#define PSW_MOUTH_O_MK _BV(PB3) +/** Mouth closed position switch mask. */ +#define PSW_MOUTH_C_MK _BV(PB4) +/** Mouth position switches mask. */ +#define PSW_MOUTH_MK (PSW_MOUTH_O_MK | PSW_MOUTH_C_MK) +/** Eyes position switches PIN. */ +#define PSW_EYES_PIN PIND +/** Eyes position switches PORT. */ +#define PSW_EYES_PT PORTD +/** Eyes position switches DDR. */ +#define PSW_EYES_DDR DDRD +/** Eyes open position switch mask. */ +#define PSW_EYES_O_MK _BV(PD6) +/** Eyes closed position switch mask. */ +#define PSW_EYES_C_MK _BV(PD7) +/** Eyes position switches mask. */ +#define PSW_EYES_MK (PSW_EYES_O_MK | PSW_EYES_C_MK) +/*! @} */ + +/** + * \name IR + * - The IR led is controlled through a power driver. Setting the output pin + * will turn the led on. + * - The IR receiver is directly connected to the input pin. The signal is + * normally high and goes low when an IR signal is received. + * @{ */ +/** IR led PORT. */ +#define IR_LED_PT PORTD +/** IR led DDR. */ +#define IR_LED_DDR DDRD +/** IR led mask. */ +#define IR_LED_MK _BV(PD5) +/** IR receiver PIN. */ +#define IR_REC_PIN PIND +/** IR receiver PORT. */ +#define IR_REC_PT PORTD +/** IR receiver DDR. */ +#define IR_REC_DDR DDRD +/** IR receiver mask. */ +#define IR_REC_MK _BV(PD2) +/*! @} */ + +/** + * \name Phototransistor + * The Phototransistor is connected as an LDR to a 1MOhms resistor. A second + * pull-up of 10kOhms can be added in parallel to change the load. The extra + * pull-up is disconnected when the pin is left in high-Z mode, and is added + * when the pin is set as strong high. + * @{ */ +/** Phototransistor extra pull-up PORT. */ +#define LIGHT_PU_PORT PORTC +/** Phototransistor extra pull-up DDR. */ +#define LIGHT_PU_DDR DDRC +/** Phototransistor extra pull-up mask. */ +#define LIGHT_PU_MK _BV(PC0) +/*! @} */ + +/** + * \name Charger inhibit + * This pin inhibits the charge when set high. It shouldn't be left in high-z + * otherwise the charge won't be stable. Keep it low. + * @{ */ +/* + * Charger + */ +/** Charger inhibit PORT. */ +#define CHARGER_INH_PT PORTB +/** Charger inhibit DDR. */ +#define CHARGER_INH_DDR DDRB +/** Charger inhibit mask. */ +#define CHARGER_INH_MK _BV(PB6) +/*! @} */ + +/** + * \name LED + * The leds are directly connected to the output pins through a 100 Ohms + * resistor. + * @{ */ +/** Blue eyes leds PIN. */ +#define LED_PIN PINC +/** Blue eyes leds PORT. */ +#define LED_PT PORTC +/** Blue eyes leds DDR. */ +#define LED_DDR DDRC +/** Blue eyes right led mask. */ +#define LED_L_MK _BV(PC2) +/** Blue eyes left led mask. */ +#define LED_R_MK _BV(PC3) +/** Blue eyes both leds mask. */ +#define LED_MK (LED_R_MK | LED_L_MK) +/*! @} */ + +/** + * \name External I/O + * The external I/O is routed to the external connector which is accessible in + * the battery compartment of tux. There's a 330 Ohms resistor in series to + * protect the IC. + * @{ */ +/** External I/O PIN. */ +#define EXIO_PIN PINB +/** External I/O PORT. */ +#define EXIO_PT PORTB +/** External I/O DDR. */ +#define EXIO_DDR DDRB +/** External I/O mask. */ +#define EXIO_MK _BV(PB7) +/*! @} */ + +/** + * \name Motors + * The motor drivers use 2 pins to move forward or backward. Setting the first + * pin to high will move forward, setting the other will turn backward. You + * can't set both simultaneously as that doesn't make sense and is dangerous + * for the motor driver. Here we added a protection so that even in this case, + * the motor driver won't burn and the motor will simply turn in one direction. + * @{ */ +/** Flippers backward motor PORT. */ +#define MOT_WINGS_BW_PT PORTD +/** Flippers backward motor DDR. */ +#define MOT_WINGS_BW_DDR DDRD +/** Flippers backward motor mask. */ +#define MOT_WINGS_BW_MK _BV(PD4) +/** Flippers forward motor PORT. */ +#define MOT_WINGS_FW_PT PORTB +/** Flippers forward motor DDR. */ +#define MOT_WINGS_FW_DDR DDRB +/** Flippers forward motor mask. */ +#define MOT_WINGS_FW_MK _BV(PB0) +/** Mouth motor PORT. */ +#define MOT_MOUTH_PT PORTD +/** Mouth motor DDR. */ +#define MOT_MOUTH_DDR DDRD +/** Mouth motor mask. */ +#define MOT_MOUTH_MK _BV(PD1) +/** Mouth inverted motor PORT. */ +#define MOT_IMOUTH_PT PORTD +/** Mouth inverted motor DDR. */ +#define MOT_IMOUTH_DDR DDRD +/** Mouth inverted motor mask. */ +#define MOT_IMOUTH_MK _BV(PD0) +/** Eyes motor PORT. */ +#define MOT_IEYES_PT PORTD +/** Eyes motor DDR. */ +#define MOT_IEYES_DDR DDRD +/** Eyes motor mask. */ +#define MOT_IEYES_MK _BV(PD1) /* inverted eyes motor (backward) */ +/** Eyes inverted motor PORT. */ +#define MOT_EYES_PT PORTD +/** Eyes inverted motor DDR. */ +#define MOT_EYES_DDR DDRD +/** Eyes inverted motor mask. */ +#define MOT_EYES_MK _BV(PD0) /* eyes motor (forward) */ +/** Spinning right motor PORT. */ +#define MOT_SPIN_R_PT PORTB +/** Spinning right motor DDR. */ +#define MOT_SPIN_R_DDR DDRB +/** Spinning right motor mask. */ +#define MOT_SPIN_R_MK _BV(PB2) /* spin motor, turn on the right */ +/** Spinning left motor PORT. */ +#define MOT_SPIN_L_PT PORTB +/** Spinning left motor DDR. */ +#define MOT_SPIN_L_DDR DDRB +/** Spinning left motor mask. */ +#define MOT_SPIN_L_MK _BV(PB1) /* spin motor, turn on the left */ +/** Spinning motor PORT. */ +#define MOT_SPIN_PT PORTB +/** Spinning motor DDR. */ +#define MOT_SPIN_DDR DDRB +/** Spinning motor mask. */ +#define MOT_SPIN_MK (MOT_SPIN_L_MK | MOT_SPIN_R_MK) +/*! @} */ + +/*! @} */ + +#endif /* _HARDWARE_H_ */ Property changes on: firmware/tuxcore/trunk/hardware.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Modified: firmware/tuxcore/trunk/ir.c =================================================================== --- firmware/tuxcore/trunk/ir.c 2007-09-06 15:23:54 UTC (rev 494) +++ firmware/tuxcore/trunk/ir.c 2007-09-06 15:25:15 UTC (rev 495) @@ -23,6 +23,7 @@ #include <avr/io.h> #include "global.h" +#include "hardware.h" #include "ir.h" // #define __debug__ Modified: firmware/tuxcore/trunk/led.c =================================================================== --- firmware/tuxcore/trunk/led.c 2007-09-06 15:23:54 UTC (rev 494) +++ firmware/tuxcore/trunk/led.c 2007-09-06 15:25:15 UTC (rev 495) @@ -20,6 +20,7 @@ /* $Id$ */ #include "global.h" +#include "hardware.h" #include "led.h" uint8_t led_delay, led_blinking_pw, led_blinking_cnt; /* led blinking registers */ Modified: firmware/tuxcore/trunk/motors.h =================================================================== --- firmware/tuxcore/trunk/motors.h 2007-09-06 15:23:54 UTC (rev 494) +++ firmware/tuxcore/trunk/motors.h 2007-09-06 15:25:15 UTC (rev 495) @@ -55,9 +55,11 @@ /** \file motors.c \ingroup movements */ -#ifndef MOTORS_H -#define MOTORS_H +#ifndef _MOTORS_H_ +#define _MOTORS_H_ +#include "hardware.h" + #define WINGS_TIM_RESET 0Xff #define WINGS_TIM_DIFF 0x10 enum mouth_pos_s @@ -72,9 +74,6 @@ extern uint8_t mouthStpCnt, mouthPosCnt, mouth_pos; extern uint8_t spinPosCnt, spinStpCnt, spinPwm; -/* switches interrupts vector for timer debounce */ -extern volatile uint8_t int_sw_flags; - /* pwm mask registers */ extern uint8_t pwmMaskB; @@ -222,7 +221,6 @@ #define PWM_PERIOD 5 uint8_t static pwm_tim; - static inline void motor_control(void) __attribute__ ((always_inline)); void motor_control(void) { @@ -296,4 +294,4 @@ } } } -#endif +#endif /* _MOTORS_H_ */ Modified: firmware/tuxcore/trunk/sensors.c =================================================================== --- firmware/tuxcore/trunk/sensors.c 2007-09-06 15:23:54 UTC (rev 494) +++ firmware/tuxcore/trunk/sensors.c 2007-09-06 15:25:15 UTC (rev 495) @@ -23,6 +23,7 @@ #include <avr/io.h> #include "global.h" +#include "hardware.h" /* * ADC conversion complete. |