Switched USART
ci/woodpecker/push/woodpecker Pipeline was successful Details

Added UTC offset
This commit is contained in:
Sebastian 2022-07-24 19:53:15 +02:00
parent 60c312bd39
commit 2449a611fd
3 changed files with 74 additions and 40 deletions

View File

@ -12,6 +12,7 @@ impl App {
if let Some(result) = self.gps_parser.parse_from_byte(byte) { if let Some(result) = self.gps_parser.parse_from_byte(byte) {
match result { match result {
Ok(ParseResult::GGA(Some(gga))) => { Ok(ParseResult::GGA(Some(gga))) => {
defmt::info!("Got a GGA, setting time");
time::set(&gga.time); time::set(&gga.time);
} }
Ok(_) => {} // Some other sentences.. Ok(_) => {} // Some other sentences..

View File

@ -1,5 +1,5 @@
use cortex_m::{asm::wfi, prelude::*}; use cortex_m::{asm::wfi, prelude::*};
use embedded_hal::digital::v2::{OutputPin, ToggleableOutputPin}; use embedded_hal::digital::v2::{InputPin, OutputPin, ToggleableOutputPin};
use nb::{self, block}; use nb::{self, block};
use nmea0183::Parser; use nmea0183::Parser;
use stm32f1xx_hal::{ use stm32f1xx_hal::{
@ -36,14 +36,17 @@ pub struct App {
delay: Delay, delay: Delay,
board_led: gpioc::PC13<Output<PushPull>>, board_led: gpioc::PC13<Output<PushPull>>,
serial: Serial< serial: Serial<
stm32::USART3, stm32::USART1,
( (
gpiob::PB10<Alternate<PushPull>>, gpioa::PA9<Alternate<PushPull>>,
gpiob::PB11<Input<Floating>>, gpioa::PA10<Input<Floating>>,
), ),
>, >,
gps_parser: Parser, gps_parser: Parser,
button1: gpiob::PB0<Input<Floating>>,
button2: gpiob::PB1<Input<Floating>>,
spi: AppSPI, spi: AppSPI,
disp_strobe: gpioa::PA0<Output<PushPull>>, disp_strobe: gpioa::PA0<Output<PushPull>>,
} }
@ -60,44 +63,69 @@ impl App {
pub fn run(mut self) -> ! { pub fn run(mut self) -> ! {
defmt::info!("Application Startup!"); defmt::info!("Application Startup!");
let mut cnt = 0;
let mut utc_offset = 2;
let mut prev_button1_state = self.button1.is_high().unwrap();
let mut prev_button2_state = self.button2.is_high().unwrap();
loop { loop {
self.poll_gps(); self.poll_gps();
let time = time::get(); if prev_button1_state && !self.button1.is_high().unwrap() {
utc_offset = if utc_offset == 0 { 23 } else { utc_offset - 1 };
defmt::info!("Button 1 pressed, new offset: {}", utc_offset);
}
if prev_button2_state && !self.button2.is_high().unwrap() {
utc_offset = if utc_offset == 23 { 0 } else { utc_offset + 1 };
defmt::info!("Button 2 pressed, new offset: {}", utc_offset);
}
prev_button1_state = self.button1.is_high().unwrap();
prev_button2_state = self.button2.is_high().unwrap();
let hours_high = (time.hours as u8) / 10; if cnt >= 250 {
let hours_low = (time.hours as u8) % 10; let mut time = time::get();
let minutes_high = (time.minutes as u8) / 10; time.hours = (time.hours + utc_offset) % 24;
let minutes_low = (time.minutes as u8) % 10;
let seconds_high = (time.seconds as u8) / 10;
let seconds_low = (time.seconds as u8) % 10;
defmt::info!( let hours_high = (time.hours as u8) / 10;
"Time: {} {} : {} {} : {} {}", let hours_low = (time.hours as u8) % 10;
hours_high, let minutes_high = (time.minutes as u8) / 10;
hours_low, let minutes_low = (time.minutes as u8) % 10;
minutes_high, let seconds_high = (time.seconds as u8) / 10;
minutes_low, let seconds_low = (time.seconds as u8) % 10;
seconds_high,
seconds_low
);
let hours_byte = fendangle_digit(hours_high) << 4 | fendangle_digit(hours_low); defmt::info!(
let minutes_byte = fendangle_digit(minutes_high) << 4 | fendangle_digit(minutes_low); "Display Time: {} {} : {} {} : {} {}",
let seconds_byte = fendangle_digit(seconds_high) << 4 | fendangle_digit(seconds_low); hours_high,
hours_low,
minutes_high,
minutes_low,
seconds_high,
seconds_low
);
self.spi let hours_byte = fendangle_digit(hours_high) << 4 | fendangle_digit(hours_low);
.write(&[hours_byte, minutes_byte, hours_byte]) let minutes_byte =
.unwrap(); fendangle_digit(minutes_high) << 4 | fendangle_digit(minutes_low);
let seconds_byte =
fendangle_digit(seconds_high) << 4 | fendangle_digit(seconds_low);
defmt::debug!("Bytes: {=[u8]:x}", [hours_byte, minutes_byte, hours_byte]); self.spi
.write(&[seconds_byte, minutes_byte, hours_byte])
.unwrap();
self.disp_strobe.set_high().unwrap(); defmt::debug!("Bytes: {=[u8]:x}", [hours_byte, minutes_byte, hours_byte]);
self.delay.delay_ms(10u16);
self.disp_strobe.set_low().unwrap();
self.board_led.toggle().unwrap(); self.disp_strobe.set_high().unwrap();
self.delay.delay_ms(240u16); self.delay.delay_ms(1u16);
self.disp_strobe.set_low().unwrap();
//self.board_led.toggle().unwrap();
cnt = 10;
}
cnt += 1;
self.delay.delay_ms(1u16);
} }
} }
} }

View File

@ -42,21 +42,24 @@ pub fn setup(cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals) -> A
let delay = Delay::new(cp.SYST, clocks); let delay = Delay::new(cp.SYST, clocks);
// USART3 let button1 = gpiob.pb0.into_floating_input(&mut gpiob.crl);
// Configure pb10 as a push_pull output, this will be the tx pin let button2 = gpiob.pb1.into_floating_input(&mut gpiob.crl);
let tx = gpiob.pb10.into_alternate_push_pull(&mut gpiob.crh);
// Take ownership over pb11 // USART1
let rx = gpiob.pb11; // Configure pa9 as a push_pull output, this will be the tx pin
let tx = gpioa.pa9.into_alternate_push_pull(&mut gpioa.crh);
// Take ownership over pa10
let rx = gpioa.pa10;
// Set up the usart device. Taks ownership over the USART register and tx/rx pins. The rest of // 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. // the registers are used to enable and configure the device.
let serial = Serial::usart3( let serial = Serial::usart1(
dp.USART3, dp.USART1,
(tx, rx), (tx, rx),
&mut afio.mapr, &mut afio.mapr,
Config::default().baudrate(9600.bps()), Config::default().baudrate(9600.bps()),
clocks, clocks,
&mut rcc.apb1, &mut rcc.apb2,
); );
let gps_parser = Parser::new(); let gps_parser = Parser::new();
@ -88,6 +91,8 @@ pub fn setup(cp: cortex_m::peripheral::Peripherals, dp: stm32::Peripherals) -> A
board_led, board_led,
serial, serial,
gps_parser, gps_parser,
button1,
button2,
spi, spi,
disp_strobe, disp_strobe,
} }