epoc32/include/assp/omap3530_assp/gpio.h
branchSymbian3
changeset 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/assp/omap3530_assp/gpio.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -0,0 +1,518 @@
     1.4 +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#ifndef __GPIO_H__
    1.20 +#define __GPIO_H__
    1.21 +
    1.22 +class TGpioCallback;	//forward declaration
    1.23 +
    1.24 +/**
    1.25 +GPIO interrupt handler
    1.26 +Takes a generic argument (TAny*)
    1.27 +*/
    1.28 +typedef void (*TGpioIsr)(TAny*);
    1.29 +
    1.30 +class GPIO
    1.31 +	{
    1.32 +public:
    1.33 +	/**
    1.34 +	GPIO pin modes (to be requested on any pin):
    1.35 +	- enabled,
    1.36 +	- disabled,
    1.37 +	- idling
    1.38 +	*/
    1.39 +	enum TGpioMode
    1.40 +		{
    1.41 +		EEnabled,
    1.42 +		EDisabled,
    1.43 +		EIdle
    1.44 +		};
    1.45 +
    1.46 +		/**
    1.47 +	GPIO pin directions (to be requested on any pin):
    1.48 +	- input,
    1.49 +	- output,
    1.50 +	- tristated
    1.51 +	*/
    1.52 +	enum TGpioDirection
    1.53 +		{
    1.54 +		EInput,
    1.55 +		EOutput,
    1.56 +		ETriStated
    1.57 +		};
    1.58 +
    1.59 +	/**
    1.60 +	GPIO pin states (to be set on an output or read from an input or output):
    1.61 +	- electrical Low,
    1.62 +	- electrical High,
    1.63 +	- state compatible with idling the pin (module)
    1.64 +	*/
    1.65 +	enum TGpioState
    1.66 +		{
    1.67 +		ELow,
    1.68 +		EHigh,
    1.69 +		EIdleState
    1.70 +		};
    1.71 +
    1.72 +	/**
    1.73 +	GPIO programmable bias:
    1.74 +	- no drive,
    1.75 +	- pulled down (Low),
    1.76 +	- pulled up (High)
    1.77 +	*/
    1.78 +	enum TGpioBias
    1.79 +		{
    1.80 +		ENoDrive,
    1.81 +		EPullDown,
    1.82 +		EPullUp
    1.83 +		};
    1.84 +
    1.85 +	/**
    1.86 +	GPIO interrupt and/or wakeup triger configuration (to be requested on an input
    1.87 + 						 that supports interrupts or wakeup function):
    1.88 +	- Level triggered, low level,
    1.89 +	- Level triggered, high level,
    1.90 +	- Edge triggered, falling edge,
    1.91 +	- Edge triggered, rising edge,
    1.92 +	- Edge triggered, both edges,
    1.93 +	*/
    1.94 +	enum TGpioDetectionTrigger
    1.95 +		{
    1.96 +		ELevelLow,
    1.97 +		ELevelHigh,
    1.98 +		EEdgeFalling,
    1.99 +		EEdgeRising,
   1.100 +		EEdgeBoth
   1.101 +		};
   1.102 +
   1.103 +    /**
   1.104 +    Sets the pin mode.
   1.105 +    
   1.106 +    @param aId   The pin Id.
   1.107 +    @param aMode The pin mode.
   1.108 +
   1.109 +    @return KErrNone, if successful; KErrArgument, if aId is invalid;
   1.110 +            KErrNotReady, when a pin that has requested to be Idle is not ready to do
   1.111 + 											     so;
   1.112 +            KErrNotSupported, if a pin cannot be used as a GPIO because it  has been
   1.113 + 							     assigned an alternative function.
   1.114 +
   1.115 +	When disabling a pin, the module which the pin is a part of may not be disabled,
   1.116 + 								but KErrNone is still returned.
   1.117 +    */
   1.118 +	IMPORT_C static TInt SetPinMode(TInt aId, TGpioMode aMode);
   1.119 +
   1.120 +    /**
   1.121 +    Reads the pin mode.
   1.122 +    
   1.123 +    @param aId   The pin Id.
   1.124 +    @param aMode On return contains the pin mode.
   1.125 +
   1.126 +    @return KErrNone, if successful; KErrArgument, if aId is invalid;
   1.127 +            KErrNotSupported, if reading the pin mode is not supported.
   1.128 +    */
   1.129 +	IMPORT_C static TInt GetPinMode(TInt aId, TGpioMode& aMode);
   1.130 +
   1.131 +    /**
   1.132 +    Sets the pin direction.
   1.133 +    
   1.134 +    @param aId        The pin Id.
   1.135 +    @param aDirection The pin direction.
   1.136 +
   1.137 +    @return KErrNone, if successful; KErrArgument, if aId is invalid;
   1.138 +            KErrNotSupported, if a pin cannot operate in the direction specified.
   1.139 +    */
   1.140 +	IMPORT_C static TInt SetPinDirection(TInt aId, TGpioDirection aDirection);
   1.141 +
   1.142 +    /**
   1.143 +    Reads the pin direction.
   1.144 +    
   1.145 +    @param aId        The pin Id.
   1.146 +    @param aDirection On return contains the pin direction.
   1.147 +
   1.148 +    @return KErrNone, if successful; KErrArgument, if aId is invalid;
   1.149 +            KErrNotSupported, if reading the pin direction is not supported.
   1.150 +    */
   1.151 +	IMPORT_C static TInt GetPinDirection(TInt aId, TGpioDirection& aDirection);
   1.152 +
   1.153 +    /**
   1.154 +    Sets the bias on a pin.
   1.155 +    
   1.156 +    @param aId    The pin Id.
   1.157 +    @param aBias  The drive on the pin.
   1.158 +
   1.159 +    @return KErrNone, if successful; KErrArgument, if aId is invalid;
   1.160 +		   KErrNotSupported, if a pin does not support setting the drive.
   1.161 +    */
   1.162 +	IMPORT_C static TInt SetPinBias(TInt aId, TGpioBias aBias);
   1.163 +
   1.164 +    /**
   1.165 +    Reads the bias on a pin.
   1.166 +    
   1.167 +    @param aId    The pin Id.
   1.168 +    @param aBias  On return contains the bias previoulsy set on the pin (or the
   1.169 + 								   default bias if first time).
   1.170 +
   1.171 +    @return KErrNone, if successful; 
   1.172 +            KErrArgument, if aId is invalid;
   1.173 +            KErrNotSupported, if reading the pin bias is not supported.
   1.174 +    */
   1.175 +	IMPORT_C static TInt GetPinBias(TInt aId, TGpioBias& aBias);
   1.176 +
   1.177 +	/**
   1.178 +	Sets the idle configuration and state. The pin configuration is the 
   1.179 +	same that the pin should have when setting the mode to EIdle and the
   1.180 +	state same it should present when setting the output state to EIdleState.
   1.181 +
   1.182 +	@param aId    The pin Id.
   1.183 +	@param aConf  An implementation specific token specifying the idle
   1.184 +				  configration and state.
   1.185 +	
   1.186 +	@return KErrNone, if successful; 
   1.187 +            KErrArgument, if aId is invalid;
   1.188 +            KErrNotSupported, if setting the pin idle configuration and state
   1.189 +							  are not supported.
   1.190 +	*/
   1.191 +	IMPORT_C static TInt SetPinIdleConfigurationAndState(TInt aId, TInt aConf);
   1.192 +
   1.193 +    /**
   1.194 +    Reads the pin idle configuration and state.
   1.195 +    
   1.196 +    @param aId    The pin Id.
   1.197 +    @param aConf  On return contains the idle configuration and state previoulsy
   1.198 +				  set on the pin.
   1.199 +
   1.200 +    @return KErrNone, if successful; 
   1.201 +            KErrArgument, if aId is invalid;
   1.202 +            KErrNotSupported, if reading the pin idle configuration and state
   1.203 +							  is not supported.
   1.204 +    */
   1.205 +	IMPORT_C static TInt GetPinIdleConfigurationAndState(TInt aId, TInt& aConf);
   1.206 +
   1.207 +    /**
   1.208 +    Associates the specified interrupt service routine (ISR) function with the
   1.209 +    								specified interrupt Id.
   1.210 +    
   1.211 +    @param aId     The pin Id.
   1.212 +    @param anIsr   The address of the ISR function. 
   1.213 +    @param aPtr    32-bit value that is passed to the ISR.
   1.214 +                   This is designated a TAny* type as it is usually a pointer to the
   1.215 +                   owning class or data to be used in the ISR, although it can be any
   1.216 +                   32-bit value.
   1.217 +                 
   1.218 +    @return KErrNone, if successful;
   1.219 +            KErrArgument, if aId is invalid;
   1.220 +            KErrNotSupported if pin does not support interrupts;
   1.221 +            KErrInUse, if an ISR is already bound to this interrupt.
   1.222 +    */
   1.223 +	IMPORT_C static TInt BindInterrupt(TInt aId, TGpioIsr aIsr, TAny* aPtr);
   1.224 +
   1.225 +    /**
   1.226 +    Unbinds the interrupt service routine (ISR) function from the specified interrupt
   1.227 +    id.
   1.228 +    
   1.229 +    @param aId The pin Id.
   1.230 +    
   1.231 +    @return KErrNone, if successful; 
   1.232 +            KErrArgument, if aId is invalid;
   1.233 +            KErrNotSupported if pin does not support interrupts;
   1.234 +            KErrGeneral, if there is no ISR bound to this interrupt.
   1.235 +    */
   1.236 +	IMPORT_C static TInt UnbindInterrupt(TInt aId);
   1.237 +
   1.238 +    /**
   1.239 +    Enables the interrupt on specified pin.
   1.240 +    
   1.241 +    @param aId  The pin Id.
   1.242 +    
   1.243 +    @return KErrNone, if successful; 
   1.244 +            KErrArgument, if aId is invalid;
   1.245 +            KErrNotSupported if pin does not support interrupts;
   1.246 +            KErrGeneral, if there is no ISR bound to this interrupt.
   1.247 +    */
   1.248 +	IMPORT_C static TInt EnableInterrupt(TInt aId);
   1.249 +
   1.250 +    /**
   1.251 +    Disables the interrupt on specified pin.
   1.252 +    
   1.253 +    @param aId  The pin Id.
   1.254 +    
   1.255 +    @return KErrNone, if successful; 
   1.256 +            KErrArgument, if aId is invalid;
   1.257 +            KErrNotSupported if pin does not support interrupts;
   1.258 +            KErrGeneral, if there is no ISR bound to this interrupt.
   1.259 +    */
   1.260 +	IMPORT_C static TInt DisableInterrupt(TInt aId);
   1.261 +
   1.262 +    /**
   1.263 +    Checks if interrupt is enabled on pin.
   1.264 +    
   1.265 +    @param aId     The pin Id.
   1.266 +    @param aEnable On return contains the enable/disable state of interrupt 
   1.267 + 								       		 (TRUE=enabled).
   1.268 +    
   1.269 +    @return KErrNone, if successful; 
   1.270 +            KErrArgument, if aId is invalid;
   1.271 +            KErrNotSupported if pin does not support interrupts;
   1.272 +            KErrGeneral, if there is no ISR bound to this interrupt.
   1.273 +    */
   1.274 +	IMPORT_C static TInt IsInterruptEnabled(TInt aId, TBool& aEnable);
   1.275 +
   1.276 +    /**
   1.277 +    Clears any pending interrupt on the specified pin.
   1.278 +    
   1.279 +    @param aId The pin Id.
   1.280 +    
   1.281 +    @return KErrNone, if successful;
   1.282 +            KErrArgument, if aId is invalid;
   1.283 +            KErrNotSupported if clearing interrupt signal is not supported on this
   1.284 + 											    pin;
   1.285 +            KErrGeneral, if there is no ISR bound to this interrupt.
   1.286 +    */
   1.287 +	IMPORT_C static TInt ClearInterrupt(TInt aId);
   1.288 +
   1.289 +    /**
   1.290 +    Reads the interrupt state as output by the GPIO interrupt controller.
   1.291 +    
   1.292 +    @param aId     The pin Id.
   1.293 +    @param aActive On return contains the state of the interrupt signal as output by
   1.294 + 						      GPIO interrupt controller (TRUE=active).
   1.295 +
   1.296 +    @return KErrNone, if successful;
   1.297 +            KErrArgument, if aId is invalid;
   1.298 +            KErrNotSupported if reading interrupt state is not supported;
   1.299 +            KErrGeneral, if there is no ISR bound to this interrupt.
   1.300 +    */
   1.301 +	IMPORT_C static TInt GetMaskedInterruptState(TInt aId, TBool& aActive);
   1.302 +
   1.303 +    /**
   1.304 +    Reads the interrupt state on the specified pin before any masking.
   1.305 +    
   1.306 +    @param aId     The pin Id.
   1.307 +    @param aActive On return contains state of the interrupt signal on the pin
   1.308 + 										  (TRUE=active).
   1.309 +
   1.310 +    @return KErrNone, if successful;
   1.311 +            KErrArgument, if aId is invalid;
   1.312 +            KErrNotSupported if reading raw interrupt state is not supported;
   1.313 +            KErrGeneral, if there is no ISR bound to this interrupt.
   1.314 +    */
   1.315 +	IMPORT_C static TInt GetRawInterruptState(TInt aId, TBool& aActive);
   1.316 +
   1.317 +    /**
   1.318 +    Sets the interrupt trigger on the specified pin.
   1.319 +    
   1.320 +    @param aId      The pin Id.
   1.321 +    @param aTrigger The trigger type.
   1.322 +
   1.323 +    @return KErrNone, if successful;
   1.324 +            KErrArgument, if aId is invalid;
   1.325 +            KErrNotSupported if pin does not support interrupts.
   1.326 +    */
   1.327 +	IMPORT_C static TInt SetInterruptTrigger(TInt aId, TGpioDetectionTrigger aTrigger);
   1.328 +
   1.329 +    /**
   1.330 +    Enables the wakeup on specified pin.
   1.331 +    
   1.332 +    @param aId  The pin Id.
   1.333 +    
   1.334 +    @return KErrNone, if successful;
   1.335 +            KErrArgument, if aId is invalid;
   1.336 +            KErrNotSupported if pin does not support wakeup.
   1.337 +    */
   1.338 +	IMPORT_C static TInt EnableWakeup(TInt aId);
   1.339 +
   1.340 +    /**
   1.341 +    Disables the wakeup on specified pin.
   1.342 +    
   1.343 +    @param aId  The pin Id.
   1.344 +    
   1.345 +    @return KErrNone, if successful;
   1.346 +            KErrArgument, if aId is invalid;
   1.347 +            KErrNotSupported if pin does not support wakeup.
   1.348 +    */
   1.349 +	IMPORT_C static TInt DisableWakeup(TInt aId);
   1.350 +
   1.351 +    /**
   1.352 +    Checks if wakeup is enabled on pin.
   1.353 +    
   1.354 +    @param aId     The pin Id.
   1.355 +    @param aEnable On return contains the enable/disable state of wakeup 
   1.356 + 								       		 (TRUE=enabled).
   1.357 +    
   1.358 +    @return KErrNone, if successful; 
   1.359 +            KErrArgument, if aId is invalid;
   1.360 +            KErrNotSupported if pin does not support wakeups;
   1.361 +    */
   1.362 +	IMPORT_C static TInt IsWakeupEnabled(TInt aId, TBool& aEnable);
   1.363 +
   1.364 +    /**
   1.365 +    Sets the wakeup trigger on the specified pin.
   1.366 +    
   1.367 +    @param aId      The pin Id.
   1.368 +    @param aTrigger The trigger type.
   1.369 +
   1.370 +    @return KErrNone, if successful;
   1.371 +            KErrArgument, if aId is invalid;
   1.372 +            KErrNotSupported if pin does not support wakeup.
   1.373 +    */
   1.374 +	IMPORT_C static TInt SetWakeupTrigger(TInt aId, TGpioDetectionTrigger aTrigger);
   1.375 +
   1.376 +    /**
   1.377 +    Sets the debouncing time on the specified pin.
   1.378 +    
   1.379 +    @param aId    The pin Id.
   1.380 +    @param aTime  The debouncing time in microseconds.
   1.381 +
   1.382 +    @return KErrNone, if the time is succesfully changed or no change is needed (see
   1.383 +                                                			         below);
   1.384 +            KErrArgument, if aId is invalid;
   1.385 +            KErrNotSupported if pin does not support debouncing.
   1.386 +
   1.387 +    If the requested time is greater than the common value for the module, the latter
   1.388 +    is increased to the value requested.
   1.389 +    If the requested time is lesser than the common value for the module then the
   1.390 +    common value is unchanged, unless it is set to the value requested on this pin.
   1.391 +    */
   1.392 +	IMPORT_C static TInt SetDebounceTime(TInt aId, TInt aTime);
   1.393 +
   1.394 +    /**
   1.395 +    Reads the debouncing time on the specified pin.
   1.396 +    
   1.397 +    @param aId    The pin Id.
   1.398 +    @param aTime  On return contains the debouncing time in microseconds.
   1.399 +
   1.400 +    @return KErrNone, if successful;
   1.401 +            KErrArgument, if aId is invalid;
   1.402 +            KErrNotSupported if pin does not support debouncing.
   1.403 +    */
   1.404 +	IMPORT_C static TInt GetDebounceTime(TInt aId, TInt& aTime);
   1.405 +
   1.406 +    /**
   1.407 +    Reads the state of an input (synchronously).
   1.408 +    
   1.409 +    @param aId    The pin Id.
   1.410 +    @param aState On return contains the pin state.
   1.411 +
   1.412 +    @return KErrNone, if successful;
   1.413 +            KErrArgument, if aId is invalid.
   1.414 +            KErrNotSupported, if reading the state synchronously is not supported.
   1.415 +    */
   1.416 +	IMPORT_C static TInt GetInputState(TInt aId, TGpioState& aState);
   1.417 +
   1.418 +    /**
   1.419 +    Sets the output pin to one of the supported states (synchronously).
   1.420 +    
   1.421 +    @param aId    The pin Id.
   1.422 +    @param aState The pin state.
   1.423 +
   1.424 +    @return KErrNone, if successful;
   1.425 +			KErrArgument, if aId is invalid;
   1.426 +            KErrNotSupported, if the state is not supported or if setting its state synchronously is not supported.
   1.427 +    */
   1.428 +	IMPORT_C static TInt SetOutputState(TInt aId, TGpioState aState);
   1.429 +
   1.430 +    /**
   1.431 +    Reads the output pin states (synchronously).
   1.432 +    
   1.433 +    @param aId    The pin Id.
   1.434 +    @param aState On return contains the pin state. On systems where the state of an
   1.435 + 			 ouptut pin cannot be read directly from hardware, or takes a non
   1.436 +			 negligible time to be retrieved, the implementation must cache it.
   1.437 +
   1.438 +    @return KErrNone, if successful; 
   1.439 +            KErrArgument, if aId is invalid.
   1.440 +    */
   1.441 +	IMPORT_C static TInt GetOutputState(TInt aId, TGpioState& aState);
   1.442 +
   1.443 +    /**
   1.444 +    Reads the state of an input (asynchronously).
   1.445 +    
   1.446 +    @param aId    The pin Id.
   1.447 +    @param aCb    A pointer to a GPIO callback object.
   1.448 +
   1.449 +    @return KErrNone, if accepted;
   1.450 +            KErrArgument, if aId is invalid.
   1.451 +            KErrNotSupported, if reading the state asynchronously is not supported.
   1.452 +
   1.453 +	This API should be used with off-chip GPIO modules only;
   1.454 +	The result of the read operation and the state of the input pin will be passed as an argument to the callback function;
   1.455 +    */
   1.456 +	IMPORT_C static TInt GetInputState(TInt aId, TGpioCallback* aCb);
   1.457 +
   1.458 +    /**
   1.459 +    Sets the output pin to one of the supported states (asynchronously).
   1.460 +    
   1.461 +    @param aId    The pin Id.
   1.462 +    @param aState The pin state.
   1.463 +    @param aCb    A pointer to a GPIO callback object.
   1.464 +
   1.465 +    @return KErrNone, if accepted;
   1.466 +			KErrArgument, if aId is invalid;
   1.467 +            KErrNotSupported, if setting its state asynchronously is not supported.
   1.468 +
   1.469 +    This API should be used with off-chip GPIO modules only;
   1.470 +	The result of the set operation will be passed as an argument to the callback function;
   1.471 +    */
   1.472 +	IMPORT_C static TInt SetOutputState(TInt aId, TGpioState aState, TGpioCallback* aCb);
   1.473 +
   1.474 +	/**
   1.475 +    Allows the platform specific implementation to extend the API.
   1.476 +
   1.477 +    @param aId        The pin Id.
   1.478 +	@param aCmd       A PSL extension function id.
   1.479 +	@param aArg1      An argument to be passed to the PSL extension function.
   1.480 +	@param aArg2      An argument to be passed to the PSL extension function.
   1.481 +
   1.482 +    @return KErrNone, if accepted;
   1.483 +			KErrArgument, if aId is invalid;
   1.484 +            KErrNotSupported, if static extensions are not supported.
   1.485 +			Any other system wide error code.
   1.486 +    */
   1.487 +	IMPORT_C static TInt StaticExtension(TInt aId, TInt aCmd, TAny* aArg1, TAny* aArg2);
   1.488 +	};
   1.489 +
   1.490 +/**
   1.491 +GPIO asynchronous callback function
   1.492 +*/
   1.493 +typedef void (*TGpioCbFn)(TInt				/*aPinId*/,
   1.494 +						  GPIO::TGpioState	/*aState*/,
   1.495 +                          TInt				/*aResult*/,
   1.496 +                          TAny*				/*aParam*/);
   1.497 +/**
   1.498 +GPIO asynchronous callback DFC
   1.499 +The client must create one of these to be passed to each asynchronous call to GetInputState and SetOutputState
   1.500 +The callback function is called in the context supplied by the client when creating an object of this kind (aQue)
   1.501 +The callback function takes as arguments the pin id and the state, so it can be common to all TGpioCallback
   1.502 +*/
   1.503 +class TGpioCallback : public TDfc
   1.504 +	{
   1.505 +public:
   1.506 +	inline TGpioCallback(TGpioCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority) : TDfc(DfcFunc, this, aQue, aPriority), iParam(aPtr), iCallback(aFn) 
   1.507 +			{}
   1.508 +private:
   1.509 +    inline static void DfcFunc(TAny* aPtr)
   1.510 +        {
   1.511 +        TGpioCallback* pCb = (TGpioCallback*) aPtr;
   1.512 +        pCb->iCallback(pCb->iPinId, pCb->iState, pCb->iResult, pCb->iParam);
   1.513 +        }
   1.514 +public:
   1.515 +	TInt iPinId;		// the Id of the pin on which the asynchronous operation is performed
   1.516 +	GPIO::TGpioState iState;	// either the state the output pin should be moved to or the state the input pin is at
   1.517 +	TInt iResult;		// the result of this transaction as a system wide error
   1.518 +	TAny* iParam;
   1.519 +	TGpioCbFn iCallback;
   1.520 +	};
   1.521 +#endif