Skip to content

rodrigo-s-lange/esp-gpio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

esp_gpio

GPIO helper layer over ESP-IDF native GPIO and LEDC APIs.

Features

  • pinMode, digitalWrite, digitalRead
  • analogWrite over 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

Init policy

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>]

Usage

#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));
}

API

  • 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)

Arduino-like modes

  • INPUT
  • OUTPUT
  • INPUT_PULLUP
  • INPUT_PULLDOWN
  • INPUT_FLOATING
  • INPUT_OUTPUT

Notes

  • 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> configures INPUT_FLOATING automatically if the pin was not configured before.
  • AT+GPIO=<pin>,<value> configures OUTPUT automatically if the pin was not configured before.

Repository

https://github.com/rodrigo-s-lange/esp-gpio

About

Basic GPIO abstraction over native ESP-IDF driver APIs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors