Beispiel #1
0
static void irq_port0_line3(void) {
  //  print_dbg("\r\n interrupt on port0_line3");
  //SW_F0
  if(gpio_get_pin_interrupt_flag(SW0_PIN)) {
    gpio_clear_pin_interrupt_flag(SW0_PIN);
    /// process_sw() will post an event, which calls cpu_irq_disable().
    /// apparently, this also clears the GPIO interrupt flags
    /// so clear the flag first to avoid triggering an infinite series of interrupts.
    /// this might be problematic if we were expecting faster interrupts from switches,
    /// but hardware pre-filtering should preclude this.
    process_sw(0);
  }
  // SW_F1
  if(gpio_get_pin_interrupt_flag(SW1_PIN)) {
    gpio_clear_pin_interrupt_flag(SW1_PIN);
    process_sw(1);
  }
  // SW_F2
  if(gpio_get_pin_interrupt_flag(SW2_PIN)) {
    gpio_clear_pin_interrupt_flag(SW2_PIN);
    process_sw(2);
  }
 
  // SW_F3
  if(gpio_get_pin_interrupt_flag(SW3_PIN)) {
    gpio_clear_pin_interrupt_flag(SW3_PIN);
    process_sw(3);
  }
  // SW_MODE
  if(gpio_get_pin_interrupt_flag(SW_MODE_PIN)) {
    gpio_clear_pin_interrupt_flag(SW_MODE_PIN);
    process_sw(4);
  }
}
Beispiel #2
0
static void irq_port1_line1(void) {
    // print_dbg("\r\ninterrupt on PB08-PB15.");

    // clock norm
    // if(gpio_get_pin_interrupt_flag(B10)) {

    //   static event_t e;
    //   e.type = kEventTrNormal;
    //   e.data = !gpio_get_pin_value(B10);
    //   event_post(&e);
    //   gpio_clear_pin_interrupt_flag(B10);
    // }

    // clock in
    if(gpio_get_pin_interrupt_flag(B08)) {
      static event_t e;
      e.type = kEventTr;
      e.data = gpio_get_pin_value(B08);
      event_post(&e);
      gpio_clear_pin_interrupt_flag(B08);
    }

    // tr in
    if(gpio_get_pin_interrupt_flag(B09)) {
      static event_t e;
      e.type = kEventTr;
      e.data = gpio_get_pin_value(B09) + 2;
      event_post(&e);
      gpio_clear_pin_interrupt_flag(B09);
    }

}
Beispiel #3
0
static void irq_port1_line1(void) {
    // print_dbg("\r\ninterrupt on PB08-PB15.");

    // static event_t e;   
    // e.type = kSwitchEvents[swIdx];
    // e.data = gpio_get_pin_value(kSwitchPins[swIdx]); 
    // event_post(&e);

    // clock norm
    if(gpio_get_pin_interrupt_flag(B09)) {

      static event_t e;
      e.type = kEventClockNormal;
      e.data = !gpio_get_pin_value(B09);
      event_post(&e);

      gpio_clear_pin_interrupt_flag(B09);
    }

    // clock in
    if(gpio_get_pin_interrupt_flag(B08)) {
      // CLOCK BOUNCY WITHOUT THESE PRINTS
      // print_dbg("\rclk: ");
      // print_dbg_ulong(gpio_get_pin_value(B08));
      // (*clock_pulse)(gpio_get_pin_value(B08));
      static event_t e;
      e.type = kEventClockExt;
      e.data = gpio_get_pin_value(B08);
      event_post(&e);
      gpio_clear_pin_interrupt_flag(B08);
    }
}
Beispiel #4
0
static void irq_port1_line3(void) {
  //  print_dbg("\r\n irq_port1_line3");
  if(gpio_get_pin_interrupt_flag(FS0_PIN)) {
    gpio_clear_pin_interrupt_flag(FS0_PIN);
    process_sw(6);
  }
  if(gpio_get_pin_interrupt_flag(FS1_PIN)) {
    gpio_clear_pin_interrupt_flag(FS1_PIN);
    process_sw(7);
  }
}
Beispiel #5
0
static void irq_port1_line1(void) {
  //    print_dbg("\r\b\interrupt on PB08-PB15.");
  // ENC3_0
  if(gpio_get_pin_interrupt_flag(ENC3_S0_PIN)) {
    process_enc(3);
    gpio_clear_pin_interrupt_flag(ENC3_S0_PIN);
  }  
  // ENC3_1
  if(gpio_get_pin_interrupt_flag(ENC3_S1_PIN)) {
    process_enc(3);
    gpio_clear_pin_interrupt_flag(ENC3_S1_PIN);
  }

}
Beispiel #6
0
/*! \internal Sensor Board GPIO interrupt handler
 *
 * This is the default ISR for the Xplained Sensor board GPIO pins.  If
 * an external interrupt interface is available, the corresponding
 * eic_pinX_handler will be used instead.
 *
 * \return  Nothing.
 */
ISR(gpio_irq_handler, AVR32_GPIO_IRQ_GROUP, GPIO_INT_LVL)
{
	if (gpio_get_pin_interrupt_flag(SENSOR_BOARD_PIN3)) {
		sensor_pin3_handler(sensor_pin3_arg);

		gpio_clear_pin_interrupt_flag(SENSOR_BOARD_PIN3);
	} else if (gpio_get_pin_interrupt_flag(SENSOR_BOARD_PIN4)) {
		sensor_pin4_handler(sensor_pin4_arg);

		gpio_clear_pin_interrupt_flag(SENSOR_BOARD_PIN4);
	} else if (gpio_get_pin_interrupt_flag(SENSOR_BOARD_PIN5)) {
		sensor_pin5_handler(sensor_pin5_arg);

		gpio_clear_pin_interrupt_flag(SENSOR_BOARD_PIN5);
	}
}
Beispiel #7
0
__interrupt
#endif
static void dip204_example_Joy_int_handler(void)
{
  if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_UP))
  {
    dip204_set_cursor_position(19,1);
    dip204_write_data(0xDE);
    display = 1;
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_UP);
  }
  if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_DOWN))
  {
    dip204_set_cursor_position(19,3);
    dip204_write_data(0xE0);
    display = 1;
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_DOWN);
  }
  if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_LEFT))
  {
    dip204_set_cursor_position(18,2);
    dip204_write_data(0xE1);
    display = 1;
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_LEFT);
  }
  if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT))
  {
    dip204_set_cursor_position(20,2);
    dip204_write_data(0xDF);
    display = 1;
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT);
  }
  if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_PUSH))
  {
    dip204_set_cursor_position(19,2);
    dip204_write_data(0xBB);
    dip204_set_cursor_position(1,4);
    dip204_write_string("  AT32UC3A Series   ");
    display = 1;
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_PUSH);
  }
}
Beispiel #8
0
static void irq_port1_line2(void) {
  //  print_dbg("\r\n interrupt on pb16-pb23 : ");
  //SW_POWER
  if(gpio_get_pin_interrupt_flag(SW_POWER_PIN)) {
    gpio_clear_pin_interrupt_flag(SW_POWER_PIN);
    process_sw(5);
  }
}
Beispiel #9
0
static void interrupt_J3(void) 
{ 
		

		if ((gpio_get_pin_interrupt_flag(TEST_A))){
			gpio_clear_pin_interrupt_flag(TEST_A);
			A = true;
		}
		if ((gpio_get_pin_interrupt_flag(TEST_B))){
			gpio_clear_pin_interrupt_flag(TEST_B);
			B = true;
		}
		if ((gpio_get_pin_interrupt_flag(TEST_C))){
			gpio_clear_pin_interrupt_flag(TEST_C);
			C = true;
			
		}
}
Beispiel #10
0
static void irq_port0_line1(void) {
    if(gpio_get_pin_interrupt_flag(NMI)) {
      gpio_clear_pin_interrupt_flag(NMI);
      // print_dbg("\r\n ### NMI ### ");
      static event_t e;
      e.type = kEventFront;
      e.data = gpio_get_pin_value(NMI);
      event_post(&e);
    }
}
Beispiel #11
0
__interrupt
#endif
static void dip204_example_PB_int_handler(void)
{
unsigned short i;

  /* display all available chars */
  if (gpio_get_pin_interrupt_flag(GPIO_CHARSET))
  {
    /* go to first column of 4th line */
    dip204_set_cursor_position(1,4);
    /* display 20 chars of charmap */
    for (i = current_char; i < current_char + 0x10; i++)
    {
      dip204_write_data(i);
    }
    dip204_write_string("    ");
    /* mark position in charmap */
    current_char = i;
    /* reset marker */
    if (current_char >= 0xFF)
    {
      current_char = 0x10;
    }
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_CHARSET);
  }
  /* increase backlight power */
  if (gpio_get_pin_interrupt_flag(GPIO_BACKLIGHT_PLUS))
  {
    dip204_set_backlight(backlight_power_increase);
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_BACKLIGHT_PLUS);
  }
  /* decrease backlight power */
  if (gpio_get_pin_interrupt_flag(GPIO_BACKLIGHT_MINUS))
  {
    dip204_set_backlight(backlight_power_decrease);
    /* allow new interrupt : clear the IFR flag */
    gpio_clear_pin_interrupt_flag(GPIO_BACKLIGHT_MINUS);
  }
}
Beispiel #12
0
static void interrupt_J3(void)
{
	if (gpio_get_pin_interrupt_flag(TEST_A)){
		A_FLAG = true;
		gpio_clear_pin_interrupt_flag(TEST_A);

	}
	
	else if(gpio_get_pin_interrupt_flag(TEST_B)){
		B_FLAG = true;
		gpio_clear_pin_interrupt_flag(TEST_B);
	}
	
	else if(gpio_get_pin_interrupt_flag(TEST_C)){
		C_FLAG = true;
		gpio_clear_pin_interrupt_flag(TEST_C);
	}
	

}
Beispiel #13
0
__interrupt
#endif
void at42qt1060_detect_int_handler(void)
{
  if(gpio_get_pin_interrupt_flag(AT42QT1060_DETECT_PIN))
  {
    gpio_clear_pin_interrupt_flag(AT42QT1060_DETECT_PIN);
    if(at42qt1060.touch_detect_callback)
    	at42qt1060.touch_detect_callback();
  }
}
Beispiel #14
0
static portBASE_TYPE prvpushb_ISR_NonNakedBehaviour( void )
{
  if (gpio_get_pin_interrupt_flag(GPIO_PUSH_BUTTON_0))
  {
    // set the flag
    bSendMail = pdTRUE;
    // allow new interrupt : clear the IFR flag
    gpio_clear_pin_interrupt_flag(GPIO_PUSH_BUTTON_0);
  }
  // no context switch required, task is polling the flag
  return( pdFALSE );
}
Beispiel #15
0
static void irq_port1_line0(void) {
  // print_dbg("\r\b\interrupt on PB00-PB07.");
  // ENC0_0
  if(gpio_get_pin_interrupt_flag(ENC0_S0_PIN)) {
    process_enc(0);
    gpio_clear_pin_interrupt_flag(ENC0_S0_PIN);
  }  
  // ENC0_1
  if(gpio_get_pin_interrupt_flag(ENC0_S1_PIN)) {
    process_enc(0);
    gpio_clear_pin_interrupt_flag(ENC0_S1_PIN);
  }
  // ENC1_0
  if(gpio_get_pin_interrupt_flag(ENC1_S0_PIN)) {
    process_enc(1);
    gpio_clear_pin_interrupt_flag(ENC1_S0_PIN);
  }  
  // ENC1_1
  if(gpio_get_pin_interrupt_flag(ENC1_S1_PIN)) {
    process_enc(1);
    gpio_clear_pin_interrupt_flag(ENC1_S1_PIN);
  }
  // ENC2_0
  if(gpio_get_pin_interrupt_flag(ENC2_S0_PIN)) {
    process_enc(2);
    gpio_clear_pin_interrupt_flag(ENC2_S0_PIN);
  }  
  // ENC2_1
  if(gpio_get_pin_interrupt_flag(ENC2_S1_PIN)) {
    process_enc(2);
    gpio_clear_pin_interrupt_flag(ENC2_S1_PIN);
  }
}
Beispiel #16
0
static inline void manage_button_isr(int pin, enum joystick_status_t status_pressed, enum joystick_status_t status_released)
{
  if (gpio_get_pin_interrupt_flag(pin))
  {
    // Clear current pin status
    joystick_status &= ~(status_pressed | status_released);
    if (gpio_get_pin_value(pin))
      joystick_status |= status_pressed;
    else
      joystick_status |= status_released;
    gpio_clear_pin_interrupt_flag(pin);
  }
}
Beispiel #17
0
__interrupt
#endif
#if(INT_MODE == INT_MODE_GPIO)
void touch_button_isr(void){
	// UP
	if(gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_0))
	{
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_0);
		gpio_tgl_gpio_pin(LED0_GPIO);
	}
	// DOWN
	if(gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_1))
	{
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_1);
		gpio_tgl_gpio_pin(LED1_GPIO);
	}
	// Right
	if(gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_2))
	{
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_2);
		gpio_tgl_gpio_pin(LED2_GPIO);
	}
	// Left
	if(gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_3))
	{
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_3);
		gpio_tgl_gpio_pin(LED3_GPIO);
	}
	// Push
	if(gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_4))
	{
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_4);
		gpio_tgl_gpio_pin(LED0_GPIO);
	}

}
Beispiel #18
0
__interrupt
#endif
void push_button_interrupt_handler(void)
{
	if (gpio_get_pin_interrupt_flag(GPIO_PUSH_BUTTON_1))
	{
		// Switch to next state based on current state
		switch (state_indicator)
		{
			case STATE_1:
			state_indicator = STATE_2;
			break;
			case STATE_2:
			state_indicator = STATE_1;
			break;
		}
		
		// Set run_once variable to true
		run_once = TRUE;
		
		// Clear interrupt flag to allow new interrupts
		gpio_clear_pin_interrupt_flag(GPIO_PUSH_BUTTON_1);
	}
}
void init_PWM(int velocidad, int direccion){
	int auxiliar;
	switch(velocidad){
		case 9:
			auxiliar = 2;
			break;
		case 8:
			auxiliar = 4;
			break;
		case 7:
			auxiliar = 6;
			break;
		case 6:
			auxiliar = 8;
			break;
		case 5:
			auxiliar = 10;
			break;
		case 4:
			auxiliar = 12;
			break;
		case 3:
			auxiliar = 14;
			break;
		case 2:
			auxiliar = 16;
			break;
		case 1:
			auxiliar = 18;
			break;
	}//SWITCH
	pwm_opt_t pwm_opt =
	{
		.diva = AVR32_PWM_DIVA_CLK_OFF,
		.divb = AVR32_PWM_DIVB_CLK_OFF,
		.prea = AVR32_PWM_PREA_MCK,
		.preb = AVR32_PWM_PREB_MCK
	};
	
	avr32_pwm_channel_t pwm_channel = { .ccnt = 0 };
		pwm_channel.cdty = auxiliar; /* Channel duty cycle, should be < CPRD. */
		pwm_channel.cprd = 20; /* Channel period. */
		pwm_channel.cupd = 0; /* Channel update is not used here. */
		pwm_channel.CMR.calg = PWM_MODE_LEFT_ALIGNED; /* Channel mode. */
		pwm_channel.CMR.cpol = PWM_POLARITY_LOW;      /* Channel polarity. */
		pwm_channel.CMR.cpd = PWM_UPDATE_DUTY;        /* Not used the first time. */
		pwm_channel.CMR.cpre = AVR32_PWM_CPRE_MCK_DIV_256; /* Channel prescaler. */
		
		gpio_enable_module_pin(PWM_PIN_3, PWM_PIN_Function);
		gpio_enable_module_pin(PWM_PIN_1, PWM_PIN_Function);
		pwm_init(&pwm_opt);
		if(direccion == 1){//FORWARD
			pwm_channel_init(PWM_ID_3, &pwm_channel);
			pwm_start_channels(1 << PWM_ID_3);

		}
		if(direccion == 0){//REVERSE
			pwm_channel_init(PWM_ID_1, &pwm_channel);
			pwm_start_channels(1 << PWM_ID_1);
		}
}
void update_PWM(int velocidad, int direccion){
	int auxiliar;
	switch(velocidad){
		case 9:
		auxiliar = 2;
		break;
		case 8:
		auxiliar = 4;
		break;
		case 7:
		auxiliar = 6;
		break;
		case 6:
		auxiliar = 8;
		break;
		case 5:
		auxiliar = 10;
		break;
		case 4:
		auxiliar = 12;
		break;
		case 3:
		auxiliar = 14;
		break;
		case 2:
		auxiliar = 16;
		break;
		case 1:
		auxiliar = 18;
		break;
	}//SWITCH
		avr32_pwm_channel_t pwm_channel = { .ccnt = 0 };
		pwm_channel.cdty = auxiliar; /* Channel duty cycle, should be < CPRD. */
		pwm_channel.cprd = 20; /* Channel period. */
		pwm_channel.cupd = 0; /* Channel update is not used here. */
		pwm_channel.CMR.calg = PWM_MODE_LEFT_ALIGNED; /* Channel mode. */
		pwm_channel.CMR.cpol = PWM_POLARITY_LOW;      /* Channel polarity. */
		pwm_channel.CMR.cpd = PWM_UPDATE_DUTY;        /* Not used the first time. */
		pwm_channel.CMR.cpre = AVR32_PWM_CPRE_MCK_DIV_256; /* Channel prescaler. */
	
	if(direccion == 1){//FORWARD
		pwm_stop_channels(1<<PWM_ID_1);
		pwm_stop_channels(1<<PWM_ID_3);
		pwm_channel_init(PWM_ID_3, &pwm_channel);
		pwm_start_channels(1 << PWM_ID_3);
		
	}
	if(direccion == 0){//REVERSE
		pwm_stop_channels(1<<PWM_ID_1);
		pwm_stop_channels(1<<PWM_ID_3);
		pwm_channel_init(PWM_ID_1, &pwm_channel);
		pwm_start_channels(1 << PWM_ID_1);
	}
	bandera = 0;
}
static void handler_interrupt(void){
	if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_UP)){
		direccion = 1;
		gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_UP);
	}
	if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_DOWN)){
		direccion = 0;
		gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_DOWN);
	}
	bandera = 1;
}
void init_INTC(void){
	gpio_enable_pin_interrupt(GPIO_JOYSTICK_UP , GPIO_FALLING_EDGE);
	gpio_enable_pin_interrupt(GPIO_JOYSTICK_DOWN , GPIO_FALLING_EDGE);
	Disable_global_interrupt();
	INTC_init_interrupts();
	  INTC_register_interrupt( &handler_interrupt, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_UP/8), AVR32_INTC_INT1);
	  INTC_register_interrupt( &handler_interrupt, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_DOWN/8), AVR32_INTC_INT1);
	Enable_global_interrupt();
}
Beispiel #20
0
__attribute__ ((__interrupt__)) void tecla_lrc_isr(void){//handler teclas left, right o center
	
	
	

	if (gpio_get_pin_interrupt_flag (QT1081_TOUCH_SENSOR_LEFT))
	{
		
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_LEFT);
		//LastRectX=RectX;
		#if	PRACTICA == 2
		
		if (actividad==0)
		{
			while(gpio_get_pin_value(QT1081_TOUCH_SENSOR_LEFT)){
				et024006_DrawFilledRect(RectX , RectY, 30, 30, BLACK);//borra la posicion pasada
				RectX+=2;
				et024006_DrawFilledRect(RectX , RectY, 30, 30, RED);
				delay_ms(10);
				
			}
			
		}
		#endif
		
		
		
	}

	if (gpio_get_pin_interrupt_flag (QT1081_TOUCH_SENSOR_RIGHT))
	{
		
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_RIGHT);
		//LastRectX=RectX;
		if (actividad != 1)
		{
			actividad = 1; //te lleva al reloj
			CLR_disp();
		}
		
		
		
		#if PRACTICA == 2
		if (actividad==0)
		{
			while(gpio_get_pin_value(QT1081_TOUCH_SENSOR_RIGHT)){
				et024006_DrawFilledRect(RectX , RectY, 30, 30, BLACK);//borra la posicion pasada
				RectX-=2;
				et024006_DrawFilledRect(RectX , RectY, 30, 30, RED);
				delay_ms(10);
			}
			
		}
		
		#endif
	}
	if (gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_UP))
	{
				gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_UP);
				
				
				if (actividad==2)//cronometro
				{
					resetTimer=1;
				}
				
				if (actividad != 2)
				{
					actividad = 2; //te lleva al cronometro
					CLR_disp();
				}
				
				
				
				#if PRACTICA == 2
				
				//LastRectY=RectY;
				if (actividad==0)
				{
					while(gpio_get_pin_value(QT1081_TOUCH_SENSOR_UP)){
						et024006_DrawFilledRect(RectX , RectY, 30, 30, BLACK);//borra la posicion pasada
						RectY+=2;
						et024006_DrawFilledRect(RectX , RectY, 30, 30, RED);
						delay_ms(10);
						
						
					}
					
				}
				#endif
		     
			  
	}
	
	if (gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_DOWN))
	{
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_DOWN);
		if (actividad !=0)
		{
			actividad = 0; //te lleva al pong
			CLR_disp();
		}
		
		
		
		#if PRACTICA == 2
		//LastRectY=RectY;
		if (actividad==0)
		{
			while(gpio_get_pin_value(QT1081_TOUCH_SENSOR_DOWN)){
				
				et024006_DrawFilledRect(RectX , RectY, 30, 30, BLACK);//borra la posicion pasada
				RectY-=2;
				et024006_DrawFilledRect(RectX , RectY, 30, 30, RED);
				delay_ms(10);
			}
			
		}
		#endif
		
	}
	
	if (gpio_get_pin_interrupt_flag (QT1081_TOUCH_SENSOR_ENTER))
	{
		
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER);
		//LastRectX=RectX;
		#if PRACTICA == 2
		enter=0;
		#endif
		if (actividad==2)
		{
			go^=(1<<0);//toggle al go del cronometro
		}
		
		if (actividad==1)
		{
			enter^=(1<<0);
		}
		
		
	}
	
	

}
Beispiel #21
0
static portBASE_TYPE prvpushb_ISR_NonNakedBehaviour( void )
{
xLogDef *pxLog;
portBASE_TYPE xSwitchRequired = pdFALSE;

  /* depending on the push buttons */
  if (gpio_get_pin_interrupt_flag(PB1_POSITION))
  {
      /* input is pulled up, if 1 : input is not active */
      if (gpio_get_pin_value(PB1_POSITION))
      {
         b_pushb1 = PUSHB_EVENT_RELEASE;
      }
      else
      {
         b_pushb1 = PUSHB_EVENT_PRESS;
         if ( bAlarm1 == pdTRUE )
         {
           // post alarm to SMTP task
           v_SMTP_PostFromISR("Push Button 1 Alarm", NULL);
         }
      }
      // Alloc and init a log.
      pxLog = pxdatalog_log_alloc_init_FromISR();
      if( NULL != pxLog )
      {
         // Init the id field of the log.
         pxLog->id = DATALOG_ID_PB1;
         /* set log event string */
         pxLog->pcStringLog = (portCHAR *)acpc_pushb_events[b_pushb1];
         /* set free function pointer */
         pxLog->pfFreeStringLog = NULL;
         /* add the log entry */
         xSwitchRequired = x_datalog_AddLogFromISR( pxLog );
      }
      /* allow new interrupt : clear the IFR flag */
      gpio_clear_pin_interrupt_flag(PB1_POSITION);
  }
  if (gpio_get_pin_interrupt_flag(PB2_POSITION))
  {
      /* input is pulled up, if 1 : input is not active */
      if (gpio_get_pin_value(PB2_POSITION))
      {
         b_pushb2 = PUSHB_EVENT_RELEASE;
      }
      else
      {
         b_pushb2 = PUSHB_EVENT_PRESS;
         if ( bAlarm2 == pdTRUE )
         {
           // post alarm to SMTP task
           v_SMTP_PostFromISR("Push Button 2 Alarm", NULL);
         }
      }
      // Alloc and init a log.
      pxLog = pxdatalog_log_alloc_init_FromISR();
      if( NULL != pxLog )
      {
         // Init the id field of the log.
         pxLog->id = DATALOG_ID_PB2;
         /* set log event string */
         pxLog->pcStringLog = (portCHAR *)acpc_pushb_events[b_pushb2];
         /* set free function pointer */
         pxLog->pfFreeStringLog = NULL;
         /* add the log entry */
         xSwitchRequired = x_datalog_AddLogFromISR( pxLog );
      }
      /* allow new interrupt : clear the IFR flag */
      gpio_clear_pin_interrupt_flag(PB2_POSITION);
  }
  if (gpio_get_pin_interrupt_flag(PB3_POSITION))
  {
      /* input is pulled up, if 1 : input is not active */
      if (gpio_get_pin_value(PB3_POSITION))
      {
         b_pushb3 = PUSHB_EVENT_RELEASE;
      }
      else
      {
         b_pushb3 = PUSHB_EVENT_PRESS;
         if ( bAlarm3 == pdTRUE )
         {
           // post alarm to SMTP task
           v_SMTP_PostFromISR("Push Button 3 Alarm", NULL);
         }
      }
      // Alloc and init a log.
      pxLog = pxdatalog_log_alloc_init_FromISR();
      if( NULL != pxLog )
      {
         // Init the id field of the log.
         pxLog->id = DATALOG_ID_PB3;
         /* set log event string */
         pxLog->pcStringLog = (portCHAR *)acpc_pushb_events[b_pushb3];
         /* set free function pointer */
         pxLog->pfFreeStringLog = NULL;
         /* add the log entry */
         xSwitchRequired = x_datalog_AddLogFromISR( pxLog );
      }
      /* allow new interrupt : clear the IFR flag */
      gpio_clear_pin_interrupt_flag(PB3_POSITION);
  }
  return( xSwitchRequired );
}
Beispiel #22
0
static void twi_init(U32 fpba_hz)
{
  const gpio_map_t AT42QT1060_TWI_GPIO_MAP =
  {
  {AT42QT1060_TWI_SCL_PIN, AT42QT1060_TWI_SCL_FUNCTION},
  {AT42QT1060_TWI_SDA_PIN, AT42QT1060_TWI_SDA_FUNCTION}
  };

  const twi_options_t AT42QT1060_TWI_OPTIONS =
  {
    .pba_hz = 24000000,
    .speed = AT42QT1060_TWI_MASTER_SPEED,
    .chip = AT42QT1060_TWI_ADDRESS
  };

  // Assign I/Os to SPI.
  gpio_enable_module(AT42QT1060_TWI_GPIO_MAP,
    sizeof(AT42QT1060_TWI_GPIO_MAP) / sizeof(AT42QT1060_TWI_GPIO_MAP[0]));
  // Initialize as master.
  twi_master_init(AT42QT1060_TWI, &AT42QT1060_TWI_OPTIONS);

}

/*! \brief Callback function for a detect event of the touch sensor device.
 */
void touch_detect_callback(void)
{
  touch_detect = true;
}

struct at42qt1060_data touch_data;

void controller_task(void)
{
    // if a touch is detected we read the status
    if(touch_detect)
    {
      touch_data.detect_status =
      	at42qt1060_read_reg(AT42QT1060_DETECTION_STATUS);
      // need to read input port status too to reset CHG line
      at42qt1060_read_reg(AT42QT1060_INPUT_PORT_STATUS);
      touch_detect = false;
    }
}

static void controller_detect_int_handler(void)
{
  if(gpio_get_pin_interrupt_flag(AT42QT1060_DETECT_PIN))
  {
    gpio_clear_pin_interrupt_flag(AT42QT1060_DETECT_PIN);
    touch_detect_callback();
  }
}

void controller_init(U32 fcpu_hz, U32 fhsb_hz, U32 fpbb_hz, U32 fpba_hz)
{
  // Disable all interrupts
  Disable_global_interrupt();

  twi_init(fpba_hz);
  // wait until the device settles its CHG line
  cpu_delay_ms(230, fcpu_hz);
  at42qt1060_init(fcpu_hz);
  BSP_INTC_IntReg(&controller_detect_int_handler, AVR32_GPIO_IRQ_0 + AT42QT1060_DETECT_PIN/8, AVR32_INTC_INT1);
  // For now we only react on falling edge
  // Actually this is a level interrupt (low active)
  gpio_enable_pin_interrupt(AT42QT1060_DETECT_PIN, GPIO_FALLING_EDGE);
  gpio_clear_pin_interrupt_flag(AT42QT1060_DETECT_PIN);
  //static_fcpu_hz = fcpu_hz;
  cpu_set_timeout(cpu_ms_2_cy(JOYSTICK_KEY_DEBOUNCE_MS, static_fcpu_hz),
  	&joystick_key_sensibility_timer);

  // Enable global interrupts
  Enable_global_interrupt();

}
Beispiel #23
0
static portBASE_TYPE prvjoystick_ISR_NonNakedBehaviour( void )
{
  xLogDef *pxLog;
  U32     u32CurrentCountValue = xTaskGetTickCount();


  // Debouncing: ignore joystick events occuring in less than 250ms before the last
  // valid joystick event.
  if((( u32CurrentCountValue >= u32LastCountValue )
        && ( u32CurrentCountValue - u32LastCountValue <= 250))
      ||
       (( u32CurrentCountValue < u32LastCountValue )
        && ( u32CurrentCountValue + (0xFFFFFFFF - u32LastCountValue) <= 250)))
  {
    // Clear all interrupts flag (it's no use checking which event has bouncing).
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_PUSH);
    Clr_bits(x_joystick, JS_EVENT_PUSH);
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_LEFT);
    Clr_bits(x_joystick, JS_EVENT_LEFT);
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT);
    Clr_bits(x_joystick, JS_EVENT_RIGHT);
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_UP);
    Clr_bits(x_joystick, JS_EVENT_UP);
    gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_DOWN);
    Clr_bits(x_joystick, JS_EVENT_DOWN);
    return(pdFALSE);
  }
  else
  {
    // Update last valid joystick event timestamp.
    u32LastCountValue = u32CurrentCountValue;

    // Check all events.
    if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_UP))
    {
       /* input is pulled up, if 1 : input is not active */
       if (gpio_get_pin_value(GPIO_JOYSTICK_UP))
       {
         /* clear bit UP */
         Clr_bits(x_joystick, JS_EVENT_UP);
       }
       else
       {
         Set_bits(x_joystick, JS_EVENT_UP);
       }
       /* allow new interrupt : clear the IFR flag */
       gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_UP);
     }
     if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_DOWN))
     {
       /* input is pulled up, if 1 : input is not active */
       if (gpio_get_pin_value(GPIO_JOYSTICK_DOWN))
       {
         Clr_bits(x_joystick, JS_EVENT_DOWN);
       }
       else
       {
         Set_bits(x_joystick, JS_EVENT_DOWN);
       }
       /* allow new interrupt : clear the IFR flag */
       gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_DOWN);
     }
     if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_LEFT))
     {
       /* input is pulled up, if 1 : input is not active */
       if (gpio_get_pin_value(GPIO_JOYSTICK_LEFT))
       {
         Clr_bits(x_joystick, JS_EVENT_LEFT);
       }
       else
       {
         Set_bits(x_joystick, JS_EVENT_LEFT);
   #ifdef MMILCD_ENABLE
         vMMI_UserMenuDisplayPreviousItem(pdTRUE);
   #endif
       }
       /* allow new interrupt : clear the IFR flag */
       gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_LEFT);
     }
     if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT))
     {
       /* input is pulled up, if 1 : input is not active */
       if (gpio_get_pin_value(GPIO_JOYSTICK_RIGHT))
       {
         Clr_bits(x_joystick, JS_EVENT_RIGHT);
       }
       else
       {
         Set_bits(x_joystick, JS_EVENT_RIGHT);
   #ifdef MMILCD_ENABLE
         vMMI_UserMenuDisplayNextItem(pdTRUE);
   #endif
       }
       /* allow new interrupt : clear the IFR flag */
       gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_RIGHT);
     }
     if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_PUSH))
     {
       /* input is pulled up, if 1 : input is not active */
       if (gpio_get_pin_value(GPIO_JOYSTICK_PUSH))
       {
         Clr_bits(x_joystick, JS_EVENT_PUSH);
       }
       else
       {
         Set_bits(x_joystick, JS_EVENT_PUSH);
         if ( bAlarm == pdTRUE )
         {
           // post alarm to SMTP task
           v_SMTP_PostFromISR("Joystick Alarm", NULL);
         }

   #ifdef MMILCD_ENABLE
         vMMI_UserMenuValidateItem(pdTRUE);
   #endif
       }
       /* allow new interrupt : clear the IFR flag */
       gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_PUSH);
     }
  }
  // Alloc and init a log.
  pxLog = pxdatalog_log_alloc_init_FromISR();
  if( NULL == pxLog )
    return( pdFALSE );
  // Init the id field of the log.
  pxLog->id = DATALOG_ID_JS;
  /* set log event string */
  pxLog->pcStringLog = (portCHAR *)acpc_js_events[x_joystick];
  /* set free function pointer */
  pxLog->pfFreeStringLog = NULL;
  /* add the log entry */
  return( x_datalog_AddLogFromISR( pxLog ) );
}
__attribute__ ((__interrupt__)) void tecla_lrc_isr(void){//handler teclas left, right o center
	
	
	if (gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER))
	{
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER);
	}
	

	if (gpio_get_pin_interrupt_flag (QT1081_TOUCH_SENSOR_LEFT))
	{
		
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_LEFT);
		pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); 
		
		while(gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER)==0){
			
			gpio_tgl_gpio_pin(LED3_GPIO);
			delay_s(50);
			
		}
		display(0);
	}

	if (gpio_get_pin_interrupt_flag (QT1081_TOUCH_SENSOR_RIGHT))
	{
		
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_RIGHT);
		pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); 
		while(gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER)==0){
			displayPrimo();
			delay_s(50);
			
		}
	}
	if (gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_UP))
	{
				gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_UP);
		       pm_switch_to_clock(&AVR32_PM,0); //cambia al RC
			   pm_pll_disable(&AVR32_PM,0); // deshabilita el el PLL 0
			   
			   pm_pll_setup(&AVR32_PM,0,2,1,0,16); // lockcount in main clock for the PLL wait lock

			   //_______________________________________________________________________________
			   // Establece la frecuencia de salida del PLL
			   pm_pll_set_option(&AVR32_PM,0,1,0,0);//1 Star-up faster, Start-up normal
			   //_______________________________________________________________________________
			   //Habilita el PLL 0
			   pm_pll_enable(&AVR32_PM,0);
			   //_______________________________________________________________________________
			   //Espera a que se establesca el PLL
			   pm_wait_for_pll0_locked(&AVR32_PM) ;
			   //_______________________________________________________________________________
			   // Set one wait-state (WS) for flash controller
			   flashc_set_wait_state(1);

			   //habilita la salida del PLL0 con 2 y el OSC0 con 1
			   pm_switch_to_clock(&AVR32_PM, 2);
			   
			   while (gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER)==0)
			   {
				   
				   displayA1();
				    /*for (uint32_t j =0; j<18000; j++)//300ms 12Mhz
				    {
						delay_ms(10);
				    }*/
					delay_s(50);
				   
			   }
			   display(0);
			   
		
	}
	
	if (gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_DOWN))
	{
		gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_DOWN);
		pm_switch_to_clock(&AVR32_PM,0); //cambia al RC
		pm_pll_disable(&AVR32_PM,0); // deshabilita el el PLL 0
		
		pm_pll_setup(&AVR32_PM,0,6,1,0,16); // lockcount in main clock for the PLL wait lock

		//_______________________________________________________________________________
		// Establece la frecuencia de salida del PLL
		pm_pll_set_option(&AVR32_PM,0,1,0,0);//1 Star-up faster, Start-up normal
		//_______________________________________________________________________________
		//Habilita el PLL 0
		pm_pll_enable(&AVR32_PM,0);
		//_______________________________________________________________________________
		//Espera a que se establesca el PLL
		pm_wait_for_pll0_locked(&AVR32_PM) ;
		//_______________________________________________________________________________
		// Set one wait-state (WS) for flash controller
		flashc_set_wait_state(1);

		//habilita la salida del PLL0 con 2 y el OSC0 con 1
		pm_switch_to_clock(&AVR32_PM, 2);
		
		while (gpio_get_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER)==0)
		{
			displayOnOff();
			
		}
		display(0);
		
		
	}
	
	
	
	

}