#![no_main] #![no_std] #[allow(unused)] use panic_halt; use nucleo_f103rb as board; use board::hal::{prelude::*, spi::*, stm32}; use cortex_m_rt::entry; #[entry] fn main() -> ! { pub const MODE: Mode = Mode { polarity: Polarity::IdleHigh, phase: Phase::CaptureOnSecondTransition, }; if let Some(p) = stm32::Peripherals::take() { let mut flash = p.FLASH.constrain(); let mut rcc = p.RCC.constrain(); let clocks = rcc.cfgr.freeze(&mut flash.acr); let mut afio = p.AFIO.constrain(&mut rcc.apb2); let mut gpioa = p.GPIOA.split(&mut rcc.apb2); let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl); let miso = gpioa.pa6; let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl); let mut spi = Spi::spi1( p.SPI1, (sck, miso, mosi), &mut afio.mapr, MODE, 100.khz(), clocks, &mut rcc.apb2, ); loop { for r in 0..255 { let _ = spi.write(&[0, 0, 0, 0]); for _i in 0..16 { let _ = spi.write(&[0b1110_0001, 0, 0, r]); } let _ = spi.write(&[0xFF, 0xFF, 0xFF, 0xFF]); } for b in 0..255 { let _ = spi.write(&[0, 0, 0, 0]); for _i in 0..16 { let _ = spi.write(&[0b1110_0001, b, 0, 0]); } let _ = spi.write(&[0xFF, 0xFF, 0xFF, 0xFF]); } for g in 0..255 { let _ = spi.write(&[0, 0, 0, 0]); for _i in 0..16 { let _ = spi.write(&[0b1110_0001, 0, g, 0]); } let _ = spi.write(&[0xFF, 0xFF, 0xFF, 0xFF]); } } } loop { continue; } }