mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-01 22:38:30 +00:00
Merge branch 'feature/utilize_rom_gpio_function' into 'master'
feat(gpio): esp_rom_gpio_connect_in/out_signal now has their hal implementation Closes IDFGH-15397 See merge request espressif/esp-idf!39383
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
#include "soc/usb_serial_jtag_struct.h"
|
||||
#include "hal/gpio_types.h"
|
||||
#include "hal/assert.h"
|
||||
#include "hal/config.h"
|
||||
#include "rom/gpio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -326,21 +328,6 @@ static inline void gpio_ll_od_enable(gpio_dev_t *hw, uint32_t gpio_num)
|
||||
hw->pin[gpio_num].pad_driver = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disconnect any peripheral output signal routed via GPIO matrix to the pin
|
||||
*
|
||||
* @param hw Peripheral GPIO hardware instance address.
|
||||
* @param gpio_num GPIO number
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void gpio_ll_matrix_out_default(gpio_dev_t *hw, uint32_t gpio_num)
|
||||
{
|
||||
gpio_func_out_sel_cfg_reg_t reg = {
|
||||
.out_sel = SIG_GPIO_OUT_IDX,
|
||||
};
|
||||
hw->func_out_sel_cfg[gpio_num].val = reg.val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO set output level
|
||||
*
|
||||
@@ -351,11 +338,15 @@ static inline void gpio_ll_matrix_out_default(gpio_dev_t *hw, uint32_t gpio_num)
|
||||
__attribute__((always_inline))
|
||||
static inline void gpio_ll_set_level(gpio_dev_t *hw, uint32_t gpio_num, uint32_t level)
|
||||
{
|
||||
#if HAL_CONFIG_GPIO_USE_ROM_API
|
||||
gpio_set_output_level(gpio_num, level);
|
||||
#else
|
||||
if (level) {
|
||||
hw->out_w1ts.val = 1 << gpio_num;
|
||||
} else {
|
||||
hw->out_w1tc.val = 1 << gpio_num;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -373,7 +364,11 @@ static inline void gpio_ll_set_level(gpio_dev_t *hw, uint32_t gpio_num, uint32_t
|
||||
__attribute__((always_inline))
|
||||
static inline int gpio_ll_get_level(gpio_dev_t *hw, uint32_t gpio_num)
|
||||
{
|
||||
#if HAL_CONFIG_GPIO_USE_ROM_API
|
||||
return gpio_get_input_level(gpio_num);
|
||||
#else
|
||||
return (hw->in.in_data_next >> gpio_num) & 0x1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -477,6 +472,40 @@ static inline void gpio_ll_set_input_signal_from(gpio_dev_t *hw, uint32_t signal
|
||||
hw->func_in_sel_cfg[signal_idx].sig_in_sel = from_gpio_matrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Connect a GPIO input with a peripheral signal, which tagged as input attribute.
|
||||
*
|
||||
* @note There's no limitation on the number of signals that a GPIO can combine with.
|
||||
*
|
||||
* @param signal_idx Peripheral signal index (tagged as input attribute)
|
||||
* @param gpio_num GPIO number, especially, `GPIO_MATRIX_CONST_ZERO_INPUT` means connect logic 0 to signal
|
||||
* `GPIO_MATRIX_CONST_ONE_INPUT` means connect logic 1 to signal
|
||||
* @param in_inv True if the GPIO input needs to be inverted, otherwise False.
|
||||
*/
|
||||
static inline void gpio_ll_set_input_signal_matrix_source(gpio_dev_t *hw, uint32_t signal_idx, uint32_t gpio_num, bool in_inv)
|
||||
{
|
||||
hw->func_in_sel_cfg[signal_idx].in_sel = gpio_num;
|
||||
hw->func_in_sel_cfg[signal_idx].in_inv_sel = in_inv;
|
||||
gpio_ll_set_input_signal_from(hw, signal_idx, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the GPIO number that is routed to the input peripheral signal through GPIO matrix.
|
||||
*
|
||||
* @param hw Peripheral GPIO hardware instance address.
|
||||
* @param in_sig_idx Peripheral signal index (tagged as input attribute).
|
||||
*
|
||||
* @return
|
||||
* - -1 Signal bypassed GPIO matrix
|
||||
* - Others GPIO number
|
||||
*/
|
||||
static inline int gpio_ll_get_in_signal_connected_io(gpio_dev_t *hw, uint32_t in_sig_idx)
|
||||
{
|
||||
gpio_func_in_sel_cfg_reg_t reg;
|
||||
reg.val = hw->func_in_sel_cfg[in_sig_idx].val;
|
||||
return (reg.sig_in_sel ? reg.in_sel : -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the source of output enable signal for the GPIO pin.
|
||||
*
|
||||
@@ -491,6 +520,21 @@ static inline void gpio_ll_set_output_enable_ctrl(gpio_dev_t *hw, uint8_t gpio_n
|
||||
hw->func_out_sel_cfg[gpio_num].oen_sel = !ctrl_by_periph;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Connect a peripheral signal which tagged as output attribute with a GPIO.
|
||||
*
|
||||
* @note There's no limitation on the number of signals that a GPIO can combine with.
|
||||
*
|
||||
* @param gpio_num GPIO number
|
||||
* @param signal_idx Peripheral signal index (tagged as output attribute). Particularly, `SIG_GPIO_OUT_IDX` means disconnect GPIO and other peripherals. Only the GPIO driver can control the output level.
|
||||
* @param out_inv True if the signal output needs to be inverted, otherwise False.
|
||||
*/
|
||||
static inline void gpio_ll_set_output_signal_matrix_source(gpio_dev_t *hw, uint32_t gpio_num, uint32_t signal_idx, bool out_inv)
|
||||
{
|
||||
hw->func_out_sel_cfg[gpio_num].out_sel = signal_idx;
|
||||
hw->func_out_sel_cfg[gpio_num].out_inv_sel = out_inv;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Select a function for the pin in the IOMUX
|
||||
*
|
||||
@@ -531,23 +575,6 @@ static inline void gpio_ll_iomux_set_clk_src(soc_module_clk_t src)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the GPIO number that is routed to the input peripheral signal through GPIO matrix.
|
||||
*
|
||||
* @param hw Peripheral GPIO hardware instance address.
|
||||
* @param in_sig_idx Peripheral signal index (tagged as input attribute).
|
||||
*
|
||||
* @return
|
||||
* - -1 Signal bypassed GPIO matrix
|
||||
* - Others GPIO number
|
||||
*/
|
||||
static inline int gpio_ll_get_in_signal_connected_io(gpio_dev_t *hw, uint32_t in_sig_idx)
|
||||
{
|
||||
gpio_func_in_sel_cfg_reg_t reg;
|
||||
reg.val = hw->func_in_sel_cfg[in_sig_idx].val;
|
||||
return (reg.sig_in_sel ? reg.in_sel : -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Force hold digital io pad.
|
||||
* @note GPIO force hold, whether the chip in sleep mode or wakeup mode.
|
||||
|
Reference in New Issue
Block a user