diff --git a/Devices/m5stack-papers3/source/drivers/papers3_power.cpp b/Devices/m5stack-papers3/source/drivers/papers3_power.cpp index 8a60f7378..0fa67d438 100644 --- a/Devices/m5stack-papers3/source/drivers/papers3_power.cpp +++ b/Devices/m5stack-papers3/source/drivers/papers3_power.cpp @@ -192,17 +192,8 @@ static void destroy_power_supply_child(Device* child) { // region Driver lifecycle static error_t acquire_input(const GpioPinSpec& pin, GpioDescriptor** out_descriptor) { - auto* descriptor = gpio_descriptor_acquire_pin_spec(&pin, GPIO_OWNER_GPIO); - if (descriptor == nullptr) { - return ERROR_RESOURCE; - } - error_t error = gpio_descriptor_set_flags(descriptor, pin.flags | GPIO_FLAG_DIRECTION_INPUT); - if (error != ERROR_NONE) { - gpio_descriptor_release(descriptor); - return error; - } - *out_descriptor = descriptor; - return ERROR_NONE; + *out_descriptor = gpio_descriptor_acquire(pin.gpio_controller, pin.pin, GPIO_FLAG_DIRECTION_INPUT, GPIO_OWNER_GPIO); + return (*out_descriptor != nullptr) ? ERROR_NONE : ERROR_RESOURCE; } static error_t start(Device* device) { @@ -226,13 +217,8 @@ static error_t start(Device* device) { return ERROR_RESOURCE; } - internal->power_off_descriptor = gpio_descriptor_acquire_pin_spec(config, GPIO_OWNER_GPIO); - if (internal->power_off_descriptor == nullptr || - gpio_descriptor_set_flags(internal->power_off_descriptor, config->pin_power_off.flags | GPIO_FLAG_DIRECTION_OUTPUT) != ERROR_NONE) { - LOG_E(TAG, "Failed to configure power-off pin"); - if (internal->power_off_descriptor != nullptr) { - gpio_descriptor_release(internal->power_off_descriptor); - } + internal->power_off_descriptor = gpio_descriptor_acquire(config->pin_power_off.gpio_controller, config->pin_power_off.pin, config->pin_power_off.flags | GPIO_FLAG_DIRECTION_OUTPUT, GPIO_OWNER_GPIO); + if (internal->power_off_descriptor == nullptr) { gpio_descriptor_release(internal->usb_detect_descriptor); gpio_descriptor_release(internal->charge_status_descriptor); delete internal; diff --git a/Drivers/audio-codec-module/source/audio_codec_gpio_if.c b/Drivers/audio-codec-module/source/audio_codec_gpio_if.c index 7e869c696..05a7531b9 100644 --- a/Drivers/audio-codec-module/source/audio_codec_gpio_if.c +++ b/Drivers/audio-codec-module/source/audio_codec_gpio_if.c @@ -31,9 +31,10 @@ static struct GpioDescriptor* acquire_descriptor(int16_t gpio, gpio_flags_t flag return NULL; } - struct GpioDescriptor* descriptor = gpio_descriptor_acquire(spec->gpio_controller, spec->pin, flags, GPIO_OWNER_GPIO); + struct GpioDescriptor* descriptor = gpio_descriptor_acquire( + spec->gpio_controller, spec->pin, spec->flags | flags, GPIO_OWNER_GPIO + ); if (descriptor != NULL) { - gpio_descriptor_set_flags(descriptor, spec->flags); g_context->descriptors[gpio] = descriptor; } return descriptor; @@ -55,6 +56,13 @@ static int gpio_setup(int16_t gpio, audio_gpio_dir_t dir, audio_gpio_mode_t mode gpio_descriptor_get_flags(descriptor, &flags); flags &= ~(GPIO_FLAG_DIRECTION_INPUT | GPIO_FLAG_DIRECTION_OUTPUT | GPIO_FLAG_PULL_UP | GPIO_FLAG_PULL_DOWN); + flags |= (dir == AUDIO_GPIO_DIR_OUT) ? GPIO_FLAG_DIRECTION_OUTPUT : GPIO_FLAG_DIRECTION_INPUT; + if ((mode & AUDIO_GPIO_MODE_PULL_UP) != 0) { + flags |= GPIO_FLAG_PULL_UP; + } + if ((mode & AUDIO_GPIO_MODE_PULL_DOWN) != 0) { + flags |= GPIO_FLAG_PULL_DOWN; + } return (gpio_descriptor_set_flags(descriptor, flags) == ERROR_NONE) ? ESP_CODEC_DEV_OK : ESP_CODEC_DEV_DRV_ERR; } diff --git a/Drivers/button-control-module/source/button_control.cpp b/Drivers/button-control-module/source/button_control.cpp index adc376fdb..9facf5e60 100644 --- a/Drivers/button-control-module/source/button_control.cpp +++ b/Drivers/button-control-module/source/button_control.cpp @@ -74,7 +74,7 @@ static error_t acquire_button(const GpioPinSpec& pin, uint32_t short_press_key, return ERROR_NONE; } - auto* descriptor = gpio_descriptor_acquire(pin.gpio_controller, pin.pin, GPIO_FLAG_DIRECTION_INPUT, GPIO_OWNER_GPIO); + auto* descriptor = gpio_descriptor_acquire(pin.gpio_controller, pin.pin, pin.flags | GPIO_FLAG_DIRECTION_INPUT, GPIO_OWNER_GPIO); if (descriptor == nullptr) { LOG_E(TAG, "Failed to acquire GPIO descriptor"); return ERROR_RESOURCE; diff --git a/Drivers/cst816t-module/source/cst816t.cpp b/Drivers/cst816t-module/source/cst816t.cpp index ba704b8de..c66ed825f 100644 --- a/Drivers/cst816t-module/source/cst816t.cpp +++ b/Drivers/cst816t-module/source/cst816t.cpp @@ -46,7 +46,7 @@ struct Cst816tInternal { // datasheet's Tpor/Tron minimum of 100ms), pulses it low for 10ms (Trst minimum is 0.1ms), then // waits another 100ms (Tron) for the chip to finish reinitializing before any I2C traffic. static error_t reset_pulse(GpioDescriptor* descriptor) { - ok = ok && gpio_descriptor_set_level(descriptor, false) == ERROR_NONE; + bool ok = gpio_descriptor_set_level(descriptor, false) == ERROR_NONE; vTaskDelay(pdMS_TO_TICKS(100)); ok = ok && gpio_descriptor_set_level(descriptor, true) == ERROR_NONE; vTaskDelay(pdMS_TO_TICKS(10)); diff --git a/Platforms/platform-esp32/source/drivers/esp32_i2c.cpp b/Platforms/platform-esp32/source/drivers/esp32_i2c.cpp index 3dc2428e0..fd328e477 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_i2c.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_i2c.cpp @@ -157,14 +157,14 @@ static error_t start(Device* device) { auto dts_config = GET_CONFIG(device); auto& sda_spec = dts_config->pinSda; - auto* sda_descriptor = gpio_descriptor_acquire(sda_spec.gpio_controller, sda_spec.pin, GPIO_FLAG_DIRECTION_INPUT_OUTPUT, GPIO_OWNER_GPIO); + auto* sda_descriptor = gpio_descriptor_acquire(sda_spec.gpio_controller, sda_spec.pin, sda_spec.flags | GPIO_FLAG_DIRECTION_INPUT_OUTPUT, GPIO_OWNER_GPIO); if (!sda_descriptor) { LOG_E(TAG, "Failed to acquire pin %u", sda_spec.pin); return ERROR_RESOURCE; } auto& scl_spec = dts_config->pinScl; - auto* scl_descriptor = gpio_descriptor_acquire(scl_spec.gpio_controller, scl_spec.pin, GPIO_FLAG_DIRECTION_OUTPUT, GPIO_OWNER_GPIO); + auto* scl_descriptor = gpio_descriptor_acquire(scl_spec.gpio_controller, scl_spec.pin, scl_spec.flags | GPIO_FLAG_DIRECTION_OUTPUT, GPIO_OWNER_GPIO); if (!scl_descriptor) { LOG_E(TAG, "Failed to acquire pin %u", scl_spec.pin); gpio_descriptor_release(sda_descriptor); diff --git a/Platforms/platform-esp32/source/drivers/esp32_i2c_master.cpp b/Platforms/platform-esp32/source/drivers/esp32_i2c_master.cpp index 8eed4342e..76c8b36fb 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_i2c_master.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_i2c_master.cpp @@ -184,14 +184,14 @@ static error_t start(Device* device) { auto dts_config = GET_CONFIG(device); auto& sda_spec = dts_config->pinSda; - auto* sda_descriptor = gpio_descriptor_acquire(sda_spec.gpio_controller, sda_spec.pin, GPIO_FLAG_DIRECTION_INPUT_OUTPUT, GPIO_OWNER_GPIO); + auto* sda_descriptor = gpio_descriptor_acquire(sda_spec.gpio_controller, sda_spec.pin, sda_spec.flags | GPIO_FLAG_DIRECTION_INPUT_OUTPUT, GPIO_OWNER_GPIO); if (!sda_descriptor) { LOG_E(TAG, "Failed to acquire pin %u", sda_spec.pin); return ERROR_RESOURCE; } auto& scl_spec = dts_config->pinScl; - auto* scl_descriptor = gpio_descriptor_acquire(scl_spec.gpio_controller, scl_spec.pin, GPIO_FLAG_DIRECTION_OUTPUT, GPIO_OWNER_GPIO); + auto* scl_descriptor = gpio_descriptor_acquire(scl_spec.gpio_controller, scl_spec.pin, scl_spec.flags | GPIO_FLAG_DIRECTION_OUTPUT, GPIO_OWNER_GPIO); if (!scl_descriptor) { LOG_E(TAG, "Failed to acquire pin %u", scl_spec.pin); gpio_descriptor_release(sda_descriptor); diff --git a/Platforms/platform-esp32/source/drivers/esp32_i8080.cpp b/Platforms/platform-esp32/source/drivers/esp32_i8080.cpp index 432a777f4..4ec072d6d 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_i8080.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_i8080.cpp @@ -68,9 +68,9 @@ static error_t start(Device* device) { const auto* config = GET_CONFIG(device); bool pins_ok = - acquire_pin_or_set_null(config->pin_dc, GPIO_FLAG_DIRECTION_INPUT, &data->dc_descriptor) && - acquire_pin_or_set_null(config->pin_wr, GPIO_FLAG_DIRECTION_INPUT, &data->wr_descriptor) && - acquire_pin_or_set_null(config->pin_rd, GPIO_FLAG_DIRECTION_INPUT, &data->rd_descriptor) && + acquire_pin_or_set_null(config->pin_dc, GPIO_FLAG_DIRECTION_OUTPUT, &data->dc_descriptor) && + acquire_pin_or_set_null(config->pin_wr, GPIO_FLAG_DIRECTION_OUTPUT, &data->wr_descriptor) && + acquire_pin_or_set_null(config->pin_rd, GPIO_FLAG_DIRECTION_OUTPUT, &data->rd_descriptor) && acquire_pin_or_set_null(config->pin_d0, GPIO_FLAG_DIRECTION_OUTPUT, &data->d0_descriptor) && acquire_pin_or_set_null(config->pin_d1, GPIO_FLAG_DIRECTION_OUTPUT, &data->d1_descriptor) && acquire_pin_or_set_null(config->pin_d2, GPIO_FLAG_DIRECTION_OUTPUT, &data->d2_descriptor) && @@ -91,7 +91,6 @@ static error_t start(Device* device) { // RD is never toggled by the i80 LCD peripheral (write-only bus); drive it high once so the // panel doesn't see spurious read strobes. if (data->rd_descriptor != nullptr) { - gpio_descriptor_set_flags(data->rd_descriptor, GPIO_FLAG_DIRECTION_OUTPUT); gpio_descriptor_set_level(data->rd_descriptor, true); } diff --git a/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp b/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp index b80d29abc..16d850386 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp @@ -84,16 +84,16 @@ static error_t start(Device* device) { // Acquire pins from the specified GPIO pin specs. Optional pins are allowed. bool pins_ok = - acquire_pin_or_set_null(sdmmc_config->pin_clk, GPIO_FLAG_DIRECTION_INPUT, &data->pin_clk_descriptor) && - acquire_pin_or_set_null(sdmmc_config->pin_cmd, GPIO_FLAG_DIRECTION_INPUT, &data->pin_cmd_descriptor) && - acquire_pin_or_set_null(sdmmc_config->pin_d0, GPIO_FLAG_DIRECTION_OUTPUT, &data->pin_d0_descriptor) && - acquire_pin_or_set_null(sdmmc_config->pin_d1, GPIO_FLAG_DIRECTION_OUTPUT, &data->pin_d1_descriptor) && - acquire_pin_or_set_null(sdmmc_config->pin_d2, GPIO_FLAG_DIRECTION_OUTPUT, &data->pin_d2_descriptor) && - acquire_pin_or_set_null(sdmmc_config->pin_d3, GPIO_FLAG_DIRECTION_OUTPUT, &data->pin_d3_descriptor) && - acquire_pin_or_set_null(sdmmc_config->pin_d4, GPIO_FLAG_DIRECTION_OUTPUT, &data->pin_d4_descriptor) && - acquire_pin_or_set_null(sdmmc_config->pin_d5, GPIO_FLAG_DIRECTION_OUTPUT, &data->pin_d5_descriptor) && - acquire_pin_or_set_null(sdmmc_config->pin_d6, GPIO_FLAG_DIRECTION_OUTPUT, &data->pin_d6_descriptor) && - acquire_pin_or_set_null(sdmmc_config->pin_d7, GPIO_FLAG_DIRECTION_OUTPUT, &data->pin_d7_descriptor) && + acquire_pin_or_set_null(sdmmc_config->pin_clk, GPIO_FLAG_DIRECTION_OUTPUT, &data->pin_clk_descriptor) && + acquire_pin_or_set_null(sdmmc_config->pin_cmd, GPIO_FLAG_DIRECTION_OUTPUT, &data->pin_cmd_descriptor) && + acquire_pin_or_set_null(sdmmc_config->pin_d0, GPIO_FLAG_DIRECTION_INPUT_OUTPUT, &data->pin_d0_descriptor) && + acquire_pin_or_set_null(sdmmc_config->pin_d1, GPIO_FLAG_DIRECTION_INPUT_OUTPUT, &data->pin_d1_descriptor) && + acquire_pin_or_set_null(sdmmc_config->pin_d2, GPIO_FLAG_DIRECTION_INPUT_OUTPUT, &data->pin_d2_descriptor) && + acquire_pin_or_set_null(sdmmc_config->pin_d3, GPIO_FLAG_DIRECTION_INPUT_OUTPUT, &data->pin_d3_descriptor) && + acquire_pin_or_set_null(sdmmc_config->pin_d4, GPIO_FLAG_DIRECTION_INPUT_OUTPUT, &data->pin_d4_descriptor) && + acquire_pin_or_set_null(sdmmc_config->pin_d5, GPIO_FLAG_DIRECTION_INPUT_OUTPUT, &data->pin_d5_descriptor) && + acquire_pin_or_set_null(sdmmc_config->pin_d6, GPIO_FLAG_DIRECTION_INPUT_OUTPUT, &data->pin_d6_descriptor) && + acquire_pin_or_set_null(sdmmc_config->pin_d7, GPIO_FLAG_DIRECTION_INPUT_OUTPUT, &data->pin_d7_descriptor) && acquire_pin_or_set_null(sdmmc_config->pin_cd, GPIO_FLAG_DIRECTION_INPUT, &data->pin_cd_descriptor) && acquire_pin_or_set_null(sdmmc_config->pin_wp, GPIO_FLAG_DIRECTION_INPUT, &data->pin_wp_descriptor); diff --git a/TactilityKernel/source/drivers/gpio_hog.cpp b/TactilityKernel/source/drivers/gpio_hog.cpp index 92fb394c7..408faf79c 100644 --- a/TactilityKernel/source/drivers/gpio_hog.cpp +++ b/TactilityKernel/source/drivers/gpio_hog.cpp @@ -35,13 +35,13 @@ static error_t start(Device* device) { return ERROR_RESOURCE; } - auto* descriptor = gpio_descriptor_acquire(config->pin.gpio_controller, config->pin.pin, flags, GPIO_OWNER_HOG); + auto* descriptor = gpio_descriptor_acquire(config->pin.gpio_controller, config->pin.pin, config->pin.flags | flags, GPIO_OWNER_HOG); if (descriptor == nullptr) { LOG_E(TAG, "Failed to acquire GPIO descriptor"); return ERROR_RESOURCE; } - if (gpio_descriptor_set_level(descriptor, initial_high) != ERROR_NONE) { + if (initial_high && gpio_descriptor_set_level(descriptor, initial_high) != ERROR_NONE) { LOG_E(TAG, "Failed to set initial level to %d", (int)initial_high); gpio_descriptor_release(descriptor); return ERROR_RESOURCE;