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