/** * \brief Main entry point for GPIO example. */ int main(void) { /* Initialize the SAM system */ sysclk_init(); board_init(); /* Initialize the console uart */ configure_console(); /* Output example information */ printf("\r\n\r\n-- GPIO interrupt and event example --\r\n"); printf("-- %s\r\n", BOARD_NAME); printf("-- Compiled: %s %s --\r\n", __DATE__, __TIME__); //! [config_button_0_trig_fall] /* Configure push button 0 to trigger an interrupt on falling edge */ //! [config_button_0_trig_fall_1] ioport_set_pin_dir(EXAMPLE_BUTTON_INT, IOPORT_DIR_INPUT); ioport_set_pin_mode(EXAMPLE_BUTTON_INT, IOPORT_MODE_PULLUP | IOPORT_MODE_GLITCH_FILTER); ioport_set_pin_sense_mode(EXAMPLE_BUTTON_INT, IOPORT_SENSE_FALLING); //! [config_button_0_trig_fall_1] //! [config_button_0_trig_fall_2] if (!gpio_set_pin_callback(EXAMPLE_BUTTON_INT, pb0_callback, 1)) { printf("Set pin callback failure!\r\n"); while (1) { } } //! [config_button_0_trig_fall_2] //! [enable_pin_interrupt] gpio_enable_pin_interrupt(EXAMPLE_BUTTON_INT); //! [enable_pin_interrupt] //! [config_button_0_trig_fall] printf("Press %s to trigger LED.\r\n", BUTTON_0_NAME); /* Configure pin to trigger an event on falling edge */ ioport_set_pin_mode(EXAMPLE_PIN_EVENT, IOPORT_MODE_PULLUP | IOPORT_MODE_MUX_C); ioport_disable_pin(EXAMPLE_PIN_EVENT); ioport_set_pin_sense_mode(EXAMPLE_PIN_EVENT, IOPORT_SENSE_FALLING); gpio_enable_pin_periph_event(EXAMPLE_PIN_EVENT); printf("Connect %s to %s to trigger an event.\r\n", EXAMPLE_PIN_NAME, EXAMPLE_GND_NAME); init_pevc(); init_pdca(); while (1) { } }
/** * Initialize the PDCA transfer for the example. */ static void init_pdca(void) { /* PDCA channel options */ static const pdca_channel_config_t pdca_tx_configs = { .addr = (void *)event_string, .pid = PDCA_PID_USART2_TX, .size = sizeof(event_string), .r_addr = 0, .r_size = 0, .ring = false, .etrig = true, .transfer_size = PDCA_MR_SIZE_BYTE }; /* Enable PDCA module */ pdca_enable(PDCA); /* Init PDCA channel with the pdca_options.*/ pdca_channel_set_config(PEVC_ID_USER_PDCA_0, &pdca_tx_configs); /* Set callback for PDCA channel */ pdca_channel_set_callback(PEVC_ID_USER_PDCA_0, pdca_tranfer_done, PDCA_0_IRQn, 1, PDCA_IER_TRC | PDCA_IER_TERR); /* Enable PDCA channel */ pdca_channel_enable(PEVC_ID_USER_PDCA_0); } /** * Configure serial console. */ static void configure_console(void) { const usart_serial_options_t uart_serial_options = { .baudrate = CONF_UART_BAUDRATE, #ifdef CONF_UART_CHAR_LENGTH .charlength = CONF_UART_CHAR_LENGTH, #endif .paritytype = CONF_UART_PARITY, #ifdef CONF_UART_STOP_BITS .stopbits = CONF_UART_STOP_BITS, #endif }; /* Configure console. */ stdio_serial_init(CONF_UART, &uart_serial_options); } /** * \brief Main entry point for event example. */ int main(void) { /* Initialize the SAM system */ sysclk_init(); board_init(); /* Initialize the console uart */ configure_console(); /* Output example information */ printf("\r\n\r\n-- Events example 2 --\r\n"); printf("-- %s\r\n", BOARD_NAME); printf("-- Compiled: %s %s --\r\n", __DATE__, __TIME__); /* Configure pin to trigger an enent on falling edge */ ioport_set_pin_mode(CONF_EXAMPLE_PIN_EVENT, IOPORT_MODE_PULLUP | IOPORT_MODE_MUX_C); ioport_disable_pin(CONF_EXAMPLE_PIN_EVENT); ioport_set_pin_sense_mode(CONF_EXAMPLE_PIN_EVENT, IOPORT_SENSE_FALLING); gpio_enable_pin_periph_event(CONF_EXAMPLE_PIN_EVENT); printf(CONF_EXAMPLE_EVENT_MSG); init_events(); init_pdca(); while (1) { /* Toggle LED0 every 500 ms */ LED_Toggle(LED0); delay_ms(500); } }