swift-mmio

0.0.2

Define and operate on type safe MMIO
apple/swift-mmio

What's New

Swift MMIO 0.0.2

2024-02-08T00:16:46Z

Quality of life improvements

Additions

  • Adds a variant of the @RegisterBank macro with offset, stride, and count
    arguments. This allows you to declare a logical vector of registers with a
    user-defined stride between them, e.g.
    @RegisterBank(offset: 0x100, stride: 0x10, count: 0x8). #65
  • Adds a variant of Register.write taking a builder closure:
    write<T>(_: (inout Value.Write) -> (T)) -> T. This method allows you to form
    a write value without needing to create a named temporary value. #75
  • Adds conditional extension to RawRepresentable types conforming to
    FixedWidthInteger for easier adoption of BitFieldProjectable. Conforming
    types only need to provide an implementation for bitWidth. #81

Changes

  • Updates bit-field macros bits parameter to be generic over BinaryInteger
    RangeExpressions. You can now specify bit ranges using any Swift range
    syntax, e.g. 0..<1, 0...1, 0..., ...1, or .... #43
  • Updates the MMIOVolatile bridge to eliminate the dependency on stdint.h,
    allowing you to build needing a copy of libc headers. #52
  • Removes restrictions on computed properties for @RegisterBank and
    @Register macros. #59
  • Updates error messages for members missing a macro annotation to include
    fix-its. #64

Fixes

  • Replaces the use of hasFeature(Embedded) with $Embedded for proper
    compilation condition checking. #60
  • Corrects the generation of placeholder attributes for Macros with multiple
    arguments, ensuring proper commas between the arguments. #63
  • Resolves build issues for 32-bit platforms, ensuring compatibility with
    watchOS. The use of 64-bit wide integers is now conditionally compiled based
    on target architecture. #79

The 0.0.2 release includes contributions from @rauhul and @SamHastings1066.
Thank you!

Swift MMIO

Swift MMIO is an open source package for defining and operating on memory mapped IO directly in Swift.

Sample Usage

Swift MMIO makes it easy to define registers directly in Swift source code and manipulate them in a safe and ergonomic manner.

@RegisterBank
struct Control {
  @RegisterBank(offset: 0x0)
  var cr1: Register<CR1>
  @RegisterBank(offset: 0x4)
  var cr2: Register<CR2>
}

@Register(bitWidth: 32)
struct CR1 {
  @ReadWrite(bits: 12..<13, as: Bool.self)
  var en: EN
}

let control = Control(unsafeAddress: 0x1000)
control.cr1.modify { $0.en = true }

Using Swift MMIO in your project

Swift MMIO supports use with the Swift Package Manager. First, add the Swift MMIO repository to your Package's dependencies:

.package(url: "https://github.com/apple/swift-mmio.git", from: "0.0.1"),

Important: This project follows semantic versioning. While still in major version 0, source-stability is only guaranteed within minor versions (e.g. between 0.0.3 and 0.0.4). If you want to guard against potentially source-breaking package updates, you can specify your package dependency using .upToNextMinor(from: "0.0.1") as the requirement.:

.package(url: "https://github.com/apple/swift-mmio.git", .upToNextMinor(from: "0.0.1")),

Second, add the MMIO library to your targets' dependencies:

.target(
  name: "DeviceRegisters",
  dependencies: [
    .product(name: "MMIO", package: "swift-mmio")
  ]),

Finally, import MMIO in your Swift source code.

Documentation

For guides, articles, and API documentation see the Package's documentation on the Web or in Xcode.

Contributing to Swift MMIO

Code of Conduct

Like all Swift.org projects, we would like the Swift MMIO project to foster a diverse and friendly community. We expect contributors to adhere to the Swift.org Code of Conduct. A copy of this document is available in this repository.

Contact information

The current code owner of this package is Rauhul Varma (@rauhul). You can contact him on the Swift forums.

In case of moderation issues, you can also directly contact a member of the Swift Core Team.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Sun May 05 2024 13:47:42 GMT-0900 (Hawaii-Aleutian Daylight Time)