author | Lukasz Forynski <lukasz.forynski@gmail.com> |
Fri, 03 Sep 2010 21:24:33 +0100 | |
branch | generic_fixes_and_updates |
changeset 60 | 5ed4f248a4cc |
parent 59 | 7f38143c4aa6 |
child 82 | 65b40f262685 |
permissions | -rwxr-xr-x |
0 | 1 |
// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// omap3530/beagle_drivers/led/led.cpp |
|
15 |
// |
|
54
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
16 |
#include <beagle/beagle_gpio.h> |
0 | 17 |
|
54
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
18 |
const TInt KBeatTimeInSeconds = 4; |
0 | 19 |
|
54
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
20 |
class LedHeartBeat |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
21 |
{ |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
22 |
public: |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
23 |
inline LedHeartBeat(); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
24 |
/*inline ~LedHeartBeat() { iTimer.Cancel(); }*/ // will it ever be destroyed? |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
25 |
TInt DoCreate(); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
26 |
static void Beat(TAny *aPtr); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
27 |
private: |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
28 |
NTimer iTimer; |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
29 |
TBool iIsLedOn; |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
30 |
}; |
0 | 31 |
|
54
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
32 |
LedHeartBeat::LedHeartBeat() : |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
33 |
iTimer(Beat, this) |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
34 |
{ |
0 | 35 |
} |
36 |
||
54
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
37 |
TInt LedHeartBeat::DoCreate() |
0 | 38 |
{ |
54
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
39 |
TInt r = GPIO::SetPinDirection(KGPIO_LED0, GPIO::EOutput); |
59
7f38143c4aa6
Fixed prcm build warnings / updated led driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
54
diff
changeset
|
40 |
if (r == KErrNone) |
7f38143c4aa6
Fixed prcm build warnings / updated led driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
54
diff
changeset
|
41 |
{ |
7f38143c4aa6
Fixed prcm build warnings / updated led driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
54
diff
changeset
|
42 |
GPIO::SetPinMode(KGPIO_LED0, GPIO::EEnabled); |
7f38143c4aa6
Fixed prcm build warnings / updated led driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
54
diff
changeset
|
43 |
GPIO::SetOutputState(KGPIO_LED0, GPIO::ELow); |
7f38143c4aa6
Fixed prcm build warnings / updated led driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
54
diff
changeset
|
44 |
iTimer.OneShot(NKern::TimerTicks(KBeatTimeInSeconds * 1000)); |
7f38143c4aa6
Fixed prcm build warnings / updated led driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
54
diff
changeset
|
45 |
} |
7f38143c4aa6
Fixed prcm build warnings / updated led driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
54
diff
changeset
|
46 |
else |
0 | 47 |
{ |
54
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
48 |
Kern::Printf("LedHeartBeat: SetPinDirection for LED failed, r %d", r); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
49 |
} |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
50 |
return r; |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
51 |
} |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
52 |
|
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
53 |
void LedHeartBeat::Beat(TAny * aPtr) |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
54 |
{ |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
55 |
LedHeartBeat* b = (LedHeartBeat*)aPtr; |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
56 |
if(b->iIsLedOn) |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
57 |
{ |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
58 |
GPIO::SetOutputState(KGPIO_LED0, GPIO::ELow); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
59 |
b->iIsLedOn = EFalse; |
0 | 60 |
} |
61 |
else |
|
62 |
{ |
|
54
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
63 |
GPIO::SetOutputState(KGPIO_LED0, GPIO::EHigh); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
64 |
b->iIsLedOn = ETrue; |
0 | 65 |
} |
54
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
66 |
b->iTimer.Again(NKern::TimerTicks(KBeatTimeInSeconds * 1000)); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
67 |
} |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
68 |
|
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
69 |
// the following macro is defined in led.mmp file.. |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
70 |
#ifdef USER_BUTTON_ENTERS_CRASH_DEBUGGER |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
71 |
static void UserButtonIsr(TAny* aPtr) |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
72 |
{ |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
73 |
//make sure the heartbeat led is OFF when we crash |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
74 |
GPIO::SetOutputState(KGPIO_LED0, GPIO::ELow); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
75 |
Kern::Printf("User button pressed, entering crash debugger..\n"); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
76 |
Kern::Fault("led.cpp", __LINE__); |
0 | 77 |
} |
78 |
||
54
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
79 |
TInt SetupUserButton() |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
80 |
{ |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
81 |
TInt r = GPIO::BindInterrupt(KGPIO_UserButton, UserButtonIsr, NULL); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
82 |
if(r != KErrNone) |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
83 |
{ |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
84 |
Kern::Printf("GPIO::BindInterrupt() failed for button %d, r=%d, (is in use?)", |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
85 |
KGPIO_UserButton, r); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
86 |
return r; |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
87 |
} |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
88 |
|
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
89 |
r = GPIO::SetInterruptTrigger(KGPIO_UserButton, GPIO::EEdgeRising); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
90 |
if(r == KErrNone) |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
91 |
{ |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
92 |
r = GPIO::SetPinDirection(KGPIO_UserButton, GPIO::EInput); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
93 |
if(r == KErrNone) |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
94 |
{ |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
95 |
GPIO::SetDebounceTime(KGPIO_UserButton, 500); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
96 |
GPIO::SetPinMode(KGPIO_UserButton, GPIO::EEnabled); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
97 |
r = GPIO::EnableInterrupt(KGPIO_UserButton); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
98 |
} |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
99 |
} |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
100 |
return r; |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
101 |
} |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
102 |
#endif |
0 | 103 |
|
104 |
DECLARE_STANDARD_EXTENSION() |
|
105 |
{ |
|
54
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
106 |
TInt r = KErrNoMemory; |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
107 |
LedHeartBeat* beat = new LedHeartBeat; |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
108 |
if(beat) |
0 | 109 |
{ |
54
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
110 |
r = beat->DoCreate(); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
111 |
} |
0 | 112 |
|
54
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
113 |
#ifdef USER_BUTTON_ENTERS_CRASH_DEBUGGER |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
114 |
if(r == KErrNone) |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
115 |
{ |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
116 |
r = SetupUserButton(); |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
117 |
} |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
118 |
#endif |
4dfcb6499328
Bug 3620 - Update for LED driver
Lukasz Forynski <lukasz.forynski@gmail.com>
parents:
0
diff
changeset
|
119 |
return r; |
0 | 120 |
} |
121 |