[3d07ba]: leds.c Maximize Restore History

Download this file

leds.c    89 lines (69 with data), 2.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
Copyright (C) 2011 Georg Ottinger
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "includes.h"
unsigned char leds_status, leds_left, leds_right;
unsigned char updatevuflag;
void InitLEDS()
{
PORT_LEDS->DDR = 0xFF;
PORT_LEDS->CR1 = 0xFF;
PORT_MUX->DDR |= PIN_MUX_STATUS | PIN_MUX_LEFT | PIN_MUX_RIGHT;
PORT_MUX->CR1 |= PIN_MUX_STATUS | PIN_MUX_LEFT | PIN_MUX_RIGHT;
#ifdef LEDS_PROFILE_ON
GPIOG->DDR = GPIO_PIN_0;
GPIOG->CR1 = GPIO_PIN_0;
#endif
TIM4_DeInit();
TIM4_TimeBaseInit(TIM4_PRESCALER_128,255);
TIM4_ITConfig(TIM4_IT_UPDATE,ENABLE);
TIM4_Cmd(ENABLE);
}
#pragma vector = TIM4_OVR_UIF_vector
__interrupt void TIM_Update_vector(void)
{
static char turn=0;
static char updatecounter=0;
#ifdef LEDS_PROFILE_ON
GPIOG->ODR = GPIO_PIN_0;
#endif
updatecounter++;
if(updatecounter >= UPDATE_VU_INTERVAL)
{
updatevuflag = 1;
updatecounter = 0;
}
PORT_MUX->ODR &= ~( PIN_MUX_STATUS | PIN_MUX_LEFT | PIN_MUX_RIGHT );
switch(turn)
{
case 0:
PORT_MUX->ODR |= PIN_MUX_STATUS;
PORT_LEDS->ODR=leds_status;
break;
case 1:
PORT_MUX->ODR |= PIN_MUX_LEFT;
PORT_LEDS->ODR=leds_left;
break;
case 2:
PORT_MUX->ODR |= PIN_MUX_RIGHT;
PORT_LEDS->ODR=leds_right;
break;
}
turn++;
if(turn >= 3) turn=0;
TIM4_ClearITPendingBit(TIM4_IT_UPDATE);
#ifdef LEDS_PROFILE_ON
GPIOG->ODR = 0;
#endif
}