Beispiel #1
0
/**
 *  \brief Configure the Pushbuttons
 *
 *  Configure the PIO as inputs and generate corresponding interrupt when
 *  pressed or released.
 */
static void configure_buttons(void)
{
// [main_button1_configure]
	/* Configure Pushbutton 1 */
	pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID);
	pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 10);
	/* Interrupt on rising edge  */
	pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID,
			PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR, Button1_Handler);
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID);
	pio_handler_set_priority(PIN_PUSHBUTTON_1_PIO,
			(IRQn_Type) PIN_PUSHBUTTON_1_ID, IRQ_PRIOR_PIO);
	pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK);
// [main_button1_configure]
#ifndef BOARD_NO_PUSHBUTTON_2
// [main_button2_configure]
	/* Configure Pushbutton 2 */
	pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID);
	pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, 10);
	/* Interrupt on falling edge */
	pio_handler_set(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_ID,
			PIN_PUSHBUTTON_2_MASK, PIN_PUSHBUTTON_2_ATTR, Button2_Handler);
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_2_ID);
	pio_handler_set_priority(PIN_PUSHBUTTON_2_PIO,
			(IRQn_Type) PIN_PUSHBUTTON_2_ID, IRQ_PRIOR_PIO);
	pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK);
// [main_button2_configure]
#endif
}
Beispiel #2
0
/**
*  \brief Configure the push buttons.
*
*  Configure the PIOs as inputs and generate corresponding interrupt when
*  the push buttons are pressed or released.
*/
static void configure_buttons(void)
{
	/* Enable the pmc clocks of the push buttons for all SAM3. */
	pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID);
	pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID);

	/* Adjust PIO debouncing filter patameters, using 10 Hz filter. */
	pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK,
			10);
	pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK,
			10);

	/* Initialize PIOs interrupt handlers (see PIO definition in board.h). */
	pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID, PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR, Int1Handler);	/* Interrupt on rising edge.  */
	pio_handler_set(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_ID, PIN_PUSHBUTTON_2_MASK, PIN_PUSHBUTTON_2_ATTR, Int2Handler);	/* Interrupt on falling edge. */

	/* Enable PIO controller IRQs. */
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID);
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_2_ID);

	/* PIO configuration for Buttons. */
	pio_handler_set_priority(PIN_PUSHBUTTON_1_PIO, (IRQn_Type) PIN_PUSHBUTTON_1_ID, 0);
	pio_handler_set_priority(PIN_PUSHBUTTON_2_PIO, (IRQn_Type) PIN_PUSHBUTTON_2_ID, 0);

	/* Enable PIO line interrupts. */
	pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK);
	pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK);
}
Beispiel #3
0
/**
 *  \brief Configure the Pushbuttons
 *
 *  Configure the PIO as inputs and generate corresponding interrupt when
 *  pressed or released.
 */
static void configure_buttons(void)
{
	pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID);
	pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID);	
	pio_set_input(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_input(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 10);
	pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, 10);	
	pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID, PIN_PUSHBUTTON_1_MASK, PIO_IT_FALL_EDGE | PIO_PULLUP, Button1_Handler);
	pio_handler_set(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_ID, PIN_PUSHBUTTON_2_MASK, PIO_IT_FALL_EDGE | PIO_PULLUP, Button2_Handler);	
	pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO , PIN_PUSHBUTTON_1_MASK);
	pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO , PIN_PUSHBUTTON_2_MASK);
	NVIC_SetPriority((IRQn_Type) PIN_PUSHBUTTON_1_ID, 0);
	NVIC_SetPriority((IRQn_Type) PIN_PUSHBUTTON_2_ID, 0);	
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID);
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_2_ID);
	}
Beispiel #4
0
/**
 *  \brief Configure the Pushbuttons
 *
 *  Configure the PIO as inputs and generate corresponding interrupt when
 *  pressed or released.
 */
static void configure_buttons(void)
{
	pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID);
	pio_set_input(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR);
	pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 100);
	pio_handler_set(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_ID, PIN_PUSHBUTTON_1_MASK,PIO_IT_FALL_EDGE, Button1_Handler);
	pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK);
	NVIC_SetPriority(PIN_PUSHBUTTON_1_ID,0);
	NVIC_EnableIRQ(PIN_PUSHBUTTON_1_ID);
	
	pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID);
	pio_set_input(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, PIN_PUSHBUTTON_2_ATTR);
	pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, 100);
	pio_handler_set(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_ID, PIN_PUSHBUTTON_2_MASK,PIO_IT_FALL_EDGE, Button2_Handler);
	pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK);
	NVIC_SetPriority(PIN_PUSHBUTTON_2_ID,1);
	NVIC_EnableIRQ(PIN_PUSHBUTTON_2_ID);
	}
Beispiel #5
0
/**
 *  \brief Configure the Pushbuttons
 *
 *  Configure the PIO as inputs and generate corresponding interrupt when
 *  pressed or released.
 */
static void configure_buttons(void)
{	
	pmc_enable_periph_clk(ID_BUT_2);
	pmc_enable_periph_clk(ID_BUT_1);
	pio_set_input(PORT_BUT_2, MASK_BUT_2, PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_input(PORT_BUT_1, MASK_BUT_1, PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_debounce_filter(PORT_BUT_2, MASK_BUT_2, 20);
	pio_set_debounce_filter(PORT_BUT_1, MASK_BUT_1, 20);
	pio_handler_set(PORT_BUT_2, ID_BUT_2, MASK_BUT_2, PIO_IT_FALL_EDGE , Button1_Handler );
	pio_handler_set(PORT_BUT_1, ID_BUT_1, MASK_BUT_1, PIO_IT_FALL_EDGE , Button2_Handler );
	pio_enable_interrupt(PORT_BUT_2, MASK_BUT_2);
	pio_enable_interrupt(PORT_BUT_1, MASK_BUT_1);
	NVIC_SetPriority((IRQn_Type) ID_PIOB, 2);
	NVIC_SetPriority((IRQn_Type) ID_PIOC, 2);
	NVIC_EnableIRQ(ID_BUT_2);
	NVIC_EnableIRQ(ID_BUT_1);	
		
}
Beispiel #6
0
void button_init(uint32_t ul_id, Pio *p_pio, const uint32_t ul_mask, IRQn_Type IRQn, void (*p_handler) (uint32_t, uint32_t))
{
	pmc_enable_periph_clk(ul_id);
	pio_set_input(p_pio, ul_mask, PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_debounce_filter(p_pio, ul_mask, DEBOUNCE_FREQ);
	pio_handler_set(p_pio, ul_id, ul_mask, PIO_IT_FALL_EDGE, p_handler);
	pio_enable_interrupt(p_pio, ul_mask);
	NVIC_EnableIRQ(IRQn);
}
void configure_botao(void)
{
	pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID);
	pio_set_input(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR);
	pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 10);
	pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID,PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR ,push_button_handle);
	pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK);
	NVIC_SetPriority((IRQn_Type) PIN_PUSHBUTTON_1_ID, 0);
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID);
}
/**
 *  \brief Configure the Pushbuttons
 *
 *  Configure the PIO as inputs and generate corresponding interrupt when
 *  pressed or released.
 */
static void configure_buttons(void)
{
	pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID);
	pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID);

	/**
	* Configura entrada
	*/ 
	pio_set_input(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_MASK , PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_input(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_MASK , PIO_PULLUP | PIO_DEBOUNCE);

	/*
	 * Configura divisor do clock para debounce
	 */
	pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_MASK ,20);
	pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_MASK ,20);
	
	/* 
	*	Configura interrupção para acontecer em borda de descida.
	*/
	pio_handler_set(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_ID,PIN_PUSHBUTTON_1_MASK ,PIN_PUSHBUTTON_1_ATTR ,Button1_Handler);
	pio_handler_set(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_ID,PIN_PUSHBUTTON_2_MASK ,PIN_PUSHBUTTON_2_ATTR ,Button2_Handler);
	
				
	/*
	*	Ativa interrupção no periférico B porta do botão
	*/	
	pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_MASK);
	pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_MASK);
	
	/*
	*	Configura a prioridade da interrupção no pORTB
	*/
	NVIC_SetPriority(ID_PIOB,2);
	NVIC_SetPriority(ID_PIOC,2);
	
	/*
	*	Ativa interrupção no port B
	*/
	NVIC_EnableIRQ(ID_PIOB);
	NVIC_EnableIRQ(ID_PIOC);
}
static void configure_buttons(void)
{	
	pmc_enable_periph_clk(ID_BUT_2);
	pmc_enable_periph_clk(ID_BUT_3);
	/**
	* Configura entrada
	*/ 
	pio_set_input(PORT_BUT_2, MASK_BUT_2, PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_input(PORT_BUT_3, MASK_BUT_3, PIO_PULLUP | PIO_DEBOUNCE);
	
	/*
	 * Configura divisor do clock para debounce
	 */
	pio_set_debounce_filter(PORT_BUT_2,MASK_BUT_2, 100);
	pio_set_debounce_filter(PORT_BUT_3,MASK_BUT_3, 100);
	
	/* 
	*	Configura interrupção para acontecer em borda de descida.
	*/
	pio_handler_set(PORT_BUT_2,ID_BUT_2,MASK_BUT_2,PIO_IT_FALL_EDGE,Button2_Handler);
	pio_handler_set(PORT_BUT_3,ID_BUT_3,MASK_BUT_3,PIO_IT_FALL_EDGE,Button3_Handler);
				
	/*
	*	Ativa interrupção no periférico B porta do botão
	*/	
	pio_enable_interrupt(PORT_BUT_2,MASK_BUT_2);
	pio_enable_interrupt(PORT_BUT_3,MASK_BUT_3);
	
	/*
	*	Configura a prioridade da interrupção no PORTB E PORTC
	*/
	NVIC_SetPriority(PIOB_IRQn, 10);
	NVIC_SetPriority(PIOC_IRQn, 10);
	
	/*
	*	Ativa interrupção no port B e C
	*/
	NVIC_EnableIRQ(PIOB_IRQn);
	NVIC_EnableIRQ(PIOC_IRQn);
		
}
Beispiel #10
0
/**
 * \brief Configure the Pushbuttons.
 *
 * Configure the PIO as inputs and generate corresponding interrupt when
 * pressed or released.
 */
static void configure_buttons(void)
{
	/* Configure Pushbutton 1. */
	pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID);
	pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 10);
	pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID,
			PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR, Button1_Handler);
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID);
	pio_handler_set_priority(PIN_PUSHBUTTON_1_PIO, (IRQn_Type) PIN_PUSHBUTTON_1_ID, IRQ_PRIOR_PIO);
	pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK);

	/* Configure Pushbutton 2. */
	pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID);
	pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, 10);
	pio_handler_set(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_ID,
			PIN_PUSHBUTTON_2_MASK, PIN_PUSHBUTTON_2_ATTR, Button2_Handler);
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_2_ID);
	pio_handler_set_priority(PIN_PUSHBUTTON_2_PIO, (IRQn_Type) PIN_PUSHBUTTON_2_ID, IRQ_PRIOR_PIO);
	pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK);

	/* Configure Pushbutton 3. */
	pmc_enable_periph_clk(PIN_PUSHBUTTON_3_ID);
	pio_set_debounce_filter(PIN_PUSHBUTTON_3_PIO, PIN_PUSHBUTTON_3_MASK, 10);
	pio_handler_set(PIN_PUSHBUTTON_3_PIO, PIN_PUSHBUTTON_3_ID,
			PIN_PUSHBUTTON_3_MASK, PIN_PUSHBUTTON_3_ATTR, Button3_Handler);
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_3_ID);
	pio_handler_set_priority(PIN_PUSHBUTTON_3_PIO, (IRQn_Type) PIN_PUSHBUTTON_3_ID, IRQ_PRIOR_PIO);
	pio_enable_interrupt(PIN_PUSHBUTTON_3_PIO, PIN_PUSHBUTTON_3_MASK);

	/* Configure SD card detection. */
	pmc_enable_periph_clk(SD_MMC_0_CD_ID);
	pio_set_debounce_filter(SD_MMC_0_CD_PIO, SD_MMC_0_CD_MASK, 10);
	pio_handler_set(SD_MMC_0_CD_PIO, SD_MMC_0_CD_ID, SD_MMC_0_CD_MASK,
			SD_MMC_0_CD_ATTR, SD_Detect_Handler);
	NVIC_EnableIRQ((IRQn_Type) SD_MMC_0_CD_ID);
	pio_handler_set_priority(SD_MMC_0_CD_PIO, (IRQn_Type) SD_MMC_0_CD_ID, IRQ_PRIOR_PIO);
	pio_enable_interrupt(SD_MMC_0_CD_PIO, SD_MMC_0_CD_MASK);
}
Beispiel #11
0
/**
 * \brief Configure the push button 1.
 *
 * \note Configure the PIO as input and generate corresponding interrupt
 * when pressed or released.
 */
static void dsp_configure_button2(void)
{
	/* Configure Pushbutton 1. */
	pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID);
	pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO,
			PIN_PUSHBUTTON_2_MASK, 10);
	pio_handler_set(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_ID,
			PIN_PUSHBUTTON_2_MASK, PIN_PUSHBUTTON_2_ATTR,
			dsp_event_button2);

	/* Take care of NVIC_SetPriority. */
	pio_handler_set_priority(PIN_PUSHBUTTON_2_PIO,
			(IRQn_Type) PIN_PUSHBUTTON_2_ID,
			INT_PRI_PUSHBUTTON);
	pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK);
}
Beispiel #12
0
/**
 *  \brief Configure the Pushbutton.
 */
static void configure_button(void)
{
    /* Enable the peripheral clock for the push button on board. */
    pmc_enable_periph_clk(PUSHBUTTON_ID);

    /* Configure PIOs as input pins. */
    pio_configure(PUSHBUTTON_PIO, PUSHBUTTON_TYPE, PUSHBUTTON_MASK,
                  PUSHBUTTON_ATTR);

    /* Adjust PIO debounce filter parameters. */
    pio_set_debounce_filter(PUSHBUTTON_PIO, PUSHBUTTON_MASK,
                            PUSHBUTTON_FILTER_GLITCH_VAULE);

    /* Initialize PIO interrupt handler, interrupt on rising edge. */
    pio_handler_set(PUSHBUTTON_PIO, PUSHBUTTON_ID, PUSHBUTTON_MASK,
                    PUSHBUTTON_ATTR, button_handler);
}
Beispiel #13
0
/**
 *  \brief Configure the push button.
 *
 *  Configure the PIO as inputs and generate corresponding interrupt when
 *  pressed or released.
 */
static void configure_button(void)
{
	/* Adjust PIO debounce filter parameters, using 10 Hz filter. */
	pio_set_debounce_filter(PIN_PUSHBUTTON_WAKEUP_PIO,
			PIN_PUSHBUTTON_WAKEUP_MASK, 10);

	/* Initialize PIO interrupt handlers, see PIO definition in board.h. */
	pio_handler_set(PIN_PUSHBUTTON_WAKEUP_PIO, PIN_PUSHBUTTON_WAKEUP_ID,
			PIN_PUSHBUTTON_WAKEUP_MASK, PIN_PUSHBUTTON_WAKEUP_ATTR,
			button_handler);

	/* Enable PIO controller IRQs. */
	NVIC_EnableIRQ((IRQn_Type)PIN_PUSHBUTTON_WAKEUP_ID);

	/* Enable PIO line interrupts. */
	pio_enable_interrupt(PIN_PUSHBUTTON_WAKEUP_PIO,
			PIN_PUSHBUTTON_WAKEUP_MASK);
}
/**
 *  \brief Configure the push button.
 *
 *  Configure the PIOs as inputs and generate corresponding interrupt when
 *  pressed or released.
 */
static void configure_button(void)
{
	/* Configure PIO clock. */
	pmc_enable_periph_clk(PUSH_BUTTON_ID);

	/* Adjust pio debounce filter parameters, uses 10 Hz filter. */
	pio_set_debounce_filter(PUSH_BUTTON_PIO, PUSH_BUTTON_PIN_MSK, 10);

	/* Initialize pios interrupt handlers, see PIO definition in board.h. */
	pio_handler_set(PUSH_BUTTON_PIO, PUSH_BUTTON_ID, PUSH_BUTTON_PIN_MSK,
		PUSH_BUTTON_ATTR, button_handler);

	/* Enable PIO controller IRQs. */
	NVIC_EnableIRQ((IRQn_Type)PUSH_BUTTON_ID);

	/* Enable PIO line interrupts. */
	pio_enable_interrupt(PUSH_BUTTON_PIO, PUSH_BUTTON_PIN_MSK);
}
Beispiel #15
0
/**
 *  \brief Configure the Pushbuttons
 *
 *  Configure the PIO as inputs and generate corresponding interrupt when
 *  pressed or released.
 */
static void _configure_buttons(void)
{
	int i = 0;
	for (i = 0; i <  ARRAY_SIZE(button_pins); ++i)
	{
		/* Configure pios as inputs. */
		pio_configure(&button_pins[i], 1);
		/* Adjust pio debounce filter parameters, uses 10 Hz filter. */
		pio_set_debounce_filter(&button_pins[i], 10);
		/* Initialize pios interrupt with its handlers */
		pio_configure_it(&button_pins[i]);
		pio_add_handler_to_group(button_pins[i].group,
					 button_pins[i].mask,
					 push_button_handler,
					 NULL);
		pio_enable_it(button_pins);
	}
}
/**
 * \brief Configure the Push buttons
 *
 * Configure the PIO as inputs and generate corresponding interrupt when
 * pressed or released.
 */
static void configure_buttons(void)
{
	/* Enable the peripheral clock for PCK and push button */
	pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID);

	/* Adjust PIO debounce filter parameters, using 10 Hz filter. */
	pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 10);

	/* Initialize PIOs interrupt handlers, see PIO definition in board.h. */
	/* Interrupt on rising edge  */
	pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID,
			PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR, button1_handler);

	/* Enable PIO controller IRQs. */
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID);

	/* Enable PIO line interrupts. */
	pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK);
}
Beispiel #17
0
/**
 * \brief Configure the INTN interrupt.
 */
void configure_intn(void (*p_handler) (uint32_t, uint32_t))
{
    /* Configure PIO clock. */
    pmc_enable_periph_clk(INTN_ID);

    /* Adjust PIO debounce filter parameters, uses 10 Hz filter. */
    pio_set_debounce_filter(INTN_PIO, INTN_PIN_MSK, 10);

    /* Initialize PIO interrupt handlers, see PIO definition in board.h. */
    pio_handler_set(INTN_PIO, INTN_ID, INTN_PIN_MSK,
                    INTN_ATTR, p_handler);

    /* Enable NVIC interrupts. */
    NVIC_SetPriority(INTN_IRQn, INT_PRIORITY_PIO);
    NVIC_EnableIRQ((IRQn_Type)INTN_ID);

    /* Enable PIO interrupts. */
    pio_enable_interrupt(INTN_PIO, INTN_PIN_MSK);
}
Beispiel #18
0
/**
 *  \brief getting-started Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	int tests = 0;
	int test_fail = 0;

	printf("<?xml version=\"1.0\" encoding=\"UTF-8\">\r\n\r\n");
	printf("<testsuite>\r\n");
	printf("  <testcase classname=\"pio.setup\" name=\"Setup\">\r\n");
	printf("    <system-out>\r\n");

	/* Output example information */
	console_example_info("PIO Testing Example");

	/* Configure PIO for input acquisition */
	pio_configure(&pio_input, 1);
	pio_set_debounce_filter(&pio_input, 100);

	/* Initialize pios interrupt with its handlers, see
	 * PIO definition in board.h. */
	pio_configure_it(&pio_input);
	pio_add_handler_to_group(pio_input.group, pio_input.mask, pio_handler, NULL);

	/* Configure PIO for output generation */
	pio_configure(&pio_output, 1);

	/* Reset event counts */
	_pio_event = 0;
	printf("    </system-out>\r\n");
	printf("  </testcase>\r\n");

	printf("<testsuite>\r\n");
	printf("  <testcase classname=\"pio.level.low\" name='PIO: Set/Get PIO LOW LEVEL'>\r\n");
	printf("    <system-out>\r\n");
	_pio_event = 0;
	pio_clear(&pio_output);
	timer_wait(10);
	printf("    </system-out>\r\n");
	if (!(pio_get(&pio_input) == 0) || !(pio_get(&pio_output) == 0)) {
		test_fail++;
		printf("    <error type=\"error\" />\r\n");
	}
	tests++;
	printf("  </testcase>\r\n");
	
	printf("  <testcase classname=\"pio.level.high\" name=\"PIO: Get PIO HIGH LEVEL\">\r\n");
    printf("    <system-out>\r\n");
	_pio_event = 0;
	pio_set(&pio_output);
	timer_wait(10);
	printf("    </system-out>\r\n");
	if (!(pio_get(&pio_input) == 1) || !(pio_get(&pio_output) == 1)) {
		test_fail++;
		printf("    <error type=\"error\" />\r\n");
	}
	tests++;
	printf("  </testcase>\r\n");
	
	printf("  <testcase classname=\"pio.irq.edge.falling\" name=\"PIO: Get PIO IRQ FALLING EDGE\">\r\n");
    printf("    <system-out>\r\n");
	_pio_event = 0;
	pio_set(&pio_output);

	pio_input.attribute |= PIO_IT_FALL_EDGE;
	pio_configure(&pio_input, 1);
	pio_enable_it(&pio_input);

	pio_clear(&pio_output);
	timer_wait(10);
	printf("    </system-out>\r\n");
	if (_pio_event != 1) {
		test_fail++;
		printf("    <error type=\"error\" />\r\n");
	}
	tests++;
	pio_input.attribute &= ~PIO_IT_FALL_EDGE;
	printf("  </test>\r\n");
	
	printf("  <testcase classname=\"pio.irq.edge.rising\" name=\"PIO: Get PIO IRQ RISING EDGE\">\r\n");
    printf("    <system-out>\r\n");
	_pio_event = 0;
	pio_clear(&pio_output);

	pio_input.attribute |= PIO_IT_RISE_EDGE;
	pio_configure(&pio_input, 1);
	pio_enable_it(&pio_input);

	pio_set(&pio_output);
	timer_wait(10);
	printf("    </system-out>\r\n");
	if (_pio_event != 1) {
		test_fail++;
		printf("    <error error=\"error\">event(s): %d</error>\r\n", _pio_event);
	}
	tests++;
	pio_input.attribute &= ~PIO_IT_RISE_EDGE;
	printf("  </test>\r\n");
	
	printf("  <testcase classname=\"pio.irq.edge.both\" name=\"PIO: Get PIO IRQ BOTH EDGE\">\r\n");
#ifdef PIO_IT_BOTH_EDGE
    printf("    <system-out>\r\n");
	_pio_event = 0;
	pio_set(&pio_output);

	pio_input.attribute |= PIO_IT_BOTH_EDGE;
	pio_configure(&pio_input, 1);
	pio_enable_it(&pio_input);

	pio_clear(&pio_output);
	timer_wait(10);

	pio_set(&pio_output);
	timer_wait(10);
	printf("    </system-out>\r\n");
	if (_pio_event != 2) {
		test_fail++;
		printf("    <error type=\"error\" />\r\n");
	}
	tests++;
	pio_input.attribute &= ~PIO_IT_BOTH_EDGE;
#else
	printf("    <skip />\r\n");
#endif	
	printf("  </testcase>\r\n");
	
	printf("  <testcase classname=\"pio.irq.level.low\" name=\"PIO: Get PIO IRQ LEVEL LOW\">\r\n");
    printf("    <system-out>\r\n");
	pio_set(&pio_output);

	pio_input.attribute |= PIO_IT_LOW_LEVEL;
	pio_configure(&pio_input, 1);
	pio_enable_it(&pio_input);

	_pio_event = 0;
	pio_clear(&pio_output);
	timer_wait(10);
	pio_set(&pio_output);
	printf("    </system-out>\r\n");
	if (_pio_event < 1) {
		test_fail++;
		printf("    <error type=\"error\" />\r\n");
	}
	tests++;
	pio_input.attribute &= ~PIO_IT_LOW_LEVEL;
	printf("  </testcase>\r\n");
	
	printf("  <testcase classname=\"pio.irq.level.high\" name=\"PIO: Get PIO IRQ LEVEL HIGH\">\r\n");
    printf("    <system-out>\r\n");
	_pio_event = 0;
	pio_clear(&pio_output);

	pio_input.attribute |= PIO_IT_HIGH_LEVEL;
	pio_configure(&pio_input, 1);
	pio_enable_it(&pio_input);
	pio_set(&pio_output);
	timer_wait(10);
	pio_clear(&pio_output);
	printf("    </system-out>\r\n");
	if (_pio_event < 1) {
		test_fail++;
		printf("    <error type=\"error\" />\r\n");
	}
	tests++;
	pio_input.attribute &= ~PIO_IT_HIGH_LEVEL;
	printf("  </test>\r\n");
	
	printf("  <testcase classname=\"pio.mode.pull.up\" name=\"PIO: Get PIO PULL UP\">\r\n");
	printf("    <system-out>\r\n");
	pio_clear(&pio_output);
	pio_output.type = PIO_INPUT;
	pio_output.attribute |= PIO_PULLUP;
	pio_configure(&pio_output, 1);
	pio_configure(&pio_input, 1);

	printf("    </system-out>\r\n");
	if (pio_get(&pio_input) != 1) {
		test_fail++;
		printf("   <error type=\"error\" />\r\n");
	}
	tests++;
	pio_output.attribute &= ~PIO_PULLUP;
	pio_output.type = PIO_OUTPUT_0;
	pio_configure(&pio_output, 1);
	printf("  </testcase>\r\n");

    printf("  <statistics>\r\n");
	printf("    <failures>%d</failures>\r\n", test_fail);
	printf("    <tests>%d</tests>\r\n", tests);
	printf("  </statistics>\r\n");
	printf("</testsuite>\r\n");
	
	while (1);
}
Beispiel #19
0
extern "C" void pinModeDuet(Pin pin, enum PinMode ulMode, uint32_t debounceCutoff)
{
	if (pin > MaxPinNumber)
	{
		return;
	}

	const PinDescription& pinDesc = g_APinDescription[pin];
    if (pinDesc.ulPinType == PIO_NOT_A_PIN)
    {
        return;
    }

	switch (ulMode)
	{
		case INPUT:
			/* Enable peripheral for clocking input */
			pmc_enable_periph_clk(pinDesc.ulPeripheralId);
			pio_pull_up(pinDesc.pPort, pinDesc.ulPin, 0);		// turn off pullup
#if SAM4E
			pio_pull_down(pinDesc.pPort, pinDesc.ulPin, 0);		// turn off pulldown
#endif
			pio_configure(
					pinDesc.pPort,
					PIO_INPUT,
					pinDesc.ulPin,
					(debounceCutoff == 0) ? 0 : PIO_DEBOUNCE);
			if (debounceCutoff != 0)
			{
				pio_set_debounce_filter(pinDesc.pPort, pinDesc.ulPin, debounceCutoff);	// enable debounce filer with specified cutoff frequency
			}
			break;

		case INPUT_PULLUP:
			/* Enable peripheral for clocking input */
			pmc_enable_periph_clk(pinDesc.ulPeripheralId);
#if SAM4E
			pio_pull_down(pinDesc.pPort, pinDesc.ulPin, 0);		// turn off pulldown
#endif
			pio_configure(
					pinDesc.pPort,
					PIO_INPUT,
					pinDesc.ulPin,
					(debounceCutoff == 0) ? PIO_PULLUP : PIO_PULLUP | PIO_DEBOUNCE);
			if (debounceCutoff != 0)
			{
				pio_set_debounce_filter(pinDesc.pPort, pinDesc.ulPin, debounceCutoff);	// enable debounce filer with specified cutoff frequency
			}
			break;

#if SAM4E
		case INPUT_PULLDOWN:
			/* Enable peripheral for clocking input */
			pmc_enable_periph_clk(pinDesc.ulPeripheralId);
			pio_pull_up(pinDesc.pPort, pinDesc.ulPin, 0);
			pio_pull_down(pinDesc.pPort, pinDesc.ulPin, 1);
			pio_configure(
					pinDesc.pPort,
					PIO_INPUT,
					pinDesc.ulPin,
					(debounceCutoff == 0) ? 0 : PIO_DEBOUNCE);
			if (debounceCutoff != 0)
			{
				pio_set_debounce_filter(pinDesc.pPort, pinDesc.ulPin, debounceCutoff);	// enable debounce filer with specified cutoff frequency
			}
			break;
#endif

		case OUTPUT_LOW:
			pio_configure(
					pinDesc.pPort,
					PIO_OUTPUT_0,
					pinDesc.ulPin,
					pinDesc.ulPinConfiguration);

			/* if all pins are output, disable PIO Controller clocking, reduce power consumption */
			if (pinDesc.pPort->PIO_OSR == 0xffffffff)
			{
				pmc_disable_periph_clk(pinDesc.ulPeripheralId);
			}
			break;

		case OUTPUT_HIGH:
			pio_configure(
					pinDesc.pPort,
					PIO_OUTPUT_1,
					pinDesc.ulPin,
					pinDesc.ulPinConfiguration);

			/* if all pins are output, disable PIO Controller clocking, reduce power consumption */
			if (pinDesc.pPort->PIO_OSR == 0xffffffff)
			{
				pmc_disable_periph_clk(pinDesc.ulPeripheralId);
			}
			break;

		case OUTPUT_PWM_LOW:
			if ((pinDesc.ulPinAttribute & (PIN_ATTR_PWM | PIN_ATTR_TIMER)) != 0)
			{
				AnalogOut(pin, 0.0, 0);							// set it to zero frequency to force re-initialisation on next AnalogOut call
			}
			break;

		case OUTPUT_PWM_HIGH:
			if ((pinDesc.ulPinAttribute & (PIN_ATTR_PWM | PIN_ATTR_TIMER)) != 0)
			{
				AnalogOut(pin, 1.0, 0);							// set it to zero frequency to force re-initialisation on next AnalogOut call
			}
			break;

		case AIN:
			pio_pull_up(pinDesc.pPort, pinDesc.ulPin, 0);		// turn off pullup
#if SAM4E
			pio_pull_down(pinDesc.pPort, pinDesc.ulPin, 0);		// turn off pulldown
#endif
			// Ideally we should record which pins are being used as analog inputs, then we can disable the clock
			// on any PIO that is being used solely for outputs and ADC inputs. But for now we don't do that.
			break;

		case SPECIAL:
			ConfigurePin(pinDesc);
			break;

		default:
			break;
	}
}
Beispiel #20
0
int main (void)
{

	/**
	* Inicializando o clock do uP
	*/
	sysclk_init();
	
	/** 
	*  Desabilitando o WathDog do uP
	*/
	WDT->WDT_MR = WDT_MR_WDDIS;
		
	/**
	* Ativa clock nos periféricos
	*/
	_pmc_enable_clock_periferico(ID_LED_BLUE);
	_pmc_enable_clock_periferico(ID_LED_GREEN);		// Redundante mas não tem problema !
	_pmc_enable_clock_periferico(ID_LED_RED);
	_pmc_enable_clock_periferico(ID_BUT_2);
				
	/**
	*	Configura saída
	*/
	pio_set_output(PORT_LED_BLUE  , MASK_LED_BLUE	,1,0,0);
	pio_set_output(PORT_LED_GREEN , MASK_LED_GREEN  ,1,0,0);
	pio_set_output(PORT_LED_RED	  , MASK_LED_RED	,1,0,0);
	


	
	/**
	* Configura entrada
	*/ 
	pio_set_input(PORT_BUT_2, MASK_BUT_2, PIO_PULLUP | PIO_DEBOUNCE);
	
	/*
	 * Configura divisor do clock para debounce
	 */
	pio_set_debounce_filter(PORT_BUT_2, MASK_BUT_2, 100);
	

	
	/* 
	*	Configura interrupção para acontecer em borda de descida.
	*/
	pio_handler_set(PIOB, ID_BUT_2, MASK_BUT_2, PIO_IT_FALL_EDGE, push_button_handle);
				
	/*
	*	Ativa interrupção no periférico B porta do botão
	*/	
	pio_enable_interrupt(PORT_BUT_2, MASK_BUT_2);	
	/*
	*	Configura a prioridade da interrupção no pORTB
	*/
	NVIC_SetPriority((IRQn_Type)PIOB_IRQn, 0);
	
	/*
	*	Ativa interrupção no port B
	*/
	NVIC_EnableIRQ((IRQn_Type)PIOB_IRQn);
	
	/**
	*	Loop infinito
	*/
	while(1){
	    /*
		pio_set(PIOA, (1 << PIN_LED_BLUE));
		delay_ms(500);
		pio_clear(PIOA, (1 << PIN_LED_BLUE));
		delay_ms(500);
		*/
	}
}