#![no_std] #![no_main] use bsp::hal; use pyportal as bsp; #[cfg(not(feature = "use_semihosting"))] use panic_halt as _; #[cfg(feature = "use_semihosting")] use panic_semihosting as _; use ws2812_timer_delay as ws2812; use bsp::entry; use hal::pac::{CorePeripherals, Peripherals}; use hal::prelude::*; use hal::timer::TimerCounter; use hal::{clock::GenericClockController, delay::Delay}; use smart_leds::{ hsv::{hsv2rgb, Hsv}, SmartLedsWrite, }; #[entry] fn main() -> ! { let mut peripherals = Peripherals::take().unwrap(); let core = CorePeripherals::take().unwrap(); let mut clocks = GenericClockController::with_internal_32kosc( peripherals.GCLK, &mut peripherals.MCLK, &mut peripherals.OSC32KCTRL, &mut peripherals.OSCCTRL, &mut peripherals.NVMCTRL, ); let pins = bsp::Pins::new(peripherals.PORT); let mut delay = Delay::new(core.SYST, &mut clocks); let gclk0 = clocks.gclk0(); let timer_clock = clocks.tc2_tc3(&gclk0).unwrap(); let mut timer = TimerCounter::tc3_(&timer_clock, peripherals.TC3, &mut peripherals.MCLK); timer.start(4.mhz()); let neopixel_pin = pins.neopixel.into_push_pull_output(); let mut neopixel = ws2812::Ws2812::new(timer, neopixel_pin); loop { for j in 0..255u8 { let colors = [hsv2rgb(Hsv { hue: j, sat: 255, val: 32, })]; neopixel.write(colors.iter().cloned()).unwrap(); delay.delay_ms(5u8); } } }