GPIO helper layer over ESP-IDF native GPIO and LEDC APIs.
pinMode,digitalWrite,digitalReadanalogWriteover LEDC- asynchronous software blink
- pull-up / pull-down configuration
- pin ownership control between GPIO, PWM and blink
- optional AT commands for bench validation
- optional internal logs
esp_gpio_init(log_enabled, at_enabled) controls optional behavior.
log_enabled- enables component logs
at_enabled- registers AT commands:
AT+GPIO=<pin>,<value>AT+GPIO?=<pin>AT+GPIO_MODE=<pin>,<mode>AT+PWM=<pin>,<duty>AT+PWM_FREQ=<hz>AT+PWM_RES=<bits>AT+BLINK=<pin>,<hz>[,<cycles>]
- registers AT commands:
#include "esp_gpio.h"
void app_main(void)
{
ESP_ERROR_CHECK(esp_gpio_init(false, false));
ESP_ERROR_CHECK(pinMode(2, OUTPUT));
ESP_ERROR_CHECK(digitalWrite(2, true));
ESP_ERROR_CHECK(analogWrite(4, 127));
ESP_ERROR_CHECK(blink(23, 0.5, 10));
}esp_gpio_init(log_enabled, at_enabled)esp_gpio_deinit()esp_gpio_is_initialized()esp_gpio_set_owner_release_handler()esp_gpio_claim_owner()esp_gpio_release_owner()esp_gpio_get_owner()esp_gpio_owner_to_string()esp_gpio_pin_mode(pin, mode)esp_gpio_set_pull(pin, pull)esp_gpio_digital_write(pin, level)esp_gpio_digital_read(pin, &level)esp_gpio_analog_write(pin, duty)esp_gpio_blink(pin, hz, cycles)esp_gpio_pwm_set_frequency(hz)esp_gpio_pwm_set_resolution(bits)pinMode(pin, mode)pullMode(pin, pull)digitalWrite(pin, level)digitalRead(pin, &level)analogWrite(pin, duty)blink(pin, hz, cycles)analogWriteFreq(hz)analogWriteResolution(bits)
INPUTOUTPUTINPUT_PULLUPINPUT_PULLDOWNINPUT_FLOATINGINPUT_OUTPUT
- Call
esp_gpio_init(...)before using the component. - Invalid pins return
ESP_ERR_INVALID_ARG. - Output-only operations reject input-only pins.
- PWM frequency and resolution are global to the component.
- Blink is asynchronous and non-blocking.
- Supported blink frequency range:
0 < hz <= 20. AT+GPIO?=<pin>configuresINPUT_FLOATINGautomatically if the pin was not configured before.AT+GPIO=<pin>,<value>configuresOUTPUTautomatically if the pin was not configured before.