feat(mcpwm): refactor mcpwm driver into a component

This commit is contained in:
morris
2023-10-30 10:59:17 +08:00
parent 92c4714128
commit eb5183f503
59 changed files with 167 additions and 143 deletions

View File

@@ -15,7 +15,6 @@ set(includes "include"
"i2c/include" "i2c/include"
"i2s/include" "i2s/include"
"ledc/include" "ledc/include"
"mcpwm/include"
"parlio/include" "parlio/include"
"rmt/include" "rmt/include"
"sdio_slave/include" "sdio_slave/include"
@@ -103,21 +102,9 @@ if(CONFIG_SOC_LEDC_SUPPORTED)
list(APPEND ldfragments "ledc/linker.lf") list(APPEND ldfragments "ledc/linker.lf")
endif() endif()
# MCPWM related source files # MCPWM legacy driver
if(CONFIG_SOC_MCPWM_SUPPORTED) if(CONFIG_SOC_MCPWM_SUPPORTED)
list(APPEND srcs "mcpwm/mcpwm_cap.c" list(APPEND srcs "deprecated/mcpwm_legacy.c")
"mcpwm/mcpwm_cmpr.c"
"mcpwm/mcpwm_com.c"
"mcpwm/mcpwm_fault.c"
"mcpwm/mcpwm_gen.c"
"mcpwm/mcpwm_oper.c"
"mcpwm/mcpwm_sync.c"
"mcpwm/mcpwm_timer.c"
"deprecated/mcpwm_legacy.c")
if(CONFIG_SOC_MCPWM_SUPPORT_ETM)
list(APPEND srcs "mcpwm/mcpwm_etm.c")
endif()
list(APPEND ldfragments "mcpwm/linker.lf")
endif() endif()
# PCNT legacy driver # PCNT legacy driver
@@ -211,7 +198,7 @@ else()
REQUIRES esp_pm esp_ringbuf freertos soc hal esp_hw_support REQUIRES esp_pm esp_ringbuf freertos soc hal esp_hw_support
# for backward compatibility, the driver component needs to # for backward compatibility, the driver component needs to
# have a public dependency on other "esp_driver_foo" components # have a public dependency on other "esp_driver_foo" components
esp_driver_gpio esp_driver_pcnt esp_driver_gptimer esp_driver_spi esp_driver_gpio esp_driver_pcnt esp_driver_gptimer esp_driver_spi esp_driver_mcpwm
LDFRAGMENTS ${ldfragments} LDFRAGMENTS ${ldfragments}
) )
endif() endif()

View File

@@ -147,8 +147,6 @@ menu "Driver Configurations"
orsource "./rmt/Kconfig.rmt" orsource "./rmt/Kconfig.rmt"
orsource "./mcpwm/Kconfig.mcpwm"
menu "I2S Configuration" menu "I2S Configuration"
depends on SOC_I2S_SUPPORTED depends on SOC_I2S_SUPPORTED
config I2S_ISR_IRAM_SAFE config I2S_ISR_IRAM_SAFE

View File

@@ -74,10 +74,14 @@ components/driver/test_apps/legacy_i2c_driver:
components/driver/test_apps/legacy_mcpwm_driver: components/driver/test_apps/legacy_mcpwm_driver:
disable: disable:
- if: SOC_MCPWM_SUPPORTED != 1 - if: SOC_MCPWM_SUPPORTED != 1
depends_filepatterns:
- components/driver/deprecated/**/*mcpwm*
components/driver/test_apps/legacy_pcnt_driver: components/driver/test_apps/legacy_pcnt_driver:
disable: disable:
- if: SOC_PCNT_SUPPORTED != 1 - if: SOC_PCNT_SUPPORTED != 1
depends_filepatterns:
- components/driver/deprecated/**/*pcnt*
components/driver/test_apps/legacy_rmt_driver: components/driver/test_apps/legacy_rmt_driver:
disable: disable:
@@ -98,10 +102,8 @@ components/driver/test_apps/legacy_sigma_delta_driver:
components/driver/test_apps/legacy_timer_driver: components/driver/test_apps/legacy_timer_driver:
disable: disable:
- if: SOC_GPTIMER_SUPPORTED != 1 - if: SOC_GPTIMER_SUPPORTED != 1
depends_filepatterns:
components/driver/test_apps/mcpwm: - components/driver/deprecated/**/*timer*
disable:
- if: SOC_MCPWM_SUPPORTED != 1
components/driver/test_apps/parlio: components/driver/test_apps/parlio:
disable: disable:

View File

@@ -8,5 +8,5 @@ endif()
# In order for the cases defined by `TEST_CASE` to be linked into the final elf, # In order for the cases defined by `TEST_CASE` to be linked into the final elf,
# the component can be registered as WHOLE_ARCHIVE # the component can be registered as WHOLE_ARCHIVE
idf_component_register(SRCS ${srcs} idf_component_register(SRCS ${srcs}
PRIV_REQUIRES unity driver PRIV_REQUIRES unity esp_driver_gptimer
WHOLE_ARCHIVE) WHOLE_ARCHIVE)

View File

@@ -0,0 +1,21 @@
set(srcs)
set(public_include "include")
if(CONFIG_SOC_MCPWM_SUPPORTED)
list(APPEND srcs "src/mcpwm_cap.c"
"src/mcpwm_cmpr.c"
"src/mcpwm_com.c"
"src/mcpwm_fault.c"
"src/mcpwm_gen.c"
"src/mcpwm_oper.c"
"src/mcpwm_sync.c"
"src/mcpwm_timer.c")
if(CONFIG_SOC_MCPWM_SUPPORT_ETM)
list(APPEND srcs "src/mcpwm_etm.c")
endif()
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES "esp_pm" "esp_driver_gpio"
LDFRAGMENTS "linker.lf"
)

View File

@@ -1,4 +1,4 @@
menu "MCPWM Configuration" menu "ESP-Driver:MCPWM Configurations"
depends on SOC_MCPWM_SUPPORTED depends on SOC_MCPWM_SUPPORTED
config MCPWM_ISR_IRAM_SAFE config MCPWM_ISR_IRAM_SAFE
bool "Place MCPWM ISR function into IRAM" bool "Place MCPWM ISR function into IRAM"
@@ -30,4 +30,4 @@ menu "MCPWM Configuration"
help help
Wether to enable the debug log message for MCPWM driver. Wether to enable the debug log message for MCPWM driver.
Note that, this option only controls the MCPWM driver log, won't affect other drivers. Note that, this option only controls the MCPWM driver log, won't affect other drivers.
endmenu # MCPWM Configuration endmenu

View File

@@ -1,5 +1,5 @@
[mapping:mcpwm_driver] [mapping:mcpwm_driver]
archive: libdriver.a archive: libesp_driver_mcpwm.a
entries: entries:
if MCPWM_CTRL_FUNC_IN_IRAM = y: if MCPWM_CTRL_FUNC_IN_IRAM = y:
mcpwm_cmpr: mcpwm_comparator_set_compare_value (noflash) mcpwm_cmpr: mcpwm_comparator_set_compare_value (noflash)

View File

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

View File

@@ -10,7 +10,7 @@ project(mcpwm_test)
if(CONFIG_COMPILER_DUMP_RTL_FILES) if(CONFIG_COMPILER_DUMP_RTL_FILES)
add_custom_target(check_test_app_sections ALL add_custom_target(check_test_app_sections ALL
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py
--rtl-dirs ${CMAKE_BINARY_DIR}/esp-idf/driver/,${CMAKE_BINARY_DIR}/esp-idf/hal/ --rtl-dirs ${CMAKE_BINARY_DIR}/esp-idf/esp_driver_mcpwm/,${CMAKE_BINARY_DIR}/esp-idf/hal/
--elf-file ${CMAKE_BINARY_DIR}/mcpwm_test.elf --elf-file ${CMAKE_BINARY_DIR}/mcpwm_test.elf
find-refs find-refs
--from-sections=.iram0.text --from-sections=.iram0.text

View File

@@ -16,5 +16,5 @@ endif()
# In order for the cases defined by `TEST_CASE` to be linked into the final elf, # In order for the cases defined by `TEST_CASE` to be linked into the final elf,
# the component can be registered as WHOLE_ARCHIVE # the component can be registered as WHOLE_ARCHIVE
idf_component_register(SRCS ${srcs} idf_component_register(SRCS ${srcs}
PRIV_REQUIRES unity driver PRIV_REQUIRES unity esp_driver_mcpwm esp_driver_gpio
WHOLE_ARCHIVE) WHOLE_ARCHIVE)

View File

@@ -163,7 +163,6 @@ TEST_CASE("mcpwm_group_set_prescale_dynamically", "[mcpwm]")
carrier_config.first_pulse_duration_us = 5; carrier_config.first_pulse_duration_us = 5;
TEST_ESP_OK(mcpwm_operator_apply_carrier(oper, &carrier_config)); TEST_ESP_OK(mcpwm_operator_apply_carrier(oper, &carrier_config));
TEST_ESP_OK(mcpwm_del_generator(generator)); TEST_ESP_OK(mcpwm_del_generator(generator));
TEST_ESP_OK(mcpwm_del_operator(oper)); TEST_ESP_OK(mcpwm_del_operator(oper));
TEST_ESP_OK(mcpwm_del_timer(timer)); TEST_ESP_OK(mcpwm_del_timer(timer));

View File

@@ -9,6 +9,5 @@ endif()
# In order for the cases defined by `TEST_CASE` to be linked into the final elf, # In order for the cases defined by `TEST_CASE` to be linked into the final elf,
# the component can be registered as WHOLE_ARCHIVE # the component can be registered as WHOLE_ARCHIVE
idf_component_register(SRCS ${srcs} idf_component_register(SRCS ${srcs}
PRIV_REQUIRES unity esp_driver_pcnt spi_flash PRIV_REQUIRES unity esp_driver_pcnt esp_driver_gpio spi_flash
driver # will be replaced by esp_driver_gpio
WHOLE_ARCHIVE) WHOLE_ARCHIVE)

View File

@@ -16,8 +16,9 @@ components/esp_hw_support/test_apps/etm:
depends_components: depends_components:
- esp_driver_gptimer - esp_driver_gptimer
- esp_driver_gpio - esp_driver_gpio
- esp_driver_mcpwm
- esp_timer - esp_timer
- driver # TODO: replace with esp_driver_mcpwm, esp_driver_ana_cmpr - driver # TODO: replace with esp_driver_ana_cmpr (IDF-8521)
components/esp_hw_support/test_apps/host_test_linux: components/esp_hw_support/test_apps/host_test_linux:
enable: enable:

View File

@@ -29,6 +29,6 @@ endif()
# In order for the cases defined by `TEST_CASE` to be linked into the final elf, # In order for the cases defined by `TEST_CASE` to be linked into the final elf,
# the component can be registered as WHOLE_ARCHIVE # the component can be registered as WHOLE_ARCHIVE
idf_component_register(SRCS ${srcs} idf_component_register(SRCS ${srcs}
PRIV_REQUIRES unity esp_timer esp_driver_gptimer esp_driver_gpio PRIV_REQUIRES unity esp_timer esp_driver_gptimer esp_driver_gpio esp_driver_mcpwm
driver # TODO: replace with esp_driver_mcpwm (IDF-8379), esp_driver_ana_cmpr driver # TODO: replace with esp_driver_ana_cmpr (IDF-8521)
WHOLE_ARCHIVE) WHOLE_ARCHIVE)

View File

@@ -92,7 +92,7 @@ typedef union {
Color Conversion Color Conversion
---------------------------------------------------------------*/ ---------------------------------------------------------------*/
/** /**
* @brief LCD color range * @brief Color range
* @note The difference between a full range color and a limited range color is * @note The difference between a full range color and a limited range color is
* the amount of shades of black and white that they can display. * the amount of shades of black and white that they can display.
*/ */

View File

@@ -89,15 +89,6 @@ INPUT = \
$(PROJECT_PATH)/components/driver/i2s/include/driver/i2s_tdm.h \ $(PROJECT_PATH)/components/driver/i2s/include/driver/i2s_tdm.h \
$(PROJECT_PATH)/components/driver/i2s/include/driver/i2s_types.h \ $(PROJECT_PATH)/components/driver/i2s/include/driver/i2s_types.h \
$(PROJECT_PATH)/components/driver/ledc/include/driver/ledc.h \ $(PROJECT_PATH)/components/driver/ledc/include/driver/ledc.h \
$(PROJECT_PATH)/components/driver/mcpwm/include/driver/mcpwm_cap.h \
$(PROJECT_PATH)/components/driver/mcpwm/include/driver/mcpwm_cmpr.h \
$(PROJECT_PATH)/components/driver/mcpwm/include/driver/mcpwm_etm.h \
$(PROJECT_PATH)/components/driver/mcpwm/include/driver/mcpwm_fault.h \
$(PROJECT_PATH)/components/driver/mcpwm/include/driver/mcpwm_gen.h \
$(PROJECT_PATH)/components/driver/mcpwm/include/driver/mcpwm_oper.h \
$(PROJECT_PATH)/components/driver/mcpwm/include/driver/mcpwm_sync.h \
$(PROJECT_PATH)/components/driver/mcpwm/include/driver/mcpwm_timer.h \
$(PROJECT_PATH)/components/driver/mcpwm/include/driver/mcpwm_types.h \
$(PROJECT_PATH)/components/driver/parlio/include/driver/parlio_tx.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/parlio/include/driver/parlio_types.h \
$(PROJECT_PATH)/components/driver/rmt/include/driver/rmt_common.h \ $(PROJECT_PATH)/components/driver/rmt/include/driver/rmt_common.h \
@@ -142,6 +133,15 @@ INPUT = \
$(PROJECT_PATH)/components/esp_driver_gptimer/include/driver/gptimer.h \ $(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_etm.h \
$(PROJECT_PATH)/components/esp_driver_gptimer/include/driver/gptimer_types.h \ $(PROJECT_PATH)/components/esp_driver_gptimer/include/driver/gptimer_types.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 \
$(PROJECT_PATH)/components/esp_driver_mcpwm/include/driver/mcpwm_fault.h \
$(PROJECT_PATH)/components/esp_driver_mcpwm/include/driver/mcpwm_gen.h \
$(PROJECT_PATH)/components/esp_driver_mcpwm/include/driver/mcpwm_oper.h \
$(PROJECT_PATH)/components/esp_driver_mcpwm/include/driver/mcpwm_sync.h \
$(PROJECT_PATH)/components/esp_driver_mcpwm/include/driver/mcpwm_timer.h \
$(PROJECT_PATH)/components/esp_driver_mcpwm/include/driver/mcpwm_types.h \
$(PROJECT_PATH)/components/esp_driver_pcnt/include/driver/pulse_cnt.h \ $(PROJECT_PATH)/components/esp_driver_pcnt/include/driver/pulse_cnt.h \
$(PROJECT_PATH)/components/esp_eth/include/esp_eth_com.h \ $(PROJECT_PATH)/components/esp_eth/include/esp_eth_com.h \
$(PROJECT_PATH)/components/esp_eth/include/esp_eth_driver.h \ $(PROJECT_PATH)/components/esp_eth/include/esp_eth_driver.h \

View File

@@ -1044,7 +1044,7 @@ API Reference
.. include-build-file:: inc/mcpwm_sync.inc .. include-build-file:: inc/mcpwm_sync.inc
.. include-build-file:: inc/mcpwm_cap.inc .. include-build-file:: inc/mcpwm_cap.inc
.. include-build-file:: inc/mcpwm_etm.inc .. include-build-file:: inc/mcpwm_etm.inc
.. include-build-file:: inc/components/driver/mcpwm/include/driver/mcpwm_types.inc .. include-build-file:: inc/components/esp_driver_mcpwm/include/driver/mcpwm_types.inc
.. include-build-file:: inc/components/hal/include/hal/mcpwm_types.inc .. include-build-file:: inc/components/hal/include/hal/mcpwm_types.inc

View File

@@ -9,6 +9,7 @@ In order to control the dependence of other components on drivers at a smaller g
- `esp_driver_pcnt` - Driver for pulse counter - `esp_driver_pcnt` - Driver for pulse counter
- `esp_driver_gpio` - Driver for GPIO - `esp_driver_gpio` - Driver for GPIO
- `esp_driver_spi` - Driver for GPSPI - `esp_driver_spi` - Driver for GPSPI
- `esp_driver_mcpwm` - Driver for Motor Control PWM
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. 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.

View File

@@ -1044,7 +1044,7 @@ API Reference
.. include-build-file:: inc/mcpwm_sync.inc .. include-build-file:: inc/mcpwm_sync.inc
.. include-build-file:: inc/mcpwm_cap.inc .. include-build-file:: inc/mcpwm_cap.inc
.. include-build-file:: inc/mcpwm_etm.inc .. include-build-file:: inc/mcpwm_etm.inc
.. include-build-file:: inc/components/driver/mcpwm/include/driver/mcpwm_types.inc .. include-build-file:: inc/components/esp_driver_mcpwm/include/driver/mcpwm_types.inc
.. include-build-file:: inc/components/hal/include/hal/mcpwm_types.inc .. include-build-file:: inc/components/hal/include/hal/mcpwm_types.inc

View File

@@ -9,6 +9,7 @@
- `esp_driver_pcnt` - 脉冲计数器驱动 - `esp_driver_pcnt` - 脉冲计数器驱动
- `esp_driver_gpio` - GPIO 驱动 - `esp_driver_gpio` - GPIO 驱动
- `esp_driver_spi` - 通用 SPI 驱动 - `esp_driver_spi` - 通用 SPI 驱动
- `esp_driver_mcpwm` - 电机控制 PWM 驱动
为了兼容性,原来的 `driver` 组件仍然存在,并作为一个 “all-in-one" 的组件,将以上这些 `esp_driver_xyz` 组件注册成自己的公共依赖。换句话说,你无需修改既有项目的 CMake 文件,但是你现在多了一个途径去指定你项目依赖的具体的外设驱动。 为了兼容性,原来的 `driver` 组件仍然存在,并作为一个 “all-in-one" 的组件,将以上这些 `esp_driver_xyz` 组件注册成自己的公共依赖。换句话说,你无需修改既有项目的 CMake 文件,但是你现在多了一个途径去指定你项目依赖的具体的外设驱动。

View File

@@ -151,10 +151,14 @@ examples/peripherals/ledc/ledc_gamma_curve_fade:
examples/peripherals/mcpwm: examples/peripherals/mcpwm:
disable: disable:
- if: SOC_MCPWM_SUPPORTED != 1 - if: SOC_MCPWM_SUPPORTED != 1
depends_components:
- esp_driver_mcpwm
examples/peripherals/mcpwm/mcpwm_bdc_speed_control: examples/peripherals/mcpwm/mcpwm_bdc_speed_control:
disable: disable:
- if: SOC_MCPWM_SUPPORTED != 1 - if: SOC_MCPWM_SUPPORTED != 1
depends_components:
- esp_driver_mcpwm
disable_test: disable_test:
- if: IDF_TARGET != "esp32s3" - if: IDF_TARGET != "esp32s3"
temporary: true temporary: true
@@ -163,6 +167,8 @@ examples/peripherals/mcpwm/mcpwm_bdc_speed_control:
examples/peripherals/mcpwm/mcpwm_bldc_hall_control: examples/peripherals/mcpwm/mcpwm_bldc_hall_control:
disable: disable:
- if: SOC_MCPWM_SUPPORTED != 1 - if: SOC_MCPWM_SUPPORTED != 1
depends_components:
- esp_driver_mcpwm
disable_test: disable_test:
- if: IDF_TARGET != "esp32s3" - if: IDF_TARGET != "esp32s3"
temporary: true temporary: true
@@ -171,6 +177,8 @@ examples/peripherals/mcpwm/mcpwm_bldc_hall_control:
examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop: examples/peripherals/mcpwm/mcpwm_foc_svpwm_open_loop:
disable: disable:
- if: SOC_MCPWM_SUPPORTED != 1 - if: SOC_MCPWM_SUPPORTED != 1
depends_components:
- esp_driver_mcpwm
disable_test: disable_test:
- if: IDF_TARGET != "esp32s3" - if: IDF_TARGET != "esp32s3"
temporary: true temporary: true

View File

@@ -35,7 +35,7 @@ set(extra_components_which_shouldnt_be_included
cxx cxx
# [refactor-todo]: driver is a dependency of esp_pm, spi_flash, vfs, esp_wifi # [refactor-todo]: driver is a dependency of esp_pm, spi_flash, vfs, esp_wifi
# all of these should be removed from G1 except for spi_flash. # all of these should be removed from G1 except for spi_flash.
driver esp_driver_gpio esp_driver_pcnt esp_driver_gptimer esp_driver_spi driver esp_driver_gpio esp_driver_pcnt esp_driver_gptimer esp_driver_spi esp_driver_mcpwm
# esp_app_format is dependency of bootloader_support, app_update # esp_app_format is dependency of bootloader_support, app_update
esp_app_format esp_app_format
# esp_bootloader_format is dependency of bootloader_support, app_update # esp_bootloader_format is dependency of bootloader_support, app_update