Ejemplo n.º 1
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);
    }
}
Ejemplo n.º 2
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);
  }
}
Ejemplo n.º 3
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);
    }

}
Ejemplo n.º 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);
  }
}
Ejemplo n.º 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);
  }

}
Ejemplo n.º 6
0
static void gpio_pin_change_interrupt_handler(void)
{
	// Clear the pin change interrupt flag
	gpio_clear_pin_interrupt_flag(GPIO_PIN_EXAMPLE_2);
	// Toggle GPIO_PIN_EXAMPLE_3
	gpio_tgl_gpio_pin(GPIO_PIN_EXAMPLE_3);
}
Ejemplo n.º 7
0
Archivo: init.c Proyecto: Mazetti/asf
void board_init(void)
{
	gpio_configure_pin(LED0_GPIO,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);
	gpio_configure_pin(LED1_GPIO,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);

#if defined (CONF_BOARD_AT86RFX)
    // AT86RFX SPI GPIO options.
    static  gpio_map_t AT86RFX_SPI_GPIO_MAP =
    {
        {AT86RFX_SPI_SCK_PIN,  AT86RFX_SPI_SCK_FUNCTION },
        {AT86RFX_SPI_MISO_PIN, AT86RFX_SPI_MISO_FUNCTION},
        {AT86RFX_SPI_MOSI_PIN, AT86RFX_SPI_MOSI_FUNCTION},
        {AT86RFX_SPI_NPCS_PIN, AT86RFX_SPI_NPCS_FUNCTION}
    };

	// Assign GPIO to SPI.
	gpio_enable_module(AT86RFX_SPI_GPIO_MAP, sizeof(AT86RFX_SPI_GPIO_MAP) / sizeof(AT86RFX_SPI_GPIO_MAP[0]));

	gpio_enable_pin_interrupt(AT86RFX_IRQ_PIN, GPIO_RISING_EDGE);
	gpio_clear_pin_interrupt_flag(AT86RFX_IRQ_PIN);

	gpio_configure_pin(AT86RFX_RST_PIN, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);
	gpio_configure_pin(AT86RFX_SLP_PIN, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);
#endif

}
Ejemplo n.º 8
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);
	}
}
Ejemplo n.º 9
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);
  }
}
Ejemplo n.º 10
0
static void irq_port0_line1(void) {
    if(gpio_get_pin_interrupt_flag(NMI)) {
      // print_dbg("\r\n ### NMI ### ");
      event_t e = { .type = kEventFront, .data = gpio_get_pin_value(NMI) };
      event_post(&e);
      gpio_clear_pin_interrupt_flag(NMI);
    }
}
Ejemplo n.º 11
0
static void inline rtouch_disable_detect_int(void)
{
	/* Disable interrupt for Y lines. */
	/* Clear the pin interrupt, or otherwise it will trigger when
	 * enabled again */
	gpio_clear_pin_interrupt_flag(rtouch_gpio_ymap[0].pin);
	gpio_disable_pin_interrupt(rtouch_gpio_ymap[0].pin);
}
Ejemplo n.º 12
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);
  }
}
Ejemplo n.º 13
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;
			
		}
}
Ejemplo n.º 14
0
//!
//! @brief Suspend callback.
//!
//! This function enables the interrupts in order to send a remote wakeup to the host.
//!
void usb_suspend(void)
{
  if(remote_wakeup_feature) {
     // Enable ISR on switches
#if BOARD == EVK1105
    gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER);
    gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_ENTER, GPIO_RISING_EDGE);
#endif
  }
}
Ejemplo n.º 15
0
static void irq_port0_line0(void) {
  for(int i=0;i<8;i++) {
    if(gpio_get_pin_interrupt_flag(i)) {
      // print_dbg("\r\n # A00");
      event_t e = { .type = kEventTrigger, .data = i };
      event_post(&e);
      gpio_clear_pin_interrupt_flag(i);
    }
  }
}
Ejemplo n.º 16
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);
  }
}
Ejemplo n.º 17
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);
	}
	

}
Ejemplo n.º 18
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();
  }
}
Ejemplo n.º 19
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 );
}
Ejemplo n.º 20
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);
  }
}
Ejemplo n.º 21
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);
  }
}
Ejemplo n.º 22
0
__interrupt
#endif
void touch_button_isr(void)
{
  // Unfreeze the clock (this has been done in the SUSPEND state
  Usb_unfreeze_clock();

  // Launch the remote wakeup
  Usb_initiate_remote_wake_up();

  //Disable the GPIO activity detection
  gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER);
  gpio_disable_pin_interrupt(QT1081_TOUCH_SENSOR_ENTER);
}
Ejemplo n.º 23
0
/** \brief Register a normal pin interrupt for the touch event.
 *
 */
void at42qt1060_register_int(void (*touch_detect_callback)(void))
{
  at42qt1060.touch_detect_callback = touch_detect_callback;

  Disable_global_interrupt();

  INTC_register_interrupt(&at42qt1060_detect_int_handler, AVR32_GPIO_IRQ_0 + AT42QT1060_DETECT_PIN/8, 0 );
  // 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);

  Enable_global_interrupt();
  return;
}
Ejemplo n.º 24
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);
	}

}
Ejemplo n.º 25
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();
}
Ejemplo n.º 27
0
static void inline rtouch_clear_detect_flag(void)
{
	gpio_clear_pin_interrupt_flag(rtouch_gpio_ymap[0].pin);
}
Ejemplo n.º 28
0
/*********************************************************************
Functions
*********************************************************************/
int main (void)
{
	int i;
	// initialize
	
	init();
	

	gpio_configure_pin(TEST_A, GPIO_DIR_INPUT | GPIO_INIT_HIGH);
	gpio_configure_pin(TEST_B, GPIO_DIR_INPUT | GPIO_INIT_HIGH);
	gpio_configure_pin(TEST_C, GPIO_DIR_INPUT | GPIO_INIT_HIGH);
	
	gpio_configure_pin(RESPONSE_A, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);
	gpio_configure_pin(RESPONSE_B, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);
	gpio_configure_pin(RESPONSE_C, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);
	
	
	// ASS C
	
	gpio_enable_pin_interrupt(TEST_A, GPIO_FALLING_EDGE );
	gpio_enable_pin_interrupt(TEST_B, GPIO_FALLING_EDGE );
	gpio_enable_pin_interrupt(TEST_C, GPIO_FALLING_EDGE );
	
	
	
	
	// start code from here
	while(1)
	{
		//gpio_toggle_pin(LED0_GPIO);
		 
		/*
		if(gpio_pin_is_low(TEST_A)){
			gpio_set_pin_low(RESPONSE_A);
			busy_delay_us(5);
			gpio_set_pin_high(RESPONSE_A);
		}
		
		if(gpio_pin_is_low(TEST_B)){
			gpio_set_pin_low(RESPONSE_B);
			busy_delay_us(5);
			gpio_set_pin_high(RESPONSE_B);
		}
		
		if (gpio_pin_is_low(TEST_C)){
			gpio_set_pin_low(RESPONSE_C);
			busy_delay_us(5);
			gpio_set_pin_high(RESPONSE_C);
		}
		*/
		
		
		//gpio_set_pin_high(LED0_GPIO);
		
		//busy_delay_ms(500);
		
		//gpio_set_pin_low(LED0_GPIO);
		//busy_delay_ms(500);
			
		// INTERRUPTS
		
		// AssD


		if (A_FLAG){
			gpio_set_pin_low(RESPONSE_A);
			busy_delay_us(5);
			gpio_set_pin_high(RESPONSE_A);
			gpio_clear_pin_interrupt_flag(TEST_A);
			A_FLAG = false;

		}
			
		else if(B_FLAG){
			gpio_set_pin_low(RESPONSE_B);
			busy_delay_us(5);
			gpio_set_pin_high(RESPONSE_B);
			gpio_clear_pin_interrupt_flag(TEST_B);
			B_FLAG = false;
		}
			
		else if(C_FLAG){
			gpio_set_pin_low(RESPONSE_C);
			busy_delay_us(5);
			gpio_set_pin_high(RESPONSE_C);
			gpio_clear_pin_interrupt_flag(TEST_C);
			C_FLAG = false;
		}

	}

}
Ejemplo n.º 29
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 ) );
}
Ejemplo n.º 30
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();

}