Skip to content

Commit 48c34ec

Browse files
committed
Update direct memory example to work with relay board.
1 parent 2a623ba commit 48c34ec

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

examples/directMemory.swift

+14-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,18 @@ func loopGPIO() {
2020
let basePointer: UnsafeMutablePointer<UInt32> = rawPointer.bindMemory(to: UInt32.self, capacity: 30)
2121

2222
// Configure GPIO pin 4 & 6 as output (3 bits/pin)
23-
// pin numbers: 6 5 4 3 2 1 0
24-
basePointer.pointee = 0b001001000000000000000
23+
// pin numbers: 8 7 6 5 4 3 2 1 0
24+
// basePointer.pointee = 0b000001001000000000000000
25+
26+
27+
guard let rawPointer2 = mmap(nil, 1024 * 4, PROT_READ | PROT_WRITE, MAP_SHARED, file, 0x3f200000) else {
28+
perror("Cannot mmap bytes for path")
29+
return
30+
}
31+
// let basePointer2: UnsafeMutabl ePointer<UInt32> = rawPointer2.bindMemory(to: UInt32.self, capacity: 30)
32+
33+
// pin numbers: 22 21 20 19 18 17 16 15 14 13 12 11 // 10 9 8 7 6 5 4 3 2 1 0
34+
// basePointer2.pointee = 0b00001000000000000000000000000000 //000000000000001001000000000000000
2535

2636
// Set up set/clear pointer objects
2737
// Offsets from docs were given in byte-size values
@@ -41,11 +51,11 @@ func loopGPIO() {
4151
// Loop through and show the LED turning on and off
4252
for i in 0...5 {
4353
print("High \(setPointer)")
44-
setPointer.pointee = 0b1100000 // Pin 6 & 4
54+
setPointer.pointee = 0b100000100000000000001100000 // Pin 20, 6 & 5
4555
usleep(500000)
4656
print("Counter: \(i)")
4757
print("Low \(clearPointer)")
48-
clearPointer.pointee = 0b1100000 // Pin 6 & 4
58+
clearPointer.pointee = 0b100000100000000000001100000 // Pin 20, 6 & 5
4959
usleep(500000)
5060
}
5161
}

0 commit comments

Comments
 (0)