Skip to content

Commit c23e26d

Browse files
authored
Merge pull request #8 from iCMDdev/RPi-4B-BCM2711
Fix styling
2 parents b1c238c + 3e623d8 commit c23e26d

File tree

7 files changed

+128
-134
lines changed

7 files changed

+128
-134
lines changed

.github/workflows/build-rpi-baremetal.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
uses: actions/checkout@v4
2424

2525
- name: Install apt dependencies
26-
run: apt-get -qq update && apt-get -qq -y install llvm make
27-
26+
run: apt-get -qq update && apt-get -qq -y install make llvm
27+
2828
- name: Build ${{ matrix.example }}
2929
run: |
3030
cd ${{ matrix.example }}

pico-w-blink-sdk/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ This example demonstrates how to integrate with the Pico SDK which is using CMak
66

77
## Requirements
88

9-
- A Raspberry Pi Pico W / Pico 2 W board. If you have a Pico (non-W) instead, refer to the [pico-blink-sdk](../pico-blink-sdk) sample instead.
9+
- A Raspberry Pi Pico W board. If you have a Pico (non-W) instead, refer to the [pico-blink-sdk](../pico-blink-sdk) sample instead.
1010
- Follow the setup steps at https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf, in particular you'll need:
11-
- A checkout of the [pico-sdk](https://github.com/raspberrypi/pico-sdk.git), with git submodules checked out. If you'd like to try RISC-V support for RP2350, you'll need Pico SDK 2.1.0 or later.
11+
- A checkout of the [pico-sdk](https://github.com/raspberrypi/pico-sdk.git), with git submodules checked out.
1212
- A checkout of the [pico-examples](https://github.com/raspberrypi/pico-examples.git).
1313
- CMake.
14-
- The [Arm Embedded Toolchain](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads), or the RISC-V toolchain if you want to build for the RISC-V cores on the RP2350.
14+
- The [Arm Embedded Toolchain](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads).
1515
- Before trying to use Swift with the Pico SDK, make sure your environment works and can build the provided C/C++ sample projects, in particular:
1616
- Try building and running the "blink" example from pico-examples written in C.
1717

@@ -23,9 +23,9 @@ This example demonstrates how to integrate with the Pico SDK which is using CMak
2323
``` console
2424
$ cd pico-w-blink-sdk
2525
$ export TOOLCHAINS='<toolchain-identifier>'
26-
$ export PICO_BOARD='<board-name>' # pico_w or pico2_w
26+
$ export PICO_BOARD=pico_w
2727
$ export PICO_SDK_PATH='<path-to-your-pico-sdk>'
28-
$ export PICO_TOOLCHAIN_PATH='<path-to-the-compiler-toolchain>' # ARM / RISC-V toolchain
28+
$ export PICO_TOOLCHAIN_PATH='<path-to-the-arm-toolchain>'
2929
$ cmake -B build -G Ninja .
3030
$ cmake --build build
3131
```

pico2-neopixel/Sources/Application/Application.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func configureOutputPin() {
4848
/// `clkdiv_restart` to clear any persisted state.
4949
func configurePio() {
5050
// Load the assembled program directly into the PIO's instruction memory.
51-
withUnsafeBytes(of: WS2812.pio_instructions) { pointer in
51+
withUnsafeBytes(of: WS2812.pioInstructions) { pointer in
5252
let pioInstructions = pointer.assumingMemoryBound(to: UInt16.self)
5353
for (index, pio_instr) in pioInstructions.enumerated() {
5454
pio0.instr_mem[index].write { w in

rpi4b-blink/Package.swift

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@
44
import PackageDescription
55

66
let package = Package(
7-
name: "RPi4B-Blink",
8-
platforms: [
9-
.macOS(.v14),
7+
name: "RPi4B-Blink",
8+
platforms: [
9+
.macOS(.v14)
1010
],
11-
products: [
12-
.library(
13-
name: "MainApp",
14-
type: .static,
15-
targets: ["MainApp"]),
16-
],
17-
dependencies: [
18-
.package(
19-
url: "https://github.com/apple/swift-mmio.git",
20-
branch: "swift-embedded-examples"),
21-
],
22-
targets: [
23-
.target(
24-
name: "MainApp",
25-
dependencies: [
26-
.product(name: "MMIO", package: "swift-mmio")
27-
],
28-
swiftSettings: [
29-
.enableExperimentalFeature("Embedded"),
30-
.unsafeFlags(["-Xfrontend", "-function-sections"])
31-
]
32-
),
33-
.target(name: "Support")
34-
35-
]
11+
products: [
12+
.library(
13+
name: "MainApp",
14+
type: .static,
15+
targets: ["MainApp"])
16+
],
17+
dependencies: [
18+
.package(
19+
url: "https://github.com/apple/swift-mmio.git",
20+
branch: "swift-embedded-examples")
21+
],
22+
targets: [
23+
.target(
24+
name: "MainApp",
25+
dependencies: [
26+
.product(name: "MMIO", package: "swift-mmio")
27+
],
28+
swiftSettings: [
29+
.enableExperimentalFeature("Embedded"),
30+
.unsafeFlags(["-Xfrontend", "-function-sections"]),
31+
]
32+
),
33+
.target(name: "Support"),
34+
35+
]
3636
)

rpi4b-blink/Sources/MainApp/MainApp.swift

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,73 +13,70 @@ import MMIO
1313

1414
@Register(bitWidth: 32)
1515
struct GPSET1 {
16-
@ReadWrite(bits: 10..<11, as: Bool.self)
17-
var set: SET
16+
@ReadWrite(bits: 10..<11, as: Bool.self)
17+
var set: SET
1818
}
1919

2020
@Register(bitWidth: 32)
2121
struct GPCLR1 {
22-
@ReadWrite(bits: 10..<11, as: Bool.self)
23-
var clear: CLEAR
22+
@ReadWrite(bits: 10..<11, as: Bool.self)
23+
var clear: CLEAR
2424
}
2525

2626
@Register(bitWidth: 32)
2727
struct GPFSEL4 {
28-
@ReadWrite(bits: 6..<7, as: Bool.self)
29-
var fsel42b1: FSEL42b1
30-
@ReadWrite(bits: 7..<8, as: Bool.self)
31-
var fsel42b2: FSEL42b2
32-
@ReadWrite(bits: 8..<9, as: Bool.self)
33-
var fsel42b3: FSEL42b3
28+
@ReadWrite(bits: 6..<7, as: Bool.self)
29+
var fsel42b1: FSEL42b1
30+
@ReadWrite(bits: 7..<8, as: Bool.self)
31+
var fsel42b2: FSEL42b2
32+
@ReadWrite(bits: 8..<9, as: Bool.self)
33+
var fsel42b3: FSEL42b3
3434
}
3535

3636
@RegisterBlock
3737
struct GPIO {
38-
@RegisterBlock(offset: 0x200020)
39-
var gpset1: Register<GPSET1>
40-
@RegisterBlock(offset: 0x20002c)
41-
var gpclr1: Register<GPCLR1>
42-
@RegisterBlock(offset: 0x200010)
43-
var gpfsel4: Register<GPFSEL4>
38+
@RegisterBlock(offset: 0x200020)
39+
var gpset1: Register<GPSET1>
40+
@RegisterBlock(offset: 0x20002c)
41+
var gpclr1: Register<GPCLR1>
42+
@RegisterBlock(offset: 0x200010)
43+
var gpfsel4: Register<GPFSEL4>
4444
}
4545

46-
47-
let gpio = GPIO(unsafeAddress: 0xFE000000)
48-
46+
let gpio = GPIO(unsafeAddress: 0xFE00_0000)
4947

5048
func setLedOutput() {
51-
gpio.gpfsel4.modify {
52-
// setFunction Select 42 (fsel42) to 001
53-
$0.fsel42b1 = true
54-
$0.fsel42b2 = false
55-
$0.fsel42b3 = false
56-
}
49+
gpio.gpfsel4.modify {
50+
// setFunction Select 42 (fsel42) to 001
51+
$0.fsel42b1 = true
52+
$0.fsel42b2 = false
53+
$0.fsel42b3 = false
54+
}
5755
}
5856

5957
func ledOn() {
60-
gpio.gpset1.modify {
61-
$0.set = true
62-
}
58+
gpio.gpset1.modify {
59+
$0.set = true
60+
}
6361
}
6462

6563
func ledOff() {
66-
gpio.gpclr1.modify {
67-
$0.clear = true
68-
}
64+
gpio.gpclr1.modify {
65+
$0.clear = true
66+
}
6967
}
7068

71-
7269
@main
7370
struct Main {
7471

75-
static func main() {
76-
setLedOutput()
72+
static func main() {
73+
setLedOutput()
7774

78-
while true {
79-
ledOn()
80-
for _ in 1..<100000 { } // just a delay
81-
ledOff()
82-
for _ in 1..<100000 { } // just a delay
83-
}
75+
while true {
76+
ledOn()
77+
for _ in 1..<100000 {} // just a delay
78+
ledOff()
79+
for _ in 1..<100000 {} // just a delay
8480
}
81+
}
8582
}

rpi5-blink/Package.swift

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@
44
import PackageDescription
55

66
let package = Package(
7-
name: "RPi5-Blink",
8-
platforms: [
9-
.macOS(.v14),
7+
name: "RPi5-Blink",
8+
platforms: [
9+
.macOS(.v14)
1010
],
11-
products: [
12-
.library(
13-
name: "MainApp",
14-
type: .static,
15-
targets: ["MainApp"]),
16-
],
17-
dependencies: [
18-
.package(
19-
url: "https://github.com/apple/swift-mmio.git",
20-
branch: "swift-embedded-examples"),
21-
],
22-
targets: [
23-
.target(
24-
name: "MainApp",
25-
dependencies: [
26-
.product(name: "MMIO", package: "swift-mmio")
27-
],
28-
swiftSettings: [
29-
.enableExperimentalFeature("Embedded"),
30-
.unsafeFlags(["-Xfrontend", "-function-sections"])
31-
]
32-
),
33-
.target(name: "Support")
34-
35-
]
11+
products: [
12+
.library(
13+
name: "MainApp",
14+
type: .static,
15+
targets: ["MainApp"])
16+
],
17+
dependencies: [
18+
.package(
19+
url: "https://github.com/apple/swift-mmio.git",
20+
branch: "swift-embedded-examples")
21+
],
22+
targets: [
23+
.target(
24+
name: "MainApp",
25+
dependencies: [
26+
.product(name: "MMIO", package: "swift-mmio")
27+
],
28+
swiftSettings: [
29+
.enableExperimentalFeature("Embedded"),
30+
.unsafeFlags(["-Xfrontend", "-function-sections"]),
31+
]
32+
),
33+
.target(name: "Support"),
34+
35+
]
3636
)

rpi5-blink/Sources/MainApp/MainApp.swift

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,55 @@ import MMIO
22

33
@Register(bitWidth: 32)
44
struct GIOIODIR {
5-
@ReadWrite(bits: 9..<10, as: Bool.self)
6-
var direction: DIRECTION
5+
@ReadWrite(bits: 9..<10, as: Bool.self)
6+
var direction: DIRECTION
77
}
88

99
@Register(bitWidth: 32)
1010
struct GIODATA {
11-
@ReadWrite(bits: 9..<10, as: Bool.self)
12-
var value: VALUE
11+
@ReadWrite(bits: 9..<10, as: Bool.self)
12+
var value: VALUE
1313
}
1414

1515
@RegisterBlock
1616
struct GPIO {
17-
@RegisterBlock(offset: 0x00008)
18-
var gioiodir: Register<GIOIODIR>
19-
@RegisterBlock(offset: 0x00004)
20-
var giodata: Register<GIODATA>
17+
@RegisterBlock(offset: 0x00008)
18+
var gioiodir: Register<GIOIODIR>
19+
@RegisterBlock(offset: 0x00004)
20+
var giodata: Register<GIODATA>
2121
}
2222

23-
24-
let gpio = GPIO(unsafeAddress: 0x107d517c00)
25-
23+
let gpio = GPIO(unsafeAddress: 0x10_7d51_7c00)
2624

2725
func setLedOutput() {
28-
gpio.gioiodir.modify {
29-
$0.direction = false // 0 is output, 1 is input
30-
}
26+
gpio.gioiodir.modify {
27+
$0.direction = false // 0 is output, 1 is input
28+
}
3129
}
3230

3331
func ledOn() {
34-
gpio.giodata.modify {
35-
$0.value = true // pin on
36-
}
32+
gpio.giodata.modify {
33+
$0.value = true // pin on
34+
}
3735
}
3836

3937
func ledOff() {
40-
gpio.giodata.modify {
41-
$0.value = false // pin off
42-
}
38+
gpio.giodata.modify {
39+
$0.value = false // pin off
40+
}
4341
}
4442

45-
4643
@main
4744
struct Main {
4845

49-
static func main() {
50-
setLedOutput()
46+
static func main() {
47+
setLedOutput()
5148

52-
while true {
53-
ledOn()
54-
for _ in 1..<100000 { } // just a delay
55-
ledOff()
56-
for _ in 1..<100000 { } // just a delay
57-
}
49+
while true {
50+
ledOn()
51+
for _ in 1..<100000 {} // just a delay
52+
ledOff()
53+
for _ in 1..<100000 {} // just a delay
5854
}
59-
}
55+
}
56+
}

0 commit comments

Comments
 (0)