mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-03 08:31:44 +01:00
gpio: support glitch filter on esp32h2
This commit is contained in:
55
components/hal/esp32h2/include/hal/dedic_gpio_cpu_ll.h
Normal file
55
components/hal/esp32h2/include/hal/dedic_gpio_cpu_ll.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "riscv/csr.h"
|
||||
|
||||
/*fast gpio*/
|
||||
#define CSR_GPIO_OEN_USER 0x803
|
||||
#define CSR_GPIO_IN_USER 0x804
|
||||
#define CSR_GPIO_OUT_USER 0x805
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
__attribute__((always_inline))
|
||||
static inline void dedic_gpio_cpu_ll_enable_output(uint32_t mask)
|
||||
{
|
||||
RV_WRITE_CSR(CSR_GPIO_OEN_USER, mask);
|
||||
}
|
||||
|
||||
static inline void dedic_gpio_cpu_ll_write_all(uint32_t value)
|
||||
{
|
||||
RV_WRITE_CSR(CSR_GPIO_OUT_USER, value);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
static inline uint32_t dedic_gpio_cpu_ll_read_in(void)
|
||||
{
|
||||
uint32_t value = RV_READ_CSR(CSR_GPIO_IN_USER);
|
||||
return value;
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
static inline uint32_t dedic_gpio_cpu_ll_read_out(void)
|
||||
{
|
||||
uint32_t value = RV_READ_CSR(CSR_GPIO_OUT_USER);
|
||||
return value;
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
static inline void dedic_gpio_cpu_ll_write_mask(uint32_t mask, uint32_t value)
|
||||
{
|
||||
RV_SET_CSR(CSR_GPIO_OUT_USER, mask & value);
|
||||
RV_CLEAR_CSR(CSR_GPIO_OUT_USER, mask & ~(value));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
66
components/hal/esp32h2/include/hal/gpio_glitch_filter_ll.h
Normal file
66
components/hal/esp32h2/include/hal/gpio_glitch_filter_ll.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* NOTICE
|
||||
* The hal is not public api, don't use in application code.
|
||||
* See readme.md in hal/include/hal/readme.md
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "hal/assert.h"
|
||||
#include "soc/gpio_ext_struct.h"
|
||||
|
||||
#define GPIO_LL_GLITCH_FILTER_MAX_WINDOW 64
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enable GPIO glitch filter
|
||||
*
|
||||
* @param hw Glitch filter register base address
|
||||
* @param filter_idx Glitch filter index
|
||||
* @param enable True to enable, false to disable
|
||||
*/
|
||||
static inline void gpio_ll_glitch_filter_enable(gpio_glitch_filter_dev_t *hw, uint32_t filter_idx, bool enable)
|
||||
{
|
||||
hw->glitch_filter_chn[filter_idx].filter_chn_en = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the input GPIO for the glitch filter
|
||||
*
|
||||
* @param hw Glitch filter register base address
|
||||
* @param filter_idx Glitch filter index
|
||||
* @param gpio_num GPIO number
|
||||
*/
|
||||
static inline void gpio_ll_glitch_filter_set_gpio(gpio_glitch_filter_dev_t *hw, uint32_t filter_idx, uint32_t gpio_num)
|
||||
{
|
||||
hw->glitch_filter_chn[filter_idx].filter_chn_input_io_num = gpio_num;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the coefficient of the glitch filter window
|
||||
*
|
||||
* @param hw Glitch filter register base address
|
||||
* @param filter_idx Glitch filter index
|
||||
* @param window_width Window width, in IOMUX clock ticks
|
||||
* @param window_threshold Window threshold, in IOMUX clock ticks
|
||||
*/
|
||||
static inline void gpio_ll_glitch_filter_set_window_coeff(gpio_glitch_filter_dev_t *hw, uint32_t filter_idx, uint32_t window_width, uint32_t window_thres)
|
||||
{
|
||||
HAL_ASSERT(window_thres <= window_width);
|
||||
hw->glitch_filter_chn[filter_idx].filter_chn_window_width = window_width - 1;
|
||||
hw->glitch_filter_chn[filter_idx].filter_chn_window_thres = window_thres - 1;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user