12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #![deny(unsafe_code)]
- #![deny(warnings)]
- #![no_main]
- #![no_std]
- extern crate panic_itm;
- use cortex_m::iprintln;
- use stm32f1xx_hal::{
- prelude::*,
- pac,
- spi::Spi,
- };
- use mfrc522::Mfrc522;
- use cortex_m_rt::entry;
- #[entry]
- fn main() -> ! {
- let mut cp = cortex_m::Peripherals::take().unwrap();
- let dp = pac::Peripherals::take().unwrap();
- let _stim = &mut cp.ITM.stim[0];
- let mut rcc = dp.RCC.constrain();
- let mut afio = dp.AFIO.constrain(&mut rcc.apb2);
- let mut flash = dp.FLASH.constrain();
- let mut gpioa = dp.GPIOA.split(&mut rcc.apb2);
- let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
- let clocks = rcc.cfgr.freeze(&mut flash.acr);
- 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 spi = Spi::spi1(
- dp.SPI1,
- (sck, miso, mosi),
- &mut afio.mapr,
- mfrc522::MODE,
- 1.mhz(),
- clocks,
- &mut rcc.apb2,
- );
- let nss = gpioa.pa4.into_push_pull_output(&mut gpioa.crl);
- let mut mfrc522 = Mfrc522::new(spi, nss).unwrap();
- let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
- led.set_high();
- loop {
- if let Ok(atqa) = mfrc522.reqa() {
- if let Ok(uid) = mfrc522.select(&atqa) {
- iprintln!(_stim, "* {:?}", uid);
- }
- }
- }
- }
|