-
Notifications
You must be signed in to change notification settings - Fork 128
GPIO and UART basics for nRF52832 #558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mattnite
wants to merge
3
commits into
main
Choose a base branch
from
nrf-hal-init
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+512
−44
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,30 @@ | ||
const std = @import("std"); | ||
const microzig = @import("microzig"); | ||
const board = microzig.board; | ||
const nrf = microzig.hal; | ||
|
||
const uart = nrf.uart.num(0); | ||
|
||
pub fn main() !void { | ||
board.init(); | ||
|
||
uart.apply(.{ | ||
.tx_pin = board.uart_tx, | ||
.rx_pin = board.uart_rx, | ||
.control_flow = .{ | ||
.cts_pin = board.uart_cts, | ||
.rts_pin = board.uart_rts, | ||
}, | ||
.baud_rate = .@"115200", | ||
}); | ||
|
||
nrf.uart.init_logger(uart); | ||
std.log.info("Hello world, I will send back bytes you send me", .{}); | ||
|
||
// now echo any bytes sent | ||
var buf: [1]u8 = undefined; | ||
while (true) { | ||
uart.read_blocking(&buf); | ||
uart.write_blocking(buf[0..]); | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# Examples for the Port `nxp-lpc` | ||
|
||
- [Blinky](src/blinky.zig) on [nRF52840 Dongle](https://www.nordicsemi.com/Products/Development-hardware/nrf52840-dongle) | ||
TODO: Implement this! | ||
|
||
- [Blinky](src/blinky.zig) on [mbed LPD1768](https://os.mbed.com/platforms/mbed-LPC1768/) |
This file contains hidden or 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 hidden or 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 hidden or 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,39 @@ | ||
const Patch = @import("microzig/build-internals").Patch; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (so far) we could use the same patch file as 52840 |
||
|
||
pub const patches: []const Patch = &.{ | ||
.{ | ||
.add_enum = .{ | ||
.parent = "types.peripherals.P0", | ||
.@"enum" = .{ | ||
.name = "Pull", | ||
.bitsize = 2, | ||
.fields = &.{ | ||
.{ .value = 0x0, .name = "disabled" }, | ||
.{ .value = 0x1, .name = "down" }, | ||
.{ .value = 0x2, .name = "up" }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
.{ .set_enum_type = .{ .of = "types.peripherals.P0.PIN_CNF.PULL", .to = "types.peripherals.P0.Pull" } }, | ||
.{ | ||
.add_enum = .{ | ||
.parent = "types.peripherals.P0", | ||
.@"enum" = .{ | ||
.name = "DriveStrength", | ||
.bitsize = 3, | ||
.fields = &.{ | ||
.{ .value = 0x0, .name = "SOS1" }, | ||
.{ .value = 0x1, .name = "HOS1" }, | ||
.{ .value = 0x2, .name = "SOH1" }, | ||
.{ .value = 0x3, .name = "HOH1" }, | ||
.{ .value = 0x4, .name = "DOS1" }, | ||
.{ .value = 0x5, .name = "DOH1" }, | ||
.{ .value = 0x6, .name = "SOD1" }, | ||
.{ .value = 0x7, .name = "HOD1" }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
.{ .set_enum_type = .{ .of = "types.peripherals.P0.PIN_CNF.DRIVE", .to = "types.peripherals.P0.DriveStrength" } }, | ||
}; |
This file contains hidden or 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,39 @@ | ||
const microzig = @import("microzig"); | ||
const nrf = microzig.hal; | ||
const gpio = nrf.gpio; | ||
|
||
pub const led_active_state = 0; | ||
pub const button_active_state = 0; | ||
pub const button_pull = .pullup; | ||
|
||
pub const leds: []const gpio.Pin = &.{ led1, led2, led3, led4 }; | ||
pub const led1 = gpio.num(0, 17); | ||
pub const led2 = gpio.num(0, 18); | ||
pub const led3 = gpio.num(0, 19); | ||
pub const led4 = gpio.num(0, 20); | ||
|
||
pub const buttons: []const gpio.Pin = &.{ button1, button2, button3, button4 }; | ||
pub const button1 = gpio.num(0, 13); | ||
pub const button2 = gpio.num(0, 14); | ||
pub const button3 = gpio.num(0, 15); | ||
pub const button4 = gpio.num(0, 16); | ||
|
||
// UART | ||
pub const uart_rts = gpio.num(0, 5); | ||
pub const uart_tx = gpio.num(0, 6); | ||
pub const uart_cts = gpio.num(0, 7); | ||
pub const uart_rx = gpio.num(0, 8); | ||
pub const hwfc = true; | ||
|
||
pub fn init() void { | ||
for (leds) |led| | ||
led.set_direction(.out); | ||
|
||
for (buttons) |button| | ||
button.set_direction(.in); | ||
|
||
uart_rx.set_direction(.in); | ||
uart_cts.set_direction(.in); | ||
uart_rts.set_direction(.out); | ||
uart_tx.set_direction(.out); | ||
} |
This file contains hidden or 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 hidden or 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 @@ | ||
pub const Chip = enum { | ||
nrf52, | ||
nrf52840, | ||
}; |
This file contains hidden or 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,13 @@ | ||
const std = @import("std"); | ||
const microzig = @import("microzig"); | ||
const Chip = @import("chip.zig").Chip; | ||
|
||
pub const chip: Chip = blk: { | ||
if (std.mem.eql(u8, microzig.config.chip_name, "nrf52")) { | ||
break :blk .nrf52; | ||
} else if (std.mem.eql(u8, microzig.config.chip_name, "nrf52840")) { | ||
break :blk .nrf52840; | ||
} else { | ||
@compileError(std.fmt.comptimePrint("Unsupported chip for nRF52 HAL: \"{s}\"", .{microzig.config.chip_name})); | ||
} | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this name? Why not nRF52-DK?