omap3530/omap3530_drivers/gpio/gpio.h
changeset 0 6663340f3fc9
equal deleted inserted replaced
-1:000000000000 0:6663340f3fc9
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __GPIO_H__
       
    17 #define __GPIO_H__
       
    18 
       
    19 class TGpioCallback;	//forward declaration
       
    20 
       
    21 /**
       
    22 GPIO interrupt handler
       
    23 Takes a generic argument (TAny*)
       
    24 */
       
    25 typedef void (*TGpioIsr)(TAny*);
       
    26 
       
    27 class GPIO
       
    28 	{
       
    29 public:
       
    30 	/**
       
    31 	GPIO pin modes (to be requested on any pin):
       
    32 	- enabled,
       
    33 	- disabled,
       
    34 	- idling
       
    35 	*/
       
    36 	enum TGpioMode
       
    37 		{
       
    38 		EEnabled,
       
    39 		EDisabled,
       
    40 		EIdle
       
    41 		};
       
    42 
       
    43 		/**
       
    44 	GPIO pin directions (to be requested on any pin):
       
    45 	- input,
       
    46 	- output,
       
    47 	- tristated
       
    48 	*/
       
    49 	enum TGpioDirection
       
    50 		{
       
    51 		EInput,
       
    52 		EOutput,
       
    53 		ETriStated
       
    54 		};
       
    55 
       
    56 	/**
       
    57 	GPIO pin states (to be set on an output or read from an input or output):
       
    58 	- electrical Low,
       
    59 	- electrical High,
       
    60 	- state compatible with idling the pin (module)
       
    61 	*/
       
    62 	enum TGpioState
       
    63 		{
       
    64 		ELow,
       
    65 		EHigh,
       
    66 		EIdleState
       
    67 		};
       
    68 
       
    69 	/**
       
    70 	GPIO programmable bias:
       
    71 	- no drive,
       
    72 	- pulled down (Low),
       
    73 	- pulled up (High)
       
    74 	*/
       
    75 	enum TGpioBias
       
    76 		{
       
    77 		ENoDrive,
       
    78 		EPullDown,
       
    79 		EPullUp
       
    80 		};
       
    81 
       
    82 	/**
       
    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,
       
    90 	*/
       
    91 	enum TGpioDetectionTrigger
       
    92 		{
       
    93 		ELevelLow,
       
    94 		ELevelHigh,
       
    95 		EEdgeFalling,
       
    96 		EEdgeRising,
       
    97 		EEdgeBoth
       
    98 		};
       
    99 
       
   100     /**
       
   101     Sets the pin mode.
       
   102     
       
   103     @param aId   The pin Id.
       
   104     @param aMode The pin mode.
       
   105 
       
   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
       
   108  											     so;
       
   109             KErrNotSupported, if a pin cannot be used as a GPIO because it  has been
       
   110  							     assigned an alternative function.
       
   111 
       
   112 	When disabling a pin, the module which the pin is a part of may not be disabled,
       
   113  								but KErrNone is still returned.
       
   114     */
       
   115 	IMPORT_C static TInt SetPinMode(TInt aId, TGpioMode aMode);
       
   116 
       
   117     /**
       
   118     Reads the pin mode.
       
   119     
       
   120     @param aId   The pin Id.
       
   121     @param aMode On return contains the pin mode.
       
   122 
       
   123     @return KErrNone, if successful; KErrArgument, if aId is invalid;
       
   124             KErrNotSupported, if reading the pin mode is not supported.
       
   125     */
       
   126 	IMPORT_C static TInt GetPinMode(TInt aId, TGpioMode& aMode);
       
   127 
       
   128     /**
       
   129     Sets the pin direction.
       
   130     
       
   131     @param aId        The pin Id.
       
   132     @param aDirection The pin direction.
       
   133 
       
   134     @return KErrNone, if successful; KErrArgument, if aId is invalid;
       
   135             KErrNotSupported, if a pin cannot operate in the direction specified.
       
   136     */
       
   137 	IMPORT_C static TInt SetPinDirection(TInt aId, TGpioDirection aDirection);
       
   138 
       
   139     /**
       
   140     Reads the pin direction.
       
   141     
       
   142     @param aId        The pin Id.
       
   143     @param aDirection On return contains the pin direction.
       
   144 
       
   145     @return KErrNone, if successful; KErrArgument, if aId is invalid;
       
   146             KErrNotSupported, if reading the pin direction is not supported.
       
   147     */
       
   148 	IMPORT_C static TInt GetPinDirection(TInt aId, TGpioDirection& aDirection);
       
   149 
       
   150     /**
       
   151     Sets the bias on a pin.
       
   152     
       
   153     @param aId    The pin Id.
       
   154     @param aBias  The drive on the pin.
       
   155 
       
   156     @return KErrNone, if successful; KErrArgument, if aId is invalid;
       
   157 		   KErrNotSupported, if a pin does not support setting the drive.
       
   158     */
       
   159 	IMPORT_C static TInt SetPinBias(TInt aId, TGpioBias aBias);
       
   160 
       
   161     /**
       
   162     Reads the bias on a pin.
       
   163     
       
   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).
       
   167 
       
   168     @return KErrNone, if successful; 
       
   169             KErrArgument, if aId is invalid;
       
   170             KErrNotSupported, if reading the pin bias is not supported.
       
   171     */
       
   172 	IMPORT_C static TInt GetPinBias(TInt aId, TGpioBias& aBias);
       
   173 
       
   174 	/**
       
   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.
       
   178 
       
   179 	@param aId    The pin Id.
       
   180 	@param aConf  An implementation specific token specifying the idle
       
   181 				  configration and state.
       
   182 	
       
   183 	@return KErrNone, if successful; 
       
   184             KErrArgument, if aId is invalid;
       
   185             KErrNotSupported, if setting the pin idle configuration and state
       
   186 							  are not supported.
       
   187 	*/
       
   188 	IMPORT_C static TInt SetPinIdleConfigurationAndState(TInt aId, TInt aConf);
       
   189 
       
   190     /**
       
   191     Reads the pin idle configuration and state.
       
   192     
       
   193     @param aId    The pin Id.
       
   194     @param aConf  On return contains the idle configuration and state previoulsy
       
   195 				  set on the pin.
       
   196 
       
   197     @return KErrNone, if successful; 
       
   198             KErrArgument, if aId is invalid;
       
   199             KErrNotSupported, if reading the pin idle configuration and state
       
   200 							  is not supported.
       
   201     */
       
   202 	IMPORT_C static TInt GetPinIdleConfigurationAndState(TInt aId, TInt& aConf);
       
   203 
       
   204     /**
       
   205     Associates the specified interrupt service routine (ISR) function with the
       
   206     								specified interrupt Id.
       
   207     
       
   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
       
   213                    32-bit value.
       
   214                  
       
   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.
       
   219     */
       
   220 	IMPORT_C static TInt BindInterrupt(TInt aId, TGpioIsr aIsr, TAny* aPtr);
       
   221 
       
   222     /**
       
   223     Unbinds the interrupt service routine (ISR) function from the specified interrupt
       
   224     id.
       
   225     
       
   226     @param aId The pin Id.
       
   227     
       
   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.
       
   232     */
       
   233 	IMPORT_C static TInt UnbindInterrupt(TInt aId);
       
   234 
       
   235     /**
       
   236     Enables the interrupt on specified pin.
       
   237     
       
   238     @param aId  The pin Id.
       
   239     
       
   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.
       
   244     */
       
   245 	IMPORT_C static TInt EnableInterrupt(TInt aId);
       
   246 
       
   247     /**
       
   248     Disables the interrupt on specified pin.
       
   249     
       
   250     @param aId  The pin Id.
       
   251     
       
   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.
       
   256     */
       
   257 	IMPORT_C static TInt DisableInterrupt(TInt aId);
       
   258 
       
   259     /**
       
   260     Checks if interrupt is enabled on pin.
       
   261     
       
   262     @param aId     The pin Id.
       
   263     @param aEnable On return contains the enable/disable state of interrupt 
       
   264  								       		 (TRUE=enabled).
       
   265     
       
   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.
       
   270     */
       
   271 	IMPORT_C static TInt IsInterruptEnabled(TInt aId, TBool& aEnable);
       
   272 
       
   273     /**
       
   274     Clears any pending interrupt on the specified pin.
       
   275     
       
   276     @param aId The pin Id.
       
   277     
       
   278     @return KErrNone, if successful;
       
   279             KErrArgument, if aId is invalid;
       
   280             KErrNotSupported if clearing interrupt signal is not supported on this
       
   281  											    pin;
       
   282             KErrGeneral, if there is no ISR bound to this interrupt.
       
   283     */
       
   284 	IMPORT_C static TInt ClearInterrupt(TInt aId);
       
   285 
       
   286     /**
       
   287     Reads the interrupt state as output by the GPIO interrupt controller.
       
   288     
       
   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).
       
   292 
       
   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.
       
   297     */
       
   298 	IMPORT_C static TInt GetMaskedInterruptState(TInt aId, TBool& aActive);
       
   299 
       
   300     /**
       
   301     Reads the interrupt state on the specified pin before any masking.
       
   302     
       
   303     @param aId     The pin Id.
       
   304     @param aActive On return contains state of the interrupt signal on the pin
       
   305  										  (TRUE=active).
       
   306 
       
   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.
       
   311     */
       
   312 	IMPORT_C static TInt GetRawInterruptState(TInt aId, TBool& aActive);
       
   313 
       
   314     /**
       
   315     Sets the interrupt trigger on the specified pin.
       
   316     
       
   317     @param aId      The pin Id.
       
   318     @param aTrigger The trigger type.
       
   319 
       
   320     @return KErrNone, if successful;
       
   321             KErrArgument, if aId is invalid;
       
   322             KErrNotSupported if pin does not support interrupts.
       
   323     */
       
   324 	IMPORT_C static TInt SetInterruptTrigger(TInt aId, TGpioDetectionTrigger aTrigger);
       
   325 
       
   326     /**
       
   327     Enables the wakeup on specified pin.
       
   328     
       
   329     @param aId  The pin Id.
       
   330     
       
   331     @return KErrNone, if successful;
       
   332             KErrArgument, if aId is invalid;
       
   333             KErrNotSupported if pin does not support wakeup.
       
   334     */
       
   335 	IMPORT_C static TInt EnableWakeup(TInt aId);
       
   336 
       
   337     /**
       
   338     Disables 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 DisableWakeup(TInt aId);
       
   347 
       
   348     /**
       
   349     Checks if wakeup is enabled on pin.
       
   350     
       
   351     @param aId     The pin Id.
       
   352     @param aEnable On return contains the enable/disable state of wakeup 
       
   353  								       		 (TRUE=enabled).
       
   354     
       
   355     @return KErrNone, if successful; 
       
   356             KErrArgument, if aId is invalid;
       
   357             KErrNotSupported if pin does not support wakeups;
       
   358     */
       
   359 	IMPORT_C static TInt IsWakeupEnabled(TInt aId, TBool& aEnable);
       
   360 
       
   361     /**
       
   362     Sets the wakeup trigger on the specified pin.
       
   363     
       
   364     @param aId      The pin Id.
       
   365     @param aTrigger The trigger type.
       
   366 
       
   367     @return KErrNone, if successful;
       
   368             KErrArgument, if aId is invalid;
       
   369             KErrNotSupported if pin does not support wakeup.
       
   370     */
       
   371 	IMPORT_C static TInt SetWakeupTrigger(TInt aId, TGpioDetectionTrigger aTrigger);
       
   372 
       
   373     /**
       
   374     Sets the debouncing time on the specified pin.
       
   375     
       
   376     @param aId    The pin Id.
       
   377     @param aTime  The debouncing time in microseconds.
       
   378 
       
   379     @return KErrNone, if the time is succesfully changed or no change is needed (see
       
   380                                                 			         below);
       
   381             KErrArgument, if aId is invalid;
       
   382             KErrNotSupported if pin does not support debouncing.
       
   383 
       
   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.
       
   388     */
       
   389 	IMPORT_C static TInt SetDebounceTime(TInt aId, TInt aTime);
       
   390 
       
   391     /**
       
   392     Reads the debouncing time on the specified pin.
       
   393     
       
   394     @param aId    The pin Id.
       
   395     @param aTime  On return contains the debouncing time in microseconds.
       
   396 
       
   397     @return KErrNone, if successful;
       
   398             KErrArgument, if aId is invalid;
       
   399             KErrNotSupported if pin does not support debouncing.
       
   400     */
       
   401 	IMPORT_C static TInt GetDebounceTime(TInt aId, TInt& aTime);
       
   402 
       
   403     /**
       
   404     Reads the state of an input (synchronously).
       
   405     
       
   406     @param aId    The pin Id.
       
   407     @param aState On return contains the pin state.
       
   408 
       
   409     @return KErrNone, if successful;
       
   410             KErrArgument, if aId is invalid.
       
   411             KErrNotSupported, if reading the state synchronously is not supported.
       
   412     */
       
   413 	IMPORT_C static TInt GetInputState(TInt aId, TGpioState& aState);
       
   414 
       
   415     /**
       
   416     Sets the output pin to one of the supported states (synchronously).
       
   417     
       
   418     @param aId    The pin Id.
       
   419     @param aState The pin state.
       
   420 
       
   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.
       
   424     */
       
   425 	IMPORT_C static TInt SetOutputState(TInt aId, TGpioState aState);
       
   426 
       
   427     /**
       
   428     Reads the output pin states (synchronously).
       
   429     
       
   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.
       
   434 
       
   435     @return KErrNone, if successful; 
       
   436             KErrArgument, if aId is invalid.
       
   437     */
       
   438 	IMPORT_C static TInt GetOutputState(TInt aId, TGpioState& aState);
       
   439 
       
   440     /**
       
   441     Reads the state of an input (asynchronously).
       
   442     
       
   443     @param aId    The pin Id.
       
   444     @param aCb    A pointer to a GPIO callback object.
       
   445 
       
   446     @return KErrNone, if accepted;
       
   447             KErrArgument, if aId is invalid.
       
   448             KErrNotSupported, if reading the state asynchronously is not supported.
       
   449 
       
   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;
       
   452     */
       
   453 	IMPORT_C static TInt GetInputState(TInt aId, TGpioCallback* aCb);
       
   454 
       
   455     /**
       
   456     Sets the output pin to one of the supported states (asynchronously).
       
   457     
       
   458     @param aId    The pin Id.
       
   459     @param aState The pin state.
       
   460     @param aCb    A pointer to a GPIO callback object.
       
   461 
       
   462     @return KErrNone, if accepted;
       
   463 			KErrArgument, if aId is invalid;
       
   464             KErrNotSupported, if setting its state asynchronously is not supported.
       
   465 
       
   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;
       
   468     */
       
   469 	IMPORT_C static TInt SetOutputState(TInt aId, TGpioState aState, TGpioCallback* aCb);
       
   470 
       
   471 	/**
       
   472     Allows the platform specific implementation to extend the API.
       
   473 
       
   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.
       
   478 
       
   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.
       
   483     */
       
   484 	IMPORT_C static TInt StaticExtension(TInt aId, TInt aCmd, TAny* aArg1, TAny* aArg2);
       
   485 	};
       
   486 
       
   487 /**
       
   488 GPIO asynchronous callback function
       
   489 */
       
   490 typedef void (*TGpioCbFn)(TInt				/*aPinId*/,
       
   491 						  GPIO::TGpioState	/*aState*/,
       
   492                           TInt				/*aResult*/,
       
   493                           TAny*				/*aParam*/);
       
   494 /**
       
   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
       
   499 */
       
   500 class TGpioCallback : public TDfc
       
   501 	{
       
   502 public:
       
   503 	inline TGpioCallback(TGpioCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority) : TDfc(DfcFunc, this, aQue, aPriority), iParam(aPtr), iCallback(aFn) 
       
   504 			{}
       
   505 private:
       
   506     inline static void DfcFunc(TAny* aPtr)
       
   507         {
       
   508         TGpioCallback* pCb = (TGpioCallback*) aPtr;
       
   509         pCb->iCallback(pCb->iPinId, pCb->iState, pCb->iResult, pCb->iParam);
       
   510         }
       
   511 public:
       
   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
       
   515 	TAny* iParam;
       
   516 	TGpioCbFn iCallback;
       
   517 	};
       
   518 #endif