Skip to content

Instantly share code, notes, and snippets.

@ExtremeGTX
Created October 15, 2019 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ExtremeGTX/b7c135afdbeccdc12c66e4b7dde433eb to your computer and use it in GitHub Desktop.
Save ExtremeGTX/b7c135afdbeccdc12c66e4b7dde433eb to your computer and use it in GitHub Desktop.
This code for bug reporting only
/* Based on esp-idf GPIO Example */
/* GPIO Example
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 <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#define GPIO_INPUT_IO_0 25
#define GPIO_INPUT_PIN_SEL ((1ULL<<GPIO_INPUT_IO_0))
#define ESP_INTR_FLAG_DEFAULT 0
static xQueueHandle gpio_evt_queue = NULL;
volatile int cnt = 0;
static void IRAM_ATTR gpio_isr_handler(void* arg)
{
//uint32_t gpio_num = (uint32_t) arg;
//xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
cnt++;
}
static void gpio_task_example(void* arg)
{
uint32_t io_num;
for(;;) {
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
printf("GPIO[%d] intr, val: %d\n", io_num, gpio_get_level(io_num));
}
}
}
void app_main(void)
{
gpio_config_t io_conf;
//interrupt of rising edge
io_conf.intr_type = GPIO_INTR_HIGH_LEVEL;
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 = 0;
gpio_config(&io_conf);
//change gpio intrrupt type for one pin
gpio_set_intr_type(GPIO_INPUT_IO_0, GPIO_INTR_HIGH_LEVEL); //GPIO_INTR_LOW_LEVEL
//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_INPUT_IO_0, gpio_isr_handler, (void*) GPIO_INPUT_IO_0);
while(1) {
printf("cnt: %d\n", cnt);
vTaskDelay(1000 / portTICK_RATE_MS);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment