/*! Configure the pins used for reading the battery state and * charging the battery. */ void InitBattery(void) { // enable the resistor on the interface pins to the battery charger BAT_CHARGE_REN |= BAT_CHARGE_OPEN_DRAIN_BITS; // Start with these as pull downs so we use less current BAT_CHARGE_OUT &= ~BAT_CHARGE_OPEN_DRAIN_BITS; // Set these bits as inputs BAT_CHARGE_DIR &= ~BAT_CHARGE_OPEN_DRAIN_BITS; // charge enable output BAT_CHARGE_DIR |= BAT_CHARGE_ENABLE_PIN; /* turn on the pullup in the MSP430 for the open drain bit of the charger * If the watch has 5V then we don't care about the current draw of the * of the pull down resistor. Otherwise, the charge chip will let * the pin go high */ BAT_CHARGE_OUT |= BAT_CHARGE_PWR_BIT; BATTERY_CHARGE_DISABLE(); InitAdc(); ChargeEnable = pdTRUE; ChargeStatus = CHARGE_STATUS_OFF; }
static int timerChargingControl(TimerHandle timer, void *context) { Timer_Destroy(timer); // Get reading unsigned char BatteryCharging = BAT_CHARGE_IN; // Work out if external power is connected bool powerGood = !(BatteryCharging & BAT_CHARGE_PWR_GOOD); // Work out battery state BatteryCharging &= BAT_CHARGE_STAT1 | BAT_CHARGE_STAT2; unsigned int powerState = BatteryCharging >> 3; if (powerState == BATTERY_CHARGE_OFF_FAULT_SLEEP) { BATTERY_CHARGE_DISABLE(); BAT_CHARGE_OUT &= ~BAT_CHARGE_OPEN_DRAIN_BITS; } // Work out new state Battery_State newState = powerState; if (powerGood) newState |= Battery_Powered; // Launch ADC cycle Adc_Request(adcBatteryLevel, adcBattery, (void*)newState); return 0; }
static void EnterShippingMode(void) { /* Turn off the watchdog timer */ WDTCTL = WDTPW + WDTHOLD; #ifdef DIGITAL ClearLcd(); #endif ConfigResetPin(RST_PIN_ENABLED); __delay_cycles(100000); __disable_interrupt(); __no_operation(); DisableRtosTick(); /* * the radio draws more current in reset than it does after * the patch is loaded */ DISABLE_DISPLAY_POWER(); DISABLE_LCD_ENABLE(); BATTERY_CHARGE_DISABLE(); LIGHT_SENSOR_SHUTDOWN(); BATTERY_SENSE_DISABLE(); HARDWARE_CFG_SENSE_DISABLE(); APPLE_POWER_DISABLE(); ACCELEROMETER_INT_DISABLE(); DISABLE_BUTTONS(); #ifdef DIGITAL /* SHIPPING */ ENABLE_SHIPPING_WAKEUP(); #endif SELECT_ACLK(SELA__REFOCLK); SELECT_FLLREF(SELREF__REFOCLK); UCSCTL8 &= ~SMCLKREQEN; UCSCTL6 |= SMCLKOFF; /* disable aclk */ P11SEL &= ~BIT0; XT1_Stop(); /* turn off the regulator */ PMMCTL0_H = PMMPW_H; PMMCTL0_L = PMMREGOFF; __low_power_mode_4(); __no_operation(); __no_operation(); /* should not get here without a power event */ SoftwareReset(); }
void ToggleCharging(void) { ChargeEnable = !ChargeEnable; PrintString2("- Charge ", ChargeEnable ? "Enabled" : "Disabled"); if (!ChargeEnable) { BATTERY_CHARGE_DISABLE(); BAT_CHARGE_OUT &= ~BAT_CHARGE_STATUS_OPEN_DRAIN_BITS; ChargeStatus = CHARGE_STATUS_OFF; } }
static void EnterShippingMode(void) { /* Turn off the watchdog timer */ WDTCTL = WDTPW | WDTHOLD; EnableRstPin(); __delay_cycles(100000); __disable_interrupt(); __no_operation(); /* * the radio draws more current in reset than it does after * the patch is loaded */ DISABLE_DISPLAY_POWER(); DISABLE_LCD_ENABLE(); BATTERY_CHARGE_DISABLE(); LIGHT_SENSOR_SHUTDOWN(); BATTERY_SENSE_DISABLE(); HARDWARE_CFG_SENSE_DISABLE(); APPLE_POWER_DISABLE(); ACCELEROMETER_INT_DISABLE(); DISABLE_BUTTONS(); SELECT_ACLK(SELA__REFOCLK); SELECT_FLLREF(SELREF__REFOCLK); UCSCTL8 &= ~SMCLKREQEN; UCSCTL6 |= SMCLKOFF; /* disable aclk */ P11SEL &= ~BIT0; XT1_Stop(); /* turn off the regulator */ unsigned char temp = PMMCTL0_L; PMMCTL0_H = PMMPW_H; PMMCTL0_L = PMMREGOFF | temp; LPM4; __no_operation(); __no_operation(); /* should not get here without a power event */ SoftwareReset(); }