16 */ |
16 */ |
17 |
17 |
18 /** @file |
18 /** @file |
19 @internalComponent |
19 @internalComponent |
20 */ |
20 */ |
|
21 |
21 #include "CUsbBatteryChargingPlugin.h" |
22 #include "CUsbBatteryChargingPlugin.h" |
22 #include <e32debug.h> |
23 #include "chargingstates.h" |
23 #include <e32def.h> |
24 #include <musbmanextensionpluginobserver.h> |
|
25 #include "cusbbatterycharginglicenseehooks.h" |
|
26 #include "reenumerator.h" |
24 #include <usb/usblogger.h> |
27 #include <usb/usblogger.h> |
25 #include <e32property.h> |
28 #include <e32property.h> |
26 #include <centralrepository.h> |
29 #include <centralrepository.h> |
27 #include <usbotgdefs.h> |
30 #include <usbotgdefs.h> |
28 #include <musbmanextensionpluginobserver.h> |
|
29 |
|
30 |
|
31 #include "chargingstates.h" |
|
32 #include "cusbbatterycharginglicenseehooks.h" |
|
33 #include "reenumerator.h" |
|
34 |
31 |
35 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV // For host OTG enabled charging plug-in |
32 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV // For host OTG enabled charging plug-in |
36 #include "idpinwatcher.h" |
33 #include "idpinwatcher.h" |
37 #include "otgstatewatcher.h" |
34 #include "otgstatewatcher.h" |
38 #endif |
35 #endif |
39 |
36 |
40 #include "vbuswatcher.h" |
37 #include "vbuswatcher.h" |
41 #include "OstTraceDefinitions.h" |
38 #include <e32debug.h> |
42 #ifdef OST_TRACE_COMPILER_IN_USE |
39 #include <e32def.h> |
43 #include "CUsbBatteryChargingPluginTraces.h" |
|
44 #endif |
|
45 |
|
46 |
40 |
47 static const TInt KUsbBatteryChargingConfigurationDescriptorCurrentOffset = 8; // see bMaxPower in section 9.6.3 of USB Spec 2.0 |
41 static const TInt KUsbBatteryChargingConfigurationDescriptorCurrentOffset = 8; // see bMaxPower in section 9.6.3 of USB Spec 2.0 |
48 static const TInt KUsbBatteryChargingCurrentRequestTimeout = 3000000; // 3 seconds |
42 static const TInt KUsbBatteryChargingCurrentRequestTimeout = 3000000; // 3 seconds |
49 |
43 |
|
44 #ifdef __FLOG_ACTIVE |
|
45 _LIT8(KLogComponent, "USBCHARGE"); |
|
46 #endif |
50 |
47 |
51 /** |
48 /** |
52 Factory function. |
49 Factory function. |
53 @return Ownership of a new CUsbBatteryChargingPlugin. |
50 @return Ownership of a new CUsbBatteryChargingPlugin. |
54 */ |
51 */ |
250 /** |
245 /** |
251 Set first power to request |
246 Set first power to request |
252 */ |
247 */ |
253 void CUsbBatteryChargingPlugin::SetInitialConfigurationL() |
248 void CUsbBatteryChargingPlugin::SetInitialConfigurationL() |
254 { |
249 { |
255 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;Setting Initial Configuration" ); |
250 LOGTEXT(_L8("Setting Initial Configuration")); |
256 if (iCurrentValues.Count() > 0) |
251 if (iCurrentValues.Count() > 0) |
257 { |
252 { |
258 TInt err; |
|
259 TInt configDescriptorSize = 0; |
253 TInt configDescriptorSize = 0; |
260 err = iLdd.GetConfigurationDescriptorSize(configDescriptorSize); |
254 LEAVEIFERRORL(iLdd.GetConfigurationDescriptorSize(configDescriptorSize)); |
261 if(err < 0) |
|
262 { |
|
263 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP1, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;iLdd.GetConfigurationDescriptorSize(configDescriptorSize) with error=%d", err ); |
|
264 User::Leave(err); |
|
265 } |
|
266 HBufC8* configDescriptor = HBufC8::NewLC(configDescriptorSize); |
255 HBufC8* configDescriptor = HBufC8::NewLC(configDescriptorSize); |
267 TPtr8 ptr(configDescriptor->Des()); |
256 TPtr8 ptr(configDescriptor->Des()); |
268 |
257 |
269 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP2, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;Getting Configuration Descriptor (size = %d)", configDescriptorSize ); |
258 LOGTEXT2(_L8("Getting Configuration Descriptor (size = %d)"),configDescriptorSize); |
270 err = iLdd.GetConfigurationDescriptor(ptr); |
259 LEAVEIFERRORL(iLdd.GetConfigurationDescriptor(ptr)); |
271 if(err < 0) |
|
272 { |
|
273 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP3, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;iLdd.GetConfigurationDescriptor(ptr) with error=%d", err ); |
|
274 User::Leave(err); |
|
275 } |
|
276 |
260 |
277 // For host OTG enabled charging plug-in |
261 // For host OTG enabled charging plug-in |
278 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
262 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
279 // Get first power to put in configurator |
263 // Get first power to put in configurator |
280 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP4, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;Checking IdPin state:" ); |
264 LOGTEXT(_L8("Checking IdPin state:")); |
281 if(iIdPinState == EUsbBatteryChargingIdPinBRole) |
265 if(iIdPinState == EUsbBatteryChargingIdPinBRole) |
282 #else |
266 #else |
283 if (ETrue) |
267 if (ETrue) |
284 #endif |
268 #endif |
285 { |
269 { |
286 if (iCurrentValues.Count() > 0) |
270 if (iCurrentValues.Count() > 0) |
287 { |
271 { |
288 iCurrentIndexRequested = 0; |
272 iCurrentIndexRequested = 0; |
289 iRequestedCurrentValue = iCurrentValues[iCurrentIndexRequested]; |
273 iRequestedCurrentValue = iCurrentValues[iCurrentIndexRequested]; |
290 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP5, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;IdPin state is 0, current set to: %d", iRequestedCurrentValue ); |
274 LOGTEXT2(_L8("IdPin state is 0, current set to: %d"), iRequestedCurrentValue); |
291 } |
275 } |
292 else |
276 else |
293 { |
277 { |
294 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP6, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;No vailable current found !" ); |
278 LOGTEXT(_L8("No vailable current found !")); |
295 } |
279 } |
296 } |
280 } |
297 else |
281 else |
298 { |
282 { |
299 iRequestedCurrentValue = 0; |
283 iRequestedCurrentValue = 0; |
300 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP7, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;IdPin state is 1, current set to 0" ); |
284 LOGTEXT(_L8("IdPin state is 1, current set to 0")); |
301 } |
285 } |
302 |
286 |
303 TUint oldCurrentValue = ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] << 1; |
287 TUint oldCurrentValue = ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] << 1; |
304 ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] = (iRequestedCurrentValue >> 1); |
288 ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] = (iRequestedCurrentValue >> 1); |
305 |
289 |
306 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP8, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;Setting Updated Configuration Descriptor" ); |
290 LOGTEXT(_L8("Setting Updated Configuration Descriptor")); |
307 err = iLdd.SetConfigurationDescriptor(ptr); |
291 LEAVEIFERRORL(iLdd.SetConfigurationDescriptor(ptr)); |
308 if(err < 0) |
|
309 { |
|
310 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP9, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;iLdd.SetConfigurationDescriptor(ptr) with error=%d", err ); |
|
311 User::Leave(err); |
|
312 } |
|
313 |
292 |
314 CleanupStack::PopAndDestroy(configDescriptor); |
293 CleanupStack::PopAndDestroy(configDescriptor); |
315 } |
294 } |
316 } |
295 } |
317 |
296 |
318 |
297 |
319 TAny* CUsbBatteryChargingPlugin::GetInterface(TUid aUid) |
298 TAny* CUsbBatteryChargingPlugin::GetInterface(TUid aUid) |
320 { |
299 { |
321 OstTrace1( TRACE_FLOW, REF_CUSBBATTERYCHARGINGPLUGIN_GETINTERFACE, "CUsbBatteryChargingPlugin::GetInterface;this = [0x%08x]", this ); |
300 LOGTEXT(KNullDesC8); |
322 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_GETINTERFACE_DUP1, "CUsbBatteryChargingPlugin::GetInterface;aUid = 0x%08x", aUid.iUid ); |
301 LOGTEXT3(_L8(">>CUsbBatteryChargingPlugin::GetInterface this = [0x%08x], aUid = 0x%08x"), this, aUid); |
323 (void)aUid; |
302 (void)aUid; |
324 |
303 |
325 TAny* ret = NULL; |
304 TAny* ret = NULL; |
326 |
305 |
327 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_GETINTERFACE_DUP2, "CUsbBatteryChargingPlugin::GetInterface;ret = [0x%08x]", ret ); |
306 LOGTEXT2(_L8("<<CUsbBatteryChargingPlugin::GetInterface ret = [0x%08x]"), ret); |
328 return ret; |
307 return ret; |
329 } |
308 } |
330 |
309 |
331 void CUsbBatteryChargingPlugin::Panic(TUsbBatteryChargingPanic aPanic) |
310 void CUsbBatteryChargingPlugin::Panic(TUsbBatteryChargingPanic aPanic) |
332 { |
311 { |
333 OstTrace1( TRACE_FATAL, REF_CUSBBATTERYCHARGINGPLUGIN_PANIC, "CUsbBatteryChargingPlugin::Panic;*** CUsbBatteryChargingPlugin::Panic(%d) ***", aPanic ); |
312 LOGTEXT2(_L8("*** CUsbBatteryChargingPlugin::Panic(%d) ***"),aPanic); |
334 _LIT(KUsbChargingPanic,"USB Charging"); |
313 _LIT(KUsbChargingPanic,"USB Charging"); |
335 User::Panic(KUsbChargingPanic, aPanic); |
314 User::Panic(KUsbChargingPanic, aPanic); |
336 } |
315 } |
337 |
316 |
338 void CUsbBatteryChargingPlugin::UsbServiceStateChange(TInt /*aLastError*/, TUsbServiceState /*aOldState*/, TUsbServiceState /*aNewState*/) |
317 void CUsbBatteryChargingPlugin::UsbServiceStateChange(TInt /*aLastError*/, TUsbServiceState /*aOldState*/, TUsbServiceState /*aNewState*/) |
392 default: |
369 default: |
393 // Should never happen ... |
370 // Should never happen ... |
394 iPluginState = EPluginStateIdle; |
371 iPluginState = EPluginStateIdle; |
395 iCurrentState = iPluginStates[EPluginStateIdle]; |
372 iCurrentState = iPluginStates[EPluginStateIdle]; |
396 |
373 |
397 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETSTATE, "CUsbBatteryChargingPlugin::SetState;Invalid new state: aState = %d", aState ); |
374 LOGTEXT2(_L8(">>CUsbBatteryChargingPlugin::SetState: Invalid new state: aState = %d"), aState); |
398 |
375 |
399 Panic(EUsbBatteryChargingPanicUnexpectedPluginState); |
376 Panic(EUsbBatteryChargingPanicUnexpectedPluginState); |
400 } |
377 } |
401 iPluginState = aState; |
378 iPluginState = aState; |
402 |
379 |
403 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETSTATE_DUP1, "CUsbBatteryChargingPlugin::SetState;New state: aState=%d", aState ); |
380 LOGTEXT2(_L8(">>CUsbBatteryChargingPlugin::SetState, New state: aState = %d"), aState); |
404 |
381 |
405 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_SETSTATE_EXIT ); |
|
406 return iPluginState; |
382 return iPluginState; |
407 } |
383 } |
408 |
384 |
409 void CUsbBatteryChargingPlugin::NegotiateChargingCurrent() |
385 void CUsbBatteryChargingPlugin::NegotiateChargingCurrent() |
410 { |
386 { |
411 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_NEGOTIATECHARGINGCURRENT_ENTRY ); |
387 LOG_FUNC |
412 |
388 |
413 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_NEGOTIATECHARGINGCURRENT, "CUsbBatteryChargingPlugin::NegotiateChargingCurrent;iDeviceState=%d", iDeviceState ); |
389 LOGTEXT2(_L8(">>CUsbBatteryChargingPlugin::StartNegotiation, iDeviceState = %d"), iDeviceState); |
414 TRAPD(result, NegotiateNextCurrentValueL()); |
390 TRAPD(result, NegotiateNextCurrentValueL()); |
415 if(result == KErrNone) |
391 if(result == KErrNone) |
416 { |
392 { |
417 SetState(EPluginStateCurrentNegotiating); |
393 SetState(EPluginStateCurrentNegotiating); |
418 } |
394 } |
419 else |
395 else |
420 { |
396 { |
421 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_NEGOTIATECHARGINGCURRENT_DUP1, "CUsbBatteryChargingPlugin::NegotiateChargingCurrent;Negotiation call failed, iVBusState = 1: result = %d", result ); |
397 LOGTEXT2(_L8("Negotiation call failed, iVBusState = 1: result = %d"), result); |
422 } |
398 } |
423 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_NEGOTIATECHARGINGCURRENT_EXIT ); |
|
424 } |
399 } |
425 |
400 |
426 void CUsbBatteryChargingPlugin::UsbDeviceStateChange(TInt aLastError, |
401 void CUsbBatteryChargingPlugin::UsbDeviceStateChange(TInt aLastError, |
427 TUsbDeviceState aOldState, TUsbDeviceState aNewState) |
402 TUsbDeviceState aOldState, TUsbDeviceState aNewState) |
428 { |
403 { |
429 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_USBDEVICESTATECHANGE_ENTRY ); |
404 LOG_FUNC |
430 |
405 |
431 iCurrentState->UsbDeviceStateChange(aLastError, aOldState, aNewState); |
406 iCurrentState->UsbDeviceStateChange(aLastError, aOldState, aNewState); |
432 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_USBDEVICESTATECHANGE_EXIT ); |
|
433 } |
407 } |
434 |
408 |
435 void CUsbBatteryChargingPlugin::HandleRepositoryValueChangedL(const TUid& aRepository, TUint aId, TInt aVal) |
409 void CUsbBatteryChargingPlugin::HandleRepositoryValueChangedL(const TUid& aRepository, TUint aId, TInt aVal) |
436 { |
410 { |
437 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_HANDLEREPOSITORYVALUECHANGEDL_ENTRY ); |
411 LOG_FUNC |
438 |
412 |
439 iCurrentState->HandleRepositoryValueChangedL(aRepository, aId, aVal); |
413 iCurrentState->HandleRepositoryValueChangedL(aRepository, aId, aVal); |
440 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_HANDLEREPOSITORYVALUECHANGEDL_EXIT ); |
|
441 } |
414 } |
442 |
415 |
443 void CUsbBatteryChargingPlugin::DeviceStateTimeout() |
416 void CUsbBatteryChargingPlugin::DeviceStateTimeout() |
444 { |
417 { |
445 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_DEVICESTATETIMEOUT_ENTRY ); |
418 LOG_FUNC |
446 |
419 |
447 iCurrentState->DeviceStateTimeout(); |
420 iCurrentState->DeviceStateTimeout(); |
448 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_DEVICESTATETIMEOUT_EXIT ); |
|
449 } |
421 } |
450 |
422 |
451 void CUsbBatteryChargingPlugin::NegotiateNextCurrentValueL() |
423 void CUsbBatteryChargingPlugin::NegotiateNextCurrentValueL() |
452 { |
424 { |
453 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_NEGOTIATENEXTCURRENTVALUEL_ENTRY ); |
425 LOG_FUNC |
454 |
426 |
455 iDeviceStateTimer->Cancel(); |
427 iDeviceStateTimer->Cancel(); |
456 TUint newCurrent = 0; |
428 TUint newCurrent = 0; |
457 |
429 |
458 if ((iPluginState == EPluginStateIdle) && iCurrentValues.Count() > 0) |
430 if ((iPluginState == EPluginStateIdle) && iCurrentValues.Count() > 0) |
480 } |
452 } |
481 |
453 |
482 RequestCurrentL(newCurrent); |
454 RequestCurrentL(newCurrent); |
483 iRequestedCurrentValue = newCurrent; |
455 iRequestedCurrentValue = newCurrent; |
484 iPluginState = EPluginStateCurrentNegotiating; |
456 iPluginState = EPluginStateCurrentNegotiating; |
485 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_NEGOTIATENEXTCURRENTVALUEL_EXIT ); |
|
486 } |
457 } |
487 |
458 |
488 void CUsbBatteryChargingPlugin::ResetPlugin() |
459 void CUsbBatteryChargingPlugin::ResetPlugin() |
489 { |
460 { |
490 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_RESETPLUGIN_ENTRY ); |
461 LOG_FUNC |
491 |
462 |
492 if((iPluginState != EPluginStateIdle)) |
463 if((iPluginState != EPluginStateIdle)) |
493 { |
464 { |
494 iDeviceStateTimer->Cancel(); // doesn't matter if not running |
465 iDeviceStateTimer->Cancel(); // doesn't matter if not running |
495 iPluginState = EPluginStateIdle; |
466 iPluginState = EPluginStateIdle; |
496 iPluginStateToRecovery = EPluginStateIdle; |
467 iPluginStateToRecovery = EPluginStateIdle; |
497 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_RESETPLUGIN, "CUsbBatteryChargingPlugin::ResetPlugin;PluginState => EPluginStateIdle(%d)", iPluginState ); |
468 LOGTEXT2(_L8("PluginState => EPluginStateIdle(%d)"),iPluginState); |
498 |
469 |
499 iRequestedCurrentValue = 0; |
470 iRequestedCurrentValue = 0; |
500 iCurrentIndexRequested = 0; |
471 iCurrentIndexRequested = 0; |
501 iAvailableMilliAmps = 0; |
472 iAvailableMilliAmps = 0; |
502 SetNegotiatedCurrent(0); |
473 SetNegotiatedCurrent(0); |
503 TRAP_IGNORE(SetInitialConfigurationL()); |
474 TRAP_IGNORE(SetInitialConfigurationL()); |
504 } |
475 } |
505 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_RESETPLUGIN_EXIT ); |
|
506 } |
476 } |
507 |
477 |
508 void CUsbBatteryChargingPlugin::RequestCurrentL(TUint aMilliAmps) |
478 void CUsbBatteryChargingPlugin::RequestCurrentL(TUint aMilliAmps) |
509 { |
479 { |
510 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_ENTRY ); |
480 LOG_FUNC |
511 |
481 |
512 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL, "CUsbBatteryChargingPlugin::RequestCurrentL;aMilliAmps=%u", aMilliAmps ); |
482 LOGTEXT2(_L8(">>CUsbBatteryChargingPlugin::RequestCurrent aMilliAmps = %d"), aMilliAmps); |
513 |
483 |
514 if((EPluginStateCurrentNegotiating == iPluginState) && (iRequestedCurrentValue != aMilliAmps)) |
484 if((EPluginStateCurrentNegotiating == iPluginState) && (iRequestedCurrentValue != aMilliAmps)) |
515 { |
485 { |
516 TInt err; |
|
517 TInt configDescriptorSize = 0; |
486 TInt configDescriptorSize = 0; |
518 err = iLdd.GetConfigurationDescriptorSize(configDescriptorSize); |
487 LEAVEIFERRORL(iLdd.GetConfigurationDescriptorSize(configDescriptorSize)); |
519 if(err < 0) |
|
520 { |
|
521 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP1, "CUsbBatteryChargingPlugin::RequestCurrentL;iLdd.GetConfigurationDescriptorSize(configDescriptorSize) with error=%d", err ); |
|
522 User::Leave(err); |
|
523 } |
|
524 HBufC8* configDescriptor = HBufC8::NewLC(configDescriptorSize); |
488 HBufC8* configDescriptor = HBufC8::NewLC(configDescriptorSize); |
525 TPtr8 ptr(configDescriptor->Des()); |
489 TPtr8 ptr(configDescriptor->Des()); |
526 |
490 |
527 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP2, "CUsbBatteryChargingPlugin::RequestCurrentL;Getting Configuration Descriptor (size = %d)", configDescriptorSize ); |
491 LOGTEXT2(_L8("Getting Configuration Descriptor (size = %d)"),configDescriptorSize); |
528 err = iLdd.GetConfigurationDescriptor(ptr); |
492 LEAVEIFERRORL(iLdd.GetConfigurationDescriptor(ptr)); |
529 if(err < 0) |
|
530 { |
|
531 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP3, "CUsbBatteryChargingPlugin::RequestCurrentL;iLdd.GetConfigurationDescriptor(ptr) with error=%d", err ); |
|
532 User::Leave(err); |
|
533 } |
|
534 |
493 |
535 // set bMaxPower field. One unit = 2mA, so need to halve aMilliAmps. |
494 // set bMaxPower field. One unit = 2mA, so need to halve aMilliAmps. |
536 OstTraceExt2( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP4, "CUsbBatteryChargingPlugin::RequestCurrentL;Setting bMaxPower to %u mA ( = %u x 2mA units)", aMilliAmps, aMilliAmps >> 1 ); |
495 LOGTEXT3(_L8("Setting bMaxPower to %d mA ( = %d x 2mA units)"),aMilliAmps, (aMilliAmps >> 1)); |
537 TUint oldCurrentValue = ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] << 1; |
496 TUint oldCurrentValue = ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] << 1; |
538 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP5, "CUsbBatteryChargingPlugin::RequestCurrentL;(old value was %u mA)", oldCurrentValue ); |
497 LOGTEXT2(_L8("(old value was %d mA)"), oldCurrentValue); |
539 |
498 |
540 //since the device will force reEnumeration if the value is odd |
499 //since the device will force reEnumeration if the value is odd |
541 aMilliAmps = aMilliAmps & 0xFFFE; |
500 aMilliAmps = aMilliAmps & 0xFFFE; |
542 |
501 |
543 // to negotiate a new current value, ReEnumerate is needed |
502 // to negotiate a new current value, ReEnumerate is needed |
544 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP6, "CUsbBatteryChargingPlugin::RequestCurrentL;Forcing ReEnumeration" ); |
503 LOGTEXT(_L8("Forcing ReEnumeration")); |
545 ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] = (aMilliAmps >> 1); |
504 ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] = (aMilliAmps >> 1); |
546 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP7, "CUsbBatteryChargingPlugin::RequestCurrentL;Setting Updated Configuration Descriptor" ); |
505 LOGTEXT(_L8("Setting Updated Configuration Descriptor")); |
547 err = iLdd.SetConfigurationDescriptor(ptr); |
506 LEAVEIFERRORL(iLdd.SetConfigurationDescriptor(ptr)); |
548 if(err < 0) |
507 LOGTEXT(_L8("Triggering Re-enumeration")); |
549 { |
|
550 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP8, "CUsbBatteryChargingPlugin::RequestCurrentL;iLdd.SetConfigurationDescriptor(ptr) with err=%d", err ); |
|
551 User::Leave(err); |
|
552 } |
|
553 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP9, "CUsbBatteryChargingPlugin::RequestCurrentL;Triggering Re-enumeration" ); |
|
554 iDeviceReEnumerator->ReEnumerate(); |
508 iDeviceReEnumerator->ReEnumerate(); |
555 |
509 |
556 CleanupStack::PopAndDestroy(configDescriptor); // configDescriptor |
510 CleanupStack::PopAndDestroy(configDescriptor); // configDescriptor |
557 } |
511 } |
558 |
512 |
559 // Always issue a timer as a watchdog to monitor the request progress |
513 // Always issue a timer as a watchdog to monitor the request progress |
560 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP10, "CUsbBatteryChargingPlugin::RequestCurrentL;Starting timer: %d", User::NTickCount() ); |
514 LOGTEXT2(_L8("Starting timer: %d"), User::NTickCount()); |
561 iDeviceStateTimer->Cancel(); |
515 iDeviceStateTimer->Cancel(); |
562 iDeviceStateTimer->Start(TTimeIntervalMicroSeconds32(KUsbBatteryChargingCurrentRequestTimeout)); |
516 iDeviceStateTimer->Start(TTimeIntervalMicroSeconds32(KUsbBatteryChargingCurrentRequestTimeout)); |
563 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_EXIT ); |
|
564 } |
517 } |
565 |
518 |
566 void CUsbBatteryChargingPlugin::ReadCurrentRequestValuesL() |
519 void CUsbBatteryChargingPlugin::ReadCurrentRequestValuesL() |
567 { |
520 { |
568 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_READCURRENTREQUESTVALUESL_ENTRY ); |
521 LOG_FUNC |
569 |
522 |
570 CRepository* repository = CRepository::NewLC(KUsbBatteryChargingCentralRepositoryUid); |
523 CRepository* repository = CRepository::NewLC(KUsbBatteryChargingCentralRepositoryUid); |
571 |
524 |
572 TInt numberOfCurrents = 0; |
525 TInt numberOfCurrents = 0; |
573 repository->Get(KUsbBatteryChargingKeyNumberOfCurrentValues, numberOfCurrents); |
526 repository->Get(KUsbBatteryChargingKeyNumberOfCurrentValues, numberOfCurrents); |
576 for (i=0; i<numberOfCurrents; i++) |
529 for (i=0; i<numberOfCurrents; i++) |
577 { |
530 { |
578 TInt value; |
531 TInt value; |
579 repository->Get(KUsbBatteryChargingCurrentValuesOffset + i, value); |
532 repository->Get(KUsbBatteryChargingCurrentValuesOffset + i, value); |
580 iCurrentValues.Append(static_cast<TUint>(value)); |
533 iCurrentValues.Append(static_cast<TUint>(value)); |
581 OstTraceExt2( TRACE_FLOW, REF_CUSBBATTERYCHARGINGPLUGIN_READCURRENTREQUESTVALUESL, "CUsbBatteryChargingPlugin::ReadCurrentRequestValuesL;CurrentValue %d = %dmA", i, value ); |
534 LOGTEXT3(_L8("CurrentValue %d = %dmA"),i,value); |
582 } |
535 } |
583 |
536 |
584 CleanupStack::PopAndDestroy(repository); |
537 CleanupStack::PopAndDestroy(repository); |
585 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_READCURRENTREQUESTVALUESL_EXIT ); |
|
586 } |
538 } |
587 |
539 |
588 void CUsbBatteryChargingPlugin::StartCharging(TUint aMilliAmps) |
540 void CUsbBatteryChargingPlugin::StartCharging(TUint aMilliAmps) |
589 { |
541 { |
590 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_STARTCHARGING_ENTRY ); |
542 LOG_FUNC |
591 |
543 |
592 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_STARTCHARGING, "CUsbBatteryChargingPlugin::StartCharging;aMilliAmps=%u", aMilliAmps ); |
544 LOGTEXT2(_L8(">>CUsbBatteryChargingPlugin::StartCharging aMilliAmps = %d"), aMilliAmps); |
593 |
545 |
594 // do licensee specific functionality (if any) |
546 // do licensee specific functionality (if any) |
595 iLicenseeHooks->StartCharging(aMilliAmps); |
547 iLicenseeHooks->StartCharging(aMilliAmps); |
596 |
548 |
597 #ifdef _DEBUG |
549 #ifdef __FLOG_ACTIVE |
598 TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
550 TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
599 KPropertyUidUsbBatteryChargingChargingCurrent, |
551 KPropertyUidUsbBatteryChargingChargingCurrent, |
600 aMilliAmps); |
552 aMilliAmps); |
601 OstTraceExt2( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_STARTCHARGING_DUP1, "CUsbBatteryChargingPlugin::StartCharging;Set P&S current = %umA - err = %d", aMilliAmps, err ); |
553 LOGTEXT3(_L8("Set P&S current = %dmA - err = %d"),aMilliAmps,err); |
602 #else |
554 #else |
603 (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
555 (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
604 KPropertyUidUsbBatteryChargingChargingCurrent, |
556 KPropertyUidUsbBatteryChargingChargingCurrent, |
605 aMilliAmps); |
557 aMilliAmps); |
606 #endif |
558 #endif |
607 |
559 |
608 SetState(EPluginStateCharging); |
560 SetState(EPluginStateCharging); |
609 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_STARTCHARGING_EXIT ); |
|
610 } |
561 } |
611 |
562 |
612 void CUsbBatteryChargingPlugin::StopCharging() |
563 void CUsbBatteryChargingPlugin::StopCharging() |
613 { |
564 { |
614 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_STOPCHARGING_ENTRY ); |
565 LOG_FUNC |
615 |
566 |
616 // do licensee specific functionality (if any) |
567 // do licensee specific functionality (if any) |
617 iLicenseeHooks->StopCharging(); |
568 iLicenseeHooks->StopCharging(); |
618 |
569 |
619 #ifdef _DEBUG |
570 #ifdef __FLOG_ACTIVE |
620 TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
571 TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
621 KPropertyUidUsbBatteryChargingChargingCurrent, |
572 KPropertyUidUsbBatteryChargingChargingCurrent, |
622 0); |
573 0); |
623 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_STOPCHARGING, "CUsbBatteryChargingPlugin::StopCharging;Set P&S current = 0mA - err = %d", err ); |
574 LOGTEXT2(_L8("Set P&S current = 0mA - err = %d"),err); |
624 #else |
575 #else |
625 (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
576 (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
626 KPropertyUidUsbBatteryChargingChargingCurrent, |
577 KPropertyUidUsbBatteryChargingChargingCurrent, |
627 0); |
578 0); |
628 #endif |
579 #endif |
629 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_STOPCHARGING_EXIT ); |
|
630 } |
580 } |
631 |
581 |
632 void CUsbBatteryChargingPlugin::SetNegotiatedCurrent(TUint aMilliAmps) |
582 void CUsbBatteryChargingPlugin::SetNegotiatedCurrent(TUint aMilliAmps) |
633 { |
583 { |
634 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_SETNEGOTIATEDCURRENT_ENTRY ); |
584 LOG_FUNC |
635 |
585 |
636 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETNEGOTIATEDCURRENT, "CUsbBatteryChargingPlugin::SetNegotiatedCurrent;aMilliAmps=%u", aMilliAmps ); |
586 LOGTEXT2(_L8(">>CUsbBatteryChargingPlugin::SetNegotiatedCurrent aMilliAmps = %d"), aMilliAmps); |
637 |
587 |
638 // Ignore errors - not much we can do if it fails |
588 // Ignore errors - not much we can do if it fails |
639 #ifdef _DEBUG |
589 #ifdef __FLOG_ACTIVE |
640 TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
590 TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
641 KPropertyUidUsbBatteryChargingAvailableCurrent, |
591 KPropertyUidUsbBatteryChargingAvailableCurrent, |
642 aMilliAmps); |
592 aMilliAmps); |
643 OstTraceExt2( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETNEGOTIATEDCURRENT_DUP1, "CUsbBatteryChargingPlugin::SetNegotiatedCurrent;Set P&S current = %umA - err = %d", aMilliAmps, err ); |
593 LOGTEXT3(_L8("Set P&S current = %dmA - err = %d"),aMilliAmps,err); |
644 #else |
594 #else |
645 (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
595 (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
646 KPropertyUidUsbBatteryChargingAvailableCurrent, |
596 KPropertyUidUsbBatteryChargingAvailableCurrent, |
647 aMilliAmps); |
597 aMilliAmps); |
648 #endif |
598 #endif |
649 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_SETNEGOTIATEDCURRENT_EXIT ); |
599 } |
650 } |
600 |
651 |
601 |
652 |
602 #ifndef __FLOG_ACTIVE |
653 #ifndef _DEBUG |
|
654 void CUsbBatteryChargingPlugin::LogStateText(TUsbDeviceState /*aState*/) |
603 void CUsbBatteryChargingPlugin::LogStateText(TUsbDeviceState /*aState*/) |
655 { |
604 { |
|
605 LOG_FUNC |
656 } |
606 } |
657 #else |
607 #else |
658 void CUsbBatteryChargingPlugin::LogStateText(TUsbDeviceState aState) |
608 void CUsbBatteryChargingPlugin::LogStateText(TUsbDeviceState aState) |
659 { |
609 { |
660 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_ENTRY ); |
610 LOG_FUNC |
661 |
611 |
662 switch (aState) |
612 switch (aState) |
663 { |
613 { |
664 case EUsbDeviceStateUndefined: |
614 case EUsbDeviceStateUndefined: |
665 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT, "CUsbBatteryChargingPlugin::LogStateText; ***** UNDEFINED *****" ); |
615 LOGTEXT(_L8(" ***** UNDEFINED *****")); |
666 break; |
616 break; |
667 case EUsbDeviceStateDefault: |
617 case EUsbDeviceStateDefault: |
668 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_DUP1, "CUsbBatteryChargingPlugin::LogStateText; ***** DEFAULT *****" ); |
618 LOGTEXT(_L8(" ***** DEFAULT *****")); |
669 break; |
619 break; |
670 case EUsbDeviceStateAttached: |
620 case EUsbDeviceStateAttached: |
671 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_DUP2, "CUsbBatteryChargingPlugin::LogStateText; ***** ATTACHED *****" ); |
621 LOGTEXT(_L8(" ***** ATTACHED *****")); |
672 break; |
622 break; |
673 case EUsbDeviceStatePowered: |
623 case EUsbDeviceStatePowered: |
674 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_DUP3, "CUsbBatteryChargingPlugin::LogStateText; ***** POWERED *****" ); |
624 LOGTEXT(_L8(" ***** POWERED *****")); |
675 break; |
625 break; |
676 case EUsbDeviceStateConfigured: |
626 case EUsbDeviceStateConfigured: |
677 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_DUP4, "CUsbBatteryChargingPlugin::LogStateText; ***** CONFIGURED *****" ); |
627 LOGTEXT(_L8(" ***** CONFIGURED *****")); |
678 break; |
628 break; |
679 case EUsbDeviceStateAddress: |
629 case EUsbDeviceStateAddress: |
680 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_DUP5, "CUsbBatteryChargingPlugin::LogStateText; ***** ADDRESS *****" ); |
630 LOGTEXT(_L8(" ***** ADDRESS *****")); |
681 break; |
631 break; |
682 case EUsbDeviceStateSuspended: |
632 case EUsbDeviceStateSuspended: |
683 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_DUP6, "CUsbBatteryChargingPlugin::LogStateText; ***** SUSPENDED *****" ); |
633 LOGTEXT(_L8(" ***** SUSPENDED *****")); |
684 break; |
634 break; |
685 default: |
635 default: |
686 break; |
636 break; |
687 } |
637 } |
688 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_EXIT ); |
|
689 } |
638 } |
690 #endif |
639 #endif |
691 |
640 |
692 void CUsbBatteryChargingPlugin::MpsoVBusStateChanged(TInt aNewState) |
641 void CUsbBatteryChargingPlugin::MpsoVBusStateChanged(TInt aNewState) |
693 { |
642 { |
694 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOVBUSSTATECHANGED_ENTRY ); |
643 LOG_FUNC |
695 |
644 |
696 iCurrentState->MpsoVBusStateChanged(aNewState); |
645 iCurrentState->MpsoVBusStateChanged(aNewState); |
697 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOVBUSSTATECHANGED_EXIT ); |
|
698 } |
646 } |
699 |
647 |
700 |
648 |
701 // For host OTG enabled charging plug-in |
649 // For host OTG enabled charging plug-in |
702 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
650 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
703 void CUsbBatteryChargingPlugin::MpsoIdPinStateChanged(TInt aValue) |
651 void CUsbBatteryChargingPlugin::MpsoIdPinStateChanged(TInt aValue) |
704 { |
652 { |
705 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOIDPINSTATECHANGED_ENTRY ); |
653 LOG_FUNC |
706 |
654 |
707 iCurrentState->MpsoIdPinStateChanged(aValue); |
655 iCurrentState->MpsoIdPinStateChanged(aValue); |
708 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOIDPINSTATECHANGED_EXIT ); |
|
709 } |
656 } |
710 |
657 |
711 void CUsbBatteryChargingPlugin::MpsoOtgStateChangedL(TUsbOtgState aNewState) |
658 void CUsbBatteryChargingPlugin::MpsoOtgStateChangedL(TUsbOtgState aNewState) |
712 { |
659 { |
713 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOOTGSTATECHANGEDL_ENTRY ); |
660 LOG_FUNC |
714 |
661 |
715 iCurrentState->MpsoOtgStateChangedL(aNewState); |
662 iCurrentState->MpsoOtgStateChangedL(aNewState); |
716 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOOTGSTATECHANGEDL_EXIT ); |
663 } |
717 } |
664 #endif |
718 #endif |
|