// /*
#include <stdio.h>
#include <stdbool.h>
#include <esp_timer.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <esp_err.h>
#include <esp_log.h>
#include <driver/gpio.h>
bool state = true;
void app_main()
{
gpio_set_direction(GPIO_NUM_2,GPIO_MODE_INPUT_OUTPUT);
// gpio_set_level(GPIO_NUM_2, false);
gpio_set_level(GPIO_NUM_2, state);
while(true)
{
// ESP_LOGI("timer-isr","GPIO STATE = %d",(gpio_get_level(GPIO_NUM_2)));
printf("GPIO STATE = %d\n",(gpio_get_level(GPIO_NUM_2)));
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
void timer_1_isr(void* args)
{
state = !state;
gpio_set_level(GPIO_NUM_2, state);
}
void timer_init()
{
// Setup and start timer with calculated interval
esp_timer_create_args_t timer_1_args = {
// Timer ISR
.callback = &timer_1_isr,
.name = "square_wave_timer_1"
};
// Temporary Timer Handler 1
esp_timer_handle_t timer_1;
// Create a timer associated with this handler
ESP_ERROR_CHECK(esp_timer_create(&timer_1_args, &timer_1));
// Start the periodic timer start 0f 1s
ESP_ERROR_CHECK(esp_timer_start_periodic(timer_1, 1000000));
}
// */
// #include <stdio.h>
// #include "esp_timer.h"
// #include "freertos/FreeRTOS.h"
// #include "freertos/task.h"
// #include "esp_log.h"
// #include "driver/gpio.h"
// void timer_callback(void *param)
// {
// static bool ON;
// ON = !ON;
// gpio_set_level(GPIO_NUM_2, ON);
// }
// void app_main(void)
// {
// gpio_pad_select_gpio(GPIO_NUM_2);
// gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT);
// const esp_timer_create_args_t my_timer_args = {
// .callback = &timer_callback,
// .name = "My Timer"};
// esp_timer_handle_t timer_handler;
// ESP_ERROR_CHECK(esp_timer_create(&my_timer_args, &timer_handler));
// ESP_ERROR_CHECK(esp_timer_start_periodic(timer_handler, 50));
// while (true)
// {
// esp_timer_dump(stdout);
// vTaskDelay(pdMS_TO_TICKS(1000));
// }
// }
// void timer_0.0_init()
// {
// // Select and initialize basic parameters of the timer
// timer_config_t config = {
// .divider = 16,
// .counter_dir = TIMER_COUNT_UP,
// .counter_en = TIMER_PAUSE,
// .alarm_en = TIMER_ALARM_EN,
// .auto_reload = true,
// }; // default clock source is APB (Advanced Peripheral Bus)
// timer_init(TIMER_GROUP_0, TIMER_0, &config);
// /* Timer's counter will initially start from value below.
// Also, if auto_reload is set, this value will be automatically reload on alarm */
// timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);
// /* Configure the alarm value and the interrupt on alarm. */
// // timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, 0.0001 * TIMER_SCALE); // 100 us timer
// // timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, TIMER_SCALE * 0.0001); // 100 us
// timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, TIMER_SCALE * 0.00002); // 20 us timer
// timer_enable_intr(TIMER_GROUP_0, TIMER_0);
// timer_info_t *timer_info = calloc(1, sizeof(timer_info_t));
// timer_info->timer_group = TIMER_GROUP_0;
// timer_info->timer_idx = TIMER_0;
// timer_info->auto_reload = true;
// timer_info->alarm_interval = 1;
// timer_isr_callback_add(TIMER_GROUP_0, TIMER_0, timer_group_isr_callback, timer_info, 0);
// timer_start(TIMER_GROUP_0, TIMER_0);
// }