kernel/eka/include/drivers/gpio.h
changeset 0 a41df078684a
child 90 947f0dc9f7a8
child 256 c1f20ce4abcf
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2008-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 // e32\include\drivers\gpio.h
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef __GPIO_H__
       
    19 #define __GPIO_H__
       
    20 
       
    21 class TGpioCallback;	//forward declaration
       
    22 
       
    23 /**
       
    24 @publishedPartner
       
    25 @prototype 9.6
       
    26 
       
    27 GPIO interrupt handler
       
    28 Takes a generic argument (TAny*)
       
    29 */
       
    30 typedef void (*TGpioIsr)(TAny*);
       
    31 
       
    32 /**
       
    33 @publishedPartner
       
    34 @prototype 9.6
       
    35 
       
    36 GPIO class handler
       
    37 */
       
    38 class GPIO
       
    39 	{
       
    40 public:
       
    41 	/**
       
    42 	GPIO pin modes (to be requested on any pin):
       
    43 	- enabled,
       
    44 	- disabled,
       
    45 	- idling
       
    46 	*/
       
    47 	enum TGpioMode
       
    48 		{
       
    49 		EEnabled,
       
    50 		EDisabled,
       
    51 		EIdle
       
    52 		};
       
    53 
       
    54 		/**
       
    55 	GPIO pin directions (to be requested on any pin):
       
    56 	- input,
       
    57 	- output,
       
    58 	- tristated
       
    59 	*/
       
    60 	enum TGpioDirection
       
    61 		{
       
    62 		EInput,
       
    63 		EOutput,
       
    64 		ETriStated
       
    65 		};
       
    66 
       
    67 	/**
       
    68 	GPIO pin states (to be set on an output or read from an input or output):
       
    69 	- electrical Low,
       
    70 	- electrical High,
       
    71 	- state compatible with idling the pin (module)
       
    72 	*/
       
    73 	enum TGpioState
       
    74 		{
       
    75 		ELow,
       
    76 		EHigh,
       
    77 		EIdleState
       
    78 		};
       
    79 
       
    80 	/**
       
    81 	GPIO programmable bias:
       
    82 	- no drive,
       
    83 	- pulled down (Low),
       
    84 	- pulled up (High)
       
    85 	*/
       
    86 	enum TGpioBias
       
    87 		{
       
    88 		ENoDrive,
       
    89 		EPullDown,
       
    90 		EPullUp
       
    91 		};
       
    92 
       
    93 	/**
       
    94 	GPIO interrupt and/or wakeup triger configuration (to be requested on an input
       
    95  						 that supports interrupts or wakeup function):
       
    96 	- Level triggered, low level,
       
    97 	- Level triggered, high level,
       
    98 	- Edge triggered, falling edge,
       
    99 	- Edge triggered, rising edge,
       
   100 	- Edge triggered, both edges,
       
   101 	*/
       
   102 	enum TGpioDetectionTrigger
       
   103 		{
       
   104 		ELevelLow,
       
   105 		ELevelHigh,
       
   106 		EEdgeFalling,
       
   107 		EEdgeRising,
       
   108 		EEdgeBoth
       
   109 		};
       
   110 
       
   111     /**
       
   112     Sets the pin mode.
       
   113     
       
   114     @param aId   The pin Id.
       
   115     @param aMode The pin mode.
       
   116 
       
   117     @return KErrNone, if successful; KErrArgument, if aId is invalid;
       
   118             KErrNotReady, when a pin that has requested to be Idle is not ready to do
       
   119  											     so;
       
   120             KErrNotSupported, if a pin cannot be used as a GPIO because it  has been
       
   121  							     assigned an alternative function.
       
   122 
       
   123 	When disabling a pin, the module which the pin is a part of may not be disabled,
       
   124  								but KErrNone is still returned.
       
   125     */
       
   126 	IMPORT_C static TInt SetPinMode(TInt aId, TGpioMode aMode);
       
   127 
       
   128     /**
       
   129     Reads the pin mode.
       
   130     
       
   131     @param aId   The pin Id.
       
   132     @param aMode On return contains the pin mode.
       
   133 
       
   134     @return KErrNone, if successful; KErrArgument, if aId is invalid;
       
   135             KErrNotSupported, if reading the pin mode is not supported.
       
   136     */
       
   137 	IMPORT_C static TInt GetPinMode(TInt aId, TGpioMode& aMode);
       
   138 
       
   139     /**
       
   140     Sets the pin direction.
       
   141     
       
   142     @param aId        The pin Id.
       
   143     @param aDirection The pin direction.
       
   144 
       
   145     @return KErrNone, if successful; KErrArgument, if aId is invalid;
       
   146             KErrNotSupported, if a pin cannot operate in the direction specified.
       
   147     */
       
   148 	IMPORT_C static TInt SetPinDirection(TInt aId, TGpioDirection aDirection);
       
   149 
       
   150     /**
       
   151     Reads the pin direction.
       
   152     
       
   153     @param aId        The pin Id.
       
   154     @param aDirection On return contains the pin direction.
       
   155 
       
   156     @return KErrNone, if successful; KErrArgument, if aId is invalid;
       
   157             KErrNotSupported, if reading the pin direction is not supported.
       
   158     */
       
   159 	IMPORT_C static TInt GetPinDirection(TInt aId, TGpioDirection& aDirection);
       
   160 
       
   161     /**
       
   162     Sets the bias on a pin.
       
   163     
       
   164     @param aId    The pin Id.
       
   165     @param aBias  The drive on the pin.
       
   166 
       
   167     @return KErrNone, if successful; KErrArgument, if aId is invalid;
       
   168 		   KErrNotSupported, if a pin does not support setting the drive.
       
   169     */
       
   170 	IMPORT_C static TInt SetPinBias(TInt aId, TGpioBias aBias);
       
   171 
       
   172     /**
       
   173     Reads the bias on a pin.
       
   174     
       
   175     @param aId    The pin Id.
       
   176     @param aBias  On return contains the bias previoulsy set on the pin (or the
       
   177  								   default bias if first time).
       
   178 
       
   179     @return KErrNone, if successful; 
       
   180             KErrArgument, if aId is invalid;
       
   181             KErrNotSupported, if reading the pin bias is not supported.
       
   182     */
       
   183 	IMPORT_C static TInt GetPinBias(TInt aId, TGpioBias& aBias);
       
   184 
       
   185 	/**
       
   186 	Sets the idle configuration and state. The pin configuration is the 
       
   187 	same that the pin should have when setting the mode to EIdle and the
       
   188 	state same it should present when setting the output state to EIdleState.
       
   189 
       
   190 	@param aId    The pin Id.
       
   191 	@param aConf  An implementation specific token specifying the idle
       
   192 				  configration and state.
       
   193 	
       
   194 	@return KErrNone, if successful; 
       
   195             KErrArgument, if aId is invalid;
       
   196             KErrNotSupported, if setting the pin idle configuration and state
       
   197 							  are not supported.
       
   198 	*/
       
   199 	IMPORT_C static TInt SetPinIdleConfigurationAndState(TInt aId, TInt aConf);
       
   200 
       
   201     /**
       
   202     Reads the pin idle configuration and state.
       
   203     
       
   204     @param aId    The pin Id.
       
   205     @param aConf  On return contains the idle configuration and state previoulsy
       
   206 				  set on the pin.
       
   207 
       
   208     @return KErrNone, if successful; 
       
   209             KErrArgument, if aId is invalid;
       
   210             KErrNotSupported, if reading the pin idle configuration and state
       
   211 							  is not supported.
       
   212     */
       
   213 	IMPORT_C static TInt GetPinIdleConfigurationAndState(TInt aId, TInt& aConf);
       
   214 
       
   215     /**
       
   216     Associates the specified interrupt service routine (ISR) function with the
       
   217     								specified interrupt Id.
       
   218     
       
   219     @param aId     The pin Id.
       
   220     @param anIsr   The address of the ISR function. 
       
   221     @param aPtr    32-bit value that is passed to the ISR.
       
   222                    This is designated a TAny* type as it is usually a pointer to the
       
   223                    owning class or data to be used in the ISR, although it can be any
       
   224                    32-bit value.
       
   225                  
       
   226     @return KErrNone, if successful;
       
   227             KErrArgument, if aId is invalid;
       
   228             KErrNotSupported if pin does not support interrupts;
       
   229             KErrInUse, if an ISR is already bound to this interrupt.
       
   230     */
       
   231 	IMPORT_C static TInt BindInterrupt(TInt aId, TGpioIsr aIsr, TAny* aPtr);
       
   232 
       
   233     /**
       
   234     Unbinds the interrupt service routine (ISR) function from the specified interrupt
       
   235     id.
       
   236     
       
   237     @param aId The pin Id.
       
   238     
       
   239     @return KErrNone, if successful; 
       
   240             KErrArgument, if aId is invalid;
       
   241             KErrNotSupported if pin does not support interrupts;
       
   242             KErrGeneral, if there is no ISR bound to this interrupt.
       
   243     */
       
   244 	IMPORT_C static TInt UnbindInterrupt(TInt aId);
       
   245 
       
   246     /**
       
   247     Enables the interrupt on specified pin.
       
   248     
       
   249     @param aId  The pin Id.
       
   250     
       
   251     @return KErrNone, if successful; 
       
   252             KErrArgument, if aId is invalid;
       
   253             KErrNotSupported if pin does not support interrupts;
       
   254             KErrGeneral, if there is no ISR bound to this interrupt.
       
   255     */
       
   256 	IMPORT_C static TInt EnableInterrupt(TInt aId);
       
   257 
       
   258     /**
       
   259     Disables the interrupt on specified pin.
       
   260     
       
   261     @param aId  The pin Id.
       
   262     
       
   263     @return KErrNone, if successful; 
       
   264             KErrArgument, if aId is invalid;
       
   265             KErrNotSupported if pin does not support interrupts;
       
   266             KErrGeneral, if there is no ISR bound to this interrupt.
       
   267     */
       
   268 	IMPORT_C static TInt DisableInterrupt(TInt aId);
       
   269 
       
   270     /**
       
   271     Checks if interrupt is enabled on pin.
       
   272     
       
   273     @param aId     The pin Id.
       
   274     @param aEnable On return contains the enable/disable state of interrupt 
       
   275  								       		 (TRUE=enabled).
       
   276     
       
   277     @return KErrNone, if successful; 
       
   278             KErrArgument, if aId is invalid;
       
   279             KErrNotSupported if pin does not support interrupts;
       
   280             KErrGeneral, if there is no ISR bound to this interrupt.
       
   281     */
       
   282 	IMPORT_C static TInt IsInterruptEnabled(TInt aId, TBool& aEnable);
       
   283 
       
   284     /**
       
   285     Clears any pending interrupt on the specified pin.
       
   286     
       
   287     @param aId The pin Id.
       
   288     
       
   289     @return KErrNone, if successful;
       
   290             KErrArgument, if aId is invalid;
       
   291             KErrNotSupported if clearing interrupt signal is not supported on this
       
   292  											    pin;
       
   293             KErrGeneral, if there is no ISR bound to this interrupt.
       
   294     */
       
   295 	IMPORT_C static TInt ClearInterrupt(TInt aId);
       
   296 
       
   297     /**
       
   298     Reads the interrupt state as output by the GPIO interrupt controller.
       
   299     
       
   300     @param aId     The pin Id.
       
   301     @param aActive On return contains the state of the interrupt signal as output by
       
   302  						      GPIO interrupt controller (TRUE=active).
       
   303 
       
   304     @return KErrNone, if successful;
       
   305             KErrArgument, if aId is invalid;
       
   306             KErrNotSupported if reading interrupt state is not supported;
       
   307             KErrGeneral, if there is no ISR bound to this interrupt.
       
   308     */
       
   309 	IMPORT_C static TInt GetMaskedInterruptState(TInt aId, TBool& aActive);
       
   310 
       
   311     /**
       
   312     Reads the interrupt state on the specified pin before any masking.
       
   313     
       
   314     @param aId     The pin Id.
       
   315     @param aActive On return contains state of the interrupt signal on the pin
       
   316  										  (TRUE=active).
       
   317 
       
   318     @return KErrNone, if successful;
       
   319             KErrArgument, if aId is invalid;
       
   320             KErrNotSupported if reading raw interrupt state is not supported;
       
   321             KErrGeneral, if there is no ISR bound to this interrupt.
       
   322     */
       
   323 	IMPORT_C static TInt GetRawInterruptState(TInt aId, TBool& aActive);
       
   324 
       
   325     /**
       
   326     Sets the interrupt trigger on the specified pin.
       
   327     
       
   328     @param aId      The pin Id.
       
   329     @param aTrigger The trigger type.
       
   330 
       
   331     @return KErrNone, if successful;
       
   332             KErrArgument, if aId is invalid;
       
   333             KErrNotSupported if pin does not support interrupts.
       
   334     */
       
   335 	IMPORT_C static TInt SetInterruptTrigger(TInt aId, TGpioDetectionTrigger aTrigger);
       
   336 
       
   337     /**
       
   338     Enables the wakeup on specified pin.
       
   339     
       
   340     @param aId  The pin Id.
       
   341     
       
   342     @return KErrNone, if successful;
       
   343             KErrArgument, if aId is invalid;
       
   344             KErrNotSupported if pin does not support wakeup.
       
   345     */
       
   346 	IMPORT_C static TInt EnableWakeup(TInt aId);
       
   347 
       
   348     /**
       
   349     Disables the wakeup on specified pin.
       
   350     
       
   351     @param aId  The pin Id.
       
   352     
       
   353     @return KErrNone, if successful;
       
   354             KErrArgument, if aId is invalid;
       
   355             KErrNotSupported if pin does not support wakeup.
       
   356     */
       
   357 	IMPORT_C static TInt DisableWakeup(TInt aId);
       
   358 
       
   359     /**
       
   360     Checks if wakeup is enabled on pin.
       
   361     
       
   362     @param aId     The pin Id.
       
   363     @param aEnable On return contains the enable/disable state of wakeup 
       
   364  								       		 (TRUE=enabled).
       
   365     
       
   366     @return KErrNone, if successful; 
       
   367             KErrArgument, if aId is invalid;
       
   368             KErrNotSupported if pin does not support wakeups;
       
   369     */
       
   370 	IMPORT_C static TInt IsWakeupEnabled(TInt aId, TBool& aEnable);
       
   371 
       
   372     /**
       
   373     Sets the wakeup trigger on the specified pin.
       
   374     
       
   375     @param aId      The pin Id.
       
   376     @param aTrigger The trigger type.
       
   377 
       
   378     @return KErrNone, if successful;
       
   379             KErrArgument, if aId is invalid;
       
   380             KErrNotSupported if pin does not support wakeup.
       
   381     */
       
   382 	IMPORT_C static TInt SetWakeupTrigger(TInt aId, TGpioDetectionTrigger aTrigger);
       
   383 
       
   384     /**
       
   385     Sets the debouncing time on the specified pin.
       
   386     
       
   387     @param aId    The pin Id.
       
   388     @param aTime  The debouncing time in microseconds.
       
   389 
       
   390     @return KErrNone, if the time is succesfully changed or no change is needed (see
       
   391                                                 			         below);
       
   392             KErrArgument, if aId is invalid;
       
   393             KErrNotSupported if pin does not support debouncing.
       
   394 
       
   395     If the requested time is greater than the common value for the module, the latter
       
   396     is increased to the value requested.
       
   397     If the requested time is lesser than the common value for the module then the
       
   398     common value is unchanged, unless it is set to the value requested on this pin.
       
   399     */
       
   400 	IMPORT_C static TInt SetDebounceTime(TInt aId, TInt aTime);
       
   401 
       
   402     /**
       
   403     Reads the debouncing time on the specified pin.
       
   404     
       
   405     @param aId    The pin Id.
       
   406     @param aTime  On return contains the debouncing time in microseconds.
       
   407 
       
   408     @return KErrNone, if successful;
       
   409             KErrArgument, if aId is invalid;
       
   410             KErrNotSupported if pin does not support debouncing.
       
   411     */
       
   412 	IMPORT_C static TInt GetDebounceTime(TInt aId, TInt& aTime);
       
   413 
       
   414     /**
       
   415     Reads the state of an input (synchronously).
       
   416     
       
   417     @param aId    The pin Id.
       
   418     @param aState On return contains the pin state.
       
   419 
       
   420     @return KErrNone, if successful;
       
   421             KErrArgument, if aId is invalid.
       
   422             KErrNotSupported, if reading the state synchronously is not supported.
       
   423     */
       
   424 	IMPORT_C static TInt GetInputState(TInt aId, TGpioState& aState);
       
   425 
       
   426     /**
       
   427     Sets the output pin to one of the supported states (synchronously).
       
   428     
       
   429     @param aId    The pin Id.
       
   430     @param aState The pin state.
       
   431 
       
   432     @return KErrNone, if successful;
       
   433 			KErrArgument, if aId is invalid;
       
   434             KErrNotSupported, if the state is not supported or if setting its state synchronously is not supported.
       
   435     */
       
   436 	IMPORT_C static TInt SetOutputState(TInt aId, TGpioState aState);
       
   437 
       
   438     /**
       
   439     Reads the output pin states (synchronously).
       
   440     
       
   441     @param aId    The pin Id.
       
   442     @param aState On return contains the pin state. On systems where the state of an
       
   443  			 ouptut pin cannot be read directly from hardware, or takes a non
       
   444 			 negligible time to be retrieved, the implementation must cache it.
       
   445 
       
   446     @return KErrNone, if successful; 
       
   447             KErrArgument, if aId is invalid.
       
   448     */
       
   449 	IMPORT_C static TInt GetOutputState(TInt aId, TGpioState& aState);
       
   450 
       
   451     /**
       
   452     Reads the state of an input (asynchronously).
       
   453     
       
   454     @param aId    The pin Id.
       
   455     @param aCb    A pointer to a GPIO callback object.
       
   456 
       
   457     @return KErrNone, if accepted;
       
   458             KErrArgument, if aId is invalid.
       
   459             KErrNotSupported, if reading the state asynchronously is not supported.
       
   460 
       
   461 	This API should be used with off-chip GPIO modules only;
       
   462 	The result of the read operation and the state of the input pin will be passed as an argument to the callback function;
       
   463     */
       
   464 	IMPORT_C static TInt GetInputState(TInt aId, TGpioCallback* aCb);
       
   465 
       
   466     /**
       
   467     Sets the output pin to one of the supported states (asynchronously).
       
   468     
       
   469     @param aId    The pin Id.
       
   470     @param aState The pin state.
       
   471     @param aCb    A pointer to a GPIO callback object.
       
   472 
       
   473     @return KErrNone, if accepted;
       
   474 			KErrArgument, if aId is invalid;
       
   475             KErrNotSupported, if setting its state asynchronously is not supported.
       
   476 
       
   477     This API should be used with off-chip GPIO modules only;
       
   478 	The result of the set operation will be passed as an argument to the callback function;
       
   479     */
       
   480 	IMPORT_C static TInt SetOutputState(TInt aId, TGpioState aState, TGpioCallback* aCb);
       
   481 
       
   482 	/**
       
   483     Allows the platform specific implementation to extend the API.
       
   484 
       
   485     @param aId        The pin Id.
       
   486 	@param aCmd       A PSL extension function id.
       
   487 	@param aArg1      An argument to be passed to the PSL extension function.
       
   488 	@param aArg2      An argument to be passed to the PSL extension function.
       
   489 
       
   490     @return KErrNone, if accepted;
       
   491 			KErrArgument, if aId is invalid;
       
   492             KErrNotSupported, if static extensions are not supported.
       
   493 			Any other system wide error code.
       
   494     */
       
   495 	IMPORT_C static TInt StaticExtension(TInt aId, TInt aCmd, TAny* aArg1, TAny* aArg2);
       
   496 	};
       
   497 
       
   498 /**
       
   499 @publishedPartner
       
   500 @prototype 9.6
       
   501 
       
   502 GPIO asynchronous callback function
       
   503 */
       
   504 typedef void (*TGpioCbFn)(TInt				/*aPinId*/,
       
   505 						  GPIO::TGpioState	/*aState*/,
       
   506                           TInt				/*aResult*/,
       
   507                           TAny*				/*aParam*/);
       
   508 /**
       
   509 @publishedPartner
       
   510 @prototype 9.6
       
   511 
       
   512 GPIO asynchronous callback DFC
       
   513 The client must create one of these to be passed to each asynchronous call to GetInputState and SetOutputState
       
   514 The callback function is called in the context supplied by the client when creating an object of this kind (aQue)
       
   515 The callback function takes as arguments the pin id and the state, so it can be common to all TGpioCallback
       
   516 */
       
   517 class TGpioCallback : public TDfc
       
   518 	{
       
   519 public:
       
   520 	inline TGpioCallback(TGpioCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority) : TDfc(DfcFunc, this, aQue, aPriority), iParam(aPtr), iCallback(aFn) 
       
   521 			{}
       
   522 private:
       
   523     inline static void DfcFunc(TAny* aPtr)
       
   524         {
       
   525         TGpioCallback* pCb = (TGpioCallback*) aPtr;
       
   526         pCb->iCallback(pCb->iPinId, pCb->iState, pCb->iResult, pCb->iParam);
       
   527         }
       
   528 public:
       
   529 	TInt iPinId;		// the Id of the pin on which the asynchronous operation is performed
       
   530 	GPIO::TGpioState iState;	// either the state the output pin should be moved to or the state the input pin is at
       
   531 	TInt iResult;		// the result of this transaction as a system wide error
       
   532 	TAny* iParam;
       
   533 	TGpioCbFn iCallback;
       
   534 	};
       
   535 
       
   536 #endif /*__GPIO_H__*/
       
   537