Skip to content

Add compressed JSON format for dac_controlset#498

Open
Schlepptop wants to merge 2 commits intosle118:master-v4.3from
Schlepptop:space-efficient-dac-controlset
Open

Add compressed JSON format for dac_controlset#498
Schlepptop wants to merge 2 commits intosle118:master-v4.3from
Schlepptop:space-efficient-dac-controlset

Conversation

@Schlepptop
Copy link
Copy Markdown

The current format for the dac_controlset JSON is very space-inefficient. NVS allows for 4000 characters, which is not a lot by itself. Setting a register with {"reg":25,"val": 5}, which is even worsened by the escapes needed to store it (NVS writes {\"reg\":25,\"val\":5}) doesn't help, so I propose supporting this alternative format that uses a single flat array instead.

  • Register write:
    [reg, val]
    Writes a single byte value to a register.

  • Burst write:
    [reg, [val1, val2, ..., valN]]
    Writes multiple bytes to a register in one burst. The second item must be a JSON array.

  • Delay:
    ["d", duration_ms]
    Pauses execution for the specified number of milliseconds.

  • Bitwise operations:
    ["&", reg, val] — Read-modify-write: AND value into register
    ["|", reg, val] — Read-modify-write: OR value into register

Notes:

  • All entries are parsed in order from the start of the array.
  • Invalid formatting or unexpected types will cause the function to return false.
  • Only numeric register addresses and values are allowed.

Example input:

     [
        0, 128,
        "d", 50,
        "|", 2, 240,
        "&", 2, 15,
        "g", 22, 0,
        25, [4, 5, 6, 7],
        1, 0
      ]

This will:

  • Write 128 to reg 0
  • Delay 50ms
  • OR 240 into reg 2
  • AND 15 into reg 2
  • Set GPIO 22 to level 0
  • Burst write [4,5,6,7] to reg 25
  • Write 0 to reg 1

This is obviously not as simple to write by hand, but easy enough to generate from header files that are supplied by manufacturers.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @Schlepptop, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly optimizes the storage and parsing of DAC control sequences by introducing a new, highly compressed JSON array format. This change allows for more complex and longer control sequences to be stored within the limited memory constraints of embedded systems, while maintaining compatibility with the existing object-based JSON format. The core functionality now intelligently dispatches to the appropriate parser based on the structure of the provided control set.

Highlights

  • New Compressed JSON Format: Introduced a space-efficient, flattened array JSON format for DAC control sequences. This new format supports direct register writes ([reg, val]), burst writes ([reg, [val1, ..., valN]]), delays (["d", duration_ms]), and bitwise AND/OR operations (["&", reg, val] or ["|", reg, val]).
  • Dual Format Support: The i2c_json_execute function has been enhanced to intelligently detect and process either the existing object-based JSON control sets or the newly introduced compressed array format, ensuring backward compatibility while enabling the new efficiency.
  • Memory Optimization: The primary motivation for this change is to significantly reduce the memory footprint of DAC control sets, which are often stored in Non-Volatile Storage (NVS) with limited capacity. The compressed format addresses the space inefficiency of the previous verbose JSON structure.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist
Copy link
Copy Markdown

Warning

Gemini is unable to generate a review due to a potential policy violation.

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.

1 participant