Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
17 #include <kernel/kern_priv.h>
18 #include <template_assp.h>
19 #include <drivers/gpio.h>
21 const TInt32 KHwGpioPinMax = 0; // TO DO: max pin number this GPIO chip supports
22 const TInt32 KIntIdGpio = 0; // TO DO: need to define which interrupt the GPIO chip is attached to
25 // TO DO: if the GPIO chip doesn't support specific features
26 // such as debouncing or pin modes, then it may be
27 // necessary to store them ourselves in an array of GpioPins
28 // other features such as pin bias or idle configurations
29 // may be left as KErrNotSupported
34 TGpioIsr iIsr; // e.g. we may want to remeber the isr attached to a pin
35 TAny * iPtr; // argument to pass to isr
38 static GpioPin GpioPins[KHwGpioPinMax+1];
40 static TInt32 GpioInterruptId; // place to store interrupt handle returned from Interrupt::Bind()
43 GPIO interrupt handler
44 generic argument (TAny*) is a pointer to the GpioPins array
46 void GpioIsrDispatch(TAny *aPtr)
48 // TO DO: work out which pins have interrupts pending
49 // and dispatch the appropriate ISR
50 GpioPin *pins = (GpioPin *)aPtr;
51 TUint32 interrupt = 0xff; // TO DO: read gpio pending interupts
52 TUint32 enabled = 0x00; // TO DO: read gpio enabled interupts
53 TUint32 masked = interrupt & enabled; // TO DO: read masked interrupts
55 // check each pin and dispatch ISR if necessary
56 for (TInt i = 0; i <= KHwGpioPinMax; i++)
58 if ((masked & 0x1) && (pins[i].iIsr != NULL))
60 // we have a pending interrupt and a registered ISR
61 (*pins[i].iIsr)(pins[i].iPtr); // dispatch this pin's ISR
65 Interrupt::Clear(GpioInterruptId);
69 EXPORT_C TInt GPIO::SetPinMode
75 if (aId < 0 || aId > KHwGpioPinMax)
79 // TO DO: store pin mode and return
83 EXPORT_C TInt GPIO::GetPinMode
89 if (aId < 0 || aId > KHwGpioPinMax)
93 // TO DO: set aMode = pin mode
97 EXPORT_C TInt GPIO::SetPinDirection
100 TGpioDirection aDirection
103 if (aId < 0 || aId > KHwGpioPinMax || aDirection == ETriStated)
107 // TO DO: if we support setting the pin direction then do it here
111 EXPORT_C TInt GPIO::GetPinDirection
114 TGpioDirection & aDirection
117 if (aId < 0 || aId > KHwGpioPinMax)
121 // TO DO: if we support getting the pin direction then do it here
125 EXPORT_C TInt GPIO::SetPinBias
131 if (aId < 0 || aId > KHwGpioPinMax)
135 // TO DO: if we support setting the pin bias then do it here
139 EXPORT_C TInt GPIO::GetPinBias
145 if (aId < 0 || aId > KHwGpioPinMax)
149 // TO DO: if we support getting the pin bias then do it here
153 EXPORT_C TInt GPIO::SetPinIdleConfigurationAndState
159 if (aId < 0 || aId > KHwGpioPinMax)
163 // TO DO: if we support setting the pin idle config then do it here
167 EXPORT_C TInt GPIO::GetPinIdleConfigurationAndState
173 if (aId < 0 || aId > KHwGpioPinMax)
177 // TO DO: if we support getting the pin idle config then do it here
181 EXPORT_C TInt GPIO::BindInterrupt
188 if (aId < 0 || aId > KHwGpioPinMax || aIsr == NULL)
192 if (GpioPins[aId].iIsr != NULL)
197 // record isr and arg bound to this pin
198 GpioPins[aId].iIsr = aIsr;
199 GpioPins[aId].iPtr = aPtr;
203 EXPORT_C TInt GPIO::UnbindInterrupt
208 if (aId < 0 || aId > KHwGpioPinMax)
212 if (GpioPins[aId].iIsr == NULL)
217 // NULL isr bound to this pin
218 GpioPins[aId].iIsr = NULL;
219 GpioPins[aId].iPtr = NULL;
223 EXPORT_C TInt GPIO::EnableInterrupt
228 if (aId < 0 || aId > KHwGpioPinMax)
232 if (GpioPins[aId].iIsr == NULL)
237 // TODO: enable interrupts on this pin
241 EXPORT_C TInt GPIO::DisableInterrupt
246 if (aId < 0 || aId > KHwGpioPinMax)
250 if (GpioPins[aId].iIsr == NULL)
255 // TODO: disable interrupts on this pin
259 EXPORT_C TInt GPIO::IsInterruptEnabled
265 if (aId < 0 || aId > KHwGpioPinMax)
269 if (GpioPins[aId].iIsr == NULL)
274 // TO DO: are interrupts enabled on this pin ?
278 EXPORT_C TInt GPIO::ClearInterrupt
283 if (aId < 0 || aId > KHwGpioPinMax)
287 if (GpioPins[aId].iIsr == NULL)
292 // TO DO: clear pin interrupt status
296 EXPORT_C TInt GPIO::GetMaskedInterruptState
302 if (aId < 0 || aId > KHwGpioPinMax)
306 // TO DO: set aActive to masked interrupt state
310 EXPORT_C TInt GPIO::GetRawInterruptState
316 if (aId < 0 || aId > KHwGpioPinMax)
320 // TO DO: set aActive to raw (unmasked) interrupt state
324 EXPORT_C TInt GPIO::SetInterruptTrigger
327 TGpioDetectionTrigger aTrigger
330 if (aId < 0 || aId > KHwGpioPinMax)
334 // TO DO: set interrupt trigger on this pin
338 EXPORT_C TInt GPIO::EnableWakeup
343 if (aId < 0 || aId > KHwGpioPinMax)
347 // TO DO: enable wakeup on this pin
351 EXPORT_C TInt GPIO::DisableWakeup
356 if (aId < 0 || aId > KHwGpioPinMax)
360 // TO DO: disable wakeup on this pin
364 EXPORT_C TInt GPIO::IsWakeupEnabled
370 if (aId < 0 || aId > KHwGpioPinMax)
374 // TO DO: set aEnable wakeup state for this pin
378 EXPORT_C TInt GPIO::SetWakeupTrigger
381 TGpioDetectionTrigger aTrigger
384 if (aId < 0 || aId > KHwGpioPinMax)
388 // TO DO: set wakeup trigger on this pin
392 EXPORT_C TInt GPIO::SetDebounceTime
398 if (aId < 0 || aId > KHwGpioPinMax)
402 // TO DO: set debounce time for this pin
403 // it may be necessary to emulate debouncing ourselves
407 EXPORT_C TInt GPIO::GetDebounceTime
413 if (aId < 0 || aId > KHwGpioPinMax)
417 // TO DO: get debounce time for this pin
421 EXPORT_C TInt GPIO::GetInputState
427 if (aId < 0 || aId > KHwGpioPinMax)
431 // TO DO: read the input state of this pin
432 // if debouncing is handled by the driver here
433 // is where we will need to work out what the
434 // debounced state is
439 EXPORT_C TInt GPIO::SetOutputState
445 if (aId < 0 || aId > KHwGpioPinMax)
449 // TO DO: set the output state of this pin
453 EXPORT_C TInt GPIO::GetOutputState
459 if (aId < 0 || aId > KHwGpioPinMax)
463 // TO DO: get the output state of this pin
467 EXPORT_C TInt GPIO::GetInputState
473 if (aId < 0 || aId > KHwGpioPinMax)
477 // TO DO: get the input state of this pin
481 EXPORT_C TInt GPIO::SetOutputState
488 if (aId < 0 || aId > KHwGpioPinMax)
492 // TO DO: set the ouput state of this pin
496 EXPORT_C TInt GPIO::StaticExtension
504 if (aId < 0 || aId > KHwGpioPinMax)
508 // TO DO: call the appropriate static extension if supported
509 return KErrNotSupported;
514 // entry point for GPIO setup
516 DECLARE_STANDARD_EXTENSION()
519 // initialise GPIO pins array (if necessary)
520 for (TInt32 i = 0; i <= KHwGpioPinMax; i++)
522 GpioPins[i].iIsr = NULL;
523 GpioPins[i].iPtr = NULL;
525 // bind and enable GPIO Isr
526 // NB Interrupt::Bind() now returns a handle (-ve value means an error)
527 TInt r = Interrupt::Bind(KIntIdGpio, GpioIsrDispatch, &GpioPins[0]);
534 // NB Interrupt::Enable() now expects the handle return from Bind
535 r = Interrupt::Enable(r);