Skip to content

Commit

Permalink
Cleanup examples
Browse files Browse the repository at this point in the history
  • Loading branch information
usbalbin committed Jan 19, 2025
1 parent 4982a32 commit 9dcaba8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
3 changes: 2 additions & 1 deletion examples/adc-continious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use crate::hal::{
config::{Continuous, Resolution, SampleTime, Sequence},
AdcClaim, ClockSource, Temperature, Vref,
},
delay::SYSTDelayExt,
gpio::GpioExt,
pwr::PwrExt,
rcc::{Config, RccExt},
signature::{VrefCal, VDDA_CALIB},
stm32::Peripherals,
};
use stm32g4xx_hal::{self as hal, delay::SYSTDelayExt};
use stm32g4xx_hal as hal;

use cortex_m_rt::entry;

Expand Down
3 changes: 2 additions & 1 deletion examples/adc-one-shot-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ use crate::hal::{
config::{Continuous, Dma as AdcDma, Resolution, SampleTime, Sequence},
AdcClaim, ClockSource, Temperature,
},
delay::SYSTDelayExt,
dma::{config::DmaConfig, stream::DMAExt, TransferExt},
gpio::GpioExt,
pwr::PwrExt,
rcc::{Config, RccExt},
stm32::Peripherals,
};
use stm32g4xx_hal::{self as hal, delay::SYSTDelayExt};
use stm32g4xx_hal as hal;

#[macro_use]
mod utils;
Expand Down
24 changes: 12 additions & 12 deletions examples/uart-fifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ extern crate cortex_m_rt as rt;

use core::fmt::Write;

use embedded_io::{Read, ReadReady};
use hal::prelude::*;
use hal::pwr::PwrExt;
use hal::serial::*;
use hal::{rcc, stm32};
use stm32g4xx_hal as hal;
// TODO: switch to embedded-hal-nb
use hal::hal_02::serial::Read;

use cortex_m_rt::entry;

Expand Down Expand Up @@ -52,23 +51,24 @@ fn main() -> ! {

let (mut tx1, mut rx1) = usart.split();

let mut buffer = [0; 4];
let mut cnt = 0;
loop {
if rx1.fifo_threshold_reached() {
loop {
match rx1.read() {
Err(nb::Error::WouldBlock) => {
// no more data available in fifo
break;
}
Err(nb::Error::Other(_err)) => {
match rx1.read_ready() {
Ok(true) => (),
Ok(false) => break, // no more data available in fifo
Err(e) => {
// Handle other error Overrun, Framing, Noise or Parity
}
Ok(byte) => {
writeln!(tx1, "{}: {}\r", cnt, byte).unwrap();
cnt += 1;
utils::logger::error!("Error: {:?}", e);
}
}

let count = rx1.read(&mut buffer).unwrap();
let bytes = &buffer[count];
writeln!(tx1, "{}: {}\r", cnt, bytes).unwrap();
cnt += count;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use hal::{rcc, stm32};
use stm32g4xx_hal as hal;

use cortex_m_rt::entry;
use nb::block;
use utils::logger::info;

#[macro_use]
Expand Down Expand Up @@ -57,10 +56,11 @@ fn main() -> ! {
usart.read_exact(&mut read_buf).unwrap();
usart.write_all(&read_buf).unwrap();

let mut single_byte_buffer = [0; 1];
let mut cnt = 0;
loop {
match block!(embedded_hal_old::serial::Read::read(&mut usart)) {
Ok(byte) => writeln!(usart, "{}: {}\r", cnt, byte).unwrap(),
match usart.read_exact(&mut single_byte_buffer) {
Ok(()) => writeln!(usart, "{}: {}\r", cnt, single_byte_buffer[0]).unwrap(),
Err(e) => writeln!(usart, "E: {:?}\r", e).unwrap(),
};
cnt += 1;
Expand Down
1 change: 1 addition & 0 deletions src/serial/usart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use embedded_io::{ReadReady, WriteReady};
use crate::serial::config::*;
/// Serial error
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
/// Framing error
Framing,
Expand Down

0 comments on commit 9dcaba8

Please sign in to comment.