#![no_std] #![no_main] use grand_central_m4 as bsp; use bsp::hal; use bsp::pac; #[cfg(not(feature = "use_semihosting"))] use panic_halt as _; #[cfg(feature = "use_semihosting")] use panic_semihosting as _; use bsp::entry; use hal::clock::GenericClockController; use hal::delay::Delay; use hal::ehal::delay::DelayNs; use hal::time::Hertz; use hal::timer::TimerCounter; use hal::timer_traits::InterruptDrivenTimer; use pac::{CorePeripherals, Peripherals}; use smart_leds::{ hsv::{hsv2rgb, Hsv}, SmartLedsWrite, }; use ws2812_timer_delay as ws2812; #[entry] fn main() -> ! { let mut peripherals = Peripherals::take().unwrap(); let core = CorePeripherals::take().unwrap(); let mut clocks = GenericClockController::with_external_32kosc( peripherals.gclk, &mut peripherals.mclk, &mut peripherals.osc32kctrl, &mut peripherals.oscctrl, &mut peripherals.nvmctrl, ); let gclk0 = clocks.gclk0(); let tc2_3 = clocks.tc2_tc3(&gclk0).unwrap(); let mut timer = TimerCounter::tc3_(&tc2_3, peripherals.tc3, &mut peripherals.mclk); timer.start(Hertz::MHz(3).into_duration()); let pins = bsp::Pins::new(peripherals.port); let neopixel_pin = pins.neopixel.into_push_pull_output(); let mut neopixel = ws2812::Ws2812::new(timer, neopixel_pin); let mut delay = Delay::new(core.SYST, &mut clocks); 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(5); } } }