1 /********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/
5 * @brief LED management.
10 /******************************************************************************/
12 /* Includes ------------------------------------------------------------------*/
17 /* Private variables ---------------------------------------------------------*/
19 int GreenLED_Counter = 0;
20 int RedLED_Counter = 0;
21 enum LED_mode GreenLED_mode = LED_UNDEF;
22 enum LED_mode RedLED_mode = LED_UNDEF;
23 enum LED_mode GreenLED_newmode = LED_OFF;
24 enum LED_mode RedLED_newmode = LED_OFF;
25 const int HalfPeriod_LF = 200;
26 const int HalfPeriod_HF = 50;
27 const int Period_LF = 200 * 2;
28 const int Period_HF = 50 * 2;
30 /* Public functions for CircleOS ---------------------------------------------*/
32 /*******************************************************************************
36 *******************************************************************************/
39 * Initialization of the GPIOs for the LEDs
41 * @note Is called by CircleOS startup.
44 /******************************************************************************/
47 GPIO_InitTypeDef GPIO_InitStructure;
49 /* Enable LED GPIO clock */
50 RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
52 /* Configure LED pins as output push-pull */
53 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 ;
54 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
55 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
57 GPIO_Init( GPIOB, &GPIO_InitStructure );
60 /*******************************************************************************
64 *******************************************************************************/
67 * Called by the CircleOS scheduler to manage the states of the LEDs.
68 * LEDs may be on, off or blinking according to their state.
71 /******************************************************************************/
72 void LED_Handler( void )
74 LED_Handler_hw(LED_GREEN);
75 LED_Handler_hw(LED_RED);
78 /*******************************************************************************
82 *******************************************************************************/
85 * Called by the CircleOS scheduler to manage the states of the LEDs.
86 * LEDs may be on, off or blinking according to their state.
88 * @param[in] id A LED_id indicating the LED to take care of.
91 /******************************************************************************/
92 void LED_Handler_hw( enum LED_id id )
97 // Choose the right LED parameters.
100 counter = GreenLED_Counter;
101 mode = GreenLED_newmode;
105 counter = RedLED_Counter;
106 mode = RedLED_newmode;
113 if( ( ( id == LED_GREEN ) && ( GreenLED_mode == mode ) ) ||
114 ( ( id == LED_RED ) && ( RedLED_mode == mode ) ) )
119 if( id == LED_GREEN )
121 GPIO_WriteBit( GPIOB, GPIO_Pin_8, ( mode == LED_OFF ) ? Bit_RESET : Bit_SET );
123 GreenLED_mode = mode;
125 else if( id == LED_RED )
127 GPIO_WriteBit( GPIOB, GPIO_Pin_9, ( mode == LED_OFF ) ? Bit_RESET : Bit_SET );
135 case LED_BLINKING_HF :
138 if( counter == HalfPeriod_HF )
140 GPIO_WriteBit( GPIOB, ( id == LED_RED ) ? GPIO_Pin_9 : GPIO_Pin_8, Bit_SET );
142 else if( ( counter < 0 ) || ( counter >= Period_HF ) )
144 GPIO_WriteBit( GPIOB, ( id == LED_RED ) ? GPIO_Pin_9 : GPIO_Pin_8, Bit_RESET );
150 case LED_BLINKING_LF :
153 if( counter == HalfPeriod_LF )
155 GPIO_WriteBit( GPIOB, ( id == LED_RED ) ? GPIO_Pin_9 : GPIO_Pin_8, Bit_SET );
158 else if( ( counter < 0 ) || ( counter >= Period_LF ) )
160 GPIO_WriteBit( GPIOB, ( id == LED_RED ) ? GPIO_Pin_9 : GPIO_Pin_8, Bit_RESET );
170 if( id == LED_GREEN )
172 GreenLED_Counter = counter;
173 GreenLED_mode = mode;
177 RedLED_Counter = counter;
184 /* Public functions ----------------------------------------------------------*/
186 /*******************************************************************************
190 *******************************************************************************/
193 * Set a specified LED in a specified mode.
195 * @param[in] id A LED_id specifying the LED to change the mode.
196 * @param[in] mode A LED_mode describing the new LED mode.
199 /******************************************************************************/
200 void LED_Set( enum LED_id id, enum LED_mode mode )
202 if( id == LED_GREEN )
204 GreenLED_newmode = mode;
206 else if( id == LED_RED )
208 RedLED_newmode = mode;