feat(ledc): make esp_driver_ledc as component

pull/12901/merge
wanlei 2023-12-28 14:54:19 +08:00
rodzic 227c5d2cb7
commit 82f26471f0
25 zmienionych plików z 79 dodań i 63 usunięć

Wyświetl plik

@ -10,7 +10,6 @@ set(srcs)
# Always included headers
set(includes "deprecated"
"i2c/include"
"ledc/include"
"parlio/include"
"touch_sensor/include"
"twai/include"
@ -54,13 +53,6 @@ if(CONFIG_SOC_I2S_SUPPORTED)
list(APPEND srcs "deprecated/i2s_legacy.c")
endif()
# LEDC related source files
if(CONFIG_SOC_LEDC_SUPPORTED)
list(APPEND srcs "ledc/ledc.c")
list(APPEND ldfragments "ledc/linker.lf")
endif()
# MCPWM legacy driver
if(CONFIG_SOC_MCPWM_SUPPORTED)
list(APPEND srcs "deprecated/mcpwm_legacy.c")
@ -127,7 +119,7 @@ else()
esp_driver_gpio esp_driver_pcnt esp_driver_gptimer esp_driver_spi esp_driver_mcpwm
esp_driver_ana_cmpr esp_driver_i2s esp_driver_sdmmc esp_driver_sdspi esp_driver_sdio
esp_driver_dac esp_driver_rmt esp_driver_tsens esp_driver_sdm esp_driver_i2c
esp_driver_uart
esp_driver_uart esp_driver_ledc
LDFRAGMENTS ${ldfragments}
)
endif()

Wyświetl plik

@ -101,6 +101,4 @@ menu "Driver Configurations"
endmenu # Parallel IO Configuration
orsource "./ledc/Kconfig.ledc"
endmenu # Driver configurations

Wyświetl plik

@ -18,10 +18,6 @@ components/driver/test_apps/i2s_test_apps/legacy_i2s_driver:
temporary: true
reason: lack of runners
components/driver/test_apps/ledc:
disable:
- if: SOC_LEDC_SUPPORTED != 1
components/driver/test_apps/legacy_adc_driver:
disable:
- if: SOC_ADC_SUPPORTED != 1

Wyświetl plik

@ -1,21 +0,0 @@
# This is the project CMakeLists.txt file for the test subproject
cmake_minimum_required(VERSION 3.16)
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
set(COMPONENTS main)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(ledc_test)
if(CONFIG_COMPILER_DUMP_RTL_FILES)
add_custom_target(check_test_app_sections ALL
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py
--rtl-dirs ${CMAKE_BINARY_DIR}/esp-idf/driver/,${CMAKE_BINARY_DIR}/esp-idf/hal/
--elf-file ${CMAKE_BINARY_DIR}/ledc_test.elf
find-refs
--from-sections=.iram0.text
--to-sections=.flash.text,.flash.rodata
--exit-code
DEPENDS ${elf}
)
endif()

Wyświetl plik

@ -0,0 +1,14 @@
set(srcs)
set(public_include "include")
if(CONFIG_SOC_LEDC_SUPPORTED)
list(APPEND srcs "src/ledc.c")
endif()
idf_component_register(
SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES "esp_pm" "esp_driver_gpio"
LDFRAGMENTS "linker.lf"
)

Wyświetl plik

@ -1,4 +1,4 @@
menu "LEDC Configuration"
menu "ESP-Driver:LEDC Configurations"
config LEDC_CTRL_FUNC_IN_IRAM
bool "Place LEDC control functions into IRAM"
@ -8,4 +8,4 @@ menu "LEDC Configuration"
so that these functions can be IRAM-safe and able to be called in an IRAM context.
Enabling this option can improve driver performance as well.
endmenu # LEDC Configuration
endmenu

Wyświetl plik

@ -634,10 +634,10 @@ esp_err_t ledc_cb_register(ledc_mode_t speed_mode, ledc_channel_t channel, ledc_
* @note Be aware of the maximum value available on each element
*/
typedef struct {
uint32_t dir : 1; /*!< Duty change direction. Set 1 as increase, 0 as decrease */
uint32_t cycle_num : SOC_LEDC_FADE_PARAMS_BIT_WIDTH; /*!< Number of PWM cycles of each step [0, 2**SOC_LEDC_FADE_PARAMS_BIT_WIDTH-1] */
uint32_t scale : SOC_LEDC_FADE_PARAMS_BIT_WIDTH; /*!< Duty change of each step [0, 2**SOC_LEDC_FADE_PARAMS_BIT_WIDTH-1] */
uint32_t step_num : SOC_LEDC_FADE_PARAMS_BIT_WIDTH; /*!< Total number of steps in one hardware fade [0, 2**SOC_LEDC_FADE_PARAMS_BIT_WIDTH-1] */
uint32_t dir : 1; /*!< Duty change direction. Set 1 as increase, 0 as decrease */
uint32_t cycle_num : SOC_LEDC_FADE_PARAMS_BIT_WIDTH; /*!< Number of PWM cycles of each step [0, 2**SOC_LEDC_FADE_PARAMS_BIT_WIDTH-1] */
uint32_t scale : SOC_LEDC_FADE_PARAMS_BIT_WIDTH; /*!< Duty change of each step [0, 2**SOC_LEDC_FADE_PARAMS_BIT_WIDTH-1] */
uint32_t step_num : SOC_LEDC_FADE_PARAMS_BIT_WIDTH; /*!< Total number of steps in one hardware fade [0, 2**SOC_LEDC_FADE_PARAMS_BIT_WIDTH-1] */
} ledc_fade_param_config_t;
/**

Wyświetl plik

@ -1,5 +1,5 @@
[mapping:ledc_driver]
archive: libdriver.a
archive: libesp_driver_ledc.a
entries:
if LEDC_CTRL_FUNC_IN_IRAM = y:
ledc: ledc_stop (noflash)

Wyświetl plik

@ -221,7 +221,7 @@ esp_err_t ledc_timer_set(ledc_mode_t speed_mode, ledc_timer_t timer_sel, uint32_
}
static IRAM_ATTR esp_err_t ledc_duty_config(ledc_mode_t speed_mode, ledc_channel_t channel, int hpoint_val,
int duty_val, ledc_duty_direction_t duty_direction, uint32_t duty_num, uint32_t duty_cycle, uint32_t duty_scale)
int duty_val, ledc_duty_direction_t duty_direction, uint32_t duty_num, uint32_t duty_cycle, uint32_t duty_scale)
{
if (hpoint_val >= 0) {
ledc_hal_set_hpoint(&(p_ledc_obj[speed_mode]->ledc_hal), channel, hpoint_val);
@ -347,7 +347,7 @@ static inline uint32_t ledc_calculate_divisor(uint32_t src_clk_freq, int freq_hz
* NOTE: We are also going to round up the value when necessary, thanks to:
* (freq_hz * precision / 2)
*/
return ( ( (uint64_t) src_clk_freq << LEDC_LL_FRACTIONAL_BITS ) + freq_hz * precision / 2 )
return (((uint64_t) src_clk_freq << LEDC_LL_FRACTIONAL_BITS) + freq_hz * precision / 2)
/ (freq_hz * precision);
}
@ -453,7 +453,6 @@ static uint32_t ledc_auto_clk_divisor(ledc_mode_t speed_mode, int freq_hz, uint3
return ret;
}
/**
* @brief Function setting the LEDC timer divisor with the given source clock,
* frequency and resolution. If the clock configuration passed is
@ -462,7 +461,7 @@ static uint32_t ledc_auto_clk_divisor(ledc_mode_t speed_mode, int freq_hz, uint3
static esp_err_t ledc_set_timer_div(ledc_mode_t speed_mode, ledc_timer_t timer_num, ledc_clk_cfg_t clk_cfg, int freq_hz, int duty_resolution)
{
uint32_t div_param = 0;
const uint32_t precision = ( 0x1 << duty_resolution );
const uint32_t precision = (0x1 << duty_resolution);
/* The clock sources are not initialized on purpose. To produce compiler warning if used but the selector functions
* don't set them properly. */
/* Timer-specific mux. Set to timer-specific clock or LEDC_SCLK if a global clock is used. */
@ -480,7 +479,7 @@ static esp_err_t ledc_set_timer_div(ledc_mode_t speed_mode, ledc_timer_t timer_n
/* Before calculating the divisor, we need to have the RC_FAST frequency.
* If it hasn't been measured yet, try calibrating it now. */
if(s_ledc_slow_clk_rc_fast_freq == 0 && ledc_slow_clk_calibrate() == false) {
if (s_ledc_slow_clk_rc_fast_freq == 0 && ledc_slow_clk_calibrate() == false) {
goto error;
}
@ -554,7 +553,7 @@ static esp_err_t ledc_set_timer_div(ledc_mode_t speed_mode, ledc_timer_t timer_n
if (i != timer_num && p_ledc_obj[speed_mode]->glb_clk_is_acquired[i]) {
portEXIT_CRITICAL(&ledc_spinlock);
ESP_RETURN_ON_FALSE(false, ESP_FAIL, LEDC_TAG,
"timer clock conflict, already is %d but attempt to %d", p_ledc_obj[speed_mode]->glb_clk, glb_clk);
"timer clock conflict, already is %d but attempt to %d", p_ledc_obj[speed_mode]->glb_clk, glb_clk);
}
}
}
@ -593,11 +592,12 @@ static esp_err_t ledc_timer_del(ledc_mode_t speed_mode, ledc_timer_t timer_sel)
bool is_configured = true;
bool is_deleted = false;
portENTER_CRITICAL(&ledc_spinlock);
if (p_ledc_obj[speed_mode]->glb_clk_is_acquired[timer_sel] == false
#if SOC_LEDC_HAS_TIMER_SPECIFIC_MUX
&& p_ledc_obj[speed_mode]->timer_specific_clk[timer_sel] == LEDC_TIMER_SPECIFIC_CLK_UNINIT
if (p_ledc_obj[speed_mode]->glb_clk_is_acquired[timer_sel] == false && p_ledc_obj[speed_mode]->timer_specific_clk[timer_sel] == LEDC_TIMER_SPECIFIC_CLK_UNINIT)
#else
if (p_ledc_obj[speed_mode]->glb_clk_is_acquired[timer_sel] == false)
#endif
) {
{
is_configured = false;
} else if (p_ledc_obj[speed_mode]->timer_is_stopped[timer_sel] == true) {
is_deleted = true;
@ -974,7 +974,7 @@ static void IRAM_ATTR ledc_fade_isr(void *arg)
} else {
// Calculate new duty config parameters
delta = (s_ledc_fade_rec[speed_mode][channel]->direction == LEDC_DUTY_DIR_DECREASE) ?
(duty_cur - duty_tar) : (duty_tar - duty_cur);
(duty_cur - duty_tar) : (duty_tar - duty_cur);
if (delta > scale) {
next_duty = duty_cur;
step = (delta / scale > LEDC_DUTY_NUM_MAX) ? LEDC_DUTY_NUM_MAX : (delta / scale);
@ -1227,7 +1227,7 @@ esp_err_t ledc_fade_stop(ledc_mode_t speed_mode, ledc_channel_t channel)
LEDC_ARG_CHECK(speed_mode < LEDC_SPEED_MODE_MAX, "speed_mode");
LEDC_ARG_CHECK(channel < LEDC_CHANNEL_MAX, "channel");
LEDC_CHECK(p_ledc_obj[speed_mode] != NULL, LEDC_NOT_INIT, ESP_ERR_INVALID_STATE);
LEDC_CHECK(ledc_fade_channel_init_check(speed_mode, channel) == ESP_OK , LEDC_FADE_INIT_ERROR_STR, ESP_FAIL);
LEDC_CHECK(ledc_fade_channel_init_check(speed_mode, channel) == ESP_OK, LEDC_FADE_INIT_ERROR_STR, ESP_FAIL);
ledc_fade_t *fade = s_ledc_fade_rec[speed_mode][channel];
ledc_fade_fsm_t state = fade->fsm;
bool wait_for_idle = false;
@ -1250,7 +1250,7 @@ esp_err_t ledc_fade_stop(ledc_mode_t speed_mode, ledc_channel_t channel)
1, //uint32_t duty_num,
1, //uint32_t duty_cycle,
0 //uint32_t duty_scale
);
);
_ledc_update_duty(speed_mode, channel);
state = fade->fsm;
assert(state != LEDC_FSM_IDLE && state != LEDC_FSM_KILLED_PENDING);
@ -1490,7 +1490,7 @@ esp_err_t ledc_fill_multi_fade_param_list(ledc_mode_t speed_mode, ledc_channel_t
uint32_t cycle, scale, step;
gamma_corrected_phase_tail = gamma_correction_operator(phase_tail);
uint32_t duty_delta = (dir == LEDC_DUTY_DIR_INCREASE) ? (gamma_corrected_phase_tail - gamma_corrected_phase_head) :
(gamma_corrected_phase_head - gamma_corrected_phase_tail);
(gamma_corrected_phase_head - gamma_corrected_phase_tail);
uint32_t cycles_per_phase = avg_cycles_per_phase + surplus_cycles_last_phase;
if (duty_delta == 0) {
scale = 0;
@ -1549,7 +1549,7 @@ esp_err_t ledc_fill_multi_fade_param_list(ledc_mode_t speed_mode, ledc_channel_t
}
uint32_t remaining_duty_delta = (dir == LEDC_DUTY_DIR_INCREASE) ? (gamma_corrected_phase_tail - gamma_corrected_phase_head) :
(gamma_corrected_phase_head - gamma_corrected_phase_tail);
(gamma_corrected_phase_head - gamma_corrected_phase_tail);
if (remaining_duty_delta) {
total_fade_range += 1;
}

Wyświetl plik

@ -0,0 +1,7 @@
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
components/esp_driver_ledc/test_apps/ledc:
disable:
- if: SOC_LEDC_SUPPORTED != 1
depends_components:
- esp_driver_ledc

Wyświetl plik

@ -0,0 +1,22 @@
# This is the project CMakeLists.txt file for the test subproject
cmake_minimum_required(VERSION 3.16)
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
set(COMPONENTS main)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(ledc_test)
if(CONFIG_COMPILER_DUMP_RTL_FILES)
add_custom_target(
check_test_app_sections ALL
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py
--rtl-dirs ${CMAKE_BINARY_DIR}/esp-idf/esp_driver_ledc/,${CMAKE_BINARY_DIR}/esp-idf/hal/
--elf-file ${CMAKE_BINARY_DIR}/ledc_test.elf
find-refs
--from-sections=.iram0.text
--to-sections=.flash.text,.flash.rodata
--exit-code
DEPENDS ${elf}
)
endif()

Wyświetl plik

@ -3,6 +3,8 @@ set(srcs "test_app_main.c"
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
# the component can be registered as WHOLE_ARCHIVE
idf_component_register(SRCS ${srcs}
PRIV_REQUIRES unity esp_driver_pcnt driver esp_timer esp_psram
WHOLE_ARCHIVE)
idf_component_register(
SRCS ${srcs}
PRIV_REQUIRES unity esp_driver_pcnt esp_driver_ledc esp_driver_gpio esp_timer esp_psram
WHOLE_ARCHIVE
)

Wyświetl plik

@ -589,7 +589,7 @@ TEST_CASE("LEDC set and get frequency", "[ledc][timeout=60]")
#if SOC_CLK_TREE_SUPPORTED
static void timer_set_clk_src_and_freq_test(ledc_mode_t speed_mode, ledc_clk_cfg_t clk_src, uint32_t duty_res,
uint32_t freq_hz)
uint32_t freq_hz)
{
ledc_timer_config_t ledc_time_config = {
.speed_mode = speed_mode,

Wyświetl plik

@ -73,7 +73,6 @@ INPUT = \
$(PROJECT_PATH)/components/bt/host/bluedroid/api/include/api/esp_spp_api.h \
$(PROJECT_PATH)/components/bt/host/nimble/esp-hci/include/esp_nimble_hci.h \
$(PROJECT_PATH)/components/console/esp_console.h \
$(PROJECT_PATH)/components/driver/ledc/include/driver/ledc.h \
$(PROJECT_PATH)/components/driver/parlio/include/driver/parlio_tx.h \
$(PROJECT_PATH)/components/driver/parlio/include/driver/parlio_types.h \
$(PROJECT_PATH)/components/driver/touch_sensor/include/driver/touch_sensor_common.h \
@ -108,6 +107,7 @@ INPUT = \
$(PROJECT_PATH)/components/esp_driver_gptimer/include/driver/gptimer.h \
$(PROJECT_PATH)/components/esp_driver_gptimer/include/driver/gptimer_etm.h \
$(PROJECT_PATH)/components/esp_driver_gptimer/include/driver/gptimer_types.h \
$(PROJECT_PATH)/components/esp_driver_ledc/include/driver/ledc.h \
$(PROJECT_PATH)/components/esp_driver_mcpwm/include/driver/mcpwm_cap.h \
$(PROJECT_PATH)/components/esp_driver_mcpwm/include/driver/mcpwm_cmpr.h \
$(PROJECT_PATH)/components/esp_driver_mcpwm/include/driver/mcpwm_etm.h \

Wyświetl plik

@ -24,6 +24,7 @@ In order to control the dependence of other components on drivers at a smaller g
- `esp_driver_sdm` - Driver for Sigma-Delta Modulator
- `esp_driver_i2c` - Driver for I2C
- `esp_driver_uart` - Driver for UART
- `esp_driver_ledc` - Driver for LEDC
For compatibility, the original `driver`` component is still treated as an all-in-one component by registering these `esp_driver_xyz`` components as its public dependencies. In other words, you do not need to modify the CMake file of an existing project, but you now have a way to specify the specific peripheral driver that your project depends on.

Wyświetl plik

@ -24,6 +24,7 @@
- `esp_driver_sdm` - Sigma-Delta 调制器驱动
- `esp_driver_i2c` - I2C 驱动
- `esp_driver_uart` - UART 驱动
- `esp_driver_ledc` - LEDC 驱动
为了兼容性,原来的 `driver` 组件仍然存在,并作为一个 “all-in-one" 的组件,将以上这些 `esp_driver_xyz` 组件注册成自己的公共依赖。换句话说,你无需修改既有项目的 CMake 文件,但是你现在多了一个途径去指定你项目依赖的具体的外设驱动。

Wyświetl plik

@ -7,6 +7,6 @@ set(COMPONENT_SRCS
set(COMPONENT_ADD_INCLUDEDIRS ". include")
# requirements can't depend on config
set(COMPONENT_REQUIRES example_nvs driver esp_driver_gpio)
set(COMPONENT_REQUIRES example_nvs driver esp_driver_gpio esp_driver_ledc)
register_component()

Wyświetl plik

@ -169,10 +169,14 @@ examples/peripherals/lcd/tjpgd:
examples/peripherals/ledc:
disable:
- if: SOC_LEDC_SUPPORTED != 1
depends_components:
- esp_driver_ledc
examples/peripherals/ledc/ledc_gamma_curve_fade:
disable:
- if: SOC_LEDC_SUPPORTED != 1 or SOC_LEDC_GAMMA_CURVE_FADE_SUPPORTED != 1
depends_components:
- esp_driver_ledc
examples/peripherals/mcpwm:
disable: