/*! Disable the button debounce ISR when all buttons are in the off state. */ static void CheckForAllButtonsOff( ) { unsigned char btnIndex; unsigned char AllButtonsOff = 1; // Go through the array of button structs looking for any buttons that are // still on the on (not off) state. for(btnIndex = 0; btnIndex < NUMBER_OF_BUTTONS; btnIndex++) { if(ButtonData[btnIndex].BtnState != BUTTON_STATE_OFF) { AllButtonsOff = 0; break; } } // If all the buttons are off then stop the ISR if(AllButtonsOff) { PrintString("AllButtonsOff\r\n"); DisableRtcPrescaleInterruptUser(RTC_TIMER_BUTTON); } }
/* * Once the phone has started a vibration event this controls the pulsing * on and off. * * This requires < 7 us and is done in the ISR */ void VibrationMotorStateMachineIsr(void) { VibeEventTimerCount++; // If we have an active event if( VibeEventActive ) { // is it time for the next action if(VibeEventTimerCount >= nextActionTime) { // if the motor is currently on if(motorOn) { motorOn = pdFALSE; nextActionTime += timeOff; if ( cycleCount > 1 ) { cycleCount --; } else /* last cycle */ { VibeEventActive = pdFALSE; DisableRtcPrescaleInterruptUser(RTC_TIMER_VIBRATION); DisableVibratorPwm(); } } else { motorOn = pdTRUE; nextActionTime += timeOn; } } // Set/clean the port bit that controls the motor SetVibeMotorState(motorOn); } else { DisableRtcPrescaleInterruptUser(RTC_TIMER_VIBRATION); DisableVibratorPwm(); } }
/* Handle the message from the host that starts a vibration event */ void SetVibrateModeHandler(tHostMsg* pMsg) { // overlay a structure pointer on the data section tSetVibrateModePayload* pMsgData; pMsgData = (tSetVibrateModePayload*) pMsg->pPayload; // set it active or cancel it VibeEventActive = pMsgData->Enable; // save the parameters from the message motorOn = pMsgData->Enable; tWordByteUnion temp; temp.byte0 = pMsgData->OnDurationLsb; temp.byte1 = pMsgData->OnDurationMsb; timeOn = temp.word / RTC_TIMER_MS_PER_TICK; temp.byte0 = pMsgData->OffDurationLsb; temp.byte1 = pMsgData->OffDurationMsb; timeOff = temp.word / RTC_TIMER_MS_PER_TICK; cycleCount = pMsgData->NumberOfCycles; // Start or stop the RTC PS timer based on whether the motor is being turned // on or off if ( VibeEventActive ) { EnableRtcPrescaleInterruptUser(RTC_TIMER_VIBRATION); EnableVibratorPwm(); } else { DisableRtcPrescaleInterruptUser(RTC_TIMER_VIBRATION); DisableVibratorPwm(); } // Use a separate timer that counts Rtc_Prescale_Timer_Static messages to // get the time for the vibe motor. if(VibeEventActive) { VibeEventTimerCount = 0; timeStart = 0; } // the next event is to turn nextActionTime = timeStart + timeOn; // Set/clear the port bit that controls the motor SetVibeMotorState(motorOn); }
/* * This part has a problem turning off the SMCLK when the uart is IDLE. * * manually turn off the clock after the last character is sent * * count more than one interrupt because we don't know when the first one * will happen */ void DisableUartSmClkIsr(void) { DisableSmClkCounter++; if ( DisableSmClkCounter > 2 ) { if ( TxBusy == 0 ) { DisableSmClkUser(BT_DEBUG_UART_USER); } /* if we are transmitting again then disable this timer */ DisableRtcPrescaleInterruptUser(RTC_TIMER_USER_DEBUG_UART); } }