Skip to content

增加ppm RC驱动#200

Merged
Rbb666 merged 1 commit intoFirmament-Autopilot:staging/edge-e83from
PeterJhon:drv_rc
Mar 25, 2026
Merged

增加ppm RC驱动#200
Rbb666 merged 1 commit intoFirmament-Autopilot:staging/edge-e83from
PeterJhon:drv_rc

Conversation

@PeterJhon
Copy link
Copy Markdown
Collaborator

No description provided.

@PeterJhon PeterJhon force-pushed the drv_rc branch 2 times, most recently from 8ec3aa0 to 6dbaf61 Compare March 25, 2026 06:00
@Rbb666 Rbb666 requested a review from Copilot March 25, 2026 06:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a PPM-based RC input driver for the Infineon edge-e83 (M33) target, wiring up a TCPWM capture channel and integrating the RC HAL/driver into the target build and early board initialization.

Changes:

  • Enable BSP_USING_RC and include RC HAL sources in the M33 build.
  • Add drv_rc implementation using TCPWM capture ISR to feed the PPM decoder and register an rc device.
  • Update ModusToolbox-generated clock/routing/peripheral config to provide the RC capture timer, pin routing, and clock divider.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
target/infineon/edge-e83/m33/rtconfig.h Enables RC feature flag for this target.
target/infineon/edge-e83/m33/config/hal.py Adds RC HAL sources to the build glob list.
target/infineon/edge-e83/m33/board/board.c Calls drv_rc_init() during early init.
target/infineon/edge-e83/libs/TARGET_APP_KIT_PSE84_EVAL_EPC2/config/design.modus Adds a TCPWM counter instance and routing for RC capture + related clock divider.
target/infineon/edge-e83/libs/TARGET_APP_KIT_PSE84_EVAL_EPC2/config/GeneratedSource/cycfg_routing.h Generated trigger routing definitions for RC capture (and UART/DMA trigger changes).
target/infineon/edge-e83/libs/TARGET_APP_KIT_PSE84_EVAL_EPC2/config/GeneratedSource/cycfg_routing.c Generated trigger mux connections including RC capture and UART/DMA triggers.
target/infineon/edge-e83/libs/TARGET_APP_KIT_PSE84_EVAL_EPC2/config/GeneratedSource/cycfg_peripherals.h Adds RC_TIMER peripheral definitions and configurator exports.
target/infineon/edge-e83/libs/TARGET_APP_KIT_PSE84_EVAL_EPC2/config/GeneratedSource/cycfg_peripherals.c Adds RC_TIMER counter config and divider assignment.
target/infineon/edge-e83/libs/TARGET_APP_KIT_PSE84_EVAL_EPC2/config/GeneratedSource/cycfg_peripheral_clocks.h Adds the new peri_0_group_1_div_8_4 divider definitions.
target/infineon/edge-e83/libs/TARGET_APP_KIT_PSE84_EVAL_EPC2/config/GeneratedSource/cycfg_peripheral_clocks.c Initializes the new divider to achieve the target timer frequency.
target/infineon/edge-e83/libraries/mtb-device-support-pse8xxgp/pdl/SConscript Conditionally adds cy_tcpwm_counter.c when RC is enabled.
target/infineon/edge-e83/drivers/drv_rc.h New RC driver header exposing drv_rc_init().
target/infineon/edge-e83/drivers/drv_rc.c New RC driver using TCPWM capture ISR + PPM decoder, registers rc device.
target/infineon/edge-e83/drivers/SConscript Adds drv_rc.c to driver sources when RC is enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +60 to +64
static rt_err_t rc_init(rc_dev_t dev)
{
(void)dev;

RT_TRY(ppm_decoder_init(&ppm_decoder, TIMER_FREQ_HZ));
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This driver advertises SBUS support (includes sbus.h, defines an sbus_decoder, and hal_rc AUTO mode will probe SBUS first), but only initializes the PPM decoder and there’s no SBUS low-level init / UART ISR feeding sbus_input() + sbus_update(). As a result, selecting protocol = sbus via configuration will never produce updates. Either implement SBUS init+RX handling for this target, or remove the SBUS path and set the default protocol to PPM (and return an error for unsupported protocols).

Copilot uses AI. Check for mistakes.
#include "cycfg_peripherals.h"

#ifndef min // mod by prife
#define min(x, y) (x < y ? x : y)
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local min macro is unsafe as written: it lacks parentheses around parameters/whole expression and can evaluate arguments multiple times. Prefer a fully-parenthesized macro (or an inline function) to avoid precedence/side-effect issues.

Suggested change
#define min(x, y) (x < y ? x : y)
#define min(x, y) (((x) < (y)) ? (x) : (y))

Copilot uses AI. Check for mistakes.
Comment on lines +36 to +38
Cy_TrigMux_Connect(PERI_0_TRIG_IN_MUX_0_SCB_TX_TR_OUT2, PERI_0_TRIG_OUT_MUX_0_PDMA0_TR_IN1, false, TRIGGER_TYPE_LEVEL);
Cy_TrigMux_Connect(PERI_0_TRIG_IN_MUX_0_SCB_TX_TR_OUT5, PERI_0_TRIG_OUT_MUX_0_PDMA0_TR_IN2, false, TRIGGER_TYPE_LEVEL);
Cy_TrigMux_Connect(PERI_0_TRIG_IN_MUX_3_PERI1_HSIOM_TR_OUT1, PERI_0_TRIG_OUT_MUX_3_TCPWM0_ALL_CNT_TR_IN27, false, TRIGGER_TYPE_LEVEL);
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These trigger-mux connections change UART/DMA routing (e.g. SCB_TX_TR_OUT10 -> SCB_TX_TR_OUT2, plus new SCB5->PDMA connection) in addition to adding the RC capture route. Since the PR title/description is about adding a PPM RC driver, please confirm these UART/DMA routing changes are intentional; otherwise regenerate the config to include only the RC-related routing or split them into a separate PR.

Copilot uses AI. Check for mistakes.
Comment on lines +105 to +107
/* init RC */
RT_CHECK(drv_rc_init());

Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drv_rc_init() is called here, but drv_rc.h isn’t included in this file (unlike other board implementations). In C99+ this can fail to compile due to an implicit function declaration. Include drv_rc.h (or otherwise provide a prototype) before calling drv_rc_init().

Copilot uses AI. Check for mistakes.

rt_err_t drv_rc_init(void)
{
RT_TRY(hal_rc_register(&rc_dev, "rc", RT_DEVICE_FLAG_RDWR, NULL));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块需要添加返回值处理

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RT_TRY 有带检查了

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok看到了


if (int_source & CY_TCPWM_INT_ON_CC0) {
uint32_t capture = Cy_TCPWM_Counter_GetCapture0Val(RC_TIMER_HW, RC_TIMER_NUM) + 1;
// rt_kprintf("%d\n", capture);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除多余的注释


ppm_lock(&ppm_decoder);

for (uint8_t i = 0; i < min(rc->config.channel_num, ppm_decoder.total_chan); i++) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用c99语法吧,把变量定义放到外面

@Rbb666 Rbb666 merged commit 78c997e into Firmament-Autopilot:staging/edge-e83 Mar 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants