1 // Copyright (c) 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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 class TGpioCallback; //forward declaration
22 GPIO interrupt handler
23 Takes a generic argument (TAny*)
25 typedef void (*TGpioIsr)(TAny*);
31 GPIO pin modes (to be requested on any pin):
44 GPIO pin directions (to be requested on any pin):
57 GPIO pin states (to be set on an output or read from an input or output):
60 - state compatible with idling the pin (module)
70 GPIO programmable bias:
83 GPIO interrupt and/or wakeup triger configuration (to be requested on an input
84 that supports interrupts or wakeup function):
85 - Level triggered, low level,
86 - Level triggered, high level,
87 - Edge triggered, falling edge,
88 - Edge triggered, rising edge,
89 - Edge triggered, both edges,
91 enum TGpioDetectionTrigger
103 @param aId The pin Id.
104 @param aMode The pin mode.
106 @return KErrNone, if successful; KErrArgument, if aId is invalid;
107 KErrNotReady, when a pin that has requested to be Idle is not ready to do
109 KErrNotSupported, if a pin cannot be used as a GPIO because it has been
110 assigned an alternative function.
112 When disabling a pin, the module which the pin is a part of may not be disabled,
113 but KErrNone is still returned.
115 IMPORT_C static TInt SetPinMode(TInt aId, TGpioMode aMode);
120 @param aId The pin Id.
121 @param aMode On return contains the pin mode.
123 @return KErrNone, if successful; KErrArgument, if aId is invalid;
124 KErrNotSupported, if reading the pin mode is not supported.
126 IMPORT_C static TInt GetPinMode(TInt aId, TGpioMode& aMode);
129 Sets the pin direction.
131 @param aId The pin Id.
132 @param aDirection The pin direction.
134 @return KErrNone, if successful; KErrArgument, if aId is invalid;
135 KErrNotSupported, if a pin cannot operate in the direction specified.
137 IMPORT_C static TInt SetPinDirection(TInt aId, TGpioDirection aDirection);
140 Reads the pin direction.
142 @param aId The pin Id.
143 @param aDirection On return contains the pin direction.
145 @return KErrNone, if successful; KErrArgument, if aId is invalid;
146 KErrNotSupported, if reading the pin direction is not supported.
148 IMPORT_C static TInt GetPinDirection(TInt aId, TGpioDirection& aDirection);
151 Sets the bias on a pin.
153 @param aId The pin Id.
154 @param aBias The drive on the pin.
156 @return KErrNone, if successful; KErrArgument, if aId is invalid;
157 KErrNotSupported, if a pin does not support setting the drive.
159 IMPORT_C static TInt SetPinBias(TInt aId, TGpioBias aBias);
162 Reads the bias on a pin.
164 @param aId The pin Id.
165 @param aBias On return contains the bias previoulsy set on the pin (or the
166 default bias if first time).
168 @return KErrNone, if successful;
169 KErrArgument, if aId is invalid;
170 KErrNotSupported, if reading the pin bias is not supported.
172 IMPORT_C static TInt GetPinBias(TInt aId, TGpioBias& aBias);
175 Sets the idle configuration and state. The pin configuration is the
176 same that the pin should have when setting the mode to EIdle and the
177 state same it should present when setting the output state to EIdleState.
179 @param aId The pin Id.
180 @param aConf An implementation specific token specifying the idle
181 configration and state.
183 @return KErrNone, if successful;
184 KErrArgument, if aId is invalid;
185 KErrNotSupported, if setting the pin idle configuration and state
188 IMPORT_C static TInt SetPinIdleConfigurationAndState(TInt aId, TInt aConf);
191 Reads the pin idle configuration and state.
193 @param aId The pin Id.
194 @param aConf On return contains the idle configuration and state previoulsy
197 @return KErrNone, if successful;
198 KErrArgument, if aId is invalid;
199 KErrNotSupported, if reading the pin idle configuration and state
202 IMPORT_C static TInt GetPinIdleConfigurationAndState(TInt aId, TInt& aConf);
205 Associates the specified interrupt service routine (ISR) function with the
206 specified interrupt Id.
208 @param aId The pin Id.
209 @param anIsr The address of the ISR function.
210 @param aPtr 32-bit value that is passed to the ISR.
211 This is designated a TAny* type as it is usually a pointer to the
212 owning class or data to be used in the ISR, although it can be any
215 @return KErrNone, if successful;
216 KErrArgument, if aId is invalid;
217 KErrNotSupported if pin does not support interrupts;
218 KErrInUse, if an ISR is already bound to this interrupt.
220 IMPORT_C static TInt BindInterrupt(TInt aId, TGpioIsr aIsr, TAny* aPtr);
223 Unbinds the interrupt service routine (ISR) function from the specified interrupt
226 @param aId The pin Id.
228 @return KErrNone, if successful;
229 KErrArgument, if aId is invalid;
230 KErrNotSupported if pin does not support interrupts;
231 KErrGeneral, if there is no ISR bound to this interrupt.
233 IMPORT_C static TInt UnbindInterrupt(TInt aId);
236 Enables the interrupt on specified pin.
238 @param aId The pin Id.
240 @return KErrNone, if successful;
241 KErrArgument, if aId is invalid;
242 KErrNotSupported if pin does not support interrupts;
243 KErrGeneral, if there is no ISR bound to this interrupt.
245 IMPORT_C static TInt EnableInterrupt(TInt aId);
248 Disables the interrupt on specified pin.
250 @param aId The pin Id.
252 @return KErrNone, if successful;
253 KErrArgument, if aId is invalid;
254 KErrNotSupported if pin does not support interrupts;
255 KErrGeneral, if there is no ISR bound to this interrupt.
257 IMPORT_C static TInt DisableInterrupt(TInt aId);
260 Checks if interrupt is enabled on pin.
262 @param aId The pin Id.
263 @param aEnable On return contains the enable/disable state of interrupt
266 @return KErrNone, if successful;
267 KErrArgument, if aId is invalid;
268 KErrNotSupported if pin does not support interrupts;
269 KErrGeneral, if there is no ISR bound to this interrupt.
271 IMPORT_C static TInt IsInterruptEnabled(TInt aId, TBool& aEnable);
274 Clears any pending interrupt on the specified pin.
276 @param aId The pin Id.
278 @return KErrNone, if successful;
279 KErrArgument, if aId is invalid;
280 KErrNotSupported if clearing interrupt signal is not supported on this
282 KErrGeneral, if there is no ISR bound to this interrupt.
284 IMPORT_C static TInt ClearInterrupt(TInt aId);
287 Reads the interrupt state as output by the GPIO interrupt controller.
289 @param aId The pin Id.
290 @param aActive On return contains the state of the interrupt signal as output by
291 GPIO interrupt controller (TRUE=active).
293 @return KErrNone, if successful;
294 KErrArgument, if aId is invalid;
295 KErrNotSupported if reading interrupt state is not supported;
296 KErrGeneral, if there is no ISR bound to this interrupt.
298 IMPORT_C static TInt GetMaskedInterruptState(TInt aId, TBool& aActive);
301 Reads the interrupt state on the specified pin before any masking.
303 @param aId The pin Id.
304 @param aActive On return contains state of the interrupt signal on the pin
307 @return KErrNone, if successful;
308 KErrArgument, if aId is invalid;
309 KErrNotSupported if reading raw interrupt state is not supported;
310 KErrGeneral, if there is no ISR bound to this interrupt.
312 IMPORT_C static TInt GetRawInterruptState(TInt aId, TBool& aActive);
315 Sets the interrupt trigger on the specified pin.
317 @param aId The pin Id.
318 @param aTrigger The trigger type.
320 @return KErrNone, if successful;
321 KErrArgument, if aId is invalid;
322 KErrNotSupported if pin does not support interrupts.
324 IMPORT_C static TInt SetInterruptTrigger(TInt aId, TGpioDetectionTrigger aTrigger);
327 Enables the wakeup on specified pin.
329 @param aId The pin Id.
331 @return KErrNone, if successful;
332 KErrArgument, if aId is invalid;
333 KErrNotSupported if pin does not support wakeup.
335 IMPORT_C static TInt EnableWakeup(TInt aId);
338 Disables the wakeup on specified pin.
340 @param aId The pin Id.
342 @return KErrNone, if successful;
343 KErrArgument, if aId is invalid;
344 KErrNotSupported if pin does not support wakeup.
346 IMPORT_C static TInt DisableWakeup(TInt aId);
349 Checks if wakeup is enabled on pin.
351 @param aId The pin Id.
352 @param aEnable On return contains the enable/disable state of wakeup
355 @return KErrNone, if successful;
356 KErrArgument, if aId is invalid;
357 KErrNotSupported if pin does not support wakeups;
359 IMPORT_C static TInt IsWakeupEnabled(TInt aId, TBool& aEnable);
362 Sets the wakeup trigger on the specified pin.
364 @param aId The pin Id.
365 @param aTrigger The trigger type.
367 @return KErrNone, if successful;
368 KErrArgument, if aId is invalid;
369 KErrNotSupported if pin does not support wakeup.
371 IMPORT_C static TInt SetWakeupTrigger(TInt aId, TGpioDetectionTrigger aTrigger);
374 Sets the debouncing time on the specified pin.
376 @param aId The pin Id.
377 @param aTime The debouncing time in microseconds.
379 @return KErrNone, if the time is succesfully changed or no change is needed (see
381 KErrArgument, if aId is invalid;
382 KErrNotSupported if pin does not support debouncing.
384 If the requested time is greater than the common value for the module, the latter
385 is increased to the value requested.
386 If the requested time is lesser than the common value for the module then the
387 common value is unchanged, unless it is set to the value requested on this pin.
389 IMPORT_C static TInt SetDebounceTime(TInt aId, TInt aTime);
392 Reads the debouncing time on the specified pin.
394 @param aId The pin Id.
395 @param aTime On return contains the debouncing time in microseconds.
397 @return KErrNone, if successful;
398 KErrArgument, if aId is invalid;
399 KErrNotSupported if pin does not support debouncing.
401 IMPORT_C static TInt GetDebounceTime(TInt aId, TInt& aTime);
404 Reads the state of an input (synchronously).
406 @param aId The pin Id.
407 @param aState On return contains the pin state.
409 @return KErrNone, if successful;
410 KErrArgument, if aId is invalid.
411 KErrNotSupported, if reading the state synchronously is not supported.
413 IMPORT_C static TInt GetInputState(TInt aId, TGpioState& aState);
416 Sets the output pin to one of the supported states (synchronously).
418 @param aId The pin Id.
419 @param aState The pin state.
421 @return KErrNone, if successful;
422 KErrArgument, if aId is invalid;
423 KErrNotSupported, if the state is not supported or if setting its state synchronously is not supported.
425 IMPORT_C static TInt SetOutputState(TInt aId, TGpioState aState);
428 Reads the output pin states (synchronously).
430 @param aId The pin Id.
431 @param aState On return contains the pin state. On systems where the state of an
432 ouptut pin cannot be read directly from hardware, or takes a non
433 negligible time to be retrieved, the implementation must cache it.
435 @return KErrNone, if successful;
436 KErrArgument, if aId is invalid.
438 IMPORT_C static TInt GetOutputState(TInt aId, TGpioState& aState);
441 Reads the state of an input (asynchronously).
443 @param aId The pin Id.
444 @param aCb A pointer to a GPIO callback object.
446 @return KErrNone, if accepted;
447 KErrArgument, if aId is invalid.
448 KErrNotSupported, if reading the state asynchronously is not supported.
450 This API should be used with off-chip GPIO modules only;
451 The result of the read operation and the state of the input pin will be passed as an argument to the callback function;
453 IMPORT_C static TInt GetInputState(TInt aId, TGpioCallback* aCb);
456 Sets the output pin to one of the supported states (asynchronously).
458 @param aId The pin Id.
459 @param aState The pin state.
460 @param aCb A pointer to a GPIO callback object.
462 @return KErrNone, if accepted;
463 KErrArgument, if aId is invalid;
464 KErrNotSupported, if setting its state asynchronously is not supported.
466 This API should be used with off-chip GPIO modules only;
467 The result of the set operation will be passed as an argument to the callback function;
469 IMPORT_C static TInt SetOutputState(TInt aId, TGpioState aState, TGpioCallback* aCb);
472 Allows the platform specific implementation to extend the API.
474 @param aId The pin Id.
475 @param aCmd A PSL extension function id.
476 @param aArg1 An argument to be passed to the PSL extension function.
477 @param aArg2 An argument to be passed to the PSL extension function.
479 @return KErrNone, if accepted;
480 KErrArgument, if aId is invalid;
481 KErrNotSupported, if static extensions are not supported.
482 Any other system wide error code.
484 IMPORT_C static TInt StaticExtension(TInt aId, TInt aCmd, TAny* aArg1, TAny* aArg2);
488 GPIO asynchronous callback function
490 typedef void (*TGpioCbFn)(TInt /*aPinId*/,
491 GPIO::TGpioState /*aState*/,
495 GPIO asynchronous callback DFC
496 The client must create one of these to be passed to each asynchronous call to GetInputState and SetOutputState
497 The callback function is called in the context supplied by the client when creating an object of this kind (aQue)
498 The callback function takes as arguments the pin id and the state, so it can be common to all TGpioCallback
500 class TGpioCallback : public TDfc
503 inline TGpioCallback(TGpioCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority) : TDfc(DfcFunc, this, aQue, aPriority), iParam(aPtr), iCallback(aFn)
506 inline static void DfcFunc(TAny* aPtr)
508 TGpioCallback* pCb = (TGpioCallback*) aPtr;
509 pCb->iCallback(pCb->iPinId, pCb->iState, pCb->iResult, pCb->iParam);
512 TInt iPinId; // the Id of the pin on which the asynchronous operation is performed
513 GPIO::TGpioState iState; // either the state the output pin should be moved to or the state the input pin is at
514 TInt iResult; // the result of this transaction as a system wide error