//Librerias ANSI C|
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
//Librerias ESP-IDF
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
//Macros
#define LED1 GPIO_NUM_2
#define LED2 GPIO_NUM_4
#define BUTTON1 GPIO_NUM_34
#define BUTTON2 GPIO_NUM_26
#define HIGH 1
#define LOW 0
//Prototipo de funcion
void port_init (void);
void app_main (void)
{
//Port init
port_init();
while(1)
{
//Leer el button1
if(0 == gpio_get_level(BUTTON1))
{
gpio_set_level(LED1, HIGH);
}
else
{
gpio_set_level(LED1, LOW);
}
//Leer el button2
if(0 == gpio_get_level(BUTTON2))
{
gpio_set_level(LED2, HIGH);
}
else
{
gpio_set_level(LED2, LOW);
}
vTaskDelay(pdMS_TO_TICKS(100));
}
}
void port_init (void)
{
/* Conversiones en ANSI C
* 1U -> 16 bits
* 1UL -> 32 bits
* 1ULL -> 64 bits
* */
//configuracion de GPIOs
gpio_config_t gpio_cfg ={
.pin_bit_mask = (1ULL << GPIO_NUM_34)|(1ULL << GPIO_NUM_26),
.mode = GPIO_MODE_INPUT,
//.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE,
};
//Establecer configuraciones al HW
gpio_config(&gpio_cfg);
//Configuracion de salidas
gpio_cfg.pin_bit_mask = (1ULL << GPIO_NUM_2) | (1ULL << GPIO_NUM_4);
gpio_cfg.mode = GPIO_MODE_OUTPUT;
gpio_cfg.pull_up_en = GPIO_PULLUP_DISABLE;
gpio_cfg.pull_down_en = GPIO_PULLDOWN_DISABLE;
gpio_cfg.intr_type = GPIO_INTR_DISABLE;
//Establecer configuraciones al HW
gpio_config(&gpio_cfg);
}