Skip to content
New issue

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

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

Already on GitHub? # to your account

Add a way to express an indexable list of registers #30

Closed
phausler opened this issue Nov 8, 2023 · 2 comments
Closed

Add a way to express an indexable list of registers #30

phausler opened this issue Nov 8, 2023 · 2 comments
Milestone

Comments

@phausler
Copy link
Member

phausler commented Nov 8, 2023

It is often the case that interfacing with things like GPIO, spin locks, clocks etc have lists of registers that all share a given type.

Definitions often have a starting offset, stride between each indexable register, and a count of those registers.

This could be achieved without needing a macro to know what the type is by just allowing construction via an encapsulating type:

public struct RegisterList<Value> where Value: RegisterValue {
  let unsafeAddress: UInt
  let startOffset: UInt
  let stride: UInt
  let count: Int
  public init(unsafeAddress: UInt, startOffset: UInt, stride: UInt, count: Int) {
    self.unsafeAddress = unsafeAddress
    self.startOffset = startOffset
    self.stride = stride
    self.count = count
  }

  public subscript(index: Int) -> Register<Value> {
    precondition(index >= 0 && index < count)
    let addr = unsafeAddress + UInt(index) * stride + startOffset
    return Register(unsafeAddress: addr)
  }
}
@rauhul rauhul added the enhancement New feature or request label Nov 8, 2023
@rauhul
Copy link
Collaborator

rauhul commented Nov 10, 2023

This is absolutely something we should support; at the register bank level I think this should be as simple as making the following code compile:

@RegisterArray(offset:stride:count:)
var gpio: RegisterArray<GPIO>

@rauhul rauhul added this to the 0.0.2 milestone Nov 17, 2023
@rauhul
Copy link
Collaborator

rauhul commented Nov 17, 2023

WIP on register-array

@rauhul rauhul closed this as completed in 5c59b5e Jan 10, 2024
@rauhul rauhul removed the enhancement New feature or request label Mar 12, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants