void SwitchDebounceCB(void) { bool err = true; // Re-enable switch 1 interrupts err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ1, PDL_INTC_ENABLE|PDL_INTC_CLEAR_IR_FLAG ); // Re-enable switch 2 interrupts err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ3, PDL_INTC_ENABLE|PDL_INTC_CLEAR_IR_FLAG ); // Re-enable switch 3 interrupts err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ4, PDL_INTC_ENABLE|PDL_INTC_CLEAR_IR_FLAG ); while(!err) ; }
void SW3_InterruptCB(void) { bool err = true; uint8_t status = 0x00; // Fetch input edge status err &= R_INTC_GetExtInterruptStatus ( PDL_INTC_IRQ4, &status ); // Check if interrupt was triggered from falling edge if((status & 0x0C) == 0x04) { // Disable switch interrupts and change to rising edge detection err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ4, PDL_INTC_DISABLE|PDL_INTC_RISING ); // Check if switch press callback function is not NULL if(SwitchPressCallbackFunc) { // Execute user callback function SwitchPressCallbackFunc(SWITCH_3); } } else { // Switch to falling edge detection err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ4, PDL_INTC_FALLING ); if(SwitchReleaseCallbackFunc) { SwitchReleaseCallbackFunc(SWITCH_3); } } // Create 10ms one-shot timer interrupt to de-bounce the switch input err &= R_CMT_CreateOneShot ( 1, PDL_NO_DATA, 10E-3, SwitchDebounceCB, 8 ); while(!err) ; }
void Pen_flag() { R_INTC_ControlExtInterrupt( PDL_INTC_IRQ5,PDL_INTC_DISABLE | PDL_INTC_CLEAR_IR_FLAG); R_INTC_CreateExtInterrupt(PDL_INTC_IRQ5,PDL_INTC_LOW ,Pen_flag,1); MainDispaly(); }
/****************************************************************************** * Outline : ControlSwitchInterrupts * Description : Enables or disables the switch IRQ interrupts, based on the * input variable, control. * Argument : bool - true : Enables switch interrupts. * false : Disables switch interrupts. * Return value : none ******************************************************************************/ void ControlSwitchInterrupts(bool control) { /* Declare error flag */ bool err = true; /* Check if control input is true */ if (control) { /* Enable SW1 interrupts */ err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ8, PDL_INTC_ENABLE | PDL_INTC_FALLING ); /* Enable SW2 interrupts */ err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ9, PDL_INTC_ENABLE | PDL_INTC_FALLING ); /* Enable SW3 interrupts */ err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ10, PDL_INTC_ENABLE | PDL_INTC_FALLING ); } /* Control input is false */ else { /* Disable SW1 interrupts */ err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ8, PDL_INTC_DISABLE ); /* Disable SW2 interrupts */ err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ9, PDL_INTC_DISABLE ); /* Disable SW3 interrupts */ err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ10, PDL_INTC_DISABLE ); } /* Halt in while loop when RPDL errors detected */ while (!err); }
/****************************************************************************** * Outline : SwitchDebounceCB * Description : Oneshot timer callback function. This function is triggered * by the timer interrupt, and re-enables switch interrupts. * Argument : none * Return value : none ******************************************************************************/ void SwitchDebounceCB(void) { /* Declare error flag */ bool err = true; /* Check if any switches are held down */ if (!(gSwitchFlag & SWITCHHOLD_ALL)) { /* Set standby ready flag to true */ gSwitchStandbyReady = true; } /* Re-enable switch 1 interrupts */ err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ8, PDL_INTC_ENABLE | PDL_INTC_CLEAR_IR_FLAG ); /* Re-enable switch 2 interrupts */ err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ9, PDL_INTC_ENABLE | PDL_INTC_CLEAR_IR_FLAG ); /* Re-enable switch 3 interrupts */ err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ10, PDL_INTC_ENABLE | PDL_INTC_CLEAR_IR_FLAG ); /* Halt in while loop when RPDL errors detected */ while (!err); }
void Switch_ControlInterrupts(bool control) { bool err = true; if(control) { // Enable SW1 interrupts err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ1, PDL_INTC_ENABLE|PDL_INTC_FALLING ); // Enable SW2 interrupts err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ3, PDL_INTC_ENABLE|PDL_INTC_FALLING ); // Enable SW3 interrupts err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ4, PDL_INTC_ENABLE|PDL_INTC_FALLING ); } else { // Disable SW1 interrupts err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ1, PDL_INTC_DISABLE ); // Disable SW2 interrupts err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ3, PDL_INTC_DISABLE ); // Disable SW3 interrupts err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ4, PDL_INTC_DISABLE ); } while(!err) ; }
/****************************************************************************** * Outline : SW3_InterruptCB * Description : Switch 3 callback ISR function. The function disables switch * interrupts, then uses a oneshot timer to re-enable them after * a 10ms debounce timer period. * Argument : none * Return value : none ******************************************************************************/ void SW3_InterruptCB(void) { /* Declare error flag */ bool err = true; /* Declare status container variable */ uint8_t status = 0x00; /* Fetch input edge status */ err &= R_INTC_GetExtInterruptStatus ( PDL_INTC_IRQ10, &status ); /* Check if interrupt was triggered from falling edge */ if ((status & 0x06) == 0x04) { /* Disable switch interrupts and change to rising edge detection */ err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ10, PDL_INTC_DISABLE | PDL_INTC_RISING ); /* Set global switch flag to indicate SW3 is held down */ gSwitchFlag |= 0x02; /* Check if switch press callback function is not NULL */ if (gSwitchPressCallbackFunc) { /* Execute user callback function */ gSwitchPressCallbackFunc(); } } else { /* Switch to falling edge detection */ err &= R_INTC_ControlExtInterrupt ( PDL_INTC_IRQ10, PDL_INTC_FALLING ); /* Clear SW3 held-down bit in switch flag */ gSwitchFlag &= 0xFD; /* Set global switch flag to indicate SW3 press complete */ gSwitchFlag |= 0x20; /* Check if switch release callback function is not NULL */ if (gSwitchReleaseCallbackFunc) { /* Execute user callback function */ gSwitchReleaseCallbackFunc(); } } /* Set standby ready flag as false */ gSwitchStandbyReady = false; /* Create 10ms one-shot timer interrupt to debounce the switch input */ err &= R_CMT_CreateOneShot ( 1, PDL_NO_DATA, 10E-3, SwitchDebounceCB, 8 ); /* Halt in while loop when RPDL errors detected */ while (!err); }