Code: Untitled.c Select all
void PT_GpioInit()
{
gpio_config_t io_conf;
//disable interrupt
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
gpio_config(&io_conf);
//interrupt of rising edge
io_conf.intr_type = GPIO_PIN_INTR_POSEDGE;
//bit mask of the pins, use GPIO4/5 here
io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
//set as input mode
io_conf.mode = GPIO_MODE_INPUT;
//enable pull-up mode
io_conf.pull_up_en = 1;
gpio_config(&io_conf);
//change gpio intrrupt type for one pin
gpio_set_intr_type(GPIO_NUM_4, GPIO_INTR_ANYEDGE);
//create a queue to handle gpio event from isr
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
//start gpio task
xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL);
//install gpio isr service
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_NUM_4, gpio_isr_handler, (void*) GPIO_NUM_4);
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_NUM_5, gpio_isr_handler, (void*) GPIO_NUM_5);
//remove isr handler for gpio number.
gpio_isr_handler_remove(GPIO_NUM_4);
//hook isr handler for specific gpio pin again
gpio_isr_handler_add(GPIO_NUM_4, gpio_isr_handler, (void*) GPIO_NUM_4);
}
void test_PT_GpioInit()
{
printf("test_PT_GpioInit()\n");
gpio_pad_select_gpio(GPIO_NUM_18);
gpio_set_direction(GPIO_NUM_18, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(GPIO_NUM_19);
gpio_set_direction(GPIO_NUM_19, GPIO_MODE_OUTPUT);
gpio_intr_disable(GPIO_NUM_18);
gpio_intr_disable(GPIO_NUM_19);
gpio_pulldown_dis(GPIO_NUM_18 );
gpio_pulldown_dis(GPIO_NUM_19);
gpio_pullup_dis(GPIO_NUM_18 );
gpio_pullup_dis(GPIO_NUM_19);
gpio_pad_select_gpio(GPIO_NUM_4);
gpio_set_direction(GPIO_NUM_4, GPIO_MODE_INPUT);
gpio_pad_select_gpio(GPIO_NUM_5);
gpio_set_direction(GPIO_NUM_5, GPIO_MODE_INPUT);
gpio_set_intr_type(GPIO_NUM_4, GPIO_INTR_NEGEDGE );
gpio_set_intr_type(GPIO_NUM_5, GPIO_INTR_NEGEDGE );
gpio_pullup_en(GPIO_NUM_4);
gpio_pullup_en(GPIO_NUM_5);
gpio_intr_enable(GPIO_NUM_4);
gpio_intr_enable(GPIO_NUM_5);
//gpio_set_intr_type(GPIO_NUM_4, GPIO_INTR_ANYEDGE);
//create a queue to handle gpio event from isr
gpio_evt_queue = xQueueCreate(100, sizeof(uint32_t));
//start gpio task
xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL);
//install gpio isr service
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_NUM_4, gpio_isr_handler, (void*) GPIO_NUM_4);
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_NUM_5, gpio_isr_handler, (void*) GPIO_NUM_5);
//remove isr handler for gpio number.
gpio_isr_handler_remove(GPIO_NUM_4);
//hook isr handler for specific gpio pin again
gpio_isr_handler_add(GPIO_NUM_4, gpio_isr_handler, (void*) GPIO_NUM_4);
}
我的问题是:如何把test_PT_GpioInit()配置成和PT_GpioInit()一样,实现IO口中断功能?谢谢
