Skip to content

apple/swift-mmio

Swift MMIO

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

Overview

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

Example Usage

@RegisterBlock
struct Control {
  @RegisterBlock(offset: 0x0)
  var cr1: Register<CR1>
  @RegisterBlock(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", from: "0.1.1"),

Second, add the MMIO library to your target's dependencies:

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

Finally, import MMIO in your Swift source code.

Source Stability

Swift MMIO follows semantic versioning. While the package is in major version 0 (e.g., 0.0.x), source stability is only guaranteed within minor versions. For example, code written for 0.0.2 is compatible with 0.0.3, but 0.1.0 might introduce source-breaking changes.

To protect your project against potentially source-breaking updates during the 0.x.y development phase, specify your package dependency using the .upToNextMinor(from:) requirement:

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

This ensures that swift package update fetches compatible updates within the 0.0.x series (e.g., 0.0.3, 0.0.4) but does not automatically update to 0.1.0 if it becomes available.

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.