int main (void) { // Insert system clock initialization code here (sysclk_init()). sysclk_init(); board_init(); // Insert application code here, after the board has been initialized. pmc_enable_periph_clk(ID_PIOA); pio_set_input(PIOA, PIO_PA16, PIO_DEFAULT); pio_pull_down(PIOA, (PIO_PA16), ENABLE); pio_handler_set(PIOA, ID_PIOA, PIO_PA16, PIO_IT_RISE_EDGE, pin_riseedge_handler); pio_enable_interrupt(PIOA,PIO_PA16); pio_set_input(PIOA, PIO_PA17, PIO_DEFAULT); pio_pull_down(PIOA, (PIO_PA17), ENABLE); pio_handler_set(PIOA, ID_PIOA, PIO_PA17, PIO_IT_RISE_EDGE, pin_riseedge_handler); pio_enable_interrupt(PIOA,PIO_PA17); NVIC_EnableIRQ(PIOA_IRQn); gpio_set_pin_low(LED0_GPIO); gpio_set_pin_high(LED1_GPIO); while(1){ } }
void config_hall_interrupt (void){ pmc_enable_periph_clk(ID_HALL); pio_set_input(PIOA, GPIO_HALLB, PIO_DEFAULT); pio_pull_down(PIOA, GPIO_HALLB, ENABLE); pio_handler_set(PIOA, ID_HALL, GPIO_HALLB, PIO_IT_RISE_EDGE, pin_riseedge_handler); pio_enable_interrupt(PIOA, GPIO_HALLB); pio_set_input(PIOA, GPIO_HALLC, PIO_DEFAULT); pio_pull_down(PIOA, GPIO_HALLC, ENABLE); pio_handler_set(PIOA, ID_HALL, GPIO_HALLC, PIO_IT_FALL_EDGE, pin_riseedge_handler); pio_enable_interrupt(PIOA, GPIO_HALLC); NVIC_DisableIRQ(PIOA_IRQn); NVIC_ClearPendingIRQ(PIOA_IRQn); NVIC_SetPriority(PIOA_IRQn, PRIORITY_MEASURE); NVIC_EnableIRQ(PIOA_IRQn); }
static void irq_init(void) { pio_configure_pin(DW_IRQ_IDX, DW_IRQ_FLAGS); pio_pull_down(DW_IRQ_PIO, DW_IRQ_MASK, true); pio_handler_set(DW_IRQ_PIO, DW_IRQ_PIO_ID, DW_IRQ_MASK, DW_IRQ_ATTR, irq_handler); pio_enable_interrupt(DW_IRQ_PIO, DW_IRQ_MASK); pio_handler_set_priority(DW_IRQ_PIO, DW_IRQ_IRQ, 0); pmc_enable_periph_clk(DW_IRQ_PIO_ID); }
int main (void) { /* Insert system clock initialization code here (sysclk_init()). */ sysclk_init(); board_init(); /* Insert application code here, after the board has been initialized. */ if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) { puts("-E- Systick configuration error\r"); while (1) { /* Capture error */ gpio_set_pin_low(LED2_GPIO); } } config_lcd(); pmc_enable_periph_clk(ID_ENC); //Interrupt for A: pio_set_input(PIOA, GPIO_A, PIO_DEFAULT); pio_pull_down(PIOA, GPIO_A, ENABLE); pio_handler_set(PIOA, ID_ENC, GPIO_A, PIO_IT_RISE_EDGE, pin_handler); pio_enable_interrupt(PIOA, GPIO_A); //Interrupt for B: pio_set_input(PIOA, GPIO_B, PIO_DEFAULT); pio_pull_down(PIOA, GPIO_B, ENABLE); pio_handler_set(PIOA, ID_ENC, GPIO_B, PIO_IT_RISE_EDGE, pin_handler); pio_enable_interrupt(PIOA, GPIO_B); //Interrupt for C: pio_set_input(PIOA, GPIO_C, PIO_DEFAULT); pio_pull_down(PIOA, GPIO_C, ENABLE); //pio_handler_set(PIOA, ID_ENC, GPIO_C, PIO_IT_RISE_EDGE, pin_handler); pio_handler_set(PIOA, ID_ENC, GPIO_C, PIO_IT_FALL_EDGE, pin_handler); pio_enable_interrupt(PIOA, GPIO_C); //Enable Interrupt GPIO: NVIC_DisableIRQ(PIOA_IRQn); NVIC_ClearPendingIRQ(PIOA_IRQn); NVIC_SetPriority(PIOA_IRQn, 0); NVIC_EnableIRQ(PIOA_IRQn); ili9225_set_foreground_color(COLOR_BLACK); ili9225_draw_string(10,10, (uint8_t *)"Encoder Test"); while (1){ ili9225_set_foreground_color(COLOR_WHITE); ili9225_draw_filled_rectangle(0,30,ILI9225_LCD_WIDTH,ILI9225_LCD_HEIGHT); ili9225_set_foreground_color(COLOR_BLACK); graus = ((float)round/ENC_RES)*VOLTA_COMP; snprintf(buf, sizeof(buf), "Graus:%.3f", graus ); ili9225_draw_string(10,50, buf); snprintf(buf, sizeof(buf), "Round:%d", round ); ili9225_draw_string(10,80, buf); mdelay(500); } }
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; } }