Skip to content

issue #316 breaks interoperability with espressif/esp_io_expander #368

Description

@cnf

the patch applied due to #316 breaks interoperability with https://components.espressif.com/components/espressif/esp_io_expander/ as that only supports GPIO_MODE_INPUT, GPIO_MODE_OUTPUT, and GPIO_MODE_OUTPUT_OD

I could work around with with handleexternalpin, but then i lose the concurrency safety etc.

relevant code here:

esp_err_t esp_io_expander_gpio_wrapper_set_direction(gpio_num_t gpio_num, gpio_mode_t mode)
{
    esp_io_expander_handle_t handle = NULL;
    uint32_t pin_mask = 0;
    if (!find_ioexp_for_num((uint32_t)gpio_num, &handle, &pin_mask)) {
        ESP_LOGE(TAG, "GPIO %d is not assigned to any IO Expander", gpio_num);
        return ESP_ERR_INVALID_ARG;
    }
    esp_io_expander_dir_t dir;
    esp_io_expander_output_mode_t out_mode = IO_EXPANDER_OUTPUT_MODE_PUSH_PULL;
    bool mode_valid = true;
    switch (mode) {
    case GPIO_MODE_INPUT:
        dir = IO_EXPANDER_INPUT;
        break;
    case GPIO_MODE_OUTPUT:
        dir = IO_EXPANDER_OUTPUT;
        out_mode = IO_EXPANDER_OUTPUT_MODE_PUSH_PULL;
        break;
    case GPIO_MODE_OUTPUT_OD:
        dir = IO_EXPANDER_OUTPUT;
        out_mode = IO_EXPANDER_OUTPUT_MODE_OPEN_DRAIN;
        if (!handle->write_highz_reg) {
            mode_valid = false;
        }
        break;
    default:
        mode_valid = false;
    }
    if (!mode_valid) {
        ESP_LOGE(TAG, "Unsupported GPIO mode %d for IO Expander GPIO %d", mode, gpio_num);
        return ESP_ERR_INVALID_ARG;
    }
    esp_err_t err = esp_io_expander_set_dir(handle, pin_mask, dir);
    if (err == ESP_OK && dir == IO_EXPANDER_OUTPUT && handle->write_highz_reg) {
        err = esp_io_expander_set_output_mode(handle, pin_mask, out_mode);
    }
    return err;
}

https://github.com/espressif/esp-bsp/blob/eb76dc6ecf21ccc4ee7ee58bfea3d3d31fa090cf/components/io_expander/esp_io_expander/esp_io_expander_gpio_wrapper.c#L175-L213

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions