Added GPS parsing test

This commit is contained in:
Sebastian 2021-04-12 00:06:18 +02:00
parent f53b9190ef
commit 1d063adee0
2 changed files with 61 additions and 11 deletions

View File

@ -1,8 +1,13 @@
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::{
delay::Delay,
gpio::{gpioc, Output, PushPull},
gpio::{gpiob, gpioc, Alternate, Floating, Input, Output, PushPull},
prelude::*,
serial::Serial,
stm32,
};
mod setup;
@ -13,20 +18,36 @@ pub use setup::setup;
pub struct App {
delay: Delay,
board_led: gpioc::PC13<Output<PushPull>>,
serial: Serial<
stm32::USART3,
(
gpiob::PB10<Alternate<PushPull>>,
gpiob::PB11<Input<Floating>>,
),
>,
}
impl App {
pub fn run(mut self) -> ! {
defmt::info!("Application Startup!");
loop {
defmt::info!("Blink!");
self.board_led.set_high().unwrap();
self.delay.delay_ms(500u32);
let mut parser = Parser::new();
defmt::info!("Blonk!");
self.board_led.set_low().unwrap();
self.delay.delay_ms(500u32);
loop {
match self.serial.read() {
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();

View File

@ -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;
@ -21,11 +26,35 @@ pub fn setup(cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals) -> A
defmt::info!("Clock Setup done");
// Acquire the GPIOC peripheral
let mut gpiob = dp.GPIOB.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 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,
}
}