Files
microcontroladores-esp32-co…/capitulo-02/registradores-esp-idf/main/main.c
T
Lucas RayanandClaude Opus 5.5 5f5506c55c
Compilar exemplos / esp32 (push) Canceled after 21m59s
Compilar exemplos / esp32c2 (push) Canceled after 0s
Compilar exemplos / esp32c3 (push) Canceled after 0s
Compilar exemplos / esp32c5 (push) Canceled after 0s
Compilar exemplos / esp32c6 (push) Canceled after 0s
Compilar exemplos / esp32c61 (push) Canceled after 0s
Compilar exemplos / esp32h2 (push) Canceled after 0s
Compilar exemplos / esp32p4 (push) Canceled after 0s
Compilar exemplos / esp32s2 (push) Canceled after 0s
Compilar exemplos / esp32s3 (push) Canceled after 0s
Exemplos do livro Microcontroladores ESP32 como projetos PlatformIO
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 12:10:42 -03:00

36 lines
1.2 KiB
C

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "esp_cpu.h" // esp_cpu_get_cycle_count()
#include "soc/gpio_reg.h" // endereços dos registradores de GPIO
#define PINO GPIO_NUM_4
#define PULSOS 1000
static const char *TAG = "regs";
void app_main(void)
{
gpio_reset_pin(PINO);
gpio_set_direction(PINO, GPIO_MODE_OUTPUT);
// 1) Pela API do driver
uint32_t t0 = esp_cpu_get_cycle_count();
for (int i = 0; i < PULSOS; i++) {
gpio_set_level(PINO, 1);
gpio_set_level(PINO, 0);
}
// 2) Escrevendo direto nos registradores W1TS e W1TC
uint32_t t1 = esp_cpu_get_cycle_count();
for (int i = 0; i < PULSOS; i++) {
REG_WRITE(GPIO_OUT_W1TS_REG, BIT(PINO));
REG_WRITE(GPIO_OUT_W1TC_REG, BIT(PINO));
}
uint32_t t2 = esp_cpu_get_cycle_count();
ESP_LOGI(TAG, "Driver: %lu ciclos por pulso", (unsigned long)((t1 - t0) / PULSOS));
ESP_LOGI(TAG, "Registrador: %lu ciclos por pulso", (unsigned long)((t2 - t1) / PULSOS));
ESP_LOGI(TAG, "GPIO_OUT_W1TS_REG fica no endereço 0x%08lx",
(unsigned long)GPIO_OUT_W1TS_REG);
}