I'm quite new to C and the embedded world, i'm trying to do an interrupt on GPIO36 and GPIO39 (these pins can't be changed). I hardware pull high both of the pins with a 10k Resistance.
I used the ESP-IDF example :
Here is my initialisation :
- #define RESET_BUTTON_0 GPIO_NUM_36
- #define RESET_BUTTON_1 GPIO_NUM_39
- #define GPIO_BUTTON_MASK ((1ULL<<RESET_BUTTON_0) | (1ULL<<RESET_BUTTON_1))
- uint64_t button_down; // store the esp_time
- uint8_t RESET_SECONDS = 10; // Number of seconds to push down RESET_BUTTON for a factory reset
- static xQueueHandle gpio_evt_queue = NULL;
- void IRAM_ATTR button_isr_handler(void* arg) {
- uint32_t gpio_num = (uint32_t) arg;
- xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
- }
- void gpio_output_conf(){
- gpio_config_t io_conf;
- //interrupt of rising edge
- io_conf.intr_type = GPIO_INTR_ANYEDGE;
- //bit mask of the pins,
- io_conf.pin_bit_mask = GPIO_BUTTON_MASK;
- //set as input mode
- io_conf.mode = GPIO_MODE_INPUT;
- // PIN 34-39 dont have pull up or pull down by software
- io_conf.pull_down_en = 0;
- //enable pull-up mode
- io_conf.pull_up_en = 0;
- gpio_config(&io_conf);
- }
[/Codebox]
- void reset_task(void *pvParamater){
- uint32_t io_num;
- while(1){
- if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
- printf("GPIO[%d] intr, val: %d\n", io_num, gpio_get_level(io_num));
- if(gpio_get_level(RESET_BUTTON_0) == 1) {
- button_down = esp_timer_get_time ();
- }
- else {
- // button released, verifiy down time
- if((esp_timer_get_time() - button_down) > RESET_SECONDS * 1000 * 1000){
- printf("Reset button was pressed for more than %d seconds, loading factory firmware...\n,",
- RESET_SECONDS);
- //search the factory partition in flash memory
- esp_partition_iterator_t pi = esp_partition_find(ESP_PARTITION_TYPE_APP,
- ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
- // if partition is found, set it to boot partition and reset the chip
- if (pi != NULL) {
- const esp_partition_t* factory = esp_partition_get(pi);
- esp_partition_iterator_release(pi);
- if(esp_ota_set_boot_partition(factory) == ESP_OK) esp_restart();
- }
- else
- {
- printf("Factory partition not found !\n");
- }
- }
- }
- }
- }
- }
- void app_main() {
- gpio_output_conf();
- gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
- xTaskCreate(reset_task, "reset_task", 8192, NULL, 5, NULL);
- // install ISR and add handler
- gpio_install_isr_service(0);
- gpio_isr_handler_add(RESET_BUTTON_0, button_isr_handler,(void*) RESET_BUTTON_0);
- gpio_isr_handler_add(RESET_BUTTON_1, button_isr_handler,(void*) RESET_BUTTON_1);
- }
I need to trigger the interrupts when the lvl is at 0. not 1.
Thank you for your time,
Tibi