Skip to content

feat: 添加JTAG 20P兼容模式 #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025

Conversation

HalfSweet
Copy link
Collaborator

@HalfSweet HalfSweet commented Apr 8, 2025

Summary by CodeRabbit

  • New Features

    • Added a configuration option for enhanced 20-pin interface compatibility.
  • Refactor

    • Streamlined settings management and initialization routines to improve reliability and maintainability.
  • Style

    • Updated code formatting for a more consistent and clear structure.

Copy link

coderabbitai bot commented Apr 8, 2025

Walkthrough

The pull request refactors JSON boolean retrieval by removing a lambda and replacing it with a generic get_json_value function. This change is extended by adding template specializations for multiple types in the settings files. In addition, a new boolean setting, jtag_20pin_compatible, is added to the settings structure and integrated into JSON parsing and stringification. Changes in the USB2UART code include formatting adjustments and modifying initialization logic: the previous uartx_preinit is replaced by a dedicated uartx_io_init function that configures UART pins conditionally based on the new setting.

Changes

Files Change Summary
projects/HSLink-Pro/src/HID_COMM/hid_comm.cpp Removed lambda get_value_bool and replaced its usage with the new get_json_value function; added assignment for HSLink_Setting.jtag_20pin_compatible; introduced function signature for get_json_value
projects/HSLink-Pro/src/USB2UART/usb2uart.c
projects/HSLink-Pro/src/USB2UART/usb2uart.h
Re-formatted function declarations (curly brace moved to new line); altered uartx_preinit to call uartx_io_init; added new initialization logic in uartx_io_init based on jtag_20pin_compatible setting; added prototype for uartx_io_init in the header file
projects/HSLink-Pro/src/setting.cpp
projects/HSLink-Pro/src/setting.h
Added template specializations for get_json_value for types (bool, int, unsigned int, double, const char*); updated store_settings, load_settings, and update_settings to streamline settings management, including calling uartx_io_init; added jtag_20pin_compatible member to HSLink_Setting_t and updated JSON handling accordingly

Sequence Diagram(s)

sequenceDiagram
    participant S as update_settings()
    participant U as uartx_io_init()
    participant C as UART_Config

    S->>U: Call uartx_io_init() after updating settings
    alt jtag_20pin_compatible == false
        U->>C: Configure pins for UART mode
    else jtag_20pin_compatible == true
        U->>C: Configure pins for GPIO mode with specific settings
    end
Loading

Possibly related PRs

  • Jtag single bit #48: Both PRs modify the HSLink_Setting structure and related JSON parsing logic to accommodate the jtag_20pin_compatible setting, ensuring consistency in handling JTAG compatibility.

Poem

I'm a rabbit with a code hop beat,
Leaping through functions so clean and neat,
JSON fields now sing with a brand new tune,
JTAG pins dance beneath the debugging moon,
With each nibble of code, my joy overflows,
Happy hops and bytes, that's how my code grows!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
projects/HSLink-Pro/src/setting.cpp (3)

90-94: Consider adding return type

The function declarations are missing return types. While C++ allows this, it's better to be explicit for readability and consistency with the rest of the codebase.

-static void store_settings();
-static void load_settings();
-static void update_settings();
+static void store_settings(void);
+static void load_settings(void);
+static void update_settings(void);

33-45: Initialize the new jtag_20pin_compatible field

The jtag_20pin_compatible field is not initialized in the HSLink_Setting struct. While default values are provided when reading from JSON, it's good practice to initialize all fields.

HSLink_Setting_t HSLink_Setting = {
        .boost = false,
        .swd_port_mode = PORT_MODE_SPI,
        .jtag_port_mode = PORT_MODE_SPI,
        .power = {
                .vref = 3.3,
                .power_on = false,
                .port_on = false,
        },
        .reset = 0,
        .led = false,
        .led_brightness = 0,
+       .jtag_20pin_compatible = false,
};

19-31: Initialize the new jtag_20pin_compatible field in default_setting

The jtag_20pin_compatible field is not initialized in the default_setting constant. While default values are provided when reading from JSON, it's good practice to initialize all fields.

const HSLink_Setting_t default_setting = {
        .boost = false,
        .swd_port_mode = PORT_MODE_SPI,
        .jtag_port_mode = PORT_MODE_SPI,
        .power = {
                .vref = 3.3,
                .power_on = true,
                .port_on = true,
        },
        .reset = 1 << RESET_NRST,
        .led = true,
        .led_brightness = 10,
+       .jtag_20pin_compatible = false,
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ca17af and 3adf5e0.

📒 Files selected for processing (5)
  • projects/HSLink-Pro/src/HID_COMM/hid_comm.cpp (3 hunks)
  • projects/HSLink-Pro/src/USB2UART/usb2uart.c (8 hunks)
  • projects/HSLink-Pro/src/USB2UART/usb2uart.h (1 hunks)
  • projects/HSLink-Pro/src/setting.cpp (6 hunks)
  • projects/HSLink-Pro/src/setting.h (2 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
projects/HSLink-Pro/src/setting.cpp (2)
projects/HSLink-Pro/src/USB2UART/usb2uart.h (1)
  • uartx_io_init (12-12)
projects/HSLink-Pro/src/USB2UART/usb2uart.c (1)
  • uartx_io_init (121-169)
projects/HSLink-Pro/src/USB2UART/usb2uart.c (4)
projects/HSLink-Pro/src/USB2UART/usb2uart.h (3)
  • usb2uart_handler (16-16)
  • uartx_io_init (12-12)
  • uartx_preinit (14-14)
projects/HSLink-Pro/common/hslinkpro/board.h (1)
  • CheckHardwareVersion (48-48)
projects/HSLink-Pro/common/hslinkpro/board.c (1)
  • CheckHardwareVersion (182-194)
dap_main.h (2)
  • chry_dap_usb2uart_uart_config_callback (135-135)
  • chry_dap_usb2uart_uart_send_bydma (137-137)
🔇 Additional comments (17)
projects/HSLink-Pro/src/USB2UART/usb2uart.h (1)

12-12: LGTM: Function declaration for UART I/O initialization

The function declaration for uartx_io_init() looks good, providing a dedicated method for UART pin configuration.

projects/HSLink-Pro/src/HID_COMM/hid_comm.cpp (3)

237-237: LGTM: Using the new template function

Good refactoring to use the generic get_json_value function instead of a lambda.


258-259: LGTM: Proper implementation of the new setting

Correctly implements the new jtag_20pin_compatible setting with a default value of false, which is a safe default for backward compatibility.


381-383: LGTM: Complete JSON response

Properly includes the new jtag_20pin_compatible setting in the JSON response.

projects/HSLink-Pro/src/setting.h (2)

40-40: LGTM: New setting field added

The jtag_20pin_compatible field is correctly added to the HSLink_Setting_t structure.


50-70: LGTM: Well-designed template specializations

Good implementation of template specializations for different data types. These functions handle the case where the key doesn't exist in the JSON by returning a default value.

projects/HSLink-Pro/src/setting.cpp (6)

15-15: LGTM: Added the necessary include

Correctly includes "usb2uart.h" to access the uartx_io_init function.


50-88: LGTM: Template specialization implementations

Good implementation of the template specializations to handle various data types for JSON value retrieval.


147-149: LGTM: JSON output updated

Correctly adds the jtag_20pin_compatible field to the JSON output.


169-169: LGTM: Using templated function

Good use of the generic get_json_value function.


189-189: LGTM: Setting the new field from JSON

Correctly sets the jtag_20pin_compatible field from the JSON input.


219-219: LGTM: UART initialization

Good addition of uartx_io_init() call to update UART pins when settings change.

projects/HSLink-Pro/src/USB2UART/usb2uart.c (5)

171-174: Good refactoring of initialization logic

The modified uartx_preinit function now delegates pin configuration to the dedicated uartx_io_init function, which improves code modularity and maintainability.


287-293: DTR control properly respects JTAG compatibility mode

The conditional check ensures that DTR signals are only modified when not in JTAG 20pin compatible mode, which correctly preserves the pin state for JTAG functionality when needed.


296-302: RTS control properly respects JTAG compatibility mode

The conditional check ensures that RTS signals are only modified when not in JTAG 20pin compatible mode, which correctly preserves the pin state for JTAG functionality when needed.


42-43: Consistent formatting changes across function definitions

The opening braces for multiple function definitions have been moved to a new line, maintaining consistent coding style throughout the file.

Also applies to: 65-66, 91-92, 184-185, 207-208, 221-222


121-169: ⚠️ Potential issue

Well-structured implementation of UART pin configuration logic

The new uartx_io_init function effectively implements the JTAG 20pin compatibility mode by conditionally configuring UART pins. When this mode is enabled, the UART pins are set to GPIO mode with appropriate default levels.

However, there's a syntax error on line 137:

-    HPM_IOC->PAD[PIN_UART_RX].FUNC_CTL = IOC_PAD_FUNC_CTL_ALT_SELECT_SET(0);;
+    HPM_IOC->PAD[PIN_UART_RX].FUNC_CTL = IOC_PAD_FUNC_CTL_ALT_SELECT_SET(0);

Likely an incorrect or invalid review comment.

@HalfSweet HalfSweet merged commit 8f6f35b into cherry-embedded:master Apr 8, 2025
3 checks passed
@kaidegit
Copy link
Collaborator

kaidegit commented Apr 9, 2025

在从db的setting json拿配置字段的时候最好也做一下判断?

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.

2 participants