void __ISR(_TIMER_4_VECTOR, IPL2SOFT) tick_timer_isr() { INTClearFlag(INT_T4); ColourEngine::Tick(); //toggle(PIO_LED2); // Power toggle if (_PORT(PIO_BTN1) == HIGH) { last_btn1 = HIGH; } else if (last_btn1 == HIGH) { last_btn1 = LOW; power = (power == OFF) ? ON : OFF; ColourEngine::SetPower(power, 1000); } // Switch mode if (_PORT(PIO_BTN2) == HIGH) { last_btn2 = HIGH; } else if (last_btn2 == HIGH) { last_btn2 = LOW; if (mode++ == (int)ColourEngine::NUM_MODES-1) mode = 0; ColourEngine::SetMode(static_cast<ColourEngine::mode_t>(mode), Q15(0.0001)); } }
void ProcessPowerMonitor() { // For debugging bq25010_status = (USB_VBUS_SENSE << 2) | (_PORT(PW_STAT1) << 1) | (_PORT(PW_STAT2)); // Determine current power state if (USB_VBUS_SENSE) { if (_PORT(PW_STAT1) == 0) power_status = pwCharging; else { if (_PORT(PW_STAT2) == 0) power_status = pwCharged; else power_status = pwBattery; // Actually Fault } } else { power_status = pwBattery; } // Read battery voltage (and VDD) adc_SetCallback(AN_VBAT, cb_ConvertedVBat); adc_StartConversion(AN_VBAT); /*uint level; // Convert the two STAT pins into a byte, then typecast directly to the charge_status enum #ifdef _MSC_VER // charge_status is updated through interface.h in win32 #else charge_status = (charge_status_t)( (_PORT(PW_STAT1) << 1) | _PORT(PW_STAT2) ); #endif battery_voltage = 0; //ReadAdc(AN_VBAT_CHANNEL) * 2; // The battery voltage is divided by 2 //TODO: Average the battery voltage // Check battery voltage if (battery_voltage < BATTERY_MIN_THRESHOLD - HYSTERESIS) { battery_good = FALSE; //TODO: Put the watch into a battery sleep mode, but allow it to // wake up if a button is pushed or if it is plugged into USB. } else if (battery_voltage > BATTERY_MIN_THRESHOLD + HYSTERESIS) { battery_good = TRUE; } // battery_status is only used to indicate the battery is "flat", so // the watch will turn itself off to save power. // Convert the battery voltage to a percentage that can be displayed level = battery_voltage - BATTERY_0_VOLTAGE; level = level / (BATTERY_100_VOLTAGE - BATTERY_0_VOLTAGE); battery_level = level; // Atomic write */ }
int main(void) { InitializeSystem(); // Wait for reset button to be released while (_PORT(PIO_BTN1) == HIGH) { } //ADCInitialize(); PWMInitialize(); PWMEnable(); USBDeviceInit(); //ADCStartCapture(); _LAT(PIO_LED1) = HIGH; ColourEngine::Initialize(); //ColourEngine::PowerOn(1000); // Fade in ColourEngine::SetPower(power, 0); //_LAT(PIO_LED2) = HIGH; while (1) { USBDeviceTasks(); USBUserProcess(); } return 0; }
////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// // // InputsInit - Initialize inputs // // Inputs: None. // // Outputs: None. // void InputsInit(void) { _SET_BIT(PCMSK_I1,PCINT_I1); _SET_BIT(PCMSK_I2,PCINT_I2); _CLR_BIT( _DDR(INPUT_I1_PORT),INPUT_I1_BIT); // Inputs are inputs _SET_BIT(_PORT(INPUT_I1_PORT),INPUT_I1_BIT); // With internal pullup _CLR_BIT( _DDR(INPUT_I2_PORT),INPUT_I2_BIT); // Inputs are inputs _SET_BIT(_PORT(INPUT_I2_PORT),INPUT_I2_BIT); // With internal pullup Input1Changed = false; Input2Changed = false; Input1On = INPUT1_PIN; Input2On = INPUT2_PIN; Input1Debounce = 0; Input2Debounce = 0; }
uint8 GetChargeStatus() { return (USB_VBUS_SENSE << 2) | (_PORT(PW_STAT1) << 1) | (_PORT(PW_STAT2)); }
// // BuzzerSet - Turn on buzzer // // Inputs: TRUE to set buzzer ON // FALSE otherwise // // Outputs: None. // void BuzzerSet(bool Set) { if( Set ) { _SET_BIT(_PORT(BUZZER_PORT),BUZZER_BIT); } else { _CLR_BIT(_PORT(BUZZER_PORT),BUZZER_BIT); } }
////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// // // BuzzerInit - Initialize buzzer // // Inputs: None. // // Outputs: None. // void BuzzerInit(void) { _SET_BIT( _DDR(BUZZER_PORT),BUZZER_BIT); // Set as output _CLR_BIT(_PORT(BUZZER_PORT),BUZZER_BIT); // Set low for now }