/**************************************************************************** NAME powerManagerChargerDisconnected DESCRIPTION This function is called when the charger is unplugged from the device RETURNS void */ void powerManagerChargerDisconnected( void ) { PM_DEBUG(("PM: Charger has been disconnected\n")); /* Immediately update charger */ PowerChargerMonitor(); powerManagerUpdateChargeCurrent(); /* Cancel current LED indication */ MessageSend(&theSink.task, EventSysCancelLedIndication, 0); /* Restore default bootmode */ usbSetBootMode(BOOTMODE_DEFAULT); }
/**************************************************************************** NAME usbUpdateChargeCurrent DESCRIPTION Set the charge current based on USB state RETURNS void */ void usbUpdateChargeCurrent(void) { /* Don't change anything if battery charging disabled */ if(USB_CLASS_ENABLED(USB_DEVICE_CLASS_TYPE_BATTERY_CHARGING)) powerManagerUpdateChargeCurrent(); }
/************************************************************************* NAME handlePowerMessage DESCRIPTION handles the Battery/Charger Monitoring Messages RETURNS */ void handlePowerMessage( Task task, MessageId id, Message message ) { switch(id) { case POWER_INIT_CFM: { POWER_INIT_CFM_T* cfm = (POWER_INIT_CFM_T*)message; PM_DEBUG(("PM: POWER_INIT_CFM\n")); if(!cfm->success) Panic(); /* Update VBUS level */ usbSetVbusLevel(cfm->vchg); /* Only indicate if low/critical (or intial reading feature enabled) */ powerManagerHandleVbat(cfm->vbat, battery_level_initial_reading); /* Update charge current based on battery temperature */ if (!powerManagerChargerSetup(&cfm->vthm)) { /* and if the charger was left disabled then handle initial charge state * to notify the app that charger is disabled */ powerManagerHandleChargeState(cfm->state); } } break; case POWER_BATTERY_VOLTAGE_IND: { POWER_BATTERY_VOLTAGE_IND_T* ind = (POWER_BATTERY_VOLTAGE_IND_T*)message; PM_DEBUG(("PM: POWER_BATTERY_VOLTAGE_IND\n")); powerManagerHandleVbat(ind->vbat, battery_level_automatic); usbUpdateChargeCurrent(); } break ; case POWER_CHARGER_VOLTAGE_IND: { PM_DEBUG(("PM: POWER_CHARGER_VOLTAGE_IND\n")); usbSetVbusLevel(((POWER_CHARGER_VOLTAGE_IND_T*)message)->vchg); usbUpdateChargeCurrent(); } break; case POWER_BATTERY_TEMPERATURE_IND: { POWER_BATTERY_TEMPERATURE_IND_T* ind = (POWER_BATTERY_TEMPERATURE_IND_T*)message; PM_DEBUG(("PM: POWER_BATTERY_TEMPERATURE_IND\n")); powerManagerChargerSetup(&ind->vthm); } break; case POWER_CHARGER_STATE_IND: { POWER_CHARGER_STATE_IND_T* ind = (POWER_CHARGER_STATE_IND_T*)message; /* Send event if not using LED overide feature or state is currently not trickle charge */ PM_DEBUG(("PM: POWER_CHARGER_STATE_IND\n")); powerManagerHandleChargeState(ind->state); /* NB. Charger state will not indicate a change from complete to fast. We assume this doesn't matter as we should run from VBUS when complete so battery should not run down */ powerManagerUpdateChargeCurrent(); } break ; default : PM_DEBUG(("PM: Unhandled Battery msg[%x]\n", id)); break ; } }