Skip to content
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

Convert SVDEnumerations into BitFieldProjections #119

Merged
merged 3 commits into from
Feb 5, 2025
Merged

Conversation

rauhul
Copy link
Collaborator

@rauhul rauhul commented Sep 10, 2024

Updates SVD2Swift to generate bit field projections if the underlying
SVDField contains an SVDEnumeration. Fully closed enumerations
(where the enumeration describes all possible bit patterns) are exported
as Swift enums, and structs otherwise.

Fields with these projected types can be accessed with safer API:

@Register(bitWidth: 32)
struct ExampleRegister {
  @ReadWrite(bits: 2..<7, as: ExampleEnumeratedValues.self)
  var exampleField: ExampleField
}

var exampleRegister = ExampleRegister(...)
exampleRegister.modify { rw in
  switch rw.exampleField {
  case .namedExample0:
    print("Named pattern")
  case ._0b00010:
    print("Anonymous pattern")
  case .exampleWithDontCare:
    print("Multi-pattern: e.g. 0bXXX00")
  default:
    print("Unknown pattern")
  }
}

@rauhul rauhul force-pushed the svd2swift-enum-value branch from 29dc996 to 7c6a1f2 Compare October 3, 2024 19:56
@rauhul rauhul marked this pull request as ready for review October 3, 2024 21:32
@rauhul rauhul force-pushed the svd2swift-enum-value branch from 7c6a1f2 to 9a68172 Compare October 3, 2024 21:32
@rauhul rauhul force-pushed the svd2swift-enum-value branch from 9a68172 to a93fd40 Compare February 4, 2025 14:53
@rauhul rauhul force-pushed the svd2swift-enum-value branch from a93fd40 to d9922b0 Compare February 4, 2025 18:14
@rauhul rauhul merged commit 0e949ae into main Feb 5, 2025
11 checks passed
@rauhul rauhul deleted the svd2swift-enum-value branch February 5, 2025 17:48
@rauhul rauhul changed the title EnumeratedValues into Projected Types Convert SVDEnumerations into BitFieldProjections Feb 5, 2025
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