#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "rom/gpio.h"
#include "driver/gpio.h"
// --- Registradores importantes ---
#define GPIO_OUT_REG 0x3FF44004
#define GPIO_ENABLE_W1TS_REG 0x3FF44020
#define GPIO_ENABLE_W1TC_REG 0x3FF44028
#define GPIO_IN1_REG 0x3FF44040 // GPIO32 ~ GPIO39
// --- Definição das chaves (entradas) ---
#define chave1 32 // bit0
#define chave2 33 // bit1
#define chave3 34 // bit2
#define chave4 35 // bit3
// --- Definição dos LEDs (saídas) ---
#define led0 19
#define led1 21
#define led2 22
#define led3 23
uint8_t chave[4] = { chave1, chave2, chave3, chave4 };
void app_main() {
//configura as chaves como entrada
for (uint8_t index = 0; index < 4; index++ ){
gpio_pad_select_gpio( chave[ index ] );
gpio_set_direction ( chave[ index ], GPIO_MODE_INPUT );
gpio_set_pull_mode ( chave[ index ], GPIO_PULLUP_ONLY);
}
// --- Configura LEDs como saída ---
REG_WRITE(GPIO_ENABLE_W1TS_REG, (1 << led0) | (1 << led1) |
(1 << led2) | (1 << led3));
while (1) {
// --- Lê as chaves (bits 0..3 do GPIO_IN1_REG) ---
uint32_t estado = REG_READ(GPIO_IN1_REG) & 0x0F;
// --- Atualiza LEDs (ligados no GPIO19,21,22,23) ---
// limpa antes
//REG_WRITE(GPIO_OUT_REG, (estado << 19));
// printf("Chaves em binário = 0x%X\n", estado);
vTaskDelay(pdMS_TO_TICKS(200));
}
}