Skip to content

Commit 08e8f45

Browse files
committed
start clocks
1 parent 89f5552 commit 08e8f45

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

examples/nordic/nrf5x/src/blinky.zig

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const nrf = microzig.hal;
55
const time = nrf.time;
66

77
const rtc_overflow_interrupt = nrf.time.rtc_overflow_interrupt;
8+
const uart = nrf.uart.num(0);
89

910
pub const microzig_options = microzig.Options{
1011
.log_level = .debug,
@@ -15,20 +16,26 @@ pub const microzig_options = microzig.Options{
1516
pub fn main() !void {
1617
board.init();
1718

19+
uart.apply(.{
20+
.tx_pin = board.uart_tx,
21+
.rx_pin = board.uart_rx,
22+
});
23+
24+
nrf.uart.init_logger(uart);
25+
1826
while (true) {
1927
board.led1.toggle();
20-
// std.log.info("Now: {}", .{time.get_time_since_boot()});
21-
std.log.info("Counter: {}", .{microzig.chip.peripherals.RTC0.COUNTER});
22-
// time.sleep_ms(500);
28+
std.log.info("Now: {}", .{time.get_time_since_boot()});
29+
time.sleep_ms(500);
2330

2431
board.led1.toggle();
2532
board.led2.toggle();
26-
// std.log.info("Now: {}", .{time.get_time_since_boot()});
27-
// time.sleep_ms(500);
33+
std.log.info("Now: {}", .{time.get_time_since_boot()});
34+
time.sleep_ms(500);
2835

2936
board.led2.toggle();
3037
board.led3.toggle();
31-
// std.log.info("Now: {}", .{time.get_time_since_boot()});
32-
// time.sleep_ms(500);
38+
std.log.info("Now: {}", .{time.get_time_since_boot()});
39+
time.sleep_ms(500);
3340
}
3441
}

port/nordic/nrf5x/src/hal/time.zig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,19 @@ pub fn init() void {
3636
// 'period' on two different events:
3737
// First, when it hits the halfway point, and again on overflow.
3838

39+
// TODO: Put this in clocks hal
40+
// Set clock source
41+
microzig.chip.peripherals.CLOCK.LFCLKSRC.modify(.{ .SRC = .RC });
42+
// Start LFCLK
43+
microzig.chip.peripherals.CLOCK.TASKS_LFCLKSTART.write_raw(1);
44+
3945
// Enable interrupt firing on compare AND on overflow
4046
rtc.INTENSET.modify(.{
4147
.COMPARE3 = .Enabled,
4248
.OVRFLW = .Enabled,
4349
});
4450
// Set the comparator to trigger on overflow of bottom 23 bits
45-
rtc.CC[COMPARE_INDEX].write(.{ .COMPARE = 0x8000 });
46-
// rtc.CC[COMPARE_INDEX].write(.{ .COMPARE = 0x800000 });
51+
rtc.CC[COMPARE_INDEX].write(.{ .COMPARE = 0x800000 });
4752

4853
// Clear counter, then start timer
4954
switch (version) {

0 commit comments

Comments
 (0)