-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: RecursiveError <[email protected]> Co-authored-by: Felix Queißner <[email protected]>
- Loading branch information
1 parent
03a313d
commit a7bf277
Showing
3 changed files
with
43 additions
and
1 deletion.
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,41 @@ | ||
const std = @import("std"); | ||
const microzig = @import("microzig"); | ||
|
||
const rp2040 = microzig.hal; | ||
const uart = rp2040.uart; | ||
const gpio = rp2040.gpio; | ||
const time = rp2040.time; | ||
const clocks = rp2040.clocks; | ||
|
||
const echo_uart = uart.instance.num(0); | ||
const baud_rate = 115200; | ||
const uart_tx_pin = gpio.num(0); | ||
const uart_rx_pin = gpio.num(1); | ||
|
||
pub fn main() !void { | ||
inline for (&.{ uart_tx_pin, uart_rx_pin }) |pin| { | ||
pin.set_function(.uart); | ||
} | ||
|
||
echo_uart.apply(.{ | ||
.baud_rate = baud_rate, | ||
.clock_config = rp2040.clock_config, | ||
//.parity = .none, | ||
//.stop_bits = .one, | ||
//.flow_control = .none | ||
}); | ||
|
||
var data: [1]u8 = .{0}; | ||
while (true) { | ||
//read one byte, timeout disabled | ||
echo_uart.read_blocking(&data, null) catch { | ||
echo_uart.clear_errors(); //You need to clear UART errors before making a new transaction | ||
continue; | ||
}; | ||
|
||
//tries to write one byte with 100ms timeout | ||
echo_uart.write_blocking(&data, time.Duration.from_ms(100)) catch { | ||
echo_uart.clear_errors(); | ||
}; | ||
} | ||
} |
File renamed without changes.