This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Felix "xq" Queißner
committed
Sep 23, 2023
1 parent
11b5bef
commit 3879307
Showing
4 changed files
with
75 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Examples for the BSP `nxp-lpc` | ||
|
||
- [Blinky](src/blinky.zig) on [mbed LPC1768](https://os.mbed.com/platforms/mbed-LPC1768/) | ||
Performs a really basic round robin blinky on the four LEDs on the development board. Flash by copying `zig-out/firmware/mbed-lpc1768_blinky.hex` to the mass storage of the board, then press the big button in the center. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const std = @import("std"); | ||
const microzig = @import("microzig"); | ||
|
||
const chip = microzig.chip; | ||
|
||
// LED-1: P1.18 | ||
// LED-2: P1.20 | ||
// LED-3: P1.21 | ||
// LED-4: P1.23 | ||
|
||
const conn = chip.peripherals.PINCONNECT; | ||
const gpio: *volatile [5]PatchedGpio = @ptrCast(@alignCast(chip.peripherals.GPIO)); | ||
|
||
const led_mask = [4]u32{ | ||
(1 << 18), | ||
(1 << 20), | ||
(1 << 21), | ||
(1 << 23), | ||
}; | ||
const all_mask = led_mask[0] | led_mask[1] | led_mask[2] | led_mask[3]; | ||
|
||
pub fn main() !void { | ||
conn.PINSEL3.modify(.{ | ||
.P1_18 = .{ .value = .GPIO_P1 }, | ||
.P1_20 = .{ .value = .GPIO_P1 }, | ||
.P1_21 = .{ .value = .GPIO_P1 }, | ||
.P1_23 = .{ .value = .GPIO_P1 }, | ||
}); | ||
|
||
const p1 = &gpio[1]; | ||
|
||
p1.dir = all_mask; | ||
|
||
while (true) { | ||
for (led_mask) |mask| { | ||
p1.pin_clr = (all_mask & ~mask); | ||
p1.pin_set = mask; | ||
microzig.core.experimental.debug.busy_sleep(100_000); | ||
} | ||
} | ||
} | ||
|
||
const PatchedGpio = extern struct { | ||
dir: u32, // 0x2009 C000 | ||
__padding0: u32, // 0x2009 C004 | ||
__padding1: u32, // 0x2009 C008 | ||
__padding2: u32, // 0x2009 C00C | ||
mask: u32, // 0x2009 C010 | ||
pin: u32, // 0x2009 C014 | ||
pin_set: u32, // 0x2009 C018 | ||
pin_clr: u32, // 0x2009 C01C | ||
|
||
comptime { | ||
std.debug.assert(@sizeOf(PatchedGpio) == 0x20); | ||
} | ||
}; |