usbmgmt/usbmgr/usbman/chargingplugin/public/CUsbBatteryChargingPlugin.h
changeset 0 c9bc50fca66e
equal deleted inserted replaced
-1:000000000000 0:c9bc50fca66e
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 /** @file
       
    19 @internalComponent
       
    20 */
       
    21 
       
    22 #ifndef USBBATTERYCHARGINGPLUGIN_H
       
    23 #define USBBATTERYCHARGINGPLUGIN_H
       
    24 
       
    25 #include <e32base.h>
       
    26 
       
    27 #ifdef __CHARGING_PLUGIN_TEST_CODE__
       
    28 #include <dummyldd.h>
       
    29 #define __D32USBC_H__ // ensure that d32usbc is ignored
       
    30 #define private protected
       
    31 #else
       
    32 #include <d32usbc.h>
       
    33 #endif
       
    34 
       
    35 #include <cusbmanextensionplugin.h>
       
    36 #include "usbbatterycharging.h"
       
    37 #include <musbdevicenotify.h>
       
    38 #include "devicestatetimer.h"
       
    39 #include "repositorynotifier.h"
       
    40 #include "motgobserver.h"
       
    41 
       
    42 class CUsbChargingReEnumerator;
       
    43 class CUsbBatteryChargingLicenseeHooks;
       
    44 
       
    45 // For host OTG enabled charging plug-in
       
    46 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
       
    47 class CIdPinWatcher;
       
    48 class COtgStateWatcher;
       
    49 #endif
       
    50 
       
    51 class CVBusWatcher;
       
    52 
       
    53 enum TUsbBatteryChargingPanic
       
    54     {
       
    55     EUsbBatteryChargingPanicBadUserSetting = 0,
       
    56     EUsbBatteryChargingPanicBadPluginState = 1,
       
    57     EUsbBatteryChargingPanicUnexpectedPluginState = 2,
       
    58     EUsbBatteryChargingPanicBadDeviceState = 3,
       
    59     EUsbBatteryChargingPanicBadOtgState = 4,
       
    60     EUsbBatteryChargingPanicBadVBusState = 5,
       
    61     EUsbBatteryChargingPanicBadCharingCurrentNegotiation = 6
       
    62     };
       
    63 
       
    64 // For host OTG enabled charging plug-in
       
    65 class MUsbBatteryChargingPluginInterface : public MUsbDeviceNotify,
       
    66     public MUsbChargingRepositoryObserver,
       
    67     public MUsbChargingDeviceStateTimerObserver, public MOtgPropertiesObserver
       
    68     {
       
    69 public:  // from MUsbDeviceNotify
       
    70     virtual void UsbServiceStateChange (TInt aLastError,
       
    71         TUsbServiceState aOldState, TUsbServiceState aNewState) = 0;
       
    72     virtual void UsbDeviceStateChange (TInt aLastError,
       
    73         TUsbDeviceState aOldState, TUsbDeviceState aNewState) = 0;
       
    74 
       
    75 public: // from MUsbChargingRepositoryObserver
       
    76     virtual void HandleRepositoryValueChangedL(const TUid& aRepository, TUint aId, TInt aVal) = 0;
       
    77     
       
    78 public: // from MUsbChargingDeviceStateTimerObserver
       
    79     virtual void DeviceStateTimeout() = 0;
       
    80 
       
    81 public: // from MOtgPropertiesObserver
       
    82 // For host OTG enabled charging plug-in
       
    83 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV 
       
    84     virtual void MpsoIdPinStateChanged(TInt aValue) = 0;
       
    85     virtual void MpsoOtgStateChangedL(TUsbOtgState aNewState) = 0;
       
    86 #endif    
       
    87     virtual void MpsoVBusStateChanged(TInt aNewState) = 0;
       
    88     };
       
    89 
       
    90 class TUsbBatteryChargingPluginStateBase;
       
    91 class TUsbBatteryChargingPluginStateIdle;
       
    92 class TUsbBatteryChargingPluginStateIdleUserDisabled;
       
    93 class TUsbBatteryChargingPluginStateNoValidcurrent;
       
    94 class TUsbBatteryChargingPluginStateCurrentNegotiating;
       
    95 class TUsbBatteryChargingPluginStateCharging;
       
    96 class TUsbBatteryChargingPluginStateIdelNegotiated;
       
    97 class TUsbBatteryChargingPluginStateBEndedCableNotPresent;
       
    98 
       
    99 enum TUsbChargingPluginState
       
   100     {
       
   101     // The default first state of this plugin
       
   102     EPluginStateIdle = 0,
       
   103     
       
   104     // Start to negotiate with A device about the charging current
       
   105     // re-enumration is executed 
       
   106     EPluginStateCurrentNegotiating,
       
   107     
       
   108     // Negotiation failed
       
   109     EPluginStateNoValidCurrent,
       
   110     
       
   111     // The only that indicate charging is going on 
       
   112     EPluginStateCharging,
       
   113     
       
   114     // charging is stopped for some reason, but negotiation is done already
       
   115     EPluginStateIdleNegotiated,
       
   116     
       
   117     // User Disabled "charging from usb" functionality
       
   118     EPluginStateUserDisabled,
       
   119 
       
   120     // Deivce is connect with A end cable, so, no way to do a charging to itself 
       
   121     EPluginStateBEndedCableNotPresent,
       
   122         
       
   123     // State counter
       
   124     EPluginStateCount
       
   125     };
       
   126 
       
   127 
       
   128 class CUsbBatteryChargingPlugin : public CUsbmanExtensionPlugin,
       
   129     private MUsbBatteryChargingPluginInterface 
       
   130     {
       
   131     friend class TUsbBatteryChargingPluginStateBase;
       
   132     friend class TUsbBatteryChargingPluginStateIdle;
       
   133     friend class TUsbBatteryChargingPluginStateUserDisabled;
       
   134     friend class TUsbBatteryChargingPluginStateNoValidCurrent;
       
   135     friend class TUsbBatteryChargingPluginStateCurrentNegotiating;
       
   136     friend class TUsbBatteryChargingPluginStateCharging;
       
   137     friend class TUsbBatteryChargingPluginStateIdleNegotiated;
       
   138     friend class TUsbBatteryChargingPluginStateBEndedCableNotPresent;
       
   139     
       
   140 public:
       
   141     static CUsbBatteryChargingPlugin* NewL(MUsbmanExtensionPluginObserver& aObserver);
       
   142     ~CUsbBatteryChargingPlugin();
       
   143 
       
   144 private: // from CUsbmanExtensionPlugin
       
   145     TAny* GetInterface(TUid aUid);
       
   146     
       
   147 private:  // from MUsbBatteryChargingPluginInterface
       
   148     // from MUsbDeviceNotify
       
   149     void UsbServiceStateChange (TInt aLastError,
       
   150         TUsbServiceState aOldState, TUsbServiceState aNewState);
       
   151     void UsbDeviceStateChange (TInt aLastError,
       
   152         TUsbDeviceState aOldState, TUsbDeviceState aNewState);
       
   153 
       
   154     // from MUsbChargingRepositoryObserver
       
   155     void HandleRepositoryValueChangedL(const TUid& aRepository, TUint aId, TInt aVal);
       
   156     
       
   157     // from MUsbChargingDeviceStateTimerObserver
       
   158     void DeviceStateTimeout();
       
   159 
       
   160 // For host OTG enabled charging plug-in
       
   161 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV 
       
   162     // from MOtgPropertiesObserver
       
   163     void MpsoIdPinStateChanged(TInt aValue);
       
   164     void MpsoOtgStateChangedL(TUsbOtgState aNewState);
       
   165 #endif
       
   166     
       
   167     void MpsoVBusStateChanged(TInt aNewState);
       
   168 private:
       
   169     CUsbBatteryChargingPlugin(MUsbmanExtensionPluginObserver& aObserver);
       
   170     void ConstructL();
       
   171     void Panic(TUsbBatteryChargingPanic aPanic);
       
   172 
       
   173 private:
       
   174     void StartCharging(TUint aMilliAmps);
       
   175     void StopCharging();
       
   176     
       
   177     void SetNegotiatedCurrent(TUint aMilliAmps);
       
   178     void ReadCurrentRequestValuesL();
       
   179     
       
   180     void NegotiateChargingCurrent();
       
   181     void NegotiateNextCurrentValueL();
       
   182     void RequestCurrentL(TUint aMilliAmps);
       
   183     
       
   184     void ResetPlugin();
       
   185             
       
   186     void SetInitialConfigurationL();
       
   187     
       
   188     TBool IsUsbChargingPossible();
       
   189     
       
   190     void LogStateText(TUsbDeviceState aState);
       
   191     void PushRecoverState(TUsbChargingPluginState aRecoverState);
       
   192     TUsbChargingPluginState PopRecoverState();
       
   193     
       
   194     TUsbChargingPluginState SetState(TUsbChargingPluginState aState);
       
   195     
       
   196 private: // owned
       
   197     RDevUsbcClient& iLdd;
       
   198        
       
   199     // user allow usb charging function already?
       
   200     TUsbBatteryChargingUserSetting iUserSetting;
       
   201     
       
   202     // More than one value will be tried by the negotiation process to 
       
   203     // aquire a as larger current value as possible for charging
       
   204     RArray<TInt> iCurrentValues;
       
   205     
       
   206     //value of requested current set to descriptor for negotiation
       
   207     TInt iRequestedCurrentValue;
       
   208     
       
   209     //index of requested value
       
   210     TInt iCurrentIndexRequested;
       
   211     
       
   212     //value of negotiated current
       
   213     TInt iAvailableMilliAmps;   
       
   214 
       
   215     CUsbChargingDeviceStateTimer*   iDeviceStateTimer;
       
   216     CUsbChargingRepositoryNotifier* iRepositoryNotifier;
       
   217     CUsbChargingReEnumerator*       iDeviceReEnumerator;
       
   218 
       
   219     CUsbBatteryChargingLicenseeHooks* iLicenseeHooks;
       
   220 
       
   221 // For host OTG enabled charging plug-in
       
   222 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV     
       
   223     //Outer state watchers
       
   224     COtgStateWatcher *iOtgStateWatcher;
       
   225     CIdPinWatcher *iIdPinWatcher;
       
   226     //Outer states
       
   227     TInt iIdPinState;
       
   228     TUsbOtgState iOtgState;
       
   229 #endif    
       
   230     
       
   231     TInt iVBusState;
       
   232     CVBusWatcher *iVBusWatcher;
       
   233     TUsbDeviceState iDeviceState;
       
   234     
       
   235     // Plug-in States
       
   236     TUsbChargingPluginState iPluginState; // Current state machine status
       
   237     TUsbChargingPluginState iPluginStateToRecovery; // The recover state when user enable USB Charging
       
   238     TUsbBatteryChargingPluginStateBase* iCurrentState; // Owned
       
   239     TUsbBatteryChargingPluginStateBase* iPluginStates[EPluginStateCount]; // State implementations
       
   240     };
       
   241 
       
   242 #endif // USBBATTERYCHARGINGPLUGIN_H