omap3530/beagle_drivers/led/led.cpp
changeset 0 6663340f3fc9
child 55 4dfcb6499328
equal deleted inserted replaced
-1:000000000000 0:6663340f3fc9
       
     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 //
       
    16 
       
    17 #include <kern_priv.h>
       
    18 #include <beagle/beagle_gpio.h>
       
    19 #include <assp/omap3530_assp/omap3530_gpio.h>
       
    20 #include <beagle/variant.h>
       
    21 #include <assp/omap3530_assp/omap3530_assp_priv.h>
       
    22 #include <assp/omap3530_assp/omap3530_irqmap.h> // GPIO interrupts
       
    23 
       
    24 #include <assp.h> // Required for definition of TIsr
       
    25 
       
    26 static NTimer * heartBeatTimer;
       
    27 
       
    28 
       
    29 
       
    30 static void ledIsr(TAny* aPtr)
       
    31 	{									
       
    32 	//make sure the led is always in the sma estate when we crash
       
    33 	
       
    34 	GPIO::SetOutputState(KGPIO_LED1, GPIO::ELow);
       
    35 	Kern::Fault("User invoked crash via keypad",KErrDied);
       
    36 	}
       
    37 
       
    38 static void beatLedHeartBeat(TAny * ptr)
       
    39 	{
       
    40 	GPIO::TGpioState ledState;
       
    41 	GPIO::GetOutputState(KGPIO_LED1, ledState);
       
    42 		
       
    43 	if(GPIO::EHigh == ledState)
       
    44 		{
       
    45 		GPIO::SetOutputState(KGPIO_LED1, GPIO::ELow);
       
    46 		}
       
    47 	else
       
    48 		{
       
    49 		GPIO::SetOutputState(KGPIO_LED1, GPIO::EHigh);
       
    50 		}
       
    51 	
       
    52 	heartBeatTimer->Again(Variant::GetMsTickPeriod());
       
    53 	}
       
    54 
       
    55 
       
    56 DECLARE_STANDARD_EXTENSION()
       
    57 	{
       
    58 		
       
    59 	//Set up the button to proivde a panic button invoking Fault()
       
    60 	if(KErrNone != GPIO::SetPinDirection(KGPIO_UserButton, GPIO::EInput))
       
    61 		return KErrArgument;
       
    62 		
       
    63 	GPIO::SetPinMode(KGPIO_UserButton, GPIO::EEnabled);
       
    64 	GPIO::SetDebounceTime(KGPIO_UserButton, 500);
       
    65 	
       
    66 	if(KErrNone !=GPIO::BindInterrupt(KGPIO_UserButton, ledIsr,NULL))
       
    67 		return KErrArgument;
       
    68 		
       
    69 	if(KErrNone !=GPIO::SetInterruptTrigger(KGPIO_UserButton, GPIO::EEdgeRising))
       
    70 		return KErrArgument;
       
    71 		
       
    72 	if(KErrNone !=GPIO::EnableInterrupt(KGPIO_UserButton))
       
    73 		{
       
    74 		GPIO::UnbindInterrupt(KGPIO_UserButton);
       
    75 		return KErrInUse;
       
    76 		}		
       
    77 
       
    78 	//setup the Led to flash at the system tick rate ( heartbeat) 
       
    79 	heartBeatTimer = new NTimer(beatLedHeartBeat,NULL);
       
    80 	
       
    81 	if(KErrNone != GPIO::SetPinDirection(KGPIO_LED1, GPIO::EOutput))
       
    82 			return KErrArgument;
       
    83 	
       
    84 	if(KErrNone != GPIO::SetPinDirection(KGPIO_LED0, GPIO::EOutput))
       
    85 				return KErrArgument;
       
    86 
       
    87 	GPIO::SetPinMode(KGPIO_LED0, GPIO::EEnabled);
       
    88 	GPIO::SetPinMode(KGPIO_LED1, GPIO::EEnabled);
       
    89 	GPIO::SetOutputState(KGPIO_LED0, GPIO::ELow);	
       
    90 	
       
    91 	heartBeatTimer->OneShot(Variant::GetMsTickPeriod(),ETrue);
       
    92 	return KErrNone;	
       
    93 	}
       
    94