#![no_main] #![no_std] extern crate panic_rtt_target; use lpc8xx_hal::{ cortex_m_rt::entry, delay::Delay, prelude::*, CorePeripherals, Peripherals, }; #[entry] fn main() -> ! { rtt_target::rtt_init_print!(); // Get access to the device's peripherals. Since only one instance of this // struct can exist, the call to `take` returns an `Option`. // If we tried to call the method a second time, it would return `None`, but // we're only calling it the one time here, so we can safely `unwrap` the // `Option` without causing a panic. let cp = CorePeripherals::take().unwrap(); let p = Peripherals::take().unwrap(); // Initialize the APIs of the peripherals we need. let swm = p.SWM.split(); let mut delay = Delay::new(cp.SYST); let mut syscon = p.SYSCON.split(); let mut handle = swm.handle.enable(&mut syscon.handle); // Select pin for the RGB LED let green = p.pins.pio1_0.into_swm_pin(); let blue = p.pins.pio1_1.into_swm_pin(); let red = p.pins.pio1_2.into_swm_pin(); // Configure the LED pins. The API tracks the state of pins at compile time, // to prevent any mistakes. let (red, _) = swm.movable_functions.t0_mat0.assign(red, &mut handle); let (green, _) = swm.movable_functions.t0_mat1.assign(green, &mut handle); let (blue, _) = swm.movable_functions.t0_mat2.assign(blue, &mut handle); // Use 8 bit pwm let ctimer = p .CTIMER0 .enable(256, 0, &mut syscon.handle) .attach(red) .attach(green) .attach(blue); let mut red = ctimer.channels.channel1; let mut green = ctimer.channels.channel2; let mut blue = ctimer.channels.channel3; // Fade each color after another loop { for i in 0..red.get_max_duty() { delay.delay_ms(4_u8); red.set_duty(i); } for i in (0..red.get_max_duty()).rev() { delay.delay_ms(4_u8); red.set_duty(i); } for i in 0..green.get_max_duty() { delay.delay_ms(4_u8); green.set_duty(i); } for i in (0..green.get_max_duty()).rev() { delay.delay_ms(4_u8); green.set_duty(i); } for i in 0..blue.get_max_duty() { delay.delay_ms(4_u8); blue.set_duty(i); } for i in (0..blue.get_max_duty()).rev() { delay.delay_ms(4_u8); blue.set_duty(i); } } }