Added GPS parsing test
This commit is contained in:
parent
f53b9190ef
commit
1d063adee0
|
@ -1,8 +1,13 @@
|
||||||
use cortex_m::prelude::*;
|
use cortex_m::prelude::*;
|
||||||
use embedded_hal::digital::v2::OutputPin;
|
use embedded_hal::digital::v2::{OutputPin, ToggleableOutputPin};
|
||||||
|
use nb::{self, block};
|
||||||
|
use nmea0183::{ParseResult, Parser};
|
||||||
use stm32f1xx_hal::{
|
use stm32f1xx_hal::{
|
||||||
delay::Delay,
|
delay::Delay,
|
||||||
gpio::{gpioc, Output, PushPull},
|
gpio::{gpiob, gpioc, Alternate, Floating, Input, Output, PushPull},
|
||||||
|
prelude::*,
|
||||||
|
serial::Serial,
|
||||||
|
stm32,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod setup;
|
mod setup;
|
||||||
|
@ -13,20 +18,36 @@ pub use setup::setup;
|
||||||
pub struct App {
|
pub struct App {
|
||||||
delay: Delay,
|
delay: Delay,
|
||||||
board_led: gpioc::PC13<Output<PushPull>>,
|
board_led: gpioc::PC13<Output<PushPull>>,
|
||||||
|
serial: Serial<
|
||||||
|
stm32::USART3,
|
||||||
|
(
|
||||||
|
gpiob::PB10<Alternate<PushPull>>,
|
||||||
|
gpiob::PB11<Input<Floating>>,
|
||||||
|
),
|
||||||
|
>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub fn run(mut self) -> ! {
|
pub fn run(mut self) -> ! {
|
||||||
defmt::info!("Application Startup!");
|
defmt::info!("Application Startup!");
|
||||||
|
|
||||||
loop {
|
let mut parser = Parser::new();
|
||||||
defmt::info!("Blink!");
|
|
||||||
self.board_led.set_high().unwrap();
|
|
||||||
self.delay.delay_ms(500u32);
|
|
||||||
|
|
||||||
defmt::info!("Blonk!");
|
loop {
|
||||||
self.board_led.set_low().unwrap();
|
match self.serial.read() {
|
||||||
self.delay.delay_ms(500u32);
|
Ok(byte) => {
|
||||||
|
self.board_led.toggle().unwrap();
|
||||||
|
if let Some(result) = parser.parse_from_byte(byte) {
|
||||||
|
match result {
|
||||||
|
Ok(ParseResult::GGA(Some(_))) => defmt::info!("Got GGA"), // Got GGA sentence
|
||||||
|
Ok(_) => {} // Some other sentences..
|
||||||
|
Err(_) => {} // Got parse error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(nb::Error::WouldBlock) => {}
|
||||||
|
Err(nb::Error::Other(_)) => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//exit();
|
//exit();
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
use stm32f1xx_hal::{delay::Delay, prelude::*, stm32};
|
use stm32f1xx_hal::{
|
||||||
|
delay::Delay,
|
||||||
|
prelude::*,
|
||||||
|
serial::{Config, Serial},
|
||||||
|
stm32,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::application::App;
|
use crate::application::App;
|
||||||
|
|
||||||
|
@ -21,11 +26,35 @@ pub fn setup(cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals) -> A
|
||||||
defmt::info!("Clock Setup done");
|
defmt::info!("Clock Setup done");
|
||||||
|
|
||||||
// Acquire the GPIOC peripheral
|
// Acquire the GPIOC peripheral
|
||||||
|
let mut gpiob = dp.GPIOB.split(&mut rcc.apb2);
|
||||||
let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
|
let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
|
||||||
|
|
||||||
|
let mut afio = dp.AFIO.constrain(&mut rcc.apb2);
|
||||||
|
|
||||||
let board_led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
|
let board_led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
|
||||||
|
|
||||||
let delay = Delay::new(cp.SYST, clocks);
|
let delay = Delay::new(cp.SYST, clocks);
|
||||||
|
|
||||||
App { delay, board_led }
|
// USART3
|
||||||
|
// Configure pb10 as a push_pull output, this will be the tx pin
|
||||||
|
let tx = gpiob.pb10.into_alternate_push_pull(&mut gpiob.crh);
|
||||||
|
// Take ownership over pb11
|
||||||
|
let rx = gpiob.pb11;
|
||||||
|
|
||||||
|
// Set up the usart device. Taks ownership over the USART register and tx/rx pins. The rest of
|
||||||
|
// the registers are used to enable and configure the device.
|
||||||
|
let serial = Serial::usart3(
|
||||||
|
dp.USART3,
|
||||||
|
(tx, rx),
|
||||||
|
&mut afio.mapr,
|
||||||
|
Config::default().baudrate(9600.bps()),
|
||||||
|
clocks,
|
||||||
|
&mut rcc.apb1,
|
||||||
|
);
|
||||||
|
|
||||||
|
App {
|
||||||
|
delay,
|
||||||
|
board_led,
|
||||||
|
serial,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue