rust-embedded / rust-embedded/svd2rust

feature: add bitfield operations for `enumeratedValues` generated types

Open
#823 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
857
Forks
164
PR merge metrics
No merged PRs in 30d

Description

This is a feature request and/or tracking issue for adding bitfield operations to enumeratedValues generated enum types.

I would like to open discussion about whether bitfield operations are desired for enumeratedValues generated types.

From those more experienced with embedded/SVD development, are enumeratedValues types meant to be explicitly "only these exact values are expected to be read/written"?

Or is it more like C enums where you can perform bitwise operations on the values?

For example, lets say a field has three variants, which may show up alone, or any combination of the three.

Currently there is no way to express the above semantics.

The example in code:

/// Represents a field with bit range [3:0]
pub enum SomeEnumValues {
    FieldValue0 = 0b0001,
    FieldValue1 = 0b0010,
    FieldValue2 = 0b0100,
}

So, the field should be able to express any combination of the FieldValue[0,2] variants, but never set the highest bit. Even though the bit range spans 4 bits.

I have run across a number of field definitions that resemble the above situtation.

Currently, it is obviously possible to just define the fields without an enumeratedValues definition, and document the semantics in the field description.

However, it would be nice to be able to define the semantics in the type system using something like types provided by the bitflags crate.

If this is something maintainers, and the wider community, would like implemented, I am happy to contribute code.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by resolving whether enumeratedValues represent exact values or composable bitfields, using the SomeEnumValues example and the linked bitflags crate as discussion context. The issue names no source files or tests; done would require an agreed representation and clearly defined generated behavior for valid combinations and reserved bits.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
embedded-iot
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.