GPIO输出
输入
中断
/*
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "driver/uart.h"
uint8_t gpio_intr = 0;
TaskHandle_t test_Handle = NULL;
void test_Task(void *pvParameters);
TaskHandle_t test1_Handle = NULL;
void test1_Task(void *pvParameters);
void gpio_handler(void *p);
/******************************************************************************
* FunctionName : app_main
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void app_main(void)
{
uart_set_baudrate(UART_NUM_0, 115200);
vTaskDelay(1000);
printf("SDK version:%s\n", esp_get_idf_version());
xTaskCreate((TaskFunction_t)test_Task,
(const char *)"test_Task",
(uint16_t)1024,
(void *)NULL,
(UBaseType_t)4,
(TaskHandle_t *)&test_Handle);
xTaskCreate((TaskFunction_t)test1_Task,
(const char *)"test1_Task",
(uint16_t)2048,
(void *)NULL,
(UBaseType_t)5,
(TaskHandle_t *)&test1_Handle);
}
void test_Task(void *pvParameters)
{
uint8_t i = 0;
gpio_config_t io_cf;
io_cf.intr_type = GPIO_INTR_DISABLE;
io_cf.mode = GPIO_MODE_OUTPUT;
io_cf.pin_bit_mask = (GPIO_Pin_4);
io_cf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_cf.pull_up_en = GPIO_PULLUP_DISABLE;
gpio_config(&io_cf);
while(1)
{
printf("hello %d\r\n", i++);
gpio_set_level(GPIO_NUM_4, (i % 2));
vTaskDelay(500);
}
}
void test1_Task(void *pvParameters)
{
gpio_config_t io_cf;
#if 0
io_cf.intr_type = GPIO_INTR_DISABLE;
io_cf.mode = GPIO_MODE_DEF_INPUT;
io_cf.pin_bit_mask = (GPIO_Pin_0);
io_cf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_cf.pull_up_en = GPIO_PULLUP_ENABLE;
gpio_config(&io_cf);
#else
io_cf.intr_type = GPIO_INTR_ANYEDGE;
io_cf.mode = GPIO_MODE_DEF_INPUT;
io_cf.pin_bit_mask = (GPIO_Pin_5);
io_cf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_cf.pull_up_en = GPIO_PULLUP_ENABLE;
gpio_config(&io_cf);
gpio_install_isr_service(0);
gpio_isr_handler_add(GPIO_NUM_5, gpio_handler, (void*)GPIO_NUM_5);
#endif
while(1)
{
// if(gpio_get_level(GPIO_NUM_0))
// {
// printf("test1_Task\r\n");
// while(gpio_get_level(GPIO_NUM_0))
// {
// vTaskDelay(10);
// }
// }
if(gpio_intr == 1)
{
gpio_intr = 0;
printf("gpio_intr5\r\n");
}
vTaskDelay(100);
}
}
void gpio_handler(void *p)
{
gpio_intr = 1;
}