xosc/
xosc.rs

1//! # XOSC (12MHz) Example
2//!
3//! This program sets up the external crystal oscillator (XOSC) at 12 MHz. It then verifies that
4//! the XOSC is enabled. While the XOSC is enabled, the LED on GPIO pin 25 blinks. If the XOSC is
5//! disabled for any reason, the program stops the blinking.
6
7#![no_std]
8#![no_main]
9
10extern crate pico_xs as hal;
11use hal::{gpio, registers, xs};
12
13#[no_mangle]
14pub extern "C" fn main() -> ! {
15    // Initialize the external crystal oscillator (XOSC)
16    registers::xosc::init();
17
18    // Reset IO_BANK0 (bit 5) for GPIO operations
19    registers::resets::reset_wait(1 << 5);
20
21    // Initialize GPIO pin 25 (LED)
22    let mut led_gpio = gpio::Gpio::new(25);
23
24    // Configure GPIO pin 25 as output for the LED
25    led_gpio.select_funcsel(5); // SIO funcsel
26    led_gpio.output_enable(true); // Enable output
27
28    // Blink the LED while XOSC is enabled
29    loop {
30        // Check if the XOSC is enabled
31        if !registers::xosc::is_enabled() {
32            // If XOSC is disabled, exit the loop and stop blinking
33            break;
34        }
35
36        // Toggle the LED: ON -> Sleep -> OFF -> Sleep
37        led_gpio.output_set(true); // Turn LED on
38        xs::sleep(); // Sleep
39        led_gpio.output_set(false); // Turn LED off
40        xs::sleep(); // Sleep
41    }
42
43    // End program - keep the system in a sleep loop
44    loop {
45        xs::sleep();
46    }
47}