[tuxdroid-svn] r523 - firmware/tuxcore/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-09-13 09:34:15
|
Author: jaguarondi Date: 2007-09-13 11:34:02 +0200 (Thu, 13 Sep 2007) New Revision: 523 Modified: firmware/tuxcore/trunk/global.c firmware/tuxcore/trunk/global.h firmware/tuxcore/trunk/led.c firmware/tuxcore/trunk/led.h firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/parser.c firmware/tuxcore/trunk/standalone.c Log: * Reorganized the led functions to move all variables back to the module and make them static. Updated the comments. Modified: firmware/tuxcore/trunk/global.c =================================================================== --- firmware/tuxcore/trunk/global.c 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/global.c 2007-09-13 09:34:02 UTC (rev 523) @@ -38,7 +38,6 @@ uint8_t updateStatusFlag, commandProcessFlag, pingCnt, statusFifoFlag = 0; uint8_t ir_delay, ir_flg, ir_oldvalue, alt_mode, ir_send_flg, tux_ir_id, last_tux_seen = 0xFF; -uint8_t led_backup; /* * Condition flags Modified: firmware/tuxcore/trunk/global.h =================================================================== --- firmware/tuxcore/trunk/global.h 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/global.h 2007-09-13 09:34:02 UTC (rev 523) @@ -182,7 +182,6 @@ extern uint8_t updateStatusFlag, commandProcessFlag, pingCnt, statusFifoFlag; extern uint8_t ir_delay, ir_flg, ir_oldvalue, alt_mode, ir_send_flg, tux_ir_id, last_tux_seen; -extern uint8_t led_backup; /* * Sleep modes Modified: firmware/tuxcore/trunk/led.c =================================================================== --- firmware/tuxcore/trunk/led.c 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/led.c 2007-09-13 09:34:02 UTC (rev 523) @@ -24,23 +24,28 @@ \ingroup led */ -#include "global.h" -#include "hardware.h" #include "led.h" -uint8_t led_delay, led_blinking_pw, led_blinking_cnt; /* led blinking registers */ +/** Buffer the leds values before being applied on the I/O port. + * \ingroup led */ +uint8_t leds_buffer; +/** Counter for the delay between 2 toggles of the leds. */ +static uint8_t led_delay; +/** Delay between 2 toggles of the leds when blinking them. */ +static uint8_t led_blinking_pw; +/** Number of times the leds should be toggled when blinking. */ +static uint8_t led_blinking_cnt; + /** - \brief blinkLeds function + \brief Blink leds \ingroup led + \param cnt Number of blinks + \param pulse_width Blinking pulse width - \param cnt number of blinks before stop - \param pulse_width blink frequency - - The eyes will start until 'cnt' blink are executed. 'cnt' can be up to 256. - 'pulse_width' can be used to change the blink frequency. - */ - -void blinkLeds(uint8_t cnt, uint8_t pulse_width) + The leds will be toggled 'cnt' times. The pulse width can be used to change + the toggle frequency. +*/ +void blink_leds(uint8_t cnt, uint8_t pulse_width) { if (led_delay) /* cancel the blink if one is already happening */ return; @@ -56,30 +61,32 @@ } /** - \brief Refresh led port \ingroup led + \brief Refresh the leds I/O with the buffer value. + \ingroup led + */ +void refresh_leds(void) +{ + LED_PT &= ~LED_MK; + LED_PT |= leds_buffer; +} - \param mk Temp variable used to store the leds status. - - This function check the value of mk for both leds, and puts the value into the - output port. - - When the eyes are closed, the leds are switched off. To make possible to - change the leds status during the eyes are closed, the value is buffered. A - reveived command when the eyes are closed will be applied when the eyes - will reopened. +/** + \brief Periodic routine that controls the leds. + \ingroup led - This function is called when eyes are opened, and they're not blinking. - */ - -void setLeds(uint8_t mk) + This function should be called regularly as it controls the blinking. The + period this function is called will be the unit period of the led blinking. + */ +void led_control(void) { - if (mk & LED_R_MK) - LED_PT |= LED_R_MK; - else - LED_PT &= ~LED_R_MK; - - if (mk & LED_L_MK) - LED_PT |= LED_L_MK; - else - LED_PT &= ~LED_L_MK; + if (led_delay) + { + led_delay--; + if (!led_delay) + { + toggleLeds(); + if (--led_blinking_cnt) + led_delay = led_blinking_pw; + } + } } Modified: firmware/tuxcore/trunk/led.h =================================================================== --- firmware/tuxcore/trunk/led.h 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/led.h 2007-09-13 09:34:02 UTC (rev 523) @@ -19,116 +19,94 @@ /* $Id$ */ -/** \defgroup led Leds - - The led module contains all the function necessary to drive eyes leds and - manage the remote control. -*/ - /** \file led.h - \brief Blue leds control interface + \brief Blue leds control interface. \ingroup led */ -#ifndef LED_H -#define LED_H +/** \defgroup led Leds + The led module contains the functions that drive the eye leds. +*/ -extern uint8_t led_delay, led_blinking_pw, led_blinking_cnt; +#ifndef _LED_H_ +#define _LED_H_ -/** - \brief Turn both LEDs on - \ingroup led +#include "hardware.h" - */ -#define turnLedsOn() (led_backup |= LED_MK) +extern uint8_t leds_buffer; /** - \brief Turn both LEDs off + \brief Turn both leds on. \ingroup led - - This declaration is used to switch off the led when the eyes are opened. - - It may be used everywhere when the eyes must be off. */ -#define turnLedsOff() (led_backup &= ~LED_MK) +#define turnLedsOn() (leds_buffer |= LED_MK) /** - \brief Turn both LEDs off when eyes are closed + \brief Turn both leds off. \ingroup led - - This declaration is used to switch off the leds when eyes are closed. In - this case, led_backup must not be changed. - If not, the last value will be - lost, and the led status will not be restored when the eyes will be - reopened. - - \note This declaration is used only in the standalone_behavior.c. It souldn't - be used elsewhere. */ -#define turnLedsOffbEyes() (LED_PT &= ~LED_MK) +#define turnLedsOff() (leds_buffer &= ~LED_MK) /** - \brief Turn left LED on + \brief Turn left led on. \ingroup led */ -#define turnLeftLedOn() (led_backup |= LED_L_MK) +#define turnLeftLedOn() (leds_buffer |= LED_L_MK) /** - \brief Turn right LED on + \brief Turn right led on. \ingroup led */ -#define turnRightLedOn() (led_backup |= LED_R_MK) +#define turnRightLedOn() (leds_buffer |= LED_R_MK) /** - \brief Turn left LED off + \brief Turn left led off. \ingroup led */ -#define turnLeftLedOff() (led_backup &= ~LED_L_MK) +#define turnLeftLedOff() (leds_buffer &= ~LED_L_MK) /** - \brief Turn right LED off + \brief Turn right led off. \ingroup led */ -#define turnRightLedOff() (led_backup &= ~LED_R_MK) +#define turnRightLedOff() (leds_buffer &= ~LED_R_MK) /** - \brief read led's status + \brief Read the value of the leds. \ingroup led */ -#define readLeds() (LED_PIN & LED_MK) +#define readLeds() (leds_buffer) /** - \brief blink leds + \brief Toggle leds. \ingroup led - \param pulse_width Blinking pulse width - - Toggle both leds once then re-toggle them after a delay given as parameter. - The result looks like a blinking of the leds. */ -void blinkLeds(uint8_t cnt, uint8_t pulse_width); -void setLeds (uint8_t mk); +#define toggleLeds() (leds_buffer ^= LED_MK) + /** - \brief toggle leds + \brief Toggle left led. \ingroup led - - The led_toggle command is bufferised to prevent a bug : - - Without this buffer, if an odd number of blink is received, the leds will blink, but at the end of this sequence, the previous state (stored before the blinking sequence) is restored. - - The visible result is that tux has executed an even number of blink. */ -#define toggleLeds() (led_backup ^= LED_MK) +#define toggleLeftLed() (leds_buffer ^= LED_L_MK) /** - \brief toggle left led + \brief toggle right led. \ingroup led */ -#define toggleLeftLed() (led_backup ^= LED_L_MK) +#define toggleRightLed() (leds_buffer ^= LED_R_MK) /** - \brief toggle right led + \brief Turn both leds off directly on the I/O port. \ingroup led + + This function is used to switch off the leds when the eyes are closed. + You shouldn't use this function elsewhere as the I/O port will be refreshed + immediately with the leds_buffer value. */ -#define toggleRightLed() (led_backup ^= LED_R_MK) +#define mask_leds() (LED_PT &= ~LED_MK) -#endif +extern void blink_leds(uint8_t cnt, uint8_t pulse_width); +extern void refresh_leds(void); +extern void led_control(void); + +#endif /* _LED_H_ */ Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/main.c 2007-09-13 09:34:02 UTC (rev 523) @@ -171,17 +171,15 @@ if (ir_delay) ir_delay--; - /* Led blinking */ - if (led_delay) - { - led_delay--; - if (!led_delay) - { - toggleLeds(); - if (--led_blinking_cnt) - led_delay = led_blinking_pw; - } - } + /* Led blinking. */ + led_control(); + /* Refresh the leds. When the eyes are closed, the leds are + * switched off. They'll be refreshed again with the buffered value + * when the eyes will reopen. */ + if (cond_flags.eyes_closed) + mask_leds(); + else + refresh_leds(); } if (t100ms_flag) { @@ -330,12 +328,10 @@ void sleep(void) { - uint8_t led_bak; uint8_t PRR_bak; /* Set power savings configuration. */ cli(); - led_bak = readLeds(); closeIO(); powersave_movements(); stop_spinning(); @@ -358,7 +354,6 @@ /* Re-configure in normal mode. */ PRR = PRR_bak; - setLeds(led_bak); /* restore leds status */ i2cCommunicationInit(); init_movements(); initIO(); Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/parser.c 2007-09-13 09:34:02 UTC (rev 523) @@ -160,7 +160,7 @@ } else if (command[0] == LED_BLINK_CMD) { - blinkLeds(command[1], command[2]); + blink_leds(command[1], command[2]); } else if (command[0] == IR_SEND_RC5_CMD) { Modified: firmware/tuxcore/trunk/standalone.c =================================================================== --- firmware/tuxcore/trunk/standalone.c 2007-09-13 09:30:32 UTC (rev 522) +++ firmware/tuxcore/trunk/standalone.c 2007-09-13 09:34:02 UTC (rev 523) @@ -200,11 +200,6 @@ if (!event_timer) eventTriggering(); - if (cond_flags.eyes_closed) - turnLedsOffbEyes(); - else - setLeds(led_backup); - /* Disable spinning when plugged */ if ((gStatus.sw & GSTATUS_POWERPLUGSW_MK)) { @@ -237,7 +232,7 @@ /* IR feedback signal */ if (tux_config.ir_feedback) - blinkLeds(2, 4); + blink_leds(2, 4); /* ALT KEYS */ if (alt_mode) |